clif.c 352 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "intif.h"
  25. #include "battle.h"
  26. #include "mob.h"
  27. #include "party.h"
  28. #include "unit.h"
  29. #include "guild.h"
  30. #include "vending.h"
  31. #include "pet.h"
  32. #include "homunculus.h"
  33. #include "mercenary.h"
  34. #include "log.h"
  35. #include "clif.h"
  36. #include "mail.h"
  37. #include "quest.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To idenfity disguised characters.
  74. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  75. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  76. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  77. static char map_ip_str[128];
  78. static uint32 map_ip;
  79. static uint32 bind_ip = INADDR_ANY;
  80. static uint16 map_port = 5121;
  81. int map_fd;
  82. int clif_parse (int fd);
  83. /*==========================================
  84. * map鯖のip設定
  85. *------------------------------------------*/
  86. int clif_setip(const char* ip)
  87. {
  88. char ip_str[16];
  89. map_ip = host2ip(ip);
  90. if (!map_ip) {
  91. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  92. return 0;
  93. }
  94. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  95. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  96. return 1;
  97. }
  98. void clif_setbindip(const char* ip)
  99. {
  100. char ip_str[16];
  101. bind_ip = host2ip(ip);
  102. if (bind_ip) {
  103. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  104. } else {
  105. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  106. }
  107. }
  108. /*==========================================
  109. * map鯖のport設定
  110. *------------------------------------------*/
  111. void clif_setport(uint16 port)
  112. {
  113. map_port = port;
  114. }
  115. /*==========================================
  116. * map鯖のip読み出し
  117. *------------------------------------------*/
  118. uint32 clif_getip(void)
  119. {
  120. return map_ip;
  121. }
  122. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  123. uint32 clif_refresh_ip(void)
  124. {
  125. uint32 new_ip;
  126. new_ip = host2ip(map_ip_str);
  127. if (new_ip && new_ip != map_ip) {
  128. map_ip = new_ip;
  129. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  130. return map_ip;
  131. }
  132. return 0;
  133. }
  134. /*==========================================
  135. * map鯖のport読み出し
  136. *------------------------------------------*/
  137. uint16 clif_getport(void)
  138. {
  139. return map_port;
  140. }
  141. /*==========================================
  142. * clif_sendでAREA*指定時用
  143. *------------------------------------------*/
  144. int clif_send_sub(struct block_list *bl, va_list ap)
  145. {
  146. struct block_list *src_bl;
  147. struct map_session_data *sd;
  148. unsigned char *buf;
  149. int len, type, fd;
  150. nullpo_retr(0, bl);
  151. nullpo_retr(0, sd = (struct map_session_data *)bl);
  152. fd = sd->fd;
  153. if (!fd) //Don't send to disconnected clients.
  154. return 0;
  155. buf = va_arg(ap,unsigned char*);
  156. len = va_arg(ap,int);
  157. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  158. type = va_arg(ap,int);
  159. switch(type)
  160. {
  161. case AREA_WOS:
  162. if (bl == src_bl)
  163. return 0;
  164. break;
  165. case AREA_WOC:
  166. if (sd->chatID || bl == src_bl)
  167. return 0;
  168. break;
  169. case AREA_WOSC:
  170. {
  171. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  172. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  173. return 0;
  174. }
  175. break;
  176. }
  177. if (session[fd] == NULL)
  178. return 0;
  179. WFIFOHEAD(fd, len);
  180. if (WFIFOP(fd,0) == buf) {
  181. ShowError("WARNING: Invalid use of clif_send function\n");
  182. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  183. ShowError(" Please correct your code.\n");
  184. // don't send to not move the pointer of the packet for next sessions in the loop
  185. //WFIFOSET(fd,0);//## TODO is this ok?
  186. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  187. return 0;
  188. }
  189. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  190. memcpy(WFIFOP(fd,0), buf, len);
  191. WFIFOSET(fd,len);
  192. }
  193. return 0;
  194. }
  195. /*==========================================
  196. *
  197. *------------------------------------------*/
  198. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  199. {
  200. int i;
  201. struct map_session_data *sd, *tsd;
  202. struct party_data *p = NULL;
  203. struct guild *g = NULL;
  204. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  205. struct s_mapiterator* iter;
  206. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  207. nullpo_retr(0, bl);
  208. sd = BL_CAST(BL_PC, bl);
  209. switch(type) {
  210. case ALL_CLIENT: //All player clients.
  211. iter = mapit_getallusers();
  212. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  213. {
  214. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  215. { // packet must exist for the client version
  216. WFIFOHEAD(tsd->fd, len);
  217. memcpy(WFIFOP(tsd->fd,0), buf, len);
  218. WFIFOSET(tsd->fd,len);
  219. }
  220. }
  221. mapit_free(iter);
  222. break;
  223. case ALL_SAMEMAP: //All players on the same map
  224. iter = mapit_getallusers();
  225. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  226. {
  227. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  228. { // packet must exist for the client version
  229. WFIFOHEAD(tsd->fd, len);
  230. memcpy(WFIFOP(tsd->fd,0), buf, len);
  231. WFIFOSET(tsd->fd,len);
  232. }
  233. }
  234. mapit_free(iter);
  235. break;
  236. case AREA:
  237. case AREA_WOSC:
  238. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  239. clif_send (buf, len, bl, SELF);
  240. case AREA_WOC:
  241. case AREA_WOS:
  242. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  243. BL_PC, buf, len, bl, type);
  244. break;
  245. case AREA_CHAT_WOC:
  246. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  247. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  248. break;
  249. case CHAT:
  250. case CHAT_WOS:
  251. {
  252. struct chat_data *cd;
  253. if (sd) {
  254. cd = (struct chat_data*)map_id2bl(sd->chatID);
  255. } else if (bl->type == BL_CHAT) {
  256. cd = (struct chat_data*)bl;
  257. } else break;
  258. if (cd == NULL)
  259. break;
  260. for(i = 0; i < cd->users; i++) {
  261. if (type == CHAT_WOS && cd->usersd[i] == sd)
  262. continue;
  263. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  264. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  265. {
  266. WFIFOHEAD(fd,len);
  267. memcpy(WFIFOP(fd,0), buf, len);
  268. WFIFOSET(fd,len);
  269. }
  270. }
  271. }
  272. }
  273. break;
  274. case CHAT_MAINCHAT: //[LuzZza]
  275. iter = mapit_getallusers();
  276. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  277. {
  278. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  279. { // packet must exist for the client version
  280. WFIFOHEAD(tsd->fd, len);
  281. memcpy(WFIFOP(tsd->fd,0), buf, len);
  282. WFIFOSET(tsd->fd,len);
  283. }
  284. }
  285. mapit_free(iter);
  286. break;
  287. case PARTY_AREA:
  288. case PARTY_AREA_WOS:
  289. x0 = bl->x - AREA_SIZE;
  290. y0 = bl->y - AREA_SIZE;
  291. x1 = bl->x + AREA_SIZE;
  292. y1 = bl->y + AREA_SIZE;
  293. case PARTY:
  294. case PARTY_WOS:
  295. case PARTY_SAMEMAP:
  296. case PARTY_SAMEMAP_WOS:
  297. if (sd && sd->status.party_id)
  298. p = party_search(sd->status.party_id);
  299. if (p) {
  300. for(i=0;i<MAX_PARTY;i++){
  301. if( (sd = p->data[i].sd) == NULL )
  302. continue;
  303. if( !(fd=sd->fd) )
  304. continue;
  305. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  306. continue;
  307. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  308. continue;
  309. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  310. continue;
  311. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  312. { // packet must exist for the client version
  313. WFIFOHEAD(fd,len);
  314. memcpy(WFIFOP(fd,0), buf, len);
  315. WFIFOSET(fd,len);
  316. }
  317. }
  318. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  319. break;
  320. iter = mapit_getallusers();
  321. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  322. {
  323. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  324. { // packet must exist for the client version
  325. WFIFOHEAD(tsd->fd, len);
  326. memcpy(WFIFOP(tsd->fd,0), buf, len);
  327. WFIFOSET(tsd->fd,len);
  328. }
  329. }
  330. mapit_free(iter);
  331. }
  332. break;
  333. case DUEL:
  334. case DUEL_WOS:
  335. if (!sd || !sd->duel_group) break; //Invalid usage.
  336. iter = mapit_getallusers();
  337. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  338. {
  339. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  340. continue;
  341. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  342. { // packet must exist for the client version
  343. WFIFOHEAD(tsd->fd, len);
  344. memcpy(WFIFOP(tsd->fd,0), buf, len);
  345. WFIFOSET(tsd->fd,len);
  346. }
  347. }
  348. mapit_free(iter);
  349. break;
  350. case SELF:
  351. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  352. WFIFOHEAD(fd,len);
  353. memcpy(WFIFOP(fd,0), buf, len);
  354. WFIFOSET(fd,len);
  355. }
  356. break;
  357. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  358. case GUILD_AREA:
  359. case GUILD_AREA_WOS:
  360. x0 = bl->x - AREA_SIZE;
  361. y0 = bl->y - AREA_SIZE;
  362. x1 = bl->x + AREA_SIZE;
  363. y1 = bl->y + AREA_SIZE;
  364. case GUILD_SAMEMAP:
  365. case GUILD_SAMEMAP_WOS:
  366. case GUILD:
  367. case GUILD_WOS:
  368. if (sd && sd->status.guild_id)
  369. g = guild_search(sd->status.guild_id);
  370. if (g) {
  371. for(i = 0; i < g->max_member; i++) {
  372. if( (sd = g->member[i].sd) != NULL )
  373. {
  374. if( !(fd=sd->fd) )
  375. continue;
  376. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  377. continue;
  378. if( type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m )
  379. continue;
  380. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  381. continue;
  382. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  383. { // packet must exist for the client version
  384. WFIFOHEAD(fd,len);
  385. memcpy(WFIFOP(fd,0), buf, len);
  386. WFIFOSET(fd,len);
  387. }
  388. }
  389. }
  390. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  391. break;
  392. iter = mapit_getallusers();
  393. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  394. {
  395. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  396. { // packet must exist for the client version
  397. WFIFOHEAD(tsd->fd, len);
  398. memcpy(WFIFOP(tsd->fd,0), buf, len);
  399. WFIFOSET(tsd->fd,len);
  400. }
  401. }
  402. mapit_free(iter);
  403. }
  404. break;
  405. default:
  406. ShowError("clif_send: Unrecognized type %d\n",type);
  407. return -1;
  408. }
  409. return 0;
  410. }
  411. //
  412. // パケット作って送信
  413. //
  414. /*==========================================
  415. *
  416. *------------------------------------------*/
  417. int clif_authok(struct map_session_data *sd)
  418. {
  419. int fd;
  420. if (!sd->fd)
  421. return 0;
  422. fd = sd->fd;
  423. WFIFOHEAD(fd, packet_len(0x73));
  424. WFIFOW(fd, 0) = 0x73;
  425. WFIFOL(fd, 2) = gettick();
  426. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  427. WFIFOB(fd, 9) = 5; // ignored
  428. WFIFOB(fd,10) = 5; // ignored
  429. WFIFOSET(fd,packet_len(0x73));
  430. return 0;
  431. }
  432. /*==========================================
  433. * Authentication failed/disconnect client.
  434. *------------------------------------------
  435. * The client closes it's socket and displays a message according to type:
  436. * 1 - server closed -> MsgStringTable[4]
  437. * 2 - ID already logged in -> MsgStringTable[5]
  438. * 3 - timeout/too much lag -> MsgStringTable[241]
  439. * 4 - server full -> MsgStringTable[264]
  440. * 5 - underaged -> MsgStringTable[305]
  441. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  442. * 9 - too many connections from this ip -> MsgStringTable[529]
  443. * 10 - out of available time paid for -> MsgStringTable[530]
  444. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  445. * other - disconnected -> MsgStringTable[3]
  446. */
  447. int clif_authfail_fd(int fd, int type)
  448. {
  449. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  450. return 0;
  451. WFIFOHEAD(fd, packet_len(0x81));
  452. WFIFOW(fd,0) = 0x81;
  453. WFIFOB(fd,2) = type;
  454. WFIFOSET(fd,packet_len(0x81));
  455. set_eof(fd);
  456. return 0;
  457. }
  458. /*==========================================
  459. *
  460. *------------------------------------------*/
  461. int clif_charselectok(int id)
  462. {
  463. struct map_session_data* sd;
  464. int fd;
  465. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  466. return 1;
  467. fd = sd->fd;
  468. WFIFOHEAD(fd,packet_len(0xb3));
  469. WFIFOW(fd,0) = 0xb3;
  470. WFIFOB(fd,2) = 1;
  471. WFIFOSET(fd,packet_len(0xb3));
  472. return 0;
  473. }
  474. /*==========================================
  475. * Makes an item appear on the ground
  476. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  477. *------------------------------------------*/
  478. int clif_dropflooritem(struct flooritem_data* fitem)
  479. {
  480. uint8 buf[17];
  481. int view;
  482. nullpo_retr(0, fitem);
  483. if (fitem->item_data.nameid <= 0)
  484. return 0;
  485. WBUFW(buf, 0) = 0x9e;
  486. WBUFL(buf, 2) = fitem->bl.id;
  487. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  488. WBUFB(buf, 8) = fitem->item_data.identify;
  489. WBUFW(buf, 9) = fitem->bl.x;
  490. WBUFW(buf,11) = fitem->bl.y;
  491. WBUFB(buf,13) = fitem->subx;
  492. WBUFB(buf,14) = fitem->suby;
  493. WBUFW(buf,15) = fitem->item_data.amount;
  494. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  495. return 0;
  496. }
  497. /*==========================================
  498. *
  499. *------------------------------------------*/
  500. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  501. {
  502. unsigned char buf[16];
  503. nullpo_retr(0, fitem);
  504. WBUFW(buf,0) = 0xa1;
  505. WBUFL(buf,2) = fitem->bl.id;
  506. if (fd == 0) {
  507. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  508. } else {
  509. WFIFOHEAD(fd,packet_len(0xa1));
  510. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  511. WFIFOSET(fd,packet_len(0xa1));
  512. }
  513. return 0;
  514. }
  515. /*==========================================
  516. * make a unit (char, npc, mob, homun) disappear to one client
  517. * id : the id of the unit
  518. * type: 0 - moved out of sight
  519. * 1 - died
  520. * 2 - respawned
  521. * 3 - teleported / logged out
  522. * fd : the target client
  523. *------------------------------------------*/
  524. int clif_clearunit_single(int id, uint8 type, int fd)
  525. {
  526. WFIFOHEAD(fd, packet_len(0x80));
  527. WFIFOW(fd,0) = 0x80;
  528. WFIFOL(fd,2) = id;
  529. WFIFOB(fd,6) = type;
  530. WFIFOSET(fd, packet_len(0x80));
  531. return 0;
  532. }
  533. /*==========================================
  534. * make a unit (char, npc, mob, homun) disappear to all clients in area
  535. * type: 0 - moved out of sight
  536. * 1 - died
  537. * 2 - respawned
  538. * 3 - teleported / logged out
  539. *------------------------------------------*/
  540. int clif_clearunit_area(struct block_list* bl, uint8 type)
  541. {
  542. unsigned char buf[16];
  543. nullpo_retr(0, bl);
  544. WBUFW(buf,0) = 0x80;
  545. WBUFL(buf,2) = bl->id;
  546. WBUFB(buf,6) = type;
  547. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  548. if(disguised(bl)) {
  549. WBUFL(buf,2) = -bl->id;
  550. clif_send(buf, packet_len(0x80), bl, SELF);
  551. }
  552. return 0;
  553. }
  554. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  555. {
  556. struct block_list *bl = (struct block_list *)data;
  557. clif_clearunit_area(bl, 0);
  558. aFree(bl);
  559. return 0;
  560. }
  561. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  562. {
  563. struct block_list *tbl;
  564. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  565. memcpy (tbl, bl, sizeof (struct block_list));
  566. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  567. return 0;
  568. }
  569. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  570. {
  571. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  572. {
  573. *rhand = *lhand = 0;
  574. return;
  575. }
  576. #if PACKETVER < 4
  577. *rhand = sd->status.weapon;
  578. *lhand = sd->status.shield;
  579. #else
  580. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  581. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  582. {
  583. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  584. if (id->view_id > 0)
  585. *rhand = id->view_id;
  586. else
  587. *rhand = id->nameid;
  588. } else
  589. *rhand = 0;
  590. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  591. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  592. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  593. {
  594. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  595. if (id->view_id > 0)
  596. *lhand = id->view_id;
  597. else
  598. *lhand = id->nameid;
  599. } else
  600. *lhand = 0;
  601. #endif
  602. }
  603. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  604. static int clif_setlevel(int lv)
  605. {
  606. if( lv < battle_config.max_lv )
  607. return lv;
  608. if( lv < battle_config.aura_lv )
  609. return battle_config.max_lv - 1;
  610. return battle_config.max_lv;
  611. }
  612. /*==========================================
  613. * Prepares 'unit standing/spawning' packet
  614. *------------------------------------------*/
  615. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  616. {
  617. struct map_session_data* sd;
  618. struct status_change* sc = status_get_sc(bl);
  619. struct view_data* vd = status_get_viewdata(bl);
  620. unsigned char *buf = WBUFP(buffer,0);
  621. bool type = !pcdb_checkid(vd->class_);
  622. #if PACKETVER >= 7
  623. unsigned short offset = 0;
  624. #endif
  625. sd = BL_CAST(BL_PC, bl);
  626. if(type)
  627. WBUFW(buf,0) = spawn?0x7c:0x78;
  628. else
  629. #if PACKETVER < 4
  630. WBUFW(buf,0) = spawn?0x79:0x78;
  631. #elif PACKETVER < 7
  632. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  633. #else
  634. WBUFW(buf,0) = spawn?0x22b:0x22a;
  635. #endif
  636. #if PACKETVER >= 20071106
  637. if (type) {
  638. // shift payload 1 byte to the right for mob packets
  639. WBUFB(buf,2) = 0; // padding?
  640. offset++;
  641. buf = WBUFP(buffer,offset);
  642. }
  643. #endif
  644. WBUFL(buf, 2) = bl->id;
  645. WBUFW(buf, 6) = status_get_speed(bl);
  646. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  647. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  648. if (type&&spawn) { //uses an older and different packet structure
  649. WBUFW(buf,12) = (sc)? sc->option : 0;
  650. WBUFW(buf,14) = vd->hair_style;
  651. WBUFW(buf,16) = vd->weapon;
  652. WBUFW(buf,18) = vd->head_bottom;
  653. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  654. WBUFW(buf,22) = vd->shield;
  655. } else {
  656. #if PACKETVER >= 7
  657. if (!type) {
  658. WBUFL(buf,12) = (sc)? sc->option : 0;
  659. offset+=2;
  660. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  661. } else
  662. #endif
  663. WBUFW(buf,12) = (sc)? sc->option : 0;
  664. WBUFW(buf,14) = vd->class_;
  665. WBUFW(buf,16) = vd->hair_style;
  666. WBUFW(buf,18) = vd->weapon;
  667. #if PACKETVER < 4
  668. WBUFW(buf,20) = vd->head_bottom;
  669. WBUFW(buf,22) = vd->shield;
  670. #else
  671. WBUFW(buf,20) = vd->shield;
  672. WBUFW(buf,22) = vd->head_bottom;
  673. #endif
  674. }
  675. WBUFW(buf,24) = vd->head_top;
  676. WBUFW(buf,26) = vd->head_mid;
  677. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  678. { //The hell, why flags work like this?
  679. WBUFL(buf,22) = status_get_emblem_id(bl);
  680. WBUFL(buf,26) = status_get_guild_id(bl);
  681. }
  682. WBUFW(buf,28) = vd->hair_color;
  683. WBUFW(buf,30) = vd->cloth_color;
  684. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  685. if (type&&spawn) { //End of packet 0x7c
  686. WBUFB(buf,34) = 0; // karma
  687. WBUFB(buf,35) = vd->sex;
  688. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  689. WBUFB(buf,39) = 0;
  690. WBUFB(buf,40) = 0;
  691. return packet_len(0x7c);
  692. }
  693. WBUFL(buf,34) = status_get_guild_id(bl);
  694. WBUFW(buf,38) = status_get_emblem_id(bl);
  695. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  696. #if PACKETVER >= 7
  697. if (!type) {
  698. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  699. offset+=2;
  700. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  701. } else
  702. #endif
  703. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  704. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  705. WBUFB(buf,45) = vd->sex;
  706. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  707. WBUFB(buf,49) = (sd)? 5 : 0;
  708. WBUFB(buf,50) = (sd)? 5 : 0;
  709. if (spawn) {
  710. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  711. } else {
  712. WBUFB(buf,51) = vd->dead_sit;
  713. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  714. }
  715. return packet_len(WBUFW(buffer,0));
  716. }
  717. /*==========================================
  718. * Prepares 'unit walking' packet
  719. *------------------------------------------*/
  720. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  721. {
  722. struct map_session_data* sd;
  723. struct status_change* sc = status_get_sc(bl);
  724. struct view_data* vd = status_get_viewdata(bl);
  725. unsigned char* buf = WBUFP(buffer,0);
  726. #if PACKETVER >= 7
  727. unsigned short offset = 0;
  728. #endif
  729. sd = BL_CAST(BL_PC, bl);
  730. #if PACKETVER < 4
  731. WBUFW(buf, 0) = 0x7b;
  732. #elif PACKETVER < 7
  733. WBUFW(buf, 0) = 0x1da;
  734. #else
  735. WBUFW(buf, 0) = 0x22c;
  736. #endif
  737. #if PACKETVER >= 20071106
  738. WBUFB(buf, 2) = 0; // padding?
  739. offset++;
  740. buf = WBUFP(buf,offset);
  741. #endif
  742. WBUFL(buf, 2) = bl->id;
  743. WBUFW(buf, 6) = status_get_speed(bl);
  744. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  745. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  746. #if PACKETVER < 7
  747. WBUFW(buf,12) = (sc)? sc->option : 0;
  748. #else
  749. WBUFL(buf,12) = (sc)? sc->option : 0;
  750. offset+=2; //Shift the rest of elements by 2 bytes.
  751. buf = WBUFP(buffer,offset);
  752. #endif
  753. WBUFW(buf,14) = vd->class_;
  754. WBUFW(buf,16) = vd->hair_style;
  755. WBUFW(buf,18) = vd->weapon;
  756. #if PACKETVER < 4
  757. WBUFW(buf,20) = vd->head_bottom;
  758. WBUFL(buf,22) = gettick();
  759. WBUFW(buf,26) = vd->shield;
  760. #else
  761. WBUFW(buf,20) = vd->shield;
  762. WBUFW(buf,22) = vd->head_bottom;
  763. WBUFL(buf,24) = gettick();
  764. #endif
  765. WBUFW(buf,28) = vd->head_top;
  766. WBUFW(buf,30) = vd->head_mid;
  767. WBUFW(buf,32) = vd->hair_color;
  768. WBUFW(buf,34) = vd->cloth_color;
  769. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  770. WBUFL(buf,38) = status_get_guild_id(bl);
  771. WBUFW(buf,42) = status_get_emblem_id(bl);
  772. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  773. #if PACKETVER < 7
  774. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  775. #else
  776. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  777. offset+=2; //Shift the rest of elements by 2 bytes.
  778. buf = WBUFP(buffer,offset);
  779. #endif
  780. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  781. WBUFB(buf,49) = vd->sex;
  782. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  783. WBUFB(buf,56) = (sd)? 5 : 0;
  784. WBUFB(buf,57) = (sd)? 5 : 0;
  785. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  786. return packet_len(WBUFW(buffer,0));
  787. }
  788. //Modifies the buffer for disguise characters and sends it to self.
  789. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  790. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  791. {
  792. #if PACKETVER >= 20071106
  793. WBUFL(buf,3)=-bl->id;
  794. #else
  795. WBUFL(buf,2)=-bl->id;
  796. #endif
  797. clif_send(buf, len, bl, SELF);
  798. }
  799. /*==========================================
  800. * クラスチェンジ typeはMobの場合は1で他は0?
  801. *------------------------------------------*/
  802. int clif_class_change(struct block_list *bl,int class_,int type)
  803. {
  804. unsigned char buf[16];
  805. nullpo_retr(0, bl);
  806. if(!pcdb_checkid(class_)) {
  807. WBUFW(buf,0)=0x1b0;
  808. WBUFL(buf,2)=bl->id;
  809. WBUFB(buf,6)=type;
  810. WBUFL(buf,7)=class_;
  811. clif_send(buf,packet_len(0x1b0),bl,AREA);
  812. }
  813. return 0;
  814. }
  815. /*==========================================
  816. *
  817. *------------------------------------------*/
  818. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  819. {
  820. WFIFOHEAD(fd, packet_len(0x1e1));
  821. WFIFOW(fd,0)=0x1e1;
  822. WFIFOL(fd,2)=sd->bl.id;
  823. WFIFOW(fd,6)=sd->spiritball;
  824. WFIFOSET(fd, packet_len(0x1e1));
  825. }
  826. // new and improved weather display [Valaris]
  827. static void clif_weather_sub(int fd, int id, int type)
  828. {
  829. WFIFOHEAD(fd,packet_len(0x1f3));
  830. WFIFOW(fd,0) = 0x1f3;
  831. WFIFOL(fd,2) = id;
  832. WFIFOL(fd,6) = type;
  833. WFIFOSET(fd,packet_len(0x1f3));
  834. }
  835. /*==========================================
  836. *
  837. *------------------------------------------*/
  838. static void clif_weather_check(struct map_session_data *sd)
  839. {
  840. int m = sd->bl.m, fd = sd->fd;
  841. if (map[m].flag.snow
  842. || map[m].flag.clouds
  843. || map[m].flag.fog
  844. || map[m].flag.fireworks
  845. || map[m].flag.sakura
  846. || map[m].flag.leaves
  847. || map[m].flag.rain
  848. || map[m].flag.clouds2)
  849. {
  850. if (map[m].flag.snow)
  851. clif_weather_sub(fd, sd->bl.id, 162);
  852. if (map[m].flag.clouds)
  853. clif_weather_sub(fd, sd->bl.id, 233);
  854. if (map[m].flag.clouds2)
  855. clif_weather_sub(fd, sd->bl.id, 516);
  856. if (map[m].flag.fog)
  857. clif_weather_sub(fd, sd->bl.id, 515);
  858. if (map[m].flag.fireworks) {
  859. clif_weather_sub(fd, sd->bl.id, 297);
  860. clif_weather_sub(fd, sd->bl.id, 299);
  861. clif_weather_sub(fd, sd->bl.id, 301);
  862. }
  863. if (map[m].flag.sakura)
  864. clif_weather_sub(fd, sd->bl.id, 163);
  865. if (map[m].flag.leaves)
  866. clif_weather_sub(fd, sd->bl.id, 333);
  867. if (map[m].flag.rain)
  868. clif_weather_sub(fd, sd->bl.id, 161);
  869. }
  870. }
  871. void clif_weather(int m)
  872. {
  873. struct s_mapiterator* iter;
  874. struct map_session_data *sd=NULL;
  875. iter = mapit_getallusers();
  876. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  877. {
  878. if( sd->bl.m == m )
  879. clif_weather_check(sd);
  880. }
  881. mapit_free(iter);
  882. }
  883. int clif_spawn(struct block_list *bl)
  884. {
  885. unsigned char buf[128];
  886. struct view_data *vd;
  887. int len;
  888. vd = status_get_viewdata(bl);
  889. if( !vd || vd->class_ == INVISIBLE_CLASS )
  890. return 0;
  891. len = clif_set_unit_idle(bl, buf,true);
  892. clif_send(buf, len, bl, AREA_WOS);
  893. if (disguised(bl))
  894. clif_setdisguise(bl, buf, len);
  895. if (vd->cloth_color)
  896. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  897. switch (bl->type)
  898. {
  899. case BL_PC:
  900. {
  901. TBL_PC *sd = ((TBL_PC*)bl);
  902. if (sd->spiritball > 0)
  903. clif_spiritball(sd);
  904. if(sd->state.size==2) // tiny/big players [Valaris]
  905. clif_specialeffect(bl,423,AREA);
  906. else if(sd->state.size==1)
  907. clif_specialeffect(bl,421,AREA);
  908. }
  909. break;
  910. case BL_MOB:
  911. {
  912. TBL_MOB *md = ((TBL_MOB*)bl);
  913. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  914. clif_specialeffect(&md->bl,423,AREA);
  915. else if(md->special_state.size==1)
  916. clif_specialeffect(&md->bl,421,AREA);
  917. }
  918. break;
  919. case BL_NPC:
  920. {
  921. TBL_NPC *nd = ((TBL_NPC*)bl);
  922. if( nd->size == 2 )
  923. clif_specialeffect(&nd->bl,423,AREA);
  924. else if( nd->size == 1 )
  925. clif_specialeffect(&nd->bl,421,AREA);
  926. }
  927. break;
  928. case BL_PET:
  929. if (vd->head_bottom)
  930. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  931. break;
  932. }
  933. return 0;
  934. }
  935. //[orn]
  936. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  937. {
  938. struct status_data *status;
  939. unsigned char buf[128];
  940. nullpo_retr(0, hd);
  941. status = &hd->battle_status;
  942. memset(buf,0,packet_len(0x22e));
  943. WBUFW(buf,0)=0x22e;
  944. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  945. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  946. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  947. WBUFW(buf,27)=hd->homunculus.level;
  948. WBUFW(buf,29)=hd->homunculus.hunger;
  949. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  950. WBUFW(buf,33)=0; // equip id
  951. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  952. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  953. WBUFW(buf,39)=status->hit;
  954. if (battle_config.hom_setting&0x10)
  955. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  956. else
  957. WBUFW(buf,41)=status->cri/10;
  958. WBUFW(buf,43)=status->def + status->vit ;
  959. WBUFW(buf,45)=status->mdef;
  960. WBUFW(buf,47)=status->flee;
  961. WBUFW(buf,49)=(flag)?0:status->amotion;
  962. if (status->max_hp > SHRT_MAX) {
  963. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  964. WBUFW(buf,53) = 100;
  965. } else {
  966. WBUFW(buf,51)=status->hp;
  967. WBUFW(buf,53)=status->max_hp;
  968. }
  969. if (status->max_sp > SHRT_MAX) {
  970. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  971. WBUFW(buf,57) = 100;
  972. } else {
  973. WBUFW(buf,55)=status->sp;
  974. WBUFW(buf,57)=status->max_sp;
  975. }
  976. WBUFL(buf,59)=hd->homunculus.exp;
  977. WBUFL(buf,63)=hd->exp_next;
  978. WBUFW(buf,67)=hd->homunculus.skillpts;
  979. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  980. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  981. return 0;
  982. }
  983. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  984. { //[orn]
  985. int fd = sd->fd;
  986. WFIFOHEAD(fd, packet_len(0x230));
  987. nullpo_retv(sd->hd);
  988. WFIFOW(fd,0)=0x230;
  989. WFIFOW(fd,2)=type;
  990. WFIFOL(fd,4)=sd->hd->bl.id;
  991. WFIFOL(fd,8)=param;
  992. WFIFOSET(fd,packet_len(0x230));
  993. return;
  994. }
  995. int clif_homskillinfoblock(struct map_session_data *sd)
  996. { //[orn]
  997. struct homun_data *hd;
  998. int fd = sd->fd;
  999. int i,j,len=4,id;
  1000. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1001. hd = sd->hd;
  1002. if ( !hd )
  1003. return 0 ;
  1004. WFIFOW(fd,0)=0x235;
  1005. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1006. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1007. j = id - HM_SKILLBASE;
  1008. WFIFOW(fd,len ) = id;
  1009. WFIFOW(fd,len+2) = skill_get_inf(id);
  1010. WFIFOW(fd,len+4) = 0;
  1011. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1012. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1013. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1014. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1015. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1016. len+=37;
  1017. }
  1018. }
  1019. WFIFOW(fd,2)=len;
  1020. WFIFOSET(fd,len);
  1021. return 0;
  1022. }
  1023. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1024. { //[orn]
  1025. struct homun_data *hd;
  1026. int fd=sd->fd, skillid;
  1027. WFIFOHEAD(fd, packet_len(0x239));
  1028. nullpo_retv(sd);
  1029. skillid = skill_num - HM_SKILLBASE;
  1030. hd=sd->hd;
  1031. WFIFOW(fd,0) = 0x239;
  1032. WFIFOW(fd,2) = skill_num;
  1033. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1034. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1035. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1036. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1037. WFIFOSET(fd,packet_len(0x239));
  1038. return;
  1039. }
  1040. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1041. {
  1042. int fd=sd->fd;
  1043. WFIFOHEAD(fd,packet_len(0x22f));
  1044. WFIFOW(fd,0)=0x22f;
  1045. WFIFOB(fd,2)=fail;
  1046. WFIFOW(fd,3)=foodid;
  1047. WFIFOSET(fd,packet_len(0x22f));
  1048. return 0;
  1049. }
  1050. /*==========================================
  1051. *
  1052. *------------------------------------------*/
  1053. int clif_walkok(struct map_session_data *sd)
  1054. {
  1055. int fd=sd->fd;
  1056. WFIFOHEAD(fd, packet_len(0x87));
  1057. WFIFOW(fd,0)=0x87;
  1058. WFIFOL(fd,2)=gettick();
  1059. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1060. WFIFOSET(fd,packet_len(0x87));
  1061. return 0;
  1062. }
  1063. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1064. {
  1065. uint8 buf[128];
  1066. int len;
  1067. len = clif_set_unit_walking(bl,ud,buf);
  1068. clif_send(buf,len,bl,AREA_WOS);
  1069. if (disguised(bl))
  1070. clif_setdisguise(bl, buf, len);
  1071. if(vd->cloth_color)
  1072. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1073. switch(bl->type)
  1074. {
  1075. case BL_PC:
  1076. {
  1077. TBL_PC *sd = ((TBL_PC*)bl);
  1078. // clif_movepc(sd);
  1079. if(sd->state.size==2) // tiny/big players [Valaris]
  1080. clif_specialeffect(&sd->bl,423,AREA);
  1081. else if(sd->state.size==1)
  1082. clif_specialeffect(&sd->bl,421,AREA);
  1083. }
  1084. break;
  1085. case BL_MOB:
  1086. {
  1087. TBL_MOB *md = ((TBL_MOB*)bl);
  1088. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1089. clif_specialeffect(&md->bl,423,AREA);
  1090. else if(md->special_state.size==1)
  1091. clif_specialeffect(&md->bl,421,AREA);
  1092. }
  1093. break;
  1094. }
  1095. return;
  1096. }
  1097. /// Move the unit (does nothing if the client has no info about the unit)
  1098. /// Note: unit must not be self
  1099. void clif_move(struct unit_data *ud)
  1100. {
  1101. unsigned char buf[16];
  1102. struct view_data* vd;
  1103. struct block_list* bl = ud->bl;
  1104. vd = status_get_viewdata(bl);
  1105. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1106. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1107. if (ud->state.speed_changed) {
  1108. // Since we don't know how to update the speed of other objects,
  1109. // use the old walk packet to update the data.
  1110. ud->state.speed_changed = 0;
  1111. clif_move2(bl, vd, ud);
  1112. return;
  1113. }
  1114. WBUFW(buf,0)=0x86;
  1115. WBUFL(buf,2)=bl->id;
  1116. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1117. WBUFL(buf,12)=gettick();
  1118. clif_send(buf, 16, bl, AREA_WOS);
  1119. if (disguised(bl))
  1120. {
  1121. WBUFL(buf,2)=-bl->id;
  1122. clif_send(buf, 16, bl, SELF);
  1123. }
  1124. }
  1125. /*==========================================
  1126. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1127. *------------------------------------------*/
  1128. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1129. {
  1130. struct map_session_data *sd = NULL;
  1131. //Remove player from map server
  1132. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1133. map_quit(sd);
  1134. return 0;
  1135. }
  1136. /*==========================================
  1137. *
  1138. *------------------------------------------*/
  1139. void clif_quitsave(int fd,struct map_session_data *sd)
  1140. {
  1141. if (!battle_config.prevent_logout ||
  1142. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1143. map_quit(sd);
  1144. else if (sd->fd)
  1145. { //Disassociate session from player (session is deleted after this function was called)
  1146. //And set a timer to make him quit later.
  1147. session[sd->fd]->session_data = NULL;
  1148. sd->fd = 0;
  1149. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1150. }
  1151. }
  1152. /*==========================================
  1153. *
  1154. *------------------------------------------*/
  1155. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1156. {
  1157. int fd;
  1158. nullpo_retv(sd);
  1159. fd = sd->fd;
  1160. WFIFOHEAD(fd,packet_len(0x91));
  1161. WFIFOW(fd,0) = 0x91;
  1162. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1163. WFIFOW(fd,18) = x;
  1164. WFIFOW(fd,20) = y;
  1165. WFIFOSET(fd,packet_len(0x91));
  1166. }
  1167. /*==========================================
  1168. * Tells the client to connect to another map-server
  1169. *------------------------------------------*/
  1170. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1171. {
  1172. int fd;
  1173. nullpo_retv(sd);
  1174. fd = sd->fd;
  1175. WFIFOHEAD(fd,packet_len(0x92));
  1176. WFIFOW(fd,0) = 0x92;
  1177. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1178. WFIFOW(fd,18) = x;
  1179. WFIFOW(fd,20) = y;
  1180. WFIFOL(fd,22) = htonl(ip);
  1181. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1182. WFIFOSET(fd,packet_len(0x92));
  1183. }
  1184. void clif_blown(struct block_list *bl)
  1185. {
  1186. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1187. // clif_fixpos(bl);
  1188. clif_slide(bl, bl->x, bl->y);
  1189. }
  1190. /*==========================================
  1191. *
  1192. *------------------------------------------*/
  1193. void clif_fixpos(struct block_list *bl)
  1194. {
  1195. unsigned char buf[10];
  1196. nullpo_retv(bl);
  1197. WBUFW(buf,0) = 0x88;
  1198. WBUFL(buf,2) = bl->id;
  1199. WBUFW(buf,6) = bl->x;
  1200. WBUFW(buf,8) = bl->y;
  1201. clif_send(buf, packet_len(0x88), bl, AREA);
  1202. if( disguised(bl) )
  1203. {
  1204. WBUFL(buf,2) = -bl->id;
  1205. clif_send(buf, packet_len(0x88), bl, SELF);
  1206. }
  1207. }
  1208. /*==========================================
  1209. *
  1210. *------------------------------------------*/
  1211. int clif_npcbuysell(struct map_session_data* sd, int id)
  1212. {
  1213. int fd;
  1214. nullpo_retr(0, sd);
  1215. fd=sd->fd;
  1216. WFIFOHEAD(fd, packet_len(0xc4));
  1217. WFIFOW(fd,0)=0xc4;
  1218. WFIFOL(fd,2)=id;
  1219. WFIFOSET(fd,packet_len(0xc4));
  1220. return 0;
  1221. }
  1222. /*==========================================
  1223. *
  1224. *------------------------------------------*/
  1225. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1226. {
  1227. int fd,i,c;
  1228. nullpo_retr(0, sd);
  1229. nullpo_retr(0, nd);
  1230. fd = sd->fd;
  1231. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1232. WFIFOW(fd,0) = 0xc6;
  1233. c = 0;
  1234. for( i = 0; i < nd->u.shop.count; i++ )
  1235. {
  1236. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1237. int val = nd->u.shop.shop_item[i].value;
  1238. if( id == NULL )
  1239. continue;
  1240. WFIFOL(fd, 4+c*11) = val;
  1241. if (!id->flag.value_notdc)
  1242. val = pc_modifybuyvalue(sd,val);
  1243. WFIFOL(fd, 8+c*11) = val;
  1244. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1245. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1246. c++;
  1247. }
  1248. WFIFOW(fd,2) = 4 + c*11;
  1249. WFIFOSET(fd,WFIFOW(fd,2));
  1250. return 0;
  1251. }
  1252. /*==========================================
  1253. *
  1254. *------------------------------------------*/
  1255. int clif_selllist(struct map_session_data *sd)
  1256. {
  1257. int fd,i,c=0,val;
  1258. nullpo_retr(0, sd);
  1259. fd=sd->fd;
  1260. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1261. WFIFOW(fd,0)=0xc7;
  1262. for( i = 0; i < MAX_INVENTORY; i++ )
  1263. {
  1264. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1265. {
  1266. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1267. continue;
  1268. if( sd->status.inventory[i].expire_time )
  1269. continue; // Cannot Sell Rental Items
  1270. val=sd->inventory_data[i]->value_sell;
  1271. if( val < 0 )
  1272. continue;
  1273. WFIFOW(fd,4+c*10)=i+2;
  1274. WFIFOL(fd,6+c*10)=val;
  1275. if( !sd->inventory_data[i]->flag.value_notoc )
  1276. val=pc_modifysellvalue(sd,val);
  1277. WFIFOL(fd,10+c*10)=val;
  1278. c++;
  1279. }
  1280. }
  1281. WFIFOW(fd,2)=c*10+4;
  1282. WFIFOSET(fd,WFIFOW(fd,2));
  1283. return 0;
  1284. }
  1285. /*==========================================
  1286. *
  1287. *------------------------------------------*/
  1288. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1289. {
  1290. int fd = sd->fd;
  1291. int slen = strlen(mes) + 9;
  1292. WFIFOHEAD(fd, slen);
  1293. WFIFOW(fd,0)=0xb4;
  1294. WFIFOW(fd,2)=slen;
  1295. WFIFOL(fd,4)=npcid;
  1296. strcpy((char*)WFIFOP(fd,8),mes);
  1297. WFIFOSET(fd,WFIFOW(fd,2));
  1298. return 0;
  1299. }
  1300. /*==========================================
  1301. *
  1302. *------------------------------------------*/
  1303. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1304. {
  1305. int fd;
  1306. nullpo_retr(0, sd);
  1307. fd=sd->fd;
  1308. WFIFOHEAD(fd, packet_len(0xb5));
  1309. WFIFOW(fd,0)=0xb5;
  1310. WFIFOL(fd,2)=npcid;
  1311. WFIFOSET(fd,packet_len(0xb5));
  1312. return 0;
  1313. }
  1314. /*==========================================
  1315. *
  1316. *------------------------------------------*/
  1317. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1318. {
  1319. int fd;
  1320. nullpo_retr(0, sd);
  1321. fd=sd->fd;
  1322. WFIFOHEAD(fd, packet_len(0xb6));
  1323. WFIFOW(fd,0)=0xb6;
  1324. WFIFOL(fd,2)=npcid;
  1325. WFIFOSET(fd,packet_len(0xb6));
  1326. return 0;
  1327. }
  1328. /*==========================================
  1329. *
  1330. *------------------------------------------*/
  1331. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1332. {
  1333. unsigned char *buf;
  1334. int fd = sd->fd;
  1335. sd->state.using_fake_npc = 1;
  1336. WFIFOHEAD(fd, packet_len(0x78));
  1337. buf = WFIFOP(fd,0);
  1338. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1339. WBUFW(buf,0)=0x78;
  1340. #if PACKETVER >= 20071106
  1341. WBUFB(buf,2) = 0; //Unknown bit
  1342. buf = WFIFOP(fd,1);
  1343. #endif
  1344. WBUFL(buf,2)=npcid;
  1345. WBUFW(buf,14)=111;
  1346. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1347. WBUFB(buf,49)=5;
  1348. WBUFB(buf,50)=5;
  1349. WFIFOSET(fd, packet_len(0x78));
  1350. return;
  1351. }
  1352. /*==========================================
  1353. *
  1354. *------------------------------------------*/
  1355. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1356. {
  1357. int fd = sd->fd;
  1358. int slen = strlen(mes) + 8;
  1359. struct block_list *bl = NULL;
  1360. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1361. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1362. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1363. clif_sendfakenpc(sd, npcid);
  1364. WFIFOHEAD(fd, slen);
  1365. WFIFOW(fd,0)=0xb7;
  1366. WFIFOW(fd,2)=slen;
  1367. WFIFOL(fd,4)=npcid;
  1368. strcpy((char*)WFIFOP(fd,8),mes);
  1369. WFIFOSET(fd,WFIFOW(fd,2));
  1370. return 0;
  1371. }
  1372. /*==========================================
  1373. *
  1374. *------------------------------------------*/
  1375. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1376. {
  1377. int fd;
  1378. struct block_list *bl = NULL;
  1379. nullpo_retr(0, sd);
  1380. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1381. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1382. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1383. clif_sendfakenpc(sd, npcid);
  1384. fd=sd->fd;
  1385. WFIFOHEAD(fd, packet_len(0x142));
  1386. WFIFOW(fd,0)=0x142;
  1387. WFIFOL(fd,2)=npcid;
  1388. WFIFOSET(fd,packet_len(0x142));
  1389. return 0;
  1390. }
  1391. /*==========================================
  1392. *
  1393. *------------------------------------------*/
  1394. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1395. {
  1396. int fd;
  1397. struct block_list *bl = NULL;
  1398. nullpo_retr(0, sd);
  1399. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1400. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1401. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1402. clif_sendfakenpc(sd, npcid);
  1403. fd=sd->fd;
  1404. WFIFOHEAD(fd, packet_len(0x1d4));
  1405. WFIFOW(fd,0)=0x1d4;
  1406. WFIFOL(fd,2)=npcid;
  1407. WFIFOSET(fd,packet_len(0x1d4));
  1408. return 0;
  1409. }
  1410. /// npc_id is ignored in the client
  1411. /// type=2 : Remove viewpoint
  1412. /// type=other : Show viewpoint
  1413. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1414. {
  1415. int fd;
  1416. nullpo_retr(0, sd);
  1417. fd=sd->fd;
  1418. WFIFOHEAD(fd, packet_len(0x144));
  1419. WFIFOW(fd,0)=0x144;
  1420. WFIFOL(fd,2)=npc_id;
  1421. WFIFOL(fd,6)=type;
  1422. WFIFOL(fd,10)=x;
  1423. WFIFOL(fd,14)=y;
  1424. WFIFOB(fd,18)=id;
  1425. WFIFOL(fd,19)=color;
  1426. WFIFOSET(fd,packet_len(0x144));
  1427. return 0;
  1428. }
  1429. /*==========================================
  1430. *
  1431. *------------------------------------------*/
  1432. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1433. {
  1434. int fd;
  1435. nullpo_retr(0, sd);
  1436. fd=sd->fd;
  1437. WFIFOHEAD(fd, packet_len(0x1b3));
  1438. WFIFOW(fd,0)=0x1b3;
  1439. strncpy((char*)WFIFOP(fd,2),image,64);
  1440. WFIFOB(fd,66)=type;
  1441. WFIFOSET(fd,packet_len(0x1b3));
  1442. return 0;
  1443. }
  1444. /*==========================================
  1445. * Fills in card data from the given item and into the buffer. [Skotlex]
  1446. *------------------------------------------*/
  1447. static void clif_addcards(unsigned char* buf, struct item* item)
  1448. {
  1449. int i=0,j;
  1450. if( item == NULL ) { //Blank data
  1451. WBUFW(buf,0) = 0;
  1452. WBUFW(buf,2) = 0;
  1453. WBUFW(buf,4) = 0;
  1454. WBUFW(buf,6) = 0;
  1455. return;
  1456. }
  1457. if( item->card[0] == CARD0_PET ) { //pet eggs
  1458. WBUFW(buf,0) = 0;
  1459. WBUFW(buf,2) = 0;
  1460. WBUFW(buf,4) = 0;
  1461. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1462. return;
  1463. }
  1464. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1465. WBUFW(buf,0) = item->card[0];
  1466. WBUFW(buf,2) = item->card[1];
  1467. WBUFW(buf,4) = item->card[2];
  1468. WBUFW(buf,6) = item->card[3];
  1469. return;
  1470. }
  1471. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1472. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1473. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1474. //Normal items.
  1475. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1476. WBUFW(buf,0) = j;
  1477. else
  1478. WBUFW(buf,0) = item->card[i];
  1479. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1480. WBUFW(buf,2) = j;
  1481. else
  1482. WBUFW(buf,2) = item->card[i];
  1483. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1484. WBUFW(buf,4) = j;
  1485. else
  1486. WBUFW(buf,4) = item->card[i];
  1487. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1488. WBUFW(buf,6) = j;
  1489. else
  1490. WBUFW(buf,6) = item->card[i];
  1491. }
  1492. /*==========================================
  1493. *
  1494. *------------------------------------------*/
  1495. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1496. {
  1497. int fd;
  1498. nullpo_retr(0, sd);
  1499. fd = sd->fd;
  1500. if (!session_isActive(fd)) //Sasuke-
  1501. return 0;
  1502. WFIFOHEAD(fd,packet_len(0xa0));
  1503. if(fail) {
  1504. WFIFOW(fd,0)=0xa0;
  1505. WFIFOW(fd,2)=n+2;
  1506. WFIFOW(fd,4)=amount;
  1507. WFIFOW(fd,6)=0;
  1508. WFIFOB(fd,8)=0;
  1509. WFIFOB(fd,9)=0;
  1510. WFIFOB(fd,10)=0;
  1511. WFIFOW(fd,11)=0;
  1512. WFIFOW(fd,13)=0;
  1513. WFIFOW(fd,15)=0;
  1514. WFIFOW(fd,17)=0;
  1515. WFIFOW(fd,19)=0;
  1516. WFIFOB(fd,21)=0;
  1517. WFIFOB(fd,22)=fail;
  1518. } else {
  1519. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1520. return 1;
  1521. WFIFOW(fd,0)=0xa0;
  1522. WFIFOW(fd,2)=n+2;
  1523. WFIFOW(fd,4)=amount;
  1524. if (sd->inventory_data[n]->view_id > 0)
  1525. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1526. else
  1527. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1528. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1529. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1530. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1531. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1532. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1533. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1534. WFIFOB(fd,22)=fail;
  1535. }
  1536. WFIFOSET(fd,packet_len(0xa0));
  1537. return 0;
  1538. }
  1539. /*==========================================
  1540. *
  1541. *------------------------------------------*/
  1542. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1543. {
  1544. int fd;
  1545. nullpo_retr(0, sd);
  1546. fd=sd->fd;
  1547. WFIFOHEAD(fd, packet_len(0xaf));
  1548. WFIFOW(fd,0)=0xaf;
  1549. WFIFOW(fd,2)=n+2;
  1550. WFIFOW(fd,4)=amount;
  1551. WFIFOSET(fd,packet_len(0xaf));
  1552. return 0;
  1553. }
  1554. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1555. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1556. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1557. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1558. {
  1559. if (id->view_id > 0)
  1560. WBUFW(buf,n)=id->view_id;
  1561. else
  1562. WBUFW(buf,n)=i->nameid;
  1563. WBUFB(buf,n+2)=itemtype(id->type);
  1564. WBUFB(buf,n+3)=i->identify;
  1565. if (equip >= 0) { //Equippable item
  1566. WBUFW(buf,n+4)=equip;
  1567. WBUFW(buf,n+6)=i->equip;
  1568. WBUFB(buf,n+8)=i->attribute;
  1569. WBUFB(buf,n+9)=i->refine;
  1570. } else { //Stackable item.
  1571. WBUFW(buf,n+4)=i->amount;
  1572. if (equip == -2 && id->equip == EQP_AMMO)
  1573. WBUFW(buf,n+6)=EQP_AMMO;
  1574. else
  1575. WBUFW(buf,n+6)=0;
  1576. }
  1577. }
  1578. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1579. void clif_inventorylist(struct map_session_data *sd)
  1580. {
  1581. int i,n,ne,fd = sd->fd,arrow=-1;
  1582. unsigned char *buf;
  1583. unsigned char bufe[MAX_INVENTORY*20+4];
  1584. #if PACKETVER < 5
  1585. const int s = 10; //Entry size.
  1586. #else
  1587. const int s = 18;
  1588. #endif
  1589. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1590. buf = WFIFOP(fd,0);
  1591. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1592. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1593. continue;
  1594. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1595. { //Non-stackable (Equippable)
  1596. WBUFW(bufe,ne*20+4)=i+2;
  1597. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1598. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1599. ne++;
  1600. } else { //Stackable.
  1601. WBUFW(buf,n*s+4)=i+2;
  1602. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1603. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1604. sd->status.inventory[i].equip)
  1605. arrow=i;
  1606. #if PACKETVER >= 5
  1607. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1608. #endif
  1609. n++;
  1610. }
  1611. }
  1612. if (n) {
  1613. #if PACKETVER < 5
  1614. WBUFW(buf,0)=0xa3;
  1615. #else
  1616. WBUFW(buf,0)=0x1ee;
  1617. #endif
  1618. WBUFW(buf,2)=4+n*s;
  1619. WFIFOSET(fd,WFIFOW(fd,2));
  1620. }
  1621. if(arrow >= 0)
  1622. clif_arrowequip(sd,arrow);
  1623. if(ne){
  1624. WBUFW(bufe,0)=0xa4;
  1625. WBUFW(bufe,2)=4+ne*20;
  1626. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1627. }
  1628. }
  1629. //Required when items break/get-repaired. Only sends equippable item list.
  1630. void clif_equiplist(struct map_session_data *sd)
  1631. {
  1632. int i,n,fd = sd->fd;
  1633. unsigned char *buf;
  1634. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1635. buf = WFIFOP(fd,0);
  1636. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1637. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1638. continue;
  1639. if(itemdb_isstackable2(sd->inventory_data[i]))
  1640. continue;
  1641. //Equippable
  1642. WBUFW(buf,n*20+4)=i+2;
  1643. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1644. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1645. n++;
  1646. }
  1647. if (n) {
  1648. WBUFW(buf,0)=0xa4;
  1649. WBUFW(buf,2)=4+n*20;
  1650. WFIFOSET(fd,WFIFOW(fd,2));
  1651. }
  1652. }
  1653. void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
  1654. {
  1655. struct item_data *id;
  1656. int i,n,ne,fd=sd->fd;
  1657. unsigned char *buf;
  1658. unsigned char bufe[MAX_STORAGE*20+4];
  1659. #if PACKETVER < 5
  1660. const int s = 10; //Entry size.
  1661. #else
  1662. const int s = 18;
  1663. #endif
  1664. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1665. buf = WFIFOP(fd,0);
  1666. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1667. if(stor->items[i].nameid<=0)
  1668. continue;
  1669. id = itemdb_search(stor->items[i].nameid);
  1670. if(!itemdb_isstackable2(id))
  1671. { //Equippable
  1672. WBUFW(bufe,ne*20+4)=i+1;
  1673. clif_item_sub(bufe, ne*20+6, &stor->items[i], id, id->equip);
  1674. clif_addcards(WBUFP(bufe, ne*20+16), &stor->items[i]);
  1675. ne++;
  1676. } else { //Stackable
  1677. WBUFW(buf,n*s+4)=i+1;
  1678. clif_item_sub(buf, n*s+6, &stor->items[i], id,-1);
  1679. #if PACKETVER >= 5
  1680. clif_addcards(WBUFP(buf,n*s+14), &stor->items[i]);
  1681. #endif
  1682. n++;
  1683. }
  1684. }
  1685. if(n){
  1686. #if PACKETVER < 5
  1687. WBUFW(buf,0)=0xa5;
  1688. #else
  1689. WBUFW(buf,0)=0x1f0;
  1690. #endif
  1691. WBUFW(buf,2)=4+n*s;
  1692. WFIFOSET(fd,WFIFOW(fd,2));
  1693. }
  1694. if(ne){
  1695. WBUFW(bufe,0)=0xa6;
  1696. WBUFW(bufe,2)=4+ne*20;
  1697. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1698. }
  1699. }
  1700. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1701. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1702. {
  1703. struct item_data *id;
  1704. int i,n,ne,fd=sd->fd;
  1705. unsigned char *buf;
  1706. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1707. #if PACKETVER < 5
  1708. const int s = 10; //Entry size.
  1709. #else
  1710. const int s = 18;
  1711. #endif
  1712. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1713. buf = WFIFOP(fd,0);
  1714. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1715. if(stor->storage_[i].nameid<=0)
  1716. continue;
  1717. id = itemdb_search(stor->storage_[i].nameid);
  1718. if(!itemdb_isstackable2(id))
  1719. { //Equippable
  1720. WBUFW(bufe,ne*20+4)=i+1;
  1721. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1722. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1723. ne++;
  1724. } else { //Stackable
  1725. WBUFW(buf,n*s+4)=i+1;
  1726. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1727. #if PACKETVER >= 5
  1728. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1729. #endif
  1730. n++;
  1731. }
  1732. }
  1733. if(n){
  1734. #if PACKETVER < 5
  1735. WBUFW(buf,0)=0xa5;
  1736. #else
  1737. WBUFW(buf,0)=0x1f0;
  1738. #endif
  1739. WBUFW(buf,2)=4+n*s;
  1740. WFIFOSET(fd,WFIFOW(fd,2));
  1741. }
  1742. if(ne){
  1743. WBUFW(bufe,0)=0xa6;
  1744. WBUFW(bufe,2)=4+ne*20;
  1745. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1746. }
  1747. }
  1748. void clif_cartlist(struct map_session_data *sd)
  1749. {
  1750. struct item_data *id;
  1751. int i,n,ne,fd=sd->fd;
  1752. unsigned char *buf;
  1753. unsigned char bufe[MAX_CART*20+4];
  1754. #if PACKETVER < 5
  1755. const int s = 10; //Entry size.
  1756. #else
  1757. const int s = 18;
  1758. #endif
  1759. WFIFOHEAD(fd, MAX_CART * s + 4);
  1760. buf = WFIFOP(fd,0);
  1761. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1762. if(sd->status.cart[i].nameid<=0)
  1763. continue;
  1764. id = itemdb_search(sd->status.cart[i].nameid);
  1765. if(!itemdb_isstackable2(id))
  1766. { //Equippable
  1767. WBUFW(bufe,ne*20+4)=i+2;
  1768. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1769. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1770. ne++;
  1771. } else { //Stackable
  1772. WBUFW(buf,n*s+4)=i+2;
  1773. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1774. #if PACKETVER >= 5
  1775. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1776. #endif
  1777. n++;
  1778. }
  1779. }
  1780. if(n){
  1781. #if PACKETVER < 5
  1782. WBUFW(buf,0)=0x123;
  1783. #else
  1784. WBUFW(buf,0)=0x1ef;
  1785. #endif
  1786. WBUFW(buf,2)=4+n*s;
  1787. WFIFOSET(fd,WFIFOW(fd,2));
  1788. }
  1789. if(ne){
  1790. WBUFW(bufe,0)=0x122;
  1791. WBUFW(bufe,2)=4+ne*20;
  1792. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1793. }
  1794. return;
  1795. }
  1796. /// Client behaviour:
  1797. /// Closes the cart storage and removes all it's items from memory.
  1798. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1799. void clif_clearcart(int fd)
  1800. {
  1801. WFIFOHEAD(fd, packet_len(0x12b));
  1802. WFIFOW(fd,0) = 0x12b;
  1803. }
  1804. // Guild XY locators [Valaris]
  1805. int clif_guild_xy(struct map_session_data *sd)
  1806. {
  1807. unsigned char buf[10];
  1808. nullpo_retr(0, sd);
  1809. WBUFW(buf,0)=0x1eb;
  1810. WBUFL(buf,2)=sd->status.account_id;
  1811. WBUFW(buf,6)=sd->bl.x;
  1812. WBUFW(buf,8)=sd->bl.y;
  1813. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1814. return 0;
  1815. }
  1816. /*==========================================
  1817. * Sends x/y dot to a single fd. [Skotlex]
  1818. *------------------------------------------*/
  1819. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1820. {
  1821. WFIFOHEAD(fd,packet_len(0x1eb));
  1822. WFIFOW(fd,0)=0x1eb;
  1823. WFIFOL(fd,2)=sd->status.account_id;
  1824. WFIFOW(fd,6)=sd->bl.x;
  1825. WFIFOW(fd,8)=sd->bl.y;
  1826. WFIFOSET(fd,packet_len(0x1eb));
  1827. return 0;
  1828. }
  1829. // Guild XY locators [Valaris]
  1830. int clif_guild_xy_remove(struct map_session_data *sd)
  1831. {
  1832. unsigned char buf[10];
  1833. nullpo_retr(0, sd);
  1834. WBUFW(buf,0)=0x1eb;
  1835. WBUFL(buf,2)=sd->status.account_id;
  1836. WBUFW(buf,6)=-1;
  1837. WBUFW(buf,8)=-1;
  1838. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1839. return 0;
  1840. }
  1841. /*==========================================
  1842. * ステータスを送りつける
  1843. * 表示専用数字はこの中で計算して送る
  1844. *------------------------------------------*/
  1845. int clif_updatestatus(struct map_session_data *sd,int type)
  1846. {
  1847. int fd,len=8;
  1848. nullpo_retr(0, sd);
  1849. fd=sd->fd;
  1850. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1851. return 0;
  1852. WFIFOHEAD(fd, 14);
  1853. WFIFOW(fd,0)=0xb0;
  1854. WFIFOW(fd,2)=type;
  1855. switch(type){
  1856. // 00b0
  1857. case SP_WEIGHT:
  1858. pc_updateweightstatus(sd);
  1859. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1860. WFIFOW(fd,2)=type;
  1861. WFIFOL(fd,4)=sd->weight;
  1862. break;
  1863. case SP_MAXWEIGHT:
  1864. WFIFOL(fd,4)=sd->max_weight;
  1865. break;
  1866. case SP_SPEED:
  1867. WFIFOL(fd,4)=sd->battle_status.speed;
  1868. break;
  1869. case SP_BASELEVEL:
  1870. WFIFOL(fd,4)=sd->status.base_level;
  1871. break;
  1872. case SP_JOBLEVEL:
  1873. WFIFOL(fd,4)=sd->status.job_level;
  1874. break;
  1875. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1876. WFIFOL(fd,4)=sd->status.karma;
  1877. break;
  1878. case SP_MANNER:
  1879. WFIFOL(fd,4)=sd->status.manner;
  1880. break;
  1881. case SP_STATUSPOINT:
  1882. WFIFOL(fd,4)=sd->status.status_point;
  1883. break;
  1884. case SP_SKILLPOINT:
  1885. WFIFOL(fd,4)=sd->status.skill_point;
  1886. break;
  1887. case SP_HIT:
  1888. WFIFOL(fd,4)=sd->battle_status.hit;
  1889. break;
  1890. case SP_FLEE1:
  1891. WFIFOL(fd,4)=sd->battle_status.flee;
  1892. break;
  1893. case SP_FLEE2:
  1894. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1895. break;
  1896. case SP_MAXHP:
  1897. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1898. break;
  1899. case SP_MAXSP:
  1900. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1901. break;
  1902. case SP_HP:
  1903. WFIFOL(fd,4)=sd->battle_status.hp;
  1904. if (battle_config.disp_hpmeter)
  1905. clif_hpmeter(sd);
  1906. if (!battle_config.party_hp_mode && sd->status.party_id)
  1907. clif_party_hp(sd);
  1908. break;
  1909. case SP_SP:
  1910. WFIFOL(fd,4)=sd->battle_status.sp;
  1911. break;
  1912. case SP_ASPD:
  1913. WFIFOL(fd,4)=sd->battle_status.amotion;
  1914. break;
  1915. case SP_ATK1:
  1916. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1917. break;
  1918. case SP_DEF1:
  1919. WFIFOL(fd,4)=sd->battle_status.def;
  1920. break;
  1921. case SP_MDEF1:
  1922. WFIFOL(fd,4)=sd->battle_status.mdef;
  1923. break;
  1924. case SP_ATK2:
  1925. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1926. break;
  1927. case SP_DEF2:
  1928. WFIFOL(fd,4)=sd->battle_status.def2;
  1929. break;
  1930. case SP_MDEF2:
  1931. //negative check (in case you have something like Berserk active)
  1932. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1933. if (len < 0) len = 0;
  1934. WFIFOL(fd,4)= len;
  1935. len = 8;
  1936. break;
  1937. case SP_CRITICAL:
  1938. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1939. break;
  1940. case SP_MATK1:
  1941. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1942. break;
  1943. case SP_MATK2:
  1944. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1945. break;
  1946. case SP_ZENY:
  1947. WFIFOW(fd,0)=0xb1;
  1948. WFIFOL(fd,4)=sd->status.zeny;
  1949. break;
  1950. case SP_BASEEXP:
  1951. WFIFOW(fd,0)=0xb1;
  1952. WFIFOL(fd,4)=sd->status.base_exp;
  1953. break;
  1954. case SP_JOBEXP:
  1955. WFIFOW(fd,0)=0xb1;
  1956. WFIFOL(fd,4)=sd->status.job_exp;
  1957. break;
  1958. case SP_NEXTBASEEXP:
  1959. WFIFOW(fd,0)=0xb1;
  1960. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  1961. break;
  1962. case SP_NEXTJOBEXP:
  1963. WFIFOW(fd,0)=0xb1;
  1964. WFIFOL(fd,4)=pc_nextjobexp(sd);
  1965. break;
  1966. // 00be 終了
  1967. case SP_USTR:
  1968. case SP_UAGI:
  1969. case SP_UVIT:
  1970. case SP_UINT:
  1971. case SP_UDEX:
  1972. case SP_ULUK:
  1973. WFIFOW(fd,0)=0xbe;
  1974. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  1975. len=5;
  1976. break;
  1977. // 013a 終了
  1978. case SP_ATTACKRANGE:
  1979. WFIFOW(fd,0)=0x13a;
  1980. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  1981. len=4;
  1982. break;
  1983. // 0141 終了
  1984. case SP_STR:
  1985. WFIFOW(fd,0)=0x141;
  1986. WFIFOL(fd,2)=type;
  1987. WFIFOL(fd,6)=sd->status.str;
  1988. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  1989. len=14;
  1990. break;
  1991. case SP_AGI:
  1992. WFIFOW(fd,0)=0x141;
  1993. WFIFOL(fd,2)=type;
  1994. WFIFOL(fd,6)=sd->status.agi;
  1995. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  1996. len=14;
  1997. break;
  1998. case SP_VIT:
  1999. WFIFOW(fd,0)=0x141;
  2000. WFIFOL(fd,2)=type;
  2001. WFIFOL(fd,6)=sd->status.vit;
  2002. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2003. len=14;
  2004. break;
  2005. case SP_INT:
  2006. WFIFOW(fd,0)=0x141;
  2007. WFIFOL(fd,2)=type;
  2008. WFIFOL(fd,6)=sd->status.int_;
  2009. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2010. len=14;
  2011. break;
  2012. case SP_DEX:
  2013. WFIFOW(fd,0)=0x141;
  2014. WFIFOL(fd,2)=type;
  2015. WFIFOL(fd,6)=sd->status.dex;
  2016. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2017. len=14;
  2018. break;
  2019. case SP_LUK:
  2020. WFIFOW(fd,0)=0x141;
  2021. WFIFOL(fd,2)=type;
  2022. WFIFOL(fd,6)=sd->status.luk;
  2023. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2024. len=14;
  2025. break;
  2026. case SP_CARTINFO:
  2027. WFIFOW(fd,0)=0x121;
  2028. WFIFOW(fd,2)=sd->cart_num;
  2029. WFIFOW(fd,4)=MAX_CART;
  2030. WFIFOL(fd,6)=sd->cart_weight;
  2031. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2032. len=14;
  2033. break;
  2034. default:
  2035. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2036. return 1;
  2037. }
  2038. WFIFOSET(fd,len);
  2039. return 0;
  2040. }
  2041. int clif_changestatus(struct block_list *bl,int type,int val)
  2042. {
  2043. unsigned char buf[12];
  2044. struct map_session_data *sd = NULL;
  2045. nullpo_retr(0, bl);
  2046. if(bl->type == BL_PC)
  2047. sd = (struct map_session_data *)bl;
  2048. if(sd){
  2049. WBUFW(buf,0)=0x1ab;
  2050. WBUFL(buf,2)=bl->id;
  2051. WBUFW(buf,6)=type;
  2052. switch(type){
  2053. case SP_MANNER:
  2054. WBUFL(buf,8)=val;
  2055. break;
  2056. default:
  2057. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2058. return 1;
  2059. }
  2060. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2061. }
  2062. return 0;
  2063. }
  2064. /*==========================================
  2065. *
  2066. *------------------------------------------*/
  2067. void clif_changelook(struct block_list *bl,int type,int val)
  2068. {
  2069. unsigned char buf[16];
  2070. struct map_session_data* sd = NULL;
  2071. struct status_change* sc;
  2072. struct view_data* vd;
  2073. enum send_target target = AREA;
  2074. nullpo_retv(bl);
  2075. sd = BL_CAST(BL_PC, bl);
  2076. sc = status_get_sc(bl);
  2077. vd = status_get_viewdata(bl);
  2078. //nullpo_ret(vd);
  2079. if( vd ) //temp hack to let Warp Portal change appearance
  2080. switch(type)
  2081. {
  2082. case LOOK_WEAPON:
  2083. if (sd)
  2084. {
  2085. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2086. val = vd->weapon;
  2087. }
  2088. else vd->weapon = val;
  2089. break;
  2090. case LOOK_SHIELD:
  2091. if (sd)
  2092. {
  2093. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2094. val = vd->shield;
  2095. }
  2096. else vd->shield = val;
  2097. break;
  2098. case LOOK_BASE:
  2099. vd->class_ = val;
  2100. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2101. vd->weapon = vd->shield = 0;
  2102. if (vd->cloth_color && (
  2103. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2104. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2105. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2106. ))
  2107. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2108. break;
  2109. case LOOK_HAIR:
  2110. vd->hair_style = val;
  2111. break;
  2112. case LOOK_HEAD_BOTTOM:
  2113. vd->head_bottom = val;
  2114. break;
  2115. case LOOK_HEAD_TOP:
  2116. vd->head_top = val;
  2117. break;
  2118. case LOOK_HEAD_MID:
  2119. vd->head_mid = val;
  2120. break;
  2121. case LOOK_HAIR_COLOR:
  2122. vd->hair_color = val;
  2123. break;
  2124. case LOOK_CLOTHES_COLOR:
  2125. if (val && (
  2126. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2127. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2128. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2129. ))
  2130. val = 0;
  2131. vd->cloth_color = val;
  2132. break;
  2133. case LOOK_SHOES:
  2134. #if PACKETVER > 3
  2135. if (sd) {
  2136. int n;
  2137. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2138. if(sd->inventory_data[n]->view_id > 0)
  2139. val = sd->inventory_data[n]->view_id;
  2140. else
  2141. val = sd->status.inventory[n].nameid;
  2142. }
  2143. val = 0;
  2144. }
  2145. #endif
  2146. //Shoes? No packet uses this....
  2147. break;
  2148. }
  2149. // prevent leaking the presence of GM-hidden objects
  2150. if( sc && sc->option&OPTION_INVISIBLE )
  2151. target = SELF;
  2152. #if PACKETVER < 4
  2153. WBUFW(buf,0)=0xc3;
  2154. WBUFL(buf,2)=bl->id;
  2155. WBUFB(buf,6)=type;
  2156. WBUFB(buf,7)=val;
  2157. clif_send(buf,packet_len(0xc3),bl,target);
  2158. #else
  2159. WBUFW(buf,0)=0x1d7;
  2160. WBUFL(buf,2)=bl->id;
  2161. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2162. WBUFB(buf,6)=LOOK_WEAPON;
  2163. WBUFW(buf,7)=vd->weapon;
  2164. WBUFW(buf,9)=vd->shield;
  2165. } else {
  2166. WBUFB(buf,6)=type;
  2167. WBUFW(buf,7)=val;
  2168. WBUFW(buf,9)=0;
  2169. }
  2170. clif_send(buf,packet_len(0x1d7),bl,target);
  2171. #endif
  2172. }
  2173. //Sends a change-base-look packet required for traps as they are triggered.
  2174. void clif_changetraplook(struct block_list *bl,int val)
  2175. {
  2176. unsigned char buf[32];
  2177. #if PACKETVER < 4
  2178. WBUFW(buf,0)=0xc3;
  2179. WBUFL(buf,2)=bl->id;
  2180. WBUFB(buf,6)=LOOK_BASE;
  2181. WBUFB(buf,7)=val;
  2182. clif_send(buf,packet_len(0xc3),bl,AREA);
  2183. #else
  2184. WBUFW(buf,0)=0x1d7;
  2185. WBUFL(buf,2)=bl->id;
  2186. WBUFB(buf,6)=LOOK_BASE;
  2187. WBUFW(buf,7)=val;
  2188. WBUFW(buf,9)=0;
  2189. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2190. #endif
  2191. }
  2192. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2193. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2194. {
  2195. unsigned char buf[32];
  2196. #if PACKETVER < 4
  2197. WBUFW(buf,0)=0xc3;
  2198. WBUFL(buf,2)=id;
  2199. WBUFB(buf,6)=type;
  2200. WBUFB(buf,7)=val;
  2201. clif_send(buf,packet_len(0xc3),bl,target);
  2202. #else
  2203. WBUFW(buf,0)=0x1d7;
  2204. WBUFL(buf,2)=id;
  2205. WBUFB(buf,6)=type;
  2206. WBUFW(buf,7)=val;
  2207. WBUFW(buf,9)=0;
  2208. clif_send(buf,packet_len(0x1d7),bl,target);
  2209. #endif
  2210. return;
  2211. }
  2212. /*==========================================
  2213. *
  2214. *------------------------------------------*/
  2215. int clif_initialstatus(struct map_session_data *sd)
  2216. {
  2217. int fd;
  2218. unsigned char *buf;
  2219. nullpo_retr(0, sd);
  2220. fd=sd->fd;
  2221. WFIFOHEAD(fd,packet_len(0xbd));
  2222. buf=WFIFOP(fd,0);
  2223. WBUFW(buf,0)=0xbd;
  2224. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2225. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2226. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2227. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2228. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2229. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2230. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2231. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2232. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2233. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2234. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2235. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2236. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2237. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2238. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2239. WBUFW(buf,20) = sd->battle_status.matk_max;
  2240. WBUFW(buf,22) = sd->battle_status.matk_min;
  2241. WBUFW(buf,24) = sd->battle_status.def; // def
  2242. WBUFW(buf,26) = sd->battle_status.def2;
  2243. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2244. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2245. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2246. WBUFW(buf,30) = fd;
  2247. fd = sd->fd;
  2248. WBUFW(buf,32) = sd->battle_status.hit;
  2249. WBUFW(buf,34) = sd->battle_status.flee;
  2250. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2251. WBUFW(buf,38) = sd->battle_status.cri/10;
  2252. WBUFW(buf,40) = sd->status.karma;
  2253. WBUFW(buf,42) = sd->status.manner;
  2254. WFIFOSET(fd,packet_len(0xbd));
  2255. clif_updatestatus(sd,SP_STR);
  2256. clif_updatestatus(sd,SP_AGI);
  2257. clif_updatestatus(sd,SP_VIT);
  2258. clif_updatestatus(sd,SP_INT);
  2259. clif_updatestatus(sd,SP_DEX);
  2260. clif_updatestatus(sd,SP_LUK);
  2261. clif_updatestatus(sd,SP_ATTACKRANGE);
  2262. clif_updatestatus(sd,SP_ASPD);
  2263. return 0;
  2264. }
  2265. /*==========================================
  2266. *矢装備
  2267. *------------------------------------------*/
  2268. int clif_arrowequip(struct map_session_data *sd,int val)
  2269. {
  2270. int fd;
  2271. nullpo_retr(0, sd);
  2272. pc_stop_attack(sd); // [Valaris]
  2273. fd=sd->fd;
  2274. WFIFOHEAD(fd, packet_len(0x013c));
  2275. WFIFOW(fd,0)=0x013c;
  2276. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2277. WFIFOSET(fd,packet_len(0x013c));
  2278. return 0;
  2279. }
  2280. /// Ammunition action message.
  2281. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2282. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2283. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2284. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2285. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2286. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2287. int clif_arrow_fail(struct map_session_data *sd,int type)
  2288. {
  2289. int fd;
  2290. nullpo_retr(0, sd);
  2291. fd=sd->fd;
  2292. WFIFOHEAD(fd, packet_len(0x013b));
  2293. WFIFOW(fd,0)=0x013b;
  2294. WFIFOW(fd,2)=type;
  2295. WFIFOSET(fd,packet_len(0x013b));
  2296. return 0;
  2297. }
  2298. /*==========================================
  2299. * 作成可能 矢リスト送信
  2300. *------------------------------------------*/
  2301. int clif_arrow_create_list(struct map_session_data *sd)
  2302. {
  2303. int i, c, j;
  2304. int fd;
  2305. nullpo_retr(0, sd);
  2306. fd = sd->fd;
  2307. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2308. WFIFOW(fd,0) = 0x1ad;
  2309. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2310. if (skill_arrow_db[i].nameid > 0 &&
  2311. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2312. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2313. {
  2314. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2315. WFIFOW(fd,c*2+4) = j;
  2316. else
  2317. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2318. c++;
  2319. }
  2320. }
  2321. WFIFOW(fd,2) = c*2+4;
  2322. WFIFOSET(fd, WFIFOW(fd,2));
  2323. if (c > 0) {
  2324. sd->menuskill_id = AC_MAKINGARROW;
  2325. sd->menuskill_val = c;
  2326. }
  2327. return 0;
  2328. }
  2329. /*==========================================
  2330. *
  2331. *------------------------------------------*/
  2332. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2333. {
  2334. int fd;
  2335. nullpo_retr(0, sd);
  2336. fd=sd->fd;
  2337. WFIFOHEAD(fd,packet_len(0xbc));
  2338. WFIFOW(fd,0)=0xbc;
  2339. WFIFOW(fd,2)=type;
  2340. WFIFOB(fd,4)=ok;
  2341. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2342. WFIFOSET(fd,packet_len(0xbc));
  2343. return 0;
  2344. }
  2345. /*==========================================
  2346. *
  2347. *------------------------------------------*/
  2348. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2349. {
  2350. int fd;
  2351. nullpo_retr(0, sd);
  2352. fd=sd->fd;
  2353. WFIFOHEAD(fd,packet_len(0xaa));
  2354. WFIFOW(fd,0)=0xaa;
  2355. WFIFOW(fd,2)=n+2;
  2356. WFIFOW(fd,4)=pos;
  2357. WFIFOB(fd,6)=ok;
  2358. WFIFOSET(fd,packet_len(0xaa));
  2359. return 0;
  2360. }
  2361. /*==========================================
  2362. *
  2363. *------------------------------------------*/
  2364. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2365. {
  2366. int fd;
  2367. nullpo_retr(0, sd);
  2368. fd=sd->fd;
  2369. WFIFOHEAD(fd,packet_len(0xac));
  2370. WFIFOW(fd,0)=0xac;
  2371. WFIFOW(fd,2)=n+2;
  2372. WFIFOW(fd,4)=pos;
  2373. WFIFOB(fd,6)=ok;
  2374. WFIFOSET(fd,packet_len(0xac));
  2375. return 0;
  2376. }
  2377. /*==========================================
  2378. *
  2379. *------------------------------------------*/
  2380. int clif_misceffect(struct block_list* bl,int type)
  2381. {
  2382. unsigned char buf[32];
  2383. nullpo_retr(0, bl);
  2384. WBUFW(buf,0) = 0x19b;
  2385. WBUFL(buf,2) = bl->id;
  2386. WBUFL(buf,6) = type;
  2387. clif_send(buf,packet_len(0x19b),bl,AREA);
  2388. return 0;
  2389. }
  2390. int clif_misceffect2(struct block_list *bl, int type)
  2391. {
  2392. unsigned char buf[24];
  2393. nullpo_retr(0, bl);
  2394. memset(buf, 0, packet_len(0x1f3));
  2395. WBUFW(buf,0) = 0x1f3;
  2396. WBUFL(buf,2) = bl->id;
  2397. WBUFL(buf,6) = type;
  2398. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2399. return 0;
  2400. }
  2401. /*==========================================
  2402. * 表示オプション変更
  2403. *------------------------------------------*/
  2404. int clif_changeoption(struct block_list* bl)
  2405. {
  2406. unsigned char buf[32];
  2407. struct status_change *sc;
  2408. nullpo_retr(0, bl);
  2409. sc = status_get_sc(bl);
  2410. if (!sc) return 0; //How can an option change if there's no sc?
  2411. #if PACKETVER >= 7
  2412. WBUFW(buf,0) = 0x229;
  2413. WBUFL(buf,2) = bl->id;
  2414. WBUFW(buf,6) = sc->opt1;
  2415. WBUFW(buf,8) = sc->opt2;
  2416. WBUFL(buf,10) = sc->option;
  2417. WBUFB(buf,14) = 0; // PK???
  2418. if(disguised(bl)) {
  2419. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2420. WBUFL(buf,2) = -bl->id;
  2421. clif_send(buf,packet_len(0x229),bl,SELF);
  2422. WBUFL(buf,2) = bl->id;
  2423. WBUFL(buf,10) = OPTION_INVISIBLE;
  2424. clif_send(buf,packet_len(0x229),bl,SELF);
  2425. } else
  2426. clif_send(buf,packet_len(0x229),bl,AREA);
  2427. #else
  2428. WBUFW(buf,0) = 0x119;
  2429. WBUFL(buf,2) = bl->id;
  2430. WBUFW(buf,6) = sc->opt1;
  2431. WBUFW(buf,8) = sc->opt2;
  2432. WBUFW(buf,10) = sc->option;
  2433. WBUFB(buf,12) = 0; // ??
  2434. if(disguised(bl)) {
  2435. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2436. WBUFL(buf,2) = -bl->id;
  2437. clif_send(buf,packet_len(0x119),bl,SELF);
  2438. WBUFL(buf,2) = bl->id;
  2439. WBUFW(buf,10) = OPTION_INVISIBLE;
  2440. clif_send(buf,packet_len(0x119),bl,SELF);
  2441. } else
  2442. clif_send(buf,packet_len(0x119),bl,AREA);
  2443. #endif
  2444. return 0;
  2445. }
  2446. int clif_changeoption2(struct block_list* bl)
  2447. {
  2448. unsigned char buf[20];
  2449. struct status_change *sc;
  2450. sc = status_get_sc(bl);
  2451. if (!sc) return 0; //How can an option change if there's no sc?
  2452. WBUFW(buf,0) = 0x28a;
  2453. WBUFL(buf,2) = bl->id;
  2454. WBUFL(buf,6) = sc->option;
  2455. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2456. WBUFL(buf,14) = sc->opt3;
  2457. if(disguised(bl)) {
  2458. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2459. WBUFL(buf,2) = -bl->id;
  2460. clif_send(buf,packet_len(0x28a),bl,SELF);
  2461. WBUFL(buf,2) = bl->id;
  2462. WBUFL(buf,6) = OPTION_INVISIBLE;
  2463. clif_send(buf,packet_len(0x28a),bl,SELF);
  2464. } else
  2465. clif_send(buf,packet_len(0x28a),bl,AREA);
  2466. return 0;
  2467. }
  2468. /*==========================================
  2469. *
  2470. *------------------------------------------*/
  2471. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2472. {
  2473. nullpo_retr(0, sd);
  2474. if(!ok) {
  2475. int fd=sd->fd;
  2476. WFIFOHEAD(fd,packet_len(0xa8));
  2477. WFIFOW(fd,0)=0xa8;
  2478. WFIFOW(fd,2)=index+2;
  2479. WFIFOW(fd,4)=amount;
  2480. WFIFOB(fd,6)=ok;
  2481. WFIFOSET(fd,packet_len(0xa8));
  2482. }
  2483. else {
  2484. #if PACKETVER < 3
  2485. int fd=sd->fd;
  2486. WFIFOHEAD(fd,packet_len(0xa8));
  2487. WFIFOW(fd,0)=0xa8;
  2488. WFIFOW(fd,2)=index+2;
  2489. WFIFOW(fd,4)=amount;
  2490. WFIFOB(fd,6)=ok;
  2491. WFIFOSET(fd,packet_len(0xa8));
  2492. #else
  2493. unsigned char buf[32];
  2494. WBUFW(buf,0)=0x1c8;
  2495. WBUFW(buf,2)=index+2;
  2496. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2497. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2498. else
  2499. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2500. WBUFL(buf,6)=sd->bl.id;
  2501. WBUFW(buf,10)=amount;
  2502. WBUFB(buf,12)=ok;
  2503. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2504. #endif
  2505. }
  2506. return 0;
  2507. }
  2508. /*==========================================
  2509. * Inform client whether chatroom creation was successful or not
  2510. * R 00d6 <fail>.B
  2511. *------------------------------------------*/
  2512. void clif_createchat(struct map_session_data* sd, int fail)
  2513. {
  2514. int fd;
  2515. nullpo_retv(sd);
  2516. fd = sd->fd;
  2517. WFIFOHEAD(fd,packet_len(0xd6));
  2518. WFIFOW(fd,0) = 0xd6;
  2519. WFIFOB(fd,2) = fail;
  2520. WFIFOSET(fd,packet_len(0xd6));
  2521. }
  2522. /*==========================================
  2523. * Display a chat above the owner
  2524. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2525. *------------------------------------------*/
  2526. int clif_dispchat(struct chat_data* cd, int fd)
  2527. {
  2528. unsigned char buf[128];
  2529. uint8 type;
  2530. if( cd == NULL || cd->owner == NULL )
  2531. return 1;
  2532. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2533. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2534. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2535. : 1;
  2536. WBUFW(buf, 0) = 0xd7;
  2537. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2538. WBUFL(buf, 4) = cd->owner->id;
  2539. WBUFL(buf, 8) = cd->bl.id;
  2540. WBUFW(buf,12) = cd->limit;
  2541. WBUFW(buf,14) = cd->users;
  2542. WBUFB(buf,16) = type;
  2543. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2544. if( fd ) {
  2545. WFIFOHEAD(fd,WBUFW(buf,2));
  2546. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2547. WFIFOSET(fd,WBUFW(buf,2));
  2548. } else {
  2549. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2550. }
  2551. return 0;
  2552. }
  2553. /*==========================================
  2554. * Chatroom properties adjustment
  2555. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2556. *------------------------------------------*/
  2557. int clif_changechatstatus(struct chat_data* cd)
  2558. {
  2559. unsigned char buf[128];
  2560. if( cd == NULL || cd->usersd[0] == NULL )
  2561. return 1;
  2562. WBUFW(buf, 0) = 0xdf;
  2563. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2564. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2565. WBUFL(buf, 8) = cd->bl.id;
  2566. WBUFW(buf,12) = cd->limit;
  2567. WBUFW(buf,14) = cd->users;
  2568. WBUFB(buf,16) = cd->pub;
  2569. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2570. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2571. return 0;
  2572. }
  2573. /*==========================================
  2574. *
  2575. *------------------------------------------*/
  2576. int clif_clearchat(struct chat_data *cd,int fd)
  2577. {
  2578. unsigned char buf[32];
  2579. nullpo_retr(0, cd);
  2580. WBUFW(buf,0) = 0xd8;
  2581. WBUFL(buf,2) = cd->bl.id;
  2582. if( fd ) {
  2583. WFIFOHEAD(fd,packet_len(0xd8));
  2584. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2585. WFIFOSET(fd,packet_len(0xd8));
  2586. } else {
  2587. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2588. }
  2589. return 0;
  2590. }
  2591. /*==========================================
  2592. *
  2593. *------------------------------------------*/
  2594. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2595. {
  2596. int fd;
  2597. nullpo_retr(0, sd);
  2598. fd = sd->fd;
  2599. WFIFOHEAD(fd,packet_len(0xda));
  2600. WFIFOW(fd,0) = 0xda;
  2601. WFIFOB(fd,2) = fail;
  2602. WFIFOSET(fd,packet_len(0xda));
  2603. return 0;
  2604. }
  2605. /*==========================================
  2606. *
  2607. *------------------------------------------*/
  2608. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2609. {
  2610. int fd;
  2611. int i;
  2612. nullpo_retr(0, sd);
  2613. nullpo_retr(0, cd);
  2614. fd = sd->fd;
  2615. if (!session_isActive(fd))
  2616. return 0;
  2617. WFIFOHEAD(fd, 8 + (28*cd->users));
  2618. WFIFOW(fd, 0) = 0xdb;
  2619. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2620. WFIFOL(fd, 4) = cd->bl.id;
  2621. for (i = 0; i < cd->users; i++) {
  2622. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2623. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2624. }
  2625. WFIFOSET(fd, WFIFOW(fd, 2));
  2626. return 0;
  2627. }
  2628. /*==========================================
  2629. *
  2630. *------------------------------------------*/
  2631. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2632. {
  2633. unsigned char buf[32];
  2634. nullpo_retr(0, sd);
  2635. nullpo_retr(0, cd);
  2636. WBUFW(buf, 0) = 0x0dc;
  2637. WBUFW(buf, 2) = cd->users;
  2638. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2639. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2640. return 0;
  2641. }
  2642. /*==========================================
  2643. * Announce the new owner
  2644. * R 00e1 <index>.l <nick>.24B
  2645. *------------------------------------------*/
  2646. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2647. {
  2648. unsigned char buf[64];
  2649. nullpo_retv(sd);
  2650. nullpo_retv(cd);
  2651. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2652. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2653. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2654. WBUFW(buf, 0) = 0xe1;
  2655. WBUFL(buf, 2) = 1;
  2656. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2657. WBUFW(buf,30) = 0xe1;
  2658. WBUFL(buf,32) = 0;
  2659. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2660. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2661. }
  2662. /*==========================================
  2663. * Notify about user leaving the chatroom
  2664. * R 00dd <index>.w <nick>.24B <flag>.B
  2665. *------------------------------------------*/
  2666. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2667. {
  2668. unsigned char buf[32];
  2669. nullpo_retv(sd);
  2670. nullpo_retv(cd);
  2671. WBUFW(buf, 0) = 0xdd;
  2672. WBUFW(buf, 2) = cd->users-1;
  2673. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2674. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2675. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2676. }
  2677. /*==========================================
  2678. * Opens a trade request window from char 'name'
  2679. * R 00e5 <nick>.24B
  2680. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2681. *------------------------------------------*/
  2682. void clif_traderequest(struct map_session_data* sd, const char* name)
  2683. {
  2684. int fd = sd->fd;
  2685. #if PACKETVER < 6
  2686. WFIFOHEAD(fd,packet_len(0xe5));
  2687. WFIFOW(fd,0) = 0xe5;
  2688. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2689. WFIFOSET(fd,packet_len(0xe5));
  2690. #else
  2691. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2692. if( !tsd ) return;
  2693. WFIFOHEAD(fd,packet_len(0x1f4));
  2694. WFIFOW(fd,0) = 0x1f4;
  2695. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2696. WFIFOL(fd,26) = tsd->status.char_id;
  2697. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2698. WFIFOSET(fd,packet_len(0x1f4));
  2699. #endif
  2700. }
  2701. /*==========================================
  2702. * Reply to a trade-request.
  2703. * R 00e7 <type>.B
  2704. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2705. * Type:
  2706. * 0: Char is too far
  2707. * 1: Character does not exist
  2708. * 2: Trade failed
  2709. * 3: Accept
  2710. * 4: Cancel
  2711. *------------------------------------------*/
  2712. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2713. {
  2714. int fd = sd->fd;
  2715. #if PACKETVER < 6
  2716. WFIFOHEAD(fd,packet_len(0xe7));
  2717. WFIFOW(fd,0) = 0xe7;
  2718. WFIFOB(fd,2) = type;
  2719. WFIFOSET(fd,packet_len(0xe7));
  2720. #else
  2721. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2722. if( !tsd ) return;
  2723. WFIFOHEAD(fd,packet_len(0x1f5));
  2724. WFIFOW(fd,0) = 0x1f5;
  2725. WFIFOB(fd,2) = type;
  2726. WFIFOL(fd,3) = tsd->status.char_id;
  2727. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2728. WFIFOSET(fd,packet_len(0x1f5));
  2729. #endif
  2730. }
  2731. /*==========================================
  2732. * 相手方からのアイテム追加
  2733. *------------------------------------------*/
  2734. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2735. {
  2736. int fd;
  2737. nullpo_retv(sd);
  2738. nullpo_retv(tsd);
  2739. fd = tsd->fd;
  2740. WFIFOHEAD(fd,packet_len(0xe9));
  2741. WFIFOW(fd,0) = 0xe9;
  2742. WFIFOL(fd,2) = amount;
  2743. if( index == 0 )
  2744. {
  2745. WFIFOW(fd,6) = 0; // type id
  2746. WFIFOB(fd,8) = 0; //identify flag
  2747. WFIFOB(fd,9) = 0; // attribute
  2748. WFIFOB(fd,10)= 0; //refine
  2749. WFIFOW(fd,11)= 0; //card (4w)
  2750. WFIFOW(fd,13)= 0; //card (4w)
  2751. WFIFOW(fd,15)= 0; //card (4w)
  2752. WFIFOW(fd,17)= 0; //card (4w)
  2753. }
  2754. else
  2755. {
  2756. index -= 2; //index fix
  2757. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2758. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2759. else
  2760. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2761. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2762. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2763. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2764. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2765. }
  2766. WFIFOSET(fd,packet_len(0xe9));
  2767. }
  2768. /*==========================================
  2769. * アイテム追加成功/失敗
  2770. *------------------------------------------*/
  2771. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2772. {
  2773. int fd;
  2774. nullpo_retv(sd);
  2775. fd = sd->fd;
  2776. WFIFOHEAD(fd,packet_len(0xea));
  2777. WFIFOW(fd,0) = 0xea;
  2778. WFIFOW(fd,2) = index;
  2779. WFIFOB(fd,4) = fail;
  2780. WFIFOSET(fd,packet_len(0xea));
  2781. }
  2782. /*==========================================
  2783. * 取り引きok押し
  2784. *------------------------------------------*/
  2785. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2786. {
  2787. int fd;
  2788. nullpo_retv(sd);
  2789. fd = sd->fd;
  2790. WFIFOHEAD(fd,packet_len(0xec));
  2791. WFIFOW(fd,0) = 0xec;
  2792. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2793. WFIFOSET(fd,packet_len(0xec));
  2794. }
  2795. /*==========================================
  2796. * 取り引きがキャンセルされました
  2797. *------------------------------------------*/
  2798. void clif_tradecancelled(struct map_session_data* sd)
  2799. {
  2800. int fd;
  2801. nullpo_retv(sd);
  2802. fd = sd->fd;
  2803. WFIFOHEAD(fd,packet_len(0xee));
  2804. WFIFOW(fd,0) = 0xee;
  2805. WFIFOSET(fd,packet_len(0xee));
  2806. }
  2807. /*==========================================
  2808. * 取り引き完了
  2809. *------------------------------------------*/
  2810. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2811. {
  2812. int fd;
  2813. nullpo_retv(sd);
  2814. fd = sd->fd;
  2815. WFIFOHEAD(fd,packet_len(0xf0));
  2816. WFIFOW(fd,0) = 0xf0;
  2817. WFIFOB(fd,2) = fail;
  2818. WFIFOSET(fd,packet_len(0xf0));
  2819. }
  2820. /*==========================================
  2821. * カプラ倉庫のアイテム数を更新
  2822. *------------------------------------------*/
  2823. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  2824. {
  2825. int fd;
  2826. nullpo_retv(sd);
  2827. fd=sd->fd;
  2828. WFIFOHEAD(fd,packet_len(0xf2));
  2829. WFIFOW(fd,0) = 0xf2; // update storage amount
  2830. WFIFOW(fd,2) = amount; //items
  2831. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2832. WFIFOSET(fd,packet_len(0xf2));
  2833. }
  2834. /*==========================================
  2835. * カプラ倉庫にアイテムを追加する
  2836. *------------------------------------------*/
  2837. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2838. {
  2839. int view,fd;
  2840. nullpo_retv(sd);
  2841. nullpo_retv(i);
  2842. fd=sd->fd;
  2843. view = itemdb_viewid(i->nameid);
  2844. #if PACKETVER < 5
  2845. WFIFOHEAD(fd,packet_len(0xf4));
  2846. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2847. WFIFOW(fd, 2) = index+1; // index
  2848. WFIFOL(fd, 4) = amount; // amount
  2849. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2850. WFIFOB(fd,10) = i->identify; //identify flag
  2851. WFIFOB(fd,11) = i->attribute; // attribute
  2852. WFIFOB(fd,12) = i->refine; //refine
  2853. clif_addcards(WFIFOP(fd,13), i);
  2854. WFIFOSET(fd,packet_len(0xf4));
  2855. #else
  2856. WFIFOHEAD(fd,packet_len(0x1c4));
  2857. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  2858. WFIFOW(fd, 2) = index+1; // index
  2859. WFIFOL(fd, 4) = amount; // amount
  2860. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2861. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  2862. WFIFOB(fd,11) = i->identify; //identify flag
  2863. WFIFOB(fd,12) = i->attribute; // attribute
  2864. WFIFOB(fd,13) = i->refine; //refine
  2865. clif_addcards(WFIFOP(fd,14), i);
  2866. WFIFOSET(fd,packet_len(0x1c4));
  2867. #endif
  2868. }
  2869. /*==========================================
  2870. *
  2871. *------------------------------------------*/
  2872. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  2873. {
  2874. int fd;
  2875. nullpo_retv(sd);
  2876. fd=sd->fd;
  2877. WFIFOHEAD(fd,packet_len(0xf2));
  2878. WFIFOW(fd,0) = 0xf2; // update storage amount
  2879. WFIFOW(fd,2) = amount; //items
  2880. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2881. WFIFOSET(fd,packet_len(0xf2));
  2882. }
  2883. /*==========================================
  2884. *
  2885. *------------------------------------------*/
  2886. void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2887. {
  2888. int view,fd;
  2889. nullpo_retv(sd);
  2890. nullpo_retv(i);
  2891. fd=sd->fd;
  2892. view = itemdb_viewid(i->nameid);
  2893. WFIFOHEAD(fd,packet_len(0xf4));
  2894. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2895. WFIFOW(fd, 2) = index+1; // index
  2896. WFIFOL(fd, 4) = amount; // amount
  2897. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2898. WFIFOB(fd,10) = i->identify; //identify flag
  2899. WFIFOB(fd,11) = i->attribute; // attribute
  2900. WFIFOB(fd,12) = i->refine; //refine
  2901. clif_addcards(WFIFOP(fd,13), i);
  2902. WFIFOSET(fd,packet_len(0xf4));
  2903. }
  2904. /*==========================================
  2905. * カプラ倉庫からアイテムを取り去る
  2906. *------------------------------------------*/
  2907. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  2908. {
  2909. int fd;
  2910. nullpo_retv(sd);
  2911. fd=sd->fd;
  2912. WFIFOHEAD(fd,packet_len(0xf6));
  2913. WFIFOW(fd,0)=0xf6; // Storage item removed
  2914. WFIFOW(fd,2)=index+1;
  2915. WFIFOL(fd,4)=amount;
  2916. WFIFOSET(fd,packet_len(0xf6));
  2917. }
  2918. /*==========================================
  2919. * カプラ倉庫を閉じる
  2920. *------------------------------------------*/
  2921. void clif_storageclose(struct map_session_data* sd)
  2922. {
  2923. int fd;
  2924. nullpo_retv(sd);
  2925. fd=sd->fd;
  2926. WFIFOHEAD(fd,packet_len(0xf8));
  2927. WFIFOW(fd,0) = 0xf8; // Storage Closed
  2928. WFIFOSET(fd,packet_len(0xf8));
  2929. }
  2930. /*==========================================
  2931. * PC表示
  2932. *------------------------------------------*/
  2933. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2934. {
  2935. int gmlvl;
  2936. struct block_list *d_bl;
  2937. int i;
  2938. if(dstsd->chatID)
  2939. {
  2940. struct chat_data *cd;
  2941. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2942. if(cd && cd->usersd[0]==dstsd)
  2943. clif_dispchat(cd,sd->fd);
  2944. }
  2945. if(dstsd->vender_id)
  2946. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2947. if(dstsd->spiritball > 0)
  2948. clif_spiritball_single(sd->fd, dstsd);
  2949. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2950. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd))
  2951. )
  2952. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2953. // display link (sd - dstsd) to sd
  2954. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2955. if( i < 5 ) clif_devotion(&sd->bl, sd);
  2956. // display links (dstsd - devotees) to sd
  2957. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  2958. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  2959. // display link (dstsd - crusader) to sd
  2960. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  2961. clif_devotion(d_bl, sd);
  2962. }
  2963. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  2964. {
  2965. uint8 buf[128];
  2966. struct unit_data *ud;
  2967. struct view_data *vd;
  2968. int len;
  2969. vd = status_get_viewdata(bl);
  2970. if (!vd || vd->class_ == INVISIBLE_CLASS)
  2971. return;
  2972. ud = unit_bl2ud(bl);
  2973. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  2974. clif_send(buf,len,&sd->bl,SELF);
  2975. if (vd->cloth_color)
  2976. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  2977. switch (bl->type)
  2978. {
  2979. case BL_PC:
  2980. {
  2981. TBL_PC* tsd = (TBL_PC*)bl;
  2982. clif_getareachar_pc(sd, tsd);
  2983. if(tsd->state.size==2) // tiny/big players [Valaris]
  2984. clif_specialeffect_single(bl,423,sd->fd);
  2985. else if(tsd->state.size==1)
  2986. clif_specialeffect_single(bl,421,sd->fd);
  2987. }
  2988. break;
  2989. case BL_MER: // Devotion Effects
  2990. if( ((TBL_MER*)bl)->devotion_flag )
  2991. clif_devotion(bl, sd);
  2992. break;
  2993. case BL_NPC:
  2994. {
  2995. TBL_NPC* nd = (TBL_NPC*)bl;
  2996. if( nd->chat_id )
  2997. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  2998. if( nd->size == 2 )
  2999. clif_specialeffect_single(bl,423,sd->fd);
  3000. else if( nd->size == 1 )
  3001. clif_specialeffect_single(bl,421,sd->fd);
  3002. }
  3003. break;
  3004. case BL_MOB:
  3005. {
  3006. TBL_MOB* md = (TBL_MOB*)bl;
  3007. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3008. clif_specialeffect_single(bl,423,sd->fd);
  3009. else if(md->special_state.size==1)
  3010. clif_specialeffect_single(bl,421,sd->fd);
  3011. }
  3012. break;
  3013. case BL_PET:
  3014. if (vd->head_bottom)
  3015. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3016. break;
  3017. }
  3018. }
  3019. //Modifies the type of damage according to status changes [Skotlex]
  3020. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3021. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3022. /*==========================================
  3023. * Estimates walk delay based on the damage criteria. [Skotlex]
  3024. *------------------------------------------*/
  3025. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3026. {
  3027. if (type == 4 || type == 9 || damage <=0)
  3028. return 0;
  3029. if (bl->type == BL_PC) {
  3030. if (battle_config.pc_walk_delay_rate != 100)
  3031. delay = delay*battle_config.pc_walk_delay_rate/100;
  3032. } else
  3033. if (battle_config.walk_delay_rate != 100)
  3034. delay = delay*battle_config.walk_delay_rate/100;
  3035. if (div_ > 1) //Multi-hit skills mean higher delays.
  3036. delay += battle_config.multihit_delay*(div_-1);
  3037. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3038. }
  3039. /*==========================================
  3040. * Sends a 'damage' packet (src performs action on dst)
  3041. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3042. *
  3043. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3044. * type=01 pick up item
  3045. * type=02 sit down
  3046. * type=03 stand up
  3047. * type=04 reflected/absorbed damage?
  3048. * type=08 double attack
  3049. * type=09 don't display flinch animation (endure)
  3050. * type=0a critical hit
  3051. * type=0b lucky dodge
  3052. *------------------------------------------*/
  3053. 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)
  3054. {
  3055. unsigned char buf[256];
  3056. struct status_change *sc;
  3057. nullpo_retr(0, src);
  3058. nullpo_retr(0, dst);
  3059. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3060. sc = status_get_sc(dst);
  3061. if(sc && sc->count) {
  3062. if(sc->data[SC_HALLUCINATION]) {
  3063. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3064. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3065. }
  3066. }
  3067. WBUFW(buf,0)=0x8a;
  3068. WBUFL(buf,2)=src->id;
  3069. WBUFL(buf,6)=dst->id;
  3070. WBUFL(buf,10)=tick;
  3071. WBUFL(buf,14)=sdelay;
  3072. WBUFL(buf,18)=ddelay;
  3073. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3074. WBUFW(buf,22)=damage?div:0;
  3075. WBUFW(buf,27)=damage2?div:0;
  3076. } else {
  3077. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3078. WBUFW(buf,27)=damage2;
  3079. }
  3080. WBUFW(buf,24)=div;
  3081. WBUFB(buf,26)=type;
  3082. if(disguised(dst)) {
  3083. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3084. WBUFL(buf,6) = -dst->id;
  3085. clif_send(buf,packet_len(0x8a),dst,SELF);
  3086. } else
  3087. clif_send(buf,packet_len(0x8a),dst,AREA);
  3088. if(disguised(src)) {
  3089. WBUFL(buf,2) = -src->id;
  3090. if (disguised(dst))
  3091. WBUFL(buf,6) = dst->id;
  3092. if(damage > 0) WBUFW(buf,22) = -1;
  3093. if(damage2 > 0) WBUFW(buf,27) = -1;
  3094. clif_send(buf,packet_len(0x8a),src,SELF);
  3095. }
  3096. //Return adjusted can't walk delay for further processing.
  3097. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3098. }
  3099. /*==========================================
  3100. * src picks up dst
  3101. *------------------------------------------*/
  3102. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3103. {
  3104. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3105. unsigned char buf[32];
  3106. nullpo_retv(src);
  3107. nullpo_retv(dst);
  3108. WBUFW(buf, 0) = 0x8a;
  3109. WBUFL(buf, 2) = src->id;
  3110. WBUFL(buf, 6) = dst->id;
  3111. WBUFB(buf,26) = 1;
  3112. clif_send(buf, packet_len(0x8a), src, AREA);
  3113. }
  3114. /*==========================================
  3115. * inform clients in area that `bl` is sitting
  3116. *------------------------------------------*/
  3117. void clif_sitting(struct block_list* bl)
  3118. {
  3119. unsigned char buf[32];
  3120. nullpo_retv(bl);
  3121. WBUFW(buf, 0) = 0x8a;
  3122. WBUFL(buf, 2) = bl->id;
  3123. WBUFB(buf,26) = 2;
  3124. clif_send(buf, packet_len(0x8a), bl, AREA);
  3125. if(disguised(bl)) {
  3126. WBUFL(buf, 2) = - bl->id;
  3127. clif_send(buf, packet_len(0x8a), bl, SELF);
  3128. }
  3129. }
  3130. /*==========================================
  3131. * inform clients in area that `bl` is standing
  3132. *------------------------------------------*/
  3133. void clif_standing(struct block_list* bl)
  3134. {
  3135. unsigned char buf[32];
  3136. nullpo_retv(bl);
  3137. WBUFW(buf, 0) = 0x8a;
  3138. WBUFL(buf, 2) = bl->id;
  3139. WBUFB(buf,26) = 3;
  3140. clif_send(buf, packet_len(0x8a), bl, AREA);
  3141. if(disguised(bl)) {
  3142. WBUFL(buf, 2) = - bl->id;
  3143. clif_send(buf, packet_len(0x8a), bl, SELF);
  3144. }
  3145. }
  3146. /*==========================================
  3147. * Inform client(s) about a map-cell change
  3148. *------------------------------------------*/
  3149. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3150. {
  3151. unsigned char buf[32];
  3152. WBUFW(buf,0) = 0x192;
  3153. WBUFW(buf,2) = x;
  3154. WBUFW(buf,4) = y;
  3155. WBUFW(buf,6) = type;
  3156. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3157. if( fd )
  3158. {
  3159. WFIFOHEAD(fd,packet_len(0x192));
  3160. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3161. WFIFOSET(fd,packet_len(0x192));
  3162. }
  3163. else
  3164. {
  3165. struct block_list dummy_bl;
  3166. dummy_bl.type = BL_NUL;
  3167. dummy_bl.x = x;
  3168. dummy_bl.y = y;
  3169. dummy_bl.m = m;
  3170. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3171. }
  3172. }
  3173. /*==========================================
  3174. *
  3175. *------------------------------------------*/
  3176. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3177. {
  3178. int view,fd;
  3179. fd=sd->fd;
  3180. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3181. WFIFOHEAD(fd,packet_len(0x9d));
  3182. WFIFOW(fd,0)=0x9d;
  3183. WFIFOL(fd,2)=fitem->bl.id;
  3184. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3185. WFIFOW(fd,6)=view;
  3186. else
  3187. WFIFOW(fd,6)=fitem->item_data.nameid;
  3188. WFIFOB(fd,8)=fitem->item_data.identify;
  3189. WFIFOW(fd,9)=fitem->bl.x;
  3190. WFIFOW(fd,11)=fitem->bl.y;
  3191. WFIFOW(fd,13)=fitem->item_data.amount;
  3192. WFIFOB(fd,15)=fitem->subx;
  3193. WFIFOB(fd,16)=fitem->suby;
  3194. WFIFOSET(fd,packet_len(0x9d));
  3195. }
  3196. /*==========================================
  3197. * 場所スキルエフェクトが視界に入る
  3198. *------------------------------------------*/
  3199. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3200. {
  3201. int fd = sd->fd;
  3202. #if PACKETVER >= 3
  3203. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3204. WFIFOHEAD(fd,packet_len(0x1c9));
  3205. WFIFOW(fd, 0)=0x1c9;
  3206. WFIFOL(fd, 2)=unit->bl.id;
  3207. WFIFOL(fd, 6)=unit->group->src_id;
  3208. WFIFOW(fd,10)=unit->bl.x;
  3209. WFIFOW(fd,12)=unit->bl.y;
  3210. WFIFOB(fd,14)=unit->group->unit_id;
  3211. WFIFOB(fd,15)=1;
  3212. WFIFOB(fd,16)=1;
  3213. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3214. WFIFOSET(fd,packet_len(0x1c9));
  3215. return;
  3216. }
  3217. #endif
  3218. WFIFOHEAD(fd,packet_len(0x11f));
  3219. WFIFOW(fd, 0)=0x11f;
  3220. WFIFOL(fd, 2)=unit->bl.id;
  3221. WFIFOL(fd, 6)=unit->group->src_id;
  3222. WFIFOW(fd,10)=unit->bl.x;
  3223. WFIFOW(fd,12)=unit->bl.y;
  3224. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3225. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3226. else
  3227. WFIFOB(fd,14)=unit->group->unit_id;
  3228. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3229. WFIFOSET(fd,packet_len(0x11f));
  3230. if(unit->group->skill_id == WZ_ICEWALL)
  3231. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3232. }
  3233. /*==========================================
  3234. * 場所スキルエフェクトが視界から消える
  3235. *------------------------------------------*/
  3236. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3237. {
  3238. nullpo_retv(unit);
  3239. WFIFOHEAD(fd,packet_len(0x120));
  3240. WFIFOW(fd, 0)=0x120;
  3241. WFIFOL(fd, 2)=unit->bl.id;
  3242. WFIFOSET(fd,packet_len(0x120));
  3243. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3244. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3245. }
  3246. /*==========================================
  3247. * 場所スキルエフェクト削除
  3248. *------------------------------------------*/
  3249. void clif_skill_delunit(struct skill_unit *unit)
  3250. {
  3251. unsigned char buf[16];
  3252. nullpo_retv(unit);
  3253. WBUFW(buf, 0)=0x120;
  3254. WBUFL(buf, 2)=unit->bl.id;
  3255. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3256. }
  3257. /*==========================================
  3258. * Unknown... trap related?
  3259. * Sent when an object gets ankle-snared
  3260. * Only affects units with class [139,153] client-side
  3261. * R 01ac <object id>.l
  3262. *------------------------------------------*/
  3263. void clif_01ac(struct block_list* bl)
  3264. {
  3265. unsigned char buf[6];
  3266. nullpo_retv(bl);
  3267. WBUFW(buf,0) = 0x1ac;
  3268. WBUFL(buf,2) = bl->id;
  3269. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3270. }
  3271. /*==========================================
  3272. *
  3273. *------------------------------------------*/
  3274. int clif_getareachar(struct block_list* bl,va_list ap)
  3275. {
  3276. struct map_session_data *sd;
  3277. nullpo_retr(0, bl);
  3278. sd=va_arg(ap,struct map_session_data*);
  3279. if (sd == NULL || !sd->fd)
  3280. return 0;
  3281. switch(bl->type){
  3282. case BL_ITEM:
  3283. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3284. break;
  3285. case BL_SKILL:
  3286. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3287. break;
  3288. default:
  3289. if(&sd->bl == bl)
  3290. break;
  3291. clif_getareachar_unit(sd,bl);
  3292. break;
  3293. }
  3294. return 0;
  3295. }
  3296. /*==========================================
  3297. * tbl has gone out of view-size of bl
  3298. *------------------------------------------*/
  3299. int clif_outsight(struct block_list *bl,va_list ap)
  3300. {
  3301. struct block_list *tbl;
  3302. struct view_data *vd;
  3303. TBL_PC *sd, *tsd;
  3304. tbl=va_arg(ap,struct block_list*);
  3305. if(bl == tbl) return 0;
  3306. sd = BL_CAST(BL_PC, bl);
  3307. tsd = BL_CAST(BL_PC, tbl);
  3308. if (tsd && tsd->fd)
  3309. { //tsd has lost sight of the bl object.
  3310. switch(bl->type){
  3311. case BL_PC:
  3312. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3313. clif_clearunit_single(bl->id,0,tsd->fd);
  3314. if(sd->chatID){
  3315. struct chat_data *cd;
  3316. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3317. if(cd->usersd[0]==sd)
  3318. clif_dispchat(cd,tsd->fd);
  3319. }
  3320. if(sd->vender_id)
  3321. clif_closevendingboard(bl,tsd->fd);
  3322. break;
  3323. case BL_ITEM:
  3324. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3325. break;
  3326. case BL_SKILL:
  3327. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3328. break;
  3329. default:
  3330. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3331. clif_clearunit_single(bl->id,0,tsd->fd);
  3332. break;
  3333. }
  3334. }
  3335. if (sd && sd->fd)
  3336. { //sd is watching tbl go out of view.
  3337. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3338. clif_clearunit_single(tbl->id,0,sd->fd);
  3339. }
  3340. return 0;
  3341. }
  3342. /*==========================================
  3343. * tbl has come into view of bl
  3344. *------------------------------------------*/
  3345. int clif_insight(struct block_list *bl,va_list ap)
  3346. {
  3347. struct block_list *tbl;
  3348. TBL_PC *sd, *tsd;
  3349. tbl=va_arg(ap,struct block_list*);
  3350. if (bl == tbl) return 0;
  3351. sd = BL_CAST(BL_PC, bl);
  3352. tsd = BL_CAST(BL_PC, tbl);
  3353. if (tsd && tsd->fd)
  3354. { //Tell tsd that bl entered into his view
  3355. switch(bl->type){
  3356. case BL_ITEM:
  3357. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3358. break;
  3359. case BL_SKILL:
  3360. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3361. break;
  3362. default:
  3363. clif_getareachar_unit(tsd,bl);
  3364. break;
  3365. }
  3366. }
  3367. if (sd && sd->fd)
  3368. { //Tell sd that tbl walked into his view
  3369. clif_getareachar_unit(sd,tbl);
  3370. }
  3371. return 0;
  3372. }
  3373. /*==========================================
  3374. *
  3375. *------------------------------------------*/
  3376. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3377. {
  3378. int fd,id;
  3379. nullpo_retr(0, sd);
  3380. fd=sd->fd;
  3381. if( (id=sd->status.skill[skillid].id) <= 0 )
  3382. return 0;
  3383. WFIFOHEAD(fd,packet_len(0x147));
  3384. WFIFOW(fd,0)=0x147;
  3385. WFIFOW(fd,2) = id;
  3386. if(type < 0)
  3387. WFIFOW(fd,4) = skill_get_inf(id);
  3388. else
  3389. WFIFOW(fd,4) = type;
  3390. WFIFOW(fd,6) = 0;
  3391. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3392. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3393. if(range < 0)
  3394. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3395. WFIFOW(fd,12)= range;
  3396. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3397. if(sd->status.skill[skillid].flag ==0)
  3398. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3399. else
  3400. WFIFOB(fd,38) = 0;
  3401. WFIFOSET(fd,packet_len(0x147));
  3402. return 0;
  3403. }
  3404. /*==========================================
  3405. * スキルリストを送信する
  3406. *------------------------------------------*/
  3407. int clif_skillinfoblock(struct map_session_data *sd)
  3408. {
  3409. int fd;
  3410. int i,c,len,id;
  3411. nullpo_retr(0, sd);
  3412. fd=sd->fd;
  3413. if (!fd) return 0;
  3414. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3415. WFIFOW(fd,0) = 0x10f;
  3416. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3417. {
  3418. if( (id = sd->status.skill[i].id) != 0 )
  3419. {
  3420. WFIFOW(fd,len) = id;
  3421. WFIFOW(fd,len+2) = skill_get_inf(id);
  3422. WFIFOW(fd,len+4) = 0;
  3423. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3424. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3425. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3426. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3427. if(sd->status.skill[i].flag == 0)
  3428. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3429. else
  3430. WFIFOB(fd,len+36) = 0;
  3431. len += 37;
  3432. c++;
  3433. }
  3434. }
  3435. WFIFOW(fd,2)=len;
  3436. WFIFOSET(fd,len);
  3437. return 1;
  3438. }
  3439. /*==========================================
  3440. * スキル割り振り通知
  3441. *------------------------------------------*/
  3442. int clif_skillup(struct map_session_data *sd,int skill_num)
  3443. {
  3444. int fd;
  3445. nullpo_retr(0, sd);
  3446. fd=sd->fd;
  3447. WFIFOHEAD(fd,packet_len(0x10e));
  3448. WFIFOW(fd,0) = 0x10e;
  3449. WFIFOW(fd,2) = skill_num;
  3450. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3451. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3452. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3453. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3454. WFIFOSET(fd,packet_len(0x10e));
  3455. return 0;
  3456. }
  3457. /*==========================================
  3458. * スキル詠唱エフェクトを送信する
  3459. *------------------------------------------*/
  3460. int clif_skillcasting(struct block_list* bl,
  3461. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3462. {
  3463. unsigned char buf[32];
  3464. WBUFW(buf,0) = 0x13e;
  3465. WBUFL(buf,2) = src_id;
  3466. WBUFL(buf,6) = dst_id;
  3467. WBUFW(buf,10) = dst_x;
  3468. WBUFW(buf,12) = dst_y;
  3469. WBUFW(buf,14) = skill_num;
  3470. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3471. WBUFL(buf,20) = casttime;
  3472. if (disguised(bl)) {
  3473. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3474. WBUFL(buf,2) = -src_id;
  3475. clif_send(buf,packet_len(0x13e), bl, SELF);
  3476. } else
  3477. clif_send(buf,packet_len(0x13e), bl, AREA);
  3478. return 0;
  3479. }
  3480. /*==========================================
  3481. *
  3482. *------------------------------------------*/
  3483. int clif_skillcastcancel(struct block_list* bl)
  3484. {
  3485. unsigned char buf[16];
  3486. nullpo_retr(0, bl);
  3487. WBUFW(buf,0) = 0x1b9;
  3488. WBUFL(buf,2) = bl->id;
  3489. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3490. return 0;
  3491. }
  3492. /// only when type==0:
  3493. /// if(skill_id==NV_BASIC)
  3494. /// btype==0 "skill failed" MsgStringTable[159]
  3495. /// btype==1 "no emotions" MsgStringTable[160]
  3496. /// btype==2 "no sit" MsgStringTable[161]
  3497. /// btype==3 "no chat" MsgStringTable[162]
  3498. /// btype==4 "no party" MsgStringTable[163]
  3499. /// btype==5 "no shout" MsgStringTable[164]
  3500. /// btype==6 "no PKing" MsgStringTable[165]
  3501. /// btype==7 "no alligning" MsgStringTable[383]
  3502. /// btype>=8: ignored
  3503. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3504. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3505. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3506. /// otherwise "skill failed" MsgStringTable[204]
  3507. /// btype irrelevant
  3508. /// type==1 "insufficient SP" MsgStringTable[202]
  3509. /// type==2 "insufficient HP" MsgStringTable[203]
  3510. /// type==3 "insufficient materials" MsgStringTable[808]
  3511. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3512. /// type==5 "insufficient zeny" MsgStringTable[233]
  3513. /// type==6 "wrong weapon" MsgStringTable[239]
  3514. /// type==7 "red gemstone needed" MsgStringTable[246]
  3515. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3516. /// type==9 "overweight" MsgStringTable[580]
  3517. /// type==10 "skill failed" MsgStringTable[285]
  3518. /// type>=11 ignored
  3519. ///
  3520. /// if(success!=0) doesn't display any of the previous messages
  3521. /// Note: when this packet is received an unknown flag is always set to 0,
  3522. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3523. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3524. {
  3525. int fd;
  3526. if (!sd) { //Since this is the most common nullpo....
  3527. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3528. return 0;
  3529. }
  3530. fd=sd->fd;
  3531. if (!fd) return 0;
  3532. if(battle_config.display_skill_fail&1)
  3533. return 0; //Disable all skill failed messages
  3534. if(type==0x4 && !sd->state.showdelay)
  3535. return 0; //Disable delay failed messages
  3536. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3537. return 0;
  3538. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3539. return 0;
  3540. WFIFOHEAD(fd,packet_len(0x110));
  3541. WFIFOW(fd,0) = 0x110;
  3542. WFIFOW(fd,2) = skill_id;
  3543. WFIFOL(fd,4) = btype;
  3544. WFIFOB(fd,8) = 0;// success?
  3545. WFIFOB(fd,9) = type;
  3546. WFIFOSET(fd,packet_len(0x110));
  3547. return 1;
  3548. }
  3549. /*==========================================
  3550. * skill attack effect and damage
  3551. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  3552. *------------------------------------------*/
  3553. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3554. {
  3555. unsigned char buf[64];
  3556. struct status_change *sc;
  3557. nullpo_retr(0, src);
  3558. nullpo_retr(0, dst);
  3559. type = clif_calc_delay(type,div,damage,ddelay);
  3560. sc = status_get_sc(dst);
  3561. if(sc && sc->count) {
  3562. if(sc->data[SC_HALLUCINATION] && damage)
  3563. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3564. }
  3565. #if PACKETVER < 3
  3566. WBUFW(buf,0)=0x114;
  3567. WBUFW(buf,2)=skill_id;
  3568. WBUFL(buf,4)=src->id;
  3569. WBUFL(buf,8)=dst->id;
  3570. WBUFL(buf,12)=tick;
  3571. WBUFL(buf,16)=sdelay;
  3572. WBUFL(buf,20)=ddelay;
  3573. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3574. WBUFW(buf,24)=damage?div:0;
  3575. } else {
  3576. WBUFW(buf,24)=damage;
  3577. }
  3578. WBUFW(buf,26)=skill_lv;
  3579. WBUFW(buf,28)=div;
  3580. WBUFB(buf,30)=type;
  3581. if (disguised(dst)) {
  3582. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3583. WBUFL(buf,8)=-dst->id;
  3584. clif_send(buf,packet_len(0x114),dst,SELF);
  3585. } else
  3586. clif_send(buf,packet_len(0x114),dst,AREA);
  3587. if(disguised(src)) {
  3588. WBUFL(buf,4)=-src->id;
  3589. if (disguised(dst))
  3590. WBUFL(buf,8)=dst->id;
  3591. if(damage > 0)
  3592. WBUFW(buf,24)=-1;
  3593. clif_send(buf,packet_len(0x114),src,SELF);
  3594. }
  3595. #else
  3596. WBUFW(buf,0)=0x1de;
  3597. WBUFW(buf,2)=skill_id;
  3598. WBUFL(buf,4)=src->id;
  3599. WBUFL(buf,8)=dst->id;
  3600. WBUFL(buf,12)=tick;
  3601. WBUFL(buf,16)=sdelay;
  3602. WBUFL(buf,20)=ddelay;
  3603. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3604. WBUFL(buf,24)=damage?div:0;
  3605. } else {
  3606. WBUFL(buf,24)=damage;
  3607. }
  3608. WBUFW(buf,28)=skill_lv;
  3609. WBUFW(buf,30)=div;
  3610. WBUFB(buf,32)=type;
  3611. if (disguised(dst)) {
  3612. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3613. WBUFL(buf,8)=-dst->id;
  3614. clif_send(buf,packet_len(0x1de),dst,SELF);
  3615. } else
  3616. clif_send(buf,packet_len(0x1de),dst,AREA);
  3617. if(disguised(src)) {
  3618. WBUFL(buf,4)=-src->id;
  3619. if (disguised(dst))
  3620. WBUFL(buf,8)=dst->id;
  3621. if(damage > 0)
  3622. WBUFL(buf,24)=-1;
  3623. clif_send(buf,packet_len(0x1de),src,SELF);
  3624. }
  3625. #endif
  3626. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3627. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3628. }
  3629. /*==========================================
  3630. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3631. *------------------------------------------*/
  3632. /*
  3633. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3634. {
  3635. unsigned char buf[64];
  3636. struct status_change *sc;
  3637. nullpo_retr(0, src);
  3638. nullpo_retr(0, dst);
  3639. type = (type>0)?type:skill_get_hit(skill_id);
  3640. type = clif_calc_delay(type,div,damage,ddelay);
  3641. sc = status_get_sc(dst);
  3642. if(sc && sc->count) {
  3643. if(sc->data[SC_HALLUCINATION] && damage)
  3644. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3645. }
  3646. WBUFW(buf,0)=0x115;
  3647. WBUFW(buf,2)=skill_id;
  3648. WBUFL(buf,4)=src->id;
  3649. WBUFL(buf,8)=dst->id;
  3650. WBUFL(buf,12)=tick;
  3651. WBUFL(buf,16)=sdelay;
  3652. WBUFL(buf,20)=ddelay;
  3653. WBUFW(buf,24)=dst->x;
  3654. WBUFW(buf,26)=dst->y;
  3655. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3656. WBUFW(buf,28)=damage?div:0;
  3657. } else {
  3658. WBUFW(buf,28)=damage;
  3659. }
  3660. WBUFW(buf,30)=skill_lv;
  3661. WBUFW(buf,32)=div;
  3662. WBUFB(buf,34)=type;
  3663. clif_send(buf,packet_len(0x115),src,AREA);
  3664. if(disguised(src)) {
  3665. WBUFL(buf,4)=-src->id;
  3666. if(damage > 0)
  3667. WBUFW(buf,28)=-1;
  3668. clif_send(buf,packet_len(0x115),src,SELF);
  3669. }
  3670. if (disguised(dst)) {
  3671. WBUFL(buf,8)=-dst->id;
  3672. if (disguised(src))
  3673. WBUFL(buf,4)=src->id;
  3674. else if(damage > 0)
  3675. WBUFW(buf,28)=-1;
  3676. clif_send(buf,packet_len(0x115),dst,SELF);
  3677. }
  3678. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3679. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3680. }
  3681. */
  3682. /*==========================================
  3683. * 支援/回復スキルエフェクト
  3684. *------------------------------------------*/
  3685. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3686. {
  3687. unsigned char buf[32];
  3688. nullpo_retr(0, dst);
  3689. WBUFW(buf,0)=0x11a;
  3690. WBUFW(buf,2)=skill_id;
  3691. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3692. WBUFL(buf,6)=dst->id;
  3693. WBUFL(buf,10)=src?src->id:0;
  3694. WBUFB(buf,14)=fail;
  3695. if (disguised(dst)) {
  3696. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3697. WBUFL(buf,6)=-dst->id;
  3698. clif_send(buf,packet_len(0x11a),dst,SELF);
  3699. } else
  3700. clif_send(buf,packet_len(0x11a),dst,AREA);
  3701. if(src && disguised(src)) {
  3702. WBUFL(buf,10)=-src->id;
  3703. if (disguised(dst))
  3704. WBUFL(buf,6)=dst->id;
  3705. clif_send(buf,packet_len(0x11a),src,SELF);
  3706. }
  3707. return fail;
  3708. }
  3709. /*==========================================
  3710. * 場所スキルエフェクト
  3711. *------------------------------------------*/
  3712. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3713. {
  3714. unsigned char buf[32];
  3715. nullpo_retr(0, src);
  3716. WBUFW(buf,0)=0x117;
  3717. WBUFW(buf,2)=skill_id;
  3718. WBUFL(buf,4)=src->id;
  3719. WBUFW(buf,8)=val;
  3720. WBUFW(buf,10)=x;
  3721. WBUFW(buf,12)=y;
  3722. WBUFL(buf,14)=tick;
  3723. if(disguised(src)) {
  3724. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3725. WBUFL(buf,4)=-src->id;
  3726. clif_send(buf,packet_len(0x117),src,SELF);
  3727. } else
  3728. clif_send(buf,packet_len(0x117),src,AREA);
  3729. return 0;
  3730. }
  3731. /*==========================================
  3732. * 場所スキルエフェクト表示
  3733. *------------------------------------------*/
  3734. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3735. void clif_skill_setunit(struct skill_unit *unit)
  3736. {
  3737. unsigned char buf[128];
  3738. nullpo_retv(unit);
  3739. #if PACKETVER >= 3
  3740. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3741. WBUFW(buf, 0)=0x1c9;
  3742. WBUFL(buf, 2)=unit->bl.id;
  3743. WBUFL(buf, 6)=unit->group->src_id;
  3744. WBUFW(buf,10)=unit->bl.x;
  3745. WBUFW(buf,12)=unit->bl.y;
  3746. WBUFB(buf,14)=unit->group->unit_id;
  3747. WBUFB(buf,15)=1;
  3748. WBUFB(buf,16)=1;
  3749. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3750. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3751. return;
  3752. }
  3753. #endif
  3754. WBUFW(buf, 0)=0x11f;
  3755. WBUFL(buf, 2)=unit->bl.id;
  3756. WBUFL(buf, 6)=unit->group->src_id;
  3757. WBUFW(buf,10)=unit->bl.x;
  3758. WBUFW(buf,12)=unit->bl.y;
  3759. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3760. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3761. else
  3762. WBUFB(buf,14)=unit->group->unit_id;
  3763. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3764. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3765. }
  3766. /*==========================================
  3767. * ワープ場所選択
  3768. *------------------------------------------*/
  3769. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  3770. {
  3771. int fd;
  3772. nullpo_retv(sd);
  3773. fd = sd->fd;
  3774. WFIFOHEAD(fd,packet_len(0x11c));
  3775. WFIFOW(fd,0) = 0x11c;
  3776. WFIFOW(fd,2) = skill_num;
  3777. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3778. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3779. else // normal map name
  3780. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3781. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3782. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3783. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3784. WFIFOSET(fd,packet_len(0x11c));
  3785. sd->menuskill_id = skill_num;
  3786. if (skill_num == AL_WARP)
  3787. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3788. else
  3789. sd->menuskill_val = skill_lv;
  3790. }
  3791. /// Memo message.
  3792. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3793. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3794. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3795. ///
  3796. /// @param sd Who receives the message
  3797. /// @param type What message
  3798. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3799. {
  3800. int fd;
  3801. nullpo_retv(sd);
  3802. fd=sd->fd;
  3803. WFIFOHEAD(fd,packet_len(0x11e));
  3804. WFIFOW(fd,0)=0x11e;
  3805. WFIFOB(fd,2)=type;
  3806. WFIFOSET(fd,packet_len(0x11e));
  3807. }
  3808. /// Teleport message.
  3809. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3810. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3811. ///
  3812. /// @param sd Who receives the message
  3813. /// @param type What message
  3814. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3815. {
  3816. int fd;
  3817. nullpo_retv(sd);
  3818. fd=sd->fd;
  3819. WFIFOHEAD(fd,packet_len(0x189));
  3820. WFIFOW(fd,0)=0x189;
  3821. WFIFOW(fd,2)=type;
  3822. WFIFOSET(fd,packet_len(0x189));
  3823. }
  3824. /*==========================================
  3825. * モンスター情報
  3826. *------------------------------------------*/
  3827. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3828. {
  3829. struct status_data *status;
  3830. unsigned char buf[64];
  3831. int i;//, fix;
  3832. nullpo_retr(0, sd);
  3833. nullpo_retr(0, dst);
  3834. if( dst->type != BL_MOB )
  3835. return 0;
  3836. status = status_get_status_data(dst);
  3837. WBUFW(buf, 0)=0x18c;
  3838. WBUFW(buf, 2)=status_get_class(dst);
  3839. WBUFW(buf, 4)=status_get_lv(dst);
  3840. WBUFW(buf, 6)=status->size;
  3841. WBUFL(buf, 8)=status->hp;
  3842. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3843. +(battle_config.estimation_type&2?status->def2:0);
  3844. WBUFW(buf,14)=status->race;
  3845. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3846. +(battle_config.estimation_type&2?status->mdef2:0);
  3847. WBUFW(buf,18)= status->def_ele;
  3848. for(i=0;i<9;i++)
  3849. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  3850. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3851. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3852. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3853. return 0;
  3854. }
  3855. /*==========================================
  3856. * アイテム合成可能リスト
  3857. *------------------------------------------*/
  3858. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3859. {
  3860. int i,c,view,fd;
  3861. nullpo_retr(0, sd);
  3862. if(sd->menuskill_id == AM_PHARMACY)
  3863. return 0; //Avoid resending the menu twice or more times...
  3864. fd=sd->fd;
  3865. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3866. WFIFOW(fd, 0)=0x18d;
  3867. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3868. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3869. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3870. WFIFOW(fd,c*8+ 4)= view;
  3871. else
  3872. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3873. WFIFOW(fd,c*8+ 6)= 0x0012;
  3874. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3875. c++;
  3876. }
  3877. }
  3878. WFIFOW(fd, 2)=c*8+8;
  3879. WFIFOSET(fd,WFIFOW(fd,2));
  3880. if(c > 0) {
  3881. sd->menuskill_id = AM_PHARMACY;
  3882. sd->menuskill_val = trigger;
  3883. return 1;
  3884. }
  3885. return 0;
  3886. }
  3887. /*==========================================
  3888. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3889. *------------------------------------------*/
  3890. int clif_status_load(struct block_list *bl,int type, int flag)
  3891. {
  3892. int fd;
  3893. if (type == SI_BLANK) //It shows nothing on the client...
  3894. return 0;
  3895. if (bl->type != BL_PC)
  3896. return 0;
  3897. fd = ((struct map_session_data*)bl)->fd;
  3898. WFIFOHEAD(fd,packet_len(0x196));
  3899. WFIFOW(fd,0)=0x0196;
  3900. WFIFOW(fd,2)=type;
  3901. WFIFOL(fd,4)=bl->id;
  3902. WFIFOB(fd,8)=flag; //Status start
  3903. WFIFOSET(fd, packet_len(0x196));
  3904. return 0;
  3905. }
  3906. /*==========================================
  3907. * 状態異常アイコン/メッセージ表示
  3908. *------------------------------------------*/
  3909. int clif_status_change(struct block_list *bl,int type,int flag)
  3910. {
  3911. unsigned char buf[16];
  3912. if (type == SI_BLANK) //It shows nothing on the client...
  3913. return 0;
  3914. nullpo_retr(0, bl);
  3915. WBUFW(buf,0)=0x0196;
  3916. WBUFW(buf,2)=type;
  3917. WBUFL(buf,4)=bl->id;
  3918. WBUFB(buf,8)=flag;
  3919. clif_send(buf,packet_len(0x196),bl,AREA);
  3920. return 0;
  3921. }
  3922. /*==========================================
  3923. * Send message (modified by [Yor])
  3924. *------------------------------------------*/
  3925. int clif_displaymessage(const int fd, const char* mes)
  3926. {
  3927. // invalid pointer?
  3928. nullpo_retr(-1, mes);
  3929. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3930. if (fd == 0)
  3931. return 0;
  3932. else {
  3933. int len_mes = strlen(mes);
  3934. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3935. WFIFOHEAD(fd, 5 + len_mes);
  3936. WFIFOW(fd,0) = 0x8e;
  3937. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3938. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3939. WFIFOSET(fd, 5 + len_mes);
  3940. }
  3941. }
  3942. return 0;
  3943. }
  3944. /*==========================================
  3945. * 天の声を送信する
  3946. *------------------------------------------*/
  3947. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3948. {
  3949. unsigned char *buf;
  3950. int lp;
  3951. lp = (flag & 0x10) ? 8 : 4;
  3952. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3953. WBUFW(buf,0) = 0x9a;
  3954. WBUFW(buf,2) = len + lp;
  3955. WBUFL(buf,4) = 0x65756c62; //"blue":
  3956. memcpy(WBUFP(buf,lp), mes, len);
  3957. flag &= 0x07;
  3958. clif_send(buf, WBUFW(buf,2), bl,
  3959. (flag == 1) ? ALL_SAMEMAP :
  3960. (flag == 2) ? AREA :
  3961. (flag == 3) ? SELF :
  3962. ALL_CLIENT);
  3963. if(buf) aFree(buf);
  3964. return 0;
  3965. }
  3966. /*==========================================
  3967. * グローバルメッセージ
  3968. *------------------------------------------*/
  3969. void clif_GlobalMessage(struct block_list* bl, const char* message)
  3970. {
  3971. char buf[100];
  3972. int len;
  3973. nullpo_retv(bl);
  3974. if(!message)
  3975. return;
  3976. len = strlen(message)+1;
  3977. WBUFW(buf,0)=0x8d;
  3978. WBUFW(buf,2)=len+8;
  3979. WBUFL(buf,4)=bl->id;
  3980. strncpy((char *) WBUFP(buf,8),message,len);
  3981. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  3982. }
  3983. /*==========================================
  3984. * Send main chat message [LuzZza]
  3985. *------------------------------------------*/
  3986. void clif_MainChatMessage(const char* message)
  3987. {
  3988. char buf[200];
  3989. int len;
  3990. if(!message)
  3991. return;
  3992. len = strlen(message)+1;
  3993. if (len+8 > sizeof(buf)) {
  3994. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  3995. len = sizeof(buf)-8;
  3996. }
  3997. WBUFW(buf,0)=0x8d;
  3998. WBUFW(buf,2)=len+8;
  3999. WBUFL(buf,4)=0;
  4000. strncpy((char *) WBUFP(buf,8),message,len);
  4001. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4002. }
  4003. /*==========================================
  4004. * Does an announce message in the given color.
  4005. *------------------------------------------*/
  4006. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4007. {
  4008. return clif_announce_ex(bl, mes, len, color, flag, 12);
  4009. }
  4010. int clif_announce_ex(struct block_list* bl, const char* mes, int len, unsigned long color, int flag, int size)
  4011. {
  4012. unsigned char *buf;
  4013. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4014. WBUFW(buf,0) = 0x1c3;
  4015. WBUFW(buf,2) = len + 16;
  4016. WBUFL(buf,4) = color;
  4017. WBUFW(buf,8) = 0x190; //Font style? Type?
  4018. WBUFW(buf,10) = size; // Font size
  4019. WBUFL(buf,12) = 0; //Unknown!
  4020. memcpy(WBUFP(buf,16), mes, len);
  4021. flag &= 0x07;
  4022. clif_send(buf, WBUFW(buf,2), bl,
  4023. (flag == 1) ? ALL_SAMEMAP :
  4024. (flag == 2) ? AREA :
  4025. (flag == 3) ? SELF :
  4026. ALL_CLIENT);
  4027. if(buf) aFree(buf);
  4028. return 0;
  4029. }
  4030. /*==========================================
  4031. * HPSP回復エフェクトを送信する
  4032. *------------------------------------------*/
  4033. int clif_heal(int fd,int type,int val)
  4034. {
  4035. WFIFOHEAD(fd,packet_len(0x13d));
  4036. WFIFOW(fd,0)=0x13d;
  4037. WFIFOW(fd,2)=type;
  4038. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4039. WFIFOSET(fd,packet_len(0x13d));
  4040. return 0;
  4041. }
  4042. /*==========================================
  4043. * 復活する
  4044. *------------------------------------------*/
  4045. int clif_resurrection(struct block_list *bl,int type)
  4046. {
  4047. unsigned char buf[16];
  4048. nullpo_retr(0, bl);
  4049. WBUFW(buf,0)=0x148;
  4050. WBUFL(buf,2)=bl->id;
  4051. WBUFW(buf,6)=type;
  4052. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4053. if (disguised(bl))
  4054. clif_spawn(bl);
  4055. return 0;
  4056. }
  4057. /// Sets the map mode.
  4058. ///
  4059. /// mode=1 : pvp mode
  4060. /// mode=2 : unknown mode (pk?)
  4061. /// mode=3 : gvg mode
  4062. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4063. /// mode=5 : pvp mode
  4064. /// mode=other : ?
  4065. void clif_set0199(struct map_session_data* sd, int mode)
  4066. {
  4067. int fd;
  4068. nullpo_retv(sd);
  4069. fd=sd->fd;
  4070. WFIFOHEAD(fd,packet_len(0x199));
  4071. WFIFOW(fd,0)=0x199;
  4072. WFIFOW(fd,2)=mode;
  4073. WFIFOSET(fd,packet_len(0x199));
  4074. }
  4075. #if 0
  4076. /// Set the map mode?
  4077. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4078. void clif_set01D6(struct map_session_data* sd, int mode)
  4079. {
  4080. int fd;
  4081. nullpo_retv(sd);
  4082. fd=sd->fd;
  4083. WFIFOHEAD(fd,packet_len(0x1D6));
  4084. WFIFOW(fd,0)=0x1D6;
  4085. WFIFOW(fd,2)=mode;
  4086. WFIFOSET(fd,packet_len(0x1D6));
  4087. }
  4088. #endif
  4089. /*==========================================
  4090. * PVP実装?(仮)
  4091. *------------------------------------------*/
  4092. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4093. {
  4094. if(type == 2) {
  4095. int fd = sd->fd;
  4096. WFIFOHEAD(fd,packet_len(0x19a));
  4097. WFIFOW(fd,0) = 0x19a;
  4098. WFIFOL(fd,2) = sd->bl.id;
  4099. WFIFOL(fd,6) = pvprank;
  4100. WFIFOL(fd,10) = pvpnum;
  4101. WFIFOSET(fd,packet_len(0x19a));
  4102. } else {
  4103. unsigned char buf[32];
  4104. WBUFW(buf,0) = 0x19a;
  4105. WBUFL(buf,2) = sd->bl.id;
  4106. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4107. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4108. else
  4109. WBUFL(buf,6) = pvprank;
  4110. WBUFL(buf,10) = pvpnum;
  4111. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4112. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4113. else if(!type)
  4114. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4115. else
  4116. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4117. }
  4118. return 0;
  4119. }
  4120. /*==========================================
  4121. *
  4122. *------------------------------------------*/
  4123. int clif_send0199(int map,int type)
  4124. {
  4125. struct block_list bl;
  4126. unsigned char buf[16];
  4127. bl.id = 0;
  4128. bl.type = BL_NUL;
  4129. bl.m = map;
  4130. WBUFW(buf,0)=0x199;
  4131. WBUFW(buf,2)=type;
  4132. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4133. return 0;
  4134. }
  4135. /*==========================================
  4136. * 精錬エフェクトを送信する
  4137. *------------------------------------------*/
  4138. void clif_refine(int fd, int fail, int index, int val)
  4139. {
  4140. WFIFOHEAD(fd,packet_len(0x188));
  4141. WFIFOW(fd,0)=0x188;
  4142. WFIFOW(fd,2)=fail;
  4143. WFIFOW(fd,4)=index+2;
  4144. WFIFOW(fd,6)=val;
  4145. WFIFOSET(fd,packet_len(0x188));
  4146. }
  4147. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4148. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4149. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4150. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4151. void clif_upgrademessage(int fd, int result, int item_id)
  4152. {
  4153. WFIFOHEAD(fd,packet_len(0x223));
  4154. WFIFOW(fd,0)=0x223;
  4155. WFIFOL(fd,2)=result;
  4156. WFIFOW(fd,6)=item_id;
  4157. WFIFOSET(fd,packet_len(0x223));
  4158. }
  4159. /*==========================================
  4160. * Wisp/page is transmitted to the destination player
  4161. * R 0097 <len>.w <nick>.24B <message>.?B
  4162. *------------------------------------------*/
  4163. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4164. {
  4165. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4166. WFIFOW(fd,0) = 0x97;
  4167. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4168. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4169. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4170. WFIFOSET(fd,WFIFOW(fd,2));
  4171. return 0;
  4172. }
  4173. /*==========================================
  4174. * Inform the player about the result of his whisper action
  4175. * R 0098 <type>.B
  4176. * 0: success to send wisper
  4177. * 1: target character is not loged in
  4178. * 2: ignored by target
  4179. * 3: everyone ignored by target
  4180. *------------------------------------------*/
  4181. int clif_wis_end(int fd, int flag)
  4182. {
  4183. WFIFOHEAD(fd,packet_len(0x98));
  4184. WFIFOW(fd,0) = 0x98;
  4185. WFIFOW(fd,2) = flag;
  4186. WFIFOSET(fd,packet_len(0x98));
  4187. return 0;
  4188. }
  4189. /*==========================================
  4190. * キャラID名前引き結果を送信する
  4191. *------------------------------------------*/
  4192. int clif_solved_charname(int fd, int charid, const char* name)
  4193. {
  4194. WFIFOHEAD(fd,packet_len(0x194));
  4195. WFIFOW(fd,0)=0x194;
  4196. WFIFOL(fd,2)=charid;
  4197. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4198. WFIFOSET(fd,packet_len(0x194));
  4199. return 0;
  4200. }
  4201. /*==========================================
  4202. * カードの挿入可能リストを返す
  4203. *------------------------------------------*/
  4204. int clif_use_card(struct map_session_data *sd,int idx)
  4205. {
  4206. int i,c,ep;
  4207. int fd=sd->fd;
  4208. nullpo_retr(0, sd);
  4209. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4210. return 0;
  4211. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4212. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4213. ep=sd->inventory_data[idx]->equip;
  4214. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4215. WFIFOW(fd,0)=0x017b;
  4216. for(i=c=0;i<MAX_INVENTORY;i++){
  4217. int j;
  4218. if(sd->inventory_data[i] == NULL)
  4219. continue;
  4220. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4221. continue;
  4222. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4223. continue;
  4224. if(sd->status.inventory[i].identify==0 ) //Not identified
  4225. continue;
  4226. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4227. continue;
  4228. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4229. continue;
  4230. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4231. if( j == sd->inventory_data[i]->slot ) // No room
  4232. continue;
  4233. WFIFOW(fd,4+c*2)=i+2;
  4234. c++;
  4235. }
  4236. WFIFOW(fd,2)=4+c*2;
  4237. WFIFOSET(fd,WFIFOW(fd,2));
  4238. return 0;
  4239. }
  4240. /*==========================================
  4241. * カードの挿入終了
  4242. *------------------------------------------*/
  4243. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4244. {
  4245. int fd;
  4246. nullpo_retr(0, sd);
  4247. fd=sd->fd;
  4248. WFIFOHEAD(fd,packet_len(0x17d));
  4249. WFIFOW(fd,0)=0x17d;
  4250. WFIFOW(fd,2)=idx_equip+2;
  4251. WFIFOW(fd,4)=idx_card+2;
  4252. WFIFOB(fd,6)=flag;
  4253. WFIFOSET(fd,packet_len(0x17d));
  4254. return 0;
  4255. }
  4256. /*==========================================
  4257. * 鑑定可能アイテムリスト送信
  4258. *------------------------------------------*/
  4259. int clif_item_identify_list(struct map_session_data *sd)
  4260. {
  4261. int i,c;
  4262. int fd;
  4263. nullpo_retr(0, sd);
  4264. fd=sd->fd;
  4265. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4266. WFIFOW(fd,0)=0x177;
  4267. for(i=c=0;i<MAX_INVENTORY;i++){
  4268. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4269. WFIFOW(fd,c*2+4)=i+2;
  4270. c++;
  4271. }
  4272. }
  4273. if(c > 0) {
  4274. WFIFOW(fd,2)=c*2+4;
  4275. WFIFOSET(fd,WFIFOW(fd,2));
  4276. sd->menuskill_id = MC_IDENTIFY;
  4277. sd->menuskill_val = c;
  4278. }
  4279. return 0;
  4280. }
  4281. /*==========================================
  4282. * 鑑定結果
  4283. *------------------------------------------*/
  4284. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4285. {
  4286. int fd;
  4287. nullpo_retr(0, sd);
  4288. fd=sd->fd;
  4289. WFIFOHEAD(fd,packet_len(0x179));
  4290. WFIFOW(fd, 0)=0x179;
  4291. WFIFOW(fd, 2)=idx+2;
  4292. WFIFOB(fd, 4)=flag;
  4293. WFIFOSET(fd,packet_len(0x179));
  4294. return 0;
  4295. }
  4296. /*==========================================
  4297. * 修理可能アイテムリスト送信
  4298. *------------------------------------------*/
  4299. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4300. {
  4301. int i,c;
  4302. int fd;
  4303. int nameid;
  4304. nullpo_retr(0, sd);
  4305. nullpo_retr(0, dstsd);
  4306. fd=sd->fd;
  4307. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4308. WFIFOW(fd,0)=0x1fc;
  4309. for(i=c=0;i<MAX_INVENTORY;i++){
  4310. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4311. WFIFOW(fd,c*13+4) = i;
  4312. WFIFOW(fd,c*13+6) = nameid;
  4313. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4314. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4315. WFIFOB(fd,c*13+16)= c;
  4316. c++;
  4317. }
  4318. }
  4319. if(c > 0) {
  4320. WFIFOW(fd,2)=c*13+4;
  4321. WFIFOSET(fd,WFIFOW(fd,2));
  4322. sd->menuskill_id = BS_REPAIRWEAPON;
  4323. sd->menuskill_val = dstsd->bl.id;
  4324. }else
  4325. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4326. return 0;
  4327. }
  4328. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4329. {
  4330. int view,fd;
  4331. nullpo_retr(0, sd);
  4332. fd=sd->fd;
  4333. WFIFOHEAD(fd,packet_len(0x1fe));
  4334. WFIFOW(fd, 0)=0x1fe;
  4335. if((view = itemdb_viewid(nameid)) > 0)
  4336. WFIFOW(fd, 2)=view;
  4337. else
  4338. WFIFOW(fd, 2)=nameid;
  4339. WFIFOB(fd, 4)=flag;
  4340. WFIFOSET(fd,packet_len(0x1fe));
  4341. return 0;
  4342. }
  4343. /*==========================================
  4344. * Weapon Refining - Taken from jAthena
  4345. *------------------------------------------*/
  4346. int clif_item_refine_list(struct map_session_data *sd)
  4347. {
  4348. int i,c;
  4349. int fd;
  4350. int skilllv;
  4351. int wlv;
  4352. int refine_item[5];
  4353. nullpo_retr(0, sd);
  4354. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4355. fd=sd->fd;
  4356. refine_item[0] = -1;
  4357. refine_item[1] = pc_search_inventory(sd,1010);
  4358. refine_item[2] = pc_search_inventory(sd,1011);
  4359. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4360. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4361. WFIFOW(fd,0)=0x221;
  4362. for(i=c=0;i<MAX_INVENTORY;i++){
  4363. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4364. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4365. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4366. WFIFOW(fd,c*13+ 4)=i+2;
  4367. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4368. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4369. WFIFOW(fd,c*13+10)=0;
  4370. WFIFOB(fd,c*13+12)=c;
  4371. c++;
  4372. }
  4373. }
  4374. WFIFOW(fd,2)=c*13+4;
  4375. WFIFOSET(fd,WFIFOW(fd,2));
  4376. if (c > 0) {
  4377. sd->menuskill_id = WS_WEAPONREFINE;
  4378. sd->menuskill_val = skilllv;
  4379. }
  4380. return 0;
  4381. }
  4382. /*==========================================
  4383. * アイテムによる一時的なスキル効果
  4384. *------------------------------------------*/
  4385. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4386. {
  4387. int fd;
  4388. nullpo_retr(0, sd);
  4389. fd=sd->fd;
  4390. WFIFOHEAD(fd,packet_len(0x147));
  4391. WFIFOW(fd, 0)=0x147;
  4392. WFIFOW(fd, 2)=skillid;
  4393. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4394. WFIFOW(fd, 6)=0;
  4395. WFIFOW(fd, 8)=skilllv;
  4396. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4397. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4398. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4399. WFIFOB(fd,38)=0;
  4400. WFIFOSET(fd,packet_len(0x147));
  4401. return 0;
  4402. }
  4403. /*==========================================
  4404. * カートにアイテム追加
  4405. *------------------------------------------*/
  4406. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4407. {
  4408. int view,fd;
  4409. unsigned char *buf;
  4410. nullpo_retr(0, sd);
  4411. fd=sd->fd;
  4412. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4413. return 1;
  4414. #if PACKETVER < 5
  4415. WFIFOHEAD(fd,packet_len(0x124));
  4416. buf=WFIFOP(fd,0);
  4417. WBUFW(buf,0)=0x124;
  4418. WBUFW(buf,2)=n+2;
  4419. WBUFL(buf,4)=amount;
  4420. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4421. WBUFW(buf,8)=view;
  4422. else
  4423. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4424. WBUFB(buf,10)=sd->status.cart[n].identify;
  4425. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4426. WBUFB(buf,12)=sd->status.cart[n].refine;
  4427. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4428. WFIFOSET(fd,packet_len(0x124));
  4429. #else
  4430. WFIFOHEAD(fd,packet_len(0x1c5));
  4431. buf=WFIFOP(fd,0);
  4432. WBUFW(buf,0)=0x1c5;
  4433. WBUFW(buf,2)=n+2;
  4434. WBUFL(buf,4)=amount;
  4435. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4436. WBUFW(buf,8)=view;
  4437. else
  4438. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4439. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4440. WBUFB(buf,11)=sd->status.cart[n].identify;
  4441. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4442. WBUFB(buf,13)=sd->status.cart[n].refine;
  4443. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4444. WFIFOSET(fd,packet_len(0x1c5));
  4445. #endif
  4446. return 0;
  4447. }
  4448. /*==========================================
  4449. * カートからアイテム削除
  4450. *------------------------------------------*/
  4451. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4452. {
  4453. int fd;
  4454. nullpo_retr(0, sd);
  4455. fd=sd->fd;
  4456. WFIFOHEAD(fd,packet_len(0x125));
  4457. WFIFOW(fd,0)=0x125;
  4458. WFIFOW(fd,2)=n+2;
  4459. WFIFOL(fd,4)=amount;
  4460. WFIFOSET(fd,packet_len(0x125));
  4461. return 0;
  4462. }
  4463. /*==========================================
  4464. * Opens the shop creation menu.
  4465. * R 012d <num>.w
  4466. * 'num' is the number of allowed item slots
  4467. *------------------------------------------*/
  4468. void clif_openvendingreq(struct map_session_data* sd, int num)
  4469. {
  4470. int fd;
  4471. nullpo_retv(sd);
  4472. fd = sd->fd;
  4473. WFIFOHEAD(fd,packet_len(0x12d));
  4474. WFIFOW(fd,0) = 0x12d;
  4475. WFIFOW(fd,2) = num;
  4476. WFIFOSET(fd,packet_len(0x12d));
  4477. }
  4478. /*==========================================
  4479. * Displays a vending board to target/area
  4480. * R 0131 <ID>.l <message>.80B
  4481. *------------------------------------------*/
  4482. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4483. {
  4484. unsigned char buf[128];
  4485. nullpo_retv(bl);
  4486. WBUFW(buf,0) = 0x131;
  4487. WBUFL(buf,2) = bl->id;
  4488. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4489. if( fd ) {
  4490. WFIFOHEAD(fd,packet_len(0x131));
  4491. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4492. WFIFOSET(fd,packet_len(0x131));
  4493. } else {
  4494. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4495. }
  4496. }
  4497. /*==========================================
  4498. * Removes a vending board from screen
  4499. *------------------------------------------*/
  4500. void clif_closevendingboard(struct block_list* bl, int fd)
  4501. {
  4502. unsigned char buf[16];
  4503. nullpo_retv(bl);
  4504. WBUFW(buf,0) = 0x132;
  4505. WBUFL(buf,2) = bl->id;
  4506. if( fd ) {
  4507. WFIFOHEAD(fd,packet_len(0x132));
  4508. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4509. WFIFOSET(fd,packet_len(0x132));
  4510. } else {
  4511. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4512. }
  4513. }
  4514. /*==========================================
  4515. * Sends a list of items in a shop
  4516. * R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  4517. *------------------------------------------*/
  4518. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4519. {
  4520. int i,fd;
  4521. int count;
  4522. struct map_session_data* vsd;
  4523. nullpo_retv(sd);
  4524. nullpo_retv(vending);
  4525. nullpo_retv(vsd=map_id2sd(id));
  4526. fd = sd->fd;
  4527. count = vsd->vend_num;
  4528. WFIFOHEAD(fd, 8+count*22);
  4529. WFIFOW(fd,0) = 0x133;
  4530. WFIFOW(fd,2) = 8+count*22;
  4531. WFIFOL(fd,4) = id;
  4532. for( i = 0; i < count; i++ )
  4533. {
  4534. int index = vending[i].index;
  4535. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4536. WFIFOL(fd, 8+i*22) = vending[i].value;
  4537. WFIFOW(fd,12+i*22) = vending[i].amount;
  4538. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4539. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4540. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4541. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4542. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4543. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4544. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4545. }
  4546. WFIFOSET(fd,WFIFOW(fd,2));
  4547. }
  4548. /*==========================================
  4549. * Shop purchase failure
  4550. * R 0135 <index>.w <amount>.w <fail>.B
  4551. * fail=1 - not enough zeny
  4552. * fail=2 - overweight
  4553. * fail=4 - out of stock
  4554. * fail=5 - "cannot use an npc shop while in a trade"
  4555. *------------------------------------------*/
  4556. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4557. {
  4558. int fd;
  4559. nullpo_retv(sd);
  4560. fd = sd->fd;
  4561. WFIFOHEAD(fd,packet_len(0x135));
  4562. WFIFOW(fd,0) = 0x135;
  4563. WFIFOW(fd,2) = index+2;
  4564. WFIFOW(fd,4) = amount;
  4565. WFIFOB(fd,6) = fail;
  4566. WFIFOSET(fd,packet_len(0x135));
  4567. }
  4568. /*==========================================
  4569. * Shop creation success
  4570. * R 0136 <len>.w <ID>.l {<value>.l <index>.w <amount>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B*
  4571. *------------------------------------------*/
  4572. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4573. {
  4574. int i,fd;
  4575. int count;
  4576. nullpo_retv(sd);
  4577. fd = sd->fd;
  4578. count = sd->vend_num;
  4579. WFIFOHEAD(fd, 8+count*22);
  4580. WFIFOW(fd,0) = 0x136;
  4581. WFIFOW(fd,2) = 8+count*22;
  4582. WFIFOL(fd,4) = id;
  4583. for( i = 0; i < count; i++ )
  4584. {
  4585. int index = vending[i].index;
  4586. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4587. WFIFOL(fd, 8+i*22) = vending[i].value;
  4588. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4589. WFIFOW(fd,14+i*22) = vending[i].amount;
  4590. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4591. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4592. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4593. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4594. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4595. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4596. }
  4597. WFIFOSET(fd,WFIFOW(fd,2));
  4598. }
  4599. /*==========================================
  4600. * Inform merchant that someone has bought an item.
  4601. * R 0137 <index>.w <amount>.w
  4602. *------------------------------------------*/
  4603. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4604. {
  4605. int fd;
  4606. nullpo_retv(sd);
  4607. fd = sd->fd;
  4608. WFIFOHEAD(fd,packet_len(0x137));
  4609. WFIFOW(fd,0) = 0x137;
  4610. WFIFOW(fd,2) = index+2;
  4611. WFIFOW(fd,4) = amount;
  4612. WFIFOSET(fd,packet_len(0x137));
  4613. }
  4614. /// Result of organizing a party.
  4615. /// R 00FA <result>.B
  4616. ///
  4617. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4618. /// result=1 : MsgStringTable[78]="party name already exists"
  4619. /// result=2 : MsgStringTable[79]="already in a party"
  4620. /// result=other : nothing
  4621. int clif_party_created(struct map_session_data *sd,int result)
  4622. {
  4623. int fd;
  4624. nullpo_retr(0, sd);
  4625. fd=sd->fd;
  4626. WFIFOHEAD(fd,packet_len(0xfa));
  4627. WFIFOW(fd,0)=0xfa;
  4628. WFIFOB(fd,2)=result;
  4629. WFIFOSET(fd,packet_len(0xfa));
  4630. return 0;
  4631. }
  4632. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4633. {
  4634. unsigned char buf[96];
  4635. int i;
  4636. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4637. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4638. } else {
  4639. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4640. }
  4641. if (i >= MAX_PARTY) return 0; //Should never happen...
  4642. sd = p->data[i].sd;
  4643. WBUFW(buf, 0) = 0x1e9;
  4644. WBUFL(buf, 2) = sd->status.account_id;
  4645. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4646. WBUFW(buf,10) = sd->bl.x;
  4647. WBUFW(buf,12) = sd->bl.y;
  4648. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4649. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4650. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4651. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4652. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4653. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4654. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4655. return 1;
  4656. }
  4657. /*==========================================
  4658. * Sends party information
  4659. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4660. *------------------------------------------*/
  4661. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4662. {
  4663. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4664. struct map_session_data* party_sd = NULL;
  4665. int i, c;
  4666. nullpo_retr(0, p);
  4667. WBUFW(buf,0) = 0xfb;
  4668. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4669. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4670. {
  4671. struct party_member* m = &p->party.member[i];
  4672. if(!m->account_id) continue;
  4673. if(party_sd == NULL) party_sd = p->data[i].sd;
  4674. WBUFL(buf,28+c*46) = m->account_id;
  4675. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4676. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4677. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4678. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4679. c++;
  4680. }
  4681. WBUFW(buf,2) = 28+c*46;
  4682. if(sd) { // send only to self
  4683. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4684. } else if (party_sd) { // send to whole party
  4685. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4686. }
  4687. return 0;
  4688. }
  4689. /*==========================================
  4690. * パーティ勧誘
  4691. *------------------------------------------*/
  4692. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4693. {
  4694. int fd;
  4695. struct party_data *p;
  4696. nullpo_retr(0, sd);
  4697. nullpo_retr(0, tsd);
  4698. fd=tsd->fd;
  4699. if( (p=party_search(sd->status.party_id))==NULL )
  4700. return 0;
  4701. WFIFOHEAD(fd,packet_len(0xfe));
  4702. WFIFOW(fd,0)=0xfe;
  4703. WFIFOL(fd,2)=sd->status.account_id;
  4704. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4705. WFIFOSET(fd,packet_len(0xfe));
  4706. return 0;
  4707. }
  4708. /*==========================================
  4709. * Party invitation result.
  4710. * R 00fd <nick>.24S <flag>.B
  4711. * R 02c5 <nick>.24S <flag>.L
  4712. * Flag values are:
  4713. * 0 -> char is already in a party
  4714. * 1 -> party invite was rejected
  4715. * 2 -> party invite was accepted
  4716. * 3 -> party is full
  4717. * 4 -> char of the same account already joined the party
  4718. *------------------------------------------*/
  4719. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4720. {
  4721. int fd;
  4722. nullpo_retv(sd);
  4723. fd=sd->fd;
  4724. #if PACKETVER < 20070821
  4725. WFIFOHEAD(fd,packet_len(0xfd));
  4726. WFIFOW(fd,0) = 0xfd;
  4727. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4728. WFIFOB(fd,26) = flag;
  4729. WFIFOSET(fd,packet_len(0xfd));
  4730. #else
  4731. WFIFOHEAD(fd,packet_len(0x2c5));
  4732. WFIFOW(fd,0) = 0x2c5;
  4733. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4734. WFIFOL(fd,26) = flag;
  4735. WFIFOSET(fd,packet_len(0x2c5));
  4736. #endif
  4737. }
  4738. /*==========================================
  4739. * パーティ設定送信
  4740. * flag & 0x001=exp変更ミス
  4741. * 0x010=item変更ミス
  4742. * 0x100=一人にのみ送信
  4743. *------------------------------------------*/
  4744. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4745. {
  4746. unsigned char buf[16];
  4747. nullpo_retr(0, p);
  4748. if(!sd && flag==0){
  4749. int i;
  4750. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4751. if (i < MAX_PARTY)
  4752. sd = p->data[i].sd;
  4753. }
  4754. if(!sd) return 0;
  4755. WBUFW(buf,0)=0x101;
  4756. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4757. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4758. WBUFW(buf,4)=0;
  4759. if(flag==0)
  4760. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4761. else
  4762. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4763. return 0;
  4764. }
  4765. /*==========================================
  4766. * パーティ脱退(脱退前に呼ぶこと)
  4767. *------------------------------------------*/
  4768. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4769. {
  4770. unsigned char buf[64];
  4771. int i;
  4772. nullpo_retr(0, p);
  4773. if(!sd && (flag&0xf0)==0)
  4774. {
  4775. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4776. if (i < MAX_PARTY)
  4777. sd = p->data[i].sd;
  4778. }
  4779. if(!sd) return 0;
  4780. WBUFW(buf,0)=0x105;
  4781. WBUFL(buf,2)=account_id;
  4782. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4783. WBUFB(buf,30)=flag&0x0f;
  4784. if((flag&0xf0)==0)
  4785. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4786. else
  4787. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4788. return 0;
  4789. }
  4790. /*==========================================
  4791. * パーティメッセージ送信
  4792. *------------------------------------------*/
  4793. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4794. {
  4795. struct map_session_data *sd;
  4796. int i;
  4797. nullpo_retr(0, p);
  4798. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4799. if(i < MAX_PARTY){
  4800. unsigned char buf[1024];
  4801. sd = p->data[i].sd;
  4802. WBUFW(buf,0)=0x109;
  4803. WBUFW(buf,2)=len+8;
  4804. WBUFL(buf,4)=account_id;
  4805. memcpy(WBUFP(buf,8),mes,len);
  4806. clif_send(buf,len+8,&sd->bl,PARTY);
  4807. }
  4808. return 0;
  4809. }
  4810. /*==========================================
  4811. * パーティ座標通知
  4812. *------------------------------------------*/
  4813. int clif_party_xy(struct map_session_data *sd)
  4814. {
  4815. unsigned char buf[16];
  4816. nullpo_retr(0, sd);
  4817. WBUFW(buf,0)=0x107;
  4818. WBUFL(buf,2)=sd->status.account_id;
  4819. WBUFW(buf,6)=sd->bl.x;
  4820. WBUFW(buf,8)=sd->bl.y;
  4821. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4822. return 0;
  4823. }
  4824. /*==========================================
  4825. * Sends x/y dot to a single fd. [Skotlex]
  4826. *------------------------------------------*/
  4827. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4828. {
  4829. WFIFOHEAD(fd,packet_len(0x107));
  4830. WFIFOW(fd,0)=0x107;
  4831. WFIFOL(fd,2)=sd->status.account_id;
  4832. WFIFOW(fd,6)=sd->bl.x;
  4833. WFIFOW(fd,8)=sd->bl.y;
  4834. WFIFOSET(fd,packet_len(0x107));
  4835. return 0;
  4836. }
  4837. /*==========================================
  4838. * パーティHP通知
  4839. *------------------------------------------*/
  4840. int clif_party_hp(struct map_session_data *sd)
  4841. {
  4842. unsigned char buf[16];
  4843. nullpo_retr(0, sd);
  4844. WBUFW(buf,0)=0x106;
  4845. WBUFL(buf,2)=sd->status.account_id;
  4846. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4847. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4848. WBUFW(buf,8) = 100;
  4849. } else {
  4850. WBUFW(buf,6) = sd->battle_status.hp;
  4851. WBUFW(buf,8) = sd->battle_status.max_hp;
  4852. }
  4853. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4854. return 0;
  4855. }
  4856. /*==========================================
  4857. * Sends HP bar to a single fd. [Skotlex]
  4858. *------------------------------------------*/
  4859. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4860. {
  4861. WFIFOHEAD(fd,packet_len(0x106));
  4862. WFIFOW(fd,0) = 0x106;
  4863. WFIFOL(fd,2) = id;
  4864. if( maxhp > SHRT_MAX )
  4865. {// To correctly display the %hp bar. [Skotlex]
  4866. WFIFOW(fd,6) = hp/(maxhp/100);
  4867. WFIFOW(fd,8) = 100;
  4868. } else {
  4869. WFIFOW(fd,6) = hp;
  4870. WFIFOW(fd,8) = maxhp;
  4871. }
  4872. WFIFOSET(fd, packet_len(0x106));
  4873. }
  4874. /*==========================================
  4875. * GMへ場所とHP通知
  4876. *------------------------------------------*/
  4877. int clif_hpmeter(struct map_session_data *sd)
  4878. {
  4879. struct map_session_data *sd2;
  4880. unsigned char buf[16];
  4881. int i, x0, y0, x1, y1;
  4882. int level;
  4883. nullpo_retr(0, sd);
  4884. x0 = sd->bl.x - AREA_SIZE;
  4885. y0 = sd->bl.y - AREA_SIZE;
  4886. x1 = sd->bl.x + AREA_SIZE;
  4887. y1 = sd->bl.y + AREA_SIZE;
  4888. WBUFW(buf,0) = 0x106;
  4889. WBUFL(buf,2) = sd->status.account_id;
  4890. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4891. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4892. WBUFW(buf,8) = 100;
  4893. } else {
  4894. WBUFW(buf,6) = sd->battle_status.hp;
  4895. WBUFW(buf,8) = sd->battle_status.max_hp;
  4896. }
  4897. for (i = 0; i < fd_max; i++) {
  4898. if (session[i] && session[i]->func_parse == clif_parse &&
  4899. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4900. sd != sd2 && sd2->state.active) {
  4901. if (sd2->bl.m != sd->bl.m ||
  4902. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4903. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4904. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4905. level < pc_isGM(sd))
  4906. continue;
  4907. WFIFOHEAD (i, packet_len(0x106));
  4908. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4909. WFIFOSET (i, packet_len(0x106));
  4910. }
  4911. }
  4912. return 0;
  4913. }
  4914. /*==========================================
  4915. * パーティ場所移動(未使用)
  4916. *------------------------------------------*/
  4917. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4918. {
  4919. unsigned char buf[128];
  4920. nullpo_retv(sd);
  4921. nullpo_retv(p);
  4922. WBUFW(buf, 0) = 0x104;
  4923. WBUFL(buf, 2) = sd->status.account_id;
  4924. WBUFL(buf, 6) = 0;
  4925. WBUFW(buf,10) = sd->bl.x;
  4926. WBUFW(buf,12) = sd->bl.y;
  4927. WBUFB(buf,14) = !online;
  4928. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4929. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4930. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4931. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4932. }
  4933. /*==========================================
  4934. * 攻撃するために移動が必要
  4935. *------------------------------------------*/
  4936. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4937. {
  4938. int fd;
  4939. nullpo_retr(0, sd);
  4940. nullpo_retr(0, bl);
  4941. fd=sd->fd;
  4942. WFIFOHEAD(fd,packet_len(0x139));
  4943. WFIFOW(fd, 0)=0x139;
  4944. WFIFOL(fd, 2)=bl->id;
  4945. WFIFOW(fd, 6)=bl->x;
  4946. WFIFOW(fd, 8)=bl->y;
  4947. WFIFOW(fd,10)=sd->bl.x;
  4948. WFIFOW(fd,12)=sd->bl.y;
  4949. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4950. WFIFOSET(fd,packet_len(0x139));
  4951. return 0;
  4952. }
  4953. /*==========================================
  4954. * 製造エフェクト
  4955. *------------------------------------------*/
  4956. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4957. {
  4958. int view,fd;
  4959. nullpo_retr(0, sd);
  4960. fd = sd->fd;
  4961. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4962. WFIFOHEAD(fd,packet_len(0x18f));
  4963. WFIFOW(fd, 0)=0x18f;
  4964. WFIFOW(fd, 2)=flag;
  4965. if((view = itemdb_viewid(nameid)) > 0)
  4966. WFIFOW(fd, 4)=view;
  4967. else
  4968. WFIFOW(fd, 4)=nameid;
  4969. WFIFOSET(fd,packet_len(0x18f));
  4970. return 0;
  4971. }
  4972. // pet
  4973. int clif_catch_process(struct map_session_data *sd)
  4974. {
  4975. int fd;
  4976. nullpo_retr(0, sd);
  4977. fd=sd->fd;
  4978. WFIFOHEAD(fd,packet_len(0x19e));
  4979. WFIFOW(fd,0)=0x19e;
  4980. WFIFOSET(fd,packet_len(0x19e));
  4981. return 0;
  4982. }
  4983. int clif_pet_roulette(struct map_session_data *sd,int data)
  4984. {
  4985. int fd;
  4986. nullpo_retr(0, sd);
  4987. fd=sd->fd;
  4988. WFIFOHEAD(fd,packet_len(0x1a0));
  4989. WFIFOW(fd,0)=0x1a0;
  4990. WFIFOB(fd,2)=data;
  4991. WFIFOSET(fd,packet_len(0x1a0));
  4992. return 0;
  4993. }
  4994. /*==========================================
  4995. * pet卵リスト作成
  4996. *------------------------------------------*/
  4997. int clif_sendegg(struct map_session_data *sd)
  4998. {
  4999. //R 01a6 <len>.w <index>.w*
  5000. int i,n=0,fd;
  5001. nullpo_retr(0, sd);
  5002. fd=sd->fd;
  5003. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5004. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5005. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5006. return 0;
  5007. }
  5008. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5009. WFIFOW(fd,0)=0x1a6;
  5010. if(sd->status.pet_id <= 0) {
  5011. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5012. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5013. sd->inventory_data[i]->type!=IT_PETEGG ||
  5014. sd->status.inventory[i].amount<=0)
  5015. continue;
  5016. WFIFOW(fd,n*2+4)=i+2;
  5017. n++;
  5018. }
  5019. }
  5020. WFIFOW(fd,2)=4+n*2;
  5021. WFIFOSET(fd,WFIFOW(fd,2));
  5022. sd->menuskill_id = SA_TAMINGMONSTER;
  5023. sd->menuskill_val = -1;
  5024. return 0;
  5025. }
  5026. /*==========================================
  5027. * Sends a specific pet data update.
  5028. * type = 0 -> param = 0 (initial data)
  5029. * type = 1 -> param = intimacy value
  5030. * type = 2 -> param = hungry value
  5031. * type = 3 -> param = accessory id
  5032. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5033. * type = 5 -> param = hairstyle number
  5034. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5035. *------------------------------------------*/
  5036. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5037. {
  5038. uint8 buf[16];
  5039. nullpo_retr(0, pd);
  5040. WBUFW(buf,0) = 0x1a4;
  5041. WBUFB(buf,2) = type;
  5042. WBUFL(buf,3) = pd->bl.id;
  5043. WBUFL(buf,7) = param;
  5044. if (sd)
  5045. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5046. else
  5047. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5048. return 0;
  5049. }
  5050. int clif_send_petstatus(struct map_session_data *sd)
  5051. {
  5052. int fd;
  5053. struct s_pet *pet;
  5054. nullpo_retr(0, sd);
  5055. nullpo_retr(0, sd->pd);
  5056. fd=sd->fd;
  5057. pet = &sd->pd->pet;
  5058. WFIFOHEAD(fd,packet_len(0x1a2));
  5059. WFIFOW(fd,0)=0x1a2;
  5060. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5061. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5062. WFIFOW(fd,27)=pet->level;
  5063. WFIFOW(fd,29)=pet->hungry;
  5064. WFIFOW(fd,31)=pet->intimate;
  5065. WFIFOW(fd,33)=pet->equip;
  5066. WFIFOSET(fd,packet_len(0x1a2));
  5067. return 0;
  5068. }
  5069. /*==========================================
  5070. *
  5071. *------------------------------------------*/
  5072. int clif_pet_emotion(struct pet_data *pd,int param)
  5073. {
  5074. unsigned char buf[16];
  5075. nullpo_retr(0, pd);
  5076. memset(buf,0,packet_len(0x1aa));
  5077. WBUFW(buf,0)=0x1aa;
  5078. WBUFL(buf,2)=pd->bl.id;
  5079. if(param >= 100 && pd->petDB->talk_convert_class) {
  5080. if(pd->petDB->talk_convert_class < 0)
  5081. return 0;
  5082. else if(pd->petDB->talk_convert_class > 0) {
  5083. param -= (pd->pet.class_ - 100)*100;
  5084. param += (pd->petDB->talk_convert_class - 100)*100;
  5085. }
  5086. }
  5087. WBUFL(buf,6)=param;
  5088. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5089. return 0;
  5090. }
  5091. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5092. {
  5093. int fd;
  5094. nullpo_retr(0, sd);
  5095. fd=sd->fd;
  5096. WFIFOHEAD(fd,packet_len(0x1a3));
  5097. WFIFOW(fd,0)=0x1a3;
  5098. WFIFOB(fd,2)=fail;
  5099. WFIFOW(fd,3)=foodid;
  5100. WFIFOSET(fd,packet_len(0x1a3));
  5101. return 0;
  5102. }
  5103. /*==========================================
  5104. * オートスペル リスト送信
  5105. *------------------------------------------*/
  5106. int clif_autospell(struct map_session_data *sd,int skilllv)
  5107. {
  5108. int fd;
  5109. nullpo_retr(0, sd);
  5110. fd=sd->fd;
  5111. WFIFOHEAD(fd,packet_len(0x1cd));
  5112. WFIFOW(fd, 0)=0x1cd;
  5113. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5114. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5115. else
  5116. WFIFOL(fd,2)= 0x00000000;
  5117. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5118. WFIFOL(fd,6)= MG_COLDBOLT;
  5119. else
  5120. WFIFOL(fd,6)= 0x00000000;
  5121. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5122. WFIFOL(fd,10)= MG_FIREBOLT;
  5123. else
  5124. WFIFOL(fd,10)= 0x00000000;
  5125. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5126. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5127. else
  5128. WFIFOL(fd,14)= 0x00000000;
  5129. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5130. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5131. else
  5132. WFIFOL(fd,18)= 0x00000000;
  5133. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5134. WFIFOL(fd,22)= MG_FIREBALL;
  5135. else
  5136. WFIFOL(fd,22)= 0x00000000;
  5137. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5138. WFIFOL(fd,26)= MG_FROSTDIVER;
  5139. else
  5140. WFIFOL(fd,26)= 0x00000000;
  5141. WFIFOSET(fd,packet_len(0x1cd));
  5142. sd->menuskill_id = SA_AUTOSPELL;
  5143. sd->menuskill_val = skilllv;
  5144. return 0;
  5145. }
  5146. /*==========================================
  5147. * Devotion's visual effect
  5148. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5149. *------------------------------------------*/
  5150. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5151. {
  5152. unsigned char buf[56];
  5153. int i;
  5154. nullpo_retv(src);
  5155. memset(buf,0,packet_len(0x1cf));
  5156. WBUFW(buf,0) = 0x1cf;
  5157. WBUFL(buf,2) = src->id;
  5158. if( src->type == BL_MER )
  5159. {
  5160. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5161. if( md && md->master && md->devotion_flag )
  5162. WBUFL(buf,6) = md->master->bl.id;
  5163. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5164. }
  5165. else
  5166. {
  5167. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5168. if( sd == NULL )
  5169. return;
  5170. for( i = 0; i < 5; i++ )
  5171. WBUFL(buf,6+4*i) = sd->devotion[i];
  5172. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5173. }
  5174. if( tsd )
  5175. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5176. else
  5177. clif_send(buf, packet_len(0x1cf), src, AREA);
  5178. }
  5179. /*==========================================
  5180. * 氣球
  5181. *------------------------------------------*/
  5182. int clif_spiritball(struct map_session_data *sd)
  5183. {
  5184. unsigned char buf[16];
  5185. nullpo_retr(0, sd);
  5186. WBUFW(buf,0)=0x1d0;
  5187. WBUFL(buf,2)=sd->bl.id;
  5188. WBUFW(buf,6)=sd->spiritball;
  5189. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5190. return 0;
  5191. }
  5192. /*==========================================
  5193. *
  5194. *------------------------------------------*/
  5195. int clif_combo_delay(struct block_list *bl,int wait)
  5196. {
  5197. unsigned char buf[32];
  5198. nullpo_retr(0, bl);
  5199. WBUFW(buf,0)=0x1d2;
  5200. WBUFL(buf,2)=bl->id;
  5201. WBUFL(buf,6)=wait;
  5202. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5203. return 0;
  5204. }
  5205. /*==========================================
  5206. *白刃取り
  5207. *------------------------------------------*/
  5208. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5209. {
  5210. unsigned char buf[32];
  5211. nullpo_retr(0, src);
  5212. WBUFW(buf,0)=0x1d1;
  5213. WBUFL(buf,2)=src->id;
  5214. WBUFL(buf,6)=dst_id;
  5215. WBUFL(buf,10)=active;
  5216. clif_send(buf,packet_len(0x1d1),src,AREA);
  5217. }
  5218. /*==========================================
  5219. * MVPエフェクト
  5220. *------------------------------------------*/
  5221. int clif_mvp_effect(struct map_session_data *sd)
  5222. {
  5223. unsigned char buf[16];
  5224. nullpo_retr(0, sd);
  5225. WBUFW(buf,0)=0x10c;
  5226. WBUFL(buf,2)=sd->bl.id;
  5227. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5228. return 0;
  5229. }
  5230. /*==========================================
  5231. * MVPアイテム所得
  5232. *------------------------------------------*/
  5233. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5234. {
  5235. int view,fd;
  5236. nullpo_retr(0, sd);
  5237. fd=sd->fd;
  5238. WFIFOHEAD(fd,packet_len(0x10a));
  5239. WFIFOW(fd,0)=0x10a;
  5240. if((view = itemdb_viewid(nameid)) > 0)
  5241. WFIFOW(fd,2)=view;
  5242. else
  5243. WFIFOW(fd,2)=nameid;
  5244. WFIFOSET(fd,packet_len(0x10a));
  5245. return 0;
  5246. }
  5247. /*==========================================
  5248. * MVP経験値所得
  5249. *------------------------------------------*/
  5250. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5251. {
  5252. int fd;
  5253. nullpo_retr(0, sd);
  5254. fd=sd->fd;
  5255. WFIFOHEAD(fd,packet_len(0x10b));
  5256. WFIFOW(fd,0)=0x10b;
  5257. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5258. WFIFOSET(fd,packet_len(0x10b));
  5259. return 0;
  5260. }
  5261. /*==========================================
  5262. * Guild creation result
  5263. * R 0167 <flag>.B
  5264. * flag = 0 -> "Guild has been created."
  5265. * flag = 1 -> "You are already in a Guild."
  5266. * flag = 2 -> "That Guild Name already exists."
  5267. * flag = 3 -> "You need the neccessary item to create a Guild."
  5268. *------------------------------------------*/
  5269. int clif_guild_created(struct map_session_data *sd,int flag)
  5270. {
  5271. int fd;
  5272. nullpo_retr(0, sd);
  5273. fd=sd->fd;
  5274. WFIFOHEAD(fd,packet_len(0x167));
  5275. WFIFOW(fd,0)=0x167;
  5276. WFIFOB(fd,2)=flag;
  5277. WFIFOSET(fd,packet_len(0x167));
  5278. return 0;
  5279. }
  5280. /*==========================================
  5281. * ギルド所属通知
  5282. *------------------------------------------*/
  5283. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5284. {
  5285. int ps,fd;
  5286. nullpo_retr(0, sd);
  5287. nullpo_retr(0, g);
  5288. fd=sd->fd;
  5289. ps=guild_getposition(g,sd);
  5290. WFIFOHEAD(fd,packet_len(0x16c));
  5291. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5292. WFIFOW(fd,0)=0x16c;
  5293. WFIFOL(fd,2)=g->guild_id;
  5294. WFIFOL(fd,6)=g->emblem_id;
  5295. WFIFOL(fd,10)=g->position[ps].mode;
  5296. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5297. WFIFOSET(fd,packet_len(0x16c));
  5298. return 0;
  5299. }
  5300. /*==========================================
  5301. * ギルドメンバログイン通知
  5302. *------------------------------------------*/
  5303. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5304. {
  5305. unsigned char buf[64];
  5306. nullpo_retr(0, g);
  5307. WBUFW(buf, 0)=0x16d;
  5308. WBUFL(buf, 2)=g->member[idx].account_id;
  5309. WBUFL(buf, 6)=g->member[idx].char_id;
  5310. WBUFL(buf,10)=flag;
  5311. if(g->member[idx].sd==NULL){
  5312. struct map_session_data *sd=guild_getavailablesd(g);
  5313. if(sd!=NULL)
  5314. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5315. }else
  5316. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5317. return 0;
  5318. }
  5319. // Function `clif_guild_memberlogin_notice` sends info about
  5320. // logins and logouts of a guild member to the rest members.
  5321. // But at the 1st time (after a player login or map changing)
  5322. // the client won't show the message.
  5323. // So I suggest use this function for sending "first-time-info"
  5324. // to some player on entering the game or changing location.
  5325. // At next time the client would always show the message.
  5326. // The function sends all the statuses in the single packet
  5327. // to economize traffic. [LuzZza]
  5328. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5329. {
  5330. struct guild *g;
  5331. unsigned char buf[14*128];
  5332. int i, count=0, p_len;
  5333. nullpo_retr(0, sd);
  5334. p_len = packet_len(0x16d);
  5335. if(!(g = guild_search(sd->status.guild_id)))
  5336. return 0;
  5337. for(i=0; i<g->max_member; i++) {
  5338. if(g->member[i].account_id > 0 &&
  5339. g->member[i].account_id != sd->status.account_id) {
  5340. WBUFW(buf,count*p_len) = 0x16d;
  5341. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5342. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5343. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5344. count++;
  5345. }
  5346. }
  5347. clif_send(buf, p_len*count, &sd->bl, SELF);
  5348. return 0;
  5349. }
  5350. /*==========================================
  5351. * ギルドマスター通知(14dへの応答)
  5352. *------------------------------------------*/
  5353. int clif_guild_masterormember(struct map_session_data *sd)
  5354. {
  5355. int fd;
  5356. nullpo_retr(0, sd);
  5357. fd=sd->fd;
  5358. WFIFOHEAD(fd,packet_len(0x14e));
  5359. WFIFOW(fd,0) = 0x14e;
  5360. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5361. WFIFOSET(fd,packet_len(0x14e));
  5362. return 0;
  5363. }
  5364. /*==========================================
  5365. * Basic Info (Territories [Valaris])
  5366. *------------------------------------------*/
  5367. int clif_guild_basicinfo(struct map_session_data *sd)
  5368. {
  5369. int fd,i,t;
  5370. struct guild *g;
  5371. struct guild_castle *gc=NULL;
  5372. nullpo_retr(0, sd);
  5373. fd=sd->fd;
  5374. g=guild_search(sd->status.guild_id);
  5375. if(g==NULL)
  5376. return 0;
  5377. WFIFOHEAD(fd,packet_len(0x1b6));
  5378. WFIFOW(fd, 0)=0x1b6;//0x150;
  5379. WFIFOL(fd, 2)=g->guild_id;
  5380. WFIFOL(fd, 6)=g->guild_lv;
  5381. WFIFOL(fd,10)=g->connect_member;
  5382. WFIFOL(fd,14)=g->max_member;
  5383. WFIFOL(fd,18)=g->average_lv;
  5384. WFIFOL(fd,22)=g->exp;
  5385. WFIFOL(fd,26)=g->next_exp;
  5386. WFIFOL(fd,30)=0; // Tax Points
  5387. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5388. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5389. WFIFOL(fd,42)=g->emblem_id;
  5390. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5391. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5392. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5393. {
  5394. gc = guild_castle_search(i);
  5395. if(gc && g->guild_id == gc->guild_id)
  5396. t++;
  5397. }
  5398. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5399. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5400. return 0;
  5401. }
  5402. /*==========================================
  5403. * ギルド同盟/敵対情報
  5404. *------------------------------------------*/
  5405. int clif_guild_allianceinfo(struct map_session_data *sd)
  5406. {
  5407. int fd,i,c;
  5408. struct guild *g;
  5409. nullpo_retr(0, sd);
  5410. fd=sd->fd;
  5411. g=guild_search(sd->status.guild_id);
  5412. if(g==NULL)
  5413. return 0;
  5414. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5415. WFIFOW(fd, 0)=0x14c;
  5416. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5417. struct guild_alliance *a=&g->alliance[i];
  5418. if(a->guild_id>0){
  5419. WFIFOL(fd,c*32+4)=a->opposition;
  5420. WFIFOL(fd,c*32+8)=a->guild_id;
  5421. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5422. c++;
  5423. }
  5424. }
  5425. WFIFOW(fd, 2)=c*32+4;
  5426. WFIFOSET(fd,WFIFOW(fd,2));
  5427. return 0;
  5428. }
  5429. /*==========================================
  5430. * ギルドメンバーリスト
  5431. *------------------------------------------*/
  5432. int clif_guild_memberlist(struct map_session_data *sd)
  5433. {
  5434. int fd;
  5435. int i,c;
  5436. struct guild *g;
  5437. nullpo_retr(0, sd);
  5438. fd=sd->fd;
  5439. if (!fd)
  5440. return 0;
  5441. g=guild_search(sd->status.guild_id);
  5442. if(g==NULL)
  5443. return 0;
  5444. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5445. WFIFOW(fd, 0)=0x154;
  5446. for(i=0,c=0;i<g->max_member;i++){
  5447. struct guild_member *m=&g->member[i];
  5448. if(m->account_id==0)
  5449. continue;
  5450. WFIFOL(fd,c*104+ 4)=m->account_id;
  5451. WFIFOL(fd,c*104+ 8)=m->char_id;
  5452. WFIFOW(fd,c*104+12)=m->hair;
  5453. WFIFOW(fd,c*104+14)=m->hair_color;
  5454. WFIFOW(fd,c*104+16)=m->gender;
  5455. WFIFOW(fd,c*104+18)=m->class_;
  5456. WFIFOW(fd,c*104+20)=m->lv;
  5457. WFIFOL(fd,c*104+22)=m->exp;
  5458. WFIFOL(fd,c*104+26)=m->online;
  5459. WFIFOL(fd,c*104+30)=m->position;
  5460. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5461. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5462. c++;
  5463. }
  5464. WFIFOW(fd, 2)=c*104+4;
  5465. WFIFOSET(fd,WFIFOW(fd,2));
  5466. return 0;
  5467. }
  5468. /*==========================================
  5469. * ギルド役職名リスト
  5470. *------------------------------------------*/
  5471. int clif_guild_positionnamelist(struct map_session_data *sd)
  5472. {
  5473. int i,fd;
  5474. struct guild *g;
  5475. nullpo_retr(0, sd);
  5476. fd=sd->fd;
  5477. g=guild_search(sd->status.guild_id);
  5478. if(g==NULL)
  5479. return 0;
  5480. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5481. WFIFOW(fd, 0)=0x166;
  5482. for(i=0;i<MAX_GUILDPOSITION;i++){
  5483. WFIFOL(fd,i*28+4)=i;
  5484. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5485. }
  5486. WFIFOW(fd,2)=i*28+4;
  5487. WFIFOSET(fd,WFIFOW(fd,2));
  5488. return 0;
  5489. }
  5490. /*==========================================
  5491. * ギルド役職情報リスト
  5492. *------------------------------------------*/
  5493. int clif_guild_positioninfolist(struct map_session_data *sd)
  5494. {
  5495. int i,fd;
  5496. struct guild *g;
  5497. nullpo_retr(0, sd);
  5498. fd=sd->fd;
  5499. g=guild_search(sd->status.guild_id);
  5500. if(g==NULL)
  5501. return 0;
  5502. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5503. WFIFOW(fd, 0)=0x160;
  5504. for(i=0;i<MAX_GUILDPOSITION;i++){
  5505. struct guild_position *p=&g->position[i];
  5506. WFIFOL(fd,i*16+ 4)=i;
  5507. WFIFOL(fd,i*16+ 8)=p->mode;
  5508. WFIFOL(fd,i*16+12)=i;
  5509. WFIFOL(fd,i*16+16)=p->exp_mode;
  5510. }
  5511. WFIFOW(fd, 2)=i*16+4;
  5512. WFIFOSET(fd,WFIFOW(fd,2));
  5513. return 0;
  5514. }
  5515. /*==========================================
  5516. * ギルド役職変更通知
  5517. *------------------------------------------*/
  5518. int clif_guild_positionchanged(struct guild *g,int idx)
  5519. {
  5520. struct map_session_data *sd;
  5521. unsigned char buf[128];
  5522. nullpo_retr(0, g);
  5523. WBUFW(buf, 0)=0x174;
  5524. WBUFW(buf, 2)=44;
  5525. WBUFL(buf, 4)=idx;
  5526. WBUFL(buf, 8)=g->position[idx].mode;
  5527. WBUFL(buf,12)=idx;
  5528. WBUFL(buf,16)=g->position[idx].exp_mode;
  5529. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5530. if( (sd=guild_getavailablesd(g))!=NULL )
  5531. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5532. return 0;
  5533. }
  5534. /*==========================================
  5535. * ギルドメンバ変更通知
  5536. *------------------------------------------*/
  5537. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5538. {
  5539. struct map_session_data *sd;
  5540. unsigned char buf[64];
  5541. nullpo_retr(0, g);
  5542. WBUFW(buf, 0)=0x156;
  5543. WBUFW(buf, 2)=16;
  5544. WBUFL(buf, 4)=g->member[idx].account_id;
  5545. WBUFL(buf, 8)=g->member[idx].char_id;
  5546. WBUFL(buf,12)=g->member[idx].position;
  5547. if( (sd=guild_getavailablesd(g))!=NULL )
  5548. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5549. return 0;
  5550. }
  5551. /*==========================================
  5552. * ギルドエンブレム送信
  5553. *------------------------------------------*/
  5554. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5555. {
  5556. int fd;
  5557. nullpo_retr(0, sd);
  5558. nullpo_retr(0, g);
  5559. fd=sd->fd;
  5560. if(g->emblem_len<=0)
  5561. return 0;
  5562. WFIFOHEAD(fd,g->emblem_len+12);
  5563. WFIFOW(fd,0)=0x152;
  5564. WFIFOW(fd,2)=g->emblem_len+12;
  5565. WFIFOL(fd,4)=g->guild_id;
  5566. WFIFOL(fd,8)=g->emblem_id;
  5567. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5568. WFIFOSET(fd,WFIFOW(fd,2));
  5569. return 0;
  5570. }
  5571. /// Sends update of the guild id/emblem id to everyone in the area.
  5572. void clif_guild_emblem_area(struct block_list* bl)
  5573. {
  5574. uint8 buf[12];
  5575. nullpo_retv(bl);
  5576. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5577. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5578. WBUFW(buf,0) = 0x1B4;
  5579. WBUFL(buf,2) = bl->id;
  5580. WBUFL(buf,6) = status_get_guild_id(bl);
  5581. WBUFW(buf,10) = status_get_emblem_id(bl);
  5582. clif_send(buf, 12, bl, AREA_WOS);
  5583. }
  5584. /*==========================================
  5585. * Send guild skills
  5586. *------------------------------------------*/
  5587. int clif_guild_skillinfo(struct map_session_data* sd)
  5588. {
  5589. int fd;
  5590. struct guild* g;
  5591. int i,c;
  5592. nullpo_retr(0, sd);
  5593. fd = sd->fd;
  5594. g = guild_search(sd->status.guild_id);
  5595. if(g == NULL)
  5596. return 0;
  5597. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5598. WFIFOW(fd,0) = 0x0162;
  5599. WFIFOW(fd,4) = g->skill_point;
  5600. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5601. {
  5602. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5603. {
  5604. int id = g->skill[i].id;
  5605. int p = 6 + c*37;
  5606. WFIFOW(fd,p+0) = id;
  5607. WFIFOW(fd,p+2) = skill_get_inf(id);
  5608. WFIFOW(fd,p+4) = 0;
  5609. WFIFOW(fd,p+6) = g->skill[i].lv;
  5610. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5611. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5612. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5613. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5614. c++;
  5615. }
  5616. }
  5617. WFIFOW(fd,2) = 6 + c*37;
  5618. WFIFOSET(fd,WFIFOW(fd,2));
  5619. return 0;
  5620. }
  5621. /*==========================================
  5622. * Sends guild notice to client
  5623. * R 016f <str1z>.60B <str2z>.120B
  5624. *------------------------------------------*/
  5625. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5626. {
  5627. int fd;
  5628. nullpo_retr(0, sd);
  5629. nullpo_retr(0, g);
  5630. fd = sd->fd;
  5631. if ( !session_isActive(fd) )
  5632. return 0;
  5633. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5634. return 0;
  5635. WFIFOHEAD(fd,packet_len(0x16f));
  5636. WFIFOW(fd,0) = 0x16f;
  5637. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5638. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5639. WFIFOSET(fd,packet_len(0x16f));
  5640. return 0;
  5641. }
  5642. /*==========================================
  5643. * ギルドメンバ勧誘
  5644. *------------------------------------------*/
  5645. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5646. {
  5647. int fd;
  5648. nullpo_retr(0, sd);
  5649. nullpo_retr(0, g);
  5650. fd=sd->fd;
  5651. WFIFOHEAD(fd,packet_len(0x16a));
  5652. WFIFOW(fd,0)=0x16a;
  5653. WFIFOL(fd,2)=g->guild_id;
  5654. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5655. WFIFOSET(fd,packet_len(0x16a));
  5656. return 0;
  5657. }
  5658. /*==========================================
  5659. * ギルドメンバ勧誘結果
  5660. *------------------------------------------*/
  5661. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5662. {
  5663. int fd;
  5664. nullpo_retr(0, sd);
  5665. fd=sd->fd;
  5666. WFIFOHEAD(fd,packet_len(0x169));
  5667. WFIFOW(fd,0)=0x169;
  5668. WFIFOB(fd,2)=flag;
  5669. WFIFOSET(fd,packet_len(0x169));
  5670. return 0;
  5671. }
  5672. /*==========================================
  5673. * ギルドメンバ脱退通知
  5674. *------------------------------------------*/
  5675. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5676. {
  5677. unsigned char buf[128];
  5678. nullpo_retr(0, sd);
  5679. WBUFW(buf, 0)=0x15a;
  5680. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5681. memcpy(WBUFP(buf,26),mes,40);
  5682. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5683. return 0;
  5684. }
  5685. /*==========================================
  5686. * ギルドメンバ追放通知
  5687. *------------------------------------------*/
  5688. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5689. {
  5690. unsigned char buf[128];
  5691. nullpo_retr(0, sd);
  5692. WBUFW(buf, 0)=0x15c;
  5693. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  5694. safestrncpy((char*)WBUFP(buf,26),mes,40);
  5695. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5696. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5697. return 0;
  5698. }
  5699. /*==========================================
  5700. * ギルド追放メンバリスト
  5701. *------------------------------------------*/
  5702. int clif_guild_expulsionlist(struct map_session_data *sd)
  5703. {
  5704. int fd;
  5705. int i,c;
  5706. struct guild *g;
  5707. nullpo_retr(0, sd);
  5708. fd=sd->fd;
  5709. g=guild_search(sd->status.guild_id);
  5710. if(g==NULL)
  5711. return 0;
  5712. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5713. WFIFOW(fd,0)=0x163;
  5714. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5715. struct guild_expulsion *e=&g->expulsion[i];
  5716. if(e->account_id>0){
  5717. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5718. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5719. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  5720. c++;
  5721. }
  5722. }
  5723. WFIFOW(fd,2) = 4 + c*88;
  5724. WFIFOSET(fd,WFIFOW(fd,2));
  5725. return 0;
  5726. }
  5727. /*==========================================
  5728. * ギルド会話
  5729. *------------------------------------------*/
  5730. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5731. {
  5732. struct map_session_data *sd;
  5733. unsigned char *buf;
  5734. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5735. WBUFW(buf, 0) = 0x17f;
  5736. WBUFW(buf, 2) = len + 4;
  5737. memcpy(WBUFP(buf,4), mes, len);
  5738. if ((sd = guild_getavailablesd(g)) != NULL)
  5739. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5740. if(buf) aFree(buf);
  5741. return 0;
  5742. }
  5743. /*==========================================
  5744. * ギルドスキル割り振り通知
  5745. *------------------------------------------*/
  5746. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5747. {
  5748. int fd;
  5749. nullpo_retr(0, sd);
  5750. fd=sd->fd;
  5751. WFIFOHEAD(fd,11);
  5752. WFIFOW(fd,0) = 0x10e;
  5753. WFIFOW(fd,2) = skill_num;
  5754. WFIFOW(fd,4) = lv;
  5755. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5756. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5757. WFIFOB(fd,10) = 1;
  5758. WFIFOSET(fd,11);
  5759. return 0;
  5760. }
  5761. /*==========================================
  5762. * ギルド同盟要請
  5763. *------------------------------------------*/
  5764. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5765. {
  5766. int fd;
  5767. nullpo_retr(0, sd);
  5768. fd=sd->fd;
  5769. WFIFOHEAD(fd,packet_len(0x171));
  5770. WFIFOW(fd,0)=0x171;
  5771. WFIFOL(fd,2)=account_id;
  5772. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5773. WFIFOSET(fd,packet_len(0x171));
  5774. return 0;
  5775. }
  5776. /*==========================================
  5777. * Reply to alliance request.
  5778. * Flag values are:
  5779. * 0: Already allied.
  5780. * 1: You rejected the offer.
  5781. * 2: You accepted the offer.
  5782. * 3: They have too any alliances
  5783. * 4: You have too many alliances.
  5784. *------------------------------------------*/
  5785. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5786. {
  5787. int fd;
  5788. nullpo_retr(0, sd);
  5789. fd=sd->fd;
  5790. WFIFOHEAD(fd,packet_len(0x173));
  5791. WFIFOW(fd,0)=0x173;
  5792. WFIFOL(fd,2)=flag;
  5793. WFIFOSET(fd,packet_len(0x173));
  5794. return 0;
  5795. }
  5796. /*==========================================
  5797. * ギルド関係解消通知
  5798. *------------------------------------------*/
  5799. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5800. {
  5801. int fd;
  5802. nullpo_retr(0, sd);
  5803. fd = sd->fd;
  5804. if (fd <= 0)
  5805. return 0;
  5806. WFIFOHEAD(fd,packet_len(0x184));
  5807. WFIFOW(fd,0)=0x184;
  5808. WFIFOL(fd,2)=guild_id;
  5809. WFIFOL(fd,6)=flag;
  5810. WFIFOSET(fd,packet_len(0x184));
  5811. return 0;
  5812. }
  5813. /*==========================================
  5814. * ギルド敵対結果
  5815. *------------------------------------------*/
  5816. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5817. {
  5818. int fd;
  5819. nullpo_retr(0, sd);
  5820. fd=sd->fd;
  5821. WFIFOHEAD(fd,packet_len(0x181));
  5822. WFIFOW(fd,0)=0x181;
  5823. WFIFOB(fd,2)=flag;
  5824. WFIFOSET(fd,packet_len(0x181));
  5825. return 0;
  5826. }
  5827. /*==========================================
  5828. * ギルド関係追加
  5829. *------------------------------------------*/
  5830. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5831. {
  5832. unsigned char buf[64];
  5833. WBUFW(fd,0)=0x185;
  5834. WBUFL(fd,2)=g->alliance[idx].opposition;
  5835. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5836. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5837. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5838. return 0;
  5839. }*/
  5840. /*==========================================
  5841. * ギルド解散通知
  5842. *------------------------------------------*/
  5843. int clif_guild_broken(struct map_session_data *sd,int flag)
  5844. {
  5845. int fd;
  5846. nullpo_retr(0, sd);
  5847. fd=sd->fd;
  5848. WFIFOHEAD(fd,packet_len(0x15e));
  5849. WFIFOW(fd,0)=0x15e;
  5850. WFIFOL(fd,2)=flag;
  5851. WFIFOSET(fd,packet_len(0x15e));
  5852. return 0;
  5853. }
  5854. /*==========================================
  5855. * エモーション
  5856. *------------------------------------------*/
  5857. void clif_emotion(struct block_list *bl,int type)
  5858. {
  5859. unsigned char buf[8];
  5860. nullpo_retv(bl);
  5861. WBUFW(buf,0)=0xc0;
  5862. WBUFL(buf,2)=bl->id;
  5863. WBUFB(buf,6)=type;
  5864. clif_send(buf,packet_len(0xc0),bl,AREA);
  5865. }
  5866. /*==========================================
  5867. * トーキーボックス
  5868. *------------------------------------------*/
  5869. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5870. {
  5871. unsigned char buf[86];
  5872. nullpo_retv(bl);
  5873. WBUFW(buf,0) = 0x191;
  5874. WBUFL(buf,2) = bl->id;
  5875. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5876. clif_send(buf,packet_len(0x191),bl,AREA);
  5877. }
  5878. /*==========================================
  5879. * 結婚エフェクト
  5880. *------------------------------------------*/
  5881. void clif_wedding_effect(struct block_list *bl)
  5882. {
  5883. unsigned char buf[6];
  5884. nullpo_retv(bl);
  5885. WBUFW(buf,0) = 0x1ea;
  5886. WBUFL(buf,2) = bl->id;
  5887. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5888. }
  5889. /*==========================================
  5890. * � なたに逢いたい使用時名前叫び
  5891. *------------------------------------------
  5892. void clif_callpartner(struct map_session_data *sd)
  5893. {
  5894. unsigned char buf[26];
  5895. char *p;
  5896. nullpo_retv(sd);
  5897. if(sd->status.partner_id){
  5898. WBUFW(buf,0)=0x1e6;
  5899. p = map_charid2nick(sd->status.partner_id);
  5900. if(p){
  5901. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5902. }else{
  5903. map_reqchariddb(sd,sd->status.partner_id);
  5904. chrif_searchcharid(sd->status.partner_id);
  5905. WBUFB(buf,2) = 0;
  5906. }
  5907. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5908. }
  5909. return;
  5910. }
  5911. */
  5912. /*==========================================
  5913. * Marry [DracoRPG]
  5914. *------------------------------------------
  5915. void clif_marriage_process(struct map_session_data *sd)
  5916. {
  5917. int fd;
  5918. nullpo_retv(sd);
  5919. fd=sd->fd;
  5920. WFIFOHEAD(fd,packet_len(0x1e4));
  5921. WFIFOW(fd,0)=0x1e4;
  5922. WFIFOSET(fd,packet_len(0x1e4));
  5923. }
  5924. */
  5925. /*==========================================
  5926. * Notice of divorce
  5927. *------------------------------------------*/
  5928. void clif_divorced(struct map_session_data* sd, const char* name)
  5929. {
  5930. int fd;
  5931. nullpo_retv(sd);
  5932. fd=sd->fd;
  5933. WFIFOHEAD(fd,packet_len(0x205));
  5934. WFIFOW(fd,0)=0x205;
  5935. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5936. WFIFOSET(fd, packet_len(0x205));
  5937. }
  5938. /*==========================================
  5939. *
  5940. *------------------------------------------*/
  5941. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5942. {
  5943. nullpo_retv(sd);
  5944. WFIFOHEAD(fd,packet_len(0x1e2));
  5945. WFIFOW(fd,0)=0x1e2;
  5946. WFIFOSET(fd, packet_len(0x1e2));
  5947. }
  5948. /*==========================================
  5949. *
  5950. *------------------------------------------*/
  5951. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5952. {
  5953. int fd;
  5954. nullpo_retr(0, sd);
  5955. fd = sd->fd;
  5956. if (!fd || !len) return 0; //Disconnected player.
  5957. WFIFOHEAD(fd, len+5);
  5958. WFIFOW(fd, 0) = 0x17f;
  5959. WFIFOW(fd, 2) = len + 5;
  5960. memcpy(WFIFOP(fd,4), mes, len);
  5961. WFIFOSET(fd, WFIFOW(fd,2));
  5962. return 1;
  5963. }
  5964. /*==========================================
  5965. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5966. *------------------------------------------*/
  5967. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5968. {
  5969. unsigned char buf[1024];
  5970. if (!len) return;
  5971. WBUFW(buf, 0) = 0x17f;
  5972. WBUFW(buf, 2) = len + 5;
  5973. memcpy(WBUFP(buf,4), mes, len);
  5974. clif_send(buf, WBUFW(buf,2), src, target);
  5975. return;
  5976. }
  5977. /*==========================================
  5978. *
  5979. *------------------------------------------*/
  5980. int clif_GM_kickack(struct map_session_data *sd, int id)
  5981. {
  5982. int fd;
  5983. nullpo_retr(0, sd);
  5984. fd = sd->fd;
  5985. WFIFOHEAD(fd,packet_len(0xcd));
  5986. WFIFOW(fd,0) = 0xcd;
  5987. WFIFOL(fd,2) = id;
  5988. WFIFOSET(fd, packet_len(0xcd));
  5989. return 0;
  5990. }
  5991. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  5992. {
  5993. int fd = tsd->fd;
  5994. if( fd > 0 )
  5995. clif_authfail_fd(fd, 15);
  5996. else
  5997. map_quit(tsd);
  5998. if( sd )
  5999. clif_GM_kickack(sd,tsd->status.account_id);
  6000. }
  6001. /// Displays various manner-related status messages
  6002. /// R 014a <type>.L
  6003. /// type: 0 - "A manner point has been successfully aligned."
  6004. /// 1 - ?
  6005. /// 2 - ?
  6006. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6007. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6008. /// 5 - "You got a good point from %s."
  6009. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6010. {
  6011. int fd;
  6012. nullpo_retv(sd);
  6013. fd = sd->fd;
  6014. WFIFOHEAD(fd,packet_len(0x14a));
  6015. WFIFOW(fd,0) = 0x14a;
  6016. WFIFOL(fd,2) = type;
  6017. WFIFOSET(fd, packet_len(0x14a));
  6018. }
  6019. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6020. /// R 014b <type>.B <GM name>.24B
  6021. /// type: 0 - positive (unmute)
  6022. /// 1 - negative (mute)
  6023. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6024. {
  6025. int fd;
  6026. nullpo_retv(sd);
  6027. nullpo_retv(tsd);
  6028. fd = tsd->fd;
  6029. WFIFOHEAD(fd,packet_len(0x14b));
  6030. WFIFOW(fd,0) = 0x14b;
  6031. WFIFOB(fd,2) = type;
  6032. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6033. WFIFOSET(fd, packet_len(0x14b));
  6034. }
  6035. /*==========================================
  6036. * Wis拒否許可応答
  6037. *------------------------------------------*/
  6038. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6039. {
  6040. int fd;
  6041. nullpo_retr(0, sd);
  6042. fd=sd->fd;
  6043. WFIFOHEAD(fd,packet_len(0xd1));
  6044. WFIFOW(fd,0)=0xd1;
  6045. WFIFOB(fd,2)=type;
  6046. WFIFOB(fd,3)=flag;
  6047. WFIFOSET(fd,packet_len(0xd1));
  6048. return 0;
  6049. }
  6050. /*==========================================
  6051. * Wis全拒否許可応答
  6052. *------------------------------------------*/
  6053. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6054. {
  6055. int fd;
  6056. nullpo_retr(0, sd);
  6057. fd=sd->fd;
  6058. WFIFOHEAD(fd,packet_len(0xd2));
  6059. WFIFOW(fd,0)=0xd2;
  6060. WFIFOB(fd,2)=type;
  6061. WFIFOB(fd,3)=flag;
  6062. WFIFOSET(fd,packet_len(0xd2));
  6063. return 0;
  6064. }
  6065. /*==========================================
  6066. * サウンドエフェクト
  6067. *------------------------------------------*/
  6068. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6069. {
  6070. int fd;
  6071. nullpo_retv(sd);
  6072. nullpo_retv(bl);
  6073. fd = sd->fd;
  6074. WFIFOHEAD(fd,packet_len(0x1d3));
  6075. WFIFOW(fd,0) = 0x1d3;
  6076. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6077. WFIFOB(fd,26) = type;
  6078. WFIFOL(fd,27) = 0;
  6079. WFIFOL(fd,31) = bl->id;
  6080. WFIFOSET(fd,packet_len(0x1d3));
  6081. return;
  6082. }
  6083. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6084. {
  6085. unsigned char buf[40];
  6086. nullpo_retr(0, bl);
  6087. WBUFW(buf,0) = 0x1d3;
  6088. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6089. WBUFB(buf,26) = type;
  6090. WBUFL(buf,27) = 0;
  6091. WBUFL(buf,31) = bl->id;
  6092. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6093. return 0;
  6094. }
  6095. // displaying special effects (npcs, weather, etc) [Valaris]
  6096. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6097. {
  6098. unsigned char buf[24];
  6099. nullpo_retr(0, bl);
  6100. memset(buf, 0, packet_len(0x1f3));
  6101. WBUFW(buf,0) = 0x1f3;
  6102. WBUFL(buf,2) = bl->id;
  6103. WBUFL(buf,6) = type;
  6104. clif_send(buf, packet_len(0x1f3), bl, target);
  6105. if (disguised(bl)) {
  6106. WBUFL(buf,2) = -bl->id;
  6107. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6108. }
  6109. return 0;
  6110. }
  6111. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6112. {
  6113. WFIFOHEAD(fd,10);
  6114. WFIFOW(fd,0) = 0x1f3;
  6115. WFIFOL(fd,2) = bl->id;
  6116. WFIFOL(fd,6) = type;
  6117. WFIFOSET(fd,10);
  6118. }
  6119. // messages (from mobs/npcs) [Valaris]
  6120. int clif_message(struct block_list* bl, const char* msg)
  6121. {
  6122. unsigned short msg_len = strlen(msg) + 1;
  6123. uint8 buf[256];
  6124. nullpo_retr(0, bl);
  6125. WBUFW(buf,0) = 0x8d;
  6126. WBUFW(buf,2) = msg_len + 8;
  6127. WBUFL(buf,4) = bl->id;
  6128. memcpy(WBUFP(buf,8), msg, msg_len);
  6129. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6130. return 0;
  6131. }
  6132. // refresh the client's screen, getting rid of any effects
  6133. int clif_refresh(struct map_session_data *sd)
  6134. {
  6135. nullpo_retr(-1, sd);
  6136. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6137. clif_inventorylist(sd);
  6138. if(pc_iscarton(sd)) {
  6139. clif_cartlist(sd);
  6140. clif_updatestatus(sd,SP_CARTINFO);
  6141. }
  6142. clif_updatestatus(sd,SP_WEIGHT);
  6143. clif_updatestatus(sd,SP_MAXWEIGHT);
  6144. clif_updatestatus(sd,SP_STR);
  6145. clif_updatestatus(sd,SP_AGI);
  6146. clif_updatestatus(sd,SP_VIT);
  6147. clif_updatestatus(sd,SP_INT);
  6148. clif_updatestatus(sd,SP_DEX);
  6149. clif_updatestatus(sd,SP_LUK);
  6150. if (sd->spiritball)
  6151. clif_spiritball_single(sd->fd, sd);
  6152. if (sd->vd.cloth_color)
  6153. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6154. if(merc_is_hom_active(sd->hd))
  6155. clif_send_homdata(sd,0,0);
  6156. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6157. clif_weather_check(sd);
  6158. if( pc_issit(sd) )
  6159. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6160. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6161. clif_clearunit_single(sd->bl.id,1,sd->fd);
  6162. #ifndef TXT_ONLY
  6163. mail_clear(sd);
  6164. #endif
  6165. return 0;
  6166. }
  6167. // updates the object's (bl) name on client
  6168. int clif_charnameack (int fd, struct block_list *bl)
  6169. {
  6170. unsigned char buf[103];
  6171. int cmd = 0x95;
  6172. nullpo_retr(0, bl);
  6173. WBUFW(buf,0) = cmd;
  6174. WBUFL(buf,2) = bl->id;
  6175. switch( bl->type )
  6176. {
  6177. case BL_PC:
  6178. {
  6179. struct map_session_data *ssd = (struct map_session_data *)bl;
  6180. struct party_data *p = NULL;
  6181. struct guild *g = NULL;
  6182. //Requesting your own "shadow" name. [Skotlex]
  6183. if (ssd->fd == fd && ssd->disguise)
  6184. WBUFL(buf,2) = -bl->id;
  6185. if (strlen(ssd->fakename)>1) {
  6186. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6187. break;
  6188. }
  6189. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6190. if (ssd->status.party_id > 0)
  6191. p = party_search(ssd->status.party_id);
  6192. if (ssd->status.guild_id > 0)
  6193. g = guild_search(ssd->status.guild_id);
  6194. if (p == NULL && g == NULL)
  6195. break;
  6196. WBUFW(buf, 0) = cmd = 0x195;
  6197. if (p)
  6198. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6199. else
  6200. WBUFB(buf,30) = 0;
  6201. if (g)
  6202. {
  6203. int i, ps = -1;
  6204. for(i = 0; i < g->max_member; i++) {
  6205. if (g->member[i].account_id == ssd->status.account_id &&
  6206. g->member[i].char_id == ssd->status.char_id )
  6207. {
  6208. ps = g->member[i].position;
  6209. break;
  6210. }
  6211. }
  6212. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6213. {
  6214. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6215. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6216. } else { //Assume no guild.
  6217. WBUFB(buf,54) = 0;
  6218. WBUFB(buf,78) = 0;
  6219. }
  6220. } else {
  6221. WBUFB(buf,54) = 0;
  6222. WBUFB(buf,78) = 0;
  6223. }
  6224. }
  6225. break;
  6226. //[blackhole89]
  6227. case BL_HOM:
  6228. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6229. break;
  6230. case BL_MER:
  6231. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6232. break;
  6233. case BL_PET:
  6234. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6235. break;
  6236. case BL_NPC:
  6237. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6238. break;
  6239. case BL_MOB:
  6240. {
  6241. struct mob_data *md = (struct mob_data *)bl;
  6242. nullpo_retr(0, md);
  6243. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6244. if (md->guardian_data && md->guardian_data->guild_id) {
  6245. WBUFW(buf, 0) = cmd = 0x195;
  6246. WBUFB(buf,30) = 0;
  6247. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6248. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6249. } else if (battle_config.show_mob_info) {
  6250. char mobhp[50], *str_p = mobhp;
  6251. WBUFW(buf, 0) = cmd = 0x195;
  6252. if (battle_config.show_mob_info&4)
  6253. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6254. if (battle_config.show_mob_info&1)
  6255. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6256. if (battle_config.show_mob_info&2)
  6257. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6258. //Even thought mobhp ain't a name, we send it as one so the client
  6259. //can parse it. [Skotlex]
  6260. if (str_p != mobhp) {
  6261. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6262. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6263. WBUFB(buf,54) = 0;
  6264. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6265. }
  6266. }
  6267. }
  6268. break;
  6269. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6270. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6271. // break;
  6272. return 0;
  6273. default:
  6274. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6275. return 0;
  6276. }
  6277. // if no receipient specified just update nearby clients
  6278. if (fd == 0)
  6279. clif_send(buf, packet_len(cmd), bl, AREA);
  6280. else {
  6281. WFIFOHEAD(fd, packet_len(cmd));
  6282. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6283. WFIFOSET(fd, packet_len(cmd));
  6284. }
  6285. return 0;
  6286. }
  6287. //Used to update when a char leaves a party/guild. [Skotlex]
  6288. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6289. int clif_charnameupdate (struct map_session_data *ssd)
  6290. {
  6291. unsigned char buf[103];
  6292. int cmd = 0x195;
  6293. struct party_data *p = NULL;
  6294. struct guild *g = NULL;
  6295. nullpo_retr(0, ssd);
  6296. if (strlen(ssd->fakename)>1)
  6297. return 0; //No need to update as the party/guild was not displayed anyway.
  6298. WBUFW(buf,0) = cmd;
  6299. WBUFL(buf,2) = ssd->bl.id;
  6300. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6301. if (ssd->status.party_id > 0)
  6302. p = party_search(ssd->status.party_id);
  6303. if (ssd->status.guild_id > 0)
  6304. g = guild_search(ssd->status.guild_id);
  6305. if (p)
  6306. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6307. else
  6308. WBUFB(buf,30) = 0;
  6309. if (g)
  6310. {
  6311. int i, ps = -1;
  6312. for(i = 0; i < g->max_member; i++) {
  6313. if (g->member[i].account_id == ssd->status.account_id &&
  6314. g->member[i].char_id == ssd->status.char_id )
  6315. {
  6316. ps = g->member[i].position;
  6317. break;
  6318. }
  6319. }
  6320. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6321. {
  6322. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6323. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6324. } else { //Assume no guild.
  6325. WBUFB(buf,54) = 0;
  6326. WBUFB(buf,78) = 0;
  6327. }
  6328. } else {
  6329. WBUFB(buf,54) = 0;
  6330. WBUFB(buf,78) = 0;
  6331. }
  6332. // Update nearby clients
  6333. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6334. return 0;
  6335. }
  6336. void clif_slide(struct block_list *bl, int x, int y)
  6337. {
  6338. unsigned char buf[10];
  6339. nullpo_retv(bl);
  6340. WBUFW(buf, 0) = 0x01ff;
  6341. WBUFL(buf, 2) = bl->id;
  6342. WBUFW(buf, 6) = x;
  6343. WBUFW(buf, 8) = y;
  6344. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6345. if( disguised(bl) )
  6346. {
  6347. WBUFL(buf,2) = -bl->id;
  6348. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6349. }
  6350. }
  6351. /*------------------------------------------
  6352. * @me command by lordalfa, rewritten implementation by Skotlex
  6353. *------------------------------------------*/
  6354. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6355. {
  6356. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6357. int len_mes = strlen(mes)+1; //Account for \0
  6358. if (len_mes + 8 >= 256) {
  6359. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6360. len_mes = 247; //Trunk it to avoid problems.
  6361. }
  6362. // send message to others
  6363. WBUFW(buf,0) = 0x8d;
  6364. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6365. WBUFL(buf,4) = sd->bl.id;
  6366. memcpy(WBUFP(buf,8), mes, len_mes);
  6367. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6368. // send back message to the speaker
  6369. WBUFW(buf,0) = 0x8e;
  6370. WBUFW(buf, 2) = len_mes + 4;
  6371. memcpy(WBUFP(buf,4), mes, len_mes);
  6372. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6373. return 0;
  6374. }
  6375. /*==========================
  6376. * Minimap fix [Kevin]
  6377. * Remove dot from minimap
  6378. *--------------------------*/
  6379. int clif_party_xy_remove(struct map_session_data *sd)
  6380. {
  6381. unsigned char buf[16];
  6382. nullpo_retr(0, sd);
  6383. WBUFW(buf,0)=0x107;
  6384. WBUFL(buf,2)=sd->status.account_id;
  6385. WBUFW(buf,6)=-1;
  6386. WBUFW(buf,8)=-1;
  6387. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6388. return 0;
  6389. }
  6390. //Displays gospel-buff information (thanks to Rayce):
  6391. //Type determines message based on this table:
  6392. /*
  6393. 0x15 End all negative status
  6394. 0x16 Immunity to all status
  6395. 0x17 MaxHP +100%
  6396. 0x18 MaxSP +100%
  6397. 0x19 All stats +20
  6398. 0x1c Enchant weapon with Holy element
  6399. 0x1d Enchant armor with Holy element
  6400. 0x1e DEF +25%
  6401. 0x1f ATK +100%
  6402. 0x20 HIT/Flee +50
  6403. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6404. */
  6405. void clif_gospel_info(struct map_session_data *sd, int type)
  6406. {
  6407. int fd=sd->fd;
  6408. WFIFOHEAD(fd,packet_len(0x215));
  6409. WFIFOW(fd,0)=0x215;
  6410. WFIFOL(fd,2)=type;
  6411. WFIFOSET(fd, packet_len(0x215));
  6412. }
  6413. /*==========================================
  6414. * Info about Star Glaldiator save map [Komurka]
  6415. * type: 1: Information, 0: Map registered
  6416. *------------------------------------------*/
  6417. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6418. {
  6419. int fd=sd->fd;
  6420. WFIFOHEAD(fd,packet_len(0x20e));
  6421. WFIFOW(fd,0) = 0x20e;
  6422. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6423. WFIFOL(fd,26) = sd->bl.id;
  6424. WFIFOB(fd,30) = feel_level;
  6425. WFIFOB(fd,31) = type?1:0;
  6426. WFIFOSET(fd,packet_len(0x20e));
  6427. }
  6428. /*==========================================
  6429. * Info about Star Glaldiator hate mob [Komurka]
  6430. * type: 1: Register mob, 0: Information.
  6431. *------------------------------------------*/
  6432. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6433. {
  6434. int fd=sd->fd;
  6435. WFIFOHEAD(fd,packet_len(0x20e));
  6436. WFIFOW(fd,0)=0x20e;
  6437. if (pcdb_checkid(class_))
  6438. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6439. else if (mobdb_checkid(class_))
  6440. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6441. else //Really shouldn't happen...
  6442. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6443. WFIFOL(fd,26)=sd->bl.id;
  6444. WFIFOB(fd,30)=hate_level;
  6445. WFIFOB(fd,31)=type?10:11; //Register/Info
  6446. WFIFOSET(fd, packet_len(0x20e));
  6447. }
  6448. /*==========================================
  6449. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6450. *------------------------------------------*/
  6451. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6452. {
  6453. int fd=sd->fd;
  6454. WFIFOHEAD(fd,packet_len(0x20e));
  6455. WFIFOW(fd,0)=0x20e;
  6456. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6457. WFIFOL(fd,26)=mob_id;
  6458. WFIFOB(fd,30)=progress; //Message to display
  6459. WFIFOB(fd,31)=20;
  6460. WFIFOSET(fd, packet_len(0x20e));
  6461. }
  6462. /*==========================================
  6463. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6464. *------------------------------------------*/
  6465. void clif_feel_hate_reset(struct map_session_data *sd)
  6466. {
  6467. int fd=sd->fd;
  6468. WFIFOHEAD(fd,packet_len(0x20e));
  6469. WFIFOW(fd,0)=0x20e;
  6470. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6471. WFIFOL(fd,26)=sd->bl.id;
  6472. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6473. WFIFOB(fd,31)=30;
  6474. WFIFOSET(fd, packet_len(0x20e));
  6475. }
  6476. /*==========================================
  6477. * Equip window (un)tick ack
  6478. * R 02d9 <zero>.L <flag>.L
  6479. *------------------------------------------*/
  6480. void clif_equiptickack(struct map_session_data* sd, int flag)
  6481. {
  6482. int fd;
  6483. nullpo_retv(sd);
  6484. fd = sd->fd;
  6485. WFIFOHEAD(fd, packet_len(0x2d9));
  6486. WFIFOW(fd, 0) = 0x2d9;
  6487. WFIFOL(fd, 2) = 0;
  6488. WFIFOL(fd, 6) = flag;
  6489. WFIFOSET(fd, packet_len(0x2d9));
  6490. }
  6491. /*==========================================
  6492. * The player's 'view equip' state, sent during login
  6493. * R 02da <flag>.B
  6494. *------------------------------------------*/
  6495. void clif_equipcheckbox(struct map_session_data* sd)
  6496. {
  6497. int fd;
  6498. nullpo_retv(sd);
  6499. fd = sd->fd;
  6500. WFIFOHEAD(fd, packet_len(0x2da));
  6501. WFIFOW(fd, 0) = 0x2da;
  6502. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6503. WFIFOSET(fd, packet_len(0x2da));
  6504. }
  6505. /*==========================================
  6506. * Sends info about a player's equipped items
  6507. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <up-viewid>.w <mid-viewid>.w <low-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.26B*
  6508. *------------------------------------------*/
  6509. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6510. {
  6511. int i, n, fd;
  6512. nullpo_retv(sd);
  6513. nullpo_retv(tsd);
  6514. fd = sd->fd;
  6515. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6516. WFIFOW(fd, 0) = 0x2d7;
  6517. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6518. WFIFOW(fd,28) = tsd->status.class_;
  6519. WFIFOW(fd,30) = tsd->vd.hair_style;
  6520. WFIFOW(fd,32) = tsd->vd.head_top;
  6521. WFIFOW(fd,34) = tsd->vd.head_mid;
  6522. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6523. WFIFOW(fd,38) = tsd->vd.hair_color;
  6524. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6525. WFIFOB(fd,42) = tsd->vd.sex;
  6526. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6527. {
  6528. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6529. continue;
  6530. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6531. continue;
  6532. // Inventory position
  6533. WFIFOW(fd, n*26+43) = i + 2;
  6534. // Add refine, identify flag, element, etc.
  6535. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6536. // Add cards
  6537. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6538. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6539. memset(WFIFOP(fd, n*26+63), 0, 6);
  6540. n++;
  6541. }
  6542. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6543. WFIFOSET(fd, WFIFOW(fd, 2));
  6544. }
  6545. /*==========================================
  6546. * View player equip request denied
  6547. * R 0291 <message>.W
  6548. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6549. *------------------------------------------*/
  6550. void clif_viewequip_fail(struct map_session_data* sd)
  6551. {
  6552. int fd;
  6553. nullpo_retv(sd);
  6554. fd = sd->fd;
  6555. WFIFOHEAD(fd, packet_len(0x291));
  6556. WFIFOW(fd, 0) = 0x291;
  6557. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6558. WFIFOSET(fd, packet_len(0x291));
  6559. }
  6560. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6561. /// Returns true if the packet was parsed successfully.
  6562. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6563. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6564. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6565. {
  6566. char *text, *name, *message;
  6567. unsigned int packetlen, textlen, namelen, messagelen;
  6568. int fd = sd->fd;
  6569. *name_ = NULL;
  6570. *namelen_ = 0;
  6571. *message_ = NULL;
  6572. *messagelen_ = 0;
  6573. packetlen = RFIFOW(fd,2);
  6574. // basic structure checks
  6575. if( packetlen > RFIFOREST(fd) )
  6576. { // there has to be enough data to read
  6577. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6578. return false;
  6579. }
  6580. if( packetlen < 4 + 1 )
  6581. { // 4-byte header and at least an empty string is expected
  6582. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6583. return false;
  6584. }
  6585. text = (char*)RFIFOP(fd,4);
  6586. textlen = packetlen - 4;
  6587. // process <name> part of the packet
  6588. if( format == 0 )
  6589. {// name and message are separated by ' : '
  6590. // validate name
  6591. name = text;
  6592. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6593. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6594. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6595. {
  6596. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6597. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6598. set_eof(fd); // Just kick them out to correct it.
  6599. return false;
  6600. }
  6601. message = name + namelen + 3;
  6602. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6603. }
  6604. else
  6605. {// name has fixed width
  6606. if( textlen < NAME_LENGTH + 1 )
  6607. {
  6608. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6609. return false;
  6610. }
  6611. // validate name
  6612. name = text;
  6613. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6614. if( name[namelen] != '\0' )
  6615. { // only restriction is that the name must be zero-terminated
  6616. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6617. return false;
  6618. }
  6619. message = name + NAME_LENGTH;
  6620. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6621. }
  6622. if( messagelen != strnlen(message, messagelen)+1 )
  6623. { // the declared length must match real length
  6624. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6625. return false;
  6626. }
  6627. // verify <message> part of the packet
  6628. if( message[messagelen-1] != '\0' )
  6629. { // message must be zero-terminated
  6630. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6631. return false;
  6632. }
  6633. if( messagelen > CHAT_SIZE_MAX-1 )
  6634. { // messages mustn't be too long
  6635. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  6636. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  6637. // Neither the official client nor server place any restriction on the length of the data in the packet,
  6638. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  6639. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  6640. return false;
  6641. }
  6642. *name_ = name;
  6643. *namelen_ = namelen;
  6644. *message_ = message;
  6645. *messagelen_ = messagelen;
  6646. return true;
  6647. }
  6648. // ---------------------
  6649. // clif_guess_PacketVer
  6650. // ---------------------
  6651. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6652. // error codes:
  6653. // 0 - Success
  6654. // 1 - Unknown packet_ver
  6655. // 2 - Invalid account_id
  6656. // 3 - Invalid char_id
  6657. // 4 - Invalid login_id1 (reserved)
  6658. // 5 - Invalid client_tick (reserved)
  6659. // 6 - Invalid sex
  6660. // Only the first 'invalid' error that appears is used.
  6661. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6662. {
  6663. static int err = 1;
  6664. static int packet_ver = -1;
  6665. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6666. if (get_previous)
  6667. {//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]
  6668. if( error )
  6669. *error = err;
  6670. return packet_ver;
  6671. }
  6672. //By default, start searching on the default one.
  6673. err = 1;
  6674. packet_ver = clif_config.packet_db_ver;
  6675. cmd = RFIFOW(fd,0);
  6676. packet_len = RFIFOREST(fd);
  6677. #define SET_ERROR(n) \
  6678. if( err == 1 )\
  6679. err = n;\
  6680. //define SET_ERROR
  6681. #define CHECK_PACKET_VER() \
  6682. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6683. ;/* not wanttoconnection or wrong length */\
  6684. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  6685. { SET_ERROR(2); }/* invalid account_id */\
  6686. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  6687. { SET_ERROR(3); }/* invalid char_id */\
  6688. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6689. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6690. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6691. { SET_ERROR(6); }/* invalid sex */\
  6692. else\
  6693. {\
  6694. err = 0;\
  6695. if( error )\
  6696. *error = 0;\
  6697. return packet_ver;\
  6698. }\
  6699. //define CHECK_PACKET_VER
  6700. CHECK_PACKET_VER();//Default packet version found.
  6701. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6702. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6703. CHECK_PACKET_VER();
  6704. }
  6705. if( error )
  6706. *error = err;
  6707. packet_ver = -1;
  6708. return -1;
  6709. #undef SET_ERROR
  6710. #undef CHECK_PACKET_VER
  6711. }
  6712. // ------------
  6713. // clif_parse_*
  6714. // ------------
  6715. // パケット読み取って色々操作
  6716. /*==========================================
  6717. *
  6718. *------------------------------------------*/
  6719. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6720. {
  6721. struct block_list* bl;
  6722. struct auth_node* node;
  6723. int cmd, account_id, char_id, login_id1, sex;
  6724. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6725. 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])
  6726. if (sd) {
  6727. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6728. return;
  6729. }
  6730. // Only valid packet version get here
  6731. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6732. cmd = RFIFOW(fd,0);
  6733. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6734. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6735. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6736. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6737. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6738. if( packet_ver < 5 || // reject really old client versions
  6739. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6740. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6741. {// packet version rejected
  6742. ShowInfo("Rejected connection attempt, forbidden packet version (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"', Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%s"CL_RESET"').\n", account_id, char_id, packet_ver, ip2str(session[fd]->client_addr, NULL));
  6743. WFIFOHEAD(fd,packet_len(0x6a));
  6744. WFIFOW(fd,0) = 0x6a;
  6745. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6746. WFIFOSET(fd,packet_len(0x6a));
  6747. set_eof(fd);
  6748. return;
  6749. }
  6750. //Check for double login.
  6751. bl = map_id2bl(account_id);
  6752. if(bl && bl->type != BL_PC) {
  6753. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6754. WFIFOHEAD(fd,packet_len(0x6a));
  6755. WFIFOW(fd,0) = 0x6a;
  6756. WFIFOB(fd,2) = 3; // Rejected by server
  6757. WFIFOSET(fd,packet_len(0x6a));
  6758. set_eof(fd);
  6759. return;
  6760. }
  6761. if (bl ||
  6762. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6763. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6764. sd = BL_CAST(BL_PC, bl);
  6765. if (!sd)
  6766. ; //We have another char with the same account logging in/out.
  6767. else //Already connected player.
  6768. if (sd->fd)
  6769. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6770. else
  6771. if(sd->state.autotrade)
  6772. map_quit(sd);// kick autotrading character
  6773. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6774. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6775. return;
  6776. }
  6777. CREATE(sd, TBL_PC, 1);
  6778. sd->fd = fd;
  6779. sd->packet_ver = packet_ver;
  6780. session[fd]->session_data = sd;
  6781. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6782. #if PACKETVER < 20070521
  6783. WFIFOHEAD(fd,4);
  6784. WFIFOL(fd,0) = sd->bl.id;
  6785. WFIFOSET(fd,4);
  6786. #else
  6787. WFIFOHEAD(fd,packet_len(0x283));
  6788. WFIFOW(fd,0) = 0x283;
  6789. WFIFOL(fd,2) = sd->bl.id;
  6790. WFIFOSET(fd,packet_len(0x283));
  6791. #endif
  6792. chrif_authreq(sd);
  6793. return;
  6794. }
  6795. /*==========================================
  6796. * 007d クライアント側マップ読み込み完了
  6797. * map侵入時に必要なデータを全て送りつける
  6798. *------------------------------------------*/
  6799. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6800. {
  6801. if(sd->bl.prev != NULL)
  6802. return;
  6803. if (!sd->state.active)
  6804. { //Character loading is not complete yet!
  6805. //Let pc_reg_received reinvoke this when ready.
  6806. sd->state.connect_new = 0;
  6807. return;
  6808. }
  6809. if (sd->state.rewarp)
  6810. { //Rewarp player.
  6811. sd->state.rewarp = 0;
  6812. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6813. return;
  6814. }
  6815. // look
  6816. #if PACKETVER < 4
  6817. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6818. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6819. #else
  6820. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6821. #endif
  6822. if(sd->vd.cloth_color)
  6823. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6824. // item
  6825. pc_checkitem(sd);
  6826. clif_inventorylist(sd);
  6827. // cart
  6828. if(pc_iscarton(sd)) {
  6829. clif_cartlist(sd);
  6830. clif_updatestatus(sd,SP_CARTINFO);
  6831. }
  6832. // weight
  6833. clif_updatestatus(sd,SP_WEIGHT);
  6834. clif_updatestatus(sd,SP_MAXWEIGHT);
  6835. // guild
  6836. // (needs to go before clif_spawn() to show guild emblems correctly)
  6837. if(sd->status.guild_id)
  6838. guild_send_memberinfoshort(sd,1);
  6839. if(battle_config.pc_invincible_time > 0) {
  6840. if(map_flag_gvg(sd->bl.m))
  6841. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6842. else
  6843. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6844. }
  6845. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6846. map_spawnmobs(sd->bl.m);
  6847. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  6848. map_addblock(&sd->bl);
  6849. clif_spawn(&sd->bl);
  6850. // Party
  6851. // (needs to go after clif_spawn() to show hp bars correctly)
  6852. if(sd->status.party_id) {
  6853. party_send_movemap(sd);
  6854. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6855. }
  6856. if(map[sd->bl.m].flag.pvp) {
  6857. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6858. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6859. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6860. sd->pvp_rank = 0;
  6861. sd->pvp_lastusers = 0;
  6862. sd->pvp_point = 5;
  6863. sd->pvp_won = 0;
  6864. sd->pvp_lost = 0;
  6865. }
  6866. clif_set0199(sd,1);
  6867. } else
  6868. // set flag, if it's a duel [LuzZza]
  6869. if(sd->duel_group)
  6870. clif_set0199(sd,1);
  6871. if (map[sd->bl.m].flag.gvg_dungeon)
  6872. {
  6873. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6874. if (!sd->pvp_point)
  6875. {
  6876. sd->pvp_point = 5; //Need to die twice to be warped out.
  6877. sd->pvp_won = 0;
  6878. sd->pvp_lost = 0;
  6879. }
  6880. }
  6881. if(map_flag_gvg(sd->bl.m))
  6882. {
  6883. clif_set0199(sd,3);
  6884. if (battle_config.gvg_flee_penalty != 100)
  6885. status_calc_bl(&sd->bl, SCB_FLEE); //Apply flee penalty
  6886. }
  6887. // info about nearby objects
  6888. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6889. 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);
  6890. //TODO: merge it with the code below
  6891. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6892. { //Return the pet to egg. [Skotlex]
  6893. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6894. pet_menu(sd, 3); //Option 3 is return to egg.
  6895. }
  6896. // pet
  6897. if(sd->pd) {
  6898. map_addblock(&sd->pd->bl);
  6899. clif_spawn(&sd->pd->bl);
  6900. clif_send_petdata(sd,sd->pd,0,0);
  6901. clif_send_petstatus(sd);
  6902. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6903. }
  6904. //homunculus [blackhole89]
  6905. if( merc_is_hom_active(sd->hd) )
  6906. {
  6907. map_addblock(&sd->hd->bl);
  6908. clif_spawn(&sd->hd->bl);
  6909. clif_send_homdata(sd,0,0);
  6910. clif_hominfo(sd,sd->hd,1);
  6911. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6912. clif_homskillinfoblock(sd);
  6913. if( battle_config.hom_setting&0x8 )
  6914. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6915. if( !(battle_config.hom_setting&0x2) )
  6916. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6917. }
  6918. if( sd->md )
  6919. {
  6920. map_addblock(&sd->md->bl);
  6921. clif_spawn(&sd->md->bl);
  6922. clif_mercenary_info(sd);
  6923. clif_mercenary_skillblock(sd);
  6924. }
  6925. if(sd->state.connect_new) {
  6926. int lv;
  6927. sd->state.connect_new = 0;
  6928. clif_skillinfoblock(sd);
  6929. clif_hotkeys_send(sd);
  6930. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6931. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6932. clif_updatestatus(sd,SP_SKILLPOINT);
  6933. clif_initialstatus(sd);
  6934. if (sd->sc.option&OPTION_FALCON)
  6935. clif_status_load(&sd->bl, SI_FALCON, 1);
  6936. if (sd->sc.option&OPTION_RIDING)
  6937. clif_status_load(&sd->bl, SI_RIDING, 1);
  6938. if(sd->status.manner < 0)
  6939. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6940. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6941. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6942. if(sd->bl.m == sd->feel_map[0].m
  6943. || sd->bl.m == sd->feel_map[1].m
  6944. || sd->bl.m == sd->feel_map[2].m)
  6945. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6946. }
  6947. if(sd->pd && sd->pd->pet.intimate > 900)
  6948. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6949. if(merc_is_hom_active(sd->hd))
  6950. merc_hom_init_timers(sd->hd);
  6951. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6952. {
  6953. sd->state.night = 1;
  6954. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6955. }
  6956. #if PACKETVER >= 20070918
  6957. clif_equipcheckbox(sd);
  6958. #endif
  6959. // Notify everyone that this char logged in [Skotlex].
  6960. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6961. //Login Event
  6962. npc_script_event(sd, NPCE_LOGIN);
  6963. } else {
  6964. //For some reason the client "loses" these on warp/map-change.
  6965. clif_updatestatus(sd,SP_STR);
  6966. clif_updatestatus(sd,SP_AGI);
  6967. clif_updatestatus(sd,SP_VIT);
  6968. clif_updatestatus(sd,SP_INT);
  6969. clif_updatestatus(sd,SP_DEX);
  6970. clif_updatestatus(sd,SP_LUK);
  6971. // abort currently running script
  6972. sd->state.using_fake_npc = 0;
  6973. sd->state.menu_or_input = 0;
  6974. sd->npc_menu = 0;
  6975. if(sd->npc_id)
  6976. npc_event_dequeue(sd);
  6977. }
  6978. if( sd->state.changemap )
  6979. {// restore information that gets lost on map-change
  6980. if( night_flag && map[sd->bl.m].flag.nightenabled )
  6981. { //Display night.
  6982. if( !sd->state.night )
  6983. {
  6984. sd->state.night = 1;
  6985. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6986. }
  6987. }
  6988. else if( sd->state.night )
  6989. { //Clear night display.
  6990. sd->state.night = 0;
  6991. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6992. }
  6993. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  6994. {
  6995. char output[128];
  6996. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  6997. clif_announce(&sd->bl, output, strlen(output) + 1, 0x00CC66, 3);
  6998. }
  6999. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7000. sd->state.changemap = false;
  7001. }
  7002. #ifndef TXT_ONLY
  7003. mail_clear(sd);
  7004. #endif
  7005. quest_pc_login(sd);
  7006. if(map[sd->bl.m].flag.loadevent) // Lance
  7007. npc_script_event(sd, NPCE_LOADMAP);
  7008. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7009. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7010. if (sd->sc.opt2) //Client loses these on warp.
  7011. clif_changeoption(&sd->bl);
  7012. clif_weather_check(sd);
  7013. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7014. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7015. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7016. else
  7017. sd->areanpc_id = 0;
  7018. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7019. if(pc_isdead(sd))
  7020. clif_clearunit_area(&sd->bl, 1);
  7021. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7022. // else
  7023. // clif_changed_dir(&sd->bl, SELF);
  7024. // Trigger skill effects if you appear standing on them
  7025. if(!battle_config.pc_invincible_time)
  7026. skill_unit_move(&sd->bl,gettick(),1);
  7027. }
  7028. /*==========================================
  7029. *
  7030. *------------------------------------------*/
  7031. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7032. {
  7033. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7034. WFIFOHEAD(fd, packet_len(0x7f));
  7035. WFIFOW(fd,0)=0x7f;
  7036. WFIFOL(fd,2)=gettick();
  7037. WFIFOSET(fd,packet_len(0x7f));
  7038. // removed until the socket problems are fixed. [FlavioJS]
  7039. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7040. return;
  7041. }
  7042. void clif_hotkeys_send(struct map_session_data *sd) {
  7043. #ifdef HOTKEY_SAVING
  7044. const int fd = sd->fd;
  7045. int i;
  7046. if (!fd) return;
  7047. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7048. WFIFOW(fd, 0) = 0x02b9;
  7049. for(i = 0; i < MAX_HOTKEYS; i++) {
  7050. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7051. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7052. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7053. }
  7054. WFIFOSET(fd, packet_len(0x02b9));
  7055. #endif
  7056. }
  7057. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7058. #ifdef HOTKEY_SAVING
  7059. unsigned short idx;
  7060. int cmd;
  7061. cmd = RFIFOW(fd, 0);
  7062. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7063. if (idx >= MAX_HOTKEYS) return;
  7064. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7065. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7066. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7067. return;
  7068. #endif
  7069. }
  7070. /*==========================================
  7071. *
  7072. *------------------------------------------*/
  7073. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7074. {
  7075. short x, y;
  7076. int cmd;
  7077. if (pc_isdead(sd)) {
  7078. clif_clearunit_area(&sd->bl, 1);
  7079. return;
  7080. }
  7081. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7082. ; //You CAN walk on this OPT1 value.
  7083. else if (pc_cant_act(sd))
  7084. return;
  7085. if(sd->sc.data[SC_RUN])
  7086. return;
  7087. pc_delinvincibletimer(sd);
  7088. cmd = RFIFOW(fd,0);
  7089. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7090. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7091. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7092. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7093. //Set last idle time... [Skotlex]
  7094. sd->idletime = last_tick;
  7095. unit_walktoxy(&sd->bl, x, y, 4);
  7096. }
  7097. /*==========================================
  7098. *
  7099. *------------------------------------------*/
  7100. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7101. {
  7102. WFIFOHEAD(fd,packet_len(0x18b));
  7103. WFIFOW(fd,0) = 0x18b;
  7104. /* Rovert's prevent logout option fixed [Valaris] */
  7105. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7106. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7107. ) {
  7108. set_eof(fd);
  7109. WFIFOW(fd,2)=0;
  7110. } else {
  7111. WFIFOW(fd,2)=1;
  7112. }
  7113. WFIFOSET(fd,packet_len(0x18b));
  7114. }
  7115. /// Requesting unit's name
  7116. /// S 0094 <object id>.l
  7117. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7118. {
  7119. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7120. struct block_list* bl;
  7121. //struct status_change *sc;
  7122. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7123. id = sd->bl.id;
  7124. bl = map_id2bl(id);
  7125. if( bl == NULL )
  7126. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7127. // 'see people in GM hide' cheat detection
  7128. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7129. sc = status_get_sc(bl);
  7130. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7131. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7132. pc_isGM(sd) < battle_config.hack_info_GM_level
  7133. ) {
  7134. char gm_msg[256];
  7135. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  7136. ShowWarning(gm_msg);
  7137. // information is sent to all online GMs
  7138. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7139. return;
  7140. }
  7141. */
  7142. clif_charnameack(fd, bl);
  7143. }
  7144. /*==========================================
  7145. * Validates and processes global messages
  7146. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7147. *------------------------------------------*/
  7148. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7149. {
  7150. const char* text = (char*)RFIFOP(fd,4);
  7151. int textlen = RFIFOW(fd,2) - 4;
  7152. char *name, *message;
  7153. int namelen, messagelen;
  7154. // validate packet and retrieve name and message
  7155. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7156. return;
  7157. if( is_atcommand(fd, sd, message) )
  7158. return;
  7159. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7160. return;
  7161. if( battle_config.min_chat_delay )
  7162. { //[Skotlex]
  7163. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7164. return;
  7165. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7166. }
  7167. // send message to others (using the send buffer for temp. storage)
  7168. WFIFOHEAD(fd, 8 + textlen);
  7169. WFIFOW(fd,0) = 0x8d;
  7170. WFIFOW(fd,2) = 8 + textlen;
  7171. WFIFOL(fd,4) = sd->bl.id;
  7172. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7173. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7174. // send back message to the speaker
  7175. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7176. WFIFOW(fd,0) = 0x8e;
  7177. WFIFOSET(fd, WFIFOW(fd,2));
  7178. #ifdef PCRE_SUPPORT
  7179. // trigger listening npcs
  7180. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7181. #endif
  7182. // check for special supernovice phrase
  7183. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7184. {
  7185. unsigned int next = pc_nextbaseexp(sd);
  7186. if( next == 0 ) next = pc_thisbaseexp(sd);
  7187. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7188. {
  7189. switch (sd->state.snovice_call_flag) {
  7190. case 0:
  7191. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7192. sd->state.snovice_call_flag++;
  7193. break;
  7194. case 1: {
  7195. char buf[256];
  7196. sprintf(buf, msg_txt(505), sd->status.name);
  7197. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7198. sd->state.snovice_call_flag++;
  7199. }
  7200. break;
  7201. case 2:
  7202. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7203. sd->state.snovice_call_flag++;
  7204. break;
  7205. case 3:
  7206. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7207. break; //Do not override the noskill mapflag. [Skotlex]
  7208. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7209. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7210. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7211. sd->state.snovice_call_flag = 0;
  7212. break;
  7213. }
  7214. }
  7215. }
  7216. // Chat logging type 'O' / Global Chat
  7217. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7218. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7219. return;
  7220. }
  7221. /*==========================================
  7222. * /mm /mapmove (as @rura GM command)
  7223. *------------------------------------------*/
  7224. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7225. {
  7226. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7227. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7228. char* map_name;
  7229. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7230. return;
  7231. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7232. return;
  7233. map_name = (char*)RFIFOP(fd,2);
  7234. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7235. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7236. atcommand_mapmove(fd, sd, "@mapmove", output);
  7237. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7238. {
  7239. sprintf(message, "/mm %s", output);
  7240. log_atcommand(sd, message);
  7241. }
  7242. return;
  7243. }
  7244. /*==========================================
  7245. *
  7246. *------------------------------------------*/
  7247. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7248. {
  7249. unsigned char buf[64];
  7250. WBUFW(buf,0) = 0x9c;
  7251. WBUFL(buf,2) = bl->id;
  7252. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7253. WBUFB(buf,8) = unit_getdir(bl);
  7254. clif_send(buf, packet_len(0x9c), bl, target);
  7255. if (disguised(bl)) {
  7256. WBUFL(buf,2) = -bl->id;
  7257. WBUFW(buf,6) = 0;
  7258. clif_send(buf, packet_len(0x9c), bl, SELF);
  7259. }
  7260. return;
  7261. }
  7262. /*==========================================
  7263. *
  7264. *------------------------------------------*/
  7265. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7266. {
  7267. unsigned char headdir, dir;
  7268. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7269. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7270. pc_setdir(sd, dir, headdir);
  7271. clif_changed_dir(&sd->bl, AREA_WOS);
  7272. return;
  7273. }
  7274. /*==========================================
  7275. *
  7276. *------------------------------------------*/
  7277. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7278. {
  7279. unsigned char buf[64];
  7280. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7281. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7282. clif_skill_fail(sd, 1, 0, 1);
  7283. return;
  7284. }
  7285. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7286. if (sd->emotionlasttime >= time(NULL)) {
  7287. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7288. clif_skill_fail(sd, 1, 0, 1);
  7289. return;
  7290. }
  7291. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7292. WBUFW(buf,0) = 0xc0;
  7293. WBUFL(buf,2) = sd->bl.id;
  7294. WBUFB(buf,6) = RFIFOB(fd,2);
  7295. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7296. } else
  7297. clif_skill_fail(sd, 1, 0, 1);
  7298. }
  7299. /*==========================================
  7300. *
  7301. *------------------------------------------*/
  7302. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7303. {
  7304. WFIFOHEAD(fd,packet_len(0xc2));
  7305. WFIFOW(fd,0) = 0xc2;
  7306. WFIFOL(fd,2) = map_getusers();
  7307. WFIFOSET(fd,packet_len(0xc2));
  7308. }
  7309. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7310. {
  7311. if (pc_isdead(sd)) {
  7312. clif_clearunit_area(&sd->bl, 1);
  7313. return;
  7314. }
  7315. if (sd->sc.count &&
  7316. (sd->sc.data[SC_TRICKDEAD] ||
  7317. sd->sc.data[SC_AUTOCOUNTER] ||
  7318. sd->sc.data[SC_BLADESTOP]))
  7319. return;
  7320. pc_stop_walking(sd, 1);
  7321. pc_stop_attack(sd);
  7322. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7323. target_id = sd->bl.id;
  7324. switch(action_type)
  7325. {
  7326. case 0x00: // once attack
  7327. case 0x07: // continuous attack
  7328. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7329. return;
  7330. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7331. return;
  7332. if( sd->sc.data[SC_BASILICA] )
  7333. return;
  7334. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7335. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7336. clif_skill_fail(sd, 1, 4, 0);
  7337. return;
  7338. }
  7339. }
  7340. pc_delinvincibletimer(sd);
  7341. sd->idletime = last_tick;
  7342. unit_attack(&sd->bl, target_id, action_type != 0);
  7343. break;
  7344. case 0x02: // sitdown
  7345. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7346. clif_skill_fail(sd, 1, 0, 2);
  7347. break;
  7348. }
  7349. if(pc_issit(sd)) {
  7350. //Bugged client? Just refresh them.
  7351. clif_sitting(&sd->bl);
  7352. return;
  7353. }
  7354. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7355. break;
  7356. if (sd->sc.count && (
  7357. sd->sc.data[SC_DANCING] ||
  7358. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7359. )) //No sitting during these states either.
  7360. break;
  7361. pc_setsit(sd);
  7362. skill_sit(sd,1);
  7363. clif_sitting(&sd->bl);
  7364. break;
  7365. case 0x03: // standup
  7366. if (!pc_issit(sd)) {
  7367. //Bugged client? Just refresh them.
  7368. clif_standing(&sd->bl);
  7369. return;
  7370. }
  7371. pc_setstand(sd);
  7372. skill_sit(sd,0);
  7373. clif_standing(&sd->bl);
  7374. break;
  7375. }
  7376. }
  7377. /*==========================================
  7378. *
  7379. *------------------------------------------*/
  7380. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7381. {
  7382. clif_parse_ActionRequest_sub(sd,
  7383. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7384. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7385. gettick()
  7386. );
  7387. }
  7388. /*==========================================
  7389. *
  7390. *------------------------------------------*/
  7391. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7392. {
  7393. switch(RFIFOB(fd,2)) {
  7394. case 0x00:
  7395. pc_respawn(sd,2);
  7396. break;
  7397. case 0x01:
  7398. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7399. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7400. { //Send to char-server for character selection.
  7401. chrif_charselectreq(sd, session[fd]->client_addr);
  7402. } else {
  7403. WFIFOHEAD(fd,packet_len(0x18b));
  7404. WFIFOW(fd,0)=0x18b;
  7405. WFIFOW(fd,2)=1;
  7406. WFIFOSET(fd,packet_len(0x018b));
  7407. }
  7408. break;
  7409. }
  7410. }
  7411. /*==========================================
  7412. * Validates and processes whispered messages
  7413. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7414. *------------------------------------------*/
  7415. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7416. {
  7417. struct map_session_data* dstsd;
  7418. int i;
  7419. char *target, *message;
  7420. int namelen, messagelen;
  7421. // validate packet and retrieve name and message
  7422. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7423. return;
  7424. if (is_atcommand(fd, sd, message) )
  7425. return;
  7426. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7427. return;
  7428. if (battle_config.min_chat_delay)
  7429. { //[Skotlex]
  7430. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7431. return;
  7432. }
  7433. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7434. }
  7435. // Chat logging type 'W' / Whisper
  7436. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7437. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7438. //-------------------------------------------------------//
  7439. // Lordalfa - Paperboy - To whisper NPC commands //
  7440. //-------------------------------------------------------//
  7441. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7442. {
  7443. char* str = target+4; //Skip the NPC: string part.
  7444. struct npc_data* npc;
  7445. if ((npc = npc_name2id(str)))
  7446. {
  7447. char split_data[10][50];
  7448. char *split;
  7449. char output[256];
  7450. str = message;
  7451. for( i = 0; i < 10; ++i )
  7452. {// Splits the message using '#' as separators
  7453. split = strchr(str,'#');
  7454. if( split == NULL )
  7455. { // use the remaining string
  7456. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7457. for( ++i; i < 10; ++i )
  7458. split_data[i][0] = '\0';
  7459. break;
  7460. }
  7461. *split = '\0';
  7462. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7463. str = split+1;
  7464. }
  7465. for( i = 0; i < 10; ++i )
  7466. {
  7467. sprintf(output, "@whispervar%d$", i);
  7468. set_var(sd,output,(char *) split_data[i]);
  7469. }
  7470. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7471. npc_event(sd,output,0); // Calls the NPC label
  7472. return;
  7473. }
  7474. }
  7475. // Main chat [LuzZza]
  7476. if(strcmpi(target, main_chat_nick) == 0)
  7477. {
  7478. if(!sd->state.mainchat)
  7479. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7480. else {
  7481. char output[256];
  7482. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7483. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7484. }
  7485. // Chat logging type 'M' / Main Chat
  7486. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7487. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7488. return;
  7489. }
  7490. // searching destination character
  7491. dstsd = map_nick2sd(target);
  7492. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7493. {
  7494. // player is not on this map-server
  7495. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7496. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7497. // and if we ask for 'Test', we must not contact 'test' player
  7498. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7499. intif_wis_message(sd, target, message, messagelen);
  7500. return;
  7501. }
  7502. // if player ignores everyone
  7503. if (dstsd->state.ignoreAll)
  7504. {
  7505. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7506. clif_wis_end(fd, 1); // 1: target character is not loged in
  7507. else
  7508. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7509. return;
  7510. }
  7511. // if player ignores the source character
  7512. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7513. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7514. { // source char present in ignore list
  7515. clif_wis_end(fd, 2); // 2: ignored by target
  7516. return;
  7517. }
  7518. // if player is autotrading
  7519. if( dstsd->state.autotrade == 1 )
  7520. {
  7521. char output[256];
  7522. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  7523. clif_wis_message(fd, sd->status.name, output, strlen(output) + 1);
  7524. return;
  7525. }
  7526. // notify sender of success
  7527. clif_wis_end(fd, 0); // 0: success to send wisper
  7528. // if player has an auto-away message
  7529. if(dstsd->away_message[0] != '\0')
  7530. {
  7531. char output[256];
  7532. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7533. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7534. if(dstsd->state.autotrade)
  7535. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7536. else
  7537. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7538. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7539. return;
  7540. }
  7541. // Normal message
  7542. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7543. return;
  7544. }
  7545. /*==========================================
  7546. * /b /nb
  7547. * S 0099 <packet len>.w <text>.?B 00
  7548. *------------------------------------------*/
  7549. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7550. {
  7551. char* msg = (char*)RFIFOP(fd,4);
  7552. unsigned int len = RFIFOW(fd,2)-4;
  7553. int lv;
  7554. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7555. return;
  7556. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7557. return;
  7558. // as the length varies depending on the command used, just block unreasonably long strings
  7559. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7560. intif_GMmessage(msg, len, 0);
  7561. if(log_config.gm && lv >= log_config.gm) {
  7562. char logmsg[CHAT_SIZE_MAX+4];
  7563. sprintf(logmsg, "/b %s", msg);
  7564. log_atcommand(sd, logmsg);
  7565. }
  7566. }
  7567. /*==========================================
  7568. *
  7569. *------------------------------------------*/
  7570. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7571. {
  7572. struct flooritem_data *fitem;
  7573. int map_object_id;
  7574. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7575. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7576. do {
  7577. if (pc_isdead(sd)) {
  7578. clif_clearunit_area(&sd->bl, 1);
  7579. break;
  7580. }
  7581. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7582. break;
  7583. if (pc_cant_act(sd))
  7584. break;
  7585. if(sd->sc.count && (
  7586. sd->sc.data[SC_HIDING] ||
  7587. sd->sc.data[SC_CLOAKING] ||
  7588. sd->sc.data[SC_TRICKDEAD] ||
  7589. sd->sc.data[SC_BLADESTOP] ||
  7590. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7591. )
  7592. break;
  7593. if (!pc_takeitem(sd, fitem))
  7594. break;
  7595. return;
  7596. } while (0);
  7597. // Client REQUIRES a fail packet or you can no longer pick items.
  7598. clif_additem(sd,0,0,6);
  7599. }
  7600. /*==========================================
  7601. *
  7602. *------------------------------------------*/
  7603. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7604. {
  7605. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7606. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7607. do {
  7608. if (pc_isdead(sd))
  7609. break;
  7610. if (pc_cant_act(sd))
  7611. break;
  7612. if (sd->sc.count && (
  7613. sd->sc.data[SC_HIDING] ||
  7614. sd->sc.data[SC_AUTOCOUNTER] ||
  7615. sd->sc.data[SC_BLADESTOP] ||
  7616. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7617. ))
  7618. break;
  7619. if (!pc_dropitem(sd, item_index, item_amount))
  7620. break;
  7621. return;
  7622. } while (0);
  7623. //Because the client does not like being ignored.
  7624. clif_delitem(sd, item_index,0);
  7625. }
  7626. /*==========================================
  7627. *
  7628. *------------------------------------------*/
  7629. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7630. {
  7631. int n;
  7632. if (pc_isdead(sd)) {
  7633. clif_clearunit_area(&sd->bl, 1);
  7634. return;
  7635. }
  7636. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7637. return;
  7638. //This flag enables you to use items while in an NPC. [Skotlex]
  7639. if (sd->npc_id) {
  7640. if (sd->npc_id != sd->npc_item_flag)
  7641. return;
  7642. } else
  7643. if (pc_istrading(sd))
  7644. return;
  7645. pc_delinvincibletimer(sd);
  7646. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7647. sd->idletime = last_tick;
  7648. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7649. if(n <0 || n >= MAX_INVENTORY)
  7650. return;
  7651. if (!pc_useitem(sd,n))
  7652. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7653. }
  7654. /*==========================================
  7655. *
  7656. *------------------------------------------*/
  7657. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7658. {
  7659. int index;
  7660. if(pc_isdead(sd)) {
  7661. clif_clearunit_area(&sd->bl,1);
  7662. return;
  7663. }
  7664. index = RFIFOW(fd,2)-2;
  7665. if (index < 0 || index >= MAX_INVENTORY)
  7666. return; //Out of bounds check.
  7667. if(sd->npc_id) {
  7668. if (sd->npc_id != sd->npc_item_flag)
  7669. return;
  7670. } else if (sd->state.storage_flag || sd->sc.opt1)
  7671. ; //You can equip/unequip stuff while storage is open/under status changes
  7672. else if (pc_cant_act(sd))
  7673. return;
  7674. if(!sd->status.inventory[index].identify) {
  7675. clif_equipitemack(sd,index,0,0); // fail
  7676. return;
  7677. }
  7678. if(!sd->inventory_data[index])
  7679. return;
  7680. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7681. pet_equipitem(sd,index);
  7682. return;
  7683. }
  7684. //Client doesn't send the position for ammo.
  7685. if(sd->inventory_data[index]->type == IT_AMMO)
  7686. pc_equipitem(sd,index,EQP_AMMO);
  7687. else
  7688. pc_equipitem(sd,index,RFIFOW(fd,4));
  7689. }
  7690. /*==========================================
  7691. *
  7692. *------------------------------------------*/
  7693. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7694. {
  7695. int index;
  7696. if(pc_isdead(sd)) {
  7697. clif_clearunit_area(&sd->bl,1);
  7698. return;
  7699. }
  7700. if (sd->state.storage_flag)
  7701. ; //You can equip/unequip stuff while storage is open.
  7702. else if (pc_cant_act(sd))
  7703. return;
  7704. index = RFIFOW(fd,2)-2;
  7705. pc_unequipitem(sd,index,1);
  7706. }
  7707. /*==========================================
  7708. *
  7709. *------------------------------------------*/
  7710. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7711. {
  7712. struct block_list *bl;
  7713. if(pc_isdead(sd)) {
  7714. clif_clearunit_area(&sd->bl,1);
  7715. return;
  7716. }
  7717. if (pc_cant_act(sd))
  7718. return;
  7719. bl = map_id2bl(RFIFOL(fd,2));
  7720. if (!bl) return;
  7721. switch (bl->type) {
  7722. case BL_MOB:
  7723. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7724. break;
  7725. case BL_PC:
  7726. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7727. break;
  7728. case BL_NPC:
  7729. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  7730. npc_click(sd,(TBL_NPC*)bl);
  7731. break;
  7732. }
  7733. return;
  7734. }
  7735. /*==========================================
  7736. *
  7737. *------------------------------------------*/
  7738. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7739. {
  7740. if (sd->state.trading)
  7741. return;
  7742. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7743. }
  7744. /// Request to buy chosen items from npc shop
  7745. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  7746. /// R 00ca <result>.b
  7747. /// result = 00 -> "The deal has successfully completed."
  7748. /// result = 01 -> "You do not have enough zeny."
  7749. /// result = 02 -> "You are over your Weight Limit."
  7750. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  7751. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  7752. {
  7753. int n = (RFIFOW(fd,2)-4) /4;
  7754. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  7755. int result;
  7756. if( sd->state.trading || !sd->npc_shopid )
  7757. result = 1;
  7758. else
  7759. result = npc_buylist(sd,n,item_list);
  7760. sd->npc_shopid = 0; //Clear shop data.
  7761. WFIFOHEAD(fd,packet_len(0xca));
  7762. WFIFOW(fd,0) = 0xca;
  7763. WFIFOB(fd,2) = result;
  7764. WFIFOSET(fd,packet_len(0xca));
  7765. }
  7766. /*==========================================
  7767. *
  7768. *------------------------------------------*/
  7769. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7770. {
  7771. int fail=0,n;
  7772. unsigned short *item_list;
  7773. n = (RFIFOW(fd,2)-4) /4;
  7774. item_list = (unsigned short*)RFIFOP(fd,4);
  7775. if (sd->state.trading || !sd->npc_shopid)
  7776. fail = 1;
  7777. else
  7778. fail = npc_selllist(sd,n,item_list);
  7779. sd->npc_shopid = 0; //Clear shop data.
  7780. WFIFOHEAD(fd,packet_len(0xcb));
  7781. WFIFOW(fd,0)=0xcb;
  7782. WFIFOB(fd,2)=fail;
  7783. WFIFOSET(fd,packet_len(0xcb));
  7784. }
  7785. /*==========================================
  7786. * Chatroom creation request
  7787. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7788. *------------------------------------------*/
  7789. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7790. {
  7791. int len = RFIFOW(fd,2)-15;
  7792. int limit = RFIFOW(fd,4);
  7793. bool pub = (RFIFOB(fd,6) != 0);
  7794. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7795. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7796. char s_title[CHATROOM_TITLE_SIZE];
  7797. char s_password[CHATROOM_PASS_SIZE];
  7798. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7799. return;
  7800. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7801. clif_skill_fail(sd,1,0,3);
  7802. return;
  7803. }
  7804. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7805. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7806. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7807. }
  7808. /*==========================================
  7809. * Chatroom join request
  7810. * S 00d9 <chat ID>.l <passwd>.8B
  7811. *------------------------------------------*/
  7812. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7813. {
  7814. int chatid = RFIFOL(fd,2);
  7815. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7816. chat_joinchat(sd,chatid,password);
  7817. }
  7818. /*==========================================
  7819. * Chatroom properties adjustment request
  7820. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7821. *------------------------------------------*/
  7822. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7823. {
  7824. int len = RFIFOW(fd,2)-15;
  7825. int limit = RFIFOW(fd,4);
  7826. bool pub = (RFIFOB(fd,6) != 0);
  7827. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7828. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7829. char s_title[CHATROOM_TITLE_SIZE];
  7830. char s_password[CHATROOM_PASS_SIZE];
  7831. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7832. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7833. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7834. }
  7835. /*==========================================
  7836. * S 00e0 ?.l <nick>.24B
  7837. *------------------------------------------*/
  7838. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7839. {
  7840. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7841. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7842. }
  7843. /*==========================================
  7844. *
  7845. *------------------------------------------*/
  7846. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7847. {
  7848. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7849. }
  7850. /*==========================================
  7851. * Request to leave the current chatroom
  7852. * S 00e3
  7853. *------------------------------------------*/
  7854. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7855. {
  7856. chat_leavechat(sd,0);
  7857. }
  7858. //Handles notifying asker and rejecter of what has just ocurred.
  7859. //Type is used to determine the correct msg_txt to use:
  7860. //0:
  7861. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7862. {
  7863. char *msg, output[256];
  7864. // Your request has been rejected by autoreject option.
  7865. msg = msg_txt(392);
  7866. clif_disp_onlyself(src, msg, strlen(msg));
  7867. //Notice that a request was rejected.
  7868. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7869. clif_disp_onlyself(target, output, strlen(output));
  7870. }
  7871. /*==========================================
  7872. * 取引要請を相手に送る
  7873. *------------------------------------------*/
  7874. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7875. {
  7876. struct map_session_data *t_sd;
  7877. t_sd = map_id2sd(RFIFOL(fd,2));
  7878. if(!sd->chatID && pc_cant_act(sd))
  7879. return; //You can trade while in a chatroom.
  7880. // @noask [LuzZza]
  7881. if(t_sd && t_sd->state.noask) {
  7882. clif_noask_sub(sd, t_sd, 0);
  7883. return;
  7884. }
  7885. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  7886. {
  7887. clif_skill_fail(sd,1,0,0);
  7888. return;
  7889. }
  7890. trade_traderequest(sd,t_sd);
  7891. }
  7892. /*==========================================
  7893. * 取引要請
  7894. *------------------------------------------*/
  7895. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7896. {
  7897. trade_tradeack(sd,RFIFOB(fd,2));
  7898. }
  7899. /*==========================================
  7900. * アイテム追加
  7901. *------------------------------------------*/
  7902. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7903. {
  7904. short index = RFIFOW(fd,2);
  7905. int amount = RFIFOL(fd,4);
  7906. if( index == 0 )
  7907. trade_tradeaddzeny(sd, amount);
  7908. else
  7909. trade_tradeadditem(sd, index, (short)amount);
  7910. }
  7911. /*==========================================
  7912. * アイテム追加完了(ok押し)
  7913. *------------------------------------------*/
  7914. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7915. {
  7916. trade_tradeok(sd);
  7917. }
  7918. /*==========================================
  7919. * 取引キャンセル
  7920. *------------------------------------------*/
  7921. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7922. {
  7923. trade_tradecancel(sd);
  7924. }
  7925. /*==========================================
  7926. * 取引許諾(trade押し)
  7927. *------------------------------------------*/
  7928. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7929. {
  7930. trade_tradecommit(sd);
  7931. }
  7932. /*==========================================
  7933. *
  7934. *------------------------------------------*/
  7935. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7936. {
  7937. pc_stop_attack(sd);
  7938. }
  7939. /*==========================================
  7940. * カートへアイテムを移す
  7941. *------------------------------------------*/
  7942. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7943. {
  7944. if (pc_istrading(sd))
  7945. return;
  7946. if (!pc_iscarton(sd))
  7947. return;
  7948. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7949. }
  7950. /*==========================================
  7951. * カートからアイテムを出す
  7952. *------------------------------------------*/
  7953. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7954. {
  7955. if (!pc_iscarton(sd))
  7956. return;
  7957. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7958. }
  7959. /*==========================================
  7960. * 付属品(鷹,ペコ,カート)をはずす
  7961. *------------------------------------------*/
  7962. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7963. {
  7964. //Can only remove Cart/Riding/Falcon.
  7965. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7966. }
  7967. /*==========================================
  7968. * チェンジカート
  7969. *------------------------------------------*/
  7970. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7971. {
  7972. int type;
  7973. type = (int)RFIFOW(fd,2);
  7974. if( (type == 5 && sd->status.base_level > 90) ||
  7975. (type == 4 && sd->status.base_level > 80) ||
  7976. (type == 3 && sd->status.base_level > 65) ||
  7977. (type == 2 && sd->status.base_level > 40) ||
  7978. (type == 1))
  7979. pc_setcart(sd,type);
  7980. }
  7981. /*==========================================
  7982. * ステータスアップ
  7983. *------------------------------------------*/
  7984. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7985. {
  7986. pc_statusup(sd,RFIFOW(fd,2));
  7987. }
  7988. /*==========================================
  7989. * スキルレベルアップ
  7990. *------------------------------------------*/
  7991. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7992. {
  7993. pc_skillup(sd,RFIFOW(fd,2));
  7994. }
  7995. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  7996. {
  7997. int lv;
  7998. if( !hd )
  7999. return;
  8000. if( skillnotok_hom(skillnum, hd) )
  8001. return;
  8002. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8003. target_id = hd->bl.id;
  8004. if( hd->ud.skilltimer != -1 )
  8005. {
  8006. if( skillnum != SA_CASTCANCEL ) return;
  8007. }
  8008. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8009. return;
  8010. lv = merc_hom_checkskill(hd, skillnum);
  8011. if( skilllv > lv )
  8012. skilllv = lv;
  8013. if( skilllv )
  8014. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8015. }
  8016. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8017. {
  8018. int lv;
  8019. if( !md )
  8020. return;
  8021. if( skillnotok_mercenary(skillnum, md) )
  8022. return;
  8023. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8024. target_id = md->bl.id;
  8025. if( md->ud.skilltimer != INVALID_TIMER )
  8026. {
  8027. if( skillnum != SA_CASTCANCEL ) return;
  8028. }
  8029. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8030. return;
  8031. lv = mercenary_checkskill(md, skillnum);
  8032. if( skilllv > lv )
  8033. skilllv = lv;
  8034. if( skilllv )
  8035. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8036. }
  8037. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  8038. {
  8039. int lv;
  8040. if( !md )
  8041. return;
  8042. if( skillnotok_mercenary(skillnum, md) )
  8043. return;
  8044. if( md->ud.skilltimer != INVALID_TIMER )
  8045. return;
  8046. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8047. {
  8048. clif_skill_fail(md->master, skillnum, 4, 0);
  8049. return;
  8050. }
  8051. if( md->sc.data[SC_BASILICA] )
  8052. return;
  8053. lv = mercenary_checkskill(md, skillnum);
  8054. if( skilllv > lv )
  8055. skilllv = lv;
  8056. if( skilllv )
  8057. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8058. }
  8059. /*==========================================
  8060. * スキル使用(ID指定)
  8061. *------------------------------------------*/
  8062. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8063. {
  8064. short skillnum, skilllv;
  8065. int tmp, target_id;
  8066. unsigned int tick = gettick();
  8067. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8068. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8069. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8070. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8071. tmp = skill_get_inf(skillnum);
  8072. if (tmp&INF_GROUND_SKILL || !tmp)
  8073. return; //Using a ground/passive skill on a target? WRONG.
  8074. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8075. {
  8076. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8077. return;
  8078. }
  8079. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8080. {
  8081. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8082. return;
  8083. }
  8084. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8085. sd->idletime = last_tick;
  8086. if( pc_cant_act(sd) )
  8087. return;
  8088. if( pc_issit(sd) )
  8089. return;
  8090. if( skillnotok(skillnum, sd) )
  8091. return;
  8092. if( sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL )
  8093. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8094. if( sd->ud.skilltimer != -1 )
  8095. {
  8096. if( skillnum != SA_CASTCANCEL )
  8097. return;
  8098. }
  8099. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8100. {
  8101. clif_skill_fail(sd, skillnum, 4, 0);
  8102. return;
  8103. }
  8104. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8105. return;
  8106. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8107. return; // On basilica only caster can use Basilica again to stop it.
  8108. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8109. target_id = sd->bl.id;
  8110. if( sd->menuskill_id )
  8111. {
  8112. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8113. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8114. else if( sd->menuskill_id != SA_AUTOSPELL )
  8115. return; //Can't use skills while a menu is open.
  8116. }
  8117. if( sd->skillitem == skillnum )
  8118. {
  8119. if( skilllv != sd->skillitemlv )
  8120. skilllv = sd->skillitemlv;
  8121. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8122. return;
  8123. }
  8124. sd->skillitem = sd->skillitemlv = 0;
  8125. if( skillnum == MO_EXTREMITYFIST )
  8126. {
  8127. if( (!sd->sc.data[SC_COMBO] ||
  8128. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8129. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8130. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8131. if( !sd->state.skill_flag )
  8132. {
  8133. sd->state.skill_flag = 1;
  8134. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8135. return;
  8136. } else if( sd->bl.id == target_id )
  8137. {
  8138. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8139. return;
  8140. }
  8141. }
  8142. }
  8143. if( skillnum == TK_JUMPKICK )
  8144. {
  8145. if( !sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK )
  8146. {
  8147. if( !sd->state.skill_flag )
  8148. {
  8149. sd->state.skill_flag = 1;
  8150. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8151. return;
  8152. }
  8153. else if( sd->bl.id == target_id )
  8154. {
  8155. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8156. return;
  8157. }
  8158. }
  8159. }
  8160. if( skillnum >= GD_SKILLBASE )
  8161. {
  8162. if( sd->state.gmaster_flag )
  8163. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8164. else
  8165. skilllv = 0;
  8166. }
  8167. else
  8168. {
  8169. tmp = pc_checkskill(sd, skillnum);
  8170. if( skilllv > tmp )
  8171. skilllv = tmp;
  8172. }
  8173. pc_delinvincibletimer(sd);
  8174. if( skilllv )
  8175. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8176. if( sd->state.skill_flag )
  8177. sd->state.skill_flag = 0;
  8178. }
  8179. /*==========================================
  8180. * スキル使用(場所指定)
  8181. *------------------------------------------*/
  8182. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8183. {
  8184. int lv;
  8185. unsigned int tick = gettick();
  8186. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8187. return; //Using a target skill on the ground? WRONG.
  8188. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8189. {
  8190. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8191. return;
  8192. }
  8193. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8194. sd->idletime = last_tick;
  8195. if( skillnotok(skillnum, sd) )
  8196. return;
  8197. if( skillmoreinfo != -1 )
  8198. {
  8199. if( pc_issit(sd) )
  8200. {
  8201. clif_skill_fail(sd, skillnum, 0, 0);
  8202. return;
  8203. }
  8204. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8205. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8206. }
  8207. if( sd->ud.skilltimer != -1 )
  8208. return;
  8209. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8210. {
  8211. clif_skill_fail(sd, skillnum, 4, 0);
  8212. return;
  8213. }
  8214. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8215. return;
  8216. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8217. return; // On basilica only caster can use Basilica again to stop it.
  8218. if( sd->menuskill_id )
  8219. {
  8220. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8221. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8222. else if( sd->menuskill_id != SA_AUTOSPELL )
  8223. return; //Can't use skills while a menu is open.
  8224. }
  8225. pc_delinvincibletimer(sd);
  8226. if( sd->skillitem == skillnum )
  8227. {
  8228. if( skilllv != sd->skillitemlv )
  8229. skilllv = sd->skillitemlv;
  8230. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8231. }
  8232. else
  8233. {
  8234. sd->skillitem = sd->skillitemlv = 0;
  8235. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8236. {
  8237. if( skilllv > lv )
  8238. skilllv = lv;
  8239. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8240. }
  8241. }
  8242. }
  8243. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8244. {
  8245. if (pc_cant_act(sd))
  8246. return;
  8247. if (pc_issit(sd))
  8248. return;
  8249. clif_parse_UseSkillToPosSub(fd, sd,
  8250. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8251. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8252. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8253. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8254. -1 //Skill more info.
  8255. );
  8256. }
  8257. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8258. {
  8259. if (pc_cant_act(sd))
  8260. return;
  8261. if (pc_issit(sd))
  8262. return;
  8263. clif_parse_UseSkillToPosSub(fd, sd,
  8264. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8265. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8266. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8267. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8268. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8269. );
  8270. }
  8271. /*==========================================
  8272. * スキル使用(map指定)
  8273. *------------------------------------------*/
  8274. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8275. {
  8276. short skill_num = RFIFOW(fd,2);
  8277. char map_name[MAP_NAME_LENGTH];
  8278. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8279. if(skill_num != sd->menuskill_id)
  8280. return;
  8281. if( pc_cant_act(sd) )
  8282. {
  8283. sd->menuskill_id = sd->menuskill_val = 0;
  8284. return;
  8285. }
  8286. pc_delinvincibletimer(sd);
  8287. skill_castend_map(sd,skill_num,map_name);
  8288. }
  8289. /*==========================================
  8290. * メモ要求
  8291. *------------------------------------------*/
  8292. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8293. {
  8294. if (!pc_isdead(sd))
  8295. pc_memo(sd,-1);
  8296. }
  8297. /*==========================================
  8298. * アイテム合成
  8299. *------------------------------------------*/
  8300. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8301. {
  8302. if (sd->menuskill_id != AM_PHARMACY)
  8303. return;
  8304. if (pc_istrading(sd)) {
  8305. //Make it fail to avoid shop exploits where you sell something different than you see.
  8306. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8307. sd->menuskill_val = sd->menuskill_id = 0;
  8308. return;
  8309. }
  8310. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8311. sd->menuskill_val = sd->menuskill_id = 0;
  8312. }
  8313. /*==========================================
  8314. * 武器修理
  8315. *------------------------------------------*/
  8316. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8317. {
  8318. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8319. return;
  8320. if (pc_istrading(sd)) {
  8321. //Make it fail to avoid shop exploits where you sell something different than you see.
  8322. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8323. sd->menuskill_val = sd->menuskill_id = 0;
  8324. return;
  8325. }
  8326. skill_repairweapon(sd,RFIFOW(fd,2));
  8327. sd->menuskill_val = sd->menuskill_id = 0;
  8328. }
  8329. /*==========================================
  8330. *
  8331. *------------------------------------------*/
  8332. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8333. {
  8334. int idx;
  8335. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8336. return;
  8337. if (pc_istrading(sd)) {
  8338. //Make it fail to avoid shop exploits where you sell something different than you see.
  8339. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8340. sd->menuskill_val = sd->menuskill_id = 0;
  8341. return;
  8342. }
  8343. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8344. skill_weaponrefine(sd, idx-2);
  8345. sd->menuskill_val = sd->menuskill_id = 0;
  8346. }
  8347. /*==========================================
  8348. *
  8349. *------------------------------------------*/
  8350. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8351. {
  8352. uint8 select;
  8353. select = RFIFOB(fd,6);
  8354. if((select > sd->npc_menu && select != 0xff) || !select){
  8355. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8356. clif_GM_kick(NULL,sd);
  8357. } else {
  8358. sd->npc_menu=select;
  8359. npc_scriptcont(sd,RFIFOL(fd,2));
  8360. }
  8361. }
  8362. /*==========================================
  8363. *
  8364. *------------------------------------------*/
  8365. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8366. {
  8367. npc_scriptcont(sd,RFIFOL(fd,2));
  8368. }
  8369. /*==========================================
  8370. * Value entered into a NPC input box.
  8371. * S 0143 <npcID>.l <amount>.l
  8372. *------------------------------------------*/
  8373. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8374. {
  8375. int npcid = RFIFOL(fd,2);
  8376. int amount = (int)RFIFOL(fd,6);
  8377. sd->npc_amount = amount;
  8378. npc_scriptcont(sd, npcid);
  8379. }
  8380. /*==========================================
  8381. * Text entered into a NPC input box.
  8382. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8383. *------------------------------------------*/
  8384. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8385. {
  8386. int message_len = RFIFOW(fd,2)-8;
  8387. int npcid = RFIFOL(fd,4);
  8388. const char* message = (char*)RFIFOP(fd,8);
  8389. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8390. npc_scriptcont(sd, npcid);
  8391. }
  8392. /*==========================================
  8393. *
  8394. *------------------------------------------*/
  8395. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8396. {
  8397. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8398. return;
  8399. npc_scriptcont(sd,RFIFOL(fd,2));
  8400. }
  8401. /*==========================================
  8402. * アイテム鑑定
  8403. *------------------------------------------*/
  8404. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8405. {
  8406. if (sd->menuskill_id != MC_IDENTIFY)
  8407. return;
  8408. skill_identify(sd,RFIFOW(fd,2)-2);
  8409. sd->menuskill_val = sd->menuskill_id = 0;
  8410. }
  8411. /*==========================================
  8412. * 矢作成
  8413. *------------------------------------------*/
  8414. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8415. {
  8416. if (sd->menuskill_id != AC_MAKINGARROW)
  8417. return;
  8418. if (pc_istrading(sd)) {
  8419. //Make it fail to avoid shop exploits where you sell something different than you see.
  8420. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8421. sd->menuskill_val = sd->menuskill_id = 0;
  8422. return;
  8423. }
  8424. skill_arrow_create(sd,RFIFOW(fd,2));
  8425. sd->menuskill_val = sd->menuskill_id = 0;
  8426. }
  8427. /*==========================================
  8428. * オートスペル受信
  8429. *------------------------------------------*/
  8430. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8431. {
  8432. if (sd->menuskill_id != SA_AUTOSPELL)
  8433. return;
  8434. skill_autospell(sd,RFIFOW(fd,2));
  8435. sd->menuskill_val = sd->menuskill_id = 0;
  8436. }
  8437. /*==========================================
  8438. * カード使用
  8439. *------------------------------------------*/
  8440. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8441. {
  8442. if (sd->state.trading != 0)
  8443. return;
  8444. clif_use_card(sd,RFIFOW(fd,2)-2);
  8445. }
  8446. /*==========================================
  8447. * カード挿入装備選択
  8448. *------------------------------------------*/
  8449. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8450. {
  8451. if (sd->state.trading != 0)
  8452. return;
  8453. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8454. }
  8455. /*==========================================
  8456. * 0193 キャラID名前引き
  8457. *------------------------------------------*/
  8458. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8459. {
  8460. int charid;
  8461. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8462. map_reqnickdb(sd, charid);
  8463. }
  8464. /*==========================================
  8465. * 0197 /resetskill /resetstate
  8466. *------------------------------------------*/
  8467. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8468. {
  8469. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8470. return;
  8471. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8472. return;
  8473. if( RFIFOW(fd,2) )
  8474. pc_resetskill(sd,1);
  8475. else
  8476. pc_resetstate(sd);
  8477. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8478. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8479. }
  8480. /*==========================================
  8481. * /lb /nlb
  8482. * S 019c <packet len>.w <text>.?B 00
  8483. *------------------------------------------*/
  8484. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8485. {
  8486. char* msg = (char*)RFIFOP(fd,4);
  8487. unsigned int len = RFIFOW(fd,2)-4;
  8488. int lv;
  8489. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8490. return;
  8491. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8492. return;
  8493. // as the length varies depending on the command used, just block unreasonably long strings
  8494. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8495. clif_GMmessage(&sd->bl, msg, len, 1);
  8496. if( log_config.gm && lv >= log_config.gm ) {
  8497. char logmsg[CHAT_SIZE_MAX+5];
  8498. sprintf(logmsg, "/lb %s", msg);
  8499. log_atcommand(sd, logmsg);
  8500. }
  8501. }
  8502. /*==========================================
  8503. * カプラ倉庫へ入れる
  8504. *------------------------------------------*/
  8505. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8506. {
  8507. int item_index, item_amount;
  8508. if (pc_istrading(sd))
  8509. return;
  8510. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8511. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8512. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8513. return;
  8514. if (sd->state.storage_flag == 1)
  8515. storage_storageadd(sd, item_index, item_amount);
  8516. else
  8517. if (sd->state.storage_flag == 2)
  8518. storage_guild_storageadd(sd, item_index, item_amount);
  8519. }
  8520. /*==========================================
  8521. * カプラ倉庫から出す
  8522. *------------------------------------------*/
  8523. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8524. {
  8525. int item_index, item_amount;
  8526. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8527. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8528. if (sd->state.storage_flag == 1)
  8529. storage_storageget(sd, item_index, item_amount);
  8530. else
  8531. if(sd->state.storage_flag == 2)
  8532. storage_guild_storageget(sd, item_index, item_amount);
  8533. }
  8534. /*==========================================
  8535. * カプラ倉庫へカートから入れる
  8536. *------------------------------------------*/
  8537. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8538. {
  8539. if(sd->vender_id)
  8540. return;
  8541. if (!pc_iscarton(sd))
  8542. return;
  8543. if (sd->state.storage_flag == 1)
  8544. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8545. else
  8546. if (sd->state.storage_flag == 2)
  8547. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8548. }
  8549. /*==========================================
  8550. * カプラ倉庫から出す
  8551. *------------------------------------------*/
  8552. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8553. {
  8554. if (sd->vender_id)
  8555. return;
  8556. if (!pc_iscarton(sd))
  8557. return;
  8558. if (sd->state.storage_flag == 1)
  8559. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8560. else
  8561. if (sd->state.storage_flag == 2)
  8562. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8563. }
  8564. /*==========================================
  8565. * カプラ倉庫を閉じる
  8566. *------------------------------------------*/
  8567. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8568. {
  8569. if( sd->state.storage_flag == 1 )
  8570. storage_storageclose(sd);
  8571. else
  8572. if( sd->state.storage_flag == 2 )
  8573. storage_guild_storageclose(sd);
  8574. }
  8575. /*==========================================
  8576. * Kafra storage protection password system
  8577. *------------------------------------------*/
  8578. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8579. {
  8580. //TODO
  8581. }
  8582. /*==========================================
  8583. * Party creation request
  8584. * S 00f9 <party name>.24S
  8585. * S 01e8 <party name>.24S <item1>.B <item2>.B
  8586. *------------------------------------------*/
  8587. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8588. {
  8589. char* name = (char*)RFIFOP(fd,2);
  8590. name[NAME_LENGTH-1] = '\0';
  8591. if( map[sd->bl.m].flag.partylock )
  8592. {// Party locked.
  8593. clif_displaymessage(fd, msg_txt(227));
  8594. return;
  8595. }
  8596. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8597. {
  8598. clif_skill_fail(sd,1,0,4);
  8599. return;
  8600. }
  8601. party_create(sd,name,0,0);
  8602. }
  8603. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8604. {
  8605. char* name = (char*)RFIFOP(fd,2);
  8606. int item1 = RFIFOB(fd,26);
  8607. int item2 = RFIFOB(fd,27);
  8608. name[NAME_LENGTH-1] = '\0';
  8609. if( map[sd->bl.m].flag.partylock )
  8610. {// Party locked.
  8611. clif_displaymessage(fd, msg_txt(227));
  8612. return;
  8613. }
  8614. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8615. {
  8616. clif_skill_fail(sd,1,0,4);
  8617. return;
  8618. }
  8619. party_create(sd,name,item1,item2);
  8620. }
  8621. /*==========================================
  8622. * Party invitation request
  8623. * S 00fc <account ID>.L
  8624. * S 02c4 <char name>.24S
  8625. *------------------------------------------*/
  8626. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8627. {
  8628. struct map_session_data *t_sd;
  8629. if(map[sd->bl.m].flag.partylock)
  8630. {// Party locked.
  8631. clif_displaymessage(fd, msg_txt(227));
  8632. return;
  8633. }
  8634. t_sd = map_id2sd(RFIFOL(fd,2));
  8635. if(t_sd && t_sd->state.noask)
  8636. {// @noask [LuzZza]
  8637. clif_noask_sub(sd, t_sd, 1);
  8638. return;
  8639. }
  8640. party_invite(sd, t_sd);
  8641. }
  8642. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8643. {
  8644. struct map_session_data *t_sd;
  8645. char *name = (char*)RFIFOP(fd,2);
  8646. name[NAME_LENGTH-1] = '\0';
  8647. if(map[sd->bl.m].flag.partylock)
  8648. {// Party locked.
  8649. clif_displaymessage(fd, msg_txt(227));
  8650. return;
  8651. }
  8652. t_sd = map_nick2sd(name);
  8653. if(t_sd && t_sd->state.noask)
  8654. {// @noask [LuzZza]
  8655. clif_noask_sub(sd, t_sd, 1);
  8656. return;
  8657. }
  8658. party_invite(sd, t_sd);
  8659. }
  8660. /*==========================================
  8661. * Party invitation reply
  8662. * S 00ff <account ID>.L <flag>.L
  8663. * S 02c7 <account ID>.L <flag>.B
  8664. * flag: 0-reject, 1-accept
  8665. *------------------------------------------*/
  8666. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8667. {
  8668. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8669. }
  8670. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8671. {
  8672. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8673. }
  8674. /*==========================================
  8675. * パーティ脱退要求
  8676. *------------------------------------------*/
  8677. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8678. {
  8679. if(map[sd->bl.m].flag.partylock)
  8680. { //Guild locked.
  8681. clif_displaymessage(fd, msg_txt(227));
  8682. return;
  8683. }
  8684. party_leave(sd);
  8685. }
  8686. /*==========================================
  8687. * パーティ除名要求
  8688. *------------------------------------------*/
  8689. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8690. {
  8691. if(map[sd->bl.m].flag.partylock)
  8692. { //Guild locked.
  8693. clif_displaymessage(fd, msg_txt(227));
  8694. return;
  8695. }
  8696. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8697. }
  8698. /*==========================================
  8699. * パーティ設定変更要求
  8700. *------------------------------------------*/
  8701. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8702. {
  8703. struct party_data *p;
  8704. int i;
  8705. if( !sd->status.party_id )
  8706. return;
  8707. p = party_search(sd->status.party_id);
  8708. if( p == NULL )
  8709. return;
  8710. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8711. if( i == MAX_PARTY )
  8712. return; //Shouldn't happen
  8713. if( !p->party.member[i].leader )
  8714. return;
  8715. //The client no longer can change the item-field, therefore it always
  8716. //comes as zero. Here, resend the item data as it is.
  8717. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8718. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8719. }
  8720. /*==========================================
  8721. * Validates and processes party messages
  8722. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8723. *------------------------------------------*/
  8724. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8725. {
  8726. const char* text = (char*)RFIFOP(fd,4);
  8727. int textlen = RFIFOW(fd,2) - 4;
  8728. char *name, *message;
  8729. int namelen, messagelen;
  8730. // validate packet and retrieve name and message
  8731. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8732. return;
  8733. if( is_atcommand(fd, sd, message) )
  8734. return;
  8735. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8736. return;
  8737. if( battle_config.min_chat_delay )
  8738. { //[Skotlex]
  8739. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8740. return;
  8741. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8742. }
  8743. party_send_message(sd, text, textlen);
  8744. }
  8745. /*==========================================
  8746. * 露店閉鎖
  8747. *------------------------------------------*/
  8748. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8749. {
  8750. vending_closevending(sd);
  8751. }
  8752. /*==========================================
  8753. * 露店アイテムリスト要求
  8754. *------------------------------------------*/
  8755. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8756. {
  8757. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8758. if( sd->npc_id )
  8759. npc_event_dequeue(sd);
  8760. }
  8761. /*==========================================
  8762. * Shop item(s) purchase request
  8763. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8764. *------------------------------------------*/
  8765. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8766. {
  8767. int len = (int)RFIFOW(fd,2) - 8;
  8768. int id = (int)RFIFOL(fd,4);
  8769. const uint8* data = (uint8*)RFIFOP(fd,8);
  8770. vending_purchasereq(sd, id, data, len/4);
  8771. }
  8772. /*==========================================
  8773. * Confirm or cancel the shop preparation window
  8774. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8775. * flag: 0=cancel, 1=confirm
  8776. *------------------------------------------*/
  8777. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8778. {
  8779. short len = (short)RFIFOW(fd,2) - 85;
  8780. const char* message = (char*)RFIFOP(fd,4);
  8781. bool flag = (bool)RFIFOB(fd,84);
  8782. const uint8* data = (uint8*)RFIFOP(fd,85);
  8783. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8784. return;
  8785. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8786. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  8787. return;
  8788. }
  8789. if( message[0] == '\0' ) // invalid input
  8790. return;
  8791. vending_openvending(sd, message, flag, data, len/8);
  8792. }
  8793. /*==========================================
  8794. * Guild creation request
  8795. * S 0165 <account id>.L <guild name>.24S
  8796. *------------------------------------------*/
  8797. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8798. {
  8799. char* name = (char*)RFIFOP(fd,6);
  8800. name[NAME_LENGTH-1] = '\0';
  8801. if(map[sd->bl.m].flag.guildlock)
  8802. { //Guild locked.
  8803. clif_displaymessage(fd, msg_txt(228));
  8804. return;
  8805. }
  8806. guild_create(sd, name);
  8807. }
  8808. /*==========================================
  8809. * ギルドマスターかどうか確認
  8810. *------------------------------------------*/
  8811. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8812. {
  8813. clif_guild_masterormember(sd);
  8814. }
  8815. /*==========================================
  8816. * ギルド情報要求
  8817. *------------------------------------------*/
  8818. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8819. {
  8820. if (!sd->status.guild_id)
  8821. return;
  8822. switch(RFIFOL(fd,2)){
  8823. case 0: // ギルド基本情報、同盟敵対情報
  8824. clif_guild_basicinfo(sd);
  8825. clif_guild_allianceinfo(sd);
  8826. break;
  8827. case 1: // メンバーリスト、役職名リスト
  8828. clif_guild_positionnamelist(sd);
  8829. clif_guild_memberlist(sd);
  8830. break;
  8831. case 2: // 役職名リスト、役職情報リスト
  8832. clif_guild_positionnamelist(sd);
  8833. clif_guild_positioninfolist(sd);
  8834. break;
  8835. case 3: // スキルリスト
  8836. clif_guild_skillinfo(sd);
  8837. break;
  8838. case 4: // 追放リスト
  8839. clif_guild_expulsionlist(sd);
  8840. break;
  8841. default:
  8842. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8843. break;
  8844. }
  8845. }
  8846. /*==========================================
  8847. * ギルド役職変更
  8848. *------------------------------------------*/
  8849. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8850. {
  8851. int i;
  8852. if(!sd->state.gmaster_flag)
  8853. return;
  8854. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8855. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8856. }
  8857. }
  8858. /*==========================================
  8859. * ギルドメンバ役職変更
  8860. *------------------------------------------*/
  8861. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8862. {
  8863. int i;
  8864. if(!sd->state.gmaster_flag)
  8865. return;
  8866. for(i=4;i<RFIFOW(fd,2);i+=12){
  8867. guild_change_memberposition(sd->status.guild_id,
  8868. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8869. }
  8870. }
  8871. /*==========================================
  8872. * ギルドエンブレム要求
  8873. *------------------------------------------*/
  8874. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8875. {
  8876. struct guild* g = guild_search(RFIFOL(fd,2));
  8877. if(g!=NULL)
  8878. clif_guild_emblem(sd,g);
  8879. }
  8880. /*==========================================
  8881. * ギルドエンブレム変更
  8882. *------------------------------------------*/
  8883. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8884. {
  8885. if(!sd->state.gmaster_flag)
  8886. return;
  8887. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8888. }
  8889. /*==========================================
  8890. * Guild notice update request
  8891. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8892. *------------------------------------------*/
  8893. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8894. {
  8895. int guild_id = RFIFOL(fd,2);
  8896. char* msg1 = (char*)RFIFOP(fd,6);
  8897. char* msg2 = (char*)RFIFOP(fd,66);
  8898. if(!sd->state.gmaster_flag)
  8899. return;
  8900. // compensate for some client defects when using multilanguage mode
  8901. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8902. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8903. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8904. guild_change_notice(sd, guild_id, msg1, msg2);
  8905. }
  8906. /*==========================================
  8907. * ギルド勧誘
  8908. *------------------------------------------*/
  8909. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8910. {
  8911. struct map_session_data *t_sd;
  8912. if(map[sd->bl.m].flag.guildlock)
  8913. { //Guild locked.
  8914. clif_displaymessage(fd, msg_txt(228));
  8915. return;
  8916. }
  8917. t_sd = map_id2sd(RFIFOL(fd,2));
  8918. // @noask [LuzZza]
  8919. if(t_sd && t_sd->state.noask) {
  8920. clif_noask_sub(sd, t_sd, 2);
  8921. return;
  8922. }
  8923. guild_invite(sd,t_sd);
  8924. }
  8925. /*==========================================
  8926. * ギルド勧誘返信
  8927. *------------------------------------------*/
  8928. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8929. {
  8930. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8931. }
  8932. /*==========================================
  8933. * ギルド脱退
  8934. *------------------------------------------*/
  8935. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8936. {
  8937. if(map[sd->bl.m].flag.guildlock)
  8938. { //Guild locked.
  8939. clif_displaymessage(fd, msg_txt(228));
  8940. return;
  8941. }
  8942. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8943. }
  8944. /*==========================================
  8945. * Request to expel a member of a guild
  8946. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8947. *------------------------------------------*/
  8948. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8949. {
  8950. if(map[sd->bl.m].flag.guildlock)
  8951. { //Guild locked.
  8952. clif_displaymessage(fd, msg_txt(228));
  8953. return;
  8954. }
  8955. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8956. }
  8957. /*==========================================
  8958. * Validates and processes guild messages
  8959. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8960. *------------------------------------------*/
  8961. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8962. {
  8963. const char* text = (char*)RFIFOP(fd,4);
  8964. int textlen = RFIFOW(fd,2) - 4;
  8965. char *name, *message;
  8966. int namelen, messagelen;
  8967. // validate packet and retrieve name and message
  8968. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8969. return;
  8970. if( is_atcommand(fd, sd, message) )
  8971. return;
  8972. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8973. return;
  8974. if( battle_config.min_chat_delay )
  8975. { //[Skotlex]
  8976. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8977. return;
  8978. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8979. }
  8980. guild_send_message(sd, text, textlen);
  8981. }
  8982. /*==========================================
  8983. * ギルド同盟要求
  8984. *------------------------------------------*/
  8985. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8986. {
  8987. struct map_session_data *t_sd;
  8988. if(!sd->state.gmaster_flag)
  8989. return;
  8990. if(map[sd->bl.m].flag.guildlock)
  8991. { //Guild locked.
  8992. clif_displaymessage(fd, msg_txt(228));
  8993. return;
  8994. }
  8995. t_sd = map_id2sd(RFIFOL(fd,2));
  8996. // @noask [LuzZza]
  8997. if(t_sd && t_sd->state.noask) {
  8998. clif_noask_sub(sd, t_sd, 3);
  8999. return;
  9000. }
  9001. guild_reqalliance(sd,t_sd);
  9002. }
  9003. /*==========================================
  9004. * ギルド同盟要求返信
  9005. *------------------------------------------*/
  9006. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9007. {
  9008. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9009. }
  9010. /*==========================================
  9011. * ギルド関係解消
  9012. *------------------------------------------*/
  9013. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9014. {
  9015. if(!sd->state.gmaster_flag)
  9016. return;
  9017. if(map[sd->bl.m].flag.guildlock)
  9018. { //Guild locked.
  9019. clif_displaymessage(fd, msg_txt(228));
  9020. return;
  9021. }
  9022. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9023. }
  9024. /*==========================================
  9025. * ギルド敵対
  9026. *------------------------------------------*/
  9027. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9028. {
  9029. struct map_session_data *t_sd;
  9030. if(!sd->state.gmaster_flag)
  9031. return;
  9032. if(map[sd->bl.m].flag.guildlock)
  9033. { //Guild locked.
  9034. clif_displaymessage(fd, msg_txt(228));
  9035. return;
  9036. }
  9037. t_sd = map_id2sd(RFIFOL(fd,2));
  9038. // @noask [LuzZza]
  9039. if(t_sd && t_sd->state.noask) {
  9040. clif_noask_sub(sd, t_sd, 4);
  9041. return;
  9042. }
  9043. guild_opposition(sd,t_sd);
  9044. }
  9045. /*==========================================
  9046. * ギルド解散
  9047. *------------------------------------------*/
  9048. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9049. {
  9050. if(map[sd->bl.m].flag.guildlock)
  9051. { //Guild locked.
  9052. clif_displaymessage(fd, msg_txt(228));
  9053. return;
  9054. }
  9055. guild_break(sd,(char*)RFIFOP(fd,2));
  9056. }
  9057. // pet
  9058. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9059. {
  9060. pet_menu(sd,RFIFOB(fd,2));
  9061. }
  9062. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9063. {
  9064. pet_catch_process2(sd,RFIFOL(fd,2));
  9065. }
  9066. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9067. {
  9068. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9069. {
  9070. //Forged packet, disconnect them [Kevin]
  9071. clif_authfail_fd(fd, 0);
  9072. return;
  9073. }
  9074. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9075. sd->menuskill_val = sd->menuskill_id = 0;
  9076. }
  9077. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9078. {
  9079. if(sd->pd)
  9080. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9081. }
  9082. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9083. {
  9084. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9085. }
  9086. /*==========================================
  9087. * /kill <???>
  9088. * (or right click menu for GM "(name) force to quit")
  9089. * S 00cc <id>.L
  9090. *------------------------------------------*/
  9091. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9092. {
  9093. struct block_list *target;
  9094. int tid,lv;
  9095. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9096. return;
  9097. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  9098. return;
  9099. tid = RFIFOL(fd,2);
  9100. target = map_id2bl(tid);
  9101. if (!target) {
  9102. clif_GM_kickack(sd, 0);
  9103. return;
  9104. }
  9105. switch (target->type) {
  9106. case BL_PC:
  9107. {
  9108. struct map_session_data *tsd = (struct map_session_data *)target;
  9109. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9110. clif_GM_kickack(sd, 0);
  9111. return;
  9112. }
  9113. clif_GM_kick(sd, tsd);
  9114. if(log_config.gm && lv >= log_config.gm) {
  9115. char message[256];
  9116. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9117. log_atcommand(sd, message);
  9118. }
  9119. }
  9120. break;
  9121. case BL_MOB:
  9122. status_percent_damage(&sd->bl, target, 100, 0, true);
  9123. if(log_config.gm && lv >= log_config.gm) {
  9124. char message[256];
  9125. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9126. log_atcommand(sd, message);
  9127. }
  9128. break;
  9129. case BL_NPC:
  9130. {
  9131. struct npc_data* nd = (struct npc_data *)target;
  9132. lv = get_atcommand_level(atcommand_unloadnpc);
  9133. if( pc_isGM(sd) < lv )
  9134. return;
  9135. // copy-pasted from atcommand_unloadnpc
  9136. npc_unload_duplicates(nd);
  9137. npc_unload(nd);
  9138. npc_read_event_script();
  9139. if( log_config.gm && lv >= log_config.gm ) {
  9140. char message[256];
  9141. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9142. log_atcommand(sd, message);
  9143. }
  9144. }
  9145. break;
  9146. default:
  9147. clif_GM_kickack(sd, 0);
  9148. }
  9149. }
  9150. /*==========================================
  9151. * /killall
  9152. *------------------------------------------*/
  9153. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9154. {
  9155. is_atcommand(fd, sd, "@kickall");
  9156. }
  9157. /*==========================================
  9158. * /shift <name>
  9159. *------------------------------------------*/
  9160. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9161. {
  9162. char *player_name;
  9163. int lv;
  9164. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9165. return;
  9166. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9167. return;
  9168. player_name = (char*)RFIFOP(fd,2);
  9169. player_name[NAME_LENGTH-1] = '\0';
  9170. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9171. if( log_config.gm && lv >= log_config.gm ) {
  9172. char message[NAME_LENGTH+7];
  9173. sprintf(message, "/shift %s", player_name);
  9174. log_atcommand(sd, message);
  9175. }
  9176. }
  9177. /*==========================================
  9178. * /recall <name>
  9179. *------------------------------------------*/
  9180. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9181. {
  9182. char *player_name;
  9183. int lv;
  9184. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9185. return;
  9186. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9187. return;
  9188. player_name = (char*)RFIFOP(fd,2);
  9189. player_name[NAME_LENGTH-1] = '\0';
  9190. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9191. if( log_config.gm && lv >= log_config.gm ) {
  9192. char message[NAME_LENGTH+8];
  9193. sprintf(message, "/recall %s", player_name);
  9194. log_atcommand(sd, message);
  9195. }
  9196. }
  9197. /*==========================================
  9198. * /monster /item
  9199. *------------------------------------------*/
  9200. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9201. {
  9202. char *monster_item_name;
  9203. char message[NAME_LENGTH+10]; //For logging.
  9204. int level;
  9205. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9206. return;
  9207. monster_item_name = (char*)RFIFOP(fd,2);
  9208. monster_item_name[NAME_LENGTH-1] = '\0';
  9209. if( mobdb_searchname(monster_item_name) ) {
  9210. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9211. return;
  9212. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9213. if( log_config.gm && level >= log_config.gm )
  9214. { //Log action. [Skotlex]
  9215. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9216. log_atcommand(sd, message);
  9217. }
  9218. return;
  9219. }
  9220. if( itemdb_searchname(monster_item_name) == NULL )
  9221. return;
  9222. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9223. return;
  9224. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9225. if( log_config.gm && level >= log_config.gm )
  9226. { //Log action. [Skotlex]
  9227. sprintf(message, "@item %s", monster_item_name);
  9228. log_atcommand(sd, message);
  9229. }
  9230. }
  9231. /*==========================================
  9232. * /hide
  9233. *------------------------------------------*/
  9234. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9235. {
  9236. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9237. return;
  9238. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9239. return;
  9240. if( sd->sc.option & OPTION_INVISIBLE ) {
  9241. sd->sc.option &= ~OPTION_INVISIBLE;
  9242. if (sd->disguise)
  9243. status_set_viewdata(&sd->bl, sd->disguise);
  9244. else
  9245. status_set_viewdata(&sd->bl, sd->status.class_);
  9246. clif_displaymessage(fd, "Invisible: Off.");
  9247. } else {
  9248. sd->sc.option |= OPTION_INVISIBLE;
  9249. sd->vd.class_ = INVISIBLE_CLASS;
  9250. clif_displaymessage(fd, "Invisible: On.");
  9251. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9252. log_atcommand(sd, "/hide");
  9253. }
  9254. clif_changeoption(&sd->bl);
  9255. }
  9256. /*==========================================
  9257. * GM adjustment of a player's manner value (right-click GM menu)
  9258. * S 0149 <id>.L <type>.B <value>.W
  9259. * type: 0 - positive points
  9260. * 1 - negative points
  9261. * 2 - self mute (+10 minutes)
  9262. *------------------------------------------*/
  9263. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9264. {
  9265. int id, type, value, level;
  9266. struct map_session_data *dstsd;
  9267. id = RFIFOL(fd,2);
  9268. type = RFIFOB(fd,6);
  9269. value = RFIFOW(fd,7);
  9270. if( type == 0 )
  9271. value = 0 - value;
  9272. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9273. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9274. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9275. return;
  9276. dstsd = map_id2sd(id);
  9277. if( dstsd == NULL )
  9278. return;
  9279. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9280. {
  9281. clif_manner_message(sd, 0);
  9282. clif_manner_message(dstsd, 5);
  9283. if( dstsd->status.manner < value ) {
  9284. dstsd->status.manner -= value;
  9285. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9286. } else {
  9287. dstsd->status.manner = 0;
  9288. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9289. }
  9290. if( type != 2 )
  9291. clif_GM_silence(sd, dstsd, type);
  9292. }
  9293. }
  9294. /*==========================================
  9295. * GM adjustment of a player's manner value by -60 (using name)
  9296. * /rc <name>
  9297. * S 0212 <name>.24B
  9298. *------------------------------------------*/
  9299. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9300. {
  9301. char* name = (char*)RFIFOP(fd,2);
  9302. struct map_session_data* dstsd;
  9303. name[23] = '\0';
  9304. dstsd = map_nick2sd(name);
  9305. if( dstsd == NULL )
  9306. return;
  9307. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9308. {
  9309. clif_manner_message(sd, 0);
  9310. clif_manner_message(dstsd, 3);
  9311. dstsd->status.manner -= 60;
  9312. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9313. clif_GM_silence(sd, dstsd, 1);
  9314. }
  9315. }
  9316. /*==========================================
  9317. * GM requesting account name (for right-click gm menu)
  9318. * S 01df <id>.L
  9319. * R 01e0 <id>.L <name>.24B
  9320. *------------------------------------------*/
  9321. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9322. {
  9323. int tid;
  9324. tid = RFIFOL(fd,2);
  9325. //TODO: find out if this works for any player or only for authorized GMs
  9326. WFIFOHEAD(fd,packet_len(0x1e0));
  9327. WFIFOW(fd,0) = 0x1e0;
  9328. WFIFOL(fd,2) = tid;
  9329. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9330. WFIFOSET(fd, packet_len(0x1e0));
  9331. }
  9332. /*==========================================
  9333. * GM single cell type change request
  9334. * /changemaptype <x> <y> <type>
  9335. * S 0198 <x>.W <y>.W <gat>.W
  9336. *------------------------------------------*/
  9337. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9338. {
  9339. int x,y,type;
  9340. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9341. return;
  9342. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9343. return;
  9344. x = RFIFOW(fd,2);
  9345. y = RFIFOW(fd,4);
  9346. type = RFIFOW(fd,6);
  9347. map_setgatcell(sd->bl.m,x,y,type);
  9348. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9349. //FIXME: once players leave the map, the client 'forgets' this information.
  9350. }
  9351. /// S 00cf <nick>.24B <type>.B
  9352. /// type: 0 (/ex nick) deny speech from nick
  9353. /// 1 (/in nick) allow speech from nick
  9354. ///
  9355. /// R 00d1 <type>.B <result>.B
  9356. /// type: 0: deny, 1: allow
  9357. /// result: 0: success, 1: fail 2: list full
  9358. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9359. {
  9360. char output[512];
  9361. char* nick;
  9362. uint8 type;
  9363. int i;
  9364. nick = (char*)RFIFOP(fd,2); // speed up
  9365. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9366. type = RFIFOB(fd,26);
  9367. WFIFOHEAD(fd,packet_len(0xd1));
  9368. WFIFOW(fd,0) = 0x0d1;
  9369. WFIFOB(fd,2) = type;
  9370. if( type == 0 )
  9371. { // Add name to ignore list (block)
  9372. // Bot-check...
  9373. if (strcmp(wisp_server_name, nick) == 0)
  9374. { // to find possible bot users who automaticaly ignore people
  9375. 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);
  9376. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9377. WFIFOB(fd,3) = 1; // fail
  9378. WFIFOSET(fd, packet_len(0x0d1));
  9379. return;
  9380. }
  9381. // try to find a free spot, while checking for duplicates at the same time
  9382. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9383. if( i == MAX_IGNORE_LIST )
  9384. {// no space for new entry
  9385. WFIFOB(fd,3) = 2; // fail
  9386. WFIFOSET(fd, packet_len(0x0d1));
  9387. return;
  9388. }
  9389. if( sd->ignore[i].name[0] != '\0' )
  9390. {// name already exists
  9391. WFIFOB(fd,3) = 0; // Aegis reports success.
  9392. WFIFOSET(fd, packet_len(0x0d1));
  9393. return;
  9394. }
  9395. //Insert in position i
  9396. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9397. WFIFOB(fd,3) = 0; // success
  9398. WFIFOSET(fd, packet_len(0x0d1));
  9399. }
  9400. else
  9401. { // Remove name from ignore list (unblock)
  9402. // find entry
  9403. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9404. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9405. { //Not found
  9406. WFIFOB(fd,3) = 1; // fail
  9407. WFIFOSET(fd, packet_len(0x0d1));
  9408. return;
  9409. }
  9410. // move everything one place down to overwrite removed entry
  9411. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9412. // wipe last entry
  9413. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9414. WFIFOB(fd,3) = 0; // success
  9415. WFIFOSET(fd, packet_len(0x0d1));
  9416. }
  9417. return;
  9418. }
  9419. /// S 00d0 <type>.B
  9420. /// type: 0 (/exall) deny all speech
  9421. /// 1 (/inall) allow all speech
  9422. ///
  9423. /// R 00d2 <type>.B <fail>.B
  9424. /// type: 0: deny, 1: allow
  9425. /// fail: 0: success, 1: fail
  9426. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9427. {
  9428. WFIFOHEAD(fd,packet_len(0xd2));
  9429. WFIFOW(fd,0) = 0x0d2;
  9430. WFIFOB(fd,2) = RFIFOB(fd,2);
  9431. if( RFIFOB(fd,2) == 0 )
  9432. {// Deny all
  9433. if( sd->state.ignoreAll ) {
  9434. WFIFOB(fd,3) = 1; // fail
  9435. } else {
  9436. sd->state.ignoreAll = 1;
  9437. WFIFOB(fd,3) = 0; // success
  9438. }
  9439. }
  9440. else
  9441. {//Unblock everyone
  9442. if( sd->state.ignoreAll ) {
  9443. sd->state.ignoreAll = 0;
  9444. WFIFOB(fd,3) = 0; // success
  9445. } else {
  9446. if (sd->ignore[0].name[0] != '\0')
  9447. { //Wipe the ignore list.
  9448. memset(sd->ignore, 0, sizeof(sd->ignore));
  9449. WFIFOB(fd,3) = 0; // success
  9450. } else {
  9451. WFIFOB(fd,3) = 1; // fail
  9452. }
  9453. }
  9454. }
  9455. WFIFOSET(fd, packet_len(0x0d2));
  9456. return;
  9457. }
  9458. /*==========================================
  9459. * Wis拒否リスト
  9460. *------------------------------------------*/
  9461. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9462. {
  9463. int i;
  9464. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9465. WFIFOW(fd,0) = 0xd4;
  9466. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9467. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9468. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9469. WFIFOSET(fd, WFIFOW(fd,2));
  9470. return;
  9471. }
  9472. /*==========================================
  9473. * スパノビの/doridoriによるSPR2倍
  9474. *------------------------------------------*/
  9475. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9476. {
  9477. if (sd->state.doridori) return;
  9478. switch (sd->class_&MAPID_UPPERMASK)
  9479. {
  9480. case MAPID_SOUL_LINKER:
  9481. case MAPID_STAR_GLADIATOR:
  9482. case MAPID_TAEKWON:
  9483. if (!sd->state.rest)
  9484. break;
  9485. case MAPID_SUPER_NOVICE:
  9486. sd->state.doridori=1;
  9487. break;
  9488. }
  9489. return;
  9490. }
  9491. /*==========================================
  9492. * スパノビの爆裂波動
  9493. *------------------------------------------*/
  9494. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9495. {
  9496. if(sd){
  9497. int nextbaseexp=pc_nextbaseexp(sd);
  9498. if (battle_config.etc_log){
  9499. if(nextbaseexp != 0)
  9500. 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));
  9501. else
  9502. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9503. }
  9504. 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){
  9505. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9506. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  9507. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9508. }
  9509. }
  9510. return;
  9511. }
  9512. // random notes:
  9513. // 0x214: monster/player info ?
  9514. /*==========================================
  9515. * Friends List
  9516. *------------------------------------------*/
  9517. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9518. { //Toggles a single friend online/offline [Skotlex]
  9519. int i, fd = sd->fd;
  9520. //Seek friend.
  9521. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9522. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9523. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9524. return; //Not found
  9525. WFIFOHEAD(fd,packet_len(0x206));
  9526. WFIFOW(fd, 0) = 0x206;
  9527. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9528. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9529. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9530. WFIFOSET(fd, packet_len(0x206));
  9531. }
  9532. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9533. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9534. {
  9535. int account_id, char_id, online;
  9536. account_id = va_arg(ap, int);
  9537. char_id = va_arg(ap, int);
  9538. online = va_arg(ap, int);
  9539. clif_friendslist_toggle(sd, account_id, char_id, online);
  9540. return 0;
  9541. }
  9542. //For sending the whole friends list.
  9543. void clif_friendslist_send(struct map_session_data *sd)
  9544. {
  9545. int i = 0, n, fd = sd->fd;
  9546. // Send friends list
  9547. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9548. WFIFOW(fd, 0) = 0x201;
  9549. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9550. {
  9551. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9552. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9553. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9554. }
  9555. if (i) {
  9556. WFIFOW(fd,2) = 4 + 32 * i;
  9557. WFIFOSET(fd, WFIFOW(fd,2));
  9558. }
  9559. for (n = 0; n < i; n++)
  9560. { //Sending the online players
  9561. if (map_charid2sd(sd->status.friends[n].char_id))
  9562. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9563. }
  9564. }
  9565. /// Reply for add friend request: (success => type 0)
  9566. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9567. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9568. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9569. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9570. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9571. {
  9572. int fd;
  9573. nullpo_retv(sd);
  9574. fd = sd->fd;
  9575. WFIFOHEAD(fd,packet_len(0x209));
  9576. WFIFOW(fd,0) = 0x209;
  9577. WFIFOW(fd,2) = type;
  9578. if (f_sd)
  9579. {
  9580. WFIFOL(fd,4) = f_sd->status.account_id;
  9581. WFIFOL(fd,8) = f_sd->status.char_id;
  9582. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9583. }
  9584. WFIFOSET(fd, packet_len(0x209));
  9585. }
  9586. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9587. {
  9588. struct map_session_data *f_sd;
  9589. int i, f_fd;
  9590. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9591. // Friend doesn't exist (no player with this name)
  9592. if (f_sd == NULL) {
  9593. clif_displaymessage(fd, msg_txt(3));
  9594. return;
  9595. }
  9596. // @noask [LuzZza]
  9597. if(f_sd->state.noask) {
  9598. clif_noask_sub(sd, f_sd, 5);
  9599. return;
  9600. }
  9601. // Friend already exists
  9602. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9603. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9604. clif_displaymessage(fd, "Friend already exists.");
  9605. return;
  9606. }
  9607. }
  9608. if (i == MAX_FRIENDS) {
  9609. //No space, list full.
  9610. clif_friendslist_reqack(sd, f_sd, 2);
  9611. return;
  9612. }
  9613. f_fd = f_sd->fd;
  9614. WFIFOHEAD(f_fd,packet_len(0x207));
  9615. WFIFOW(f_fd,0) = 0x207;
  9616. WFIFOL(f_fd,2) = sd->status.account_id;
  9617. WFIFOL(f_fd,6) = sd->status.char_id;
  9618. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9619. WFIFOSET(f_fd, packet_len(0x207));
  9620. return;
  9621. }
  9622. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9623. {
  9624. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9625. struct map_session_data *f_sd;
  9626. int char_id, account_id;
  9627. char reply;
  9628. account_id = RFIFOL(fd,2);
  9629. char_id = RFIFOL(fd,6);
  9630. reply = RFIFOB(fd,10);
  9631. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9632. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9633. if (f_sd == NULL)
  9634. return;
  9635. if (reply == 0)
  9636. clif_friendslist_reqack(f_sd, sd, 1);
  9637. else {
  9638. int i;
  9639. // Find an empty slot
  9640. for (i = 0; i < MAX_FRIENDS; i++)
  9641. if (f_sd->status.friends[i].char_id == 0)
  9642. break;
  9643. if (i == MAX_FRIENDS) {
  9644. clif_friendslist_reqack(f_sd, sd, 2);
  9645. return;
  9646. }
  9647. f_sd->status.friends[i].account_id = sd->status.account_id;
  9648. f_sd->status.friends[i].char_id = sd->status.char_id;
  9649. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9650. clif_friendslist_reqack(f_sd, sd, 0);
  9651. if (battle_config.friend_auto_add) {
  9652. // Also add f_sd to sd's friendlist.
  9653. for (i = 0; i < MAX_FRIENDS; i++) {
  9654. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9655. return; //No need to add anything.
  9656. if (sd->status.friends[i].char_id == 0)
  9657. break;
  9658. }
  9659. if (i == MAX_FRIENDS) {
  9660. clif_friendslist_reqack(sd, f_sd, 2);
  9661. return;
  9662. }
  9663. sd->status.friends[i].account_id = f_sd->status.account_id;
  9664. sd->status.friends[i].char_id = f_sd->status.char_id;
  9665. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9666. clif_friendslist_reqack(sd, f_sd, 0);
  9667. }
  9668. }
  9669. return;
  9670. }
  9671. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9672. {
  9673. // 0x203 </o> <ID to be removed W 4B>
  9674. int account_id, char_id;
  9675. int i, j;
  9676. account_id = RFIFOL(fd,2);
  9677. char_id = RFIFOL(fd,6);
  9678. // Search friend
  9679. for (i = 0; i < MAX_FRIENDS &&
  9680. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9681. if (i == MAX_FRIENDS) {
  9682. clif_displaymessage(fd, "Name not found in list.");
  9683. return;
  9684. }
  9685. // move all chars down
  9686. for(j = i + 1; j < MAX_FRIENDS; j++)
  9687. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9688. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9689. clif_displaymessage(fd, "Friend removed");
  9690. WFIFOHEAD(fd,packet_len(0x20a));
  9691. WFIFOW(fd,0) = 0x20a;
  9692. WFIFOL(fd,2) = account_id;
  9693. WFIFOL(fd,6) = char_id;
  9694. WFIFOSET(fd, packet_len(0x20a));
  9695. // clif_friendslist_send(sd); //This is not needed anymore.
  9696. return;
  9697. }
  9698. /*==========================================
  9699. * /pvpinfo
  9700. *------------------------------------------*/
  9701. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9702. {
  9703. WFIFOHEAD(fd,packet_len(0x210));
  9704. WFIFOW(fd,0) = 0x210;
  9705. //WFIFOL(fd,2) = 0; // not sure what for yet
  9706. //WFIFOL(fd,6) = 0;
  9707. WFIFOL(fd,10) = sd->pvp_won; // times won
  9708. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9709. WFIFOL(fd,18) = sd->pvp_point;
  9710. WFIFOSET(fd, packet_len(0x210));
  9711. return;
  9712. }
  9713. /*==========================================
  9714. * /blacksmith
  9715. *------------------------------------------*/
  9716. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9717. {
  9718. int i;
  9719. const char* name;
  9720. WFIFOHEAD(fd,packet_len(0x219));
  9721. WFIFOW(fd,0) = 0x219;
  9722. //Packet size limits this list to 10 elements. [Skotlex]
  9723. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9724. if (smith_fame_list[i].id > 0) {
  9725. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9726. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9727. {
  9728. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9729. } else
  9730. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9731. } else
  9732. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9733. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9734. }
  9735. for(;i < 10; i++) { //In case the MAX is less than 10.
  9736. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9737. WFIFOL(fd, 242 + i * 4) = 0;
  9738. }
  9739. WFIFOSET(fd, packet_len(0x219));
  9740. }
  9741. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9742. {
  9743. int fd = sd->fd;
  9744. WFIFOHEAD(fd,packet_len(0x21b));
  9745. WFIFOW(fd,0) = 0x21b;
  9746. WFIFOL(fd,2) = points;
  9747. WFIFOL(fd,6) = sd->status.fame;
  9748. WFIFOSET(fd, packet_len(0x21b));
  9749. return 0;
  9750. }
  9751. /*==========================================
  9752. * /alchemist
  9753. *------------------------------------------*/
  9754. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9755. {
  9756. int i;
  9757. const char* name;
  9758. WFIFOHEAD(fd,packet_len(0x21a));
  9759. WFIFOW(fd,0) = 0x21a;
  9760. //Packet size limits this list to 10 elements. [Skotlex]
  9761. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9762. if (chemist_fame_list[i].id > 0) {
  9763. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9764. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9765. {
  9766. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9767. } else
  9768. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9769. } else
  9770. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9771. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9772. }
  9773. for(;i < 10; i++) { //In case the MAX is less than 10.
  9774. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9775. WFIFOL(fd, 242 + i * 4) = 0;
  9776. }
  9777. WFIFOSET(fd, packet_len(0x21a));
  9778. }
  9779. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9780. {
  9781. int fd = sd->fd;
  9782. WFIFOHEAD(fd,packet_len(0x21c));
  9783. WFIFOW(fd,0) = 0x21c;
  9784. WFIFOL(fd,2) = points;
  9785. WFIFOL(fd,6) = sd->status.fame;
  9786. WFIFOSET(fd, packet_len(0x21c));
  9787. return 0;
  9788. }
  9789. /*==========================================
  9790. * /taekwon
  9791. *------------------------------------------*/
  9792. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9793. {
  9794. int i;
  9795. const char* name;
  9796. WFIFOHEAD(fd,packet_len(0x226));
  9797. WFIFOW(fd,0) = 0x226;
  9798. //Packet size limits this list to 10 elements. [Skotlex]
  9799. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9800. if (taekwon_fame_list[i].id > 0) {
  9801. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9802. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9803. {
  9804. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9805. } else
  9806. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9807. } else
  9808. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9809. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9810. }
  9811. for(;i < 10; i++) { //In case the MAX is less than 10.
  9812. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9813. WFIFOL(fd, 242 + i * 4) = 0;
  9814. }
  9815. WFIFOSET(fd, packet_len(0x226));
  9816. }
  9817. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9818. {
  9819. int fd = sd->fd;
  9820. WFIFOHEAD(fd,packet_len(0x224));
  9821. WFIFOW(fd,0) = 0x224;
  9822. WFIFOL(fd,2) = points;
  9823. WFIFOL(fd,6) = sd->status.fame;
  9824. WFIFOSET(fd, packet_len(0x224));
  9825. return 0;
  9826. }
  9827. /*==========================================
  9828. * PK Ranking table?
  9829. *------------------------------------------*/
  9830. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9831. {
  9832. int i;
  9833. WFIFOHEAD(fd,packet_len(0x238));
  9834. WFIFOW(fd,0) = 0x238;
  9835. for(i=0;i<10;i++){
  9836. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9837. WFIFOL(fd,i*4+242) = 0;
  9838. }
  9839. WFIFOSET(fd, packet_len(0x238));
  9840. return;
  9841. }
  9842. /*==========================================
  9843. * SG Feel save OK [Komurka]
  9844. *------------------------------------------*/
  9845. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9846. {
  9847. int i;
  9848. if (sd->menuskill_id != SG_FEEL)
  9849. return;
  9850. i = sd->menuskill_val-1;
  9851. if (i<0 || i > 2) return; //Bug?
  9852. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9853. sd->feel_map[i].m = sd->bl.m;
  9854. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9855. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9856. // clif_misceffect2(&sd->bl, 0x1b0);
  9857. // clif_misceffect2(&sd->bl, 0x21f);
  9858. clif_feel_info(sd, i, 0);
  9859. sd->menuskill_val = sd->menuskill_id = 0;
  9860. }
  9861. /*==========================================
  9862. * Question about Star Glaldiator save map [Komurka]
  9863. *------------------------------------------*/
  9864. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9865. {
  9866. WFIFOHEAD(fd,packet_len(0x253));
  9867. WFIFOW(fd,0)=0x253;
  9868. WFIFOSET(fd, packet_len(0x253));
  9869. sd->menuskill_id = SG_FEEL;
  9870. sd->menuskill_val = skilllv;
  9871. }
  9872. /*==========================================
  9873. * Homunculus packets
  9874. *------------------------------------------*/
  9875. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9876. {
  9877. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9878. }
  9879. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9880. {
  9881. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9882. struct block_list *bl = NULL;
  9883. struct unit_data *ud = NULL;
  9884. if( sd->md && sd->md->bl.id == id )
  9885. bl = &sd->md->bl;
  9886. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9887. bl = &sd->hd->bl; // Moving Homunculus
  9888. else return;
  9889. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  9890. ud = unit_bl2ud(bl);
  9891. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  9892. }
  9893. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  9894. {
  9895. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9896. struct block_list *bl = NULL;
  9897. short x, y, cmd;
  9898. cmd = RFIFOW(fd,0);
  9899. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9900. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9901. if( sd->md && sd->md->bl.id == id )
  9902. bl = &sd->md->bl; // Moving Mercenary
  9903. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9904. bl = &sd->hd->bl; // Moving Homunculus
  9905. else return;
  9906. unit_walktoxy(bl, x, y, 4);
  9907. }
  9908. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9909. {
  9910. struct block_list *bl = NULL;
  9911. int id = RFIFOL(fd,2),
  9912. target_id = RFIFOL(fd,6),
  9913. action_type = RFIFOB(fd,10);
  9914. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9915. bl = &sd->hd->bl;
  9916. else if( sd->md && sd->md->bl.id == id )
  9917. bl = &sd->md->bl;
  9918. else return;
  9919. unit_stop_walking(bl, 1);
  9920. unit_stop_attack(bl);
  9921. unit_attack(bl, target_id, action_type != 0);
  9922. }
  9923. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9924. { //[orn]
  9925. int cmd;
  9926. cmd = RFIFOW(fd,0);
  9927. if(!merc_is_hom_active(sd->hd))
  9928. return;
  9929. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9930. }
  9931. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9932. {
  9933. int item_position = pc_search_inventory(sd, 7621);
  9934. if (item_position < 0)
  9935. return;
  9936. if (!status_revive(&sd->bl, 100, 100))
  9937. return;
  9938. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9939. pc_delitem(sd, item_position, 1, 0);
  9940. }
  9941. /// /check <string>
  9942. /// S 0213 <string>.24B
  9943. void clif_parse_Check(int fd, struct map_session_data *sd)
  9944. {
  9945. // no info
  9946. }
  9947. #ifndef TXT_ONLY
  9948. /*==========================================
  9949. * MAIL SYSTEM
  9950. * By Zephyrus
  9951. *==========================================*/
  9952. /*------------------------------------------
  9953. * Reply to Set Attachment operation
  9954. * 0 : Successfully attached item to mail
  9955. * 1 : Fail to set the attachment
  9956. *------------------------------------------*/
  9957. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9958. {
  9959. WFIFOHEAD(fd,packet_len(0x255));
  9960. WFIFOW(fd,0) = 0x255;
  9961. WFIFOW(fd,2) = index;
  9962. WFIFOB(fd,4) = flag;
  9963. WFIFOSET(fd,packet_len(0x255));
  9964. }
  9965. /*------------------------------------------
  9966. * Reply to Get Attachment operation
  9967. * 0 : Successfully added attachment to Inventory
  9968. * 1 : Fail to set the item to inventory
  9969. * 2 : Weight problems
  9970. *------------------------------------------*/
  9971. void clif_Mail_getattachment(int fd, uint8 flag)
  9972. {
  9973. WFIFOHEAD(fd,packet_len(0x245));
  9974. WFIFOW(fd,0) = 0x245;
  9975. WFIFOB(fd,2) = flag;
  9976. WFIFOSET(fd,packet_len(0x245));
  9977. }
  9978. /*------------------------------------------
  9979. * Send Mail ack
  9980. * 0 : Message Send Ok
  9981. * 1 : Recipient does not exist
  9982. *------------------------------------------*/
  9983. void clif_Mail_send(int fd, bool fail)
  9984. {
  9985. WFIFOHEAD(fd,packet_len(0x249));
  9986. WFIFOW(fd,0) = 0x249;
  9987. WFIFOB(fd,2) = fail;
  9988. WFIFOSET(fd,packet_len(0x249));
  9989. }
  9990. /*------------------------------------------
  9991. * Delete Mail ack
  9992. * 0 : Delete ok
  9993. * 1 : Delete failed
  9994. *------------------------------------------*/
  9995. void clif_Mail_delete(int fd, int mail_id, short fail)
  9996. {
  9997. WFIFOHEAD(fd, packet_len(0x257));
  9998. WFIFOW(fd,0) = 0x257;
  9999. WFIFOL(fd,2) = mail_id;
  10000. WFIFOW(fd,6) = fail;
  10001. WFIFOSET(fd, packet_len(0x257));
  10002. }
  10003. /*------------------------------------------
  10004. * Return Mail ack
  10005. * 0 : Mail returned to the sender
  10006. * 1 : The mail does not exist
  10007. *------------------------------------------*/
  10008. void clif_Mail_return(int fd, int mail_id, short fail)
  10009. {
  10010. WFIFOHEAD(fd,packet_len(0x274));
  10011. WFIFOW(fd,0) = 0x274;
  10012. WFIFOL(fd,2) = mail_id;
  10013. WFIFOW(fd,6) = fail;
  10014. WFIFOSET(fd,packet_len(0x274));
  10015. }
  10016. /*------------------------------------------
  10017. * You have New Mail
  10018. *------------------------------------------*/
  10019. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10020. {
  10021. WFIFOHEAD(fd,packet_len(0x24a));
  10022. WFIFOW(fd,0) = 0x24a;
  10023. WFIFOL(fd,2) = mail_id;
  10024. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10025. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10026. WFIFOSET(fd,packet_len(0x24a));
  10027. }
  10028. /*------------------------------------------
  10029. * Handles Mail Window on Client
  10030. * flag : 0 open | 1 close
  10031. *------------------------------------------*/
  10032. void clif_Mail_window(int fd, int flag)
  10033. {
  10034. WFIFOHEAD(fd,packet_len(0x260));
  10035. WFIFOW(fd,0) = 0x260;
  10036. WFIFOL(fd,2) = flag;
  10037. WFIFOSET(fd,packet_len(0x260));
  10038. }
  10039. /*------------------------------------------
  10040. * Send Inbox Data to Client
  10041. *------------------------------------------*/
  10042. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10043. {
  10044. int fd = sd->fd;
  10045. struct mail_data *md = &sd->mail.inbox;
  10046. struct mail_message *msg;
  10047. int len, i, j;
  10048. len = 8 + (73 * md->amount);
  10049. WFIFOHEAD(fd,len);
  10050. WFIFOW(fd,0) = 0x240;
  10051. WFIFOW(fd,2) = len;
  10052. WFIFOL(fd,4) = md->amount;
  10053. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10054. {
  10055. msg = &md->msg[i];
  10056. if (msg->id < 1)
  10057. continue;
  10058. WFIFOL(fd,8+73*j) = msg->id;
  10059. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10060. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10061. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10062. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10063. j++;
  10064. }
  10065. WFIFOSET(fd,len);
  10066. if( md->full )
  10067. {
  10068. char output[100];
  10069. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10070. clif_disp_onlyself(sd, output, strlen(output));
  10071. }
  10072. }
  10073. /*------------------------------------------
  10074. * Client Request Inbox List
  10075. *------------------------------------------*/
  10076. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10077. {
  10078. struct mail_data* md = &sd->mail.inbox;
  10079. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10080. intif_Mail_requestinbox(sd->status.char_id, 1);
  10081. else
  10082. clif_Mail_refreshinbox(sd);
  10083. mail_removeitem(sd, 0);
  10084. mail_removezeny(sd, 0);
  10085. }
  10086. /*------------------------------------------
  10087. * Read Message
  10088. *------------------------------------------*/
  10089. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10090. {
  10091. int i, fd = sd->fd;
  10092. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10093. if( i == MAIL_MAX_INBOX )
  10094. {
  10095. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10096. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10097. return;
  10098. }
  10099. else
  10100. {
  10101. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10102. struct item *item = &msg->item;
  10103. struct item_data *data;
  10104. int msg_len = strlen(msg->body), len;
  10105. if( msg_len == 0 ) {
  10106. strcpy(msg->body, "(no message)");
  10107. msg_len = strlen(msg->body);
  10108. }
  10109. len = 101 + msg_len;
  10110. WFIFOHEAD(fd,len);
  10111. WFIFOW(fd,0) = 0x242;
  10112. WFIFOW(fd,2) = len;
  10113. WFIFOL(fd,4) = msg->id;
  10114. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10115. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10116. WFIFOL(fd,72) = 0;
  10117. WFIFOL(fd,76) = msg->zeny;
  10118. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  10119. {
  10120. WFIFOL(fd,80) = item->amount;
  10121. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10122. WFIFOW(fd,86) = data->type;
  10123. WFIFOB(fd,88) = item->identify;
  10124. WFIFOB(fd,89) = item->attribute;
  10125. WFIFOB(fd,90) = item->refine;
  10126. WFIFOW(fd,91) = item->card[0];
  10127. WFIFOW(fd,93) = item->card[1];
  10128. WFIFOW(fd,95) = item->card[2];
  10129. WFIFOW(fd,97) = item->card[3];
  10130. }
  10131. else // no item, set all to zero
  10132. memset(WFIFOP(fd,80), 0x00, 19);
  10133. WFIFOB(fd,99) = (unsigned char)msg_len;
  10134. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10135. WFIFOSET(fd,len);
  10136. if (msg->status == MAIL_UNREAD) {
  10137. msg->status = MAIL_READ;
  10138. intif_Mail_read(mail_id);
  10139. clif_parse_Mail_refreshinbox(fd, sd);
  10140. }
  10141. }
  10142. }
  10143. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10144. {
  10145. if( mail_invalid_operation(sd) )
  10146. return;
  10147. clif_Mail_read(sd, RFIFOL(fd,2));
  10148. }
  10149. /*------------------------------------------
  10150. * Get Attachment from Message
  10151. *------------------------------------------*/
  10152. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10153. {
  10154. int i, mail_id = RFIFOL(fd,2);
  10155. bool fail = false;
  10156. if( mail_invalid_operation(sd) )
  10157. return;
  10158. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10159. if( i == MAIL_MAX_INBOX )
  10160. return;
  10161. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10162. return;
  10163. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10164. {
  10165. struct item_data *data;
  10166. unsigned int weight;
  10167. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10168. return;
  10169. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10170. {
  10171. case ADDITEM_NEW:
  10172. fail = ( pc_inventoryblank(sd) == 0 );
  10173. break;
  10174. case ADDITEM_OVERAMOUNT:
  10175. fail = true;
  10176. }
  10177. if( fail )
  10178. {
  10179. clif_Mail_getattachment(fd, 1);
  10180. return;
  10181. }
  10182. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10183. if( weight > sd->max_weight - sd->weight )
  10184. {
  10185. clif_Mail_getattachment(fd, 2);
  10186. return;
  10187. }
  10188. }
  10189. sd->mail.inbox.msg[i].zeny = 0;
  10190. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10191. clif_Mail_read(sd, mail_id);
  10192. intif_Mail_getattach(sd->status.char_id, mail_id);
  10193. }
  10194. /*------------------------------------------
  10195. * Delete Message
  10196. *------------------------------------------*/
  10197. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10198. {
  10199. int i, mail_id = RFIFOL(fd,2);
  10200. if( mail_invalid_operation(sd) )
  10201. return;
  10202. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10203. if (i < MAIL_MAX_INBOX)
  10204. {
  10205. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10206. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10207. {// can't delete mail without removing attachment first
  10208. clif_Mail_delete(sd->fd, mail_id, 1);
  10209. return;
  10210. }
  10211. intif_Mail_delete(sd->status.char_id, mail_id);
  10212. }
  10213. }
  10214. /*------------------------------------------
  10215. * Return Mail Message
  10216. *------------------------------------------*/
  10217. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10218. {
  10219. int i, mail_id = RFIFOL(fd,2);
  10220. if( mail_invalid_operation(sd) )
  10221. return;
  10222. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10223. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10224. intif_Mail_return(sd->status.char_id, mail_id);
  10225. else
  10226. clif_Mail_return(sd->fd, mail_id, 1);
  10227. }
  10228. /*------------------------------------------
  10229. * Set Attachment
  10230. *------------------------------------------*/
  10231. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10232. {
  10233. int idx = RFIFOW(fd,2);
  10234. int amount = RFIFOL(fd,4);
  10235. unsigned char flag;
  10236. if (idx < 0 || amount < 0)
  10237. return;
  10238. flag = mail_setitem(sd, idx, amount);
  10239. clif_Mail_setattachment(fd,idx,flag);
  10240. }
  10241. /*------------------------------------------
  10242. * Mail Window Operation
  10243. * 0 : Switch to 'new mail' window, or Close mailbox
  10244. * 1 : ???
  10245. * 2 : ???
  10246. *------------------------------------------*/
  10247. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10248. {
  10249. int flag = RFIFOW(fd,2);
  10250. if (flag == 0 || flag == 1)
  10251. mail_removeitem(sd, 0);
  10252. if (flag == 0 || flag == 2)
  10253. mail_removezeny(sd, 0);
  10254. }
  10255. /*------------------------------------------
  10256. * Send Mail
  10257. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10258. *------------------------------------------*/
  10259. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10260. {
  10261. struct mail_message msg;
  10262. int body_len;
  10263. if( sd->state.trading )
  10264. return;
  10265. if( RFIFOW(fd,2) < 69 ) {
  10266. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10267. return;
  10268. }
  10269. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10270. {
  10271. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10272. clif_Mail_send(fd, true); // fail
  10273. return;
  10274. }
  10275. body_len = RFIFOB(fd,68);
  10276. if (body_len > MAIL_BODY_LENGTH)
  10277. body_len = MAIL_BODY_LENGTH;
  10278. if( !mail_setattachment(sd, &msg) )
  10279. { // Invalid Append condition
  10280. clif_Mail_send(sd->fd, true); // fail
  10281. mail_removeitem(sd,0);
  10282. mail_removezeny(sd,0);
  10283. return;
  10284. }
  10285. msg.id = 0; // id will be assigned by charserver
  10286. msg.send_id = sd->status.char_id;
  10287. msg.dest_id = 0; // will attempt to resolve name
  10288. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10289. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10290. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10291. if (body_len)
  10292. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10293. else
  10294. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10295. msg.timestamp = time(NULL);
  10296. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10297. mail_deliveryfail(sd, &msg);
  10298. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10299. }
  10300. /*==========================================
  10301. * AUCTION SYSTEM
  10302. * By Zephyrus
  10303. *==========================================*/
  10304. void clif_Auction_openwindow(struct map_session_data *sd)
  10305. {
  10306. int fd = sd->fd;
  10307. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10308. return;
  10309. WFIFOHEAD(fd,12);
  10310. WFIFOW(fd,0) = 0x25f;
  10311. WFIFOL(fd,2) = 0;
  10312. WFIFOB(fd,6) = 0xb6;
  10313. WFIFOB(fd,7) = 0x00;
  10314. WFIFOB(fd,8) = 0xa6;
  10315. WFIFOB(fd,9) = 0xde;
  10316. WFIFOW(fd,10) = 0;
  10317. WFIFOSET(fd,12);
  10318. }
  10319. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  10320. {
  10321. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10322. struct auction_data auction;
  10323. struct item_data *item;
  10324. int k;
  10325. WFIFOHEAD(fd,20);
  10326. WFIFOW(fd,0) = 0x252;
  10327. WFIFOW(fd,2) = 12 + (count * 83);
  10328. WFIFOL(fd,4) = pages;
  10329. WFIFOL(fd,8) = count;
  10330. for( i = 0; i < count; i++ )
  10331. {
  10332. memcpy(&auction, RBUFP(buf,i * len), len);
  10333. k = 12 + (i * 83);
  10334. WFIFOL(fd,k) = auction.auction_id;
  10335. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10336. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10337. WFIFOW(fd,28+k) = item->view_id;
  10338. else
  10339. WFIFOW(fd,28+k) = auction.item.nameid;
  10340. WFIFOW(fd,30+k) = auction.type;
  10341. WFIFOW(fd,32+k) = 0; // ??
  10342. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10343. WFIFOB(fd,36+k) = auction.item.identify;
  10344. WFIFOB(fd,37+k) = auction.item.attribute;
  10345. WFIFOB(fd,38+k) = auction.item.refine;
  10346. WFIFOW(fd,39+k) = auction.item.card[0];
  10347. WFIFOW(fd,41+k) = auction.item.card[1];
  10348. WFIFOW(fd,43+k) = auction.item.card[2];
  10349. WFIFOW(fd,45+k) = auction.item.card[3];
  10350. WFIFOL(fd,47+k) = auction.price;
  10351. WFIFOL(fd,51+k) = auction.buynow;
  10352. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10353. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  10354. }
  10355. WFIFOSET(fd, 12 + (count * 83));
  10356. }
  10357. static void clif_Auction_setitem(int fd, int index, bool fail)
  10358. {
  10359. WFIFOHEAD(fd,packet_len(0x256));
  10360. WFIFOW(fd,0) = 0x256;
  10361. WFIFOW(fd,2) = index;
  10362. WFIFOB(fd,4) = fail;
  10363. WFIFOSET(fd,packet_len(0x256));
  10364. }
  10365. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10366. {
  10367. if( sd->auction.amount > 0 )
  10368. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10369. sd->auction.amount = 0;
  10370. }
  10371. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10372. {
  10373. int idx = RFIFOW(fd,2) - 2;
  10374. int amount = RFIFOL(fd,4); // Allways 1
  10375. struct item_data *item;
  10376. if( sd->auction.amount > 0 )
  10377. sd->auction.amount = 0;
  10378. if( idx < 0 || idx >= MAX_INVENTORY )
  10379. {
  10380. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10381. return;
  10382. }
  10383. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10384. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10385. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10386. return;
  10387. }
  10388. if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
  10389. { // Consumible or pets are not allowed
  10390. clif_Auction_setitem(sd->fd, idx, true);
  10391. return;
  10392. }
  10393. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify || sd->status.inventory[idx].expire_time )
  10394. { // Quest Item or something else
  10395. clif_Auction_setitem(sd->fd, idx, true);
  10396. return;
  10397. }
  10398. sd->auction.index = idx;
  10399. sd->auction.amount = amount;
  10400. clif_Auction_setitem(fd, idx + 2, false);
  10401. }
  10402. // 0 = You have failed to bid into the auction
  10403. // 1 = You have successfully bid in the auction
  10404. // 2 = The auction has been canceled
  10405. // 3 = An auction with at least one bidder cannot be canceled
  10406. // 4 = You cannot register more than 5 items in an auction at a time
  10407. // 5 = You do not have enough Zeny to pay the Auction Fee
  10408. // 6 = You have won the auction
  10409. // 7 = You have failed to win the auction
  10410. // 8 = You do not have enough Zeny
  10411. // 9 = You cannot place more than 5 bids at a time
  10412. void clif_Auction_message(int fd, unsigned char flag)
  10413. {
  10414. WFIFOHEAD(fd,3);
  10415. WFIFOW(fd,0) = 0x250;
  10416. WFIFOB(fd,2) = flag;
  10417. WFIFOSET(fd,3);
  10418. }
  10419. // 0 = You have ended the auction
  10420. // 1 = You cannot end the auction
  10421. // 2 = Bid number is incorrect
  10422. void clif_Auction_close(int fd, unsigned char flag)
  10423. {
  10424. WFIFOHEAD(fd,6);
  10425. WFIFOW(fd,0) = 0x25d;
  10426. WFIFOL(fd,2) = flag;
  10427. WFIFOSET(fd,6);
  10428. }
  10429. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10430. {
  10431. struct auction_data auction;
  10432. struct item_data *item;
  10433. auction.price = RFIFOL(fd,2);
  10434. auction.buynow = RFIFOL(fd,6);
  10435. auction.hours = RFIFOW(fd,10);
  10436. // Invalid Situations...
  10437. if( sd->auction.amount < 1 )
  10438. {
  10439. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10440. return;
  10441. }
  10442. if( auction.price >= auction.buynow )
  10443. {
  10444. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10445. return;
  10446. }
  10447. if( auction.hours < 1 || auction.hours > 48 )
  10448. {
  10449. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10450. return;
  10451. }
  10452. // Auction checks...
  10453. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10454. {
  10455. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10456. return;
  10457. }
  10458. if( auction.buynow > battle_config.auction_maximumprice )
  10459. { // Zeny Limits
  10460. auction.buynow = battle_config.auction_maximumprice;
  10461. if( auction.price >= auction.buynow )
  10462. auction.price = auction.buynow - 1;
  10463. }
  10464. auction.auction_id = 0;
  10465. auction.seller_id = sd->status.char_id;
  10466. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10467. auction.buyer_id = 0;
  10468. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10469. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10470. {
  10471. clif_Auction_message(fd, 2); // The auction has been canceled
  10472. return;
  10473. }
  10474. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10475. { // Just in case
  10476. clif_Auction_message(fd, 2); // The auction has been canceled
  10477. return;
  10478. }
  10479. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10480. auction.type = item->type;
  10481. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10482. auction.item.amount = 1;
  10483. auction.timestamp = 0;
  10484. if( !intif_Auction_register(&auction) )
  10485. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10486. else
  10487. {
  10488. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10489. sd->auction.amount = 0;
  10490. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10491. }
  10492. }
  10493. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10494. {
  10495. unsigned int auction_id = RFIFOL(fd,2);
  10496. intif_Auction_cancel(sd->status.char_id, auction_id);
  10497. }
  10498. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10499. {
  10500. unsigned int auction_id = RFIFOL(fd,2);
  10501. intif_Auction_close(sd->status.char_id, auction_id);
  10502. }
  10503. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10504. {
  10505. unsigned int auction_id = RFIFOL(fd,2);
  10506. int bid = RFIFOL(fd,6);
  10507. if( bid <= 0 )
  10508. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10509. else if( bid > sd->status.zeny )
  10510. clif_Auction_message(fd, 8); // You do not have enough zeny
  10511. else
  10512. {
  10513. pc_payzeny(sd, bid);
  10514. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10515. }
  10516. }
  10517. /*------------------------------------------
  10518. * Auction Search
  10519. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10520. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10521. *------------------------------------------*/
  10522. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10523. {
  10524. char search_text[NAME_LENGTH];
  10525. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10526. int price = RFIFOL(fd,4);
  10527. clif_parse_Auction_cancelreg(fd, sd);
  10528. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10529. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10530. }
  10531. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10532. {
  10533. short type = RFIFOW(fd,2) + 6;
  10534. clif_parse_Auction_cancelreg(fd, sd);
  10535. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10536. }
  10537. #endif
  10538. /*==========================================
  10539. * CASH/POINT SHOP
  10540. *==========================================*/
  10541. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10542. {
  10543. int fd,i;
  10544. nullpo_retv(sd);
  10545. nullpo_retv(nd);
  10546. fd = sd->fd;
  10547. sd->npc_shopid = nd->bl.id;
  10548. WFIFOHEAD(fd, 200 * 11 + 12);
  10549. WFIFOW(fd,0) = 0x287;
  10550. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10551. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10552. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10553. for( i = 0; i < nd->u.shop.count; i++ )
  10554. {
  10555. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10556. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10557. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10558. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10559. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10560. }
  10561. WFIFOSET(fd,WFIFOW(fd,2));
  10562. }
  10563. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10564. {
  10565. int fail = 0, amount, points;
  10566. short nameid;
  10567. struct npc_data *nd;
  10568. nullpo_retv(sd);
  10569. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10570. nameid = RFIFOW(fd,2);
  10571. amount = RFIFOW(fd,4);
  10572. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10573. if( sd->state.trading || !sd->npc_shopid )
  10574. fail = 1;
  10575. else
  10576. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10577. WFIFOHEAD(fd,12);
  10578. WFIFOW(fd,0) = 0x289;
  10579. WFIFOL(fd,2) = sd->cashPoints;
  10580. WFIFOL(fd,6) = sd->kafraPoints;
  10581. WFIFOW(fd,10) = fail;
  10582. WFIFOSET(fd,12);
  10583. }
  10584. /*==========================================
  10585. * Adoption System
  10586. *==========================================*/
  10587. // 0 : "You cannot adopt more than 1 child."
  10588. // 1 : "You must be at least character level 70 in order to adopt someone."
  10589. // 2 : "You cannot adopt a married person."
  10590. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10591. {
  10592. int fd = sd->fd;
  10593. WFIFOHEAD(fd,6);
  10594. WFIFOW(fd,0) = 0x0216;
  10595. WFIFOL(fd,2) = type;
  10596. WFIFOSET(fd,6);
  10597. }
  10598. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10599. {
  10600. int fd = sd->fd;
  10601. WFIFOHEAD(fd,34);
  10602. WFIFOW(fd,0) = 0x01f6;
  10603. WFIFOL(fd,2) = src->status.account_id;
  10604. WFIFOL(fd,6) = p_id;
  10605. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10606. WFIFOSET(fd,34);
  10607. }
  10608. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10609. {
  10610. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10611. if( pc_can_Adopt(sd, p_sd, tsd) )
  10612. {
  10613. tsd->adopt_invite = sd->status.account_id;
  10614. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10615. }
  10616. }
  10617. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10618. {
  10619. int p1_id = RFIFOL(fd,2);
  10620. int p2_id = RFIFOL(fd,6);
  10621. int result = RFIFOL(fd,10);
  10622. struct map_session_data* p1_sd = map_id2sd(p1_id);
  10623. struct map_session_data* p2_sd = map_id2sd(p2_id);
  10624. int pid = sd->adopt_invite;
  10625. sd->adopt_invite = 0;
  10626. if( p1_sd == NULL || p2_sd == NULL )
  10627. return; // Both players need to be online
  10628. if( pid != p1_sd->status.account_id )
  10629. return; // Incorrect values
  10630. if( result == 0 )
  10631. return; // Rejected
  10632. pc_adoption(p1_sd, p2_sd, sd);
  10633. }
  10634. /*==========================================
  10635. * Convex Mirror
  10636. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  10637. *==========================================*/
  10638. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  10639. {
  10640. WFIFOHEAD(fd,70);
  10641. memset(WFIFOP(fd,0),0,70);
  10642. WFIFOW(fd,0) = 0x0293;
  10643. if( md != NULL )
  10644. {
  10645. if( md->bl.prev != NULL )
  10646. { // Boss on This Map
  10647. if( flag )
  10648. {
  10649. WFIFOB(fd,2) = 1;
  10650. WFIFOL(fd,3) = md->bl.x;
  10651. WFIFOL(fd,7) = md->bl.y;
  10652. }
  10653. else
  10654. WFIFOB(fd,2) = 2; // First Time
  10655. }
  10656. else
  10657. { // Boss is Dead
  10658. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  10659. unsigned int seconds;
  10660. int hours, minutes;
  10661. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000;
  10662. hours = seconds / (60 * 60);
  10663. seconds = seconds - (60 * 60 * hours);
  10664. minutes = seconds / 60;
  10665. WFIFOB(fd,2) = 3;
  10666. WFIFOW(fd,11) = hours; // Hours
  10667. WFIFOW(fd,13) = minutes; // Minutes
  10668. }
  10669. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  10670. }
  10671. WFIFOSET(fd,70);
  10672. }
  10673. /*==========================================
  10674. * Requesting equip of a player
  10675. *------------------------------------------*/
  10676. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10677. {
  10678. int charid = RFIFOL(fd, 2);
  10679. struct map_session_data* tsd = map_id2sd(charid);
  10680. if (!tsd)
  10681. return;
  10682. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  10683. clif_viewequip_ack(sd, tsd);
  10684. else
  10685. clif_viewequip_fail(sd);
  10686. }
  10687. /*==========================================
  10688. * Equip window (un)tick
  10689. * S 02d8 <zero?>.L <flag>.L
  10690. *------------------------------------------*/
  10691. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10692. {
  10693. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10694. sd->status.show_equip = flag;
  10695. clif_equiptickack(sd, flag);
  10696. }
  10697. /*==========================================
  10698. * Questlog System [Kevin]
  10699. * 02B5 <packet_len>.W <ignored>.L { }.10B* <-- UNKOWN PACKET
  10700. * 02B6 <quest_id>.L <state>.B
  10701. *------------------------------------------*/
  10702. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  10703. {
  10704. }
  10705. //Send simple list of quests upon login
  10706. //* 02B1 <packet_len>.W <ignored>.L { <quest_id>.L <state>.B }.5B*
  10707. void clif_send_questlog(struct map_session_data * sd)
  10708. {
  10709. int fd = sd->fd;
  10710. int i;
  10711. WFIFOHEAD(fd,sd->num_quests*5+8);
  10712. WFIFOW(fd, 0) = 0x02B1;
  10713. WFIFOW(fd, 2) = sd->num_quests*5+8;
  10714. for(i=0; i<MAX_QUEST; i++)
  10715. {
  10716. if(!sd->quest_log[i].quest_id)
  10717. continue;
  10718. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  10719. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  10720. }
  10721. WFIFOSET(fd, WFIFOW(fd, 2));
  10722. }
  10723. //Send objective info on login
  10724. //* 02B2 <packet_len>.W <ignored>.L { <quest_id>.L <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  10725. void clif_send_questlog_info(struct map_session_data * sd)
  10726. {
  10727. int fd = sd->fd;
  10728. int i, j;
  10729. WFIFOHEAD(fd,sd->num_quests*104+8);
  10730. WFIFOW(fd, 0) = 0x02B2;
  10731. WFIFOW(fd, 2) = sd->num_quests*104+8;
  10732. for(i=0; i<MAX_QUEST; i++)
  10733. {
  10734. if(!sd->quest_log[i].quest_id)
  10735. continue;
  10736. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  10737. // I have no idea what the time field does [Kevin]
  10738. WFIFOL(fd, i*104+16) = 0;
  10739. WFIFOW(fd, i*104+20) = sd->quest_log[i].num_objectives;
  10740. for(j=0; j<sd->quest_log[i].num_objectives; j++)
  10741. {
  10742. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].objectives[j].count;
  10743. memcpy(WFIFOP(fd, i*104+28+j*30), sd->quest_log[i].objectives[j].name, NAME_LENGTH);
  10744. }
  10745. }
  10746. WFIFOSET(fd, WFIFOW(fd, 2));
  10747. }
  10748. //Send info when objective info needs an update
  10749. //* 02B3 <quest_id>.L <state>.B <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3]
  10750. void clif_send_quest_info(struct map_session_data * sd, struct quest * qd)
  10751. {
  10752. int fd = sd->fd;
  10753. int i;
  10754. WFIFOHEAD(fd,qd->num_objectives*30+17);
  10755. WFIFOW(fd, 0) = 0x02B3;
  10756. WFIFOL(fd, 2) = qd->quest_id;
  10757. WFIFOB(fd, 6) = qd->state;
  10758. //Same time value thing
  10759. WFIFOW(fd, 11) = 0;
  10760. WFIFOW(fd, 15) = qd->num_objectives;
  10761. for(i=0; i<qd->num_objectives; i++)
  10762. {
  10763. WFIFOW(fd, i*30+21) = qd->objectives[i].count;
  10764. memcpy(WFIFOP(fd, i*30+23), qd->objectives[i].name, NAME_LENGTH);
  10765. }
  10766. WFIFOSET(fd, qd->num_objectives*30+17);
  10767. }
  10768. //Send delete msg
  10769. //* 02B4 <quest_id>.L
  10770. void clif_send_quest_delete(struct map_session_data * sd, int quest_id)
  10771. {
  10772. int fd = sd->fd;
  10773. WFIFOHEAD(fd, 6);
  10774. WFIFOW(fd, 0) = 0x02B4;
  10775. WFIFOL(fd, 2) = quest_id;
  10776. WFIFOSET(fd, 6);
  10777. }
  10778. //Change active state of the quest
  10779. //* 02B7 <quest_id>.L <state_to>.B
  10780. void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active)
  10781. {
  10782. int fd = sd->fd;
  10783. WFIFOHEAD(fd, 7);
  10784. WFIFOW(fd, 0) = 0x02B7;
  10785. WFIFOL(fd, 2) = quest_id;
  10786. WFIFOB(fd, 6) = active?1:0;
  10787. WFIFOSET(fd, 7);
  10788. }
  10789. /*==========================================
  10790. * Mercenary System
  10791. *==========================================*/
  10792. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  10793. {
  10794. struct mercenary_data *md;
  10795. struct status_data *status;
  10796. int fd;
  10797. if( sd == NULL || (md = sd->md) == NULL )
  10798. return;
  10799. fd = sd->fd;
  10800. status = &md->battle_status;
  10801. WFIFOHEAD(fd,8);
  10802. WFIFOW(fd,0) = 0x02a2;
  10803. WFIFOW(fd,2) = type;
  10804. switch( type )
  10805. {
  10806. case SP_ATK1:
  10807. {
  10808. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10809. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  10810. }
  10811. break;
  10812. case SP_MATK1:
  10813. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  10814. break;
  10815. case SP_HIT:
  10816. WFIFOL(fd,4) = status->hit;
  10817. break;
  10818. case SP_CRITICAL:
  10819. WFIFOL(fd,4) = status->cri/10;
  10820. break;
  10821. case SP_DEF1:
  10822. WFIFOL(fd,4) = status->def;
  10823. break;
  10824. case SP_MDEF1:
  10825. WFIFOL(fd,4) = status->mdef;
  10826. break;
  10827. case SP_MERCFLEE:
  10828. WFIFOL(fd,4) = status->flee;
  10829. break;
  10830. case SP_ASPD:
  10831. WFIFOL(fd,4) = status->amotion;
  10832. break;
  10833. case SP_HP:
  10834. WFIFOL(fd,4) = status->hp;
  10835. break;
  10836. case SP_MAXHP:
  10837. WFIFOL(fd,4) = status->max_hp;
  10838. break;
  10839. case SP_SP:
  10840. WFIFOL(fd,4) = status->sp;
  10841. break;
  10842. case SP_MAXSP:
  10843. WFIFOL(fd,4) = status->max_sp;
  10844. break;
  10845. case SP_MERCKILLS:
  10846. WFIFOL(fd,4) = md->mercenary.kill_count;
  10847. break;
  10848. case SP_MERCFAITH:
  10849. WFIFOL(fd,4) = mercenary_get_faith(md);
  10850. break;
  10851. }
  10852. WFIFOSET(fd,8);
  10853. }
  10854. void clif_mercenary_info(struct map_session_data *sd)
  10855. {
  10856. int fd;
  10857. struct mercenary_data *md;
  10858. struct status_data *status;
  10859. int atk;
  10860. if( sd == NULL || (md = sd->md) == NULL )
  10861. return;
  10862. fd = sd->fd;
  10863. status = &md->battle_status;
  10864. WFIFOHEAD(fd,80);
  10865. WFIFOW(fd,0) = 0x029b;
  10866. WFIFOL(fd,2) = md->bl.id;
  10867. // Mercenary shows ATK as a random value between ATK ~ ATK2
  10868. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10869. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  10870. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  10871. WFIFOW(fd,10) = status->hit;
  10872. WFIFOW(fd,12) = status->cri/10;
  10873. WFIFOW(fd,14) = status->def;
  10874. WFIFOW(fd,16) = status->mdef;
  10875. WFIFOW(fd,18) = status->flee;
  10876. WFIFOW(fd,20) = status->amotion;
  10877. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  10878. WFIFOW(fd,46) = md->db->lv;
  10879. WFIFOL(fd,48) = status->hp;
  10880. WFIFOL(fd,52) = status->max_hp;
  10881. WFIFOL(fd,56) = status->sp;
  10882. WFIFOL(fd,60) = status->max_sp;
  10883. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  10884. WFIFOW(fd,68) = mercenary_get_faith(md);
  10885. WFIFOL(fd,70) = mercenary_get_calls(md);
  10886. WFIFOL(fd,74) = md->mercenary.kill_count;
  10887. WFIFOW(fd,78) = md->battle_status.rhw.range;
  10888. WFIFOSET(fd,80);
  10889. }
  10890. void clif_mercenary_skillblock(struct map_session_data *sd)
  10891. {
  10892. struct mercenary_data *md;
  10893. int fd, i, len = 4, id, j;
  10894. if( sd == NULL || (md = sd->md) == NULL )
  10895. return;
  10896. fd = sd->fd;
  10897. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  10898. WFIFOW(fd,0) = 0x029d;
  10899. for( i = 0; i < MAX_MERCSKILL; i++ )
  10900. {
  10901. if( (id = md->db->skill[i].id) == 0 )
  10902. continue;
  10903. j = id - MC_SKILLBASE;
  10904. WFIFOW(fd,len) = id;
  10905. WFIFOW(fd,len+2) = skill_get_inf(id);
  10906. WFIFOW(fd,len+4) = 0;
  10907. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  10908. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  10909. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  10910. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  10911. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  10912. len += 37;
  10913. }
  10914. WFIFOW(fd,2) = len;
  10915. WFIFOSET(fd,len);
  10916. }
  10917. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  10918. {
  10919. int option = RFIFOB(fd,2);
  10920. if( sd->md == NULL )
  10921. return;
  10922. if( option == 2 ) merc_delete(sd->md, 2);
  10923. }
  10924. /*------------------------------------------
  10925. * Mercenary Message
  10926. * 0 = Mercenary soldier's duty hour is over.
  10927. * 1 = Your mercenary soldier has been killed.
  10928. * 2 = Your mercenary soldier has been fired.
  10929. * 3 = Your mercenary soldier has ran away.
  10930. *------------------------------------------*/
  10931. void clif_mercenary_message(int fd, int message)
  10932. {
  10933. WFIFOHEAD(fd,4);
  10934. WFIFOW(fd,0) = 0x0291;
  10935. WFIFOW(fd,2) = 1266 + message;
  10936. WFIFOSET(fd,4);
  10937. }
  10938. /*------------------------------------------
  10939. * Rental System Messages
  10940. *------------------------------------------*/
  10941. void clif_rental_time(int fd, int nameid, int seconds)
  10942. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  10943. WFIFOHEAD(fd,8);
  10944. WFIFOW(fd,0) = 0x0298;
  10945. WFIFOW(fd,2) = nameid;
  10946. WFIFOL(fd,4) = seconds;
  10947. WFIFOSET(fd,8);
  10948. }
  10949. void clif_rental_expired(int fd, int nameid)
  10950. { // '<ItemName>' item has been deleted from the Inventory
  10951. WFIFOHEAD(fd,6);
  10952. WFIFOW(fd,0) = 0x0299;
  10953. WFIFOW(fd,2) = 0;
  10954. WFIFOW(fd,4) = nameid;
  10955. WFIFOSET(fd,6);
  10956. }
  10957. /*------------------------------------------
  10958. * Book Reading
  10959. *------------------------------------------*/
  10960. void clif_readbook(int fd, int book_id, int page)
  10961. {
  10962. WFIFOHEAD(fd,10);
  10963. WFIFOW(fd,0) = 0x0294;
  10964. WFIFOL(fd,2) = book_id;
  10965. WFIFOL(fd,6) = page;
  10966. WFIFOSET(fd,10);
  10967. }
  10968. /*==========================================
  10969. * パケットデバッグ
  10970. *------------------------------------------*/
  10971. void clif_parse_debug(int fd,struct map_session_data *sd)
  10972. {
  10973. int i, cmd, len;
  10974. cmd = RFIFOW(fd,0);
  10975. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10976. ShowDebug("packet debug 0x%4X\n",cmd);
  10977. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10978. for(i=0;i<len;i++){
  10979. if((i&15)==0)
  10980. ShowMessage("\n%04X ",i);
  10981. ShowMessage("%02X ",RFIFOB(fd,i));
  10982. }
  10983. ShowMessage("\n");
  10984. }
  10985. /*==========================================
  10986. * Main client packet processing function
  10987. *------------------------------------------*/
  10988. int clif_parse(int fd)
  10989. {
  10990. int cmd, packet_ver, packet_len, err;
  10991. TBL_PC* sd;
  10992. int pnum;
  10993. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10994. // Note: "click masters" can do 80+ clicks in 10 seconds
  10995. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10996. { // begin main client packet processing loop
  10997. sd = (TBL_PC *)session[fd]->session_data;
  10998. if (session[fd]->flag.eof) {
  10999. if (sd) {
  11000. if (sd->state.autotrade) {
  11001. //Disassociate character from the socket connection.
  11002. session[fd]->session_data = NULL;
  11003. sd->fd = 0;
  11004. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11005. } else
  11006. if (sd->state.active) {
  11007. // Player logout display [Valaris]
  11008. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11009. clif_quitsave(fd, sd);
  11010. } else {
  11011. //Unusual logout (during log on/off/map-changer procedure)
  11012. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  11013. map_quit(sd);
  11014. }
  11015. } else {
  11016. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  11017. }
  11018. do_close(fd);
  11019. return 0;
  11020. }
  11021. if (RFIFOREST(fd) < 2)
  11022. return 0;
  11023. cmd = RFIFOW(fd,0);
  11024. // identify client's packet version
  11025. if (sd) {
  11026. packet_ver = sd->packet_ver;
  11027. } else {
  11028. // check authentification packet to know packet version
  11029. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  11030. if( err )
  11031. {// failed to identify packet version
  11032. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  11033. err == 1 ? "" :
  11034. err == 2 ? ", possibly for having an invalid account_id" :
  11035. err == 3 ? ", possibly for having an invalid char_id." :
  11036. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  11037. err == 4 ? ", possibly for having an invalid login_id1." :
  11038. err == 5 ? ", possibly for having an invalid client_tick." :
  11039. */
  11040. err == 6 ? ", possibly for having an invalid sex." :
  11041. ". ERROR invalid error code"));
  11042. WFIFOHEAD(fd,packet_len(0x6a));
  11043. WFIFOW(fd,0) = 0x6a;
  11044. WFIFOB(fd,2) = 3; // Rejected from Server
  11045. WFIFOSET(fd,packet_len(0x6a));
  11046. RFIFOSKIP(fd, RFIFOREST(fd));
  11047. set_eof(fd);
  11048. return 0;
  11049. }
  11050. }
  11051. // filter out invalid / unsupported packets
  11052. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  11053. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  11054. set_eof(fd);
  11055. return 0;
  11056. }
  11057. // determine real packet length
  11058. packet_len = packet_db[packet_ver][cmd].len;
  11059. if (packet_len == -1) { // variable-length packet
  11060. if (RFIFOREST(fd) < 4)
  11061. return 0;
  11062. packet_len = RFIFOW(fd,2);
  11063. if (packet_len < 4 || packet_len > 32768) {
  11064. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  11065. set_eof(fd);
  11066. return 0;
  11067. }
  11068. }
  11069. if ((int)RFIFOREST(fd) < packet_len)
  11070. return 0; // not enough data received to form the packet
  11071. if (packet_db[packet_ver][cmd].func) {
  11072. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  11073. ; //Only valid packet when player is not on a map is the finish-loading packet.
  11074. else
  11075. if ((sd && sd->state.active)
  11076. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  11077. || packet_db[packet_ver][cmd].func == clif_parse_debug
  11078. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  11079. packet_db[packet_ver][cmd].func(fd, sd);
  11080. }
  11081. #if DUMP_UNKNOWN_PACKET
  11082. else if (battle_config.error_log)
  11083. {
  11084. int i;
  11085. FILE *fp;
  11086. char packet_txt[256] = "save/packet.txt";
  11087. time_t now;
  11088. dump = 1;
  11089. if ((fp = fopen(packet_txt, "a")) == NULL) {
  11090. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  11091. return 1;
  11092. } else {
  11093. time(&now);
  11094. if (sd && sd->state.active) {
  11095. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  11096. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  11097. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11098. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  11099. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11100. for(i = 0; i < packet_len; i++) {
  11101. if ((i & 15) == 0)
  11102. fprintf(fp, "\n\t%04X ", i);
  11103. fprintf(fp, "%02X ", RFIFOB(fd,i));
  11104. }
  11105. fprintf(fp, "\n\n");
  11106. fclose(fp);
  11107. }
  11108. }
  11109. #endif
  11110. /* TODO: use utils.c :: dump()
  11111. if (dump) {
  11112. int i;
  11113. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  11114. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11115. for(i = 0; i < packet_len; i++) {
  11116. if ((i & 15) == 0)
  11117. ShowMessage("\n%04X ",i);
  11118. ShowMessage("%02X ", RFIFOB(fd,i));
  11119. }
  11120. ShowMessage("\n");
  11121. if (sd && sd->state.active) {
  11122. if (sd->status.name != NULL)
  11123. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  11124. sd->status.account_id, sd->status.char_id, sd->status.name);
  11125. else
  11126. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11127. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11128. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11129. }*/
  11130. RFIFOSKIP(fd, packet_len);
  11131. }; // main loop end
  11132. return 0;
  11133. }
  11134. /*==========================================
  11135. * パケットデータベース読み込み
  11136. *------------------------------------------*/
  11137. static int packetdb_readdb(void)
  11138. {
  11139. FILE *fp;
  11140. char line[1024];
  11141. int ln=0;
  11142. int cmd,i,j,packet_ver;
  11143. int max_cmd=-1;
  11144. int skip_ver = 0;
  11145. int warned = 0;
  11146. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  11147. int packet_len_table[MAX_PACKET_DB] = {
  11148. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11152. //#0x0040
  11153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11155. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  11156. #if PACKETVER < 2
  11157. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  11158. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  11159. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  11160. #else // change in 0x78 and 0x7c
  11161. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  11162. #endif
  11163. //#0x0080
  11164. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  11165. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  11166. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  11167. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  11168. //#0x00C0
  11169. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  11170. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  11171. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  11172. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  11173. //#0x0100
  11174. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  11175. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  11176. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  11177. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  11178. //#0x0140
  11179. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  11180. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  11181. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  11182. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  11183. //#0x0180
  11184. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  11185. #if PACKETVER < 1
  11186. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11187. #else // 196 comodo以降 状態表示アイコン用
  11188. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11189. #endif
  11190. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  11191. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  11192. //#0x01C0, Set 0x1d5=-1
  11193. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  11194. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  11195. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  11196. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  11197. //#0x0200
  11198. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  11199. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  11200. #if PACKETVER < 20071106
  11201. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  11202. #else // 0x22c changed
  11203. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  11204. #endif
  11205. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  11206. //#0x0240
  11207. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  11208. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  11209. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11210. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11211. //#0x0280
  11212. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  11213. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11215. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  11216. //#0x02C0
  11217. 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11218. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  11219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11221. };
  11222. struct {
  11223. void (*func)(int, struct map_session_data *);
  11224. char *name;
  11225. } clif_parse_func[]={
  11226. {clif_parse_WantToConnection,"wanttoconnection"},
  11227. {clif_parse_LoadEndAck,"loadendack"},
  11228. {clif_parse_TickSend,"ticksend"},
  11229. {clif_parse_WalkToXY,"walktoxy"},
  11230. {clif_parse_QuitGame,"quitgame"},
  11231. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  11232. {clif_parse_GlobalMessage,"globalmessage"},
  11233. {clif_parse_MapMove,"mapmove"},
  11234. {clif_parse_ChangeDir,"changedir"},
  11235. {clif_parse_Emotion,"emotion"},
  11236. {clif_parse_HowManyConnections,"howmanyconnections"},
  11237. {clif_parse_ActionRequest,"actionrequest"},
  11238. {clif_parse_Restart,"restart"},
  11239. {clif_parse_WisMessage,"wis"},
  11240. {clif_parse_GMmessage,"gmmessage"},
  11241. {clif_parse_TakeItem,"takeitem"},
  11242. {clif_parse_DropItem,"dropitem"},
  11243. {clif_parse_UseItem,"useitem"},
  11244. {clif_parse_EquipItem,"equipitem"},
  11245. {clif_parse_UnequipItem,"unequipitem"},
  11246. {clif_parse_NpcClicked,"npcclicked"},
  11247. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  11248. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  11249. {clif_parse_NpcSellListSend,"npcselllistsend"},
  11250. {clif_parse_CreateChatRoom,"createchatroom"},
  11251. {clif_parse_ChatAddMember,"chataddmember"},
  11252. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  11253. {clif_parse_ChangeChatOwner,"changechatowner"},
  11254. {clif_parse_KickFromChat,"kickfromchat"},
  11255. {clif_parse_ChatLeave,"chatleave"},
  11256. {clif_parse_TradeRequest,"traderequest"},
  11257. {clif_parse_TradeAck,"tradeack"},
  11258. {clif_parse_TradeAddItem,"tradeadditem"},
  11259. {clif_parse_TradeOk,"tradeok"},
  11260. {clif_parse_TradeCancel,"tradecancel"},
  11261. {clif_parse_TradeCommit,"tradecommit"},
  11262. {clif_parse_StopAttack,"stopattack"},
  11263. {clif_parse_PutItemToCart,"putitemtocart"},
  11264. {clif_parse_GetItemFromCart,"getitemfromcart"},
  11265. {clif_parse_RemoveOption,"removeoption"},
  11266. {clif_parse_ChangeCart,"changecart"},
  11267. {clif_parse_StatusUp,"statusup"},
  11268. {clif_parse_SkillUp,"skillup"},
  11269. {clif_parse_UseSkillToId,"useskilltoid"},
  11270. {clif_parse_UseSkillToPos,"useskilltopos"},
  11271. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  11272. {clif_parse_UseSkillMap,"useskillmap"},
  11273. {clif_parse_RequestMemo,"requestmemo"},
  11274. {clif_parse_ProduceMix,"producemix"},
  11275. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  11276. {clif_parse_NpcNextClicked,"npcnextclicked"},
  11277. {clif_parse_NpcAmountInput,"npcamountinput"},
  11278. {clif_parse_NpcStringInput,"npcstringinput"},
  11279. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  11280. {clif_parse_ItemIdentify,"itemidentify"},
  11281. {clif_parse_SelectArrow,"selectarrow"},
  11282. {clif_parse_AutoSpell,"autospell"},
  11283. {clif_parse_UseCard,"usecard"},
  11284. {clif_parse_InsertCard,"insertcard"},
  11285. {clif_parse_RepairItem,"repairitem"},
  11286. {clif_parse_WeaponRefine,"weaponrefine"},
  11287. {clif_parse_SolveCharName,"solvecharname"},
  11288. {clif_parse_ResetChar,"resetchar"},
  11289. {clif_parse_LGMmessage,"lgmmessage"},
  11290. {clif_parse_MoveToKafra,"movetokafra"},
  11291. {clif_parse_MoveFromKafra,"movefromkafra"},
  11292. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  11293. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  11294. {clif_parse_CloseKafra,"closekafra"},
  11295. {clif_parse_CreateParty,"createparty"},
  11296. {clif_parse_CreateParty2,"createparty2"},
  11297. {clif_parse_PartyInvite,"partyinvite"},
  11298. {clif_parse_PartyInvite2,"partyinvite2"},
  11299. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  11300. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  11301. {clif_parse_LeaveParty,"leaveparty"},
  11302. {clif_parse_RemovePartyMember,"removepartymember"},
  11303. {clif_parse_PartyChangeOption,"partychangeoption"},
  11304. {clif_parse_PartyMessage,"partymessage"},
  11305. {clif_parse_CloseVending,"closevending"},
  11306. {clif_parse_VendingListReq,"vendinglistreq"},
  11307. {clif_parse_PurchaseReq,"purchasereq"},
  11308. {clif_parse_OpenVending,"openvending"},
  11309. {clif_parse_CreateGuild,"createguild"},
  11310. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  11311. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  11312. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  11313. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  11314. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  11315. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  11316. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  11317. {clif_parse_GuildInvite,"guildinvite"},
  11318. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  11319. {clif_parse_GuildLeave,"guildleave"},
  11320. {clif_parse_GuildExpulsion,"guildexpulsion"},
  11321. {clif_parse_GuildMessage,"guildmessage"},
  11322. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  11323. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  11324. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  11325. {clif_parse_GuildOpposition,"guildopposition"},
  11326. {clif_parse_GuildBreak,"guildbreak"},
  11327. {clif_parse_PetMenu,"petmenu"},
  11328. {clif_parse_CatchPet,"catchpet"},
  11329. {clif_parse_SelectEgg,"selectegg"},
  11330. {clif_parse_SendEmotion,"sendemotion"},
  11331. {clif_parse_ChangePetName,"changepetname"},
  11332. {clif_parse_GMKick,"gmkick"},
  11333. {clif_parse_GMHide,"gmhide"},
  11334. {clif_parse_GMReqNoChat,"gmreqnochat"},
  11335. {clif_parse_GMReqAccountName,"gmreqaccname"},
  11336. {clif_parse_GMKickAll,"killall"},
  11337. {clif_parse_GMRecall,"recall"},
  11338. {clif_parse_GMRecall,"summon"},
  11339. {clif_parse_GM_Monster_Item,"itemmonster"},
  11340. {clif_parse_GMShift,"remove"},
  11341. {clif_parse_GMShift,"shift"},
  11342. {clif_parse_GMChangeMapType,"changemaptype"},
  11343. {clif_parse_GMRc,"rc"},
  11344. {clif_parse_NoviceDoriDori,"sndoridori"},
  11345. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  11346. {clif_parse_PMIgnore,"wisexin"},
  11347. {clif_parse_PMIgnoreList,"wisexlist"},
  11348. {clif_parse_PMIgnoreAll,"wisall"},
  11349. {clif_parse_FriendsListAdd,"friendslistadd"},
  11350. {clif_parse_FriendsListRemove,"friendslistremove"},
  11351. {clif_parse_FriendsListReply,"friendslistreply"},
  11352. {clif_parse_Blacksmith,"blacksmith"},
  11353. {clif_parse_Alchemist,"alchemist"},
  11354. {clif_parse_Taekwon,"taekwon"},
  11355. {clif_parse_RankingPk,"rankingpk"},
  11356. {clif_parse_FeelSaveOk,"feelsaveok"},
  11357. {clif_parse_debug,"debug"},
  11358. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  11359. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  11360. {clif_parse_HomMoveTo,"hommoveto"},
  11361. {clif_parse_HomAttack,"homattack"},
  11362. {clif_parse_HomMenu,"hommenu"},
  11363. {clif_parse_StoragePassword,"storagepassword"},
  11364. {clif_parse_Hotkey,"hotkey"},
  11365. {clif_parse_AutoRevive,"autorevive"},
  11366. {clif_parse_Check,"check"},
  11367. {clif_parse_Adopt_request,"adoptrequest"},
  11368. {clif_parse_Adopt_reply,"adoptreply"},
  11369. #ifndef TXT_ONLY
  11370. // MAIL SYSTEM
  11371. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  11372. {clif_parse_Mail_read,"mailread"},
  11373. {clif_parse_Mail_getattach,"mailgetattach"},
  11374. {clif_parse_Mail_delete,"maildelete"},
  11375. {clif_parse_Mail_return,"mailreturn"},
  11376. {clif_parse_Mail_setattach,"mailsetattach"},
  11377. {clif_parse_Mail_winopen,"mailwinopen"},
  11378. {clif_parse_Mail_send,"mailsend"},
  11379. // AUCTION SYSTEM
  11380. {clif_parse_Auction_search,"auctionsearch"},
  11381. {clif_parse_Auction_buysell,"auctionbuysell"},
  11382. {clif_parse_Auction_setitem,"auctionsetitem"},
  11383. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  11384. {clif_parse_Auction_register,"auctionregister"},
  11385. {clif_parse_Auction_cancel,"auctioncancel"},
  11386. {clif_parse_Auction_close,"auctionclose"},
  11387. {clif_parse_Auction_bid,"auctionbid"},
  11388. #endif
  11389. {clif_parse_cashshop_buy,"cashshopbuy"},
  11390. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  11391. {clif_parse_EquipTick,"equiptickbox"},
  11392. {clif_parse_mercenary_action,"mermenu"},
  11393. {NULL,NULL}
  11394. };
  11395. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  11396. memset(packet_db,0,sizeof(packet_db));
  11397. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  11398. packet_len(i) = packet_len_table[i];
  11399. sprintf(line, "%s/packet_db.txt", db_path);
  11400. if( (fp=fopen(line,"r"))==NULL ){
  11401. ShowFatalError("can't read %s\n", line);
  11402. exit(EXIT_FAILURE);
  11403. }
  11404. clif_config.packet_db_ver = MAX_PACKET_VER;
  11405. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  11406. while( fgets(line, sizeof(line), fp) )
  11407. {
  11408. ln++;
  11409. if(line[0]=='/' && line[1]=='/')
  11410. continue;
  11411. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  11412. {
  11413. if(strcmpi(w1,"packet_ver")==0) {
  11414. int prev_ver = packet_ver;
  11415. skip_ver = 0;
  11416. packet_ver = atoi(w2);
  11417. if ( packet_ver > MAX_PACKET_VER )
  11418. { //Check to avoid overflowing. [Skotlex]
  11419. if( (warned&1) == 0 )
  11420. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  11421. warned &= 1;
  11422. skip_ver = 1;
  11423. }
  11424. else if( packet_ver < 0 )
  11425. {
  11426. if( (warned&2) == 0 )
  11427. ShowWarning("Negative packet versions are not supported.\n");
  11428. warned &= 2;
  11429. skip_ver = 1;
  11430. }
  11431. else if( packet_ver == SERVER )
  11432. {
  11433. if( (warned&4) == 0 )
  11434. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  11435. warned &= 4;
  11436. skip_ver = 1;
  11437. }
  11438. if( skip_ver )
  11439. {
  11440. ShowWarning("Skipping packet version %d.\n", packet_ver);
  11441. packet_ver = prev_ver;
  11442. continue;
  11443. }
  11444. // copy from previous version into new version and continue
  11445. // - indicating all following packets should be read into the newer version
  11446. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  11447. continue;
  11448. } else if(strcmpi(w1,"packet_db_ver")==0) {
  11449. if(strcmpi(w2,"default")==0) //This is the preferred version.
  11450. clif_config.packet_db_ver = MAX_PACKET_VER;
  11451. else // to manually set the packet DB version
  11452. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  11453. continue;
  11454. }
  11455. }
  11456. if( skip_ver != 0 )
  11457. continue; // Skipping current packet version
  11458. memset(str,0,sizeof(str));
  11459. for(j=0,p=line;j<4 && p; ++j)
  11460. {
  11461. str[j]=p;
  11462. p=strchr(p,',');
  11463. if(p) *p++=0;
  11464. }
  11465. if(str[0]==NULL)
  11466. continue;
  11467. cmd=strtol(str[0],(char **)NULL,0);
  11468. if(max_cmd < cmd)
  11469. max_cmd = cmd;
  11470. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  11471. continue;
  11472. if(str[1]==NULL){
  11473. ShowError("packet_db: packet len error\n");
  11474. continue;
  11475. }
  11476. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  11477. if(str[2]==NULL){
  11478. packet_db[packet_ver][cmd].func = NULL;
  11479. ln++;
  11480. continue;
  11481. }
  11482. // look up processing function by name
  11483. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  11484. if( j < ARRAYLENGTH(clif_parse_func) )
  11485. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  11486. // set the identifying cmd for the packet_db version
  11487. if (strcmp(str[2],"wanttoconnection")==0)
  11488. clif_config.connect_cmd[packet_ver] = cmd;
  11489. if(str[3]==NULL){
  11490. ShowError("packet_db: packet error\n");
  11491. exit(EXIT_FAILURE);
  11492. }
  11493. for(j=0,p2=str[3];p2;j++){
  11494. short k;
  11495. str2[j]=p2;
  11496. p2=strchr(p2,':');
  11497. if(p2) *p2++=0;
  11498. k = atoi(str2[j]);
  11499. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  11500. packet_db[packet_ver][cmd].pos[j] = k;
  11501. }
  11502. }
  11503. fclose(fp);
  11504. if(max_cmd > MAX_PACKET_DB)
  11505. {
  11506. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11507. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11508. }
  11509. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11510. { //Locate the nearest version that we still support. [Skotlex]
  11511. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11512. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11513. }
  11514. 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);
  11515. return 0;
  11516. }
  11517. /*==========================================
  11518. *
  11519. *------------------------------------------*/
  11520. int do_init_clif(void)
  11521. {
  11522. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11523. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11524. memset(packet_db,0,sizeof(packet_db));
  11525. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11526. packetdb_readdb();
  11527. set_defaultparse(clif_parse);
  11528. if( make_listen_bind(bind_ip,map_port) == -1 )
  11529. {
  11530. ShowFatalError("can't bind game port\n");
  11531. exit(EXIT_FAILURE);
  11532. }
  11533. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11534. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11535. return 0;
  11536. }