clif.c 515 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050
  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/grfio.h"
  7. #include "../common/malloc.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/random.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "../common/ers.h"
  14. #include "../common/conf.h"
  15. #include "map.h"
  16. #include "chrif.h"
  17. #include "pc.h"
  18. #include "status.h"
  19. #include "npc.h"
  20. #include "itemdb.h"
  21. #include "chat.h"
  22. #include "trade.h"
  23. #include "storage.h"
  24. #include "script.h"
  25. #include "skill.h"
  26. #include "atcommand.h"
  27. #include "intif.h"
  28. #include "battle.h"
  29. #include "battleground.h"
  30. #include "mob.h"
  31. #include "party.h"
  32. #include "unit.h"
  33. #include "guild.h"
  34. #include "vending.h"
  35. #include "pet.h"
  36. #include "homunculus.h"
  37. #include "instance.h"
  38. #include "mercenary.h"
  39. #include "elemental.h"
  40. #include "log.h"
  41. #include "clif.h"
  42. #include "mail.h"
  43. #include "quest.h"
  44. #include "cashshop.h"
  45. #include "channel.h"
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <stdarg.h>
  50. #include <time.h>
  51. /* for clif_clearunit_delayed */
  52. static struct eri *delay_clearunit_ers;
  53. //#define DUMP_UNKNOWN_PACKET
  54. //#define DUMP_INVALID_PACKET
  55. struct Clif_Config {
  56. int packet_db_ver; //Preferred packet version.
  57. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  58. } clif_config;
  59. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  60. int packet_db_ack[MAX_PACKET_VER + 1][MAX_ACK_FUNC + 1];
  61. /** Converts item type to display it on client if necessary.
  62. * @param nameid: Item ID
  63. * @return item type. For IT_PETEGG will be displayed as IT_WEAPON. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  64. */
  65. static inline int itemtype(int nameid) {
  66. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  67. int type = id->type;
  68. if( type == IT_SHADOWGEAR ) {
  69. if( id->equip&EQP_SHADOW_WEAPON )
  70. return IT_WEAPON;
  71. else
  72. return IT_ARMOR;
  73. }
  74. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  75. }
  76. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  77. p += pos;
  78. p[0] = (uint8)(x>>2);
  79. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  80. p[2] = (uint8)((y<<4) | (dir&0xf));
  81. }
  82. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  83. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  84. p += pos;
  85. p[0] = (uint8)(x0>>2);
  86. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  87. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  88. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  89. p[4] = (uint8)y1;
  90. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  91. }
  92. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  93. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  94. }
  95. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  96. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  97. }
  98. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  99. p += pos;
  100. if( x ) {
  101. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  102. }
  103. if( y ) {
  104. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  105. }
  106. if( dir ) {
  107. dir[0] = ( p[2] & 0x0f );
  108. }
  109. }
  110. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  111. p += pos;
  112. if( x0 ) {
  113. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  114. }
  115. if( y0 ) {
  116. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  117. }
  118. if( x1 ) {
  119. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  120. }
  121. if( y1 ) {
  122. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  123. }
  124. if( sx0 ) {
  125. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  126. }
  127. if( sy0 ) {
  128. sy0[0] = ( p[5] & 0x0f ) >> 0;
  129. }
  130. }
  131. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  132. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  133. }
  134. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  135. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  136. }
  137. //To idenfity disguised characters.
  138. static inline bool disguised(struct block_list* bl) {
  139. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  140. }
  141. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  142. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  143. if( len > max )
  144. len = max;
  145. mes[len-1] = '\0';
  146. return len;
  147. }
  148. static char map_ip_str[128];
  149. static uint32 map_ip;
  150. static uint32 bind_ip = INADDR_ANY;
  151. static uint16 map_port = 5121;
  152. static bool clif_ally_only = false;
  153. int map_fd;
  154. static int clif_parse (int fd);
  155. /*==========================================
  156. * Ip setting of map-server
  157. *------------------------------------------*/
  158. int clif_setip(const char* ip) {
  159. char ip_str[16];
  160. map_ip = host2ip(ip);
  161. if (!map_ip) {
  162. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  163. return 0;
  164. }
  165. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  166. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  167. return 1;
  168. }
  169. void clif_setbindip(const char* ip)
  170. {
  171. bind_ip = host2ip(ip);
  172. if (bind_ip) {
  173. char ip_str[16];
  174. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  175. } else {
  176. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  177. }
  178. }
  179. /*==========================================
  180. * Sets map port to 'port'
  181. * is run from map.c upon loading map server configuration
  182. *------------------------------------------*/
  183. void clif_setport(uint16 port)
  184. {
  185. map_port = port;
  186. }
  187. /*==========================================
  188. * Returns map server IP
  189. *------------------------------------------*/
  190. uint32 clif_getip(void)
  191. {
  192. return map_ip;
  193. }
  194. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  195. uint32 clif_refresh_ip(void)
  196. {
  197. uint32 new_ip;
  198. new_ip = host2ip(map_ip_str);
  199. if (new_ip && new_ip != map_ip) {
  200. map_ip = new_ip;
  201. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  202. return map_ip;
  203. }
  204. return 0;
  205. }
  206. /*==========================================
  207. * Returns map port which is set by clif_setport()
  208. *------------------------------------------*/
  209. uint16 clif_getport(void)
  210. {
  211. return map_port;
  212. }
  213. #if PACKETVER >= 20071106
  214. static inline unsigned char clif_bl_type(struct block_list *bl) {
  215. switch (bl->type) {
  216. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  217. case BL_ITEM: return 0x2; //ITEM_TYPE
  218. case BL_SKILL: return 0x3; //SKILL_TYPE
  219. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  220. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  221. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  222. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  223. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  224. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  225. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  226. default: return 0x1; //NPC_TYPE
  227. }
  228. }
  229. #endif
  230. /*==========================================
  231. * sub process of clif_send
  232. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  233. * In order to send area-wise packets, such as:
  234. * - AREA : everyone nearby your area
  235. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  236. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  237. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  238. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  239. *------------------------------------------*/
  240. static int clif_send_sub(struct block_list *bl, va_list ap)
  241. {
  242. struct block_list *src_bl;
  243. struct map_session_data *sd;
  244. unsigned char *buf;
  245. int len, type, fd;
  246. nullpo_ret(bl);
  247. nullpo_ret(sd = (struct map_session_data *)bl);
  248. fd = sd->fd;
  249. if (!fd) //Don't send to disconnected clients.
  250. return 0;
  251. buf = va_arg(ap,unsigned char*);
  252. len = va_arg(ap,int);
  253. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  254. type = va_arg(ap,int);
  255. switch(type) {
  256. case AREA_WOS:
  257. if (bl == src_bl)
  258. return 0;
  259. break;
  260. case AREA_WOC:
  261. if (sd->chatID || bl == src_bl)
  262. return 0;
  263. break;
  264. case AREA_WOSC:
  265. {
  266. if(src_bl->type == BL_PC) {
  267. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  268. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  269. return 0;
  270. }
  271. else if(src_bl->type == BL_NPC) {
  272. struct npc_data *nd = (struct npc_data *)src_bl;
  273. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  274. return 0;
  275. }
  276. }
  277. break;
  278. }
  279. if (session[fd] == NULL)
  280. return 0;
  281. /* unless visible, hold it here */
  282. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  283. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  284. return 0;
  285. WFIFOHEAD(fd, len);
  286. if (WFIFOP(fd,0) == buf) {
  287. ShowError("WARNING: Invalid use of clif_send function\n");
  288. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  289. ShowError(" Please correct your code.\n");
  290. // don't send to not move the pointer of the packet for next sessions in the loop
  291. //WFIFOSET(fd,0);//## TODO is this ok?
  292. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  293. return 0;
  294. }
  295. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  296. memcpy(WFIFOP(fd,0), buf, len);
  297. WFIFOSET(fd,len);
  298. }
  299. return 0;
  300. }
  301. /*==========================================
  302. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  303. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  304. *------------------------------------------*/
  305. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  306. {
  307. int i;
  308. struct map_session_data *sd, *tsd;
  309. struct party_data *p = NULL;
  310. struct guild *g = NULL;
  311. struct battleground_data *bg = NULL;
  312. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  313. struct s_mapiterator* iter;
  314. if( type != ALL_CLIENT )
  315. nullpo_ret(bl);
  316. sd = BL_CAST(BL_PC, bl);
  317. switch(type) {
  318. case ALL_CLIENT: //All player clients.
  319. iter = mapit_getallusers();
  320. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  321. {
  322. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  323. { // packet must exist for the client version
  324. WFIFOHEAD(tsd->fd, len);
  325. memcpy(WFIFOP(tsd->fd,0), buf, len);
  326. WFIFOSET(tsd->fd,len);
  327. }
  328. }
  329. mapit_free(iter);
  330. break;
  331. case ALL_SAMEMAP: //All players on the same map
  332. iter = mapit_getallusers();
  333. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  334. {
  335. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  336. { // packet must exist for the client version
  337. WFIFOHEAD(tsd->fd, len);
  338. memcpy(WFIFOP(tsd->fd,0), buf, len);
  339. WFIFOSET(tsd->fd,len);
  340. }
  341. }
  342. mapit_free(iter);
  343. break;
  344. case AREA:
  345. case AREA_WOSC:
  346. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  347. clif_send (buf, len, bl, SELF);
  348. case AREA_WOC:
  349. case AREA_WOS:
  350. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  351. BL_PC, buf, len, bl, type);
  352. break;
  353. case AREA_CHAT_WOC:
  354. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  355. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  356. break;
  357. case CHAT:
  358. case CHAT_WOS:
  359. {
  360. struct chat_data *cd;
  361. if (sd) {
  362. cd = (struct chat_data*)map_id2bl(sd->chatID);
  363. } else if (bl->type == BL_CHAT) {
  364. cd = (struct chat_data*)bl;
  365. } else break;
  366. if (cd == NULL)
  367. break;
  368. for(i = 0; i < cd->users; i++) {
  369. if (type == CHAT_WOS && cd->usersd[i] == sd)
  370. continue;
  371. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  372. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  373. {
  374. WFIFOHEAD(fd,len);
  375. memcpy(WFIFOP(fd,0), buf, len);
  376. WFIFOSET(fd,len);
  377. }
  378. }
  379. }
  380. }
  381. break;
  382. case PARTY_AREA:
  383. case PARTY_AREA_WOS:
  384. x0 = bl->x - AREA_SIZE;
  385. y0 = bl->y - AREA_SIZE;
  386. x1 = bl->x + AREA_SIZE;
  387. y1 = bl->y + AREA_SIZE;
  388. case PARTY:
  389. case PARTY_WOS:
  390. case PARTY_SAMEMAP:
  391. case PARTY_SAMEMAP_WOS:
  392. if (sd && sd->status.party_id)
  393. p = party_search(sd->status.party_id);
  394. if (p) {
  395. for(i=0;i<MAX_PARTY;i++){
  396. if( (sd = p->data[i].sd) == NULL )
  397. continue;
  398. if( !(fd=sd->fd) )
  399. continue;
  400. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  401. continue;
  402. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  403. continue;
  404. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  405. continue;
  406. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  407. { // packet must exist for the client version
  408. WFIFOHEAD(fd,len);
  409. memcpy(WFIFOP(fd,0), buf, len);
  410. WFIFOSET(fd,len);
  411. }
  412. }
  413. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  414. break;
  415. iter = mapit_getallusers();
  416. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  417. {
  418. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  419. { // packet must exist for the client version
  420. WFIFOHEAD(tsd->fd, len);
  421. memcpy(WFIFOP(tsd->fd,0), buf, len);
  422. WFIFOSET(tsd->fd,len);
  423. }
  424. }
  425. mapit_free(iter);
  426. }
  427. break;
  428. case DUEL:
  429. case DUEL_WOS:
  430. if (!sd || !sd->duel_group) break; //Invalid usage.
  431. iter = mapit_getallusers();
  432. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  433. {
  434. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  435. continue;
  436. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  437. { // packet must exist for the client version
  438. WFIFOHEAD(tsd->fd, len);
  439. memcpy(WFIFOP(tsd->fd,0), buf, len);
  440. WFIFOSET(tsd->fd,len);
  441. }
  442. }
  443. mapit_free(iter);
  444. break;
  445. case SELF:
  446. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  447. WFIFOHEAD(fd,len);
  448. memcpy(WFIFOP(fd,0), buf, len);
  449. WFIFOSET(fd,len);
  450. }
  451. break;
  452. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  453. case GUILD_AREA:
  454. case GUILD_AREA_WOS:
  455. x0 = bl->x - AREA_SIZE;
  456. y0 = bl->y - AREA_SIZE;
  457. x1 = bl->x + AREA_SIZE;
  458. y1 = bl->y + AREA_SIZE;
  459. case GUILD_SAMEMAP:
  460. case GUILD_SAMEMAP_WOS:
  461. case GUILD:
  462. case GUILD_WOS:
  463. case GUILD_NOBG:
  464. if (sd && sd->status.guild_id)
  465. g = sd->guild;
  466. if (g) {
  467. for(i = 0; i < g->max_member; i++) {
  468. if( (sd = g->member[i].sd) != NULL )
  469. {
  470. if( !(fd=sd->fd) )
  471. continue;
  472. if( type == GUILD_NOBG && sd->bg_id )
  473. continue;
  474. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  475. continue;
  476. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  477. continue;
  478. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  479. continue;
  480. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  481. { // packet must exist for the client version
  482. WFIFOHEAD(fd,len);
  483. memcpy(WFIFOP(fd,0), buf, len);
  484. WFIFOSET(fd,len);
  485. }
  486. }
  487. }
  488. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  489. break;
  490. iter = mapit_getallusers();
  491. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  492. {
  493. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  494. { // packet must exist for the client version
  495. WFIFOHEAD(tsd->fd, len);
  496. memcpy(WFIFOP(tsd->fd,0), buf, len);
  497. WFIFOSET(tsd->fd,len);
  498. }
  499. }
  500. mapit_free(iter);
  501. }
  502. break;
  503. case BG_AREA:
  504. case BG_AREA_WOS:
  505. x0 = bl->x - AREA_SIZE;
  506. y0 = bl->y - AREA_SIZE;
  507. x1 = bl->x + AREA_SIZE;
  508. y1 = bl->y + AREA_SIZE;
  509. case BG_SAMEMAP:
  510. case BG_SAMEMAP_WOS:
  511. case BG:
  512. case BG_WOS:
  513. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  514. {
  515. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  516. {
  517. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  518. continue;
  519. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  520. continue;
  521. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  522. continue;
  523. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  524. continue;
  525. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  526. { // packet must exist for the client version
  527. WFIFOHEAD(fd,len);
  528. memcpy(WFIFOP(fd,0), buf, len);
  529. WFIFOSET(fd,len);
  530. }
  531. }
  532. }
  533. break;
  534. default:
  535. ShowError("clif_send: Unrecognized type %d\n",type);
  536. return -1;
  537. }
  538. return 0;
  539. }
  540. /// Notifies the client, that it's connection attempt was accepted.
  541. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  542. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  543. void clif_authok(struct map_session_data *sd)
  544. {
  545. #if PACKETVER < 20080102
  546. const int cmd = 0x73;
  547. #else
  548. const int cmd = 0x2eb;
  549. #endif
  550. int fd = sd->fd;
  551. WFIFOHEAD(fd,packet_len(cmd));
  552. WFIFOW(fd, 0) = cmd;
  553. WFIFOL(fd, 2) = gettick();
  554. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  555. WFIFOB(fd, 9) = 5; // ignored
  556. WFIFOB(fd,10) = 5; // ignored
  557. #if PACKETVER >= 20080102
  558. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  559. #endif
  560. WFIFOSET(fd,packet_len(cmd));
  561. }
  562. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  563. /// 0074 <error code>.B
  564. /// error code:
  565. /// 0 = client type mismatch
  566. /// 1 = ID mismatch
  567. /// 2 = mobile - out of available time
  568. /// 3 = mobile - already logged in
  569. /// 4 = mobile - waiting state
  570. void clif_authrefuse(int fd, uint8 error_code)
  571. {
  572. WFIFOHEAD(fd,packet_len(0x74));
  573. WFIFOW(fd,0) = 0x74;
  574. WFIFOB(fd,2) = error_code;
  575. WFIFOSET(fd,packet_len(0x74));
  576. }
  577. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  578. /// 0081 <error code>.B
  579. /// error code:
  580. /// 0 = BAN_UNFAIR
  581. /// 1 = server closed -> MsgStringTable[4]
  582. /// 2 = ID already logged in -> MsgStringTable[5]
  583. /// 3 = timeout/too much lag -> MsgStringTable[241]
  584. /// 4 = server full -> MsgStringTable[264]
  585. /// 5 = underaged -> MsgStringTable[305]
  586. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  587. /// 9 = too many connections from this ip -> MsgStringTable[529]
  588. /// 10 = out of available time paid for -> MsgStringTable[530]
  589. /// 11 = BAN_PAY_SUSPEND
  590. /// 12 = BAN_PAY_CHANGE
  591. /// 13 = BAN_PAY_WRONGIP
  592. /// 14 = BAN_PAY_PNGAMEROOM
  593. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  594. /// 16 = BAN_JAPAN_REFUSE1
  595. /// 17 = BAN_JAPAN_REFUSE2
  596. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  597. /// 100 = BAN_PC_IP_UNFAIR
  598. /// 101 = BAN_PC_IP_COUNT_ALL
  599. /// 102 = BAN_PC_IP_COUNT
  600. /// 103 = BAN_GRAVITY_MEM_AGREE
  601. /// 104 = BAN_GAME_MEM_AGREE
  602. /// 105 = BAN_HAN_VALID
  603. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  604. /// 107 = BAN_OVER_CHARACTER_LIST
  605. /// 108 = BAN_IP_BLOCK
  606. /// 109 = BAN_INVALID_PWD_CNT
  607. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  608. /// ? = disconnected -> MsgStringTable[3]
  609. void clif_authfail_fd(int fd, int type)
  610. {
  611. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  612. return;
  613. WFIFOHEAD(fd, packet_len(0x81));
  614. WFIFOW(fd,0) = 0x81;
  615. WFIFOB(fd,2) = type;
  616. WFIFOSET(fd,packet_len(0x81));
  617. set_eof(fd);
  618. }
  619. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  620. /// 00b3 <type>.B
  621. /// type:
  622. /// 1 = disconnect, char-select
  623. /// ? = nothing
  624. void clif_charselectok(int id, uint8 ok)
  625. {
  626. struct map_session_data* sd;
  627. int fd;
  628. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  629. return;
  630. fd = sd->fd;
  631. WFIFOHEAD(fd,packet_len(0xb3));
  632. WFIFOW(fd,0) = 0xb3;
  633. WFIFOB(fd,2) = ok;
  634. WFIFOSET(fd,packet_len(0xb3));
  635. }
  636. /// Makes an item appear on the ground.
  637. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  638. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  639. void clif_dropflooritem(struct flooritem_data* fitem)
  640. {
  641. #if PACKETVER >= 20130000
  642. uint8 buf[19];
  643. uint32 header=0x84b;
  644. #else
  645. uint8 buf[17];
  646. uint32 header=0x09e;
  647. #endif
  648. int view, offset=0;
  649. nullpo_retv(fitem);
  650. if (fitem->item_data.nameid <= 0)
  651. return;
  652. WBUFW(buf, offset+0) = header;
  653. WBUFL(buf, offset+2) = fitem->bl.id;
  654. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  655. #if PACKETVER >= 20130000
  656. WBUFW(buf, offset+8) = itemtype(fitem->item_data.nameid);
  657. offset +=2;
  658. #endif
  659. WBUFB(buf, offset+8) = fitem->item_data.identify;
  660. WBUFW(buf, offset+9) = fitem->bl.x;
  661. WBUFW(buf, offset+11) = fitem->bl.y;
  662. WBUFB(buf, offset+13) = fitem->subx;
  663. WBUFB(buf, offset+14) = fitem->suby;
  664. WBUFW(buf, offset+15) = fitem->item_data.amount;
  665. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  666. }
  667. /// Makes an item disappear from the ground.
  668. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  669. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  670. {
  671. unsigned char buf[16];
  672. nullpo_retv(fitem);
  673. WBUFW(buf,0) = 0xa1;
  674. WBUFL(buf,2) = fitem->bl.id;
  675. if (fd == 0) {
  676. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  677. } else {
  678. WFIFOHEAD(fd,packet_len(0xa1));
  679. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  680. WFIFOSET(fd,packet_len(0xa1));
  681. }
  682. }
  683. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  684. /// 0080 <id>.L <type>.B
  685. /// type:
  686. /// 0 = out of sight
  687. /// 1 = died
  688. /// 2 = logged out
  689. /// 3 = teleport
  690. /// 4 = trickdead
  691. void clif_clearunit_single(int id, clr_type type, int fd)
  692. {
  693. WFIFOHEAD(fd, packet_len(0x80));
  694. WFIFOW(fd,0) = 0x80;
  695. WFIFOL(fd,2) = id;
  696. WFIFOB(fd,6) = type;
  697. WFIFOSET(fd, packet_len(0x80));
  698. }
  699. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  700. /// 0080 <id>.L <type>.B
  701. /// type:
  702. /// 0 = out of sight
  703. /// 1 = died
  704. /// 2 = logged out
  705. /// 3 = teleport
  706. /// 4 = trickdead
  707. void clif_clearunit_area(struct block_list* bl, clr_type type)
  708. {
  709. unsigned char buf[8];
  710. nullpo_retv(bl);
  711. WBUFW(buf,0) = 0x80;
  712. WBUFL(buf,2) = bl->id;
  713. WBUFB(buf,6) = type;
  714. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  715. if(disguised(bl)) {
  716. WBUFL(buf,2) = -bl->id;
  717. clif_send(buf, packet_len(0x80), bl, SELF);
  718. }
  719. }
  720. /// Used to make monsters with player-sprites disappear after dying
  721. /// like normal monsters, because the client does not remove those
  722. /// automatically.
  723. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  724. {
  725. struct block_list *bl = (struct block_list *)data;
  726. clif_clearunit_area(bl, (clr_type) id);
  727. ers_free(delay_clearunit_ers,bl);
  728. return 0;
  729. }
  730. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  731. {
  732. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  733. memcpy (tbl, bl, sizeof (struct block_list));
  734. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  735. }
  736. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  737. {
  738. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK|OPTION_OKTOBERFEST))
  739. {
  740. *rhand = *lhand = 0;
  741. return;
  742. }
  743. #if PACKETVER < 4
  744. *rhand = sd->status.weapon;
  745. *lhand = sd->status.shield;
  746. #else
  747. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  748. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  749. {
  750. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  751. if (id->view_id > 0)
  752. *rhand = id->view_id;
  753. else
  754. *rhand = id->nameid;
  755. } else
  756. *rhand = 0;
  757. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  758. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  759. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  760. {
  761. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  762. if (id->view_id > 0)
  763. *lhand = id->view_id;
  764. else
  765. *lhand = id->nameid;
  766. } else
  767. *lhand = 0;
  768. #endif
  769. }
  770. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  771. static int clif_setlevel_sub(int lv) {
  772. if( lv < battle_config.max_lv ) {
  773. ;
  774. } else if( lv < battle_config.aura_lv ) {
  775. lv = battle_config.max_lv - 1;
  776. } else {
  777. lv = battle_config.max_lv;
  778. }
  779. return lv;
  780. }
  781. static int clif_setlevel(struct block_list* bl) {
  782. int lv = status_get_lv(bl);
  783. if( battle_config.client_limit_unit_lv&bl->type )
  784. return clif_setlevel_sub(lv);
  785. switch( bl->type ) {
  786. case BL_NPC:
  787. case BL_PET:
  788. // npcs and pets do not have level
  789. return 0;
  790. }
  791. return lv;
  792. }
  793. /*==========================================
  794. * Prepares 'unit standing/spawning' packet
  795. *------------------------------------------*/
  796. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  797. {
  798. struct map_session_data* sd;
  799. struct status_change* sc = status_get_sc(bl);
  800. struct view_data* vd = status_get_viewdata(bl);
  801. unsigned char *buf = WBUFP(buffer,0);
  802. #if PACKETVER < 20091103
  803. bool type = !pcdb_checkid(vd->class_);
  804. #endif
  805. unsigned short offset = 0;
  806. #if PACKETVER >= 20091103
  807. const char *name;
  808. #endif
  809. sd = BL_CAST(BL_PC, bl);
  810. #if PACKETVER < 20091103
  811. if(type)
  812. WBUFW(buf,0) = spawn?0x7c:0x78;
  813. else
  814. #endif
  815. #if PACKETVER < 4
  816. WBUFW(buf,0) = spawn?0x79:0x78;
  817. #elif PACKETVER < 7
  818. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  819. #elif PACKETVER < 20080102
  820. WBUFW(buf,0) = spawn?0x22b:0x22a;
  821. #elif PACKETVER < 20091103
  822. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  823. #elif PACKETVER < 20101124
  824. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  825. #else
  826. WBUFW(buf,0) = spawn?0x858:0x857;
  827. #endif
  828. #if PACKETVER >= 20091103
  829. name = status_get_name(bl);
  830. #if PACKETVER < 20110111
  831. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  832. #else
  833. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  834. #endif
  835. WBUFB(buf,4) = clif_bl_type(bl);
  836. offset+=3;
  837. buf = WBUFP(buffer,offset);
  838. #elif PACKETVER >= 20071106
  839. if (type) { //Non-player packets
  840. WBUFB(buf,2) = clif_bl_type(bl);
  841. offset++;
  842. buf = WBUFP(buffer,offset);
  843. }
  844. #endif
  845. WBUFL(buf, 2) = bl->id;
  846. WBUFW(buf, 6) = status_get_speed(bl);
  847. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  848. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  849. #if PACKETVER < 20091103
  850. if (type&&spawn) { //uses an older and different packet structure
  851. WBUFW(buf,12) = (sc)? sc->option : 0;
  852. WBUFW(buf,14) = vd->hair_style;
  853. WBUFW(buf,16) = vd->weapon;
  854. WBUFW(buf,18) = vd->head_bottom;
  855. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  856. WBUFW(buf,22) = vd->shield;
  857. } else {
  858. #endif
  859. #if PACKETVER >= 20091103
  860. WBUFL(buf,12) = (sc)? sc->option : 0;
  861. offset+=2;
  862. buf = WBUFP(buffer,offset);
  863. #elif PACKETVER >= 7
  864. if (!type) {
  865. WBUFL(buf,12) = (sc)? sc->option : 0;
  866. offset+=2;
  867. buf = WBUFP(buffer,offset);
  868. } else
  869. WBUFW(buf,12) = (sc)? sc->option : 0;
  870. #else
  871. WBUFW(buf,12) = (sc)? sc->option : 0;
  872. #endif
  873. WBUFW(buf,14) = vd->class_;
  874. WBUFW(buf,16) = vd->hair_style;
  875. WBUFW(buf,18) = vd->weapon;
  876. #if PACKETVER < 4
  877. WBUFW(buf,20) = vd->head_bottom;
  878. WBUFW(buf,22) = vd->shield;
  879. #else
  880. WBUFW(buf,20) = vd->shield;
  881. WBUFW(buf,22) = vd->head_bottom;
  882. #endif
  883. #if PACKETVER < 20091103
  884. }
  885. #endif
  886. WBUFW(buf,24) = vd->head_top;
  887. WBUFW(buf,26) = vd->head_mid;
  888. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  889. { //The hell, why flags work like this?
  890. WBUFW(buf,22) = status_get_emblem_id(bl);
  891. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  892. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  893. }
  894. WBUFW(buf,28) = vd->hair_color;
  895. WBUFW(buf,30) = vd->cloth_color;
  896. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  897. #if PACKETVER < 20091103
  898. if (type&&spawn) { //End of packet 0x7c
  899. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  900. WBUFB(buf,35) = vd->sex;
  901. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  902. WBUFB(buf,39) = 0;
  903. WBUFB(buf,40) = 0;
  904. return packet_len(0x7c);
  905. }
  906. #endif
  907. #if PACKETVER >= 20110111
  908. WBUFW(buf,34) = vd->robe;
  909. offset+= 2;
  910. buf = WBUFP(buffer,offset);
  911. #endif
  912. WBUFL(buf,34) = status_get_guild_id(bl);
  913. WBUFW(buf,38) = status_get_emblem_id(bl);
  914. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  915. #if PACKETVER >= 20091103
  916. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  917. offset+=2;
  918. buf = WBUFP(buffer,offset);
  919. #elif PACKETVER >= 7
  920. if (!type) {
  921. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  922. offset+=2;
  923. buf = WBUFP(buffer,offset);
  924. } else
  925. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  926. #else
  927. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  928. #endif
  929. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  930. WBUFB(buf,45) = vd->sex;
  931. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  932. WBUFB(buf,49) = (sd)? 5 : 0;
  933. WBUFB(buf,50) = (sd)? 5 : 0;
  934. if (!spawn) {
  935. WBUFB(buf,51) = vd->dead_sit;
  936. offset++;
  937. buf = WBUFP(buffer,offset);
  938. }
  939. WBUFW(buf,51) = clif_setlevel(bl);
  940. #if PACKETVER < 20091103
  941. if (type) //End for non-player packet
  942. return packet_len(WBUFW(buffer,0));
  943. #endif
  944. #if PACKETVER >= 20080102
  945. WBUFW(buf,53) = sd?sd->user_font:0;
  946. #endif
  947. #if PACKETVER >= 20091103
  948. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  949. return WBUFW(buffer,2);
  950. #else
  951. return packet_len(WBUFW(buffer,0));
  952. #endif
  953. }
  954. /*==========================================
  955. * Prepares 'unit walking' packet
  956. *------------------------------------------*/
  957. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  958. {
  959. struct map_session_data* sd;
  960. struct status_change* sc = status_get_sc(bl);
  961. struct view_data* vd = status_get_viewdata(bl);
  962. unsigned char* buf = WBUFP(buffer,0);
  963. #if PACKETVER >= 7
  964. unsigned short offset = 0;
  965. #endif
  966. #if PACKETVER >= 20091103
  967. const char *name;
  968. #endif
  969. sd = BL_CAST(BL_PC, bl);
  970. #if PACKETVER < 4
  971. WBUFW(buf, 0) = 0x7b;
  972. #elif PACKETVER < 7
  973. WBUFW(buf, 0) = 0x1da;
  974. #elif PACKETVER < 20080102
  975. WBUFW(buf, 0) = 0x22c;
  976. #elif PACKETVER < 20091103
  977. WBUFW(buf, 0) = 0x2ec;
  978. #elif PACKETVER < 20101124
  979. WBUFW(buf, 0) = 0x7f7;
  980. #else
  981. WBUFW(buf, 0) = 0x856;
  982. #endif
  983. #if PACKETVER >= 20091103
  984. name = status_get_name(bl);
  985. #if PACKETVER < 20110111
  986. WBUFW(buf, 2) = 69+strlen(name);
  987. #else
  988. WBUFW(buf, 2) = 71+strlen(name);
  989. #endif
  990. offset+=2;
  991. buf = WBUFP(buffer,offset);
  992. #endif
  993. #if PACKETVER >= 20071106
  994. WBUFB(buf, 2) = clif_bl_type(bl);
  995. offset++;
  996. buf = WBUFP(buffer,offset);
  997. #endif
  998. WBUFL(buf, 2) = bl->id;
  999. WBUFW(buf, 6) = status_get_speed(bl);
  1000. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1001. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1002. #if PACKETVER < 7
  1003. WBUFW(buf,12) = (sc)? sc->option : 0;
  1004. #else
  1005. WBUFL(buf,12) = (sc)? sc->option : 0;
  1006. offset+=2; //Shift the rest of elements by 2 bytes.
  1007. buf = WBUFP(buffer,offset);
  1008. #endif
  1009. WBUFW(buf,14) = vd->class_;
  1010. WBUFW(buf,16) = vd->hair_style;
  1011. WBUFW(buf,18) = vd->weapon;
  1012. #if PACKETVER < 4
  1013. WBUFW(buf,20) = vd->head_bottom;
  1014. WBUFL(buf,22) = gettick();
  1015. WBUFW(buf,26) = vd->shield;
  1016. #else
  1017. WBUFW(buf,20) = vd->shield;
  1018. WBUFW(buf,22) = vd->head_bottom;
  1019. WBUFL(buf,24) = gettick();
  1020. #endif
  1021. WBUFW(buf,28) = vd->head_top;
  1022. WBUFW(buf,30) = vd->head_mid;
  1023. WBUFW(buf,32) = vd->hair_color;
  1024. WBUFW(buf,34) = vd->cloth_color;
  1025. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1026. #if PACKETVER >= 20110111
  1027. WBUFW(buf,38) = vd->robe;
  1028. offset+= 2;
  1029. buf = WBUFP(buffer,offset);
  1030. #endif
  1031. WBUFL(buf,38) = status_get_guild_id(bl);
  1032. WBUFW(buf,42) = status_get_emblem_id(bl);
  1033. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1034. #if PACKETVER < 7
  1035. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1036. #else
  1037. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1038. offset+=2; //Shift the rest of elements by 2 bytes.
  1039. buf = WBUFP(buffer,offset);
  1040. #endif
  1041. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1042. WBUFB(buf,49) = vd->sex;
  1043. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1044. WBUFB(buf,56) = (sd)? 5 : 0;
  1045. WBUFB(buf,57) = (sd)? 5 : 0;
  1046. WBUFW(buf,58) = clif_setlevel(bl);
  1047. #if PACKETVER >= 20080102
  1048. WBUFW(buf,60) = sd?sd->user_font:0;
  1049. #endif
  1050. #if PACKETVER >= 20091103
  1051. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1052. return WBUFW(buffer,2);
  1053. #else
  1054. return packet_len(WBUFW(buffer,0));
  1055. #endif
  1056. }
  1057. //Modifies the buffer for disguise characters and sends it to self.
  1058. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1059. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1060. {
  1061. #if PACKETVER >= 20091103
  1062. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1063. WBUFL(buf,5)=-bl->id;
  1064. #elif PACKETVER >= 20071106
  1065. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. WBUFL(buf,3)=-bl->id;
  1067. #else
  1068. WBUFL(buf,2)=-bl->id;
  1069. #endif
  1070. clif_send(buf, len, bl, SELF);
  1071. }
  1072. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1073. /// 01b0 <id>.L <type>.B <value>.L
  1074. /// type:
  1075. /// unused
  1076. void clif_class_change(struct block_list *bl,int class_,int type)
  1077. {
  1078. nullpo_retv(bl);
  1079. if(!pcdb_checkid(class_))
  1080. {// player classes yield missing sprites
  1081. unsigned char buf[16];
  1082. WBUFW(buf,0)=0x1b0;
  1083. WBUFL(buf,2)=bl->id;
  1084. WBUFB(buf,6)=type;
  1085. WBUFL(buf,7)=class_;
  1086. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1087. }
  1088. }
  1089. /// Notifies the client of an object's spirits.
  1090. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1091. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1092. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1093. {
  1094. WFIFOHEAD(fd, packet_len(0x1e1));
  1095. WFIFOW(fd,0)=0x1e1;
  1096. WFIFOL(fd,2)=sd->bl.id;
  1097. WFIFOW(fd,6)=sd->spiritball;
  1098. WFIFOSET(fd, packet_len(0x1e1));
  1099. }
  1100. /*==========================================
  1101. * Kagerou/Oboro amulet spirit
  1102. *------------------------------------------*/
  1103. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1104. {
  1105. WFIFOHEAD(fd, packet_len(0x08cf));
  1106. WFIFOW(fd,0)=0x08cf;
  1107. WFIFOL(fd,2)=sd->bl.id;
  1108. WFIFOW(fd,6)=type;
  1109. WFIFOW(fd,8)=sd->talisman[type];
  1110. WFIFOSET(fd, packet_len(0x08cf));
  1111. }
  1112. /*==========================================
  1113. * Run when player changes map / refreshes
  1114. * Tells its client to display all weather settings being used by this map
  1115. *------------------------------------------*/
  1116. static void clif_weather_check(struct map_session_data *sd)
  1117. {
  1118. int16 m = sd->bl.m;
  1119. int fd = sd->fd;
  1120. if (map[m].flag.snow
  1121. || map[m].flag.clouds
  1122. || map[m].flag.fog
  1123. || map[m].flag.fireworks
  1124. || map[m].flag.sakura
  1125. || map[m].flag.leaves
  1126. || map[m].flag.clouds2)
  1127. {
  1128. if (map[m].flag.snow)
  1129. clif_specialeffect_single(&sd->bl, 162, fd);
  1130. if (map[m].flag.clouds)
  1131. clif_specialeffect_single(&sd->bl, 233, fd);
  1132. if (map[m].flag.clouds2)
  1133. clif_specialeffect_single(&sd->bl, 516, fd);
  1134. if (map[m].flag.fog)
  1135. clif_specialeffect_single(&sd->bl, 515, fd);
  1136. if (map[m].flag.fireworks) {
  1137. clif_specialeffect_single(&sd->bl, 297, fd);
  1138. clif_specialeffect_single(&sd->bl, 299, fd);
  1139. clif_specialeffect_single(&sd->bl, 301, fd);
  1140. }
  1141. if (map[m].flag.sakura)
  1142. clif_specialeffect_single(&sd->bl, 163, fd);
  1143. if (map[m].flag.leaves)
  1144. clif_specialeffect_single(&sd->bl, 333, fd);
  1145. }
  1146. }
  1147. /**
  1148. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1149. **/
  1150. void clif_weather(int16 m)
  1151. {
  1152. struct s_mapiterator* iter;
  1153. struct map_session_data *sd=NULL;
  1154. iter = mapit_getallusers();
  1155. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1156. {
  1157. if( sd->bl.m == m )
  1158. clif_weather_check(sd);
  1159. }
  1160. mapit_free(iter);
  1161. }
  1162. /**
  1163. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1164. **/
  1165. int clif_spawn(struct block_list *bl)
  1166. {
  1167. unsigned char buf[128];
  1168. struct view_data *vd;
  1169. int len;
  1170. vd = status_get_viewdata(bl);
  1171. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1172. return 0;
  1173. /**
  1174. * Hide NPC from maya purple card.
  1175. **/
  1176. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1177. return 0;
  1178. len = clif_set_unit_idle(bl, buf,true);
  1179. clif_send(buf, len, bl, AREA_WOS);
  1180. if (disguised(bl))
  1181. clif_setdisguise(bl, buf, len);
  1182. if (vd->cloth_color)
  1183. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1184. switch (bl->type)
  1185. {
  1186. case BL_PC:
  1187. {
  1188. TBL_PC *sd = ((TBL_PC*)bl);
  1189. int i;
  1190. if (sd->spiritball > 0)
  1191. clif_spiritball(&sd->bl);
  1192. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1193. clif_specialeffect(bl,423,AREA);
  1194. else if(sd->state.size==SZ_MEDIUM)
  1195. clif_specialeffect(bl,421,AREA);
  1196. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1197. clif_sendbgemblem_area(sd);
  1198. for(i = 1; i < 5; i++){
  1199. if( sd->talisman[i] > 0 )
  1200. clif_talisman(sd, i);
  1201. }
  1202. for( i = SC_SPHERE_1; i <= SC_SPHERE_5; i++ ) {
  1203. if( sd->sc.data[i] )
  1204. clif_status_change(bl,StatusIconChangeTable[i],1,0,sd->sc.data[i]->val1,sd->sc.data[i]->val2,0);
  1205. }
  1206. #ifdef NEW_CARTS
  1207. if( sd->sc.data[SC_PUSH_CART] )
  1208. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1209. #endif
  1210. if (sd->status.robe)
  1211. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1212. if (!&sd->sc)
  1213. break;
  1214. if( sd->sc.data[SC_CAMOUFLAGE] )
  1215. clif_status_load(bl,SI_CAMOUFLAGE,1);
  1216. if( sd->sc.data[SC_MONSTER_TRANSFORM] )
  1217. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,sd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  1218. if( sd->sc.data[SC_MOONSTAR] )
  1219. clif_status_load(bl,SI_MOONSTAR,1);
  1220. if( sd->sc.data[SC_SUPER_STAR] )
  1221. clif_status_load(bl,SI_SUPER_STAR,1);
  1222. if( sd->sc.data[SC_ALL_RIDING] )
  1223. clif_status_load(bl,SI_ALL_RIDING,1);
  1224. }
  1225. break;
  1226. case BL_MOB:
  1227. {
  1228. TBL_MOB *md = ((TBL_MOB*)bl);
  1229. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1230. clif_specialeffect(&md->bl,423,AREA);
  1231. else if(md->special_state.size==SZ_MEDIUM)
  1232. clif_specialeffect(&md->bl,421,AREA);
  1233. }
  1234. break;
  1235. case BL_NPC:
  1236. {
  1237. TBL_NPC *nd = ((TBL_NPC*)bl);
  1238. if( nd->size == SZ_BIG )
  1239. clif_specialeffect(&nd->bl,423,AREA);
  1240. else if( nd->size == SZ_MEDIUM )
  1241. clif_specialeffect(&nd->bl,421,AREA);
  1242. }
  1243. break;
  1244. case BL_PET:
  1245. if (vd->head_bottom)
  1246. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1247. break;
  1248. }
  1249. return 0;
  1250. }
  1251. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1252. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W
  1253. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1254. {
  1255. struct status_data *status;
  1256. unsigned char buf[128];
  1257. int htype;
  1258. nullpo_retv(hd);
  1259. status = &hd->battle_status;
  1260. htype = hom_class2type(hd->homunculus.class_);
  1261. memset(buf,0,packet_len(0x22e));
  1262. WBUFW(buf,0)=0x22e;
  1263. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1264. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1265. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1266. WBUFW(buf,27)=hd->homunculus.level;
  1267. WBUFW(buf,29)=hd->homunculus.hunger;
  1268. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1269. WBUFW(buf,33)=0; // equip id
  1270. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1271. WBUFW(buf,37)=min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1272. WBUFW(buf,39)=status->hit;
  1273. if (battle_config.hom_setting&0x10)
  1274. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1275. else
  1276. WBUFW(buf,41)=status->cri/10;
  1277. WBUFW(buf,43)=status->def + status->vit ;
  1278. WBUFW(buf,45)=status->mdef;
  1279. WBUFW(buf,47)=status->flee;
  1280. WBUFW(buf,49)=(flag)?0:status->amotion;
  1281. if (status->max_hp > INT16_MAX) {
  1282. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1283. WBUFW(buf,53) = 100;
  1284. } else {
  1285. WBUFW(buf,51)=status->hp;
  1286. WBUFW(buf,53)=status->max_hp;
  1287. }
  1288. if (status->max_sp > INT16_MAX) {
  1289. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1290. WBUFW(buf,57) = 100;
  1291. } else {
  1292. WBUFW(buf,55)=status->sp;
  1293. WBUFW(buf,57)=status->max_sp;
  1294. }
  1295. WBUFL(buf,59)=hd->homunculus.exp;
  1296. WBUFL(buf,63)=hd->exp_next;
  1297. switch( htype ) {
  1298. case HT_REG:
  1299. case HT_EVO:
  1300. if( hd->homunculus.level >= battle_config.hom_max_level )
  1301. WBUFL(buf,63)=0;
  1302. break;
  1303. case HT_S:
  1304. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1305. WBUFL(buf,63)=0;
  1306. break;
  1307. }
  1308. WBUFW(buf,67)=hd->homunculus.skillpts;
  1309. WBUFW(buf,69)=status_get_range(&hd->bl);
  1310. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1311. }
  1312. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1313. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1314. /// type:
  1315. /// unused
  1316. /// state:
  1317. /// 0 = pre-init
  1318. /// 1 = intimacy
  1319. /// 2 = hunger
  1320. /// 3 = accessory?
  1321. /// ? = ignored
  1322. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1323. { //[orn]
  1324. int fd = sd->fd;
  1325. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1326. merc_hom_calc_skilltree(sd->hd, 0);
  1327. WFIFOHEAD(fd, packet_len(0x230));
  1328. WFIFOW(fd,0)=0x230;
  1329. WFIFOB(fd,2)=0;
  1330. WFIFOB(fd,3)=state;
  1331. WFIFOL(fd,4)=sd->hd->bl.id;
  1332. WFIFOL(fd,8)=param;
  1333. WFIFOSET(fd,packet_len(0x230));
  1334. }
  1335. int clif_homskillinfoblock(struct map_session_data *sd)
  1336. { //[orn]
  1337. struct homun_data *hd;
  1338. int fd = sd->fd;
  1339. int i,j,len=4,id;
  1340. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1341. hd = sd->hd;
  1342. if ( !hd )
  1343. return 0 ;
  1344. WFIFOW(fd,0)=0x235;
  1345. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1346. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1347. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1348. j = id - HM_SKILLBASE;
  1349. WFIFOW(fd,len ) = id;
  1350. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1351. WFIFOW(fd,len+4) = 0;
  1352. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1353. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1354. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1355. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1356. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1357. len+=37;
  1358. }
  1359. }
  1360. WFIFOW(fd,2)=len;
  1361. WFIFOSET(fd,len);
  1362. return 0;
  1363. }
  1364. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1365. { //[orn]
  1366. struct homun_data *hd;
  1367. int fd, idx;
  1368. nullpo_retv(sd);
  1369. idx = skill_id - HM_SKILLBASE;
  1370. fd=sd->fd;
  1371. hd=sd->hd;
  1372. WFIFOHEAD(fd, packet_len(0x239));
  1373. WFIFOW(fd,0) = 0x239;
  1374. WFIFOW(fd,2) = skill_id;
  1375. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1376. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1377. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1378. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1379. WFIFOSET(fd,packet_len(0x239));
  1380. }
  1381. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1382. {
  1383. int fd=sd->fd;
  1384. WFIFOHEAD(fd,packet_len(0x22f));
  1385. WFIFOW(fd,0)=0x22f;
  1386. WFIFOB(fd,2)=fail;
  1387. WFIFOW(fd,3)=foodid;
  1388. WFIFOSET(fd,packet_len(0x22f));
  1389. return 0;
  1390. }
  1391. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1392. /// 0087 <walk start time>.L <walk data>.6B
  1393. void clif_walkok(struct map_session_data *sd)
  1394. {
  1395. int fd=sd->fd;
  1396. WFIFOHEAD(fd, packet_len(0x87));
  1397. WFIFOW(fd,0)=0x87;
  1398. WFIFOL(fd,2)=gettick();
  1399. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1400. WFIFOSET(fd,packet_len(0x87));
  1401. }
  1402. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1403. {
  1404. uint8 buf[128];
  1405. int len;
  1406. struct status_change *sc = NULL;
  1407. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1408. clif_ally_only = true;
  1409. len = clif_set_unit_walking(bl,ud,buf);
  1410. clif_send(buf,len,bl,AREA_WOS);
  1411. if (disguised(bl))
  1412. clif_setdisguise(bl, buf, len);
  1413. if(vd->cloth_color)
  1414. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1415. switch(bl->type) {
  1416. case BL_PC:
  1417. {
  1418. TBL_PC *sd = ((TBL_PC*)bl);
  1419. // clif_movepc(sd);
  1420. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1421. clif_specialeffect(&sd->bl,423,AREA);
  1422. else if(sd->state.size==SZ_MEDIUM)
  1423. clif_specialeffect(&sd->bl,421,AREA);
  1424. }
  1425. break;
  1426. case BL_MOB:
  1427. {
  1428. TBL_MOB *md = ((TBL_MOB*)bl);
  1429. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1430. clif_specialeffect(&md->bl,423,AREA);
  1431. else if(md->special_state.size==SZ_MEDIUM)
  1432. clif_specialeffect(&md->bl,421,AREA);
  1433. }
  1434. break;
  1435. case BL_PET:
  1436. if(vd->head_bottom) // needed to display pet equip properly
  1437. clif_pet_equip_area((TBL_PET*)bl);
  1438. break;
  1439. }
  1440. clif_ally_only = false;
  1441. }
  1442. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1443. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1444. /// Note: unit must not be self
  1445. void clif_move(struct unit_data *ud)
  1446. {
  1447. unsigned char buf[16];
  1448. struct view_data* vd;
  1449. struct block_list* bl = ud->bl;
  1450. struct status_change *sc = NULL;
  1451. vd = status_get_viewdata(bl);
  1452. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1453. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1454. /**
  1455. * Hide NPC from maya purple card.
  1456. **/
  1457. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1458. return;
  1459. if (ud->state.speed_changed) {
  1460. // Since we don't know how to update the speed of other objects,
  1461. // use the old walk packet to update the data.
  1462. ud->state.speed_changed = 0;
  1463. clif_move2(bl, vd, ud);
  1464. return;
  1465. }
  1466. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1467. clif_ally_only = true;
  1468. WBUFW(buf,0)=0x86;
  1469. WBUFL(buf,2)=bl->id;
  1470. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1471. WBUFL(buf,12)=gettick();
  1472. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1473. if (disguised(bl)) {
  1474. WBUFL(buf,2)=-bl->id;
  1475. clif_send(buf, packet_len(0x86), bl, SELF);
  1476. }
  1477. clif_ally_only = false;
  1478. }
  1479. /*==========================================
  1480. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1481. *------------------------------------------*/
  1482. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1483. {
  1484. struct map_session_data *sd = NULL;
  1485. //Remove player from map server
  1486. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1487. map_quit(sd);
  1488. return 0;
  1489. }
  1490. /*==========================================
  1491. *
  1492. *------------------------------------------*/
  1493. void clif_quitsave(int fd,struct map_session_data *sd) {
  1494. if (!battle_config.prevent_logout ||
  1495. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1496. map_quit(sd);
  1497. else if (sd->fd) {
  1498. //Disassociate session from player (session is deleted after this function was called)
  1499. //And set a timer to make him quit later.
  1500. session[sd->fd]->session_data = NULL;
  1501. sd->fd = 0;
  1502. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1503. }
  1504. }
  1505. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1506. /// 0091 <map name>.16B <x>.W <y>.W
  1507. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1508. {
  1509. int fd;
  1510. nullpo_retv(sd);
  1511. fd = sd->fd;
  1512. WFIFOHEAD(fd,packet_len(0x91));
  1513. WFIFOW(fd,0) = 0x91;
  1514. if(map[m].instance_id) { // Instance map check to send client source map name so we don't crash player
  1515. struct instance_data *im = &instance_data[map[m].instance_id];
  1516. int i;
  1517. if(!im) // This shouldn't happen but if it does give them the map we intended to give
  1518. mapindex_getmapname_ext(map[m].name, (char*)WFIFOP(fd,2));
  1519. for(i = 0; i < MAX_MAP_PER_INSTANCE; i++) // Loop to find the src map we want
  1520. if(im->map[i].m == m) {
  1521. mapindex_getmapname_ext(map[im->map[i].src_m].name, (char*)WFIFOP(fd,2));
  1522. break;
  1523. }
  1524. } else
  1525. mapindex_getmapname_ext(map[m].name, (char*)WFIFOP(fd,2));
  1526. WFIFOW(fd,18) = x;
  1527. WFIFOW(fd,20) = y;
  1528. WFIFOSET(fd,packet_len(0x91));
  1529. }
  1530. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1531. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1532. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1533. {
  1534. int fd;
  1535. nullpo_retv(sd);
  1536. fd = sd->fd;
  1537. WFIFOHEAD(fd,packet_len(0x92));
  1538. WFIFOW(fd,0) = 0x92;
  1539. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1540. WFIFOW(fd,18) = x;
  1541. WFIFOW(fd,20) = y;
  1542. WFIFOL(fd,22) = htonl(ip);
  1543. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1544. WFIFOSET(fd,packet_len(0x92));
  1545. }
  1546. void clif_blown(struct block_list *bl) //FIXME: This needs a better behaviour than just sending 2 position fixes
  1547. {
  1548. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1549. clif_fixpos(bl);
  1550. clif_slide(bl, bl->x, bl->y);
  1551. }
  1552. /// Visually moves(slides) a character to x,y. If the target cell
  1553. /// isn't walkable, the char doesn't move at all. If the char is
  1554. /// sitting it will stand up (ZC_STOPMOVE).
  1555. /// 0088 <id>.L <x>.W <y>.W
  1556. void clif_fixpos(struct block_list *bl)
  1557. {
  1558. unsigned char buf[10];
  1559. nullpo_retv(bl);
  1560. WBUFW(buf,0) = 0x88;
  1561. WBUFL(buf,2) = bl->id;
  1562. WBUFW(buf,6) = bl->x;
  1563. WBUFW(buf,8) = bl->y;
  1564. clif_send(buf, packet_len(0x88), bl, AREA);
  1565. if( disguised(bl) ) {
  1566. WBUFL(buf,2) = -bl->id;
  1567. clif_send(buf, packet_len(0x88), bl, SELF);
  1568. }
  1569. }
  1570. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1571. /// 00c4 <shop id>.L
  1572. void clif_npcbuysell(struct map_session_data* sd, int id)
  1573. {
  1574. int fd;
  1575. nullpo_retv(sd);
  1576. fd=sd->fd;
  1577. WFIFOHEAD(fd, packet_len(0xc4));
  1578. WFIFOW(fd,0)=0xc4;
  1579. WFIFOL(fd,2)=id;
  1580. WFIFOSET(fd,packet_len(0xc4));
  1581. }
  1582. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1583. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1584. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1585. {
  1586. int fd,i,c;
  1587. bool discount;
  1588. nullpo_retv(sd);
  1589. nullpo_retv(nd);
  1590. fd = sd->fd;
  1591. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1592. WFIFOW(fd,0) = 0xc6;
  1593. c = 0;
  1594. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1595. for( i = 0; i < nd->u.shop.count; i++ )
  1596. {
  1597. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1598. int val = nd->u.shop.shop_item[i].value;
  1599. if( id == NULL )
  1600. continue;
  1601. WFIFOL(fd, 4+c*11) = val;
  1602. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1603. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1604. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1605. c++;
  1606. }
  1607. WFIFOW(fd,2) = 4 + c*11;
  1608. WFIFOSET(fd,WFIFOW(fd,2));
  1609. }
  1610. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1611. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1612. void clif_selllist(struct map_session_data *sd)
  1613. {
  1614. int fd,i,c=0,val;
  1615. nullpo_retv(sd);
  1616. fd=sd->fd;
  1617. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1618. WFIFOW(fd,0)=0xc7;
  1619. for( i = 0; i < MAX_INVENTORY; i++ )
  1620. {
  1621. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1622. {
  1623. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1624. continue;
  1625. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1626. continue; // Cannot Sell Rental Items or Account Bounded Items
  1627. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1628. continue; // Don't allow sale of bound items
  1629. val=sd->inventory_data[i]->value_sell;
  1630. if( val < 0 )
  1631. continue;
  1632. WFIFOW(fd,4+c*10)=i+2;
  1633. WFIFOL(fd,6+c*10)=val;
  1634. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1635. c++;
  1636. }
  1637. }
  1638. WFIFOW(fd,2)=c*10+4;
  1639. WFIFOSET(fd,WFIFOW(fd,2));
  1640. }
  1641. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1642. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1643. /// Client behavior (dialog window):
  1644. /// - disable mouse targeting
  1645. /// - open the dialog window
  1646. /// - set npcid of dialog window (0 by default)
  1647. /// - if set to clear on next mes, clear contents
  1648. /// - append this text
  1649. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1650. {
  1651. int fd = sd->fd;
  1652. int slen = strlen(mes) + 9;
  1653. WFIFOHEAD(fd, slen);
  1654. WFIFOW(fd,0)=0xb4;
  1655. WFIFOW(fd,2)=slen;
  1656. WFIFOL(fd,4)=npcid;
  1657. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1658. WFIFOSET(fd,WFIFOW(fd,2));
  1659. }
  1660. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1661. /// 00b5 <npc id>.L
  1662. /// Client behavior (dialog window):
  1663. /// - disable mouse targeting
  1664. /// - open the dialog window
  1665. /// - add 'next' button
  1666. /// When 'next' is pressed:
  1667. /// - 00B9 <npcid of dialog window>.L
  1668. /// - set to clear on next mes
  1669. /// - remove 'next' button
  1670. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1671. {
  1672. int fd;
  1673. nullpo_retv(sd);
  1674. fd=sd->fd;
  1675. WFIFOHEAD(fd, packet_len(0xb5));
  1676. WFIFOW(fd,0)=0xb5;
  1677. WFIFOL(fd,2)=npcid;
  1678. WFIFOSET(fd,packet_len(0xb5));
  1679. }
  1680. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1681. /// 00b6 <npc id>.L
  1682. /// Client behavior:
  1683. /// - if dialog window is open:
  1684. /// - remove 'next' button
  1685. /// - add 'close' button
  1686. /// - else:
  1687. /// - enable mouse targeting
  1688. /// - close the dialog window
  1689. /// - close the menu window
  1690. /// When 'close' is pressed:
  1691. /// - enable mouse targeting
  1692. /// - close the dialog window
  1693. /// - close the menu window
  1694. /// - 0146 <npcid of dialog window>.L
  1695. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1696. {
  1697. int fd;
  1698. nullpo_retv(sd);
  1699. fd=sd->fd;
  1700. WFIFOHEAD(fd, packet_len(0xb6));
  1701. WFIFOW(fd,0)=0xb6;
  1702. WFIFOL(fd,2)=npcid;
  1703. WFIFOSET(fd,packet_len(0xb6));
  1704. }
  1705. /**
  1706. * Close script when player is idle
  1707. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1708. * @author [Ind/Hercules]
  1709. * @param sd : player pointer
  1710. * @param npcid : npc gid to close
  1711. */
  1712. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1713. {
  1714. struct s_packet_db* info;
  1715. int16 len;
  1716. int cmd = 0;
  1717. int fd;
  1718. nullpo_retv(sd);
  1719. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1720. if(!cmd) cmd = 0x8d6; //default
  1721. info = &packet_db[sd->packet_ver][cmd];
  1722. len = info->len;
  1723. fd = sd->fd;
  1724. WFIFOHEAD(fd, len);
  1725. WFIFOW(fd,0)=0x8d6;
  1726. WFIFOL(fd,info->pos[0])=npcid;
  1727. WFIFOSET(fd,len);
  1728. }
  1729. /*==========================================
  1730. *
  1731. *------------------------------------------*/
  1732. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1733. unsigned char *buf;
  1734. int fd = sd->fd;
  1735. sd->state.using_fake_npc = 1;
  1736. WFIFOHEAD(fd, packet_len(0x78));
  1737. buf = WFIFOP(fd,0);
  1738. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1739. WBUFW(buf,0)=0x78;
  1740. #if PACKETVER >= 20071106
  1741. WBUFB(buf,2) = 0; // object type
  1742. buf = WFIFOP(fd,1);
  1743. #endif
  1744. WBUFL(buf,2)=npcid;
  1745. WBUFW(buf,14)=111;
  1746. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1747. WBUFB(buf,49)=5;
  1748. WBUFB(buf,50)=5;
  1749. WFIFOSET(fd, packet_len(0x78));
  1750. }
  1751. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1752. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1753. /// Client behavior:
  1754. /// - disable mouse targeting
  1755. /// - close the menu window
  1756. /// - open the menu window
  1757. /// - add options to the menu (separated in the text by ":")
  1758. /// - set npcid of menu window
  1759. /// - if dialog window is open:
  1760. /// - remove 'next' button
  1761. /// When 'ok' is pressed:
  1762. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1763. /// - close the menu window
  1764. /// When 'cancel' is pressed:
  1765. /// - 00B8 <npcid of menu window>.L <-1>.B
  1766. /// - enable mouse targeting
  1767. /// - close a bunch of windows...
  1768. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1769. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1770. /// TODO investigate behavior of other windows [FlavioJS]
  1771. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1772. {
  1773. int fd = sd->fd;
  1774. int slen = strlen(mes) + 9;
  1775. struct block_list *bl = NULL;
  1776. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1777. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1778. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1779. clif_sendfakenpc(sd, npcid);
  1780. WFIFOHEAD(fd, slen);
  1781. WFIFOW(fd,0)=0xb7;
  1782. WFIFOW(fd,2)=slen;
  1783. WFIFOL(fd,4)=npcid;
  1784. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1785. WFIFOSET(fd,WFIFOW(fd,2));
  1786. }
  1787. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1788. /// 0142 <npc id>.L
  1789. /// Client behavior (inputnum window):
  1790. /// - if npcid exists in the client:
  1791. /// - open the inputnum window
  1792. /// - set npcid of inputnum window
  1793. /// When 'ok' is pressed:
  1794. /// - if inputnum window has text:
  1795. /// - if npcid exists in the client:
  1796. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1797. /// - close inputnum window
  1798. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1799. {
  1800. int fd;
  1801. struct block_list *bl = NULL;
  1802. nullpo_retv(sd);
  1803. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1804. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1805. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1806. clif_sendfakenpc(sd, npcid);
  1807. fd=sd->fd;
  1808. WFIFOHEAD(fd, packet_len(0x142));
  1809. WFIFOW(fd,0)=0x142;
  1810. WFIFOL(fd,2)=npcid;
  1811. WFIFOSET(fd,packet_len(0x142));
  1812. }
  1813. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1814. /// 01d4 <npc id>.L
  1815. /// Client behavior (inputstr window):
  1816. /// - if npcid is 0 or npcid exists in the client:
  1817. /// - open the inputstr window
  1818. /// - set npcid of inputstr window
  1819. /// When 'ok' is pressed:
  1820. /// - if inputstr window has text and isn't an insult(manner.txt):
  1821. /// - if npcid is 0 or npcid exists in the client:
  1822. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1823. /// - close inputstr window
  1824. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1825. {
  1826. int fd;
  1827. struct block_list *bl = NULL;
  1828. nullpo_retv(sd);
  1829. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1830. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1831. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1832. clif_sendfakenpc(sd, npcid);
  1833. fd=sd->fd;
  1834. WFIFOHEAD(fd, packet_len(0x1d4));
  1835. WFIFOW(fd,0)=0x1d4;
  1836. WFIFOL(fd,2)=npcid;
  1837. WFIFOSET(fd,packet_len(0x1d4));
  1838. }
  1839. /// Marks a position on client's minimap (ZC_COMPASS).
  1840. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1841. /// npc id:
  1842. /// is ignored in the client
  1843. /// type:
  1844. /// 0 = display mark for 15 seconds
  1845. /// 1 = display mark until dead or teleported
  1846. /// 2 = remove mark
  1847. /// color:
  1848. /// 0x00RRGGBB
  1849. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1850. {
  1851. int fd;
  1852. nullpo_retv(sd);
  1853. fd=sd->fd;
  1854. WFIFOHEAD(fd, packet_len(0x144));
  1855. WFIFOW(fd,0)=0x144;
  1856. WFIFOL(fd,2)=npc_id;
  1857. WFIFOL(fd,6)=type;
  1858. WFIFOL(fd,10)=x;
  1859. WFIFOL(fd,14)=y;
  1860. WFIFOB(fd,18)=id;
  1861. WFIFOL(fd,19)=color;
  1862. WFIFOSET(fd,packet_len(0x144));
  1863. }
  1864. /// Displays an illustration image.
  1865. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1866. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1867. /// type:
  1868. /// 0 = bottom left corner
  1869. /// 1 = bottom middle
  1870. /// 2 = bottom right corner
  1871. /// 3 = middle of screen, inside a movable window
  1872. /// 4 = middle of screen, movable with a close button, chrome-less
  1873. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1874. {
  1875. int fd;
  1876. nullpo_retv(sd);
  1877. fd=sd->fd;
  1878. WFIFOHEAD(fd, packet_len(0x1b3));
  1879. WFIFOW(fd,0)=0x1b3;
  1880. strncpy((char*)WFIFOP(fd,2),image,64);
  1881. WFIFOB(fd,66)=type;
  1882. WFIFOSET(fd,packet_len(0x1b3));
  1883. }
  1884. /*==========================================
  1885. * Fills in card data from the given item and into the buffer. [Skotlex]
  1886. *------------------------------------------*/
  1887. static void clif_addcards(unsigned char* buf, struct item* item)
  1888. {
  1889. int i=0,j;
  1890. if( item == NULL ) { //Blank data
  1891. WBUFW(buf,0) = 0;
  1892. WBUFW(buf,2) = 0;
  1893. WBUFW(buf,4) = 0;
  1894. WBUFW(buf,6) = 0;
  1895. return;
  1896. }
  1897. if( item->card[0] == CARD0_PET ) { //pet eggs
  1898. WBUFW(buf,0) = 0;
  1899. WBUFW(buf,2) = 0;
  1900. WBUFW(buf,4) = 0;
  1901. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1902. return;
  1903. }
  1904. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1905. WBUFW(buf,0) = item->card[0];
  1906. WBUFW(buf,2) = item->card[1];
  1907. WBUFW(buf,4) = item->card[2];
  1908. WBUFW(buf,6) = item->card[3];
  1909. return;
  1910. }
  1911. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1912. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1913. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1914. //Normal items.
  1915. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1916. WBUFW(buf,0) = j;
  1917. else
  1918. WBUFW(buf,0) = item->card[i];
  1919. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1920. WBUFW(buf,2) = j;
  1921. else
  1922. WBUFW(buf,2) = item->card[i];
  1923. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1924. WBUFW(buf,4) = j;
  1925. else
  1926. WBUFW(buf,4) = item->card[i];
  1927. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1928. WBUFW(buf,6) = j;
  1929. else
  1930. WBUFW(buf,6) = item->card[i];
  1931. }
  1932. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1933. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  1934. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  1935. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  1936. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  1937. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1938. {
  1939. int fd, header, offs=0;
  1940. #if PACKETVER < 20061218
  1941. header = 0xa0;
  1942. #elif PACKETVER < 20071002
  1943. header = 0x29a;
  1944. #elif PACKETVER < 20120925
  1945. header = 0x2d4;
  1946. #else
  1947. header = 0x990;
  1948. #endif
  1949. nullpo_retv(sd);
  1950. fd = sd->fd;
  1951. if( !session_isActive(fd) ) //Sasuke-
  1952. return;
  1953. WFIFOHEAD(fd,packet_len(header));
  1954. if( fail )
  1955. {
  1956. WFIFOW(fd,offs+0)=header;
  1957. WFIFOW(fd,offs+2)=n+2;
  1958. WFIFOW(fd,offs+4)=amount;
  1959. WFIFOW(fd,offs+6)=0;
  1960. WFIFOB(fd,offs+8)=0;
  1961. WFIFOB(fd,offs+9)=0;
  1962. WFIFOB(fd,offs+10)=0;
  1963. WFIFOW(fd,offs+11)=0;
  1964. WFIFOW(fd,offs+13)=0;
  1965. WFIFOW(fd,offs+15)=0;
  1966. WFIFOW(fd,offs+17)=0;
  1967. #if PACKETVER < 20120925
  1968. WFIFOW(fd,offs+19)=0;
  1969. #else
  1970. WFIFOL(fd,offs+19)=0;
  1971. offs += 2;
  1972. #endif
  1973. WFIFOB(fd,offs+21)=0;
  1974. WFIFOB(fd,offs+22)=fail;
  1975. #if PACKETVER >= 20061218
  1976. WFIFOL(fd,offs+23)=0;
  1977. #endif
  1978. #if PACKETVER >= 20071002
  1979. WFIFOW(fd,offs+27)=0; // HireExpireDate
  1980. #endif
  1981. }
  1982. else
  1983. {
  1984. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1985. return;
  1986. WFIFOW(fd,offs+0)=header;
  1987. WFIFOW(fd,offs+2)=n+2;
  1988. WFIFOW(fd,offs+4)=amount;
  1989. if (sd->inventory_data[n]->view_id > 0)
  1990. WFIFOW(fd,offs+6)=sd->inventory_data[n]->view_id;
  1991. else
  1992. WFIFOW(fd,offs+6)=sd->status.inventory[n].nameid;
  1993. WFIFOB(fd,offs+8)=sd->status.inventory[n].identify;
  1994. WFIFOB(fd,offs+9)=sd->status.inventory[n].attribute;
  1995. WFIFOB(fd,offs+10)=sd->status.inventory[n].refine;
  1996. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  1997. #if PACKETVER < 20120925
  1998. WFIFOW(fd,offs+19)=pc_equippoint(sd,n);
  1999. #else
  2000. WFIFOL(fd,offs+19)=pc_equippoint(sd,n);
  2001. offs += 2;
  2002. #endif
  2003. WFIFOB(fd,offs+21)=itemtype(sd->inventory_data[n]->nameid);
  2004. WFIFOB(fd,offs+22)=fail;
  2005. #if PACKETVER >= 20061218
  2006. WFIFOL(fd,offs+23)=sd->status.inventory[n].expire_time;
  2007. #endif
  2008. #if PACKETVER >= 20071002
  2009. WFIFOW(fd,offs+27)=sd->status.inventory[n].bound ? 2 : 0;
  2010. #endif
  2011. }
  2012. WFIFOSET(fd,packet_len(header));
  2013. }
  2014. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2015. /// 00af <index>.W <amount>.W
  2016. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2017. {
  2018. int fd;
  2019. nullpo_retv(sd);
  2020. fd=sd->fd;
  2021. WFIFOHEAD(fd, packet_len(0xaf));
  2022. WFIFOW(fd,0)=0xaf;
  2023. WFIFOW(fd,2)=n+2;
  2024. WFIFOW(fd,4)=amount;
  2025. WFIFOSET(fd,packet_len(0xaf));
  2026. }
  2027. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2028. /// 07fa <delete type>.W <index>.W <amount>.W
  2029. /// delete type:
  2030. /// 0 = Normal
  2031. /// 1 = Item used for a skill
  2032. /// 2 = Refine failed
  2033. /// 3 = Material changed
  2034. /// 4 = Moved to storage
  2035. /// 5 = Moved to cart
  2036. /// 6 = Item sold
  2037. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2038. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2039. {
  2040. #if PACKETVER < 20091117
  2041. clif_dropitem(sd,n,amount);
  2042. #else
  2043. int fd;
  2044. nullpo_retv(sd);
  2045. fd=sd->fd;
  2046. WFIFOHEAD(fd, packet_len(0x7fa));
  2047. WFIFOW(fd,0)=0x7fa;
  2048. WFIFOW(fd,2)=reason;
  2049. WFIFOW(fd,4)=n+2;
  2050. WFIFOW(fd,6)=amount;
  2051. WFIFOSET(fd,packet_len(0x7fa));
  2052. #endif
  2053. }
  2054. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2055. char normal = (equip < 0);
  2056. WBUFW(buf,n)=idx; //index
  2057. WBUFW(buf,n+2)= (id->view_id > 0)?id->view_id:i->nameid;
  2058. WBUFB(buf,n+4)=itemtype(id->nameid);
  2059. if(!normal){ //equip 31B
  2060. WBUFL(buf,n+5)= equip; //location
  2061. WBUFL(buf,n+9)= i->equip; //wear state
  2062. WBUFB(buf,n+13)= i->refine; //refine lvl
  2063. clif_addcards(WBUFP(buf, n+14), i); //EQUIPSLOTINFO 8B
  2064. WBUFL(buf,n+22) = i->expire_time;
  2065. WBUFW(buf,n+26)= 0; //bindOnEquipType
  2066. WBUFW(buf,n+28)= (id->equip&EQP_VISIBLE)?id->look:0;
  2067. //V5_ITEM_flag
  2068. WBUFB(buf,n+30)=i->identify; //0x1 IsIdentified
  2069. WBUFB(buf,n+30)|=(i->attribute)?0x2:0; //0x2 IsDamaged
  2070. WBUFB(buf,n+30)|= (i->favorite)?0x4:0; //0x4 PlaceETCTab
  2071. }
  2072. else { //normal 24B
  2073. WBUFW(buf,n+5)=i->amount;
  2074. WBUFL(buf,n+7)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2075. clif_addcards(WBUFP(buf, n+11), i); //EQUIPSLOTINFO 8B
  2076. WBUFL(buf,n+19) = i->expire_time;
  2077. //V5_ITEM_flag
  2078. WBUFB(buf,n+23)=i->identify; //0x1 IsIdentified
  2079. WBUFB(buf,n+23)|= (i->favorite)?0x2:0; //0x4,0x2 PlaceETCTab
  2080. }
  2081. }
  2082. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2083. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2084. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2085. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2086. #if PACKETVER >= 20120925
  2087. clif_item_sub_v5(buf, n, idx, i, id, equip);
  2088. #else
  2089. WBUFW(buf,n)=idx; //index
  2090. WBUFW(buf,n+2)=(id->view_id > 0)?id->view_id:i->nameid; //itid
  2091. WBUFB(buf,n+4)=itemtype(id->nameid);
  2092. WBUFB(buf,n+5)=i->identify;
  2093. if (equip >= 0) { //Equippable item 28.B
  2094. WBUFW(buf,n+6)=equip;
  2095. WBUFW(buf,n+8)=i->equip;
  2096. WBUFB(buf,n+10)=i->attribute;
  2097. WBUFB(buf,n+11)=i->refine;
  2098. clif_addcards(WBUFP(buf, n+12), i); //8B
  2099. #if PACKETVER >= 20071002
  2100. WBUFL(buf,n+20)=i->expire_time;
  2101. WBUFW(buf,n+24)=i->bound ? 2 : 0;
  2102. #endif
  2103. #if PACKETVER >= 20100629
  2104. WBUFW(buf,n+26)= (id->equip&EQP_VISIBLE)?id->look:0;
  2105. #endif
  2106. } else { //Stackable item. 22.B
  2107. WBUFW(buf,n+6)=i->amount;
  2108. WBUFW(buf,n+8)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0;
  2109. clif_addcards(WBUFP(buf, n+10), i); //8B
  2110. #if PACKETVER >= 20071002
  2111. WBUFL(buf,n+18)=i->expire_time;
  2112. #endif
  2113. }
  2114. #endif
  2115. }
  2116. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2117. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2118. void clif_inventorylist(struct map_session_data *sd) {
  2119. int i,n,ne,arrow=-1;
  2120. unsigned char *buf;
  2121. unsigned char *bufe;
  2122. #if PACKETVER < 5
  2123. const int s = 10; //Entry size
  2124. #elif PACKETVER < 20080102
  2125. const int s = 18;
  2126. #elif PACKETVER < 20120925
  2127. const int s = 22;
  2128. #else
  2129. const int s = 24;
  2130. #endif
  2131. #if PACKETVER < 20071002
  2132. const int se = 20;
  2133. #elif PACKETVER < 20100629
  2134. const int se = 26;
  2135. #elif PACKETVER < 20120925
  2136. const int se = 28;
  2137. #else
  2138. const int se = 31;
  2139. #endif
  2140. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2141. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2142. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2143. {
  2144. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2145. continue;
  2146. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2147. { //Non-stackable (Equippable)
  2148. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2149. ne++;
  2150. }
  2151. else { //Stackable.
  2152. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2153. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2154. arrow=i;
  2155. n++;
  2156. }
  2157. }
  2158. if( n )
  2159. {
  2160. #if PACKETVER < 5
  2161. WBUFW(buf,0)=0xa3;
  2162. #elif PACKETVER < 20080102
  2163. WBUFW(buf,0)=0x1ee;
  2164. #elif PACKETVER < 20120925
  2165. WBUFW(buf,0)=0x2e8;
  2166. #else
  2167. WBUFW(buf,0)=0x991;
  2168. #endif
  2169. WBUFW(buf,2)=4+n*s;
  2170. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2171. }
  2172. if( arrow >= 0 )
  2173. clif_arrowequip(sd,arrow);
  2174. if( ne ) {
  2175. #if PACKETVER < 20071002
  2176. WBUFW(bufe,0)=0xa4;
  2177. #elif PACKETVER < 20120925
  2178. WBUFW(bufe,0)=0x2d0;
  2179. #else
  2180. WBUFW(bufe,0)=0x992;
  2181. #endif
  2182. WBUFW(bufe,2)=4+ne*se;
  2183. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2184. }
  2185. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2186. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2187. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2188. continue;
  2189. if ( sd->status.inventory[i].favorite )
  2190. clif_favorite_item(sd, i);
  2191. }
  2192. #endif
  2193. if( buf ) aFree(buf);
  2194. if( bufe ) aFree(bufe);
  2195. }
  2196. //Required when items break/get-repaired. Only sends equippable item list.
  2197. void clif_equiplist(struct map_session_data *sd)
  2198. {
  2199. int i,n,fd = sd->fd;
  2200. unsigned char *buf;
  2201. #if PACKETVER < 20071002
  2202. const int cmd = 20;
  2203. #elif PACKETVER < 20100629
  2204. const int cmd = 26;
  2205. #elif PACKETVER < 20120925
  2206. const int cmd = 28;
  2207. #else
  2208. const int cmd = 31;
  2209. #endif
  2210. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2211. buf = WFIFOP(fd,0);
  2212. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2213. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2214. continue;
  2215. if(itemdb_isstackable2(sd->inventory_data[i]))
  2216. continue;
  2217. //Equippable
  2218. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2219. n++;
  2220. }
  2221. if (n) {
  2222. #if PACKETVER < 20071002
  2223. WBUFW(buf,0)=0xa4;
  2224. #elif PACKETVER < 20120925
  2225. WBUFW(buf,0)=0x2d0;
  2226. #else
  2227. WBUFW(buf,0)=0x992;
  2228. #endif
  2229. WBUFW(buf,2)=4+n*cmd;
  2230. WFIFOSET(fd,WFIFOW(fd,2));
  2231. }
  2232. }
  2233. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2234. {
  2235. static const int client_buf = 0x5000; // Max buffer to send
  2236. struct item_data *id;
  2237. int i,n,ne,nn;
  2238. unsigned char *buf;
  2239. unsigned char *bufe;
  2240. #if PACKETVER < 5
  2241. const int s = 10; //Entry size.normal item
  2242. const int sidx=4; //start itemlist idx
  2243. const int cmd = 0xa5;
  2244. #elif PACKETVER < 20080102
  2245. const int s = 18;
  2246. const int sidx=4;
  2247. const int cmd = 0x1f0;
  2248. #elif PACKETVER < 20120925
  2249. const int s = 22;
  2250. const int sidx=4;
  2251. const int cmd = 0x2ea;
  2252. #else
  2253. const int s = 24;
  2254. const int sidx = 4+24;
  2255. const int cmd = 0x995;
  2256. #endif
  2257. #if PACKETVER < 20071002
  2258. const int se = 20; //entry size equip
  2259. const int sidxe = 4; //start itemlist idx
  2260. const int cmde = 0xa6;
  2261. #elif PACKETVER < 20100629
  2262. const int se = 26;
  2263. const int sidxe = 4;
  2264. const int cmde = 0xa6;
  2265. #elif PACKETVER < 20120925
  2266. const int se = 28;
  2267. const int sidxe = 4;
  2268. const int cmde = 0x2d1;
  2269. #else
  2270. const int se = 31;
  2271. const int sidxe = 4+24;
  2272. const int cmde = 0x996;
  2273. #endif
  2274. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2275. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2276. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2277. {
  2278. if( items[i].nameid <= 0 )
  2279. continue;
  2280. id = itemdb_search(items[i].nameid);
  2281. if( !itemdb_isstackable2(id) ) { //Equippable
  2282. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2283. ne++;
  2284. }
  2285. else { //Stackable
  2286. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2287. n++;
  2288. }
  2289. }
  2290. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2291. {
  2292. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2293. WFIFOHEAD(sd->fd,sidx+nn*s);
  2294. WFIFOW(sd->fd,0)=cmd;
  2295. WFIFOW(sd->fd,2)=sidx+nn*s;
  2296. #if PACKETVER >= 20120925
  2297. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2298. #endif
  2299. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2300. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2301. }
  2302. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2303. {
  2304. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2305. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2306. WFIFOW(sd->fd,0)=cmde;
  2307. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2308. #if PACKETVER >= 20120925
  2309. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2310. #endif
  2311. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2312. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2313. }
  2314. if( buf ) aFree(buf);
  2315. if( bufe ) aFree(bufe);
  2316. }
  2317. void clif_cartlist(struct map_session_data *sd)
  2318. {
  2319. struct item_data *id;
  2320. int i,n,ne;
  2321. unsigned char *buf;
  2322. unsigned char *bufe;
  2323. #if PACKETVER < 5
  2324. const int s = 10; //Entry size.
  2325. #elif PACKETVER < 20080102
  2326. const int s = 18;
  2327. #elif PACKETVER < 20120925
  2328. const int s = 22;
  2329. #else
  2330. const int s = 24;
  2331. #endif
  2332. #if PACKETVER < 20071002
  2333. const int cmd = 20;
  2334. #elif PACKETVER < 20100629
  2335. const int cmd = 26;
  2336. #elif PACKETVER < 20120925
  2337. const int cmd = 28;
  2338. #else
  2339. const int cmd = 31;
  2340. #endif
  2341. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2342. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2343. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2344. {
  2345. if( sd->status.cart[i].nameid <= 0 )
  2346. continue;
  2347. id = itemdb_search(sd->status.cart[i].nameid);
  2348. if( !itemdb_isstackable2(id) ) { //Equippable
  2349. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2350. ne++;
  2351. }
  2352. else { //Stackable
  2353. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2354. n++;
  2355. }
  2356. }
  2357. if( n )
  2358. {
  2359. #if PACKETVER < 5
  2360. WBUFW(buf,0)=0x123;
  2361. #elif PACKETVER < 20080102
  2362. WBUFW(buf,0)=0x1ef;
  2363. #elif PACKETVER < 20120925
  2364. WBUFW(buf,0)=0x2e9;
  2365. #else
  2366. WBUFW(buf,0)=0x993;
  2367. #endif
  2368. WBUFW(buf,2)=4+n*s;
  2369. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2370. }
  2371. if( ne )
  2372. {
  2373. #if PACKETVER < 20071002
  2374. WBUFW(bufe,0)=0x122;
  2375. #elif PACKETVER < 20120925
  2376. WBUFW(bufe,0)=0x2d2;
  2377. #else
  2378. WBUFW(bufe,0)=0x994;
  2379. #endif
  2380. WBUFW(bufe,2)=4+ne*cmd;
  2381. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2382. }
  2383. if( buf ) aFree(buf);
  2384. if( bufe ) aFree(bufe);
  2385. }
  2386. /// Removes cart (ZC_CARTOFF).
  2387. /// 012b
  2388. /// Client behaviour:
  2389. /// Closes the cart storage and removes all it's items from memory.
  2390. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2391. void clif_clearcart(int fd)
  2392. {
  2393. WFIFOHEAD(fd, packet_len(0x12b));
  2394. WFIFOW(fd,0) = 0x12b;
  2395. WFIFOSET(fd, packet_len(0x12b));
  2396. }
  2397. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2398. /// 01eb <account id>.L <x>.W <y>.W
  2399. void clif_guild_xy(struct map_session_data *sd)
  2400. {
  2401. unsigned char buf[10];
  2402. nullpo_retv(sd);
  2403. WBUFW(buf,0)=0x1eb;
  2404. WBUFL(buf,2)=sd->status.account_id;
  2405. WBUFW(buf,6)=sd->bl.x;
  2406. WBUFW(buf,8)=sd->bl.y;
  2407. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2408. }
  2409. /*==========================================
  2410. * Sends x/y dot to a single fd. [Skotlex]
  2411. *------------------------------------------*/
  2412. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2413. {
  2414. if( sd->bg_id )
  2415. return;
  2416. WFIFOHEAD(fd,packet_len(0x1eb));
  2417. WFIFOW(fd,0)=0x1eb;
  2418. WFIFOL(fd,2)=sd->status.account_id;
  2419. WFIFOW(fd,6)=sd->bl.x;
  2420. WFIFOW(fd,8)=sd->bl.y;
  2421. WFIFOSET(fd,packet_len(0x1eb));
  2422. }
  2423. // Guild XY locators [Valaris]
  2424. void clif_guild_xy_remove(struct map_session_data *sd)
  2425. {
  2426. unsigned char buf[10];
  2427. nullpo_retv(sd);
  2428. WBUFW(buf,0)=0x1eb;
  2429. WBUFL(buf,2)=sd->status.account_id;
  2430. WBUFW(buf,6)=-1;
  2431. WBUFW(buf,8)=-1;
  2432. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2433. }
  2434. /*==========================================
  2435. *
  2436. *------------------------------------------*/
  2437. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2438. {
  2439. struct map_session_data *sd, *tsd;
  2440. #if PACKETVER < 20100126
  2441. const int cmd = 0x106;
  2442. #else
  2443. const int cmd = 0x80e;
  2444. #endif
  2445. sd = va_arg(ap, struct map_session_data *);
  2446. tsd = (TBL_PC *)bl;
  2447. nullpo_ret(sd);
  2448. nullpo_ret(tsd);
  2449. if( !tsd->fd || tsd == sd )
  2450. return 0;
  2451. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2452. return 0;
  2453. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2454. WFIFOW(tsd->fd,0) = cmd;
  2455. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2456. #if PACKETVER < 20100126
  2457. if( sd->battle_status.max_hp > INT16_MAX )
  2458. { //To correctly display the %hp bar. [Skotlex]
  2459. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2460. WFIFOW(tsd->fd,8) = 100;
  2461. } else {
  2462. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2463. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2464. }
  2465. #else
  2466. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2467. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2468. #endif
  2469. WFIFOSET(tsd->fd,packet_len(cmd));
  2470. return 0;
  2471. }
  2472. /*==========================================
  2473. * Server tells all players that are allowed to view HP bars
  2474. * and are nearby 'sd' that 'sd' hp bar was updated.
  2475. *------------------------------------------*/
  2476. static int clif_hpmeter(struct map_session_data *sd)
  2477. {
  2478. nullpo_ret(sd);
  2479. map_foreachinarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2480. return 0;
  2481. }
  2482. /// Notifies client of a character parameter change.
  2483. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2484. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2485. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2486. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2487. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2488. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2489. /// TODO: Extract individual packets.
  2490. /// FIXME: Packet lengths from packet_len(cmd)
  2491. void clif_updatestatus(struct map_session_data *sd,int type)
  2492. {
  2493. int fd,len=8;
  2494. nullpo_retv(sd);
  2495. fd=sd->fd;
  2496. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2497. return;
  2498. WFIFOHEAD(fd, 14);
  2499. WFIFOW(fd,0)=0xb0;
  2500. WFIFOW(fd,2)=type;
  2501. switch(type){
  2502. // 00b0
  2503. case SP_WEIGHT:
  2504. pc_updateweightstatus(sd);
  2505. WFIFOHEAD(fd,14);
  2506. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2507. WFIFOW(fd,2)=type;
  2508. WFIFOL(fd,4)=sd->weight;
  2509. break;
  2510. case SP_MAXWEIGHT:
  2511. WFIFOL(fd,4)=sd->max_weight;
  2512. break;
  2513. case SP_SPEED:
  2514. WFIFOL(fd,4)=sd->battle_status.speed;
  2515. break;
  2516. case SP_BASELEVEL:
  2517. WFIFOL(fd,4)=sd->status.base_level;
  2518. break;
  2519. case SP_JOBLEVEL:
  2520. WFIFOL(fd,4)=sd->status.job_level;
  2521. break;
  2522. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2523. WFIFOL(fd,4)=sd->status.karma;
  2524. break;
  2525. case SP_MANNER:
  2526. WFIFOL(fd,4)=sd->status.manner;
  2527. break;
  2528. case SP_STATUSPOINT:
  2529. WFIFOL(fd,4)=sd->status.status_point;
  2530. break;
  2531. case SP_SKILLPOINT:
  2532. WFIFOL(fd,4)=sd->status.skill_point;
  2533. break;
  2534. case SP_HIT:
  2535. WFIFOL(fd,4)=sd->battle_status.hit;
  2536. break;
  2537. case SP_FLEE1:
  2538. WFIFOL(fd,4)=sd->battle_status.flee;
  2539. break;
  2540. case SP_FLEE2:
  2541. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2542. break;
  2543. case SP_MAXHP:
  2544. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2545. break;
  2546. case SP_MAXSP:
  2547. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2548. break;
  2549. case SP_HP:
  2550. WFIFOL(fd,4)=sd->battle_status.hp;
  2551. // TODO: Won't these overwrite the current packet?
  2552. if( map[sd->bl.m].hpmeter_visible )
  2553. clif_hpmeter(sd);
  2554. if( !battle_config.party_hp_mode && sd->status.party_id )
  2555. clif_party_hp(sd);
  2556. if( sd->bg_id )
  2557. clif_bg_hp(sd);
  2558. break;
  2559. case SP_SP:
  2560. WFIFOL(fd,4)=sd->battle_status.sp;
  2561. break;
  2562. case SP_ASPD:
  2563. WFIFOL(fd,4)=sd->battle_status.amotion;
  2564. break;
  2565. case SP_ATK1:
  2566. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2567. break;
  2568. case SP_DEF1:
  2569. WFIFOL(fd,4)=pc_leftside_def(sd);
  2570. break;
  2571. case SP_MDEF1:
  2572. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2573. break;
  2574. case SP_ATK2:
  2575. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2576. break;
  2577. case SP_DEF2:
  2578. WFIFOL(fd,4)=pc_rightside_def(sd);
  2579. break;
  2580. case SP_MDEF2: {
  2581. //negative check (in case you have something like Berserk active)
  2582. int mdef2 = pc_rightside_mdef(sd);
  2583. WFIFOL(fd,4)=
  2584. #ifndef RENEWAL
  2585. ( mdef2 < 0 ) ? 0 :
  2586. #endif
  2587. mdef2;
  2588. }
  2589. break;
  2590. case SP_CRITICAL:
  2591. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2592. break;
  2593. case SP_MATK1:
  2594. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2595. break;
  2596. case SP_MATK2:
  2597. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2598. break;
  2599. case SP_ZENY:
  2600. WFIFOW(fd,0)=0xb1;
  2601. WFIFOL(fd,4)=sd->status.zeny;
  2602. break;
  2603. case SP_BASEEXP:
  2604. WFIFOW(fd,0)=0xb1;
  2605. WFIFOL(fd,4)=sd->status.base_exp;
  2606. break;
  2607. case SP_JOBEXP:
  2608. WFIFOW(fd,0)=0xb1;
  2609. WFIFOL(fd,4)=sd->status.job_exp;
  2610. break;
  2611. case SP_NEXTBASEEXP:
  2612. WFIFOW(fd,0)=0xb1;
  2613. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2614. break;
  2615. case SP_NEXTJOBEXP:
  2616. WFIFOW(fd,0)=0xb1;
  2617. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2618. break;
  2619. /**
  2620. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2621. **/
  2622. case SP_USTR:
  2623. case SP_UAGI:
  2624. case SP_UVIT:
  2625. case SP_UINT:
  2626. case SP_UDEX:
  2627. case SP_ULUK:
  2628. WFIFOW(fd,0)=0xbe;
  2629. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2630. len=5;
  2631. break;
  2632. /**
  2633. * Tells the client how far it is allowed to attack (weapon range)
  2634. **/
  2635. case SP_ATTACKRANGE:
  2636. WFIFOW(fd,0)=0x13a;
  2637. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2638. len=4;
  2639. break;
  2640. case SP_STR:
  2641. WFIFOW(fd,0)=0x141;
  2642. WFIFOL(fd,2)=type;
  2643. WFIFOL(fd,6)=sd->status.str;
  2644. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2645. len=14;
  2646. break;
  2647. case SP_AGI:
  2648. WFIFOW(fd,0)=0x141;
  2649. WFIFOL(fd,2)=type;
  2650. WFIFOL(fd,6)=sd->status.agi;
  2651. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2652. len=14;
  2653. break;
  2654. case SP_VIT:
  2655. WFIFOW(fd,0)=0x141;
  2656. WFIFOL(fd,2)=type;
  2657. WFIFOL(fd,6)=sd->status.vit;
  2658. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2659. len=14;
  2660. break;
  2661. case SP_INT:
  2662. WFIFOW(fd,0)=0x141;
  2663. WFIFOL(fd,2)=type;
  2664. WFIFOL(fd,6)=sd->status.int_;
  2665. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2666. len=14;
  2667. break;
  2668. case SP_DEX:
  2669. WFIFOW(fd,0)=0x141;
  2670. WFIFOL(fd,2)=type;
  2671. WFIFOL(fd,6)=sd->status.dex;
  2672. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2673. len=14;
  2674. break;
  2675. case SP_LUK:
  2676. WFIFOW(fd,0)=0x141;
  2677. WFIFOL(fd,2)=type;
  2678. WFIFOL(fd,6)=sd->status.luk;
  2679. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2680. len=14;
  2681. break;
  2682. case SP_CARTINFO:
  2683. WFIFOW(fd,0)=0x121;
  2684. WFIFOW(fd,2)=sd->cart_num;
  2685. WFIFOW(fd,4)=MAX_CART;
  2686. WFIFOL(fd,6)=sd->cart_weight;
  2687. WFIFOL(fd,10)=sd->cart_weight_max;
  2688. len=14;
  2689. break;
  2690. default:
  2691. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2692. return;
  2693. }
  2694. WFIFOSET(fd,len);
  2695. }
  2696. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2697. /// 01ab <account id>.L <var id>.W <value>.L
  2698. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2699. {
  2700. unsigned char buf[12];
  2701. nullpo_retv(sd);
  2702. WBUFW(buf,0)=0x1ab;
  2703. WBUFL(buf,2)=sd->bl.id;
  2704. WBUFW(buf,6)=type;
  2705. switch(type)
  2706. {
  2707. case SP_MANNER:
  2708. WBUFL(buf,8)=val;
  2709. break;
  2710. default:
  2711. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2712. return;
  2713. }
  2714. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2715. }
  2716. /// Updates sprite/style properties of an object.
  2717. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2718. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2719. void clif_changelook(struct block_list *bl,int type,int val)
  2720. {
  2721. unsigned char buf[16];
  2722. struct map_session_data* sd;
  2723. struct status_change* sc;
  2724. struct view_data* vd;
  2725. enum send_target target = AREA;
  2726. nullpo_retv(bl);
  2727. sd = BL_CAST(BL_PC, bl);
  2728. sc = status_get_sc(bl);
  2729. vd = status_get_viewdata(bl);
  2730. //nullpo_ret(vd);
  2731. if( vd ) //temp hack to let Warp Portal change appearance
  2732. switch(type)
  2733. {
  2734. case LOOK_WEAPON:
  2735. if (sd)
  2736. {
  2737. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2738. val = vd->weapon;
  2739. }
  2740. else vd->weapon = val;
  2741. break;
  2742. case LOOK_SHIELD:
  2743. if (sd)
  2744. {
  2745. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2746. val = vd->shield;
  2747. }
  2748. else vd->shield = val;
  2749. break;
  2750. case LOOK_BASE:
  2751. vd->class_ = val;
  2752. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER || vd->class_ == JOB_HANBOK || vd->class_ == JOB_OKTOBERFEST)
  2753. vd->weapon = vd->shield = 0;
  2754. if (vd->cloth_color && (
  2755. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2756. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2757. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2758. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette) ||
  2759. (vd->class_ == JOB_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2760. ))
  2761. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2762. break;
  2763. case LOOK_HAIR:
  2764. vd->hair_style = val;
  2765. break;
  2766. case LOOK_HEAD_BOTTOM:
  2767. vd->head_bottom = val;
  2768. break;
  2769. case LOOK_HEAD_TOP:
  2770. vd->head_top = val;
  2771. break;
  2772. case LOOK_HEAD_MID:
  2773. vd->head_mid = val;
  2774. break;
  2775. case LOOK_HAIR_COLOR:
  2776. vd->hair_color = val;
  2777. break;
  2778. case LOOK_CLOTHES_COLOR:
  2779. if (val && (
  2780. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2781. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2782. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette) ||
  2783. (vd->class_ == JOB_HANBOK && battle_config.hanbok_ignorepalette) ||
  2784. (vd->class_ == JOB_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2785. ))
  2786. val = 0;
  2787. vd->cloth_color = val;
  2788. break;
  2789. case LOOK_SHOES:
  2790. #if PACKETVER > 3
  2791. if (sd) {
  2792. int n;
  2793. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2794. if(sd->inventory_data[n]->view_id > 0)
  2795. val = sd->inventory_data[n]->view_id;
  2796. else
  2797. val = sd->status.inventory[n].nameid;
  2798. } else
  2799. val = 0;
  2800. }
  2801. #endif
  2802. //Shoes? No packet uses this....
  2803. break;
  2804. case LOOK_BODY:
  2805. // unknown purpose
  2806. break;
  2807. case LOOK_ROBE:
  2808. #if PACKETVER < 20110111
  2809. return;
  2810. #else
  2811. vd->robe = val;
  2812. #endif
  2813. break;
  2814. }
  2815. // prevent leaking the presence of GM-hidden objects
  2816. if( sc && sc->option&OPTION_INVISIBLE )
  2817. target = SELF;
  2818. #if PACKETVER < 4
  2819. WBUFW(buf,0)=0xc3;
  2820. WBUFL(buf,2)=bl->id;
  2821. WBUFB(buf,6)=type;
  2822. WBUFB(buf,7)=val;
  2823. clif_send(buf,packet_len(0xc3),bl,target);
  2824. #else
  2825. WBUFW(buf,0)=0x1d7;
  2826. WBUFL(buf,2)=bl->id;
  2827. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2828. WBUFB(buf,6)=LOOK_WEAPON;
  2829. WBUFW(buf,7)=vd->weapon;
  2830. WBUFW(buf,9)=vd->shield;
  2831. } else {
  2832. WBUFB(buf,6)=type;
  2833. WBUFL(buf,7)=val;
  2834. }
  2835. clif_send(buf,packet_len(0x1d7),bl,target);
  2836. #endif
  2837. }
  2838. //Sends a change-base-look packet required for traps as they are triggered.
  2839. void clif_changetraplook(struct block_list *bl,int val)
  2840. {
  2841. unsigned char buf[32];
  2842. #if PACKETVER < 4
  2843. WBUFW(buf,0)=0xc3;
  2844. WBUFL(buf,2)=bl->id;
  2845. WBUFB(buf,6)=LOOK_BASE;
  2846. WBUFB(buf,7)=val;
  2847. clif_send(buf,packet_len(0xc3),bl,AREA);
  2848. #else
  2849. WBUFW(buf,0)=0x1d7;
  2850. WBUFL(buf,2)=bl->id;
  2851. WBUFB(buf,6)=LOOK_BASE;
  2852. WBUFW(buf,7)=val;
  2853. WBUFW(buf,9)=0;
  2854. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2855. #endif
  2856. }
  2857. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2858. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2859. {
  2860. unsigned char buf[32];
  2861. #if PACKETVER < 4
  2862. WBUFW(buf,0)=0xc3;
  2863. WBUFL(buf,2)=id;
  2864. WBUFB(buf,6)=type;
  2865. WBUFB(buf,7)=val;
  2866. clif_send(buf,packet_len(0xc3),bl,target);
  2867. #else
  2868. WBUFW(buf,0)=0x1d7;
  2869. WBUFL(buf,2)=id;
  2870. WBUFB(buf,6)=type;
  2871. WBUFW(buf,7)=val;
  2872. WBUFW(buf,9)=0;
  2873. clif_send(buf,packet_len(0x1d7),bl,target);
  2874. #endif
  2875. }
  2876. /// Character status (ZC_STATUS).
  2877. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2878. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2879. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2880. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2881. void clif_initialstatus(struct map_session_data *sd) {
  2882. int fd, mdef2;
  2883. unsigned char *buf;
  2884. nullpo_retv(sd);
  2885. fd=sd->fd;
  2886. WFIFOHEAD(fd,packet_len(0xbd));
  2887. buf=WFIFOP(fd,0);
  2888. WBUFW(buf,0)=0xbd;
  2889. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2890. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2891. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2892. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2893. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2894. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2895. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2896. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2897. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2898. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2899. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2900. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2901. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2902. WBUFW(buf,16) = pc_leftside_atk(sd);
  2903. WBUFW(buf,18) = pc_rightside_atk(sd);
  2904. WBUFW(buf,20) = pc_rightside_matk(sd);
  2905. WBUFW(buf,22) = pc_leftside_matk(sd);
  2906. WBUFW(buf,24) = pc_leftside_def(sd);
  2907. WBUFW(buf,26) = pc_rightside_def(sd);
  2908. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2909. mdef2 = pc_rightside_mdef(sd);
  2910. WBUFW(buf,30) =
  2911. #ifndef RENEWAL
  2912. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2913. #endif
  2914. mdef2;
  2915. WBUFW(buf,32) = sd->battle_status.hit;
  2916. WBUFW(buf,34) = sd->battle_status.flee;
  2917. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2918. WBUFW(buf,38) = sd->battle_status.cri/10;
  2919. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2920. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2921. WFIFOSET(fd,packet_len(0xbd));
  2922. clif_updatestatus(sd,SP_STR);
  2923. clif_updatestatus(sd,SP_AGI);
  2924. clif_updatestatus(sd,SP_VIT);
  2925. clif_updatestatus(sd,SP_INT);
  2926. clif_updatestatus(sd,SP_DEX);
  2927. clif_updatestatus(sd,SP_LUK);
  2928. clif_updatestatus(sd,SP_ATTACKRANGE);
  2929. clif_updatestatus(sd,SP_ASPD);
  2930. }
  2931. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2932. /// 013c <index>.W
  2933. void clif_arrowequip(struct map_session_data *sd,int val)
  2934. {
  2935. int fd;
  2936. nullpo_retv(sd);
  2937. pc_stop_attack(sd); // [Valaris]
  2938. #if PACKETVER >= 20121128
  2939. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2940. #endif
  2941. fd=sd->fd;
  2942. WFIFOHEAD(fd, packet_len(0x013c));
  2943. WFIFOW(fd,0)=0x013c;
  2944. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2945. WFIFOSET(fd,packet_len(0x013c));
  2946. }
  2947. /// Ammunition action message (ZC_ACTION_FAILURE).
  2948. /// 013b <type>.W
  2949. /// type:
  2950. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2951. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2952. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2953. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2954. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2955. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2956. void clif_arrow_fail(struct map_session_data *sd,int type)
  2957. {
  2958. int fd;
  2959. nullpo_retv(sd);
  2960. fd=sd->fd;
  2961. WFIFOHEAD(fd, packet_len(0x013b));
  2962. WFIFOW(fd,0)=0x013b;
  2963. WFIFOW(fd,2)=type;
  2964. WFIFOSET(fd,packet_len(0x013b));
  2965. }
  2966. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2967. /// 01ad <packet len>.W { <name id>.W }*
  2968. void clif_arrow_create_list(struct map_session_data *sd)
  2969. {
  2970. int i, c, j;
  2971. int fd;
  2972. nullpo_retv(sd);
  2973. fd = sd->fd;
  2974. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2975. WFIFOW(fd,0) = 0x1ad;
  2976. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2977. if (skill_arrow_db[i].nameid > 0 &&
  2978. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2979. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2980. {
  2981. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2982. WFIFOW(fd,c*2+4) = j;
  2983. else
  2984. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2985. c++;
  2986. }
  2987. }
  2988. WFIFOW(fd,2) = c*2+4;
  2989. WFIFOSET(fd, WFIFOW(fd,2));
  2990. if (c > 0) {
  2991. sd->menuskill_id = AC_MAKINGARROW;
  2992. sd->menuskill_val = c;
  2993. }
  2994. }
  2995. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2996. /// 00bc <status id>.W <result>.B <value>.B
  2997. /// status id:
  2998. /// SP_STR ~ SP_LUK
  2999. /// result:
  3000. /// 0 = failure
  3001. /// 1 = success
  3002. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3003. {
  3004. int fd;
  3005. nullpo_retv(sd);
  3006. fd=sd->fd;
  3007. WFIFOHEAD(fd,packet_len(0xbc));
  3008. WFIFOW(fd,0)=0xbc;
  3009. WFIFOW(fd,2)=type;
  3010. WFIFOB(fd,4)=ok;
  3011. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3012. WFIFOSET(fd,packet_len(0xbc));
  3013. }
  3014. /// Notifies the client about the result of a request to equip an item.
  3015. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3016. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3017. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3018. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3019. /// @ok: //inversed forv2 v5
  3020. /// 0 = failure
  3021. /// 1 = success
  3022. /// 2 = failure due to low level
  3023. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3024. {
  3025. int fd,header,offs=0,success;
  3026. #if PACKETVER < 20110824
  3027. header = 0xaa;
  3028. success = (ok==1);
  3029. #elif PACKETVER < 20120925
  3030. header = 0x8d0;
  3031. success = ok ? 0:1;
  3032. #else
  3033. header = 0x999;
  3034. success = ok ? 0:1;
  3035. #endif
  3036. nullpo_retv(sd);
  3037. fd=sd->fd;
  3038. WFIFOHEAD(fd,packet_len(header));
  3039. WFIFOW(fd,offs+0)=header;
  3040. WFIFOW(fd,offs+2)=n+2;
  3041. #if PACKETVER >= 20120925
  3042. WFIFOL(fd,offs+4)=pos;
  3043. offs+=2;
  3044. #else
  3045. WFIFOW(fd,offs+4)=(int)pos;
  3046. #endif
  3047. #if PACKETVER < 20100629
  3048. WFIFOB(fd,offs+6)=success;
  3049. #else
  3050. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3051. WFIFOW(fd,offs+6)=sd->inventory_data[n]->look;
  3052. else
  3053. WFIFOW(fd,offs+6)=0;
  3054. WFIFOB(fd,offs+8)=success;
  3055. #endif
  3056. WFIFOSET(fd,packet_len(header));
  3057. }
  3058. /// Notifies the client about the result of a request to take off an item.
  3059. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3060. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3061. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3062. /// @ok : //inversed for v2 v5
  3063. /// 0 = failure
  3064. /// 1 = success
  3065. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3066. {
  3067. int fd,header,offs=0;
  3068. #if PACKETVER >= 20130000
  3069. header = 0x99a;
  3070. ok = ok ? 0:1;
  3071. #elif PACKETVER >= 20110824
  3072. header = 0x8d1;
  3073. ok = ok ? 0:1;
  3074. #else
  3075. header = 0xac;
  3076. #endif
  3077. nullpo_retv(sd);
  3078. fd=sd->fd;
  3079. WFIFOHEAD(fd,packet_len(header));
  3080. WFIFOW(fd,offs+0)=header;
  3081. WFIFOW(fd,offs+2)=n+2;
  3082. #if PACKETVER >= 20130000
  3083. WFIFOL(fd,offs+4)=pos;
  3084. offs +=2;
  3085. #else
  3086. WFIFOW(fd,offs+4)=pos;
  3087. #endif
  3088. WFIFOB(fd,offs+6)=ok;
  3089. WFIFOSET(fd,packet_len(header));
  3090. }
  3091. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3092. /// 019b <id>.L <effect id>.L
  3093. /// effect id:
  3094. /// 0 = base level up
  3095. /// 1 = job level up
  3096. /// 2 = refine failure
  3097. /// 3 = refine success
  3098. /// 4 = game over
  3099. /// 5 = pharmacy success
  3100. /// 6 = pharmacy failure
  3101. /// 7 = base level up (super novice)
  3102. /// 8 = job level up (super novice)
  3103. /// 9 = base level up (taekwon)
  3104. void clif_misceffect(struct block_list* bl,int type)
  3105. {
  3106. unsigned char buf[32];
  3107. nullpo_retv(bl);
  3108. WBUFW(buf,0) = 0x19b;
  3109. WBUFL(buf,2) = bl->id;
  3110. WBUFL(buf,6) = type;
  3111. clif_send(buf,packet_len(0x19b),bl,AREA);
  3112. }
  3113. /// Notifies clients in the area of a state change.
  3114. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3115. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3116. void clif_changeoption(struct block_list* bl)
  3117. {
  3118. unsigned char buf[32];
  3119. struct status_change *sc;
  3120. struct map_session_data* sd;
  3121. nullpo_retv(bl);
  3122. sc = status_get_sc(bl);
  3123. if (!sc) return; //How can an option change if there's no sc?
  3124. sd = BL_CAST(BL_PC, bl);
  3125. #if PACKETVER >= 7
  3126. WBUFW(buf,0) = 0x229;
  3127. WBUFL(buf,2) = bl->id;
  3128. WBUFW(buf,6) = sc->opt1;
  3129. WBUFW(buf,8) = sc->opt2;
  3130. WBUFL(buf,10) = sc->option;
  3131. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3132. if(disguised(bl)) {
  3133. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3134. WBUFL(buf,2) = -bl->id;
  3135. clif_send(buf,packet_len(0x229),bl,SELF);
  3136. WBUFL(buf,2) = bl->id;
  3137. WBUFL(buf,10) = OPTION_INVISIBLE;
  3138. clif_send(buf,packet_len(0x229),bl,SELF);
  3139. } else
  3140. clif_send(buf,packet_len(0x229),bl,AREA);
  3141. #else
  3142. WBUFW(buf,0) = 0x119;
  3143. WBUFL(buf,2) = bl->id;
  3144. WBUFW(buf,6) = sc->opt1;
  3145. WBUFW(buf,8) = sc->opt2;
  3146. WBUFW(buf,10) = sc->option;
  3147. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3148. if(disguised(bl)) {
  3149. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3150. WBUFL(buf,2) = -bl->id;
  3151. clif_send(buf,packet_len(0x119),bl,SELF);
  3152. WBUFL(buf,2) = bl->id;
  3153. WBUFW(buf,10) = OPTION_INVISIBLE;
  3154. clif_send(buf,packet_len(0x119),bl,SELF);
  3155. } else
  3156. clif_send(buf,packet_len(0x119),bl,AREA);
  3157. #endif
  3158. }
  3159. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3160. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3161. void clif_changeoption2(struct block_list* bl)
  3162. {
  3163. unsigned char buf[20];
  3164. struct status_change *sc;
  3165. sc = status_get_sc(bl);
  3166. if (!sc) return; //How can an option change if there's no sc?
  3167. WBUFW(buf,0) = 0x28a;
  3168. WBUFL(buf,2) = bl->id;
  3169. WBUFL(buf,6) = sc->option;
  3170. WBUFL(buf,10) = clif_setlevel(bl);
  3171. WBUFL(buf,14) = sc->opt3;
  3172. if(disguised(bl)) {
  3173. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3174. WBUFL(buf,2) = -bl->id;
  3175. clif_send(buf,packet_len(0x28a),bl,SELF);
  3176. WBUFL(buf,2) = bl->id;
  3177. WBUFL(buf,6) = OPTION_INVISIBLE;
  3178. clif_send(buf,packet_len(0x28a),bl,SELF);
  3179. } else
  3180. clif_send(buf,packet_len(0x28a),bl,AREA);
  3181. }
  3182. /// Notifies the client about the result of an item use request.
  3183. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3184. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3185. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3186. {
  3187. nullpo_retv(sd);
  3188. if(!ok) {
  3189. int fd=sd->fd;
  3190. WFIFOHEAD(fd,packet_len(0xa8));
  3191. WFIFOW(fd,0)=0xa8;
  3192. WFIFOW(fd,2)=index+2;
  3193. WFIFOW(fd,4)=amount;
  3194. WFIFOB(fd,6)=ok;
  3195. WFIFOSET(fd,packet_len(0xa8));
  3196. }
  3197. else {
  3198. #if PACKETVER < 3
  3199. int fd=sd->fd;
  3200. WFIFOHEAD(fd,packet_len(0xa8));
  3201. WFIFOW(fd,0)=0xa8;
  3202. WFIFOW(fd,2)=index+2;
  3203. WFIFOW(fd,4)=amount;
  3204. WFIFOB(fd,6)=ok;
  3205. WFIFOSET(fd,packet_len(0xa8));
  3206. #else
  3207. unsigned char buf[32];
  3208. WBUFW(buf,0)=0x1c8;
  3209. WBUFW(buf,2)=index+2;
  3210. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3211. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3212. else
  3213. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3214. WBUFL(buf,6)=sd->bl.id;
  3215. WBUFW(buf,10)=amount;
  3216. WBUFB(buf,12)=ok;
  3217. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3218. #endif
  3219. }
  3220. }
  3221. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3222. /// 00d6 <flag>.B
  3223. /// flag:
  3224. /// 0 = Room has been successfully created (opens chat room)
  3225. /// 1 = Room limit exceeded
  3226. /// 2 = Same room already exists
  3227. void clif_createchat(struct map_session_data* sd, int flag)
  3228. {
  3229. int fd;
  3230. nullpo_retv(sd);
  3231. fd = sd->fd;
  3232. WFIFOHEAD(fd,packet_len(0xd6));
  3233. WFIFOW(fd,0) = 0xd6;
  3234. WFIFOB(fd,2) = flag;
  3235. WFIFOSET(fd,packet_len(0xd6));
  3236. }
  3237. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3238. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3239. /// type:
  3240. /// 0 = private (password protected)
  3241. /// 1 = public
  3242. /// 2 = arena (npc waiting room)
  3243. /// 3 = PK zone (non-clickable)
  3244. void clif_dispchat(struct chat_data* cd, int fd)
  3245. {
  3246. unsigned char buf[128];
  3247. uint8 type;
  3248. if( cd == NULL || cd->owner == NULL )
  3249. return;
  3250. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3251. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3252. : 1;
  3253. WBUFW(buf, 0) = 0xd7;
  3254. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3255. WBUFL(buf, 4) = cd->owner->id;
  3256. WBUFL(buf, 8) = cd->bl.id;
  3257. WBUFW(buf,12) = cd->limit;
  3258. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3259. WBUFB(buf,16) = type;
  3260. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3261. if( fd ) {
  3262. WFIFOHEAD(fd,WBUFW(buf,2));
  3263. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3264. WFIFOSET(fd,WBUFW(buf,2));
  3265. } else {
  3266. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3267. }
  3268. }
  3269. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3270. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3271. /// type:
  3272. /// 0 = private (password protected)
  3273. /// 1 = public
  3274. /// 2 = arena (npc waiting room)
  3275. /// 3 = PK zone (non-clickable)
  3276. void clif_changechatstatus(struct chat_data* cd)
  3277. {
  3278. unsigned char buf[128];
  3279. uint8 type;
  3280. if( cd == NULL || cd->usersd[0] == NULL )
  3281. return;
  3282. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3283. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3284. : 1;
  3285. WBUFW(buf, 0) = 0xdf;
  3286. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3287. WBUFL(buf, 4) = cd->owner->id;
  3288. WBUFL(buf, 8) = cd->bl.id;
  3289. WBUFW(buf,12) = cd->limit;
  3290. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3291. WBUFB(buf,16) = type;
  3292. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3293. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3294. }
  3295. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3296. /// 00d8 <chat id>.L
  3297. void clif_clearchat(struct chat_data *cd,int fd)
  3298. {
  3299. unsigned char buf[32];
  3300. nullpo_retv(cd);
  3301. WBUFW(buf,0) = 0xd8;
  3302. WBUFL(buf,2) = cd->bl.id;
  3303. if( fd ) {
  3304. WFIFOHEAD(fd,packet_len(0xd8));
  3305. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3306. WFIFOSET(fd,packet_len(0xd8));
  3307. } else {
  3308. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3309. }
  3310. }
  3311. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3312. /// 00da <result>.B
  3313. /// result:
  3314. /// 0 = room full
  3315. /// 1 = wrong password
  3316. /// 2 = kicked
  3317. /// 3 = success (no message)
  3318. /// 4 = no enough zeny
  3319. /// 5 = too low level
  3320. /// 6 = too high level
  3321. /// 7 = unsuitable job class
  3322. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3323. {
  3324. int fd;
  3325. nullpo_retv(sd);
  3326. fd = sd->fd;
  3327. WFIFOHEAD(fd,packet_len(0xda));
  3328. WFIFOW(fd,0) = 0xda;
  3329. WFIFOB(fd,2) = flag;
  3330. WFIFOSET(fd,packet_len(0xda));
  3331. }
  3332. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3333. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3334. /// role:
  3335. /// 0 = owner (menu)
  3336. /// 1 = normal
  3337. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3338. {
  3339. int fd;
  3340. int i,t;
  3341. nullpo_retv(sd);
  3342. nullpo_retv(cd);
  3343. fd = sd->fd;
  3344. if (!session_isActive(fd))
  3345. return;
  3346. t = (int)(cd->owner->type == BL_NPC);
  3347. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3348. WFIFOW(fd, 0) = 0xdb;
  3349. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3350. WFIFOL(fd, 4) = cd->bl.id;
  3351. if(cd->owner->type == BL_NPC){
  3352. WFIFOL(fd, 30) = 1;
  3353. WFIFOL(fd, 8) = 0;
  3354. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3355. for (i = 0; i < cd->users; i++) {
  3356. WFIFOL(fd, 8+(i+1)*28) = 1;
  3357. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3358. }
  3359. } else
  3360. for (i = 0; i < cd->users; i++) {
  3361. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3362. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3363. }
  3364. WFIFOSET(fd, WFIFOW(fd, 2));
  3365. }
  3366. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3367. /// 00dc <users>.W <name>.24B
  3368. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3369. {
  3370. unsigned char buf[32];
  3371. nullpo_retv(sd);
  3372. nullpo_retv(cd);
  3373. WBUFW(buf, 0) = 0xdc;
  3374. WBUFW(buf, 2) = cd->users;
  3375. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3376. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3377. }
  3378. /// Announce the new owner (ZC_ROLE_CHANGE).
  3379. /// 00e1 <role>.L <nick>.24B
  3380. /// role:
  3381. /// 0 = owner (menu)
  3382. /// 1 = normal
  3383. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3384. {
  3385. unsigned char buf[64];
  3386. nullpo_retv(sd);
  3387. nullpo_retv(cd);
  3388. WBUFW(buf, 0) = 0xe1;
  3389. WBUFL(buf, 2) = 1;
  3390. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3391. WBUFW(buf,30) = 0xe1;
  3392. WBUFL(buf,32) = 0;
  3393. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3394. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3395. }
  3396. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3397. /// 00dd <users>.W <nick>.24B <flag>.B
  3398. /// flag:
  3399. /// 0 = left
  3400. /// 1 = kicked
  3401. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3402. {
  3403. unsigned char buf[32];
  3404. nullpo_retv(sd);
  3405. nullpo_retv(cd);
  3406. WBUFW(buf, 0) = 0xdd;
  3407. WBUFW(buf, 2) = cd->users-1;
  3408. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3409. WBUFB(buf,28) = flag;
  3410. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3411. }
  3412. /// Opens a trade request window from char 'name'.
  3413. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3414. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3415. void clif_traderequest(struct map_session_data* sd, const char* name)
  3416. {
  3417. int fd = sd->fd;
  3418. #if PACKETVER < 6
  3419. WFIFOHEAD(fd,packet_len(0xe5));
  3420. WFIFOW(fd,0) = 0xe5;
  3421. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3422. WFIFOSET(fd,packet_len(0xe5));
  3423. #else
  3424. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3425. if( !tsd ) return;
  3426. WFIFOHEAD(fd,packet_len(0x1f4));
  3427. WFIFOW(fd,0) = 0x1f4;
  3428. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3429. WFIFOL(fd,26) = tsd->status.char_id;
  3430. WFIFOW(fd,30) = tsd->status.base_level;
  3431. WFIFOSET(fd,packet_len(0x1f4));
  3432. #endif
  3433. }
  3434. /// Reply to a trade-request.
  3435. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3436. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3437. /// result:
  3438. /// 0 = Char is too far
  3439. /// 1 = Character does not exist
  3440. /// 2 = Trade failed
  3441. /// 3 = Accept
  3442. /// 4 = Cancel
  3443. /// 5 = Busy
  3444. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3445. {
  3446. int fd = sd->fd;
  3447. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3448. if( PACKETVER < 6 || !tsd ) {
  3449. WFIFOHEAD(fd,packet_len(0xe7));
  3450. WFIFOW(fd,0) = 0xe7;
  3451. WFIFOB(fd,2) = type;
  3452. WFIFOSET(fd,packet_len(0xe7));
  3453. } else {
  3454. WFIFOHEAD(fd,packet_len(0x1f5));
  3455. WFIFOW(fd,0) = 0x1f5;
  3456. WFIFOB(fd,2) = type;
  3457. WFIFOL(fd,3) = tsd->status.char_id;
  3458. WFIFOW(fd,7) = tsd->status.base_level;
  3459. WFIFOSET(fd,packet_len(0x1f5));
  3460. }
  3461. }
  3462. /// Notifies the client about an item from other player in current trade.
  3463. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3464. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  3465. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3466. {
  3467. int fd;
  3468. unsigned char *buf;
  3469. #if PACKETVER < 20100223
  3470. const int cmd = 0xe9;
  3471. #else
  3472. const int cmd = 0x80f;
  3473. #endif
  3474. nullpo_retv(sd);
  3475. nullpo_retv(tsd);
  3476. fd = tsd->fd;
  3477. buf = WFIFOP(fd,0);
  3478. WFIFOHEAD(fd,packet_len(cmd));
  3479. WBUFW(buf,0) = cmd;
  3480. if( index == 0 )
  3481. {
  3482. #if PACKETVER < 20100223
  3483. WBUFL(buf,2) = amount; //amount
  3484. WBUFW(buf,6) = 0; // type id
  3485. #else
  3486. WBUFW(buf,2) = 0; // type id
  3487. WBUFB(buf,4) = 0; // item type
  3488. WBUFL(buf,5) = amount; // amount
  3489. buf = WBUFP(buf,1); //Advance 1B
  3490. #endif
  3491. WBUFB(buf,8) = 0; //identify flag
  3492. WBUFB(buf,9) = 0; // attribute
  3493. WBUFB(buf,10)= 0; //refine
  3494. WBUFW(buf,11)= 0; //card (4w)
  3495. WBUFW(buf,13)= 0; //card (4w)
  3496. WBUFW(buf,15)= 0; //card (4w)
  3497. WBUFW(buf,17)= 0; //card (4w)
  3498. }
  3499. else
  3500. {
  3501. index -= 2; //index fix
  3502. #if PACKETVER < 20100223
  3503. WBUFL(buf,2) = amount; //amount
  3504. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3505. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3506. else
  3507. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3508. #else
  3509. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3510. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3511. else
  3512. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3513. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3514. WBUFL(buf,5) = amount; // amount
  3515. buf = WBUFP(buf,1); //Advance 1B
  3516. #endif
  3517. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3518. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3519. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3520. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3521. }
  3522. WFIFOSET(fd,packet_len(cmd));
  3523. }
  3524. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3525. /// 00ea <index>.W <result>.B
  3526. /// result:
  3527. /// 0 = success
  3528. /// 1 = overweight
  3529. /// 2 = trade canceled
  3530. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3531. {
  3532. int fd;
  3533. nullpo_retv(sd);
  3534. fd = sd->fd;
  3535. WFIFOHEAD(fd,packet_len(0xea));
  3536. WFIFOW(fd,0) = 0xea;
  3537. WFIFOW(fd,2) = index;
  3538. WFIFOB(fd,4) = fail;
  3539. WFIFOSET(fd,packet_len(0xea));
  3540. }
  3541. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3542. /// 00ec <who>.B
  3543. /// who:
  3544. /// 0 = self
  3545. /// 1 = other player
  3546. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3547. {
  3548. int fd;
  3549. nullpo_retv(sd);
  3550. fd = sd->fd;
  3551. WFIFOHEAD(fd,packet_len(0xec));
  3552. WFIFOW(fd,0) = 0xec;
  3553. WFIFOB(fd,2) = fail;
  3554. WFIFOSET(fd,packet_len(0xec));
  3555. }
  3556. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3557. /// 00ee
  3558. void clif_tradecancelled(struct map_session_data* sd)
  3559. {
  3560. int fd;
  3561. nullpo_retv(sd);
  3562. fd = sd->fd;
  3563. WFIFOHEAD(fd,packet_len(0xee));
  3564. WFIFOW(fd,0) = 0xee;
  3565. WFIFOSET(fd,packet_len(0xee));
  3566. }
  3567. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3568. /// 00f0 <result>.B
  3569. /// result:
  3570. /// 0 = success
  3571. /// 1 = failure
  3572. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3573. {
  3574. int fd;
  3575. nullpo_retv(sd);
  3576. fd = sd->fd;
  3577. WFIFOHEAD(fd,packet_len(0xf0));
  3578. WFIFOW(fd,0) = 0xf0;
  3579. WFIFOB(fd,2) = fail;
  3580. WFIFOSET(fd,packet_len(0xf0));
  3581. }
  3582. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3583. /// 00f1
  3584. /// NOTE: Unknown purpose. Items are not removed until the window is
  3585. /// refreshed (ex. by putting another item in there).
  3586. void clif_tradeundo(struct map_session_data* sd)
  3587. {
  3588. int fd = sd->fd;
  3589. WFIFOHEAD(fd,packet_len(0xf1));
  3590. WFIFOW(fd,0) = 0xf1;
  3591. WFIFOSET(fd,packet_len(0xf1));
  3592. }
  3593. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3594. /// 00f2 <current count>.W <max count>.W
  3595. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3596. {
  3597. int fd;
  3598. nullpo_retv(sd);
  3599. fd=sd->fd;
  3600. WFIFOHEAD(fd,packet_len(0xf2));
  3601. WFIFOW(fd,0) = 0xf2;
  3602. WFIFOW(fd,2) = amount;
  3603. WFIFOW(fd,4) = max_amount;
  3604. WFIFOSET(fd,packet_len(0xf2));
  3605. }
  3606. /// Notifies the client of an item being added to the storage.
  3607. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  3608. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  3609. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3610. {
  3611. int view,fd;
  3612. nullpo_retv(sd);
  3613. nullpo_retv(i);
  3614. fd=sd->fd;
  3615. view = itemdb_viewid(i->nameid);
  3616. #if PACKETVER < 5
  3617. WFIFOHEAD(fd,packet_len(0xf4));
  3618. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3619. WFIFOW(fd, 2) = index+1; // index
  3620. WFIFOL(fd, 4) = amount; // amount
  3621. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3622. WFIFOB(fd,10) = i->identify; //identify flag
  3623. WFIFOB(fd,11) = i->attribute; // attribute
  3624. WFIFOB(fd,12) = i->refine; //refine
  3625. clif_addcards(WFIFOP(fd,13), i);
  3626. WFIFOSET(fd,packet_len(0xf4));
  3627. #else
  3628. WFIFOHEAD(fd,packet_len(0x1c4));
  3629. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3630. WFIFOW(fd, 2) = index+1; // index
  3631. WFIFOL(fd, 4) = amount; // amount
  3632. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3633. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3634. WFIFOB(fd,11) = i->identify; //identify flag
  3635. WFIFOB(fd,12) = i->attribute; // attribute
  3636. WFIFOB(fd,13) = i->refine; //refine
  3637. clif_addcards(WFIFOP(fd,14), i);
  3638. WFIFOSET(fd,packet_len(0x1c4));
  3639. #endif
  3640. }
  3641. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3642. /// 00f6 <index>.W <amount>.L
  3643. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3644. {
  3645. int fd;
  3646. nullpo_retv(sd);
  3647. fd=sd->fd;
  3648. WFIFOHEAD(fd,packet_len(0xf6));
  3649. WFIFOW(fd,0)=0xf6; // Storage item removed
  3650. WFIFOW(fd,2)=index+1;
  3651. WFIFOL(fd,4)=amount;
  3652. WFIFOSET(fd,packet_len(0xf6));
  3653. }
  3654. /// Closes storage (ZC_CLOSE_STORE).
  3655. /// 00f8
  3656. void clif_storageclose(struct map_session_data* sd)
  3657. {
  3658. int fd;
  3659. nullpo_retv(sd);
  3660. fd=sd->fd;
  3661. WFIFOHEAD(fd,packet_len(0xf8));
  3662. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3663. WFIFOSET(fd,packet_len(0xf8));
  3664. }
  3665. /*==========================================
  3666. * Server tells 'sd' player client the abouts of 'dstsd' player
  3667. *------------------------------------------*/
  3668. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3669. {
  3670. struct block_list *d_bl;
  3671. int i;
  3672. if( dstsd->chatID ) {
  3673. struct chat_data *cd = NULL;
  3674. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3675. clif_dispchat(cd,sd->fd);
  3676. } else if( dstsd->state.vending )
  3677. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3678. else if( dstsd->state.buyingstore )
  3679. clif_buyingstore_entry_single(sd, dstsd);
  3680. if(dstsd->spiritball > 0)
  3681. clif_spiritball_single(sd->fd, dstsd);
  3682. for(i = 1; i < 5; i++){
  3683. if( dstsd->talisman[i] > 0 )
  3684. clif_talisman_single(sd->fd, dstsd, i);
  3685. }
  3686. for( i = SC_SPHERE_1; i <= SC_SPHERE_5; i++ ) {
  3687. if( dstsd->sc.data[i] )
  3688. clif_status_load_single(sd->fd,dstsd->bl.id,StatusIconChangeTable[i],1,dstsd->sc.data[i]->val1,dstsd->sc.data[i]->val2,0);
  3689. }
  3690. #ifdef NEW_CARTS
  3691. if( dstsd->sc.data[SC_PUSH_CART] )
  3692. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3693. #endif
  3694. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3695. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3696. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3697. )
  3698. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3699. // display link (sd - dstsd) to sd
  3700. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3701. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3702. // display links (dstsd - devotees) to sd
  3703. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3704. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3705. // display link (dstsd - crusader) to sd
  3706. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3707. clif_devotion(d_bl, sd);
  3708. }
  3709. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3710. {
  3711. uint8 buf[128];
  3712. struct unit_data *ud;
  3713. struct view_data *vd;
  3714. int len;
  3715. vd = status_get_viewdata(bl);
  3716. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3717. return;
  3718. /**
  3719. * Hide NPC from maya purple card.
  3720. **/
  3721. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3722. return;
  3723. ud = unit_bl2ud(bl);
  3724. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3725. clif_send(buf,len,&sd->bl,SELF);
  3726. if (vd->cloth_color)
  3727. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3728. switch (bl->type)
  3729. {
  3730. case BL_PC:
  3731. {
  3732. TBL_PC* tsd = (TBL_PC*)bl;
  3733. clif_getareachar_pc(sd, tsd);
  3734. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3735. clif_specialeffect_single(bl,423,sd->fd);
  3736. else if(tsd->state.size==SZ_MEDIUM)
  3737. clif_specialeffect_single(bl,421,sd->fd);
  3738. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3739. clif_sendbgemblem_single(sd->fd,tsd);
  3740. if ( tsd->status.robe )
  3741. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3742. if (!&tsd->sc)
  3743. break;
  3744. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3745. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3746. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3747. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3748. if( tsd->sc.data[SC_MOONSTAR] )
  3749. clif_status_load(bl,SI_MOONSTAR,1);
  3750. if( tsd->sc.data[SC_SUPER_STAR] )
  3751. clif_status_load(bl,SI_SUPER_STAR,1);
  3752. if( tsd->sc.data[SC_ALL_RIDING] )
  3753. clif_status_load(bl,SI_ALL_RIDING,1);
  3754. }
  3755. break;
  3756. case BL_MER: // Devotion Effects
  3757. if( ((TBL_MER*)bl)->devotion_flag )
  3758. clif_devotion(bl, sd);
  3759. break;
  3760. case BL_NPC:
  3761. {
  3762. TBL_NPC* nd = (TBL_NPC*)bl;
  3763. if( nd->chat_id )
  3764. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3765. if( nd->size == SZ_BIG )
  3766. clif_specialeffect_single(bl,423,sd->fd);
  3767. else if( nd->size == SZ_MEDIUM )
  3768. clif_specialeffect_single(bl,421,sd->fd);
  3769. }
  3770. break;
  3771. case BL_MOB:
  3772. {
  3773. TBL_MOB* md = (TBL_MOB*)bl;
  3774. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3775. clif_specialeffect_single(bl,423,sd->fd);
  3776. else if(md->special_state.size==SZ_MEDIUM)
  3777. clif_specialeffect_single(bl,421,sd->fd);
  3778. #if PACKETVER >= 20120404
  3779. if( !(md->status.mode&MD_BOSS) ){
  3780. int i;
  3781. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3782. if( md->dmglog[i].id == sd->status.char_id )
  3783. clif_monster_hp_bar(md, sd->fd);
  3784. }
  3785. #endif
  3786. }
  3787. break;
  3788. case BL_PET:
  3789. if (vd->head_bottom)
  3790. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3791. break;
  3792. }
  3793. }
  3794. //Modifies the type of damage according to status changes [Skotlex]
  3795. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3796. static inline int clif_calc_delay(int type, int div, int64 damage, int delay)
  3797. {
  3798. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3799. }
  3800. /*==========================================
  3801. * Estimates walk delay based on the damage criteria. [Skotlex]
  3802. *------------------------------------------*/
  3803. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int64 damage, int div_)
  3804. {
  3805. if (type == 4 || type == 9 || damage <=0)
  3806. return 0;
  3807. if (bl->type == BL_PC) {
  3808. if (battle_config.pc_walk_delay_rate != 100)
  3809. delay = delay*battle_config.pc_walk_delay_rate/100;
  3810. } else
  3811. if (battle_config.walk_delay_rate != 100)
  3812. delay = delay*battle_config.walk_delay_rate/100;
  3813. if (div_ > 1) //Multi-hit skills mean higher delays.
  3814. delay += battle_config.multihit_delay*(div_-1);
  3815. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3816. }
  3817. /// Sends a 'damage' packet (src performs action on dst)
  3818. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  3819. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  3820. /// type:
  3821. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3822. /// 1 = pick up item
  3823. /// 2 = sit down
  3824. /// 3 = stand up
  3825. /// 4 = damage (endure)
  3826. /// 5 = (splash?)
  3827. /// 6 = (skill?)
  3828. /// 7 = (repeat damage?)
  3829. /// 8 = multi-hit damage
  3830. /// 9 = multi-hit damage (endure)
  3831. /// 10 = critical hit
  3832. /// 11 = lucky dodge
  3833. /// 12 = (touch skill?)
  3834. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, int type, int64 sdamage2)
  3835. {
  3836. unsigned char buf[33];
  3837. struct status_change *sc;
  3838. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3839. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3840. #if PACKETVER < 20071113
  3841. const int cmd = 0x8a;
  3842. #else
  3843. const int cmd = 0x2e1;
  3844. #endif
  3845. nullpo_ret(src);
  3846. nullpo_ret(dst);
  3847. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3848. sc = status_get_sc(dst);
  3849. if(sc && sc->count) {
  3850. if(sc->data[SC_HALLUCINATION]) {
  3851. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3852. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3853. }
  3854. }
  3855. WBUFW(buf,0)=cmd;
  3856. WBUFL(buf,2)=src->id;
  3857. WBUFL(buf,6)=dst->id;
  3858. WBUFL(buf,10)=tick;
  3859. WBUFL(buf,14)=sdelay;
  3860. WBUFL(buf,18)=ddelay;
  3861. #if PACKETVER < 20071113
  3862. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3863. WBUFW(buf,22)=damage?div:0;
  3864. WBUFW(buf,27)=damage2?div:0;
  3865. } else {
  3866. WBUFW(buf,22)=min(damage, INT16_MAX);
  3867. WBUFW(buf,27)=damage2;
  3868. }
  3869. WBUFW(buf,24)=div;
  3870. WBUFB(buf,26)=type;
  3871. #else
  3872. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3873. WBUFL(buf,22)=damage?div:0;
  3874. WBUFL(buf,29)=damage2?div:0;
  3875. } else {
  3876. WBUFL(buf,22)=damage;
  3877. WBUFL(buf,29)=damage2;
  3878. }
  3879. WBUFW(buf,26)=div;
  3880. WBUFB(buf,28)=type;
  3881. #endif
  3882. if(disguised(dst)) {
  3883. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3884. WBUFL(buf,6) = -dst->id;
  3885. clif_send(buf,packet_len(cmd),dst,SELF);
  3886. } else
  3887. clif_send(buf,packet_len(cmd),dst,AREA);
  3888. if(disguised(src)) {
  3889. WBUFL(buf,2) = -src->id;
  3890. if (disguised(dst))
  3891. WBUFL(buf,6) = dst->id;
  3892. #if PACKETVER < 20071113
  3893. if(damage > 0) WBUFW(buf,22) = -1;
  3894. if(damage2 > 0) WBUFW(buf,27) = -1;
  3895. #else
  3896. if(damage > 0) WBUFL(buf,22) = -1;
  3897. if(damage2 > 0) WBUFL(buf,29) = -1;
  3898. #endif
  3899. clif_send(buf,packet_len(cmd),src,SELF);
  3900. }
  3901. if(src == dst) {
  3902. unit_setdir(src,unit_getdir(src));
  3903. }
  3904. //Return adjusted can't walk delay for further processing.
  3905. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3906. }
  3907. /*==========================================
  3908. * src picks up dst
  3909. *------------------------------------------*/
  3910. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3911. {
  3912. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3913. unsigned char buf[32];
  3914. nullpo_retv(src);
  3915. nullpo_retv(dst);
  3916. WBUFW(buf, 0) = 0x8a;
  3917. WBUFL(buf, 2) = src->id;
  3918. WBUFL(buf, 6) = dst->id;
  3919. WBUFB(buf,26) = 1;
  3920. clif_send(buf, packet_len(0x8a), src, AREA);
  3921. }
  3922. /*==========================================
  3923. * inform clients in area that `bl` is sitting
  3924. *------------------------------------------*/
  3925. void clif_sitting(struct block_list* bl)
  3926. {
  3927. unsigned char buf[32];
  3928. nullpo_retv(bl);
  3929. WBUFW(buf, 0) = 0x8a;
  3930. WBUFL(buf, 2) = bl->id;
  3931. WBUFB(buf,26) = 2;
  3932. clif_send(buf, packet_len(0x8a), bl, AREA);
  3933. if(disguised(bl)) {
  3934. WBUFL(buf, 2) = - bl->id;
  3935. clif_send(buf, packet_len(0x8a), bl, SELF);
  3936. }
  3937. }
  3938. /*==========================================
  3939. * inform clients in area that `bl` is standing
  3940. *------------------------------------------*/
  3941. void clif_standing(struct block_list* bl)
  3942. {
  3943. unsigned char buf[32];
  3944. nullpo_retv(bl);
  3945. WBUFW(buf, 0) = 0x8a;
  3946. WBUFL(buf, 2) = bl->id;
  3947. WBUFB(buf,26) = 3;
  3948. clif_send(buf, packet_len(0x8a), bl, AREA);
  3949. if(disguised(bl)) {
  3950. WBUFL(buf, 2) = - bl->id;
  3951. clif_send(buf, packet_len(0x8a), bl, SELF);
  3952. }
  3953. }
  3954. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3955. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3956. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3957. {
  3958. unsigned char buf[32];
  3959. WBUFW(buf,0) = 0x192;
  3960. WBUFW(buf,2) = x;
  3961. WBUFW(buf,4) = y;
  3962. WBUFW(buf,6) = type;
  3963. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3964. if( fd )
  3965. {
  3966. WFIFOHEAD(fd,packet_len(0x192));
  3967. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3968. WFIFOSET(fd,packet_len(0x192));
  3969. }
  3970. else
  3971. {
  3972. struct block_list dummy_bl;
  3973. dummy_bl.type = BL_NUL;
  3974. dummy_bl.x = x;
  3975. dummy_bl.y = y;
  3976. dummy_bl.m = m;
  3977. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3978. }
  3979. }
  3980. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3981. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3982. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3983. {
  3984. int view,fd;
  3985. fd=sd->fd;
  3986. WFIFOHEAD(fd,packet_len(0x9d));
  3987. WFIFOW(fd,0)=0x9d;
  3988. WFIFOL(fd,2)=fitem->bl.id;
  3989. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3990. WFIFOW(fd,6)=view;
  3991. else
  3992. WFIFOW(fd,6)=fitem->item_data.nameid;
  3993. WFIFOB(fd,8)=fitem->item_data.identify;
  3994. WFIFOW(fd,9)=fitem->bl.x;
  3995. WFIFOW(fd,11)=fitem->bl.y;
  3996. WFIFOW(fd,13)=fitem->item_data.amount;
  3997. WFIFOB(fd,15)=fitem->subx;
  3998. WFIFOB(fd,16)=fitem->suby;
  3999. WFIFOSET(fd,packet_len(0x9d));
  4000. }
  4001. /// Notifies the client of a skill unit.
  4002. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4003. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4004. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4005. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4006. static void clif_getareachar_skillunit(int type,struct map_session_data *sd, struct skill_unit *unit)
  4007. {
  4008. int fd = sd->fd;
  4009. int header=0, unit_id=0, pos=0;
  4010. if( unit->group->state.guildaura )
  4011. return;
  4012. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  4013. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  4014. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4015. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  4016. else
  4017. unit_id=unit->group->unit_id;
  4018. #if PACKETVER >= 3
  4019. if(unit->group->unit_id==UNT_GRAFFITI) // Graffiti [Valaris]
  4020. type = 2;
  4021. #endif
  4022. switch(type){
  4023. case 2: header=0x1c9; break;
  4024. case 3: header=0x8c7; break;
  4025. case 4: header=0x99f; break;
  4026. default:
  4027. case 1: header=0x11f; break;
  4028. }
  4029. WFIFOHEAD(fd,packet_len(header));
  4030. WFIFOW(fd,pos)=header;
  4031. if(type==3 || type==4){
  4032. WFIFOW(fd, pos+2)=packet_len(header);
  4033. pos +=2;
  4034. }
  4035. WFIFOL(fd,pos+2)=unit->bl.id;
  4036. WFIFOL(fd,pos+6)=unit->group->src_id;
  4037. WFIFOW(fd,pos+10)=unit->bl.x;
  4038. WFIFOW(fd,pos+12)=unit->bl.y;
  4039. switch(type){
  4040. case 1: WFIFOB(fd,pos+14)=unit_id;
  4041. WFIFOB(fd,pos+15)=1;
  4042. break;
  4043. case 2: WFIFOB(fd,pos+14)=unit_id;
  4044. WFIFOB(fd,pos+15)=1;
  4045. WFIFOB(fd,pos+16)=1;
  4046. safestrncpy((char*)WFIFOP(fd,pos+17),unit->group->valstr,MESSAGE_SIZE);
  4047. break;
  4048. case 3: WFIFOB(fd,pos+14)=unit_id;
  4049. WFIFOW(fd,pos+15)=unit->range;
  4050. WFIFOB(fd,pos+17)=1; //visible
  4051. break;
  4052. case 4: WFIFOL(fd,pos+14)=unit_id; pos += 3;
  4053. WFIFOW(fd,pos+15)=unit->range;
  4054. WFIFOB(fd,pos+17)=1;
  4055. break;
  4056. }
  4057. WFIFOSET(fd,packet_len(header));
  4058. if(unit->group->skill_id == WZ_ICEWALL)
  4059. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  4060. }
  4061. /*==========================================
  4062. * Server tells client to remove unit of id 'unit->bl.id'
  4063. *------------------------------------------*/
  4064. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4065. {
  4066. nullpo_retv(unit);
  4067. WFIFOHEAD(fd,packet_len(0x120));
  4068. WFIFOW(fd, 0)=0x120;
  4069. WFIFOL(fd, 2)=unit->bl.id;
  4070. WFIFOSET(fd,packet_len(0x120));
  4071. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4072. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4073. }
  4074. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4075. /// 0120 <id>.L
  4076. void clif_skill_delunit(struct skill_unit *unit)
  4077. {
  4078. unsigned char buf[16];
  4079. nullpo_retv(unit);
  4080. WBUFW(buf, 0)=0x120;
  4081. WBUFL(buf, 2)=unit->bl.id;
  4082. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4083. }
  4084. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4085. /// 01ac <id>.L
  4086. /// Only affects units with class [139,153] client-side.
  4087. void clif_skillunit_update(struct block_list* bl)
  4088. {
  4089. unsigned char buf[6];
  4090. nullpo_retv(bl);
  4091. WBUFW(buf,0) = 0x1ac;
  4092. WBUFL(buf,2) = bl->id;
  4093. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4094. }
  4095. /*==========================================
  4096. *
  4097. *------------------------------------------*/
  4098. static int clif_getareachar(struct block_list* bl,va_list ap)
  4099. {
  4100. struct map_session_data *sd;
  4101. nullpo_ret(bl);
  4102. sd=va_arg(ap,struct map_session_data*);
  4103. if (sd == NULL || !sd->fd)
  4104. return 0;
  4105. switch(bl->type){
  4106. case BL_ITEM:
  4107. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4108. break;
  4109. case BL_SKILL:
  4110. clif_getareachar_skillunit(1,sd,(TBL_SKILL*)bl);
  4111. break;
  4112. default:
  4113. if(&sd->bl == bl)
  4114. break;
  4115. clif_getareachar_unit(sd,bl);
  4116. break;
  4117. }
  4118. return 0;
  4119. }
  4120. /*==========================================
  4121. * tbl has gone out of view-size of bl
  4122. *------------------------------------------*/
  4123. int clif_outsight(struct block_list *bl,va_list ap)
  4124. {
  4125. struct block_list *tbl;
  4126. struct view_data *vd;
  4127. TBL_PC *sd, *tsd;
  4128. tbl=va_arg(ap,struct block_list*);
  4129. if(bl == tbl) return 0;
  4130. sd = BL_CAST(BL_PC, bl);
  4131. tsd = BL_CAST(BL_PC, tbl);
  4132. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4133. switch(bl->type){
  4134. case BL_PC:
  4135. if (sd->vd.class_ != INVISIBLE_CLASS)
  4136. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4137. if(sd->chatID){
  4138. struct chat_data *cd;
  4139. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4140. if(cd->usersd[0]==sd)
  4141. clif_dispchat(cd,tsd->fd);
  4142. }
  4143. if( sd->state.vending )
  4144. clif_closevendingboard(bl,tsd->fd);
  4145. if( sd->state.buyingstore )
  4146. clif_buyingstore_disappear_entry_single(tsd, sd);
  4147. break;
  4148. case BL_ITEM:
  4149. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4150. break;
  4151. case BL_SKILL:
  4152. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4153. break;
  4154. case BL_NPC:
  4155. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4156. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4157. break;
  4158. default:
  4159. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4160. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4161. break;
  4162. }
  4163. }
  4164. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4165. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4166. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4167. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4168. }
  4169. return 0;
  4170. }
  4171. /*==========================================
  4172. * tbl has come into view of bl
  4173. *------------------------------------------*/
  4174. int clif_insight(struct block_list *bl,va_list ap)
  4175. {
  4176. struct block_list *tbl;
  4177. TBL_PC *sd, *tsd;
  4178. tbl=va_arg(ap,struct block_list*);
  4179. if (bl == tbl) return 0;
  4180. sd = BL_CAST(BL_PC, bl);
  4181. tsd = BL_CAST(BL_PC, tbl);
  4182. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4183. switch(bl->type){
  4184. case BL_ITEM:
  4185. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4186. break;
  4187. case BL_SKILL:
  4188. clif_getareachar_skillunit(1,tsd,(TBL_SKILL*)bl);
  4189. break;
  4190. default:
  4191. clif_getareachar_unit(tsd,bl);
  4192. break;
  4193. }
  4194. }
  4195. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4196. clif_getareachar_unit(sd,tbl);
  4197. }
  4198. return 0;
  4199. }
  4200. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4201. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4202. void clif_skillinfoblock(struct map_session_data *sd)
  4203. {
  4204. int fd;
  4205. int i,len,id;
  4206. nullpo_retv(sd);
  4207. fd=sd->fd;
  4208. if (!fd) return;
  4209. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4210. WFIFOW(fd,0) = 0x10f;
  4211. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4212. {
  4213. if( (id = sd->status.skill[i].id) != 0 )
  4214. {
  4215. // workaround for bugreport:5348
  4216. if (len + 37 > 8192)
  4217. break;
  4218. WFIFOW(fd,len) = id;
  4219. WFIFOL(fd,len+2) = skill_get_inf(id);
  4220. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4221. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4222. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4223. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4224. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4225. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4226. else
  4227. WFIFOB(fd,len+36) = 0;
  4228. len += 37;
  4229. }
  4230. }
  4231. WFIFOW(fd,2)=len;
  4232. WFIFOSET(fd,len);
  4233. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4234. for ( ; i < MAX_SKILL; i++)
  4235. {
  4236. if( (id = sd->status.skill[i].id) != 0 )
  4237. {
  4238. clif_addskill(sd, id);
  4239. clif_skillinfo(sd, id, 0);
  4240. }
  4241. }
  4242. }
  4243. /**
  4244. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4245. **/
  4246. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4247. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4248. void clif_addskill(struct map_session_data *sd, int id)
  4249. {
  4250. int fd;
  4251. nullpo_retv(sd);
  4252. fd = sd->fd;
  4253. if (!fd) return;
  4254. if( sd->status.skill[id].id <= 0 )
  4255. return;
  4256. WFIFOHEAD(fd, packet_len(0x111));
  4257. WFIFOW(fd,0) = 0x111;
  4258. WFIFOW(fd,2) = id;
  4259. WFIFOL(fd,4) = skill_get_inf(id);
  4260. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4261. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4262. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4263. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4264. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4265. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4266. else
  4267. WFIFOB(fd,38) = 0;
  4268. WFIFOSET(fd,packet_len(0x111));
  4269. }
  4270. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4271. /// 0441 <skill id>.W
  4272. void clif_deleteskill(struct map_session_data *sd, int id)
  4273. {
  4274. #if PACKETVER >= 20081217
  4275. int fd;
  4276. nullpo_retv(sd);
  4277. fd = sd->fd;
  4278. if( !fd ) return;
  4279. WFIFOHEAD(fd,packet_len(0x441));
  4280. WFIFOW(fd,0) = 0x441;
  4281. WFIFOW(fd,2) = id;
  4282. WFIFOSET(fd,packet_len(0x441));
  4283. #endif
  4284. clif_skillinfoblock(sd);
  4285. }
  4286. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4287. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4288. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4289. int fd;
  4290. nullpo_retv(sd);
  4291. fd = sd->fd;
  4292. WFIFOHEAD(fd, packet_len(0x10e));
  4293. WFIFOW(fd, 0) = 0x10e;
  4294. WFIFOW(fd, 2) = skill_id;
  4295. WFIFOW(fd, 4) = lv;
  4296. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4297. WFIFOW(fd, 8) = range;
  4298. WFIFOB(fd, 10) = upgradable;
  4299. WFIFOSET(fd, packet_len(0x10e));
  4300. }
  4301. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4302. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4303. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4304. {
  4305. const int fd = sd->fd;
  4306. WFIFOHEAD(fd,packet_len(0x7e1));
  4307. WFIFOW(fd,0) = 0x7e1;
  4308. WFIFOW(fd,2) = skill;
  4309. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4310. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4311. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4312. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4313. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4314. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4315. else
  4316. WFIFOB(fd,14) = 0;
  4317. WFIFOSET(fd,packet_len(0x7e1));
  4318. }
  4319. /// Notifies clients in area, that an object is about to use a skill.
  4320. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4321. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4322. /// property:
  4323. /// 0 = Yellow cast aura
  4324. /// 1 = Water elemental cast aura
  4325. /// 2 = Earth elemental cast aura
  4326. /// 3 = Fire elemental cast aura
  4327. /// 4 = Wind elemental cast aura
  4328. /// 5 = Poison elemental cast aura
  4329. /// 6 = Holy elemental cast aura
  4330. /// ? = like 0
  4331. /// is disposable:
  4332. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4333. /// 1 = no text
  4334. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, int property, int casttime)
  4335. {
  4336. #if PACKETVER < 20091124
  4337. const int cmd = 0x13e;
  4338. #else
  4339. const int cmd = 0x7fb;
  4340. #endif
  4341. unsigned char buf[32];
  4342. WBUFW(buf,0) = cmd;
  4343. WBUFL(buf,2) = src_id;
  4344. WBUFL(buf,6) = dst_id;
  4345. WBUFW(buf,10) = dst_x;
  4346. WBUFW(buf,12) = dst_y;
  4347. WBUFW(buf,14) = skill_id;
  4348. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4349. WBUFL(buf,20) = casttime;
  4350. #if PACKETVER >= 20091124
  4351. WBUFB(buf,24) = 0; // isDisposable
  4352. #endif
  4353. if (disguised(bl)) {
  4354. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4355. WBUFL(buf,2) = -src_id;
  4356. clif_send(buf,packet_len(cmd), bl, SELF);
  4357. } else
  4358. clif_send(buf,packet_len(cmd), bl, AREA);
  4359. }
  4360. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4361. /// 01b9 <id>.L
  4362. void clif_skillcastcancel(struct block_list* bl)
  4363. {
  4364. unsigned char buf[16];
  4365. nullpo_retv(bl);
  4366. WBUFW(buf,0) = 0x1b9;
  4367. WBUFL(buf,2) = bl->id;
  4368. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4369. }
  4370. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4371. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4372. /// num (only used when skill id = NV_BASIC and cause = 0):
  4373. /// 0 = "skill failed" MsgStringTable[159]
  4374. /// 1 = "no emotions" MsgStringTable[160]
  4375. /// 2 = "no sit" MsgStringTable[161]
  4376. /// 3 = "no chat" MsgStringTable[162]
  4377. /// 4 = "no party" MsgStringTable[163]
  4378. /// 5 = "no shout" MsgStringTable[164]
  4379. /// 6 = "no PKing" MsgStringTable[165]
  4380. /// 7 = "no alligning" MsgStringTable[383]
  4381. /// ? = ignored
  4382. /// cause:
  4383. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4384. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4385. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4386. /// "skill failed" MsgStringTable[204] (otherwise)
  4387. /// ... = @see enum useskill_fail_cause
  4388. /// ? = ignored
  4389. ///
  4390. /// if(result!=0) doesn't display any of the previous messages
  4391. /// Note: when this packet is received an unknown flag is always set to 0,
  4392. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4393. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4394. {
  4395. int fd;
  4396. if (!sd) { //Since this is the most common nullpo....
  4397. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4398. return;
  4399. }
  4400. fd=sd->fd;
  4401. if (!fd) return;
  4402. if(battle_config.display_skill_fail&1)
  4403. return; //Disable all skill failed messages
  4404. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4405. return; //Disable delay failed messages
  4406. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4407. return;
  4408. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4409. return;
  4410. WFIFOHEAD(fd,packet_len(0x110));
  4411. WFIFOW(fd,0) = 0x110;
  4412. WFIFOW(fd,2) = skill_id;
  4413. WFIFOL(fd,4) = btype;
  4414. WFIFOB(fd,8) = 0;// success
  4415. WFIFOB(fd,9) = cause;
  4416. WFIFOSET(fd,packet_len(0x110));
  4417. }
  4418. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4419. /// 043d <skill ID>.W <tick>.L
  4420. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4421. {
  4422. #if PACKETVER>=20081112
  4423. int fd;
  4424. nullpo_retv(sd);
  4425. fd=sd->fd;
  4426. WFIFOHEAD(fd,packet_len(0x43d));
  4427. WFIFOW(fd,0) = 0x43d;
  4428. WFIFOW(fd,2) = skill_id;
  4429. WFIFOL(fd,4) = tick;
  4430. WFIFOSET(fd,packet_len(0x43d));
  4431. #endif
  4432. }
  4433. /// Skill attack effect and damage.
  4434. /// 0114 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.W <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL)
  4435. /// 01de <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.L <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL2)
  4436. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4437. {
  4438. unsigned char buf[64];
  4439. struct status_change *sc;
  4440. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4441. nullpo_ret(src);
  4442. nullpo_ret(dst);
  4443. type = clif_calc_delay(type,div,damage,ddelay);
  4444. sc = status_get_sc(dst);
  4445. if(sc && sc->count) {
  4446. if(sc->data[SC_HALLUCINATION] && damage)
  4447. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4448. }
  4449. #if PACKETVER < 3
  4450. WBUFW(buf,0)=0x114;
  4451. WBUFW(buf,2)=skill_id;
  4452. WBUFL(buf,4)=src->id;
  4453. WBUFL(buf,8)=dst->id;
  4454. WBUFL(buf,12)=tick;
  4455. WBUFL(buf,16)=sdelay;
  4456. WBUFL(buf,20)=ddelay;
  4457. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4458. WBUFW(buf,24)=damage?div:0;
  4459. } else {
  4460. WBUFW(buf,24)=damage;
  4461. }
  4462. WBUFW(buf,26)=skill_lv;
  4463. WBUFW(buf,28)=div;
  4464. WBUFB(buf,30)=type;
  4465. if (disguised(dst)) {
  4466. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4467. WBUFL(buf,8)=-dst->id;
  4468. clif_send(buf,packet_len(0x114),dst,SELF);
  4469. } else
  4470. clif_send(buf,packet_len(0x114),dst,AREA);
  4471. if(disguised(src)) {
  4472. WBUFL(buf,4)=-src->id;
  4473. if (disguised(dst))
  4474. WBUFL(buf,8)=dst->id;
  4475. if(damage > 0)
  4476. WBUFW(buf,24)=-1;
  4477. clif_send(buf,packet_len(0x114),src,SELF);
  4478. }
  4479. #else
  4480. WBUFW(buf,0)=0x1de;
  4481. WBUFW(buf,2)=skill_id;
  4482. WBUFL(buf,4)=src->id;
  4483. WBUFL(buf,8)=dst->id;
  4484. WBUFL(buf,12)=tick;
  4485. WBUFL(buf,16)=sdelay;
  4486. WBUFL(buf,20)=ddelay;
  4487. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4488. WBUFL(buf,24)=damage?div:0;
  4489. } else {
  4490. WBUFL(buf,24)=damage;
  4491. }
  4492. WBUFW(buf,28)=skill_lv;
  4493. WBUFW(buf,30)=div;
  4494. WBUFB(buf,32)=type;
  4495. if (disguised(dst)) {
  4496. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4497. WBUFL(buf,8)=-dst->id;
  4498. clif_send(buf,packet_len(0x1de),dst,SELF);
  4499. } else
  4500. clif_send(buf,packet_len(0x1de),dst,AREA);
  4501. if(disguised(src)) {
  4502. WBUFL(buf,4)=-src->id;
  4503. if (disguised(dst))
  4504. WBUFL(buf,8)=dst->id;
  4505. if(damage > 0)
  4506. WBUFL(buf,24)=-1;
  4507. clif_send(buf,packet_len(0x1de),src,SELF);
  4508. }
  4509. #endif
  4510. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4511. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4512. }
  4513. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4514. /// 0115 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <x>.W <y>.W <damage>.W <level>.W <div>.W <type>.B
  4515. /*
  4516. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4517. {
  4518. unsigned char buf[64];
  4519. struct status_change *sc;
  4520. nullpo_ret(src);
  4521. nullpo_ret(dst);
  4522. type = (type>0)?type:skill_get_hit(skill_id);
  4523. type = clif_calc_delay(type,div,damage,ddelay);
  4524. sc = status_get_sc(dst);
  4525. if(sc && sc->count) {
  4526. if(sc->data[SC_HALLUCINATION] && damage)
  4527. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4528. }
  4529. WBUFW(buf,0)=0x115;
  4530. WBUFW(buf,2)=skill_id;
  4531. WBUFL(buf,4)=src->id;
  4532. WBUFL(buf,8)=dst->id;
  4533. WBUFL(buf,12)=tick;
  4534. WBUFL(buf,16)=sdelay;
  4535. WBUFL(buf,20)=ddelay;
  4536. WBUFW(buf,24)=dst->x;
  4537. WBUFW(buf,26)=dst->y;
  4538. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4539. WBUFW(buf,28)=damage?div:0;
  4540. } else {
  4541. WBUFW(buf,28)=damage;
  4542. }
  4543. WBUFW(buf,30)=skill_lv;
  4544. WBUFW(buf,32)=div;
  4545. WBUFB(buf,34)=type;
  4546. clif_send(buf,packet_len(0x115),src,AREA);
  4547. if(disguised(src)) {
  4548. WBUFL(buf,4)=-src->id;
  4549. if(damage > 0)
  4550. WBUFW(buf,28)=-1;
  4551. clif_send(buf,packet_len(0x115),src,SELF);
  4552. }
  4553. if (disguised(dst)) {
  4554. WBUFL(buf,8)=-dst->id;
  4555. if (disguised(src))
  4556. WBUFL(buf,4)=src->id;
  4557. else if(damage > 0)
  4558. WBUFW(buf,28)=-1;
  4559. clif_send(buf,packet_len(0x115),dst,SELF);
  4560. }
  4561. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4562. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4563. }
  4564. */
  4565. /// Non-damaging skill effect (ZC_USE_SKILL).
  4566. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4567. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4568. {
  4569. unsigned char buf[32];
  4570. nullpo_ret(dst);
  4571. WBUFW(buf,0)=0x11a;
  4572. WBUFW(buf,2)=skill_id;
  4573. WBUFW(buf,4)=min(heal, INT16_MAX);
  4574. WBUFL(buf,6)=dst->id;
  4575. WBUFL(buf,10)=src?src->id:0;
  4576. WBUFB(buf,14)=fail;
  4577. if (disguised(dst)) {
  4578. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4579. WBUFL(buf,6)=-dst->id;
  4580. clif_send(buf,packet_len(0x11a),dst,SELF);
  4581. } else
  4582. clif_send(buf,packet_len(0x11a),dst,AREA);
  4583. if(src && disguised(src)) {
  4584. WBUFL(buf,10)=-src->id;
  4585. if (disguised(dst))
  4586. WBUFL(buf,6)=dst->id;
  4587. clif_send(buf,packet_len(0x11a),src,SELF);
  4588. }
  4589. return fail;
  4590. }
  4591. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4592. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4593. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4594. {
  4595. unsigned char buf[32];
  4596. nullpo_retv(src);
  4597. WBUFW(buf,0)=0x117;
  4598. WBUFW(buf,2)=skill_id;
  4599. WBUFL(buf,4)=src->id;
  4600. WBUFW(buf,8)=val;
  4601. WBUFW(buf,10)=x;
  4602. WBUFW(buf,12)=y;
  4603. WBUFL(buf,14)=tick;
  4604. if(disguised(src)) {
  4605. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4606. WBUFL(buf,4)=-src->id;
  4607. clif_send(buf,packet_len(0x117),src,SELF);
  4608. } else
  4609. clif_send(buf,packet_len(0x117),src,AREA);
  4610. }
  4611. /*==========================================
  4612. * Tells all client's nearby 'unit' sight range that it spawned
  4613. *------------------------------------------*/
  4614. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4615. void clif_skill_setunit(struct skill_unit *unit)
  4616. {
  4617. unsigned char buf[128];
  4618. nullpo_retv(unit);
  4619. if( unit->group->state.guildaura )
  4620. return;
  4621. #if PACKETVER >= 3
  4622. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4623. WBUFW(buf, 0)=0x1c9;
  4624. WBUFL(buf, 2)=unit->bl.id;
  4625. WBUFL(buf, 6)=unit->group->src_id;
  4626. WBUFW(buf,10)=unit->bl.x;
  4627. WBUFW(buf,12)=unit->bl.y;
  4628. WBUFB(buf,14)=unit->group->unit_id;
  4629. WBUFB(buf,15)=1;
  4630. WBUFB(buf,16)=1;
  4631. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4632. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4633. return;
  4634. }
  4635. #endif
  4636. WBUFW(buf, 0)=0x11f;
  4637. WBUFL(buf, 2)=unit->bl.id;
  4638. WBUFL(buf, 6)=unit->group->src_id;
  4639. WBUFW(buf,10)=unit->bl.x;
  4640. WBUFW(buf,12)=unit->bl.y;
  4641. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4642. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4643. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4644. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4645. else
  4646. WBUFB(buf,14)=unit->group->unit_id;
  4647. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4648. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4649. }
  4650. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4651. /// 011c <skill id>.W { <map name>.16B }*4
  4652. void clif_skill_warppoint(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4653. {
  4654. int fd;
  4655. nullpo_retv(sd);
  4656. fd = sd->fd;
  4657. WFIFOHEAD(fd,packet_len(0x11c));
  4658. WFIFOW(fd,0) = 0x11c;
  4659. WFIFOW(fd,2) = skill_id;
  4660. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4661. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4662. else // normal map name
  4663. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4664. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4665. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4666. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4667. WFIFOSET(fd,packet_len(0x11c));
  4668. sd->menuskill_id = skill_id;
  4669. if (skill_id == AL_WARP)
  4670. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4671. else
  4672. sd->menuskill_val = skill_lv;
  4673. }
  4674. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4675. /// 011e <type>.B
  4676. /// type:
  4677. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4678. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4679. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4680. ///
  4681. /// @param sd Who receives the message
  4682. /// @param type What message
  4683. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4684. {
  4685. int fd;
  4686. nullpo_retv(sd);
  4687. fd=sd->fd;
  4688. WFIFOHEAD(fd,packet_len(0x11e));
  4689. WFIFOW(fd,0)=0x11e;
  4690. WFIFOB(fd,2)=type;
  4691. WFIFOSET(fd,packet_len(0x11e));
  4692. }
  4693. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4694. /// 0189 <type>.W
  4695. /// type:
  4696. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4697. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4698. ///
  4699. /// @param sd Who receives the message
  4700. /// @param type What message
  4701. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4702. {
  4703. int fd;
  4704. nullpo_retv(sd);
  4705. fd=sd->fd;
  4706. WFIFOHEAD(fd,packet_len(0x189));
  4707. WFIFOW(fd,0)=0x189;
  4708. WFIFOW(fd,2)=type;
  4709. WFIFOSET(fd,packet_len(0x189));
  4710. }
  4711. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4712. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4713. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4714. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4715. {
  4716. struct status_data *status;
  4717. unsigned char buf[64];
  4718. int i;//, fix;
  4719. nullpo_retv(sd);
  4720. nullpo_retv(dst);
  4721. if( dst->type != BL_MOB )
  4722. return;
  4723. status = status_get_status_data(dst);
  4724. WBUFW(buf, 0)=0x18c;
  4725. WBUFW(buf, 2)=status_get_class(dst);
  4726. WBUFW(buf, 4)=status_get_lv(dst);
  4727. WBUFW(buf, 6)=status->size;
  4728. WBUFL(buf, 8)=status->hp;
  4729. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4730. +(battle_config.estimation_type&2?status->def2:0);
  4731. WBUFW(buf,14)=status->race;
  4732. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4733. +(battle_config.estimation_type&2?status->mdef2:0);
  4734. WBUFW(buf,18)= status->def_ele;
  4735. for(i=0;i<9;i++)
  4736. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4737. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4738. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4739. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4740. }
  4741. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4742. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4743. /// material id:
  4744. /// unused by the client
  4745. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4746. {
  4747. int i,c,view,fd;
  4748. nullpo_retv(sd);
  4749. if(sd->menuskill_id == skill_id)
  4750. return; //Avoid resending the menu twice or more times...
  4751. if( skill_id == GC_CREATENEWPOISON )
  4752. skill_id = GC_RESEARCHNEWPOISON;
  4753. fd=sd->fd;
  4754. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4755. WFIFOW(fd, 0)=0x18d;
  4756. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4757. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4758. ( ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4759. ){
  4760. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4761. WFIFOW(fd,c*8+ 4)= view;
  4762. else
  4763. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4764. WFIFOW(fd,c*8+ 6)= 0;
  4765. WFIFOW(fd,c*8+ 8)= 0;
  4766. WFIFOW(fd,c*8+10)= 0;
  4767. c++;
  4768. }
  4769. }
  4770. WFIFOW(fd, 2)=c*8+8;
  4771. WFIFOSET(fd,WFIFOW(fd,2));
  4772. if(c > 0) {
  4773. sd->menuskill_id = skill_id;
  4774. sd->menuskill_val = trigger;
  4775. return;
  4776. }
  4777. }
  4778. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4779. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4780. /// mk type:
  4781. /// 1 = cooking
  4782. /// 2 = arrow
  4783. /// 3 = elemental
  4784. /// 4 = GN_MIX_COOKING
  4785. /// 5 = GN_MAKEBOMB
  4786. /// 6 = GN_S_PHARMACY
  4787. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4788. {
  4789. int fd;
  4790. int i, c;
  4791. int view;
  4792. nullpo_retv(sd);
  4793. fd = sd->fd;
  4794. if(sd->menuskill_id == skill_id)
  4795. return; //Avoid resending the menu twice or more times...
  4796. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4797. WFIFOW(fd,0) = 0x25a;
  4798. WFIFOW(fd,4) = list_type; // list type
  4799. c = 0;
  4800. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4801. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4802. continue;
  4803. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4804. WFIFOW(fd, 6 + 2 * c) = view;
  4805. else
  4806. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4807. c++;
  4808. }
  4809. if( c > 0 || skill_id == AM_PHARMACY) {
  4810. sd->menuskill_id = skill_id;
  4811. sd->menuskill_val = trigger;
  4812. sd->menuskill_val2 = qty; // amount.
  4813. WFIFOW(fd,2) = 6 + 2 * c;
  4814. WFIFOSET(fd,WFIFOW(fd,2));
  4815. } else {
  4816. clif_menuskill_clear(sd);
  4817. #if PACKETVER >= 20090922
  4818. clif_msg_skill(sd,skill_id,0x625);
  4819. #else
  4820. WFIFOW(fd,2) = 6 + 2 * c;
  4821. WFIFOSET(fd,WFIFOW(fd,2));
  4822. #endif
  4823. }
  4824. }
  4825. /// Notifies clients of a status change.
  4826. /// 0196 <index>.W <id>.L <state>.B (ZC_MSG_STATE_CHANGE) [used for ending status changes and starting them on non-pc units (when needed)]
  4827. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4828. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4829. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4830. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4831. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4832. {
  4833. unsigned char buf[32];
  4834. struct map_session_data *sd;
  4835. if (type == SI_BLANK) //It shows nothing on the client...
  4836. return;
  4837. nullpo_retv(bl);
  4838. sd = BL_CAST(BL_PC, bl);
  4839. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4840. return;
  4841. #if PACKETVER >= 20120618
  4842. if(flag && battle_config.display_status_timers && sd)
  4843. WBUFW(buf,0)=0x983;
  4844. else
  4845. #elif PACKETVER >= 20090121
  4846. if(flag && battle_config.display_status_timers && sd)
  4847. WBUFW(buf,0)=0x43f;
  4848. else
  4849. #endif
  4850. WBUFW(buf,0)=0x196;
  4851. WBUFW(buf,2)=type;
  4852. WBUFL(buf,4)=bl->id;
  4853. WBUFB(buf,8)=flag;
  4854. #if PACKETVER >= 20120618
  4855. if(flag && battle_config.display_status_timers && sd) {
  4856. if (tick <= 0)
  4857. tick = 9999; // this is indeed what official servers do
  4858. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4859. WBUFL(buf,13)=tick;
  4860. WBUFL(buf,17) = val1;
  4861. WBUFL(buf,21) = val2;
  4862. WBUFL(buf,25) = val3;
  4863. }
  4864. #elif PACKETVER >= 20090121
  4865. if(flag && battle_config.display_status_timers && sd) {
  4866. if (tick <= 0)
  4867. tick = 9999; // this is indeed what official servers do
  4868. WBUFL(buf,9) = tick;
  4869. WBUFL(buf,13) = val1;
  4870. WBUFL(buf,17) = val2;
  4871. WBUFL(buf,21) = val3;
  4872. }
  4873. #endif
  4874. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4875. }
  4876. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4877. /// 008e <packet len>.W <message>.?B
  4878. void clif_displaymessage(const int fd, const char* mes)
  4879. {
  4880. nullpo_retv(mes);
  4881. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4882. if (fd == 0)
  4883. ;
  4884. else {
  4885. char *message, *line;
  4886. message = aStrdup(mes);
  4887. line = strtok(message, "\n");
  4888. while(line != NULL) {
  4889. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4890. int len = strnlen(line, 255);
  4891. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4892. WFIFOHEAD(fd, 5 + len);
  4893. WFIFOW(fd,0) = 0x8e;
  4894. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4895. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4896. WFIFOSET(fd, 5 + len);
  4897. }
  4898. line = strtok(NULL, "\n");
  4899. }
  4900. aFree(message);
  4901. }
  4902. }
  4903. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4904. /// 009a <packet len>.W <message>.?B
  4905. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4906. {
  4907. int lp = type ? 4 : 0;
  4908. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4909. WBUFW(buf,0) = 0x9a;
  4910. WBUFW(buf,2) = 4 + lp + len;
  4911. if (type == 0x10) // bc_blue
  4912. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4913. else if (type == 0x20) // bc_woe
  4914. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4915. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4916. clif_send(buf, WBUFW(buf,2), bl, target);
  4917. if (buf)
  4918. aFree(buf);
  4919. }
  4920. /*==========================================
  4921. * Displays a message on a 'bl' to all it's nearby clients
  4922. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4923. *------------------------------------------*/
  4924. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4925. char buf[100];
  4926. int len;
  4927. nullpo_retv(bl);
  4928. if(!message)
  4929. return;
  4930. len = strlen(message)+1;
  4931. if( len > sizeof(buf)-8 ) {
  4932. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4933. len = sizeof(buf)-8;
  4934. }
  4935. WBUFW(buf,0)=0x8d;
  4936. WBUFW(buf,2)=len+8;
  4937. WBUFL(buf,4)=bl->id;
  4938. safestrncpy((char *) WBUFP(buf,8),message,len);
  4939. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4940. }
  4941. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4942. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4943. void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  4944. {
  4945. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4946. WBUFW(buf,0) = 0x1c3;
  4947. WBUFW(buf,2) = len + 16;
  4948. WBUFL(buf,4) = fontColor;
  4949. WBUFW(buf,8) = fontType;
  4950. WBUFW(buf,10) = fontSize;
  4951. WBUFW(buf,12) = fontAlign;
  4952. WBUFW(buf,14) = fontY;
  4953. memcpy(WBUFP(buf,16), mes, len);
  4954. clif_send(buf, WBUFW(buf,2), bl, target);
  4955. if (buf)
  4956. aFree(buf);
  4957. }
  4958. /*
  4959. * Display *msg from *sd to all *users in channel
  4960. */
  4961. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4962. DBIterator *iter;
  4963. struct map_session_data *user;
  4964. unsigned short msg_len = strlen(msg) + 1;
  4965. WFIFOHEAD(sd->fd,msg_len + 12);
  4966. WFIFOW(sd->fd,0) = 0x2C1;
  4967. WFIFOW(sd->fd,2) = msg_len + 12;
  4968. WFIFOL(sd->fd,4) = 0;
  4969. WFIFOL(sd->fd,8) = Channel_Config.colors[color];
  4970. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4971. iter = db_iterator(channel->users);
  4972. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4973. if( user->fd == sd->fd )
  4974. continue;
  4975. WFIFOHEAD(user->fd,msg_len + 12);
  4976. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4977. WFIFOSET(user->fd, msg_len + 12);
  4978. }
  4979. dbi_destroy(iter);
  4980. WFIFOSET(sd->fd, msg_len + 12);
  4981. }
  4982. /// Displays heal effect (ZC_RECOVERY).
  4983. /// 013d <var id>.W <amount>.W
  4984. /// var id:
  4985. /// 5 = HP (SP_HP)
  4986. /// 7 = SP (SP_SP)
  4987. /// ? = ignored
  4988. void clif_heal(int fd,int type,int val)
  4989. {
  4990. WFIFOHEAD(fd,packet_len(0x13d));
  4991. WFIFOW(fd,0)=0x13d;
  4992. WFIFOW(fd,2)=type;
  4993. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4994. WFIFOSET(fd,packet_len(0x13d));
  4995. }
  4996. /// Displays resurrection effect (ZC_RESURRECTION).
  4997. /// 0148 <id>.L <type>.W
  4998. /// type:
  4999. /// ignored
  5000. void clif_resurrection(struct block_list *bl,int type)
  5001. {
  5002. unsigned char buf[16];
  5003. nullpo_retv(bl);
  5004. WBUFW(buf,0)=0x148;
  5005. WBUFL(buf,2)=bl->id;
  5006. WBUFW(buf,6)=0;
  5007. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5008. if (disguised(bl))
  5009. clif_spawn(bl);
  5010. }
  5011. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5012. /// 0199 <type>.W
  5013. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5014. {
  5015. int fd;
  5016. nullpo_retv(sd);
  5017. fd=sd->fd;
  5018. WFIFOHEAD(fd,packet_len(0x199));
  5019. WFIFOW(fd,0)=0x199;
  5020. WFIFOW(fd,2)=property;
  5021. WFIFOSET(fd,packet_len(0x199));
  5022. }
  5023. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5024. #if PACKETVER >= 20130000
  5025. uint8 buf[8];
  5026. WBUFW(buf,0)=0x99b; //2
  5027. WBUFW(buf,2)=0x28; //2
  5028. WBUFB(buf,4) = ((map_flag_vs(bl->m))?0x01:0); //tvt ?
  5029. WBUFB(buf,4) |= ((map_flag_gvg(bl->m))?0x02:0); //gvg
  5030. WBUFB(buf,4) |= ((map_flag_gvg2(bl->m))?0x04:0); //siege
  5031. WBUFB(buf,4) |= (map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m))?0:0x08; //disable mine effect on nomineeffect map and enable it on gvgmap by default
  5032. WBUFB(buf,4) |= ((map[bl->m].flag.nolockon)?0x10:0); //nolockon 0x10 @FIXME what this do
  5033. WBUFB(buf,4) |= ((map[bl->m].flag.pvp)?0x20:0); //countpk
  5034. WBUFB(buf,4) |= 0; //nopartyformation 0x40
  5035. WBUFB(buf,4) |= ((map[bl->m].flag.battleground)?0x80:0); //battleground
  5036. WBUFB(buf,5) = ((map[bl->m].flag.noitemconsumption)?0x01:0); //noitemconsumption
  5037. WBUFB(buf,5) |= ((map[bl->m].flag.nousecart)?0:0x02); // usecart
  5038. WBUFB(buf,5) |= ((map[bl->m].flag.nosumstarmiracle)?0:0x04); //summonstarmiracle
  5039. // WBUFB(buf,5) |= RBUFB(buf,5)&0xf8; //sparebit[0-4]
  5040. WBUFW(buf,6) = 0; //sparebit [5-15], + extra[4]
  5041. clif_send(buf,packet_len(0x99b),bl,t);
  5042. #endif
  5043. }
  5044. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5045. /// 01d6 <type>.W
  5046. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5047. {
  5048. int fd;
  5049. nullpo_retv(sd);
  5050. fd=sd->fd;
  5051. WFIFOHEAD(fd,packet_len(0x1D6));
  5052. WFIFOW(fd,0)=0x1D6;
  5053. WFIFOW(fd,2)=type;
  5054. WFIFOSET(fd,packet_len(0x1D6));
  5055. }
  5056. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5057. /// 019a <id>.L <ranking>.L <total>.L
  5058. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5059. {
  5060. if(type == 2) {
  5061. int fd = sd->fd;
  5062. WFIFOHEAD(fd,packet_len(0x19a));
  5063. WFIFOW(fd,0) = 0x19a;
  5064. WFIFOL(fd,2) = sd->bl.id;
  5065. WFIFOL(fd,6) = pvprank;
  5066. WFIFOL(fd,10) = pvpnum;
  5067. WFIFOSET(fd,packet_len(0x19a));
  5068. } else {
  5069. unsigned char buf[32];
  5070. WBUFW(buf,0) = 0x19a;
  5071. WBUFL(buf,2) = sd->bl.id;
  5072. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5073. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5074. else
  5075. WBUFL(buf,6) = pvprank;
  5076. WBUFL(buf,10) = pvpnum;
  5077. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5078. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5079. else if(!type)
  5080. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5081. else
  5082. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5083. }
  5084. }
  5085. /*==========================================
  5086. *
  5087. *------------------------------------------*/
  5088. void clif_map_property_mapall(int map, enum map_property property)
  5089. {
  5090. struct block_list bl;
  5091. unsigned char buf[16];
  5092. bl.id = 0;
  5093. bl.type = BL_NUL;
  5094. bl.m = map;
  5095. WBUFW(buf,0)=0x199;
  5096. WBUFW(buf,2)=property;
  5097. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5098. }
  5099. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5100. /// 0188 <result>.W <index>.W <refine>.W
  5101. /// result:
  5102. /// 0 = success
  5103. /// 1 = failure
  5104. /// 2 = downgrade
  5105. void clif_refine(int fd, int fail, int index, int val)
  5106. {
  5107. WFIFOHEAD(fd,packet_len(0x188));
  5108. WFIFOW(fd,0)=0x188;
  5109. WFIFOW(fd,2)=fail;
  5110. WFIFOW(fd,4)=index+2;
  5111. WFIFOW(fd,6)=val;
  5112. WFIFOSET(fd,packet_len(0x188));
  5113. }
  5114. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5115. /// 0223 <result>.L <nameid>.W
  5116. /// result:
  5117. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5118. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5119. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5120. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5121. void clif_upgrademessage(int fd, int result, int item_id)
  5122. {
  5123. WFIFOHEAD(fd,packet_len(0x223));
  5124. WFIFOW(fd,0)=0x223;
  5125. WFIFOL(fd,2)=result;
  5126. WFIFOW(fd,6)=item_id;
  5127. WFIFOSET(fd,packet_len(0x223));
  5128. }
  5129. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5130. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5131. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5132. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5133. {
  5134. #if PACKETVER < 20091104
  5135. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5136. WFIFOW(fd,0) = 0x97;
  5137. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5138. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5139. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5140. WFIFOSET(fd,WFIFOW(fd,2));
  5141. #else
  5142. struct map_session_data *ssd = map_nick2sd(nick);
  5143. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5144. WFIFOW(fd,0) = 0x97;
  5145. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5146. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5147. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5148. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5149. WFIFOSET(fd,WFIFOW(fd,2));
  5150. #endif
  5151. }
  5152. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5153. /// 0098 <result>.B
  5154. /// result:
  5155. /// 0 = success to send wisper
  5156. /// 1 = target character is not loged in
  5157. /// 2 = ignored by target
  5158. /// 3 = everyone ignored by target
  5159. void clif_wis_end(int fd, int flag)
  5160. {
  5161. WFIFOHEAD(fd,packet_len(0x98));
  5162. WFIFOW(fd,0) = 0x98;
  5163. WFIFOW(fd,2) = flag;
  5164. WFIFOSET(fd,packet_len(0x98));
  5165. }
  5166. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5167. /// 0194 <char id>.L <name>.24B
  5168. void clif_solved_charname(int fd, int charid, const char* name)
  5169. {
  5170. WFIFOHEAD(fd,packet_len(0x194));
  5171. WFIFOW(fd,0)=0x194;
  5172. WFIFOL(fd,2)=charid;
  5173. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5174. WFIFOSET(fd,packet_len(0x194));
  5175. }
  5176. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5177. /// 017b <packet len>.W { <name id>.W }*
  5178. void clif_use_card(struct map_session_data *sd,int idx)
  5179. {
  5180. int i,c,ep;
  5181. int fd=sd->fd;
  5182. nullpo_retv(sd);
  5183. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5184. return;
  5185. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5186. return; //Avoid parsing invalid item indexes (no card/no item)
  5187. ep=sd->inventory_data[idx]->equip;
  5188. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5189. WFIFOW(fd,0)=0x17b;
  5190. for(i=c=0;i<MAX_INVENTORY;i++){
  5191. int j;
  5192. if(sd->inventory_data[i] == NULL)
  5193. continue;
  5194. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5195. continue;
  5196. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5197. continue;
  5198. if(sd->status.inventory[i].identify==0 ) //Not identified
  5199. continue;
  5200. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5201. continue;
  5202. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5203. continue;
  5204. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5205. if( j == sd->inventory_data[i]->slot ) // No room
  5206. continue;
  5207. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5208. continue;
  5209. WFIFOW(fd,4+c*2)=i+2;
  5210. c++;
  5211. }
  5212. if( !c ) return; // no item is available for card insertion
  5213. WFIFOW(fd,2)=4+c*2;
  5214. WFIFOSET(fd,WFIFOW(fd,2));
  5215. }
  5216. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5217. /// 017d <equip index>.W <card index>.W <result>.B
  5218. /// result:
  5219. /// 0 = success
  5220. /// 1 = failure
  5221. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5222. {
  5223. int fd;
  5224. nullpo_retv(sd);
  5225. fd=sd->fd;
  5226. WFIFOHEAD(fd,packet_len(0x17d));
  5227. WFIFOW(fd,0)=0x17d;
  5228. WFIFOW(fd,2)=idx_equip+2;
  5229. WFIFOW(fd,4)=idx_card+2;
  5230. WFIFOB(fd,6)=flag;
  5231. WFIFOSET(fd,packet_len(0x17d));
  5232. }
  5233. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5234. /// 0177 <packet len>.W { <name id>.W }*
  5235. void clif_item_identify_list(struct map_session_data *sd)
  5236. {
  5237. int i,c;
  5238. int fd;
  5239. nullpo_retv(sd);
  5240. fd=sd->fd;
  5241. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5242. WFIFOW(fd,0)=0x177;
  5243. for(i=c=0;i<MAX_INVENTORY;i++){
  5244. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5245. WFIFOW(fd,c*2+4)=i+2;
  5246. c++;
  5247. }
  5248. }
  5249. if(c > 0) {
  5250. WFIFOW(fd,2)=c*2+4;
  5251. WFIFOSET(fd,WFIFOW(fd,2));
  5252. sd->menuskill_id = MC_IDENTIFY;
  5253. sd->menuskill_val = c;
  5254. }
  5255. }
  5256. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5257. /// 0179 <index>.W <result>.B
  5258. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5259. {
  5260. int fd;
  5261. nullpo_retv(sd);
  5262. fd=sd->fd;
  5263. WFIFOHEAD(fd,packet_len(0x179));
  5264. WFIFOW(fd, 0)=0x179;
  5265. WFIFOW(fd, 2)=idx+2;
  5266. WFIFOB(fd, 4)=flag;
  5267. WFIFOSET(fd,packet_len(0x179));
  5268. }
  5269. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5270. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5271. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5272. {
  5273. int i,c;
  5274. int fd;
  5275. int nameid;
  5276. nullpo_retv(sd);
  5277. nullpo_retv(dstsd);
  5278. fd=sd->fd;
  5279. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5280. WFIFOW(fd,0)=0x1fc;
  5281. for(i=c=0;i<MAX_INVENTORY;i++){
  5282. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5283. WFIFOW(fd,c*13+4) = i;
  5284. WFIFOW(fd,c*13+6) = nameid;
  5285. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5286. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5287. c++;
  5288. }
  5289. }
  5290. if(c > 0) {
  5291. WFIFOW(fd,2)=c*13+4;
  5292. WFIFOSET(fd,WFIFOW(fd,2));
  5293. sd->menuskill_id = BS_REPAIRWEAPON;
  5294. sd->menuskill_val = dstsd->bl.id;
  5295. sd->menuskill_val2 = lv;
  5296. }else
  5297. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5298. }
  5299. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5300. /// 01fe <index>.W <result>.B
  5301. /// index:
  5302. /// ignored (inventory index)
  5303. /// result:
  5304. /// 0 = Item repair success.
  5305. /// 1 = Item repair failure.
  5306. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5307. {
  5308. int fd;
  5309. nullpo_retv(sd);
  5310. fd = sd->fd;
  5311. WFIFOHEAD(fd,packet_len(0x1fe));
  5312. WFIFOW(fd, 0)=0x1fe;
  5313. WFIFOW(fd, 2)=idx+2;
  5314. WFIFOB(fd, 4)=flag;
  5315. WFIFOSET(fd,packet_len(0x1fe));
  5316. }
  5317. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5318. /// 02bb <equip location>.W <account id>.L
  5319. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5320. {
  5321. int fd = sd->fd;
  5322. WFIFOHEAD(fd,packet_len(0x2bb));
  5323. WFIFOW(fd,0) = 0x2bb;
  5324. WFIFOW(fd,2) = position;
  5325. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5326. WFIFOSET(fd,packet_len(0x2bb));
  5327. }
  5328. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5329. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5330. void clif_item_refine_list(struct map_session_data *sd)
  5331. {
  5332. int i,c;
  5333. int fd;
  5334. uint16 skill_lv;
  5335. int wlv;
  5336. int refine_item[5];
  5337. nullpo_retv(sd);
  5338. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5339. fd=sd->fd;
  5340. refine_item[0] = -1;
  5341. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5342. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5343. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5344. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5345. WFIFOW(fd,0)=0x221;
  5346. for(i=c=0;i<MAX_INVENTORY;i++){
  5347. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5348. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5349. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5350. WFIFOW(fd,c*13+ 4)=i+2;
  5351. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5352. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5353. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5354. c++;
  5355. }
  5356. }
  5357. WFIFOW(fd,2)=c*13+4;
  5358. WFIFOSET(fd,WFIFOW(fd,2));
  5359. if (c > 0) {
  5360. sd->menuskill_id = WS_WEAPONREFINE;
  5361. sd->menuskill_val = skill_lv;
  5362. }
  5363. }
  5364. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5365. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5366. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5367. {
  5368. int fd;
  5369. nullpo_retv(sd);
  5370. fd=sd->fd;
  5371. WFIFOHEAD(fd,packet_len(0x147));
  5372. WFIFOW(fd, 0)=0x147;
  5373. WFIFOW(fd, 2)=skill_id;
  5374. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5375. WFIFOW(fd, 6)=0;
  5376. WFIFOW(fd, 8)=skill_lv;
  5377. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5378. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5379. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5380. WFIFOB(fd,38)=0;
  5381. WFIFOSET(fd,packet_len(0x147));
  5382. }
  5383. /// Adds an item to character's cart.
  5384. /// 0124 <index>.W <amount>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART)
  5385. /// 01c5 <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART2)
  5386. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5387. {
  5388. int view,fd;
  5389. unsigned char *buf;
  5390. nullpo_retv(sd);
  5391. fd=sd->fd;
  5392. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5393. return;
  5394. #if PACKETVER < 5
  5395. WFIFOHEAD(fd,packet_len(0x124));
  5396. buf=WFIFOP(fd,0);
  5397. WBUFW(buf,0)=0x124;
  5398. WBUFW(buf,2)=n+2;
  5399. WBUFL(buf,4)=amount;
  5400. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5401. WBUFW(buf,8)=view;
  5402. else
  5403. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5404. WBUFB(buf,10)=sd->status.cart[n].identify;
  5405. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5406. WBUFB(buf,12)=sd->status.cart[n].refine;
  5407. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5408. WFIFOSET(fd,packet_len(0x124));
  5409. #else
  5410. WFIFOHEAD(fd,packet_len(0x1c5));
  5411. buf=WFIFOP(fd,0);
  5412. WBUFW(buf,0)=0x1c5;
  5413. WBUFW(buf,2)=n+2;
  5414. WBUFL(buf,4)=amount;
  5415. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5416. WBUFW(buf,8)=view;
  5417. else
  5418. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5419. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5420. WBUFB(buf,11)=sd->status.cart[n].identify;
  5421. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5422. WBUFB(buf,13)=sd->status.cart[n].refine;
  5423. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5424. WFIFOSET(fd,packet_len(0x1c5));
  5425. #endif
  5426. }
  5427. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5428. /* Acknowledge an item have been added to cart
  5429. * 012c <result>B
  5430. * result :
  5431. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5432. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5433. */
  5434. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5435. {
  5436. int fd;
  5437. unsigned char *buf;
  5438. nullpo_retv(sd);
  5439. fd = sd->fd;
  5440. buf = WFIFOP(fd,0);
  5441. WBUFW(buf,0) = 0x12c;
  5442. WBUFB(buf,2) = flag;
  5443. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5444. }
  5445. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5446. void clif_bank_open(struct map_session_data *sd){
  5447. int fd;
  5448. nullpo_retv(sd);
  5449. fd = sd->fd;
  5450. WFIFOHEAD(fd,4);
  5451. WFIFOW(fd,0) = 0x09b7;
  5452. WFIFOW(fd,2) = 0;
  5453. WFIFOSET(fd,4);
  5454. }
  5455. /*
  5456. * Request to Open the banking system
  5457. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5458. */
  5459. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5460. //TODO check if preventing trade or stuff like that
  5461. //also mark something in case char ain't available for saving, should we check now ?
  5462. nullpo_retv(sd);
  5463. if( !battle_config.feature_banking ) {
  5464. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5465. return;
  5466. }
  5467. else {
  5468. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5469. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5470. if(sd->status.account_id == aid){
  5471. sd->state.banking = 1;
  5472. //request save ?
  5473. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5474. //on succes open bank ?
  5475. clif_bank_open(sd);
  5476. }
  5477. }
  5478. }
  5479. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5480. void clif_bank_close(struct map_session_data *sd){
  5481. int fd;
  5482. nullpo_retv(sd);
  5483. fd = sd->fd;
  5484. WFIFOHEAD(fd,4);
  5485. WFIFOW(fd,0) = 0x09B9;
  5486. WFIFOW(fd,2) = 0;
  5487. WFIFOSET(fd,4);
  5488. }
  5489. /*
  5490. * Request to close the banking system
  5491. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5492. */
  5493. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5494. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5495. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5496. nullpo_retv(sd);
  5497. if( !battle_config.feature_banking ) {
  5498. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5499. //still allow to go trough to not stuck player if we have disable it while they was in
  5500. }
  5501. if(sd->status.account_id == aid){
  5502. sd->state.banking = 0;
  5503. clif_bank_close(sd);
  5504. }
  5505. }
  5506. /*
  5507. * Display how much we got in bank (I suppose)
  5508. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5509. */
  5510. void clif_Bank_Check(struct map_session_data* sd) {
  5511. unsigned char buf[13];
  5512. struct s_packet_db* info;
  5513. int16 len;
  5514. int cmd = 0;
  5515. nullpo_retv(sd);
  5516. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5517. if(!cmd) cmd = 0x09A6; //default
  5518. info = &packet_db[sd->packet_ver][cmd];
  5519. len = info->len;
  5520. if(!len) return; //version as packet disable
  5521. // sd->state.banking = 1; //mark opening and closing
  5522. WBUFW(buf,0) = cmd;
  5523. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5524. WBUFW(buf,info->pos[1]) = 0; //reason
  5525. clif_send(buf,len,&sd->bl,SELF);
  5526. }
  5527. /*
  5528. * Requesting the data in bank
  5529. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5530. */
  5531. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5532. nullpo_retv(sd);
  5533. if( !battle_config.feature_banking ) {
  5534. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5535. return;
  5536. }
  5537. else {
  5538. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5539. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5540. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5541. clif_Bank_Check(sd);
  5542. }
  5543. }
  5544. /*
  5545. * Acknowledge of deposit some money in bank
  5546. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5547. */
  5548. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5549. unsigned char buf[17];
  5550. struct s_packet_db* info;
  5551. int16 len;
  5552. int cmd =0;
  5553. nullpo_retv(sd);
  5554. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5555. if(!cmd) cmd = 0x09A8;
  5556. info = &packet_db[sd->packet_ver][cmd];
  5557. len = info->len;
  5558. if(!len) return; //version as packet disable
  5559. WBUFW(buf,0) = cmd;
  5560. WBUFW(buf,info->pos[0]) = (short)reason;
  5561. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5562. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5563. clif_send(buf,len,&sd->bl,SELF);
  5564. }
  5565. /*
  5566. * Request saving some money in bank
  5567. * @author : original [Yommy/Hercules]
  5568. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5569. */
  5570. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5571. nullpo_retv(sd);
  5572. if( !battle_config.feature_banking ) {
  5573. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5574. return;
  5575. }
  5576. else {
  5577. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5578. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5579. int money = RFIFOL(fd,info->pos[1]);
  5580. if(sd->status.account_id == aid){
  5581. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5582. clif_bank_deposit(sd,reason);
  5583. }
  5584. }
  5585. }
  5586. /*
  5587. * Acknowledge of withdrawing some money from bank
  5588. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5589. */
  5590. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5591. unsigned char buf[17];
  5592. struct s_packet_db* info;
  5593. int16 len;
  5594. int cmd;
  5595. nullpo_retv(sd);
  5596. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5597. if(!cmd) cmd = 0x09AA;
  5598. info = &packet_db[sd->packet_ver][cmd];
  5599. len = info->len;
  5600. if(!len) return; //version as packet disable
  5601. WBUFW(buf,0) = cmd;
  5602. WBUFW(buf,info->pos[0]) = (short)reason;
  5603. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5604. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5605. clif_send(buf,len,&sd->bl,SELF);
  5606. }
  5607. /*
  5608. * Request Withdrawing some money from bank
  5609. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5610. */
  5611. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5612. nullpo_retv(sd);
  5613. if( !battle_config.feature_banking ) {
  5614. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5615. return;
  5616. }
  5617. else {
  5618. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5619. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5620. int money = RFIFOL(fd,info->pos[1]);
  5621. if(sd->status.account_id == aid){
  5622. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5623. clif_bank_withdraw(sd,reason);
  5624. }
  5625. }
  5626. }
  5627. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5628. /// 0125 <index>.W <amount>.L
  5629. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5630. {
  5631. int fd;
  5632. nullpo_retv(sd);
  5633. fd=sd->fd;
  5634. WFIFOHEAD(fd,packet_len(0x125));
  5635. WFIFOW(fd,0)=0x125;
  5636. WFIFOW(fd,2)=n+2;
  5637. WFIFOL(fd,4)=amount;
  5638. WFIFOSET(fd,packet_len(0x125));
  5639. }
  5640. /// Opens the shop creation menu (ZC_OPENSTORE).
  5641. /// 012d <num>.W
  5642. /// num:
  5643. /// number of allowed item slots
  5644. void clif_openvendingreq(struct map_session_data* sd, int num)
  5645. {
  5646. int fd;
  5647. nullpo_retv(sd);
  5648. fd = sd->fd;
  5649. WFIFOHEAD(fd,packet_len(0x12d));
  5650. WFIFOW(fd,0) = 0x12d;
  5651. WFIFOW(fd,2) = num;
  5652. WFIFOSET(fd,packet_len(0x12d));
  5653. }
  5654. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5655. /// 0131 <owner id>.L <message>.80B
  5656. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5657. {
  5658. unsigned char buf[128];
  5659. nullpo_retv(bl);
  5660. WBUFW(buf,0) = 0x131;
  5661. WBUFL(buf,2) = bl->id;
  5662. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5663. if( fd ) {
  5664. WFIFOHEAD(fd,packet_len(0x131));
  5665. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5666. WFIFOSET(fd,packet_len(0x131));
  5667. } else {
  5668. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5669. }
  5670. }
  5671. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5672. /// 0132 <owner id>.L
  5673. void clif_closevendingboard(struct block_list* bl, int fd)
  5674. {
  5675. unsigned char buf[16];
  5676. nullpo_retv(bl);
  5677. WBUFW(buf,0) = 0x132;
  5678. WBUFL(buf,2) = bl->id;
  5679. if( fd ) {
  5680. WFIFOHEAD(fd,packet_len(0x132));
  5681. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5682. WFIFOSET(fd,packet_len(0x132));
  5683. } else {
  5684. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5685. }
  5686. }
  5687. /// Sends a list of items in a shop.
  5688. /// R 0133 <packet len>.W <owner id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC)
  5689. /// R 0800 <packet len>.W <owner id>.L <unique id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  5690. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5691. {
  5692. int i,fd;
  5693. int count;
  5694. struct map_session_data* vsd;
  5695. #if PACKETVER < 20100105
  5696. const int cmd = 0x133;
  5697. const int offset = 8;
  5698. #else
  5699. const int cmd = 0x800;
  5700. const int offset = 12;
  5701. #endif
  5702. nullpo_retv(sd);
  5703. nullpo_retv(vending);
  5704. nullpo_retv(vsd=map_id2sd(id));
  5705. fd = sd->fd;
  5706. count = vsd->vend_num;
  5707. WFIFOHEAD(fd, offset+count*22);
  5708. WFIFOW(fd,0) = cmd;
  5709. WFIFOW(fd,2) = offset+count*22;
  5710. WFIFOL(fd,4) = id;
  5711. #if PACKETVER >= 20100105
  5712. WFIFOL(fd,8) = vsd->vender_id;
  5713. #endif
  5714. for( i = 0; i < count; i++ )
  5715. {
  5716. int index = vending[i].index;
  5717. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5718. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5719. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5720. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5721. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5722. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5723. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5724. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5725. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5726. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5727. }
  5728. WFIFOSET(fd,WFIFOW(fd,2));
  5729. }
  5730. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5731. /// 0135 <index>.W <amount>.W <result>.B
  5732. /// result:
  5733. /// 0 = success
  5734. /// 1 = not enough zeny
  5735. /// 2 = overweight
  5736. /// 4 = out of stock
  5737. /// 5 = "cannot use an npc shop while in a trade"
  5738. /// 6 = Because the store information was incorrect the item was not purchased.
  5739. /// 7 = No sales information.
  5740. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5741. {
  5742. int fd;
  5743. nullpo_retv(sd);
  5744. fd = sd->fd;
  5745. WFIFOHEAD(fd,packet_len(0x135));
  5746. WFIFOW(fd,0) = 0x135;
  5747. WFIFOW(fd,2) = index+2;
  5748. WFIFOW(fd,4) = amount;
  5749. WFIFOB(fd,6) = fail;
  5750. WFIFOSET(fd,packet_len(0x135));
  5751. }
  5752. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5753. /// 0136 <packet len>.W <owner id>.L { <price>.L <index>.W <amount>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5754. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5755. {
  5756. int i,fd;
  5757. int count;
  5758. nullpo_retv(sd);
  5759. fd = sd->fd;
  5760. count = sd->vend_num;
  5761. WFIFOHEAD(fd, 8+count*22);
  5762. WFIFOW(fd,0) = 0x136;
  5763. WFIFOW(fd,2) = 8+count*22;
  5764. WFIFOL(fd,4) = id;
  5765. for( i = 0; i < count; i++ ) {
  5766. int index = vending[i].index;
  5767. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5768. WFIFOL(fd, 8+i*22) = vending[i].value;
  5769. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5770. WFIFOW(fd,14+i*22) = vending[i].amount;
  5771. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5772. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5773. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5774. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5775. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5776. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5777. }
  5778. WFIFOSET(fd,WFIFOW(fd,2));
  5779. }
  5780. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5781. /// 0137 <index>.W <amount>.W
  5782. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5783. {
  5784. int fd;
  5785. nullpo_retv(sd);
  5786. fd = sd->fd;
  5787. WFIFOHEAD(fd,packet_len(0x137));
  5788. WFIFOW(fd,0) = 0x137;
  5789. WFIFOW(fd,2) = index+2;
  5790. WFIFOW(fd,4) = amount;
  5791. WFIFOSET(fd,packet_len(0x137));
  5792. }
  5793. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5794. /// 00fa <result>.B
  5795. /// result:
  5796. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5797. /// 1 = MsgStringTable[78]="party name already exists"
  5798. /// 2 = MsgStringTable[79]="already in a party"
  5799. /// 3 = cannot organize parties on this map
  5800. /// ? = nothing
  5801. void clif_party_created(struct map_session_data *sd,int result)
  5802. {
  5803. int fd;
  5804. nullpo_retv(sd);
  5805. fd=sd->fd;
  5806. WFIFOHEAD(fd,packet_len(0xfa));
  5807. WFIFOW(fd,0)=0xfa;
  5808. WFIFOB(fd,2)=result;
  5809. WFIFOSET(fd,packet_len(0xfa));
  5810. }
  5811. /// Adds new member to a party.
  5812. /// 0104 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B (ZC_ADD_MEMBER_TO_GROUP)
  5813. /// 01e9 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP2)
  5814. /// role:
  5815. /// 0 = leader
  5816. /// 1 = normal
  5817. /// state:
  5818. /// 0 = connected
  5819. /// 1 = disconnected
  5820. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5821. {
  5822. unsigned char buf[81];
  5823. int i;
  5824. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5825. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5826. } else {
  5827. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5828. }
  5829. if (i >= MAX_PARTY) return; //Should never happen...
  5830. sd = p->data[i].sd;
  5831. WBUFW(buf, 0) = 0x1e9;
  5832. WBUFL(buf, 2) = sd->status.account_id;
  5833. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5834. WBUFW(buf,10) = sd->bl.x;
  5835. WBUFW(buf,12) = sd->bl.y;
  5836. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5837. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5838. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5839. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5840. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5841. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5842. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5843. }
  5844. /// Sends party information (ZC_GROUP_LIST).
  5845. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5846. /// role:
  5847. /// 0 = leader
  5848. /// 1 = normal
  5849. /// state:
  5850. /// 0 = connected
  5851. /// 1 = disconnected
  5852. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5853. {
  5854. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5855. struct map_session_data* party_sd = NULL;
  5856. int i, c;
  5857. nullpo_retv(p);
  5858. WBUFW(buf,0) = 0xfb;
  5859. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5860. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5861. {
  5862. struct party_member* m = &p->party.member[i];
  5863. if(!m->account_id) continue;
  5864. if(party_sd == NULL) party_sd = p->data[i].sd;
  5865. WBUFL(buf,28+c*46) = m->account_id;
  5866. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5867. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5868. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5869. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5870. c++;
  5871. }
  5872. WBUFW(buf,2) = 28+c*46;
  5873. if(sd) { // send only to self
  5874. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5875. } else if (party_sd) { // send to whole party
  5876. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5877. }
  5878. }
  5879. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5880. /// 02c9 <flag>.B
  5881. /// flag:
  5882. /// 0 = allow party invites
  5883. /// 1 = auto-deny party invites
  5884. void clif_partyinvitationstate(struct map_session_data* sd)
  5885. {
  5886. int fd;
  5887. nullpo_retv(sd);
  5888. fd = sd->fd;
  5889. WFIFOHEAD(fd, packet_len(0x2c9));
  5890. WFIFOW(fd, 0) = 0x2c9;
  5891. WFIFOB(fd, 2) = 0; // not implemented
  5892. WFIFOSET(fd, packet_len(0x2c9));
  5893. }
  5894. /// Party invitation request.
  5895. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5896. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5897. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5898. {
  5899. #if PACKETVER < 20070821
  5900. const int cmd = 0xfe;
  5901. #else
  5902. const int cmd = 0x2c6;
  5903. #endif
  5904. int fd;
  5905. struct party_data *p;
  5906. nullpo_retv(sd);
  5907. nullpo_retv(tsd);
  5908. fd=tsd->fd;
  5909. if( (p=party_search(sd->status.party_id))==NULL )
  5910. return;
  5911. WFIFOHEAD(fd,packet_len(cmd));
  5912. WFIFOW(fd,0)=cmd;
  5913. WFIFOL(fd,2)=sd->status.party_id;
  5914. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5915. WFIFOSET(fd,packet_len(cmd));
  5916. }
  5917. /// Party invite result.
  5918. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5919. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5920. /// result=0 : char is already in a party -> MsgStringTable[80]
  5921. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5922. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5923. /// result=3 : party is full -> MsgStringTable[83]
  5924. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5925. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5926. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5927. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5928. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5929. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5930. {
  5931. int fd;
  5932. nullpo_retv(sd);
  5933. fd=sd->fd;
  5934. #if PACKETVER < 20070904
  5935. if( result == 7 ) {
  5936. clif_displaymessage(fd, msg_txt(sd,3));
  5937. return;
  5938. }
  5939. #endif
  5940. #if PACKETVER < 20070821
  5941. WFIFOHEAD(fd,packet_len(0xfd));
  5942. WFIFOW(fd,0) = 0xfd;
  5943. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5944. WFIFOB(fd,26) = result;
  5945. WFIFOSET(fd,packet_len(0xfd));
  5946. #else
  5947. WFIFOHEAD(fd,packet_len(0x2c5));
  5948. WFIFOW(fd,0) = 0x2c5;
  5949. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5950. WFIFOL(fd,26) = result;
  5951. WFIFOSET(fd,packet_len(0x2c5));
  5952. #endif
  5953. }
  5954. /// Updates party settings.
  5955. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5956. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5957. /// exp option:
  5958. /// 0 = exp sharing disabled
  5959. /// 1 = exp sharing enabled
  5960. /// 2 = cannot change exp sharing
  5961. ///
  5962. /// flag:
  5963. /// 0 = send to party
  5964. /// 1 = send to sd
  5965. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5966. {
  5967. unsigned char buf[16];
  5968. #if PACKETVER < 20090603
  5969. const int cmd = 0x101;
  5970. #else
  5971. const int cmd = 0x7d8;
  5972. #endif
  5973. nullpo_retv(p);
  5974. if(!sd && flag==0){
  5975. int i;
  5976. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5977. if (i < MAX_PARTY)
  5978. sd = p->data[i].sd;
  5979. }
  5980. if(!sd) return;
  5981. WBUFW(buf,0)=cmd;
  5982. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5983. #if PACKETVER >= 20090603
  5984. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5985. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5986. #endif
  5987. if(flag==0)
  5988. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5989. else
  5990. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5991. }
  5992. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5993. /// result:
  5994. /// 0 = leave
  5995. /// 1 = expel
  5996. /// 2 = cannot leave party on this map
  5997. /// 3 = cannot expel from party on this map
  5998. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5999. {
  6000. unsigned char buf[64];
  6001. nullpo_retv(p);
  6002. if(!sd && (flag&0xf0)==0)
  6003. {
  6004. int i;
  6005. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6006. if (i < MAX_PARTY)
  6007. sd = p->data[i].sd;
  6008. }
  6009. if(!sd) return;
  6010. WBUFW(buf,0)=0x105;
  6011. WBUFL(buf,2)=account_id;
  6012. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6013. WBUFB(buf,30)=flag&0x0f;
  6014. if((flag&0xf0)==0)
  6015. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6016. else
  6017. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6018. }
  6019. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6020. /// 0109 <packet len>.W <account id>.L <message>.?B
  6021. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  6022. {
  6023. struct map_session_data *sd;
  6024. int i;
  6025. nullpo_retv(p);
  6026. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6027. if(i < MAX_PARTY){
  6028. unsigned char buf[1024];
  6029. if( len > sizeof(buf)-8 )
  6030. {
  6031. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6032. len = sizeof(buf)-8;
  6033. }
  6034. sd = p->data[i].sd;
  6035. WBUFW(buf,0)=0x109;
  6036. WBUFW(buf,2)=len+8;
  6037. WBUFL(buf,4)=account_id;
  6038. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6039. clif_send(buf,len+8,&sd->bl,PARTY);
  6040. }
  6041. }
  6042. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6043. /// 0107 <account id>.L <x>.W <y>.W
  6044. void clif_party_xy(struct map_session_data *sd)
  6045. {
  6046. unsigned char buf[16];
  6047. nullpo_retv(sd);
  6048. WBUFW(buf,0)=0x107;
  6049. WBUFL(buf,2)=sd->status.account_id;
  6050. WBUFW(buf,6)=sd->bl.x;
  6051. WBUFW(buf,8)=sd->bl.y;
  6052. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6053. }
  6054. /*==========================================
  6055. * Sends x/y dot to a single fd. [Skotlex]
  6056. *------------------------------------------*/
  6057. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6058. {
  6059. WFIFOHEAD(fd,packet_len(0x107));
  6060. WFIFOW(fd,0)=0x107;
  6061. WFIFOL(fd,2)=sd->status.account_id;
  6062. WFIFOW(fd,6)=sd->bl.x;
  6063. WFIFOW(fd,8)=sd->bl.y;
  6064. WFIFOSET(fd,packet_len(0x107));
  6065. }
  6066. /// Updates HP bar of a party member.
  6067. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6068. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6069. void clif_party_hp(struct map_session_data *sd)
  6070. {
  6071. unsigned char buf[16];
  6072. #if PACKETVER < 20100126
  6073. const int cmd = 0x106;
  6074. #else
  6075. const int cmd = 0x80e;
  6076. #endif
  6077. nullpo_retv(sd);
  6078. WBUFW(buf,0)=cmd;
  6079. WBUFL(buf,2)=sd->status.account_id;
  6080. #if PACKETVER < 20100126
  6081. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6082. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6083. WBUFW(buf,8) = 100;
  6084. } else {
  6085. WBUFW(buf,6) = sd->battle_status.hp;
  6086. WBUFW(buf,8) = sd->battle_status.max_hp;
  6087. }
  6088. #else
  6089. WBUFL(buf,6) = sd->battle_status.hp;
  6090. WBUFL(buf,10) = sd->battle_status.max_hp;
  6091. #endif
  6092. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6093. }
  6094. /*==========================================
  6095. * Sends HP bar to a single fd. [Skotlex]
  6096. *------------------------------------------*/
  6097. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6098. {
  6099. #if PACKETVER < 20100126
  6100. const int cmd = 0x106;
  6101. #else
  6102. const int cmd = 0x80e;
  6103. #endif
  6104. WFIFOHEAD(fd,packet_len(cmd));
  6105. WFIFOW(fd,0) = cmd;
  6106. WFIFOL(fd,2) = id;
  6107. #if PACKETVER < 20100126
  6108. if( maxhp > INT16_MAX )
  6109. {// To correctly display the %hp bar. [Skotlex]
  6110. WFIFOW(fd,6) = hp/(maxhp/100);
  6111. WFIFOW(fd,8) = 100;
  6112. } else {
  6113. WFIFOW(fd,6) = hp;
  6114. WFIFOW(fd,8) = maxhp;
  6115. }
  6116. #else
  6117. WFIFOL(fd,6) = hp;
  6118. WFIFOL(fd,10) = maxhp;
  6119. #endif
  6120. WFIFOSET(fd, packet_len(cmd));
  6121. }
  6122. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6123. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6124. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6125. {
  6126. int fd;
  6127. nullpo_retv(sd);
  6128. nullpo_retv(bl);
  6129. fd=sd->fd;
  6130. WFIFOHEAD(fd,packet_len(0x139));
  6131. WFIFOW(fd, 0)=0x139;
  6132. WFIFOL(fd, 2)=bl->id;
  6133. WFIFOW(fd, 6)=bl->x;
  6134. WFIFOW(fd, 8)=bl->y;
  6135. WFIFOW(fd,10)=sd->bl.x;
  6136. WFIFOW(fd,12)=sd->bl.y;
  6137. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6138. WFIFOSET(fd,packet_len(0x139));
  6139. }
  6140. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6141. /// 018f <result>.W <name id>.W
  6142. /// result:
  6143. /// 0 = success
  6144. /// 1 = failure
  6145. /// 2 = success (alchemist)
  6146. /// 3 = failure (alchemist)
  6147. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  6148. {
  6149. int view,fd;
  6150. nullpo_retv(sd);
  6151. fd = sd->fd;
  6152. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6153. WFIFOHEAD(fd,packet_len(0x18f));
  6154. WFIFOW(fd, 0)=0x18f;
  6155. WFIFOW(fd, 2)=flag;
  6156. if((view = itemdb_viewid(nameid)) > 0)
  6157. WFIFOW(fd, 4)=view;
  6158. else
  6159. WFIFOW(fd, 4)=nameid;
  6160. WFIFOSET(fd,packet_len(0x18f));
  6161. }
  6162. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6163. /// 019e
  6164. void clif_catch_process(struct map_session_data *sd)
  6165. {
  6166. int fd;
  6167. nullpo_retv(sd);
  6168. fd=sd->fd;
  6169. WFIFOHEAD(fd,packet_len(0x19e));
  6170. WFIFOW(fd,0)=0x19e;
  6171. WFIFOSET(fd,packet_len(0x19e));
  6172. }
  6173. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6174. /// 01a0 <result>.B
  6175. /// 0 = failure
  6176. /// 1 = success
  6177. void clif_pet_roulette(struct map_session_data *sd,int data)
  6178. {
  6179. int fd;
  6180. nullpo_retv(sd);
  6181. fd=sd->fd;
  6182. WFIFOHEAD(fd,packet_len(0x1a0));
  6183. WFIFOW(fd,0)=0x1a0;
  6184. WFIFOB(fd,2)=data;
  6185. WFIFOSET(fd,packet_len(0x1a0));
  6186. }
  6187. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6188. /// 01a6 <packet len>.W { <index>.W }*
  6189. void clif_sendegg(struct map_session_data *sd)
  6190. {
  6191. int i,n=0,fd;
  6192. nullpo_retv(sd);
  6193. fd=sd->fd;
  6194. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6195. clif_displaymessage(fd, msg_txt(sd,666));
  6196. return;
  6197. }
  6198. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6199. WFIFOW(fd,0)=0x1a6;
  6200. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6201. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6202. sd->inventory_data[i]->type!=IT_PETEGG ||
  6203. sd->status.inventory[i].amount<=0)
  6204. continue;
  6205. WFIFOW(fd,n*2+4)=i+2;
  6206. n++;
  6207. }
  6208. WFIFOW(fd,2)=4+n*2;
  6209. WFIFOSET(fd,WFIFOW(fd,2));
  6210. sd->menuskill_id = SA_TAMINGMONSTER;
  6211. sd->menuskill_val = -1;
  6212. }
  6213. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6214. /// 01a4 <type>.B <id>.L <data>.L
  6215. /// type:
  6216. /// 0 = pre-init (data = 0)
  6217. /// 1 = intimacy (data = 0~4)
  6218. /// 2 = hunger (data = 0~4)
  6219. /// 3 = accessory
  6220. /// 4 = performance (data = 1~3: normal, 4: special)
  6221. /// 5 = hairstyle
  6222. ///
  6223. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6224. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6225. {
  6226. uint8 buf[16];
  6227. nullpo_retv(pd);
  6228. WBUFW(buf,0) = 0x1a4;
  6229. WBUFB(buf,2) = type;
  6230. WBUFL(buf,3) = pd->bl.id;
  6231. WBUFL(buf,7) = param;
  6232. if (sd)
  6233. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6234. else
  6235. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6236. }
  6237. /// Pet's base data (ZC_PROPERTY_PET).
  6238. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6239. void clif_send_petstatus(struct map_session_data *sd)
  6240. {
  6241. int fd;
  6242. struct s_pet *pet;
  6243. nullpo_retv(sd);
  6244. nullpo_retv(sd->pd);
  6245. fd=sd->fd;
  6246. pet = &sd->pd->pet;
  6247. WFIFOHEAD(fd,packet_len(0x1a2));
  6248. WFIFOW(fd,0)=0x1a2;
  6249. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6250. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6251. WFIFOW(fd,27)=pet->level;
  6252. WFIFOW(fd,29)=pet->hungry;
  6253. WFIFOW(fd,31)=pet->intimate;
  6254. WFIFOW(fd,33)=pet->equip;
  6255. #if PACKETVER >= 20081126
  6256. WFIFOW(fd,35)=pet->class_;
  6257. #endif
  6258. WFIFOSET(fd,packet_len(0x1a2));
  6259. }
  6260. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6261. /// 01aa <id>.L <data>.L
  6262. /// data:
  6263. /// @see CZ_PET_ACT.
  6264. void clif_pet_emotion(struct pet_data *pd,int param)
  6265. {
  6266. unsigned char buf[16];
  6267. nullpo_retv(pd);
  6268. memset(buf,0,packet_len(0x1aa));
  6269. WBUFW(buf,0)=0x1aa;
  6270. WBUFL(buf,2)=pd->bl.id;
  6271. if(param >= 100 && pd->petDB->talk_convert_class) {
  6272. if(pd->petDB->talk_convert_class < 0)
  6273. return;
  6274. else if(pd->petDB->talk_convert_class > 0) {
  6275. // replace mob_id component of talk/act data
  6276. param -= (pd->pet.class_ - 100)*100;
  6277. param += (pd->petDB->talk_convert_class - 100)*100;
  6278. }
  6279. }
  6280. WBUFL(buf,6)=param;
  6281. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6282. }
  6283. /// Result of request to feed a pet (ZC_FEED_PET).
  6284. /// 01a3 <result>.B <name id>.W
  6285. /// result:
  6286. /// 0 = failure
  6287. /// 1 = success
  6288. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6289. {
  6290. int fd;
  6291. nullpo_retv(sd);
  6292. fd=sd->fd;
  6293. WFIFOHEAD(fd,packet_len(0x1a3));
  6294. WFIFOW(fd,0)=0x1a3;
  6295. WFIFOB(fd,2)=fail;
  6296. WFIFOW(fd,3)=foodid;
  6297. WFIFOSET(fd,packet_len(0x1a3));
  6298. }
  6299. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6300. /// 01cd { <skill id>.L }*7
  6301. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6302. {
  6303. int fd;
  6304. nullpo_retv(sd);
  6305. fd=sd->fd;
  6306. WFIFOHEAD(fd,packet_len(0x1cd));
  6307. WFIFOW(fd, 0)=0x1cd;
  6308. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6309. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6310. else
  6311. WFIFOL(fd,2)= 0x00000000;
  6312. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6313. WFIFOL(fd,6)= MG_COLDBOLT;
  6314. else
  6315. WFIFOL(fd,6)= 0x00000000;
  6316. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6317. WFIFOL(fd,10)= MG_FIREBOLT;
  6318. else
  6319. WFIFOL(fd,10)= 0x00000000;
  6320. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6321. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6322. else
  6323. WFIFOL(fd,14)= 0x00000000;
  6324. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6325. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6326. else
  6327. WFIFOL(fd,18)= 0x00000000;
  6328. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6329. WFIFOL(fd,22)= MG_FIREBALL;
  6330. else
  6331. WFIFOL(fd,22)= 0x00000000;
  6332. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6333. WFIFOL(fd,26)= MG_FROSTDIVER;
  6334. else
  6335. WFIFOL(fd,26)= 0x00000000;
  6336. WFIFOSET(fd,packet_len(0x1cd));
  6337. sd->menuskill_id = SA_AUTOSPELL;
  6338. sd->menuskill_val = skill_lv;
  6339. }
  6340. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6341. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6342. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6343. {
  6344. unsigned char buf[56];
  6345. nullpo_retv(src);
  6346. memset(buf,0,packet_len(0x1cf));
  6347. WBUFW(buf,0) = 0x1cf;
  6348. WBUFL(buf,2) = src->id;
  6349. if( src->type == BL_MER )
  6350. {
  6351. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6352. if( md && md->master && md->devotion_flag )
  6353. WBUFL(buf,6) = md->master->bl.id;
  6354. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6355. }
  6356. else
  6357. {
  6358. int i;
  6359. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6360. if( sd == NULL )
  6361. return;
  6362. for( i = 0; i < 5; i++ )
  6363. WBUFL(buf,6+4*i) = sd->devotion[i];
  6364. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6365. }
  6366. if( tsd )
  6367. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6368. else
  6369. clif_send(buf, packet_len(0x1cf), src, AREA);
  6370. }
  6371. /*==========================================
  6372. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6373. * Notifies clients in an area of an object's spirits.
  6374. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6375. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6376. *------------------------------------------*/
  6377. void clif_spiritball(struct block_list *bl) {
  6378. unsigned char buf[16];
  6379. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6380. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6381. nullpo_retv(bl);
  6382. WBUFW(buf, 0) = 0x1d0;
  6383. WBUFL(buf, 2) = bl->id;
  6384. WBUFW(buf, 6) = 0; //init to 0
  6385. switch(bl->type){
  6386. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6387. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6388. }
  6389. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6390. }
  6391. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6392. /// 01d2 <account id>.L <delay>.L
  6393. void clif_combo_delay(struct block_list *bl,int wait)
  6394. {
  6395. unsigned char buf[32];
  6396. nullpo_retv(bl);
  6397. WBUFW(buf,0)=0x1d2;
  6398. WBUFL(buf,2)=bl->id;
  6399. WBUFL(buf,6)=wait;
  6400. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6401. }
  6402. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6403. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6404. /// flag:
  6405. /// 0 = inactive
  6406. /// 1 = active
  6407. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6408. {
  6409. unsigned char buf[32];
  6410. nullpo_retv(src);
  6411. WBUFW(buf,0)=0x1d1;
  6412. WBUFL(buf,2)=src->id;
  6413. WBUFL(buf,6)=dst_id;
  6414. WBUFL(buf,10)=active;
  6415. clif_send(buf,packet_len(0x1d1),src,AREA);
  6416. }
  6417. /// MVP effect (ZC_MVP).
  6418. /// 010c <account id>.L
  6419. void clif_mvp_effect(struct map_session_data *sd)
  6420. {
  6421. unsigned char buf[16];
  6422. nullpo_retv(sd);
  6423. WBUFW(buf,0)=0x10c;
  6424. WBUFL(buf,2)=sd->bl.id;
  6425. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6426. }
  6427. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6428. /// 010a <name id>.W
  6429. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6430. {
  6431. int view,fd;
  6432. nullpo_retv(sd);
  6433. fd=sd->fd;
  6434. WFIFOHEAD(fd,packet_len(0x10a));
  6435. WFIFOW(fd,0)=0x10a;
  6436. if((view = itemdb_viewid(nameid)) > 0)
  6437. WFIFOW(fd,2)=view;
  6438. else
  6439. WFIFOW(fd,2)=nameid;
  6440. WFIFOSET(fd,packet_len(0x10a));
  6441. }
  6442. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6443. /// 010b <exp>.L
  6444. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6445. {
  6446. int fd;
  6447. nullpo_retv(sd);
  6448. fd=sd->fd;
  6449. WFIFOHEAD(fd,packet_len(0x10b));
  6450. WFIFOW(fd,0)=0x10b;
  6451. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6452. WFIFOSET(fd,packet_len(0x10b));
  6453. }
  6454. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6455. /// 010d
  6456. ///
  6457. /// "You are the MVP, but cannot obtain the reward because
  6458. /// you are overweight."
  6459. void clif_mvp_noitem(struct map_session_data* sd)
  6460. {
  6461. int fd = sd->fd;
  6462. WFIFOHEAD(fd,packet_len(0x10d));
  6463. WFIFOW(fd,0) = 0x10d;
  6464. WFIFOSET(fd,packet_len(0x10d));
  6465. }
  6466. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6467. /// 0167 <result>.B
  6468. /// result:
  6469. /// 0 = "Guild has been created."
  6470. /// 1 = "You are already in a Guild."
  6471. /// 2 = "That Guild Name already exists."
  6472. /// 3 = "You need the neccessary item to create a Guild."
  6473. void clif_guild_created(struct map_session_data *sd,int flag)
  6474. {
  6475. int fd;
  6476. nullpo_retv(sd);
  6477. fd=sd->fd;
  6478. WFIFOHEAD(fd,packet_len(0x167));
  6479. WFIFOW(fd,0)=0x167;
  6480. WFIFOB(fd,2)=flag;
  6481. WFIFOSET(fd,packet_len(0x167));
  6482. }
  6483. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6484. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6485. /// mode:
  6486. /// &0x01 = allow invite
  6487. /// &0x10 = allow expel
  6488. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6489. {
  6490. int ps,fd;
  6491. nullpo_retv(sd);
  6492. nullpo_retv(g);
  6493. fd=sd->fd;
  6494. ps=guild_getposition(g,sd);
  6495. WFIFOHEAD(fd,packet_len(0x16c));
  6496. WFIFOW(fd,0)=0x16c;
  6497. WFIFOL(fd,2)=g->guild_id;
  6498. WFIFOL(fd,6)=g->emblem_id;
  6499. WFIFOL(fd,10)=g->position[ps].mode;
  6500. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6501. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6502. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6503. WFIFOSET(fd,packet_len(0x16c));
  6504. }
  6505. /// Guild member login notice.
  6506. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6507. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6508. /// status:
  6509. /// 0 = offline
  6510. /// 1 = online
  6511. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6512. {
  6513. unsigned char buf[64];
  6514. struct map_session_data* sd;
  6515. nullpo_retv(g);
  6516. WBUFW(buf, 0)=0x1f2;
  6517. WBUFL(buf, 2)=g->member[idx].account_id;
  6518. WBUFL(buf, 6)=g->member[idx].char_id;
  6519. WBUFL(buf,10)=flag;
  6520. if( ( sd = g->member[idx].sd ) != NULL )
  6521. {
  6522. WBUFW(buf,14) = sd->status.sex;
  6523. WBUFW(buf,16) = sd->status.hair;
  6524. WBUFW(buf,18) = sd->status.hair_color;
  6525. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6526. }
  6527. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6528. {
  6529. WBUFW(buf,14) = 0;
  6530. WBUFW(buf,16) = 0;
  6531. WBUFW(buf,18) = 0;
  6532. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6533. }
  6534. }
  6535. // Function `clif_guild_memberlogin_notice` sends info about
  6536. // logins and logouts of a guild member to the rest members.
  6537. // But at the 1st time (after a player login or map changing)
  6538. // the client won't show the message.
  6539. // So I suggest use this function for sending "first-time-info"
  6540. // to some player on entering the game or changing location.
  6541. // At next time the client would always show the message.
  6542. // The function sends all the statuses in the single packet
  6543. // to economize traffic. [LuzZza]
  6544. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6545. {
  6546. struct guild *g;
  6547. unsigned char buf[14*128];
  6548. int i, count=0, p_len;
  6549. nullpo_retv(sd);
  6550. p_len = packet_len(0x16d);
  6551. if(!(g = sd->guild))
  6552. return;
  6553. for(i=0; i<g->max_member; i++) {
  6554. if(g->member[i].account_id > 0 &&
  6555. g->member[i].account_id != sd->status.account_id) {
  6556. WBUFW(buf,count*p_len) = 0x16d;
  6557. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6558. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6559. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6560. count++;
  6561. }
  6562. }
  6563. clif_send(buf, p_len*count, &sd->bl, SELF);
  6564. }
  6565. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6566. /// 014e <menu flag>.L
  6567. /// menu flag:
  6568. /// 0x00 = Basic Info (always on)
  6569. /// &0x01 = Member manager
  6570. /// &0x02 = Positions
  6571. /// &0x04 = Skills
  6572. /// &0x10 = Expulsion list
  6573. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6574. /// &0x80 = Notice
  6575. void clif_guild_masterormember(struct map_session_data *sd)
  6576. {
  6577. int fd;
  6578. nullpo_retv(sd);
  6579. fd=sd->fd;
  6580. WFIFOHEAD(fd,packet_len(0x14e));
  6581. WFIFOW(fd,0) = 0x14e;
  6582. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6583. WFIFOSET(fd,packet_len(0x14e));
  6584. }
  6585. /// Guild basic information (Territories [Valaris])
  6586. /// 0150 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B (ZC_GUILD_INFO)
  6587. /// 01b6 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B <zeny>.L (ZC_GUILD_INFO2)
  6588. void clif_guild_basicinfo(struct map_session_data *sd) {
  6589. int fd;
  6590. struct guild *g;
  6591. nullpo_retv(sd);
  6592. fd = sd->fd;
  6593. if( (g = sd->guild) == NULL )
  6594. return;
  6595. WFIFOHEAD(fd,packet_len(0x1b6));
  6596. WFIFOW(fd, 0)=0x1b6;//0x150;
  6597. WFIFOL(fd, 2)=g->guild_id;
  6598. WFIFOL(fd, 6)=g->guild_lv;
  6599. WFIFOL(fd,10)=g->connect_member;
  6600. WFIFOL(fd,14)=g->max_member;
  6601. WFIFOL(fd,18)=g->average_lv;
  6602. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6603. WFIFOL(fd,26)=g->next_exp;
  6604. WFIFOL(fd,30)=0; // Tax Points
  6605. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6606. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6607. WFIFOL(fd,42)=g->emblem_id;
  6608. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6609. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6610. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6611. WFIFOL(fd,110) = 0; // zeny
  6612. WFIFOSET(fd,packet_len(0x1b6));
  6613. }
  6614. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6615. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6616. void clif_guild_allianceinfo(struct map_session_data *sd)
  6617. {
  6618. int fd,i,c;
  6619. struct guild *g;
  6620. nullpo_retv(sd);
  6621. if( (g = sd->guild) == NULL )
  6622. return;
  6623. fd = sd->fd;
  6624. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6625. WFIFOW(fd, 0)=0x14c;
  6626. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6627. struct guild_alliance *a=&g->alliance[i];
  6628. if(a->guild_id>0){
  6629. WFIFOL(fd,c*32+4)=a->opposition;
  6630. WFIFOL(fd,c*32+8)=a->guild_id;
  6631. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6632. c++;
  6633. }
  6634. }
  6635. WFIFOW(fd, 2)=c*32+4;
  6636. WFIFOSET(fd,WFIFOW(fd,2));
  6637. }
  6638. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6639. /// 0154 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L <memo>.50B <name>.24B }*
  6640. /// state:
  6641. /// 0 = offline
  6642. /// 1 = online
  6643. /// memo:
  6644. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6645. void clif_guild_memberlist(struct map_session_data *sd)
  6646. {
  6647. int fd;
  6648. int i,c;
  6649. struct guild *g;
  6650. nullpo_retv(sd);
  6651. if( (fd = sd->fd) == 0 )
  6652. return;
  6653. if( (g = sd->guild) == NULL )
  6654. return;
  6655. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6656. WFIFOW(fd, 0)=0x154;
  6657. for(i=0,c=0;i<g->max_member;i++){
  6658. struct guild_member *m=&g->member[i];
  6659. if(m->account_id==0)
  6660. continue;
  6661. WFIFOL(fd,c*104+ 4)=m->account_id;
  6662. WFIFOL(fd,c*104+ 8)=m->char_id;
  6663. WFIFOW(fd,c*104+12)=m->hair;
  6664. WFIFOW(fd,c*104+14)=m->hair_color;
  6665. WFIFOW(fd,c*104+16)=m->gender;
  6666. WFIFOW(fd,c*104+18)=m->class_;
  6667. WFIFOW(fd,c*104+20)=m->lv;
  6668. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6669. WFIFOL(fd,c*104+26)=m->online;
  6670. WFIFOL(fd,c*104+30)=m->position;
  6671. memset(WFIFOP(fd,c*104+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  6672. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6673. c++;
  6674. }
  6675. WFIFOW(fd, 2)=c*104+4;
  6676. WFIFOSET(fd,WFIFOW(fd,2));
  6677. }
  6678. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6679. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6680. void clif_guild_positionnamelist(struct map_session_data *sd)
  6681. {
  6682. int i,fd;
  6683. struct guild *g;
  6684. nullpo_retv(sd);
  6685. if( (g = sd->guild) == NULL )
  6686. return;
  6687. fd = sd->fd;
  6688. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6689. WFIFOW(fd, 0)=0x166;
  6690. for(i=0;i<MAX_GUILDPOSITION;i++){
  6691. WFIFOL(fd,i*28+4)=i;
  6692. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6693. }
  6694. WFIFOW(fd,2)=i*28+4;
  6695. WFIFOSET(fd,WFIFOW(fd,2));
  6696. }
  6697. /// Guild position information (ZC_POSITION_INFO).
  6698. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6699. /// mode:
  6700. /// &0x01 = allow invite
  6701. /// &0x10 = allow expel
  6702. /// ranking:
  6703. /// TODO
  6704. void clif_guild_positioninfolist(struct map_session_data *sd)
  6705. {
  6706. int i,fd;
  6707. struct guild *g;
  6708. nullpo_retv(sd);
  6709. if( (g = sd->guild) == NULL )
  6710. return;
  6711. fd = sd->fd;
  6712. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6713. WFIFOW(fd, 0)=0x160;
  6714. for(i=0;i<MAX_GUILDPOSITION;i++){
  6715. struct guild_position *p=&g->position[i];
  6716. WFIFOL(fd,i*16+ 4)=i;
  6717. WFIFOL(fd,i*16+ 8)=p->mode;
  6718. WFIFOL(fd,i*16+12)=i;
  6719. WFIFOL(fd,i*16+16)=p->exp_mode;
  6720. }
  6721. WFIFOW(fd, 2)=i*16+4;
  6722. WFIFOSET(fd,WFIFOW(fd,2));
  6723. }
  6724. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6725. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6726. /// mode:
  6727. /// &0x01 = allow invite
  6728. /// &0x10 = allow expel
  6729. /// ranking:
  6730. /// TODO
  6731. void clif_guild_positionchanged(struct guild *g,int idx)
  6732. {
  6733. // FIXME: This packet is intended to update the clients after a
  6734. // commit of position info changes, not sending one packet per
  6735. // position.
  6736. struct map_session_data *sd;
  6737. unsigned char buf[128];
  6738. nullpo_retv(g);
  6739. WBUFW(buf, 0)=0x174;
  6740. WBUFW(buf, 2)=44; // packet len
  6741. // GUILD_REG_POSITION_INFO{
  6742. WBUFL(buf, 4)=idx;
  6743. WBUFL(buf, 8)=g->position[idx].mode;
  6744. WBUFL(buf,12)=idx;
  6745. WBUFL(buf,16)=g->position[idx].exp_mode;
  6746. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6747. // }*
  6748. if( (sd=guild_getavailablesd(g))!=NULL )
  6749. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6750. }
  6751. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6752. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6753. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6754. {
  6755. // FIXME: This packet is intended to update the clients after a
  6756. // commit of member position assignment changes, not sending one
  6757. // packet per position.
  6758. struct map_session_data *sd;
  6759. unsigned char buf[64];
  6760. nullpo_retv(g);
  6761. WBUFW(buf, 0)=0x156;
  6762. WBUFW(buf, 2)=16; // packet len
  6763. // MEMBER_POSITION_INFO{
  6764. WBUFL(buf, 4)=g->member[idx].account_id;
  6765. WBUFL(buf, 8)=g->member[idx].char_id;
  6766. WBUFL(buf,12)=g->member[idx].position;
  6767. // }*
  6768. if( (sd=guild_getavailablesd(g))!=NULL )
  6769. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6770. }
  6771. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6772. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6773. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6774. {
  6775. int fd;
  6776. nullpo_retv(sd);
  6777. nullpo_retv(g);
  6778. fd = sd->fd;
  6779. if( g->emblem_len <= 0 )
  6780. return;
  6781. WFIFOHEAD(fd,g->emblem_len+12);
  6782. WFIFOW(fd,0)=0x152;
  6783. WFIFOW(fd,2)=g->emblem_len+12;
  6784. WFIFOL(fd,4)=g->guild_id;
  6785. WFIFOL(fd,8)=g->emblem_id;
  6786. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6787. WFIFOSET(fd,WFIFOW(fd,2));
  6788. }
  6789. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6790. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6791. void clif_guild_emblem_area(struct block_list* bl)
  6792. {
  6793. uint8 buf[12];
  6794. nullpo_retv(bl);
  6795. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6796. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6797. WBUFW(buf,0) = 0x1b4;
  6798. WBUFL(buf,2) = bl->id;
  6799. WBUFL(buf,6) = status_get_guild_id(bl);
  6800. WBUFW(buf,10) = status_get_emblem_id(bl);
  6801. clif_send(buf, 12, bl, AREA_WOS);
  6802. }
  6803. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6804. /// 0162 <packet len>.W <skill points>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B }*
  6805. void clif_guild_skillinfo(struct map_session_data* sd)
  6806. {
  6807. int fd;
  6808. struct guild* g;
  6809. int i,c;
  6810. nullpo_retv(sd);
  6811. if( (g = sd->guild) == NULL )
  6812. return;
  6813. fd = sd->fd;
  6814. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6815. WFIFOW(fd,0) = 0x0162;
  6816. WFIFOW(fd,4) = g->skill_point;
  6817. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6818. {
  6819. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6820. {
  6821. int id = g->skill[i].id;
  6822. int p = 6 + c*37;
  6823. WFIFOW(fd,p+0) = id;
  6824. WFIFOL(fd,p+2) = skill_get_inf(id);
  6825. WFIFOW(fd,p+6) = g->skill[i].lv;
  6826. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6827. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6828. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6829. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6830. c++;
  6831. }
  6832. }
  6833. WFIFOW(fd,2) = 6 + c*37;
  6834. WFIFOSET(fd,WFIFOW(fd,2));
  6835. }
  6836. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6837. /// 016f <subject>.60B <notice>.120B
  6838. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6839. {
  6840. int fd;
  6841. nullpo_retv(sd);
  6842. nullpo_retv(g);
  6843. fd = sd->fd;
  6844. if ( !session_isActive(fd) )
  6845. return;
  6846. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6847. return;
  6848. WFIFOHEAD(fd,packet_len(0x16f));
  6849. WFIFOW(fd,0) = 0x16f;
  6850. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6851. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6852. WFIFOSET(fd,packet_len(0x16f));
  6853. }
  6854. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6855. /// 016a <guild id>.L <guild name>.24B
  6856. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6857. {
  6858. int fd;
  6859. nullpo_retv(sd);
  6860. nullpo_retv(g);
  6861. fd=sd->fd;
  6862. WFIFOHEAD(fd,packet_len(0x16a));
  6863. WFIFOW(fd,0)=0x16a;
  6864. WFIFOL(fd,2)=g->guild_id;
  6865. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6866. WFIFOSET(fd,packet_len(0x16a));
  6867. }
  6868. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6869. /// 0169 <answer>.B
  6870. /// answer:
  6871. /// 0 = Already in guild.
  6872. /// 1 = Offer rejected.
  6873. /// 2 = Offer accepted.
  6874. /// 3 = Guild full.
  6875. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6876. {
  6877. int fd;
  6878. nullpo_retv(sd);
  6879. fd=sd->fd;
  6880. WFIFOHEAD(fd,packet_len(0x169));
  6881. WFIFOW(fd,0)=0x169;
  6882. WFIFOB(fd,2)=flag;
  6883. WFIFOSET(fd,packet_len(0x169));
  6884. }
  6885. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6886. /// 015a <char name>.24B <reason>.40B
  6887. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6888. {
  6889. unsigned char buf[128];
  6890. nullpo_retv(sd);
  6891. WBUFW(buf, 0)=0x15a;
  6892. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6893. memcpy(WBUFP(buf,26),mes,40);
  6894. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6895. }
  6896. /// Notifies clients of a guild of an expelled member.
  6897. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6898. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6899. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6900. {
  6901. unsigned char buf[128];
  6902. #if PACKETVER < 20100803
  6903. const unsigned short cmd = 0x15c;
  6904. #else
  6905. const unsigned short cmd = 0x839;
  6906. #endif
  6907. nullpo_retv(sd);
  6908. WBUFW(buf,0) = cmd;
  6909. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6910. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6911. #if PACKETVER < 20100803
  6912. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6913. #endif
  6914. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6915. }
  6916. /// Guild expulsion list (ZC_BAN_LIST).
  6917. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6918. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6919. void clif_guild_expulsionlist(struct map_session_data* sd)
  6920. {
  6921. #if PACKETVER < 20100803
  6922. const int offset = NAME_LENGTH*2+40;
  6923. #else
  6924. const int offset = NAME_LENGTH+40;
  6925. #endif
  6926. int fd, i, c = 0;
  6927. struct guild* g;
  6928. nullpo_retv(sd);
  6929. if( (g = sd->guild) == NULL )
  6930. return;
  6931. fd = sd->fd;
  6932. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6933. WFIFOW(fd,0) = 0x163;
  6934. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6935. {
  6936. struct guild_expulsion* e = &g->expulsion[i];
  6937. if( e->account_id > 0 )
  6938. {
  6939. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6940. #if PACKETVER < 20100803
  6941. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6942. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6943. #else
  6944. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6945. #endif
  6946. c++;
  6947. }
  6948. }
  6949. WFIFOW(fd,2) = 4 + c*offset;
  6950. WFIFOSET(fd,WFIFOW(fd,2));
  6951. }
  6952. /// Guild chat message (ZC_GUILD_CHAT).
  6953. /// 017f <packet len>.W <message>.?B
  6954. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6955. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6956. struct map_session_data *sd;
  6957. uint8 buf[256];
  6958. if( len == 0 )
  6959. {
  6960. return;
  6961. }
  6962. else if( len > sizeof(buf)-5 )
  6963. {
  6964. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6965. len = sizeof(buf)-5;
  6966. }
  6967. WBUFW(buf, 0) = 0x17f;
  6968. WBUFW(buf, 2) = len + 5;
  6969. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6970. if ((sd = guild_getavailablesd(g)) != NULL)
  6971. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6972. }
  6973. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6974. /// 0171 <inviter account id>.L <guild name>.24B
  6975. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6976. {
  6977. int fd;
  6978. nullpo_retv(sd);
  6979. fd=sd->fd;
  6980. WFIFOHEAD(fd,packet_len(0x171));
  6981. WFIFOW(fd,0)=0x171;
  6982. WFIFOL(fd,2)=account_id;
  6983. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6984. WFIFOSET(fd,packet_len(0x171));
  6985. }
  6986. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6987. /// 0173 <answer>.B
  6988. /// answer:
  6989. /// 0 = Already allied.
  6990. /// 1 = You rejected the offer.
  6991. /// 2 = You accepted the offer.
  6992. /// 3 = They have too any alliances.
  6993. /// 4 = You have too many alliances.
  6994. /// 5 = Alliances are disabled.
  6995. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6996. {
  6997. int fd;
  6998. nullpo_retv(sd);
  6999. fd=sd->fd;
  7000. WFIFOHEAD(fd,packet_len(0x173));
  7001. WFIFOW(fd,0)=0x173;
  7002. WFIFOL(fd,2)=flag;
  7003. WFIFOSET(fd,packet_len(0x173));
  7004. }
  7005. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7006. /// 0184 <other guild id>.L <relation>.L
  7007. /// relation:
  7008. /// 0 = Ally
  7009. /// 1 = Enemy
  7010. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7011. {
  7012. int fd;
  7013. nullpo_retv(sd);
  7014. fd = sd->fd;
  7015. if (fd <= 0)
  7016. return;
  7017. WFIFOHEAD(fd,packet_len(0x184));
  7018. WFIFOW(fd,0)=0x184;
  7019. WFIFOL(fd,2)=guild_id;
  7020. WFIFOL(fd,6)=flag;
  7021. WFIFOSET(fd,packet_len(0x184));
  7022. }
  7023. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7024. /// 0181 <result>.B
  7025. /// result:
  7026. /// 0 = Antagonist has been set.
  7027. /// 1 = Guild has too many Antagonists.
  7028. /// 2 = Already set as an Antagonist.
  7029. /// 3 = Antagonists are disabled.
  7030. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7031. {
  7032. int fd;
  7033. nullpo_retv(sd);
  7034. fd=sd->fd;
  7035. WFIFOHEAD(fd,packet_len(0x181));
  7036. WFIFOW(fd,0)=0x181;
  7037. WFIFOB(fd,2)=flag;
  7038. WFIFOSET(fd,packet_len(0x181));
  7039. }
  7040. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7041. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7042. /*
  7043. void clif_guild_allianceadded(struct guild *g,int idx)
  7044. {
  7045. unsigned char buf[64];
  7046. WBUFW(buf,0)=0x185;
  7047. WBUFL(buf,2)=g->alliance[idx].opposition;
  7048. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7049. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7050. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7051. }
  7052. */
  7053. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7054. /// 015e <reason>.L
  7055. /// 0 = success
  7056. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7057. /// 2 = there are still members in the guild
  7058. void clif_guild_broken(struct map_session_data *sd,int flag)
  7059. {
  7060. int fd;
  7061. nullpo_retv(sd);
  7062. fd=sd->fd;
  7063. WFIFOHEAD(fd,packet_len(0x15e));
  7064. WFIFOW(fd,0)=0x15e;
  7065. WFIFOL(fd,2)=flag;
  7066. WFIFOSET(fd,packet_len(0x15e));
  7067. }
  7068. /// Displays emotion on an object (ZC_EMOTION).
  7069. /// 00c0 <id>.L <type>.B
  7070. /// type:
  7071. /// enum emotion_type
  7072. void clif_emotion(struct block_list *bl,int type)
  7073. {
  7074. unsigned char buf[8];
  7075. nullpo_retv(bl);
  7076. WBUFW(buf,0)=0xc0;
  7077. WBUFL(buf,2)=bl->id;
  7078. WBUFB(buf,6)=type;
  7079. clif_send(buf,packet_len(0xc0),bl,AREA);
  7080. }
  7081. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7082. /// 0191 <id>.L <contents>.80B
  7083. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7084. {
  7085. unsigned char buf[MESSAGE_SIZE+6];
  7086. nullpo_retv(bl);
  7087. WBUFW(buf,0) = 0x191;
  7088. WBUFL(buf,2) = bl->id;
  7089. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7090. clif_send(buf,packet_len(0x191),bl,AREA);
  7091. }
  7092. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7093. /// 01ea <id>.L
  7094. void clif_wedding_effect(struct block_list *bl)
  7095. {
  7096. unsigned char buf[6];
  7097. nullpo_retv(bl);
  7098. WBUFW(buf,0) = 0x1ea;
  7099. WBUFL(buf,2) = bl->id;
  7100. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7101. }
  7102. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7103. /// 01e6 <partner name>.24B
  7104. void clif_callpartner(struct map_session_data *sd)
  7105. {
  7106. unsigned char buf[26];
  7107. nullpo_retv(sd);
  7108. WBUFW(buf,0) = 0x1e6;
  7109. if( sd->status.partner_id ) {
  7110. const char *p = map_charid2nick(sd->status.partner_id);
  7111. struct map_session_data *p_sd = pc_get_partner(sd);
  7112. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7113. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7114. else
  7115. WBUFB(buf,2) = 0;
  7116. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7117. WBUFB(buf,2) = 0;
  7118. }
  7119. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7120. }
  7121. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7122. /// 01e4
  7123. /// This packet while still implemented by the client is no longer being officially used.
  7124. /*
  7125. void clif_marriage_process(struct map_session_data *sd)
  7126. {
  7127. int fd;
  7128. nullpo_retv(sd);
  7129. fd=sd->fd;
  7130. WFIFOHEAD(fd,packet_len(0x1e4));
  7131. WFIFOW(fd,0)=0x1e4;
  7132. WFIFOSET(fd,packet_len(0x1e4));
  7133. }
  7134. */
  7135. /// Notice of divorce (ZC_DIVORCE).
  7136. /// 0205 <partner name>.24B
  7137. void clif_divorced(struct map_session_data* sd, const char* name)
  7138. {
  7139. int fd;
  7140. nullpo_retv(sd);
  7141. fd=sd->fd;
  7142. WFIFOHEAD(fd,packet_len(0x205));
  7143. WFIFOW(fd,0)=0x205;
  7144. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7145. WFIFOSET(fd, packet_len(0x205));
  7146. }
  7147. /// Marriage proposal (ZC_REQ_COUPLE).
  7148. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7149. /// This packet while still implemented by the client is no longer being officially used.
  7150. /*
  7151. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7152. {
  7153. nullpo_retv(sd);
  7154. WFIFOHEAD(fd,packet_len(0x1e2));
  7155. WFIFOW(fd,0) = 0x1e2;
  7156. WFIFOL(fd,2) = ssd->status.account_id;
  7157. WFIFOL(fd,6) = ssd->status.char_id;
  7158. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7159. WFIFOSET(fd, packet_len(0x1e2));
  7160. }
  7161. */
  7162. /*==========================================
  7163. *
  7164. *------------------------------------------*/
  7165. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7166. {
  7167. clif_disp_message(&sd->bl, mes, len, SELF);
  7168. }
  7169. /*==========================================
  7170. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7171. *------------------------------------------*/
  7172. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7173. {
  7174. unsigned char buf[256];
  7175. if( len == 0 ) {
  7176. return;
  7177. } else if( len > sizeof(buf)-5 ) {
  7178. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7179. len = sizeof(buf)-5;
  7180. }
  7181. WBUFW(buf, 0) = 0x17f;
  7182. WBUFW(buf, 2) = len + 5;
  7183. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7184. clif_send(buf, WBUFW(buf,2), src, target);
  7185. }
  7186. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7187. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7188. /// 00cd <result>.B
  7189. /// result:
  7190. /// 0 = failure
  7191. /// 1 = success
  7192. void clif_GM_kickack(struct map_session_data *sd, int id)
  7193. {
  7194. int fd;
  7195. nullpo_retv(sd);
  7196. fd = sd->fd;
  7197. WFIFOHEAD(fd,packet_len(0xcd));
  7198. WFIFOW(fd,0) = 0xcd;
  7199. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7200. WFIFOSET(fd, packet_len(0xcd));
  7201. }
  7202. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7203. {
  7204. int fd = tsd->fd;
  7205. if( fd > 0 )
  7206. clif_authfail_fd(fd, 15);
  7207. else
  7208. map_quit(tsd);
  7209. if( sd )
  7210. clif_GM_kickack(sd,tsd->status.account_id);
  7211. }
  7212. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7213. /// 014a <result>.L
  7214. /// result:
  7215. /// 0 = "A manner point has been successfully aligned."
  7216. /// 1 = MP_FAILURE_EXHAUST
  7217. /// 2 = MP_FAILURE_ALREADY_GIVING
  7218. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7219. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7220. /// 5 = "You got a good point from %s."
  7221. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7222. {
  7223. int fd;
  7224. nullpo_retv(sd);
  7225. fd = sd->fd;
  7226. WFIFOHEAD(fd,packet_len(0x14a));
  7227. WFIFOW(fd,0) = 0x14a;
  7228. WFIFOL(fd,2) = type;
  7229. WFIFOSET(fd, packet_len(0x14a));
  7230. }
  7231. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7232. /// 014b <type>.B <GM name>.24B
  7233. /// type:
  7234. /// 0 = positive (unmute)
  7235. /// 1 = negative (mute)
  7236. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7237. {
  7238. int fd;
  7239. nullpo_retv(sd);
  7240. nullpo_retv(tsd);
  7241. fd = tsd->fd;
  7242. WFIFOHEAD(fd,packet_len(0x14b));
  7243. WFIFOW(fd,0) = 0x14b;
  7244. WFIFOB(fd,2) = type;
  7245. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7246. WFIFOSET(fd, packet_len(0x14b));
  7247. }
  7248. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7249. /// 00d1 <type>.B <result>.B
  7250. /// type:
  7251. /// 0 = /ex (deny)
  7252. /// 1 = /in (allow)
  7253. /// result:
  7254. /// 0 = success
  7255. /// 1 = failure
  7256. /// 2 = too many blocks
  7257. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7258. {
  7259. int fd;
  7260. nullpo_retv(sd);
  7261. fd=sd->fd;
  7262. WFIFOHEAD(fd,packet_len(0xd1));
  7263. WFIFOW(fd,0)=0xd1;
  7264. WFIFOB(fd,2)=type;
  7265. WFIFOB(fd,3)=flag;
  7266. WFIFOSET(fd,packet_len(0xd1));
  7267. }
  7268. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7269. /// 00d2 <type>.B <result>.B
  7270. /// type:
  7271. /// 0 = /exall (deny)
  7272. /// 1 = /inall (allow)
  7273. /// result:
  7274. /// 0 = success
  7275. /// 1 = failure
  7276. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7277. {
  7278. int fd;
  7279. nullpo_retv(sd);
  7280. fd=sd->fd;
  7281. WFIFOHEAD(fd,packet_len(0xd2));
  7282. WFIFOW(fd,0)=0xd2;
  7283. WFIFOB(fd,2)=type;
  7284. WFIFOB(fd,3)=flag;
  7285. WFIFOSET(fd,packet_len(0xd2));
  7286. }
  7287. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7288. /// 07fe <bgm>.24B
  7289. void clif_playBGM(struct map_session_data* sd, const char* name)
  7290. {
  7291. int fd;
  7292. nullpo_retv(sd);
  7293. fd = sd->fd;
  7294. WFIFOHEAD(fd,packet_len(0x7fe));
  7295. WFIFOW(fd,0) = 0x7fe;
  7296. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7297. WFIFOSET(fd,packet_len(0x7fe));
  7298. }
  7299. /// Plays/stops a wave sound (ZC_SOUND).
  7300. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7301. /// file name:
  7302. /// relative to data\wav
  7303. /// act:
  7304. /// 0 = play (once)
  7305. /// 1 = play (repeat, does not work)
  7306. /// 2 = stops all sound instances of file name (does not work)
  7307. /// term:
  7308. /// unknown purpose, only relevant to act = 1
  7309. /// npc id:
  7310. /// The accustic direction of the sound is determined by the
  7311. /// relative position of the NPC to the player (3D sound).
  7312. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7313. {
  7314. int fd;
  7315. nullpo_retv(sd);
  7316. nullpo_retv(bl);
  7317. fd = sd->fd;
  7318. WFIFOHEAD(fd,packet_len(0x1d3));
  7319. WFIFOW(fd,0) = 0x1d3;
  7320. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7321. WFIFOB(fd,26) = type;
  7322. WFIFOL(fd,27) = 0;
  7323. WFIFOL(fd,31) = bl->id;
  7324. WFIFOSET(fd,packet_len(0x1d3));
  7325. }
  7326. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7327. {
  7328. unsigned char buf[40];
  7329. nullpo_retv(bl);
  7330. WBUFW(buf,0) = 0x1d3;
  7331. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7332. WBUFB(buf,26) = type;
  7333. WBUFL(buf,27) = 0;
  7334. WBUFL(buf,31) = bl->id;
  7335. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7336. }
  7337. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7338. /// 01f3 <id>.L <effect id>.L
  7339. /// effect id:
  7340. /// @see doc/effect_list.txt
  7341. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7342. {
  7343. unsigned char buf[24];
  7344. nullpo_retv(bl);
  7345. memset(buf, 0, packet_len(0x1f3));
  7346. WBUFW(buf,0) = 0x1f3;
  7347. WBUFL(buf,2) = bl->id;
  7348. WBUFL(buf,6) = type;
  7349. clif_send(buf, packet_len(0x1f3), bl, target);
  7350. if (disguised(bl)) {
  7351. WBUFL(buf,2) = -bl->id;
  7352. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7353. }
  7354. }
  7355. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7356. {
  7357. WFIFOHEAD(fd,10);
  7358. WFIFOW(fd,0) = 0x1f3;
  7359. WFIFOL(fd,2) = bl->id;
  7360. WFIFOL(fd,6) = type;
  7361. WFIFOSET(fd,10);
  7362. }
  7363. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7364. /// 0284 <id>.L <effect id>.L <num data>.L
  7365. /// effect id:
  7366. /// @see doc/effect_list.txt
  7367. /// num data:
  7368. /// effect-dependent value
  7369. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7370. {
  7371. uint8 buf[14];
  7372. WBUFW(buf,0) = 0x284;
  7373. WBUFL(buf,2) = bl->id;
  7374. WBUFL(buf,6) = effect_id;
  7375. WBUFL(buf,10) = num;
  7376. clif_send(buf, packet_len(0x284), bl, target);
  7377. if( disguised(bl) )
  7378. {
  7379. WBUFL(buf,2) = -bl->id;
  7380. clif_send(buf, packet_len(0x284), bl, SELF);
  7381. }
  7382. }
  7383. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7384. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7385. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7386. unsigned short msg_len = strlen(msg) + 1;
  7387. WFIFOHEAD(sd->fd,msg_len + 12);
  7388. WFIFOW(sd->fd,0) = 0x2C1;
  7389. WFIFOW(sd->fd,2) = msg_len + 12;
  7390. WFIFOL(sd->fd,4) = 0;
  7391. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7392. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7393. WFIFOSET(sd->fd, msg_len + 12);
  7394. return 0;
  7395. }
  7396. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7397. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7398. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7399. unsigned short msg_len = strlen(msg) + 1;
  7400. uint8 buf[256];
  7401. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7402. nullpo_retv(bl);
  7403. if( msg_len > sizeof(buf)-12 ) {
  7404. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7405. msg_len = sizeof(buf)-12;
  7406. }
  7407. WBUFW(buf,0) = 0x2C1;
  7408. WBUFW(buf,2) = msg_len + 12;
  7409. WBUFL(buf,4) = bl->id;
  7410. WBUFL(buf,8) = color;
  7411. memcpy(WBUFP(buf,12), msg, msg_len);
  7412. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7413. }
  7414. // refresh the client's screen, getting rid of any effects
  7415. void clif_refresh(struct map_session_data *sd)
  7416. {
  7417. int i;
  7418. nullpo_retv(sd);
  7419. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7420. clif_inventorylist(sd);
  7421. if(pc_iscarton(sd)) {
  7422. clif_cartlist(sd);
  7423. clif_updatestatus(sd,SP_CARTINFO);
  7424. }
  7425. clif_updatestatus(sd,SP_WEIGHT);
  7426. clif_updatestatus(sd,SP_MAXWEIGHT);
  7427. clif_updatestatus(sd,SP_STR);
  7428. clif_updatestatus(sd,SP_AGI);
  7429. clif_updatestatus(sd,SP_VIT);
  7430. clif_updatestatus(sd,SP_INT);
  7431. clif_updatestatus(sd,SP_DEX);
  7432. clif_updatestatus(sd,SP_LUK);
  7433. if (sd->spiritball)
  7434. clif_spiritball_single(sd->fd, sd);
  7435. for(i = 1; i < 5; i++){
  7436. if( sd->talisman[i] > 0 )
  7437. clif_talisman_single(sd->fd, sd, i);
  7438. }
  7439. if (sd->vd.cloth_color)
  7440. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7441. if(merc_is_hom_active(sd->hd))
  7442. clif_send_homdata(sd,SP_ACK,0);
  7443. if( sd->md ) {
  7444. clif_mercenary_info(sd);
  7445. clif_mercenary_skillblock(sd);
  7446. }
  7447. if( sd->ed )
  7448. clif_elemental_info(sd);
  7449. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7450. clif_weather_check(sd);
  7451. if( sd->chatID )
  7452. chat_leavechat(sd,0);
  7453. if( sd->state.vending )
  7454. clif_openvending(sd, sd->bl.id, sd->vending);
  7455. if( pc_issit(sd) )
  7456. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7457. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7458. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7459. else
  7460. clif_changed_dir(&sd->bl, SELF);
  7461. // unlike vending, resuming buyingstore crashes the client.
  7462. buyingstore_close(sd);
  7463. mail_clear(sd);
  7464. if( disguised(&sd->bl) ) {/* refresh-da */
  7465. short disguise = sd->disguise;
  7466. pc_disguise(sd, 0);
  7467. pc_disguise(sd, disguise);
  7468. }
  7469. }
  7470. /// Updates the object's (bl) name on client.
  7471. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7472. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7473. void clif_charnameack (int fd, struct block_list *bl)
  7474. {
  7475. unsigned char buf[103];
  7476. int cmd = 0x95, i, ps = -1;
  7477. nullpo_retv(bl);
  7478. WBUFW(buf,0) = cmd;
  7479. WBUFL(buf,2) = bl->id;
  7480. switch( bl->type )
  7481. {
  7482. case BL_PC:
  7483. {
  7484. struct map_session_data *ssd = (struct map_session_data *)bl;
  7485. struct party_data *p = NULL;
  7486. struct guild *g = NULL;
  7487. //Requesting your own "shadow" name. [Skotlex]
  7488. if (ssd->fd == fd && ssd->disguise)
  7489. WBUFL(buf,2) = -bl->id;
  7490. if( ssd->fakename[0] ) {
  7491. WBUFW(buf, 0) = cmd = 0x195;
  7492. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7493. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7494. break;
  7495. }
  7496. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7497. if( ssd->status.party_id ) {
  7498. p = party_search(ssd->status.party_id);
  7499. }
  7500. if( ssd->status.guild_id ) {
  7501. if( ( g = ssd->guild ) != NULL ) {
  7502. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7503. if( i < g->max_member ) ps = g->member[i].position;
  7504. }
  7505. }
  7506. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7507. p = NULL;
  7508. }
  7509. if (p == NULL && g == NULL)
  7510. break;
  7511. WBUFW(buf, 0) = cmd = 0x195;
  7512. if (p)
  7513. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7514. else
  7515. WBUFB(buf,30) = 0;
  7516. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7517. {
  7518. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7519. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7520. } else { //Assume no guild.
  7521. WBUFB(buf,54) = 0;
  7522. WBUFB(buf,78) = 0;
  7523. }
  7524. }
  7525. break;
  7526. //[blackhole89]
  7527. case BL_HOM:
  7528. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7529. break;
  7530. case BL_MER:
  7531. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7532. break;
  7533. case BL_PET:
  7534. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7535. break;
  7536. case BL_NPC:
  7537. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7538. break;
  7539. case BL_MOB:
  7540. {
  7541. struct mob_data *md = (struct mob_data *)bl;
  7542. nullpo_retv(md);
  7543. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7544. if( md->guardian_data && md->guardian_data->guild_id )
  7545. {
  7546. WBUFW(buf, 0) = cmd = 0x195;
  7547. WBUFB(buf,30) = 0;
  7548. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7549. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7550. }
  7551. else if( battle_config.show_mob_info )
  7552. {
  7553. char mobhp[50], *str_p = mobhp;
  7554. WBUFW(buf, 0) = cmd = 0x195;
  7555. if( battle_config.show_mob_info&4 )
  7556. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7557. if( battle_config.show_mob_info&1 )
  7558. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7559. if( battle_config.show_mob_info&2 )
  7560. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7561. //Even thought mobhp ain't a name, we send it as one so the client
  7562. //can parse it. [Skotlex]
  7563. if( str_p != mobhp )
  7564. {
  7565. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7566. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7567. WBUFB(buf,54) = 0;
  7568. WBUFB(buf,78) = 0;
  7569. }
  7570. }
  7571. }
  7572. break;
  7573. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7574. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7575. // break;
  7576. return;
  7577. case BL_ELEM:
  7578. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7579. break;
  7580. default:
  7581. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7582. return;
  7583. }
  7584. // if no receipient specified just update nearby clients
  7585. if (fd == 0)
  7586. clif_send(buf, packet_len(cmd), bl, AREA);
  7587. else {
  7588. WFIFOHEAD(fd, packet_len(cmd));
  7589. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7590. WFIFOSET(fd, packet_len(cmd));
  7591. }
  7592. }
  7593. //Used to update when a char leaves a party/guild. [Skotlex]
  7594. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7595. void clif_charnameupdate (struct map_session_data *ssd)
  7596. {
  7597. unsigned char buf[103];
  7598. int cmd = 0x195, ps = -1;
  7599. struct party_data *p = NULL;
  7600. struct guild *g = NULL;
  7601. nullpo_retv(ssd);
  7602. if( ssd->fakename[0] )
  7603. return; //No need to update as the party/guild was not displayed anyway.
  7604. WBUFW(buf,0) = cmd;
  7605. WBUFL(buf,2) = ssd->bl.id;
  7606. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7607. if (!battle_config.display_party_name) {
  7608. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7609. p = party_search(ssd->status.party_id);
  7610. }else{
  7611. if (ssd->status.party_id > 0)
  7612. p = party_search(ssd->status.party_id);
  7613. }
  7614. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7615. {
  7616. int i;
  7617. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7618. if( i < g->max_member ) ps = g->member[i].position;
  7619. }
  7620. if( p )
  7621. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7622. else
  7623. WBUFB(buf,30) = 0;
  7624. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7625. {
  7626. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7627. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7628. }
  7629. else
  7630. {
  7631. WBUFB(buf,54) = 0;
  7632. WBUFB(buf,78) = 0;
  7633. }
  7634. // Update nearby clients
  7635. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7636. }
  7637. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7638. /// 01ff <id>.L <x>.W <y>.W
  7639. ///
  7640. /// Visually moves(instant) a character to x,y. The char moves even
  7641. /// when the target cell isn't walkable. If the char is sitting it
  7642. /// stays that way.
  7643. void clif_slide(struct block_list *bl, int x, int y)
  7644. {
  7645. unsigned char buf[10];
  7646. nullpo_retv(bl);
  7647. WBUFW(buf, 0) = 0x01ff;
  7648. WBUFL(buf, 2) = bl->id;
  7649. WBUFW(buf, 6) = x;
  7650. WBUFW(buf, 8) = y;
  7651. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7652. if( disguised(bl) )
  7653. {
  7654. WBUFL(buf,2) = -bl->id;
  7655. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7656. }
  7657. }
  7658. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7659. /// 008d <packet len>.W <id>.L <message>.?B
  7660. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7661. {
  7662. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7663. int len_mes = strlen(mes)+1; //Account for \0
  7664. if (len_mes > sizeof(buf)-8) {
  7665. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7666. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7667. }
  7668. // send message to others
  7669. WBUFW(buf,0) = 0x8d;
  7670. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7671. WBUFL(buf,4) = bl->id;
  7672. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7673. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7674. // send back message to the speaker
  7675. if( bl->type == BL_PC ) {
  7676. WBUFW(buf,0) = 0x8e;
  7677. WBUFW(buf, 2) = len_mes + 4;
  7678. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7679. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7680. }
  7681. }
  7682. /*==========================
  7683. * Minimap fix [Kevin]
  7684. * Remove dot from minimap
  7685. *--------------------------*/
  7686. void clif_party_xy_remove(struct map_session_data *sd)
  7687. {
  7688. unsigned char buf[16];
  7689. nullpo_retv(sd);
  7690. WBUFW(buf,0)=0x107;
  7691. WBUFL(buf,2)=sd->status.account_id;
  7692. WBUFW(buf,6)=-1;
  7693. WBUFW(buf,8)=-1;
  7694. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7695. }
  7696. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7697. /// 0215 <msg id>.L
  7698. /// msg id:
  7699. /// 0x15 = End all negative status (PA_GOSPEL)
  7700. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7701. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7702. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7703. /// 0x19 = All stats +20 (PA_GOSPEL)
  7704. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7705. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7706. /// 0x1e = DEF +25% (PA_GOSPEL)
  7707. /// 0x1f = ATK +100% (PA_GOSPEL)
  7708. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7709. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7710. /// ? = nothing
  7711. void clif_gospel_info(struct map_session_data *sd, int type)
  7712. {
  7713. int fd=sd->fd;
  7714. WFIFOHEAD(fd,packet_len(0x215));
  7715. WFIFOW(fd,0)=0x215;
  7716. WFIFOL(fd,2)=type;
  7717. WFIFOSET(fd, packet_len(0x215));
  7718. }
  7719. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7720. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7721. /// result:
  7722. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7723. /// star:
  7724. /// 0 = Place of the Sun
  7725. /// 1 = Place of the Moon
  7726. /// 2 = Place of the Stars
  7727. /// 1 = Star Gladiator %s's %s: <mapname>
  7728. /// star:
  7729. /// 0 = Place of the Sun
  7730. /// 1 = Place of the Moon
  7731. /// 2 = Place of the Stars
  7732. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7733. /// star:
  7734. /// 0 = Target of the Sun
  7735. /// 1 = Target of the Moon
  7736. /// 2 = Target of the Stars
  7737. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7738. /// star:
  7739. /// 0 = Monster of the Sun
  7740. /// 1 = Monster of the Moon
  7741. /// 2 = Monster of the Stars
  7742. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7743. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7744. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7745. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7746. /// 40 = Target HP : <monster_id used as HP>
  7747. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7748. {
  7749. int fd = sd->fd;
  7750. WFIFOHEAD(fd,packet_len(0x20e));
  7751. WFIFOW(fd,0) = 0x20e;
  7752. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7753. WFIFOL(fd,26) = monster_id;
  7754. WFIFOB(fd,30) = star;
  7755. WFIFOB(fd,31) = result;
  7756. WFIFOSET(fd,packet_len(0x20e));
  7757. }
  7758. /*==========================================
  7759. * Info about Star Glaldiator save map [Komurka]
  7760. * type: 1: Information, 0: Map registered
  7761. *------------------------------------------*/
  7762. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7763. {
  7764. char mapname[MAP_NAME_LENGTH_EXT];
  7765. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7766. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7767. }
  7768. /*==========================================
  7769. * Info about Star Glaldiator hate mob [Komurka]
  7770. * type: 1: Register mob, 0: Information.
  7771. *------------------------------------------*/
  7772. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7773. {
  7774. if( pcdb_checkid(class_) ) {
  7775. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7776. } else if( mobdb_checkid(class_) ) {
  7777. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7778. } else {
  7779. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  7780. }
  7781. }
  7782. /*==========================================
  7783. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7784. *------------------------------------------*/
  7785. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7786. {
  7787. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7788. }
  7789. /*==========================================
  7790. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7791. *------------------------------------------*/
  7792. void clif_feel_hate_reset(struct map_session_data *sd)
  7793. {
  7794. clif_starskill(sd, "", 0, 0, 30);
  7795. }
  7796. /// Equip window (un)tick ack (ZC_CONFIG).
  7797. /// 02d9 <type>.L <value>.L
  7798. /// type:
  7799. /// 0 = open equip window
  7800. /// value:
  7801. /// 0 = disabled
  7802. /// 1 = enabled
  7803. void clif_equiptickack(struct map_session_data* sd, int flag)
  7804. {
  7805. int fd;
  7806. nullpo_retv(sd);
  7807. fd = sd->fd;
  7808. WFIFOHEAD(fd, packet_len(0x2d9));
  7809. WFIFOW(fd, 0) = 0x2d9;
  7810. WFIFOL(fd, 2) = 0;
  7811. WFIFOL(fd, 6) = flag;
  7812. WFIFOSET(fd, packet_len(0x2d9));
  7813. }
  7814. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7815. /// 02da <open equip window>.B
  7816. /// open equip window:
  7817. /// 0 = disabled
  7818. /// 1 = enabled
  7819. void clif_equipcheckbox(struct map_session_data* sd)
  7820. {
  7821. int fd;
  7822. nullpo_retv(sd);
  7823. fd = sd->fd;
  7824. WFIFOHEAD(fd, packet_len(0x2da));
  7825. WFIFOW(fd, 0) = 0x2da;
  7826. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7827. WFIFOSET(fd, packet_len(0x2da));
  7828. }
  7829. /// Sends info about a player's equipped items.
  7830. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <up-viewid>.W <mid-viewid>.W <low-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.26B* (ZC_EQUIPWIN_MICROSCOPE)
  7831. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE, PACKETVER >= 20100629)
  7832. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20101124)
  7833. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20110111)
  7834. /// 0997 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.31B* (ZC_EQUIPWIN_MICROSCOPE_V5, PACKETVER >= 20120925)
  7835. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7836. {
  7837. uint8* buf;
  7838. int i, n, fd, offset = 0;
  7839. #if PACKETVER < 20100629
  7840. const int s = 26;
  7841. #elif PACKETVER < 20120925
  7842. const int s = 28;
  7843. #else
  7844. const int s = 31;
  7845. #endif
  7846. nullpo_retv(sd);
  7847. nullpo_retv(tsd);
  7848. fd = sd->fd;
  7849. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7850. buf = WFIFOP(fd,0);
  7851. #if PACKETVER < 20101124
  7852. WBUFW(buf, 0) = 0x2d7;
  7853. #elif PACKETVER < 20120925
  7854. WBUFW(buf, 0) = 0x859;
  7855. #else
  7856. WBUFW(buf, 0) = 0x997;
  7857. #endif
  7858. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7859. WBUFW(buf,28) = tsd->status.class_;
  7860. WBUFW(buf,30) = tsd->vd.hair_style;
  7861. WBUFW(buf,32) = tsd->vd.head_bottom;
  7862. WBUFW(buf,34) = tsd->vd.head_mid;
  7863. WBUFW(buf,36) = tsd->vd.head_top;
  7864. #if PACKETVER >= 20110111
  7865. WBUFW(buf,38) = tsd->vd.robe;
  7866. offset+= 2;
  7867. buf = WBUFP(buf,2);
  7868. #endif
  7869. WBUFW(buf,38) = tsd->vd.hair_color;
  7870. WBUFW(buf,40) = tsd->vd.cloth_color;
  7871. WBUFB(buf,42) = tsd->vd.sex;
  7872. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7873. {
  7874. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7875. continue;
  7876. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7877. continue;
  7878. // Add item info : refine, identify flag, element, etc.
  7879. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7880. n++;
  7881. }
  7882. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7883. WFIFOSET(fd, WFIFOW(fd, 2));
  7884. }
  7885. /// Display msgstringtable.txt string (ZC_MSG).
  7886. /// 0291 <message>.W
  7887. void clif_msg(struct map_session_data* sd, unsigned short id)
  7888. {
  7889. int fd;
  7890. nullpo_retv(sd);
  7891. fd = sd->fd;
  7892. WFIFOHEAD(fd, packet_len(0x291));
  7893. WFIFOW(fd, 0) = 0x291;
  7894. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7895. WFIFOSET(fd, packet_len(0x291));
  7896. }
  7897. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7898. /// 0x7e2 <message>.W <value>.L
  7899. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7900. {
  7901. int fd = sd->fd;
  7902. WFIFOHEAD(fd, packet_len(0x7e2));
  7903. WFIFOW(fd,0) = 0x7e2;
  7904. WFIFOW(fd,2) = id;
  7905. WFIFOL(fd,4) = value;
  7906. WFIFOSET(fd, packet_len(0x7e2));
  7907. }
  7908. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7909. /// 07e6 <skill id>.W <msg id>.L
  7910. ///
  7911. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7912. /// "[SkillName] Message"
  7913. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7914. {
  7915. int fd = sd->fd;
  7916. WFIFOHEAD(fd, packet_len(0x7e6));
  7917. WFIFOW(fd,0) = 0x7e6;
  7918. WFIFOW(fd,2) = skill_id;
  7919. WFIFOL(fd,4) = msg_id;
  7920. WFIFOSET(fd, packet_len(0x7e6));
  7921. }
  7922. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7923. /// Returns true if the packet was parsed successfully.
  7924. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7925. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7926. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7927. {
  7928. char *text, *name, *message;
  7929. unsigned int packetlen, textlen, namelen, messagelen;
  7930. int fd = sd->fd;
  7931. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  7932. *name_ = NULL;
  7933. *namelen_ = 0;
  7934. *message_ = NULL;
  7935. *messagelen_ = 0;
  7936. packetlen = RFIFOW(fd,info->pos[0]);
  7937. // basic structure checks
  7938. if( packetlen < 4 + 1 )
  7939. { // 4-byte header and at least an empty string is expected
  7940. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7941. return false;
  7942. }
  7943. text = (char*)RFIFOP(fd,info->pos[1]);
  7944. textlen = packetlen - 4;
  7945. // process <name> part of the packet
  7946. if( format == 0 )
  7947. {// name and message are separated by ' : '
  7948. // validate name
  7949. name = text;
  7950. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7951. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7952. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7953. {
  7954. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7955. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7956. set_eof(fd); // Just kick them out to correct it.
  7957. return false;
  7958. }
  7959. message = name + namelen + 3;
  7960. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7961. }
  7962. else
  7963. {// name has fixed width
  7964. if( textlen < NAME_LENGTH + 1 )
  7965. {
  7966. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7967. return false;
  7968. }
  7969. // validate name
  7970. name = text;
  7971. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7972. if( name[namelen] != '\0' )
  7973. { // only restriction is that the name must be zero-terminated
  7974. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7975. return false;
  7976. }
  7977. message = name + NAME_LENGTH;
  7978. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7979. }
  7980. if( messagelen != strnlen(message, messagelen)+1 )
  7981. { // the declared length must match real length
  7982. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7983. return false;
  7984. }
  7985. // verify <message> part of the packet
  7986. if( message[messagelen-1] != '\0' )
  7987. { // message must be zero-terminated
  7988. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7989. return false;
  7990. }
  7991. if( messagelen > CHAT_SIZE_MAX-1 )
  7992. { // messages mustn't be too long
  7993. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7994. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7995. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7996. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7997. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7998. return false;
  7999. }
  8000. *name_ = name;
  8001. *namelen_ = namelen;
  8002. *message_ = message;
  8003. *messagelen_ = messagelen;
  8004. return true;
  8005. }
  8006. // ---------------------
  8007. // clif_guess_PacketVer
  8008. // ---------------------
  8009. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8010. // error codes:
  8011. // 0 - Success
  8012. // 1 - Unknown packet_ver
  8013. // 2 - Invalid account_id
  8014. // 3 - Invalid char_id
  8015. // 4 - Invalid login_id1 (reserved)
  8016. // 5 - Invalid client_tick (reserved)
  8017. // 6 - Invalid sex
  8018. // Only the first 'invalid' error that appears is used.
  8019. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8020. {
  8021. static int err = 1;
  8022. static int packet_ver = -1;
  8023. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  8024. if (get_previous)
  8025. {//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]
  8026. if( error )
  8027. *error = err;
  8028. return packet_ver;
  8029. }
  8030. //By default, start searching on the default one.
  8031. err = 1;
  8032. packet_ver = clif_config.packet_db_ver;
  8033. cmd = RFIFOW(fd,0);
  8034. packet_len = RFIFOREST(fd);
  8035. #define SET_ERROR(n) \
  8036. if( err == 1 )\
  8037. err = n;\
  8038. //define SET_ERROR
  8039. // FIXME: If the packet is not received at once, this will FAIL.
  8040. // Figure out, when it happens, that only part of the packet is
  8041. // received, or fix the function to be able to deal with that
  8042. // case.
  8043. #define CHECK_PACKET_VER() \
  8044. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8045. ;/* not wanttoconnection or wrong length */\
  8046. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8047. { SET_ERROR(2); }/* invalid account_id */\
  8048. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8049. { SET_ERROR(3); }/* invalid char_id */\
  8050. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8051. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8052. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8053. { SET_ERROR(6); }/* invalid sex */\
  8054. else\
  8055. {\
  8056. err = 0;\
  8057. if( error )\
  8058. *error = 0;\
  8059. return packet_ver;\
  8060. }\
  8061. //define CHECK_PACKET_VER
  8062. CHECK_PACKET_VER();//Default packet version found.
  8063. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8064. CHECK_PACKET_VER();
  8065. }
  8066. if( error )
  8067. *error = err;
  8068. packet_ver = -1;
  8069. return -1;
  8070. #undef SET_ERROR
  8071. #undef CHECK_PACKET_VER
  8072. }
  8073. // ------------
  8074. // clif_parse_*
  8075. // ------------
  8076. // Parses incoming (player) connection
  8077. /// Request to connect to map-server.
  8078. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8079. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8080. /// There are various variants of this packet, some of them have padding between fields.
  8081. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8082. {
  8083. struct block_list* bl;
  8084. struct auth_node* node;
  8085. int cmd, account_id, char_id, login_id1, sex;
  8086. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8087. 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])
  8088. if (sd) {
  8089. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8090. return;
  8091. }
  8092. // Only valid packet version get here
  8093. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8094. cmd = RFIFOW(fd,0);
  8095. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8096. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8097. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8098. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8099. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8100. if( packet_ver < 5 || // reject really old client versions
  8101. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8102. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8103. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8104. {// packet version rejected
  8105. 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));
  8106. WFIFOHEAD(fd,packet_len(0x6a));
  8107. WFIFOW(fd,0) = 0x6a;
  8108. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8109. WFIFOSET(fd,packet_len(0x6a));
  8110. set_eof(fd);
  8111. return;
  8112. }
  8113. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8114. clif_authfail_fd(fd,1);// server closed
  8115. return;
  8116. }
  8117. //Check for double login.
  8118. bl = map_id2bl(account_id);
  8119. if(bl && bl->type != BL_PC) {
  8120. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8121. WFIFOHEAD(fd,packet_len(0x6a));
  8122. WFIFOW(fd,0) = 0x6a;
  8123. WFIFOB(fd,2) = 3; // Rejected by server
  8124. WFIFOSET(fd,packet_len(0x6a));
  8125. set_eof(fd);
  8126. return;
  8127. }
  8128. if (bl ||
  8129. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8130. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8131. {
  8132. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8133. return;
  8134. }
  8135. CREATE(sd, TBL_PC, 1);
  8136. sd->fd = fd;
  8137. sd->packet_ver = packet_ver;
  8138. session[fd]->session_data = sd;
  8139. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8140. #if PACKETVER < 20070521
  8141. WFIFOHEAD(fd,4);
  8142. WFIFOL(fd,0) = sd->bl.id;
  8143. WFIFOSET(fd,4);
  8144. #else
  8145. WFIFOHEAD(fd,packet_len(0x283));
  8146. WFIFOW(fd,0) = 0x283;
  8147. WFIFOL(fd,2) = sd->bl.id;
  8148. WFIFOSET(fd,packet_len(0x283));
  8149. #endif
  8150. chrif_authreq(sd,false);
  8151. }
  8152. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8153. /// 007d
  8154. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8155. {
  8156. if(sd->bl.prev != NULL)
  8157. return;
  8158. if (!sd->state.active) { //Character loading is not complete yet!
  8159. //Let pc_reg_received reinvoke this when ready.
  8160. sd->state.connect_new = 0;
  8161. return;
  8162. }
  8163. if (sd->state.rewarp) { //Rewarp player.
  8164. sd->state.rewarp = 0;
  8165. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8166. return;
  8167. }
  8168. sd->state.warping = 0;
  8169. // look
  8170. #if PACKETVER < 4
  8171. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8172. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8173. #else
  8174. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8175. #endif
  8176. if(sd->vd.cloth_color)
  8177. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8178. // item
  8179. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8180. pc_checkitem(sd);
  8181. // cart
  8182. if(pc_iscarton(sd)) {
  8183. clif_cartlist(sd);
  8184. clif_updatestatus(sd,SP_CARTINFO);
  8185. }
  8186. // weight
  8187. clif_updatestatus(sd,SP_WEIGHT);
  8188. clif_updatestatus(sd,SP_MAXWEIGHT);
  8189. // guild
  8190. // (needs to go before clif_spawn() to show guild emblems correctly)
  8191. if(sd->status.guild_id)
  8192. guild_send_memberinfoshort(sd,1);
  8193. if(battle_config.pc_invincible_time > 0) {
  8194. if(map_flag_gvg(sd->bl.m))
  8195. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8196. else
  8197. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8198. }
  8199. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8200. map_spawnmobs(sd->bl.m);
  8201. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8202. map[sd->bl.m].users_pvp++;
  8203. }
  8204. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8205. // reset the callshop flag if the player changes map
  8206. sd->state.callshop = 0;
  8207. if(map_addblock(&sd->bl))
  8208. return;
  8209. clif_spawn(&sd->bl);
  8210. // Party
  8211. // (needs to go after clif_spawn() to show hp bars correctly)
  8212. if(sd->status.party_id) {
  8213. party_send_movemap(sd);
  8214. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8215. }
  8216. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8217. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8218. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8219. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8220. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8221. sd->pvp_rank = 0;
  8222. sd->pvp_lastusers = 0;
  8223. sd->pvp_point = 5;
  8224. sd->pvp_won = 0;
  8225. sd->pvp_lost = 0;
  8226. }
  8227. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8228. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8229. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8230. if (map[sd->bl.m].flag.gvg_dungeon)
  8231. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8232. if( map_flag_gvg(sd->bl.m) )
  8233. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8234. // info about nearby objects
  8235. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8236. 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);
  8237. // pet
  8238. if( sd->pd ) {
  8239. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8240. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8241. pet_menu(sd, 3); //Option 3 is return to egg.
  8242. } else {
  8243. if(map_addblock(&sd->pd->bl))
  8244. return;
  8245. clif_spawn(&sd->pd->bl);
  8246. clif_send_petdata(sd,sd->pd,0,0);
  8247. clif_send_petstatus(sd);
  8248. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8249. }
  8250. }
  8251. //homunculus [blackhole89]
  8252. if( merc_is_hom_active(sd->hd) ) {
  8253. if(map_addblock(&sd->hd->bl))
  8254. return;
  8255. clif_spawn(&sd->hd->bl);
  8256. clif_send_homdata(sd,SP_ACK,0);
  8257. clif_hominfo(sd,sd->hd,1);
  8258. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8259. clif_homskillinfoblock(sd);
  8260. if( battle_config.hom_setting&0x8 )
  8261. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8262. if( !(battle_config.hom_setting&0x2) )
  8263. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8264. }
  8265. if( sd->md ) {
  8266. if(map_addblock(&sd->md->bl))
  8267. return;
  8268. clif_spawn(&sd->md->bl);
  8269. clif_mercenary_info(sd);
  8270. clif_mercenary_skillblock(sd);
  8271. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8272. }
  8273. if( sd->ed ) {
  8274. map_addblock(&sd->ed->bl);
  8275. clif_spawn(&sd->ed->bl);
  8276. clif_elemental_info(sd);
  8277. clif_elemental_updatestatus(sd,SP_HP);
  8278. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8279. clif_elemental_updatestatus(sd,SP_SP);
  8280. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8281. }
  8282. if(sd->state.connect_new) {
  8283. int lv;
  8284. sd->state.connect_new = 0;
  8285. clif_skillinfoblock(sd);
  8286. clif_hotkeys_send(sd);
  8287. clif_updatestatus(sd,SP_BASEEXP);
  8288. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8289. clif_updatestatus(sd,SP_JOBEXP);
  8290. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8291. clif_updatestatus(sd,SP_SKILLPOINT);
  8292. clif_initialstatus(sd);
  8293. if (sd->sc.option&OPTION_FALCON)
  8294. clif_status_load(&sd->bl, SI_FALCON, 1);
  8295. if (sd->sc.option&OPTION_RIDING)
  8296. clif_status_load(&sd->bl, SI_RIDING, 1);
  8297. else if (sd->sc.option&OPTION_WUGRIDER)
  8298. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8299. if(sd->status.manner < 0)
  8300. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8301. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8302. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8303. if(sd->bl.m == sd->feel_map[0].m
  8304. || sd->bl.m == sd->feel_map[1].m
  8305. || sd->bl.m == sd->feel_map[2].m)
  8306. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8307. }
  8308. if(sd->pd && sd->pd->pet.intimate > 900)
  8309. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8310. if(merc_is_hom_active(sd->hd))
  8311. merc_hom_init_timers(sd->hd);
  8312. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8313. sd->state.night = 1;
  8314. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8315. }
  8316. // Notify everyone that this char logged in [Skotlex].
  8317. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8318. // Set the initial idle time
  8319. sd->idletime = last_tick;
  8320. //Login Event
  8321. npc_script_event(sd, NPCE_LOGIN);
  8322. } else {
  8323. //For some reason the client "loses" these on warp/map-change.
  8324. clif_updatestatus(sd,SP_STR);
  8325. clif_updatestatus(sd,SP_AGI);
  8326. clif_updatestatus(sd,SP_VIT);
  8327. clif_updatestatus(sd,SP_INT);
  8328. clif_updatestatus(sd,SP_DEX);
  8329. clif_updatestatus(sd,SP_LUK);
  8330. // abort currently running script
  8331. sd->state.using_fake_npc = 0;
  8332. sd->state.menu_or_input = 0;
  8333. sd->npc_menu = 0;
  8334. if(sd->npc_id)
  8335. npc_event_dequeue(sd);
  8336. }
  8337. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8338. #if PACKETVER >= 20070918
  8339. clif_partyinvitationstate(sd);
  8340. clif_equipcheckbox(sd);
  8341. #endif
  8342. #ifdef VIP_ENABLE
  8343. if (!sd->disableshowrate) {
  8344. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8345. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8346. }
  8347. #endif
  8348. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8349. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8350. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8351. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8352. { //Display night.
  8353. if( !sd->state.night )
  8354. {
  8355. sd->state.night = 1;
  8356. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8357. }
  8358. }
  8359. else if( sd->state.night )
  8360. { //Clear night display.
  8361. sd->state.night = 0;
  8362. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8363. }
  8364. if( map[sd->bl.m].flag.battleground )
  8365. {
  8366. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8367. if( map[sd->bl.m].flag.battleground == 2 )
  8368. clif_bg_updatescore_single(sd);
  8369. }
  8370. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8371. {
  8372. char output[128];
  8373. safesnprintf(output,sizeof(output),"[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8374. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8375. }
  8376. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8377. map[sd->bl.m].hpmeter_visible++;
  8378. sd->state.hpmeter_visible = 1;
  8379. }
  8380. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8381. status_calc_pc(sd, false); // Some conditions are map-dependent so we must recalculate
  8382. sd->state.changemap = false;
  8383. // Instances do not need their own channels
  8384. if( Channel_Config.map_enable && Channel_Config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id ) {
  8385. channel_mjoin(sd); //join new map
  8386. }
  8387. }
  8388. mail_clear(sd);
  8389. clif_maptypeproperty2(&sd->bl,SELF);
  8390. /* Guild Aura Init */
  8391. if( sd->state.gmaster_flag ) {
  8392. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8393. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8394. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8395. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8396. }
  8397. if( sd->state.vending ) { /* show we have a vending */
  8398. clif_openvending(sd,sd->bl.id,sd->vending);
  8399. clif_showvendingboard(&sd->bl,sd->message,0);
  8400. }
  8401. if(map[sd->bl.m].flag.loadevent) // Lance
  8402. npc_script_event(sd, NPCE_LOADMAP);
  8403. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8404. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8405. if (sd->sc.opt2) //Client loses these on warp.
  8406. clif_changeoption(&sd->bl);
  8407. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8408. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8409. clif_displaymessage(sd->fd, msg_txt(sd,1500)); // Transforming into monster is not allowed in Guild Wars.
  8410. }
  8411. clif_weather_check(sd);
  8412. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8413. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8414. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8415. else
  8416. sd->areanpc_id = 0;
  8417. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8418. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8419. pc_setdead(sd);
  8420. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8421. if(pc_isdead(sd))
  8422. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8423. else {
  8424. skill_usave_trigger(sd);
  8425. clif_changed_dir(&sd->bl, SELF);
  8426. }
  8427. // Trigger skill effects if you appear standing on them
  8428. if(!battle_config.pc_invincible_time)
  8429. skill_unit_move(&sd->bl,gettick(),1);
  8430. }
  8431. /// Server's tick (ZC_NOTIFY_TIME).
  8432. /// 007f <time>.L
  8433. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8434. {
  8435. int fd = sd->fd;
  8436. WFIFOHEAD(fd,packet_len(0x7f));
  8437. WFIFOW(fd,0) = 0x7f;
  8438. WFIFOL(fd,2) = time;
  8439. WFIFOSET(fd,packet_len(0x7f));
  8440. }
  8441. /// Request for server's tick.
  8442. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8443. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8444. /// There are various variants of this packet, some of them have padding between fields.
  8445. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8446. {
  8447. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8448. clif_notify_time(sd, gettick());
  8449. }
  8450. /// Sends hotkey bar.
  8451. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8452. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8453. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8454. void clif_hotkeys_send(struct map_session_data *sd) {
  8455. #ifdef HOTKEY_SAVING
  8456. const int fd = sd->fd;
  8457. int i;
  8458. #if PACKETVER < 20090603
  8459. const int cmd = 0x2b9;
  8460. #else
  8461. const int cmd = 0x7d9;
  8462. #endif
  8463. if (!fd) return;
  8464. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8465. WFIFOW(fd, 0) = cmd;
  8466. for(i = 0; i < MAX_HOTKEYS; i++) {
  8467. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8468. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8469. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8470. }
  8471. WFIFOSET(fd, packet_len(cmd));
  8472. #endif
  8473. }
  8474. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8475. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8476. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8477. #ifdef HOTKEY_SAVING
  8478. unsigned short idx;
  8479. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8480. idx = RFIFOW(fd, info->pos[0]);
  8481. if (idx >= MAX_HOTKEYS) return;
  8482. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8483. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8484. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8485. #endif
  8486. }
  8487. /// Displays cast-like progress bar (ZC_PROGRESS).
  8488. /// 02f0 <color>.L <time>.L
  8489. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8490. {
  8491. int fd = sd->fd;
  8492. WFIFOHEAD(fd,packet_len(0x2f0));
  8493. WFIFOW(fd,0) = 0x2f0;
  8494. WFIFOL(fd,2) = color;
  8495. WFIFOL(fd,6) = second;
  8496. WFIFOSET(fd,packet_len(0x2f0));
  8497. }
  8498. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8499. /// 02f2
  8500. void clif_progressbar_abort(struct map_session_data * sd)
  8501. {
  8502. int fd = sd->fd;
  8503. WFIFOHEAD(fd,packet_len(0x2f2));
  8504. WFIFOW(fd,0) = 0x2f2;
  8505. WFIFOSET(fd,packet_len(0x2f2));
  8506. }
  8507. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8508. /// 02f1
  8509. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8510. {
  8511. int npc_id = sd->progressbar.npc_id;
  8512. if( gettick() < sd->progressbar.timeout && sd->st )
  8513. sd->st->state = END;
  8514. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8515. npc_scriptcont(sd, npc_id, false);
  8516. }
  8517. /// Request to walk to a certain position on the current map.
  8518. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8519. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8520. /// There are various variants of this packet, some of them have padding between fields.
  8521. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8522. {
  8523. short x, y;
  8524. if (pc_isdead(sd)) {
  8525. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8526. return;
  8527. }
  8528. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8529. ; //You CAN walk on this OPT1 value.
  8530. else if( sd->progressbar.npc_id )
  8531. clif_progressbar_abort(sd);
  8532. else if (pc_cant_act(sd))
  8533. return;
  8534. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8535. return;
  8536. // Cloaking wall check is actually updated when you click to process next movement
  8537. // not when you move each cell. This is official behaviour.
  8538. if (sd->sc.data[SC_CLOAKING])
  8539. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8540. pc_delinvincibletimer(sd);
  8541. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8542. //Set last idle time... [Skotlex]
  8543. sd->idletime = last_tick;
  8544. unit_walktoxy(&sd->bl, x, y, 4);
  8545. }
  8546. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8547. /// 018b <result>.W
  8548. /// result:
  8549. /// 0 = disconnect (quit)
  8550. /// 1 = cannot disconnect (wait 10 seconds)
  8551. /// ? = ignored
  8552. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8553. {
  8554. int fd = sd->fd;
  8555. WFIFOHEAD(fd,packet_len(0x18b));
  8556. WFIFOW(fd,0) = 0x18b;
  8557. WFIFOW(fd,2) = result;
  8558. WFIFOSET(fd,packet_len(0x18b));
  8559. }
  8560. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8561. /// 018a <type>.W
  8562. /// type:
  8563. /// 0 = quit
  8564. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8565. {
  8566. /* Rovert's prevent logout option fixed [Valaris] */
  8567. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8568. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8569. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8570. {
  8571. set_eof(fd);
  8572. pc_damage_log_clear(sd,0);
  8573. clif_disconnect_ack(sd, 0);
  8574. } else {
  8575. clif_disconnect_ack(sd, 1);
  8576. }
  8577. }
  8578. /// Requesting unit's name.
  8579. /// 0094 <id>.L (CZ_REQNAME)
  8580. /// 0368 <id>.L (CZ_REQNAME2)
  8581. /// There are various variants of this packet, some of them have padding between fields.
  8582. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8583. {
  8584. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8585. struct block_list* bl;
  8586. //struct status_change *sc;
  8587. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8588. id = sd->bl.id;
  8589. bl = map_id2bl(id);
  8590. if( bl == NULL )
  8591. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8592. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8593. return; // Block namerequests past view range
  8594. // 'see people in GM hide' cheat detection
  8595. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8596. sc = status_get_sc(bl);
  8597. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8598. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8599. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8600. ) {
  8601. char gm_msg[256];
  8602. 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);
  8603. ShowWarning(gm_msg);
  8604. // information is sent to all online GMs
  8605. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8606. return;
  8607. }
  8608. */
  8609. clif_charnameack(fd, bl);
  8610. }
  8611. /// Validates and processes global messages
  8612. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8613. /// There are various variants of this packet.
  8614. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8615. {
  8616. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8617. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8618. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8619. char *name, *message, *fakename = NULL;
  8620. int namelen, messagelen;
  8621. bool is_fake;
  8622. // validate packet and retrieve name and message
  8623. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8624. return;
  8625. if( is_atcommand(fd, sd, message, 1) )
  8626. return;
  8627. if (sd->sc.cant.chat)
  8628. return; //no "chatting" while muted.
  8629. if( battle_config.min_chat_delay ) { //[Skotlex]
  8630. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8631. return;
  8632. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8633. }
  8634. if( sd->gcbind ) {
  8635. channel_send(sd->gcbind,sd,message);
  8636. return;
  8637. }
  8638. /**
  8639. * Fake Name Design by FatalEror (bug report #9)
  8640. **/
  8641. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8642. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8643. strcpy(fakename, sd->fakename);
  8644. strcat(fakename, " : ");
  8645. strcat(fakename, message);
  8646. textlen = strlen(fakename) + 1;
  8647. }
  8648. // send message to others (using the send buffer for temp. storage)
  8649. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8650. // send back message to the speaker
  8651. if( is_fake ) {
  8652. WFIFOW(fd,0) = 0x8e;
  8653. WFIFOW(fd,2) = textlen + 4;
  8654. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8655. aFree(fakename);
  8656. } else {
  8657. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8658. WFIFOW(fd,0) = 0x8e;
  8659. }
  8660. WFIFOSET(fd, WFIFOW(fd,2));
  8661. #ifdef PCRE_SUPPORT
  8662. // trigger listening npcs
  8663. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8664. #endif
  8665. // Reset idle time when using normal chat.
  8666. sd->idletime = last_tick;
  8667. // Chat logging type 'O' / Global Chat
  8668. log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8669. }
  8670. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8671. /// Request to warp to a map on given coordinates.
  8672. /// 0140 <map name>.16B <x>.W <y>.W
  8673. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8674. {
  8675. char command[MAP_NAME_LENGTH_EXT+25];
  8676. char* map_name;
  8677. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8678. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8679. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8680. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8681. RFIFOW(fd,info->pos[1]), //x
  8682. RFIFOW(fd,info->pos[2])); //y
  8683. is_atcommand(fd, sd, command, 1);
  8684. }
  8685. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8686. /// 009c <id>.L <head dir>.W <dir>.B
  8687. /// head dir:
  8688. /// 0 = straight
  8689. /// 1 = turned CW
  8690. /// 2 = turned CCW
  8691. /// dir:
  8692. /// 0 = north
  8693. /// 1 = northwest
  8694. /// 2 = west
  8695. /// 3 = southwest
  8696. /// 4 = south
  8697. /// 5 = southeast
  8698. /// 6 = east
  8699. /// 7 = northeast
  8700. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8701. {
  8702. unsigned char buf[64];
  8703. WBUFW(buf,0) = 0x9c;
  8704. WBUFL(buf,2) = bl->id;
  8705. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8706. WBUFB(buf,8) = unit_getdir(bl);
  8707. clif_send(buf, packet_len(0x9c), bl, target);
  8708. if (disguised(bl)) {
  8709. WBUFL(buf,2) = -bl->id;
  8710. WBUFW(buf,6) = 0;
  8711. clif_send(buf, packet_len(0x9c), bl, SELF);
  8712. }
  8713. }
  8714. /// Request to change own body and head direction.
  8715. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8716. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8717. /// There are various variants of this packet, some of them have padding between fields.
  8718. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8719. {
  8720. unsigned char headdir, dir;
  8721. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8722. headdir = RFIFOB(fd,info->pos[0]);
  8723. dir = RFIFOB(fd,info->pos[1]);
  8724. pc_setdir(sd, dir, headdir);
  8725. clif_changed_dir(&sd->bl, AREA_WOS);
  8726. }
  8727. /// Request to show an emotion (CZ_REQ_EMOTION).
  8728. /// 00bf <type>.B
  8729. /// type:
  8730. /// @see enum emotion_type
  8731. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8732. {
  8733. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8734. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8735. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8736. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8737. return;
  8738. }
  8739. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8740. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8741. sd->emotionlasttime = time(NULL);
  8742. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8743. return;
  8744. }
  8745. sd->emotionlasttime = time(NULL);
  8746. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8747. emoticon = rnd()%6+E_DICE1;
  8748. }
  8749. clif_emotion(&sd->bl, emoticon);
  8750. } else
  8751. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8752. }
  8753. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8754. /// 00c2 <count>.L
  8755. void clif_user_count(struct map_session_data* sd, int count)
  8756. {
  8757. int fd = sd->fd;
  8758. WFIFOHEAD(fd,packet_len(0xc2));
  8759. WFIFOW(fd,0) = 0xc2;
  8760. WFIFOL(fd,2) = count;
  8761. WFIFOSET(fd,packet_len(0xc2));
  8762. }
  8763. /// /w /who (CZ_REQ_USER_COUNT).
  8764. /// Request to display amount of currently connected players.
  8765. /// 00c1
  8766. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8767. {
  8768. clif_user_count(sd, map_getusers());
  8769. }
  8770. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8771. {
  8772. if (pc_isdead(sd)) {
  8773. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8774. return;
  8775. }
  8776. if (sd->sc.count &&
  8777. (sd->sc.data[SC_TRICKDEAD] ||
  8778. sd->sc.data[SC_AUTOCOUNTER] ||
  8779. sd->sc.data[SC_BLADESTOP] ||
  8780. sd->sc.data[SC__MANHOLE] ||
  8781. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8782. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8783. return;
  8784. pc_stop_walking(sd, 1);
  8785. pc_stop_attack(sd);
  8786. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8787. target_id = sd->bl.id;
  8788. switch(action_type)
  8789. {
  8790. case 0x00: // once attack
  8791. case 0x07: // continuous attack
  8792. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8793. return;
  8794. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK|OPTION_OKTOBERFEST) )
  8795. return;
  8796. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8797. return;
  8798. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8799. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8800. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8801. return;
  8802. }
  8803. }
  8804. pc_delinvincibletimer(sd);
  8805. sd->idletime = last_tick;
  8806. unit_attack(&sd->bl, target_id, action_type != 0);
  8807. break;
  8808. case 0x02: // sitdown
  8809. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8810. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8811. break;
  8812. }
  8813. if(pc_issit(sd)) {
  8814. //Bugged client? Just refresh them.
  8815. clif_sitting(&sd->bl);
  8816. return;
  8817. }
  8818. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8819. break;
  8820. if (sd->sc.count && (
  8821. sd->sc.data[SC_DANCING] ||
  8822. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8823. )) //No sitting during these states either.
  8824. break;
  8825. sd->idletime = last_tick;
  8826. pc_setsit(sd);
  8827. skill_sit(sd,1);
  8828. clif_sitting(&sd->bl);
  8829. break;
  8830. case 0x03: // standup
  8831. if (!pc_issit(sd)) {
  8832. //Bugged client? Just refresh them.
  8833. clif_standing(&sd->bl);
  8834. return;
  8835. }
  8836. sd->idletime = last_tick;
  8837. pc_setstand(sd);
  8838. skill_sit(sd,0);
  8839. clif_standing(&sd->bl);
  8840. break;
  8841. }
  8842. }
  8843. /// Request for an action.
  8844. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8845. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8846. /// action:
  8847. /// 0 = attack
  8848. /// 1 = pick up item
  8849. /// 2 = sit down
  8850. /// 3 = stand up
  8851. /// 7 = continous attack
  8852. /// 12 = (touch skill?)
  8853. /// There are various variants of this packet, some of them have padding between fields.
  8854. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8855. {
  8856. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8857. clif_parse_ActionRequest_sub(sd,
  8858. RFIFOB(fd,info->pos[1]),
  8859. RFIFOL(fd,info->pos[0]),
  8860. gettick()
  8861. );
  8862. }
  8863. /// Response to the death/system menu (CZ_RESTART).
  8864. /// 00b2 <type>.B
  8865. /// type:
  8866. /// 0 = restart (respawn)
  8867. /// 1 = char-select (disconnect)
  8868. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8869. {
  8870. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8871. case 0x00:
  8872. pc_respawn(sd,CLR_RESPAWN);
  8873. break;
  8874. case 0x01:
  8875. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8876. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8877. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8878. { //Send to char-server for character selection.
  8879. pc_damage_log_clear(sd,0);
  8880. chrif_charselectreq(sd, session[fd]->client_addr);
  8881. } else {
  8882. clif_disconnect_ack(sd, 1);
  8883. }
  8884. break;
  8885. }
  8886. }
  8887. /// Validates and processes whispered messages (CZ_WHISPER).
  8888. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8889. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8890. {
  8891. struct map_session_data* dstsd;
  8892. int i;
  8893. char *target, *message;
  8894. int namelen, messagelen;
  8895. // validate packet and retrieve name and message
  8896. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8897. return;
  8898. if ( is_atcommand(fd, sd, message, 1) )
  8899. return;
  8900. if (sd->sc.cant.chat)
  8901. return; //no "chatting" while muted.
  8902. if (battle_config.min_chat_delay) { //[Skotlex]
  8903. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8904. return;
  8905. }
  8906. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8907. }
  8908. // Reset idle time when using whisper/main chat.
  8909. sd->idletime = last_tick;
  8910. // Chat logging type 'W' / Whisper
  8911. log_chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  8912. //-------------------------------------------------------//
  8913. // Lordalfa - Paperboy - To whisper NPC commands //
  8914. //-------------------------------------------------------//
  8915. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8916. {
  8917. char* str = target+4; //Skip the NPC: string part.
  8918. struct npc_data* npc;
  8919. if ((npc = npc_name2id(str))) {
  8920. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8921. char *split;
  8922. char output[256];
  8923. str = message;
  8924. // skip codepage indicator, if detected
  8925. if( str[0] == '|' && strlen(str) >= 4 )
  8926. str += 3;
  8927. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8928. split = strchr(str,'#');
  8929. if( split == NULL ) { // use the remaining string
  8930. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8931. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8932. split_data[i][0] = '\0';
  8933. break;
  8934. }
  8935. *split = '\0';
  8936. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8937. str = split+1;
  8938. }
  8939. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8940. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  8941. set_var(sd,output,(char *) split_data[i]);
  8942. }
  8943. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  8944. npc_event(sd,output,0); // Calls the NPC label
  8945. return;
  8946. }
  8947. } else if( target[0] == '#' ) {
  8948. struct Channel *channel = NULL;
  8949. char* chname = target;
  8950. channel = channel_name2channel(chname,sd,3);
  8951. if(channel){
  8952. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  8953. channel_send(channel,sd,message);
  8954. }
  8955. else if( channel->pass[0] == '\0') { //no pass needed
  8956. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  8957. }
  8958. else {
  8959. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  8960. }
  8961. return;
  8962. }
  8963. }
  8964. // searching destination character
  8965. dstsd = map_nick2sd(target);
  8966. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8967. // player is not on this map-server
  8968. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8969. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8970. // and if we ask for 'Test', we must not contact 'test' player
  8971. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8972. intif_wis_message(sd, target, message, messagelen);
  8973. return;
  8974. }
  8975. // if player ignores everyone
  8976. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  8977. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8978. clif_wis_end(fd, 1); // 1: target character is not logged in
  8979. else
  8980. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8981. return;
  8982. }
  8983. // if player is autotrading
  8984. if (dstsd->state.autotrade == 1) {
  8985. char output[256];
  8986. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8987. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8988. return;
  8989. }
  8990. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  8991. // if player ignores the source character
  8992. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8993. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8994. clif_wis_end(fd, 2); // 2: ignored by target
  8995. return;
  8996. }
  8997. }
  8998. // notify sender of success
  8999. clif_wis_end(fd, 0); // 0: success to send wisper
  9000. // Normal message
  9001. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9002. }
  9003. /// /b /nb (CZ_BROADCAST).
  9004. /// Request to broadcast a message on whole server.
  9005. /// 0099 <packet len>.W <text>.?B 00
  9006. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9007. char command[CHAT_SIZE_MAX+11];
  9008. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9009. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9010. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9011. // as the length varies depending on the command used, just block unreasonably long strings
  9012. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9013. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9014. is_atcommand(fd, sd, command, 1);
  9015. }
  9016. /// Request to pick up an item.
  9017. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9018. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9019. /// There are various variants of this packet, some of them have padding between fields.
  9020. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9021. {
  9022. struct flooritem_data *fitem;
  9023. int map_object_id;
  9024. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9025. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9026. do {
  9027. if (pc_isdead(sd)) {
  9028. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9029. break;
  9030. }
  9031. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9032. break;
  9033. if (pc_cant_act(sd))
  9034. break;
  9035. if (!pc_takeitem(sd, fitem))
  9036. break;
  9037. return;
  9038. } while (0);
  9039. // Client REQUIRES a fail packet or you can no longer pick items.
  9040. clif_additem(sd,0,0,6);
  9041. }
  9042. /// Request to drop an item.
  9043. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9044. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9045. /// There are various variants of this packet, some of them have padding between fields.
  9046. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9047. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9048. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9049. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9050. for(;;) {
  9051. if (pc_isdead(sd))
  9052. break;
  9053. if (pc_cant_act2(sd) || sd->npc_id)
  9054. break;
  9055. if (sd->sc.count && (
  9056. sd->sc.data[SC_AUTOCOUNTER] ||
  9057. sd->sc.data[SC_BLADESTOP] ||
  9058. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9059. ))
  9060. break;
  9061. if (!pc_dropitem(sd, item_index, item_amount))
  9062. break;
  9063. return;
  9064. }
  9065. //Because the client does not like being ignored.
  9066. clif_dropitem(sd, item_index,0);
  9067. }
  9068. /// Request to use an item.
  9069. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9070. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9071. /// There are various variants of this packet, some of them have padding between fields.
  9072. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9073. {
  9074. int n;
  9075. if (pc_isdead(sd)) {
  9076. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9077. return;
  9078. }
  9079. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9080. return;
  9081. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9082. sd->idletime = last_tick;
  9083. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9084. if(n <0 || n >= MAX_INVENTORY)
  9085. return;
  9086. if (!pc_useitem(sd,n))
  9087. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9088. }
  9089. /// Request to equip an item
  9090. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9091. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9092. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9093. {
  9094. int index, req_pos;
  9095. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9096. if(pc_isdead(sd)) {
  9097. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9098. return;
  9099. }
  9100. index = RFIFOW(fd,info->pos[0])-2;
  9101. if (index < 0 || index >= MAX_INVENTORY)
  9102. return; //Out of bounds check.
  9103. if(sd->npc_id && !sd->npc_item_flag) {
  9104. return;
  9105. } else if (sd->state.storage_flag || sd->sc.opt1)
  9106. ; //You can equip/unequip stuff while storage is open/under status changes
  9107. else if (pc_cant_act2(sd))
  9108. return;
  9109. if(!sd->status.inventory[index].identify) {
  9110. clif_equipitemack(sd,index,0,0); // fail
  9111. return;
  9112. }
  9113. if(!sd->inventory_data[index])
  9114. return;
  9115. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9116. pet_equipitem(sd,index);
  9117. return;
  9118. }
  9119. //Client doesn't send the position for ammo.
  9120. if(sd->inventory_data[index]->type == IT_AMMO)
  9121. pc_equipitem(sd,index,EQP_AMMO);
  9122. else {
  9123. #if PACKETVER >= 20120925
  9124. req_pos = RFIFOL(fd,info->pos[1]);
  9125. #else
  9126. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9127. #endif
  9128. pc_equipitem(sd,index,req_pos);
  9129. }
  9130. }
  9131. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9132. /// 00ab <index>.W
  9133. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9134. {
  9135. int index;
  9136. if(pc_isdead(sd)) {
  9137. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9138. return;
  9139. }
  9140. if (sd->npc_id && !sd->npc_item_flag) {
  9141. return;
  9142. } else if (sd->state.storage_flag || sd->sc.opt1)
  9143. ; //You can equip/unequip stuff while storage is open/under status changes
  9144. else if (pc_cant_act2(sd))
  9145. return;
  9146. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9147. pc_unequipitem(sd,index,1);
  9148. }
  9149. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9150. /// 0090 <id>.L <type>.B
  9151. /// type:
  9152. /// 1 = click
  9153. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9154. {
  9155. struct block_list *bl;
  9156. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9157. if(pc_isdead(sd)) {
  9158. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9159. return;
  9160. }
  9161. if (pc_cant_act2(sd) || sd->npc_id)
  9162. return;
  9163. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9164. //type = RFIFOB(fd,info->pos[1]);
  9165. if (!bl) return;
  9166. switch (bl->type) {
  9167. case BL_MOB:
  9168. case BL_PC:
  9169. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9170. break;
  9171. case BL_NPC:
  9172. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9173. npc_click(sd,(TBL_NPC*)bl);
  9174. break;
  9175. }
  9176. }
  9177. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9178. /// 00c5 <id>.L <type>.B
  9179. /// type:
  9180. /// 0 = buy
  9181. /// 1 = sell
  9182. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9183. {
  9184. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9185. if (sd->state.trading)
  9186. return;
  9187. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9188. }
  9189. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9190. /// 00ca <result>.B
  9191. /// result:
  9192. /// 0 = "The deal has successfully completed."
  9193. /// 1 = "You do not have enough zeny."
  9194. /// 2 = "You are over your Weight Limit."
  9195. /// 3 = "Out of the maximum capacity, you have too many items."
  9196. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9197. {
  9198. int fd = sd->fd;
  9199. WFIFOHEAD(fd,packet_len(0xca));
  9200. WFIFOW(fd,0) = 0xca;
  9201. WFIFOB(fd,2) = result;
  9202. WFIFOSET(fd,packet_len(0xca));
  9203. }
  9204. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9205. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9206. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9207. {
  9208. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9209. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9210. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9211. int result;
  9212. if( sd->state.trading || !sd->npc_shopid )
  9213. result = 1;
  9214. else
  9215. result = npc_buylist(sd,n,item_list);
  9216. sd->npc_shopid = 0; //Clear shop data.
  9217. clif_npc_buy_result(sd, result);
  9218. }
  9219. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9220. /// 00cb <result>.B
  9221. /// result:
  9222. /// 0 = "The deal has successfully completed."
  9223. /// 1 = "The deal has failed."
  9224. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9225. {
  9226. int fd = sd->fd;
  9227. WFIFOHEAD(fd,packet_len(0xcb));
  9228. WFIFOW(fd,0) = 0xcb;
  9229. WFIFOB(fd,2) = result;
  9230. WFIFOSET(fd,packet_len(0xcb));
  9231. }
  9232. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9233. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9234. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9235. {
  9236. int fail=0,n;
  9237. unsigned short *item_list;
  9238. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9239. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9240. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9241. if (sd->state.trading || !sd->npc_shopid)
  9242. fail = 1;
  9243. else
  9244. fail = npc_selllist(sd,n,item_list);
  9245. sd->npc_shopid = 0; //Clear shop data.
  9246. clif_npc_sell_result(sd, fail);
  9247. }
  9248. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9249. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9250. /// type:
  9251. /// 0 = private
  9252. /// 1 = public
  9253. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9254. {
  9255. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9256. int len = RFIFOW(fd,info->pos[0])-15;
  9257. int limit = RFIFOW(fd,info->pos[1]);
  9258. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9259. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9260. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9261. char s_password[CHATROOM_PASS_SIZE];
  9262. char s_title[CHATROOM_TITLE_SIZE];
  9263. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9264. return;
  9265. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9266. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9267. return;
  9268. }
  9269. if( npc_isnear(&sd->bl) ) {
  9270. // uncomment to send msg_txt.
  9271. //char output[150];
  9272. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9273. //clif_displaymessage(sd->fd, output);
  9274. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9275. return;
  9276. }
  9277. if( len <= 0 )
  9278. return; // invalid input
  9279. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9280. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9281. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9282. }
  9283. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9284. /// 00d9 <chat ID>.L <passwd>.8B
  9285. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9286. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9287. int chatid = RFIFOL(fd,info->pos[0]);
  9288. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9289. chat_joinchat(sd,chatid,password);
  9290. }
  9291. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9292. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9293. /// type:
  9294. /// 0 = private
  9295. /// 1 = public
  9296. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9297. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9298. int len = RFIFOW(fd,info->pos[0])-15;
  9299. int limit = RFIFOW(fd,info->pos[1]);
  9300. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9301. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9302. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9303. char s_password[CHATROOM_PASS_SIZE];
  9304. char s_title[CHATROOM_TITLE_SIZE];
  9305. if( len <= 0 )
  9306. return; // invalid input
  9307. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9308. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9309. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9310. }
  9311. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9312. /// 00e0 <role>.L <nick>.24B
  9313. /// role:
  9314. /// 0 = owner
  9315. /// 1 = normal
  9316. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9317. {
  9318. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9319. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9320. }
  9321. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9322. /// 00e2 <name>.24B
  9323. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9324. {
  9325. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9326. }
  9327. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9328. /// 00e3
  9329. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9330. {
  9331. chat_leavechat(sd,0);
  9332. }
  9333. //Handles notifying asker and rejecter of what has just ocurred.
  9334. //Type is used to determine the correct msg_txt to use:
  9335. //0:
  9336. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9337. {
  9338. const char* msg;
  9339. char output[256];
  9340. // Your request has been rejected by autoreject option.
  9341. msg = msg_txt(sd,392);
  9342. clif_disp_onlyself(sd, msg, strlen(msg));
  9343. //Notice that a request was rejected.
  9344. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9345. clif_disp_onlyself(tsd, output, strlen(output));
  9346. }
  9347. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9348. /// 00e4 <account id>.L
  9349. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9350. {
  9351. struct map_session_data *t_sd;
  9352. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9353. if(!sd->chatID && pc_cant_act(sd))
  9354. return; //You can trade while in a chatroom.
  9355. // @noask [LuzZza]
  9356. if(t_sd && t_sd->state.noask) {
  9357. clif_noask_sub(sd, t_sd, 0);
  9358. return;
  9359. }
  9360. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9361. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9362. return;
  9363. }
  9364. trade_traderequest(sd,t_sd);
  9365. }
  9366. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9367. /// 00e6 <result>.B
  9368. /// result:
  9369. /// 3 = accepted
  9370. /// 4 = rejected
  9371. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9372. {
  9373. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9374. }
  9375. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9376. /// 00e8 <index>.W <amount>.L
  9377. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9378. {
  9379. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9380. short index = RFIFOW(fd,info->pos[0]);
  9381. int amount = RFIFOL(fd,info->pos[1]);
  9382. if( index == 0 )
  9383. trade_tradeaddzeny(sd, amount);
  9384. else
  9385. trade_tradeadditem(sd, index, (short)amount);
  9386. }
  9387. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9388. /// 00eb
  9389. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9390. {
  9391. trade_tradeok(sd);
  9392. }
  9393. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9394. /// 00ed
  9395. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9396. {
  9397. trade_tradecancel(sd);
  9398. }
  9399. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9400. /// 00ef
  9401. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9402. {
  9403. trade_tradecommit(sd);
  9404. }
  9405. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9406. /// 0118
  9407. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9408. {
  9409. pc_stop_attack(sd);
  9410. }
  9411. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9412. /// 0126 <index>.W <amount>.L
  9413. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9414. {
  9415. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9416. short flag = 0;
  9417. if (pc_istrading(sd))
  9418. return;
  9419. if (!pc_iscarton(sd))
  9420. return;
  9421. if ((flag = pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1])))) {
  9422. clif_dropitem(sd,RFIFOW(fd,info->pos[0])-2,0);
  9423. clif_cart_additem_ack(sd,(flag==1)?ADDITEM_TO_CART_FAIL_WEIGHT:ADDITEM_TO_CART_FAIL_COUNT);
  9424. }
  9425. }
  9426. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9427. /// 0127 <index>.W <amount>.L
  9428. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9429. {
  9430. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9431. if (!pc_iscarton(sd))
  9432. return;
  9433. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,
  9434. RFIFOL(fd,info->pos[1]));
  9435. }
  9436. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9437. /// 012a
  9438. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9439. {
  9440. /**
  9441. * Attempts to remove these options when this function is called (will remove all available)
  9442. **/
  9443. #ifdef NEW_CARTS
  9444. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9445. if( sd->sc.data[SC_PUSH_CART] )
  9446. pc_setcart(sd,0);
  9447. #else
  9448. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9449. #endif
  9450. }
  9451. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9452. /// 01af <num>.W
  9453. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9454. {// TODO: State tracking?
  9455. int type;
  9456. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9457. return;
  9458. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9459. #ifdef NEW_CARTS
  9460. if( (type == 9 && sd->status.base_level > 131) ||
  9461. (type == 8 && sd->status.base_level > 121) ||
  9462. (type == 7 && sd->status.base_level > 111) ||
  9463. (type == 6 && sd->status.base_level > 101) ||
  9464. (type == 5 && sd->status.base_level > 90) ||
  9465. (type == 4 && sd->status.base_level > 80) ||
  9466. (type == 3 && sd->status.base_level > 65) ||
  9467. (type == 2 && sd->status.base_level > 40) ||
  9468. (type == 1))
  9469. #else
  9470. if( (type == 5 && sd->status.base_level > 90) ||
  9471. (type == 4 && sd->status.base_level > 80) ||
  9472. (type == 3 && sd->status.base_level > 65) ||
  9473. (type == 2 && sd->status.base_level > 40) ||
  9474. (type == 1))
  9475. #endif
  9476. pc_setcart(sd,type);
  9477. }
  9478. /// Request to increase status (CZ_STATUS_CHANGE).
  9479. /// 00bb <status id>.W <amount>.B
  9480. /// status id:
  9481. /// SP_STR ~ SP_LUK
  9482. /// amount:
  9483. /// client sends always 1 for this, even when using /str+ and
  9484. /// the like
  9485. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9486. {
  9487. //char amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9488. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9489. }
  9490. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9491. /// 0112 <skill id>.W
  9492. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9493. {
  9494. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9495. }
  9496. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  9497. {
  9498. int lv;
  9499. if( !hd )
  9500. return;
  9501. if( skill_isNotOk_hom(skill_id, hd) )
  9502. return;
  9503. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9504. target_id = hd->bl.id;
  9505. if( hd->ud.skilltimer != INVALID_TIMER )
  9506. {
  9507. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9508. }
  9509. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9510. return;
  9511. lv = merc_hom_checkskill(hd, skill_id);
  9512. if( skill_lv > lv )
  9513. skill_lv = lv;
  9514. if( skill_lv )
  9515. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9516. }
  9517. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  9518. {
  9519. int lv;
  9520. if( !hd )
  9521. return;
  9522. if( skill_isNotOk_hom(skill_id, hd) )
  9523. return;
  9524. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9525. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9526. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9527. return;
  9528. if( hd->sc.data[SC_BASILICA] )
  9529. return;
  9530. lv = merc_hom_checkskill(hd, skill_id);
  9531. if( skill_lv > lv )
  9532. skill_lv = lv;
  9533. if( skill_lv )
  9534. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9535. }
  9536. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  9537. {
  9538. int lv;
  9539. if( !md )
  9540. return;
  9541. if( skill_isNotOk_mercenary(skill_id, md) )
  9542. return;
  9543. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9544. target_id = md->bl.id;
  9545. if( md->ud.skilltimer != INVALID_TIMER )
  9546. {
  9547. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9548. }
  9549. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9550. return;
  9551. lv = mercenary_checkskill(md, skill_id);
  9552. if( skill_lv > lv )
  9553. skill_lv = lv;
  9554. if( skill_lv )
  9555. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9556. }
  9557. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  9558. {
  9559. int lv;
  9560. if( !md )
  9561. return;
  9562. if( skill_isNotOk_mercenary(skill_id, md) )
  9563. return;
  9564. if( md->ud.skilltimer != INVALID_TIMER )
  9565. return;
  9566. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9567. {
  9568. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9569. return;
  9570. }
  9571. if( md->sc.data[SC_BASILICA] )
  9572. return;
  9573. lv = mercenary_checkskill(md, skill_id);
  9574. if( skill_lv > lv )
  9575. skill_lv = lv;
  9576. if( skill_lv )
  9577. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9578. }
  9579. /// Request to use a targeted skill.
  9580. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9581. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9582. /// There are various variants of this packet, some of them have padding between fields.
  9583. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9584. {
  9585. uint16 skill_id, skill_lv;
  9586. int tmp, target_id;
  9587. unsigned int tick = gettick();
  9588. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9589. skill_lv = RFIFOW(fd,info->pos[0]);
  9590. skill_id = RFIFOW(fd,info->pos[1]);
  9591. target_id = RFIFOL(fd,info->pos[2]);
  9592. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9593. tmp = skill_get_inf(skill_id);
  9594. if (tmp&INF_GROUND_SKILL || !tmp)
  9595. return; //Using a ground/passive skill on a target? WRONG.
  9596. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9597. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9598. return;
  9599. }
  9600. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9601. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9602. return;
  9603. }
  9604. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9605. sd->idletime = last_tick;
  9606. if( sd->npc_id ){
  9607. #ifdef RENEWAL
  9608. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9609. return;
  9610. #else
  9611. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9612. return;
  9613. #endif
  9614. }
  9615. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9616. return;
  9617. if( pc_issit(sd) )
  9618. return;
  9619. if( skill_isNotOk(skill_id, sd) )
  9620. return;
  9621. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9622. target_id = sd->bl.id; // never trust the client
  9623. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9624. target_id = sd->bl.id;
  9625. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9626. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9627. return;
  9628. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9629. if( sd->skillitem != skill_id ) {
  9630. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9631. return;
  9632. }
  9633. }
  9634. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK|OPTION_OKTOBERFEST) )
  9635. return;
  9636. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9637. return; // On basilica only caster can use Basilica again to stop it.
  9638. if( sd->menuskill_id ) {
  9639. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9640. clif_menuskill_clear(sd); //Cancel pet capture.
  9641. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9642. return; //Can't use skills while a menu is open.
  9643. }
  9644. if( sd->skillitem == skill_id ) {
  9645. if( skill_lv != sd->skillitemlv )
  9646. skill_lv = sd->skillitemlv;
  9647. if( !(tmp&INF_SELF_SKILL) )
  9648. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9649. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9650. return;
  9651. }
  9652. sd->skillitem = sd->skillitemlv = 0;
  9653. if( skill_id >= GD_SKILLBASE ) {
  9654. if( sd->state.gmaster_flag )
  9655. skill_lv = guild_checkskill(sd->state.gmaster_flag, skill_id);
  9656. else
  9657. skill_lv = 0;
  9658. } else {
  9659. tmp = pc_checkskill(sd, skill_id);
  9660. if( skill_lv > tmp )
  9661. skill_lv = tmp;
  9662. }
  9663. pc_delinvincibletimer(sd);
  9664. if( skill_lv )
  9665. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9666. }
  9667. /*==========================================
  9668. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9669. *------------------------------------------*/
  9670. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9671. {
  9672. unsigned int tick = gettick();
  9673. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9674. return; //Using a target skill on the ground? WRONG.
  9675. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9676. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9677. return;
  9678. }
  9679. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9680. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9681. return;
  9682. }
  9683. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9684. sd->idletime = last_tick;
  9685. if( skill_isNotOk(skill_id, sd) )
  9686. return;
  9687. if( skillmoreinfo != -1 ) {
  9688. if( pc_issit(sd) ) {
  9689. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9690. return;
  9691. }
  9692. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9693. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9694. }
  9695. if( sd->ud.skilltimer != INVALID_TIMER )
  9696. return;
  9697. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9698. if( sd->skillitem != skill_id ) {
  9699. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9700. return;
  9701. }
  9702. }
  9703. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER|OPTION_HANBOK|OPTION_OKTOBERFEST) )
  9704. return;
  9705. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9706. return; // On basilica only caster can use Basilica again to stop it.
  9707. if( sd->menuskill_id ) {
  9708. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9709. clif_menuskill_clear(sd); //Cancel pet capture.
  9710. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9711. return; //Can't use skills while a menu is open.
  9712. }
  9713. pc_delinvincibletimer(sd);
  9714. if( sd->skillitem == skill_id ) {
  9715. if( skill_lv != sd->skillitemlv )
  9716. skill_lv = sd->skillitemlv;
  9717. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9718. } else {
  9719. int lv;
  9720. sd->skillitem = sd->skillitemlv = 0;
  9721. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9722. if( skill_lv > lv )
  9723. skill_lv = lv;
  9724. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9725. }
  9726. }
  9727. }
  9728. /// Request to use a ground skill.
  9729. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9730. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9731. /// There are various variants of this packet, some of them have padding between fields.
  9732. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9733. {
  9734. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9735. if (pc_cant_act(sd))
  9736. return;
  9737. if (pc_issit(sd))
  9738. return;
  9739. clif_parse_UseSkillToPosSub(fd, sd,
  9740. RFIFOW(fd,info->pos[0]), //skill lv
  9741. RFIFOW(fd,info->pos[1]), //skill num
  9742. RFIFOW(fd,info->pos[2]), //pos x
  9743. RFIFOW(fd,info->pos[3]), //pos y
  9744. -1 //Skill more info.
  9745. );
  9746. }
  9747. /// Request to use a ground skill with text.
  9748. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9749. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9750. /// There are various variants of this packet, some of them have padding between fields.
  9751. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9752. {
  9753. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9754. if (pc_cant_act(sd))
  9755. return;
  9756. if (pc_issit(sd))
  9757. return;
  9758. clif_parse_UseSkillToPosSub(fd, sd,
  9759. RFIFOW(fd,info->pos[0]), //Skill lv
  9760. RFIFOW(fd,info->pos[1]), //Skill num
  9761. RFIFOW(fd,info->pos[2]), //pos x
  9762. RFIFOW(fd,info->pos[3]), //pos y
  9763. info->pos[4] //skill more info
  9764. );
  9765. }
  9766. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9767. /// 011b <skill id>.W <map name>.16B
  9768. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9769. {
  9770. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9771. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9772. char map_name[MAP_NAME_LENGTH];
  9773. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9774. if(skill_id != sd->menuskill_id)
  9775. return;
  9776. if( pc_cant_act(sd) ) {
  9777. clif_menuskill_clear(sd);
  9778. return;
  9779. }
  9780. pc_delinvincibletimer(sd);
  9781. skill_castend_map(sd,skill_id,map_name);
  9782. }
  9783. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9784. /// 011d
  9785. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9786. {
  9787. if (!pc_isdead(sd))
  9788. pc_memo(sd,-1);
  9789. }
  9790. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9791. /// 018e <name id>.W { <material id>.W }*3
  9792. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9793. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9794. int nameid = RFIFOW(fd,info->pos[0]);
  9795. int slot1 = RFIFOW(fd,info->pos[1]);
  9796. int slot2 = RFIFOW(fd,info->pos[2]);
  9797. int slot3 = RFIFOW(fd,info->pos[3]);
  9798. switch( sd->menuskill_id ) {
  9799. case -1:
  9800. case AM_PHARMACY:
  9801. case RK_RUNEMASTERY:
  9802. case GC_RESEARCHNEWPOISON:
  9803. break;
  9804. default:
  9805. return;
  9806. }
  9807. if (pc_istrading(sd)) {
  9808. //Make it fail to avoid shop exploits where you sell something different than you see.
  9809. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9810. clif_menuskill_clear(sd);
  9811. return;
  9812. }
  9813. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9814. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9815. clif_menuskill_clear(sd);
  9816. }
  9817. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9818. /// 025b <mk type>.W <name id>.W
  9819. /// mk type:
  9820. /// 1 = cooking
  9821. /// 2 = arrow
  9822. /// 3 = elemental
  9823. /// 4 = GN_MIX_COOKING
  9824. /// 5 = GN_MAKEBOMB
  9825. /// 6 = GN_S_PHARMACY
  9826. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9827. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9828. int type = RFIFOW(fd,info->pos[0]);
  9829. int nameid = RFIFOW(fd,info->pos[1]);
  9830. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9831. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9832. return;
  9833. if (pc_istrading(sd)) {
  9834. //Make it fail to avoid shop exploits where you sell something different than you see.
  9835. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9836. clif_menuskill_clear(sd);
  9837. return;
  9838. }
  9839. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9840. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9841. clif_menuskill_clear(sd);
  9842. }
  9843. /// Answer to repair weapon item selection dialog
  9844. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9845. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9846. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9847. {
  9848. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9849. return;
  9850. if (pc_istrading(sd)) {
  9851. //Make it fail to avoid shop exploits where you sell something different than you see.
  9852. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9853. clif_menuskill_clear(sd);
  9854. return;
  9855. }
  9856. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9857. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9858. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9859. //for(i = 0; i<MAX_SLOTS; i++)
  9860. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9861. clif_menuskill_clear(sd);
  9862. }
  9863. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9864. /// 0222 <index>.L
  9865. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9866. {
  9867. int idx;
  9868. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9869. return;
  9870. if (pc_istrading(sd)) {
  9871. //Make it fail to avoid shop exploits where you sell something different than you see.
  9872. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9873. clif_menuskill_clear(sd);
  9874. return;
  9875. }
  9876. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9877. skill_weaponrefine(sd, idx-2);
  9878. clif_menuskill_clear(sd);
  9879. }
  9880. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9881. /// 00b8 <npc id>.L <choice>.B
  9882. /// choice:
  9883. /// 1~254 = menu item
  9884. /// 255 = cancel
  9885. /// NOTE: If there were more than 254 items in the list, choice
  9886. /// overflows to choice%256.
  9887. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  9888. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9889. int npc_id = RFIFOL(fd,info->pos[0]);
  9890. uint8 select = RFIFOB(fd,info->pos[1]);
  9891. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9892. #ifdef SECURE_NPCTIMEOUT
  9893. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9894. #endif
  9895. TBL_NPC* nd = map_id2nd(npc_id);
  9896. ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name);
  9897. clif_GM_kick(NULL,sd);
  9898. #ifdef SECURE_NPCTIMEOUT
  9899. }
  9900. #endif
  9901. return;
  9902. }
  9903. sd->npc_menu = select;
  9904. npc_scriptcont(sd,npc_id, false);
  9905. }
  9906. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9907. /// 00b9 <npc id>.L
  9908. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9909. {
  9910. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  9911. }
  9912. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9913. /// 0143 <npc id>.L <value>.L
  9914. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  9915. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9916. int npcid = RFIFOL(fd,info->pos[0]);
  9917. int amount = (int)RFIFOL(fd,info->pos[1]);
  9918. sd->npc_amount = amount;
  9919. npc_scriptcont(sd, npcid, false);
  9920. }
  9921. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9922. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9923. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  9924. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9925. int message_len = RFIFOW(fd,info->pos[0])-8;
  9926. int npcid = RFIFOL(fd,info->pos[1]);
  9927. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  9928. if( message_len <= 0 )
  9929. return; // invalid input
  9930. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9931. npc_scriptcont(sd, npcid, false);
  9932. }
  9933. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9934. /// 0146 <npc id>.L
  9935. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9936. {
  9937. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9938. return;
  9939. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  9940. }
  9941. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9942. /// 0178 <index>.W
  9943. /// index:
  9944. /// -1 = cancel
  9945. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9946. {
  9947. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9948. if (sd->menuskill_id != MC_IDENTIFY)
  9949. return;
  9950. if( idx == -1 ) {// cancel pressed
  9951. clif_menuskill_clear(sd);
  9952. return;
  9953. }
  9954. skill_identify(sd,idx-2);
  9955. clif_menuskill_clear(sd);
  9956. }
  9957. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9958. /// 01ae <name id>.W
  9959. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  9960. int nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9961. if (pc_istrading(sd)) {
  9962. //Make it fail to avoid shop exploits where you sell something different than you see.
  9963. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9964. clif_menuskill_clear(sd);
  9965. return;
  9966. }
  9967. switch( sd->menuskill_id ) {
  9968. case AC_MAKINGARROW:
  9969. skill_arrow_create(sd,nameid);
  9970. break;
  9971. case SA_CREATECON:
  9972. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  9973. break;
  9974. case WL_READING_SB:
  9975. skill_spellbook(sd,nameid);
  9976. break;
  9977. case GC_POISONINGWEAPON:
  9978. skill_poisoningweapon(sd,nameid);
  9979. break;
  9980. case NC_MAGICDECOY:
  9981. skill_magicdecoy(sd,nameid);
  9982. break;
  9983. }
  9984. clif_menuskill_clear(sd);
  9985. }
  9986. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9987. /// 01ce <skill id>.L
  9988. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9989. {
  9990. if (sd->menuskill_id != SA_AUTOSPELL)
  9991. return;
  9992. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9993. clif_menuskill_clear(sd);
  9994. }
  9995. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9996. /// 017a <card index>.W
  9997. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9998. {
  9999. if (sd->state.trading != 0)
  10000. return;
  10001. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10002. }
  10003. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10004. /// 017c <card index>.W <equip index>.W
  10005. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10006. {
  10007. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10008. if (sd->state.trading != 0)
  10009. return;
  10010. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10011. }
  10012. /// Request of character's name by char ID.
  10013. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10014. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10015. /// There are various variants of this packet, some of them have padding between fields.
  10016. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10017. {
  10018. int charid;
  10019. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10020. map_reqnickdb(sd, charid);
  10021. }
  10022. /// /resetskill /resetstate (CZ_RESET).
  10023. /// Request to reset stats or skills.
  10024. /// 0197 <type>.W
  10025. /// type:
  10026. /// 0 = state
  10027. /// 1 = skill
  10028. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10029. char cmd[15];
  10030. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10031. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10032. else
  10033. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10034. is_atcommand(fd, sd, cmd, 1);
  10035. }
  10036. /// /lb /nlb (CZ_LOCALBROADCAST).
  10037. /// Request to broadcast a message on current map.
  10038. /// 019c <packet len>.W <text>.?B
  10039. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10040. {
  10041. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10042. char command[CHAT_SIZE_MAX+16];
  10043. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10044. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10045. // as the length varies depending on the command used, just block unreasonably long strings
  10046. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10047. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10048. is_atcommand(fd, sd, command, 1);
  10049. }
  10050. /// Request to move an item from inventory to storage.
  10051. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10052. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10053. /// There are various variants of this packet, some of them have padding between fields.
  10054. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10055. {
  10056. int item_index, item_amount;
  10057. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10058. if (pc_istrading(sd))
  10059. return;
  10060. item_index = RFIFOW(fd,info->pos[0])-2;
  10061. item_amount = RFIFOL(fd,info->pos[1]);
  10062. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10063. return;
  10064. if (sd->state.storage_flag == 1)
  10065. storage_storageadd(sd, item_index, item_amount);
  10066. else
  10067. if (sd->state.storage_flag == 2)
  10068. storage_guild_storageadd(sd, item_index, item_amount);
  10069. }
  10070. /// Request to move an item from storage to inventory.
  10071. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10072. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10073. /// There are various variants of this packet, some of them have padding between fields.
  10074. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10075. {
  10076. int item_index, item_amount;
  10077. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10078. item_index = RFIFOW(fd,info->pos[0])-1;
  10079. item_amount = RFIFOL(fd,info->pos[1]);
  10080. if (sd->state.storage_flag == 1)
  10081. storage_storageget(sd, item_index, item_amount);
  10082. else if(sd->state.storage_flag == 2)
  10083. storage_guild_storageget(sd, item_index, item_amount);
  10084. }
  10085. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10086. /// 0129 <index>.W <amount>.L
  10087. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10088. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10089. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10090. int amount = RFIFOL(fd,info->pos[1]);
  10091. if( sd->state.vending )
  10092. return;
  10093. if (!pc_iscarton(sd))
  10094. return;
  10095. if (sd->state.storage_flag == 1)
  10096. storage_storageaddfromcart(sd, idx, amount);
  10097. else if (sd->state.storage_flag == 2)
  10098. storage_guild_storageaddfromcart(sd, idx, amount);
  10099. }
  10100. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10101. /// 0128 <index>.W <amount>.L
  10102. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10103. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10104. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10105. int amount = RFIFOL(fd,info->pos[1]);
  10106. if( sd->state.vending )
  10107. return;
  10108. if (!pc_iscarton(sd))
  10109. return;
  10110. if (sd->state.storage_flag == 1)
  10111. storage_storagegettocart(sd, idx, amount);
  10112. else
  10113. if (sd->state.storage_flag == 2)
  10114. storage_guild_storagegettocart(sd, idx, amount);
  10115. }
  10116. /// Request to close storage (CZ_CLOSE_STORE).
  10117. /// 00f7
  10118. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10119. {
  10120. if( sd->state.storage_flag == 1 )
  10121. storage_storageclose(sd);
  10122. else
  10123. if( sd->state.storage_flag == 2 )
  10124. storage_guild_storageclose(sd);
  10125. }
  10126. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10127. /// 023a <info>.W
  10128. /// info:
  10129. /// 0 = password has not been set yet
  10130. /// 1 = storage is password-protected
  10131. /// 8 = too many wrong passwords
  10132. /// ? = ignored
  10133. /// NOTE: This packet is only available on certain non-kRO clients.
  10134. void clif_storagepassword(struct map_session_data* sd, short info)
  10135. {
  10136. int fd = sd->fd;
  10137. WFIFOHEAD(fd,packet_len(0x23a));
  10138. WFIFOW(fd,0) = 0x23a;
  10139. WFIFOW(fd,2) = info;
  10140. WFIFOSET(fd,packet_len(0x23a));
  10141. }
  10142. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10143. /// 023b <type>.W <password>.16B <new password>.16B
  10144. /// type:
  10145. /// 2 = change password
  10146. /// 3 = check password
  10147. /// NOTE: This packet is only available on certain non-kRO clients.
  10148. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10149. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10150. // int type = RFIFOW(fd,info->pos[0]);
  10151. // char* password = RFIFOP(fd,info->pos[1]);
  10152. // char* new_password = RFIFOP(fd,info->pos[2]);
  10153. // storage_changepass(sd,password,new_password);
  10154. }
  10155. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10156. /// 023c <result>.W <error count>.W
  10157. /// result:
  10158. /// 4 = password change success
  10159. /// 5 = password change failure
  10160. /// 6 = password check success
  10161. /// 7 = password check failure
  10162. /// 8 = too many wrong passwords
  10163. /// ? = ignored
  10164. /// NOTE: This packet is only available on certain non-kRO clients.
  10165. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10166. {
  10167. int fd = sd->fd;
  10168. WFIFOHEAD(fd,packet_len(0x23c));
  10169. WFIFOW(fd,0) = 0x23c;
  10170. WFIFOW(fd,2) = result;
  10171. WFIFOW(fd,4) = error_count;
  10172. WFIFOSET(fd,packet_len(0x23c));
  10173. }
  10174. /// Party creation request
  10175. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10176. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10177. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10178. name[NAME_LENGTH-1] = '\0';
  10179. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10180. clif_displaymessage(fd, msg_txt(sd,227));
  10181. return;
  10182. }
  10183. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10184. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10185. return;
  10186. }
  10187. party_create(sd,name,0,0);
  10188. }
  10189. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10190. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10191. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10192. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10193. int item1 = RFIFOB(fd,info->pos[1]);
  10194. int item2 = RFIFOB(fd,info->pos[2]);
  10195. name[NAME_LENGTH-1] = '\0';
  10196. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10197. clif_displaymessage(fd, msg_txt(sd,227));
  10198. return;
  10199. }
  10200. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10201. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10202. return;
  10203. }
  10204. party_create(sd,name,item1,item2);
  10205. }
  10206. /// Party invitation request
  10207. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10208. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10209. {
  10210. struct map_session_data *t_sd;
  10211. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10212. clif_displaymessage(fd, msg_txt(sd,227));
  10213. return;
  10214. }
  10215. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10216. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10217. clif_noask_sub(sd, t_sd, 1);
  10218. return;
  10219. }
  10220. party_invite(sd, t_sd);
  10221. }
  10222. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10223. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10224. struct map_session_data *t_sd;
  10225. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10226. name[NAME_LENGTH-1] = '\0';
  10227. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10228. clif_displaymessage(fd, msg_txt(sd,227));
  10229. return;
  10230. }
  10231. t_sd = map_nick2sd(name);
  10232. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10233. clif_noask_sub(sd, t_sd, 1);
  10234. return;
  10235. }
  10236. party_invite(sd, t_sd);
  10237. }
  10238. /// Party invitation reply
  10239. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10240. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10241. /// flag:
  10242. /// 0 = reject
  10243. /// 1 = accept
  10244. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10245. {
  10246. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10247. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10248. RFIFOL(fd,info->pos[1]));
  10249. }
  10250. //(CZ_PARTY_JOIN_REQ_ACK)
  10251. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10252. {
  10253. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10254. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10255. RFIFOB(fd,info->pos[1]));
  10256. }
  10257. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10258. /// 0100
  10259. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10260. {
  10261. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10262. clif_displaymessage(fd, msg_txt(sd,227));
  10263. return;
  10264. }
  10265. party_leave(sd);
  10266. }
  10267. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10268. /// 0103 <account id>.L <char name>.24B
  10269. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10270. {
  10271. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10272. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10273. clif_displaymessage(fd, msg_txt(sd,227));
  10274. return;
  10275. }
  10276. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10277. (char*)RFIFOP(fd,info->pos[1]));
  10278. }
  10279. /// Request to change party options.
  10280. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10281. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10282. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10283. {
  10284. struct party_data *p;
  10285. int i,expflag;
  10286. int cmd = RFIFOW(fd,0);
  10287. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10288. if( !sd->status.party_id )
  10289. return;
  10290. p = party_search(sd->status.party_id);
  10291. if( p == NULL )
  10292. return;
  10293. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10294. if( i == MAX_PARTY )
  10295. return; //Shouldn't happen
  10296. if( !p->party.member[i].leader )
  10297. return;
  10298. expflag = RFIFOL(fd,info->pos[0]);
  10299. if(cmd == 0x0102){ //Client can't change the item-field
  10300. party_changeoption(sd, expflag, p->party.item);
  10301. }
  10302. else {
  10303. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10304. party_changeoption(sd, expflag, itemflag);
  10305. }
  10306. }
  10307. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10308. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10309. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10310. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10311. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10312. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10313. char *name, *message;
  10314. int namelen, messagelen;
  10315. // validate packet and retrieve name and message
  10316. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10317. return;
  10318. if( is_atcommand(fd, sd, message, 1) )
  10319. return;
  10320. if (sd->sc.cant.chat)
  10321. return; //no "chatting" while muted.
  10322. if( battle_config.min_chat_delay )
  10323. { //[Skotlex]
  10324. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10325. return;
  10326. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10327. }
  10328. // Reset idle time when using party chat.
  10329. sd->idletime = last_tick;
  10330. party_send_message(sd, text, textlen);
  10331. }
  10332. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10333. /// 07da <account id>.L
  10334. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10335. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10336. }
  10337. /// Party Booking in KRO [Spiria]
  10338. ///
  10339. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10340. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10341. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10342. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10343. short level = RFIFOW(fd,info->pos[0]);
  10344. short mapid = RFIFOW(fd,info->pos[1]);
  10345. int idxpbj = info->pos[2];
  10346. short job[PARTY_BOOKING_JOBS];
  10347. int i;
  10348. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10349. job[i] = RFIFOB(fd,idxpbj+i*2);
  10350. party_booking_register(sd, level, mapid, job);
  10351. }
  10352. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10353. /// 0803 <result>.W
  10354. /// result:
  10355. /// 0 = success
  10356. /// 1 = failure
  10357. /// 2 = already registered
  10358. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10359. {
  10360. int fd = sd->fd;
  10361. WFIFOHEAD(fd,packet_len(0x803));
  10362. WFIFOW(fd,0) = 0x803;
  10363. WFIFOW(fd,2) = flag;
  10364. WFIFOSET(fd,packet_len(0x803));
  10365. }
  10366. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10367. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10368. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10369. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10370. short level = RFIFOW(fd,info->pos[0]);
  10371. short mapid = RFIFOW(fd,info->pos[1]);
  10372. short job = RFIFOW(fd,info->pos[2]);
  10373. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10374. short resultcount = RFIFOW(fd,info->pos[4]);
  10375. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10376. }
  10377. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10378. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10379. /// more results:
  10380. /// 0 = no
  10381. /// 1 = yes
  10382. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10383. {
  10384. int i, j;
  10385. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10386. struct party_booking_ad_info *pb_ad;
  10387. WFIFOHEAD(fd,size*count + 5);
  10388. WFIFOW(fd,0) = 0x805;
  10389. WFIFOW(fd,2) = size*count + 5;
  10390. WFIFOB(fd,4) = more_result;
  10391. for(i=0; i<count; i++)
  10392. {
  10393. pb_ad = results[i];
  10394. WFIFOL(fd,i*size+5) = pb_ad->index;
  10395. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10396. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10397. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10398. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10399. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10400. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10401. }
  10402. WFIFOSET(fd,WFIFOW(fd,2));
  10403. }
  10404. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10405. /// 0806
  10406. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10407. {
  10408. if(party_booking_delete(sd))
  10409. clif_PartyBookingDeleteAck(sd, 0);
  10410. }
  10411. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10412. /// 0807 <result>.W
  10413. /// result:
  10414. /// 0 = success
  10415. /// 1 = success (auto-removed expired ad)
  10416. /// 2 = failure
  10417. /// 3 = nothing registered
  10418. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10419. {
  10420. int fd = sd->fd;
  10421. WFIFOHEAD(fd,packet_len(0x807));
  10422. WFIFOW(fd,0) = 0x807;
  10423. WFIFOW(fd,2) = flag;
  10424. WFIFOSET(fd,packet_len(0x807));
  10425. }
  10426. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10427. /// 0808 { <job>.W }*6
  10428. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10429. {
  10430. short job[PARTY_BOOKING_JOBS];
  10431. int i;
  10432. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10433. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10434. job[i] = RFIFOW(fd,idxpbu+i*2);
  10435. party_booking_update(sd, job);
  10436. }
  10437. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10438. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10439. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10440. {
  10441. int i;
  10442. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10443. if(pb_ad == NULL) return;
  10444. WBUFW(buf,0) = 0x809;
  10445. WBUFL(buf,2) = pb_ad->index;
  10446. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10447. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10448. WBUFW(buf,34) = pb_ad->p_detail.level;
  10449. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10450. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10451. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10452. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10453. }
  10454. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10455. /// 080a <index>.L { <job>.W }*6
  10456. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10457. {
  10458. int i;
  10459. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10460. if(pb_ad == NULL) return;
  10461. WBUFW(buf,0) = 0x80a;
  10462. WBUFL(buf,2) = pb_ad->index;
  10463. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10464. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10465. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10466. }
  10467. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10468. /// 080b <index>.L
  10469. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10470. {
  10471. uint8 buf[6];
  10472. WBUFW(buf,0) = 0x80b;
  10473. WBUFL(buf,2) = index;
  10474. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10475. }
  10476. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10477. /// 012e
  10478. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10479. {
  10480. vending_closevending(sd);
  10481. }
  10482. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10483. /// 0130 <account id>.L
  10484. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10485. {
  10486. if( sd->npc_id ) {// using an NPC
  10487. return;
  10488. }
  10489. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10490. }
  10491. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10492. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10493. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10494. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10495. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10496. int id = (int)RFIFOL(fd,info->pos[1]);
  10497. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10498. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10499. // whether it fails or not, the buy window is closed
  10500. sd->vended_id = 0;
  10501. }
  10502. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10503. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10504. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10505. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10506. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10507. int aid = (int)RFIFOL(fd,info->pos[1]);
  10508. int uid = (int)RFIFOL(fd,info->pos[2]);
  10509. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10510. vending_purchasereq(sd, aid, uid, data, len/4);
  10511. // whether it fails or not, the buy window is closed
  10512. sd->vended_id = 0;
  10513. }
  10514. /// Confirm or cancel the shop preparation window.
  10515. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10516. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10517. /// result:
  10518. /// 0 = canceled
  10519. /// 1 = open
  10520. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10521. int cmd = RFIFOW(fd,0);
  10522. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10523. short len = (short)RFIFOW(fd,info->pos[0]);
  10524. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10525. bool flag;
  10526. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10527. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10528. len -= 84;
  10529. }
  10530. else { //(CZ_REQ_OPENSTORE2)
  10531. len -= 85;
  10532. flag = (bool)RFIFOB(fd,info->pos[2]);
  10533. if( !flag )
  10534. sd->state.prevend = 0;
  10535. }
  10536. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10537. return;
  10538. if( map[sd->bl.m].flag.novending ) {
  10539. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10540. return;
  10541. }
  10542. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10543. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10544. return;
  10545. }
  10546. if( message[0] == '\0' ) // invalid input
  10547. return;
  10548. vending_openvending(sd, message, data, len/8);
  10549. }
  10550. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10551. /// 0165 <char id>.L <guild name>.24B
  10552. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10553. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10554. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10555. name[NAME_LENGTH-1] = '\0';
  10556. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10557. clif_displaymessage(fd, msg_txt(sd,228));
  10558. return;
  10559. }
  10560. guild_create(sd, name);
  10561. }
  10562. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10563. /// 014d
  10564. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10565. {
  10566. clif_guild_masterormember(sd);
  10567. }
  10568. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10569. /// 014f <type>.L
  10570. /// type:
  10571. /// 0 = basic info
  10572. /// 1 = member manager
  10573. /// 2 = positions
  10574. /// 3 = skills
  10575. /// 4 = expulsion list
  10576. /// 5 = unknown (GM_ALLGUILDLIST)
  10577. /// 6 = notice
  10578. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10579. {
  10580. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10581. if( !sd->status.guild_id && !sd->bg_id )
  10582. return;
  10583. switch( type )
  10584. {
  10585. case 0: // Basic Information Guild, hostile alliance information
  10586. clif_guild_basicinfo(sd);
  10587. clif_guild_allianceinfo(sd);
  10588. break;
  10589. case 1: // Members list, list job title
  10590. clif_guild_positionnamelist(sd);
  10591. clif_guild_memberlist(sd);
  10592. break;
  10593. case 2: // List job title, title information list
  10594. clif_guild_positionnamelist(sd);
  10595. clif_guild_positioninfolist(sd);
  10596. break;
  10597. case 3: // Skill list
  10598. clif_guild_skillinfo(sd);
  10599. break;
  10600. case 4: // Expulsion list
  10601. clif_guild_expulsionlist(sd);
  10602. break;
  10603. default:
  10604. ShowError("clif: guild request info: unknown type %d\n", type);
  10605. break;
  10606. }
  10607. }
  10608. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10609. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10610. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10611. {
  10612. int i;
  10613. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10614. int len = RFIFOW(fd,info->pos[0]);
  10615. int idxgpos = info->pos[1];
  10616. if(!sd->state.gmaster_flag)
  10617. return;
  10618. for(i = idxgpos; i < len; i += 40 ){
  10619. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10620. }
  10621. }
  10622. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10623. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10624. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10625. {
  10626. int i;
  10627. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10628. int len = RFIFOW(fd,info->pos[0]);
  10629. int idxgpos = info->pos[1];
  10630. if(!sd->state.gmaster_flag)
  10631. return;
  10632. for(i=idxgpos;i<len;i+=12){
  10633. guild_change_memberposition(sd->status.guild_id,
  10634. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10635. }
  10636. }
  10637. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10638. /// 0151 <guild id>.L
  10639. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10640. {
  10641. struct guild* g;
  10642. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10643. if( (g = guild_search(guild_id)) != NULL )
  10644. clif_guild_emblem(sd,g);
  10645. }
  10646. /// Validates data of a guild emblem (compressed bitmap)
  10647. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len){
  10648. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10649. unsigned long buf_len = sizeof(buf);
  10650. int i,j, transcount=1, offset=0, tmp[3];
  10651. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10652. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10653. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10654. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10655. ))
  10656. return -1;
  10657. if(battle_config.emblem_transparency_limit != 100){
  10658. for(i=offset; i<buf_len-1; i++){
  10659. j = i%3;
  10660. tmp[j] = RBUFL(buf,i);
  10661. if(j==2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10662. transcount++;
  10663. }
  10664. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10665. return -2;
  10666. }
  10667. return 0;
  10668. }
  10669. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10670. /// 0153 <packet len>.W <emblem data>.?B
  10671. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10672. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10673. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10674. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10675. int emb_val=0;
  10676. if( !emblem_len || !sd->state.gmaster_flag )
  10677. return;
  10678. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10679. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10680. return;
  10681. }
  10682. emb_val = clif_validate_emblem(emblem, emblem_len);
  10683. if(emb_val ==-1 ){
  10684. ShowWarning("clif_parse_GuildChangeEmblem: Rejected malformed guild emblem (size=%lu, accound_id=%d, char_id=%d, guild_id=%d).\n", emblem_len, sd->status.account_id, sd->status.char_id, sd->status.guild_id);
  10685. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10686. return;
  10687. } else if(emb_val == -2){
  10688. char output[128];
  10689. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10690. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10691. return;
  10692. }
  10693. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10694. }
  10695. /// Guild notice update request (CZ_GUILD_NOTICE).
  10696. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10697. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10698. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10699. int guild_id = RFIFOL(fd,info->pos[0]);
  10700. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10701. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10702. if(!sd->state.gmaster_flag)
  10703. return;
  10704. // compensate for some client defects when using multilanguage mode
  10705. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10706. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10707. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10708. guild_change_notice(sd, guild_id, msg1, msg2);
  10709. }
  10710. // Helper function for guild invite functions
  10711. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10712. {
  10713. if (t_sd == NULL) // not online or does not exist
  10714. return 1;
  10715. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10716. clif_displaymessage(fd, msg_txt(sd,228));
  10717. return 1;
  10718. }
  10719. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10720. clif_noask_sub(sd, t_sd, 2);
  10721. return 1;
  10722. }
  10723. guild_invite(sd, t_sd);
  10724. return 0;
  10725. }
  10726. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10727. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10728. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10729. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10730. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10731. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10732. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10733. if (clif_sub_guild_invite(fd, sd, t_sd))
  10734. return;
  10735. }
  10736. /// Guild invite request (/guildinvite)
  10737. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10738. void
  10739. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10740. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10741. if (clif_sub_guild_invite(fd, sd, t_sd))
  10742. return;
  10743. }
  10744. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10745. /// 016b <guild id>.L <answer>.L
  10746. /// answer:
  10747. /// 0 = refuse
  10748. /// 1 = accept
  10749. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10750. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10751. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10752. RFIFOL(fd,info->pos[1]));
  10753. }
  10754. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10755. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10756. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10757. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10758. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10759. clif_displaymessage(fd, msg_txt(sd,228));
  10760. return;
  10761. }
  10762. if( sd->bg_id ) {
  10763. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10764. return;
  10765. }
  10766. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10767. RFIFOL(fd,info->pos[1]),
  10768. RFIFOL(fd,info->pos[2]),
  10769. (char*)RFIFOP(fd,info->pos[3]));
  10770. }
  10771. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10772. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10773. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10774. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10775. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10776. { // Guild locked.
  10777. clif_displaymessage(fd, msg_txt(sd,228));
  10778. return;
  10779. }
  10780. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10781. RFIFOL(fd,info->pos[1]),
  10782. RFIFOL(fd,info->pos[2]),
  10783. (char*)RFIFOP(fd,info->pos[3]));
  10784. }
  10785. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10786. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10787. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10788. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10789. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10790. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10791. char *name, *message;
  10792. int namelen, messagelen;
  10793. // validate packet and retrieve name and message
  10794. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10795. return;
  10796. if( is_atcommand(fd, sd, message, 1) )
  10797. return;
  10798. if (sd->sc.cant.chat)
  10799. return; //no "chatting" while muted.
  10800. if( battle_config.min_chat_delay )
  10801. { //[Skotlex]
  10802. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10803. return;
  10804. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10805. }
  10806. // Reset idle time when using guild chat.
  10807. sd->idletime = last_tick;
  10808. if( sd->bg_id )
  10809. bg_send_message(sd, text, textlen);
  10810. else
  10811. guild_send_message(sd, text, textlen);
  10812. }
  10813. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10814. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10815. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10816. {
  10817. struct map_session_data *t_sd;
  10818. if(!sd->state.gmaster_flag)
  10819. return;
  10820. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10821. clif_displaymessage(fd, msg_txt(sd,228));
  10822. return;
  10823. }
  10824. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10825. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10826. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10827. // @noask [LuzZza]
  10828. if(t_sd && t_sd->state.noask) {
  10829. clif_noask_sub(sd, t_sd, 3);
  10830. return;
  10831. }
  10832. guild_reqalliance(sd,t_sd);
  10833. }
  10834. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10835. /// 0172 <inviter account id>.L <answer>.L
  10836. /// answer:
  10837. /// 0 = refuse
  10838. /// 1 = accept
  10839. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10840. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10841. guild_reply_reqalliance(sd,
  10842. RFIFOL(fd,info->pos[0]),
  10843. RFIFOL(fd,info->pos[1]));
  10844. }
  10845. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10846. /// 0183 <opponent guild id>.L <relation>.L
  10847. /// relation:
  10848. /// 0 = Ally
  10849. /// 1 = Enemy
  10850. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10851. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10852. if(!sd->state.gmaster_flag)
  10853. return;
  10854. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10855. clif_displaymessage(fd, msg_txt(sd,228));
  10856. return;
  10857. }
  10858. guild_delalliance(sd,
  10859. RFIFOL(fd,info->pos[0]),
  10860. RFIFOL(fd,info->pos[1]));
  10861. }
  10862. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10863. /// 0180 <account id>.L
  10864. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10865. {
  10866. struct map_session_data *t_sd;
  10867. if(!sd->state.gmaster_flag)
  10868. return;
  10869. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10870. clif_displaymessage(fd, msg_txt(sd,228));
  10871. return;
  10872. }
  10873. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10874. // @noask [LuzZza]
  10875. if(t_sd && t_sd->state.noask) {
  10876. clif_noask_sub(sd, t_sd, 4);
  10877. return;
  10878. }
  10879. guild_opposition(sd,t_sd);
  10880. }
  10881. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10882. /// 015d <key>.40B
  10883. /// key:
  10884. /// now guild name; might have been (intended) email, since the
  10885. /// field name and size is same as the one in CH_DELETE_CHAR.
  10886. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10887. {
  10888. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10889. clif_displaymessage(fd, msg_txt(sd,228));
  10890. return;
  10891. }
  10892. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10893. }
  10894. /// Pet
  10895. ///
  10896. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10897. /// 01a1 <type>.B
  10898. /// type:
  10899. /// 0 = pet information
  10900. /// 1 = feed
  10901. /// 2 = performance
  10902. /// 3 = return to egg
  10903. /// 4 = unequip accessory
  10904. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  10905. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10906. }
  10907. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10908. /// 019f <id>.L
  10909. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  10910. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10911. }
  10912. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10913. /// 01a7 <index>.W
  10914. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  10915. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1) {
  10916. //Forged packet, disconnect them [Kevin]
  10917. clif_authfail_fd(fd, 0);
  10918. return;
  10919. }
  10920. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10921. clif_menuskill_clear(sd);
  10922. }
  10923. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10924. /// 01a9 <data>.L
  10925. /// data:
  10926. /// is either emotion (@see enum emotion_type) or a compound value
  10927. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10928. /// entry (given in parentheses) in data\pettalktable.xml
  10929. /// act id:
  10930. /// 0 = feeding
  10931. /// 1 = hunting
  10932. /// 2 = danger
  10933. /// 3 = dead
  10934. /// 4 = normal (stand)
  10935. /// 5 = special performance (perfor_s)
  10936. /// 6 = level up (levelup)
  10937. /// 7 = performance 1 (perfor_1)
  10938. /// 8 = performance 2 (perfor_2)
  10939. /// 9 = performance 3 (perfor_3)
  10940. /// 10 = log-in greeting (connect)
  10941. /// hungry value:
  10942. /// 0 = very hungry (hungry)
  10943. /// 1 = hungry (bit_hungry)
  10944. /// 2 = satisfied (noting)
  10945. /// 3 = stuffed (full)
  10946. /// 4 = full (so_full)
  10947. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10948. {
  10949. if(sd->pd)
  10950. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10951. }
  10952. /// Request to change pet's name (CZ_RENAME_PET).
  10953. /// 01a5 <name>.24B
  10954. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10955. {
  10956. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10957. }
  10958. /// /kill (CZ_DISCONNECT_CHARACTER).
  10959. /// Request to disconnect a character.
  10960. /// 00cc <account id>.L
  10961. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10962. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10963. {
  10964. struct block_list *target;
  10965. int tid;
  10966. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10967. target = map_id2bl(tid);
  10968. if (!target) {
  10969. clif_GM_kickack(sd, 0);
  10970. return;
  10971. }
  10972. switch (target->type) {
  10973. case BL_PC:
  10974. {
  10975. char command[NAME_LENGTH+6];
  10976. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  10977. is_atcommand(fd, sd, command, 1);
  10978. }
  10979. break;
  10980. /**
  10981. * This one does not invoke any atcommand, so we need to check for permissions.
  10982. */
  10983. case BL_MOB:
  10984. {
  10985. char command[100];
  10986. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10987. clif_GM_kickack(sd, 0);
  10988. return;
  10989. }
  10990. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  10991. log_atcommand(sd, command);
  10992. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10993. }
  10994. break;
  10995. case BL_NPC:
  10996. {
  10997. struct npc_data* nd = (struct npc_data *)target;
  10998. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  10999. npc_unload_duplicates(nd);
  11000. npc_unload(nd,true);
  11001. npc_read_event_script();
  11002. }
  11003. }
  11004. break;
  11005. default:
  11006. clif_GM_kickack(sd, 0);
  11007. }
  11008. }
  11009. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11010. /// Request to disconnect all characters.
  11011. /// 00ce
  11012. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11013. char cmd[15];
  11014. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11015. is_atcommand(fd, sd, cmd, 1);
  11016. }
  11017. /// /remove (CZ_REMOVE_AID).
  11018. /// Request to warp to a character with given login ID.
  11019. /// 01ba <account name>.24B
  11020. /// /shift (CZ_SHIFT).
  11021. /// Request to warp to a character with given name.
  11022. /// 01bb <char name>.24B
  11023. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11024. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11025. char *player_name;
  11026. char command[NAME_LENGTH+8];
  11027. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11028. player_name[NAME_LENGTH-1] = '\0';
  11029. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11030. is_atcommand(fd, sd, command, 1);
  11031. }
  11032. /// /remove (CZ_REMOVE_AID_SSO).
  11033. /// Request to warp to a character with given account ID.
  11034. /// 0843 <account id>.L
  11035. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11036. {
  11037. int account_id;
  11038. struct map_session_data* pl_sd;
  11039. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11040. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11041. char command[NAME_LENGTH+8];
  11042. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11043. is_atcommand(fd, sd, command, 1);
  11044. }
  11045. }
  11046. /// /recall (CZ_RECALL).
  11047. /// Request to summon a player with given login ID to own position.
  11048. /// 01bc <account name>.24B
  11049. /// /summon (CZ_RECALL_GID).
  11050. /// Request to summon a player with given name to own position.
  11051. /// 01bd <char name>.24B
  11052. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11053. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11054. char *player_name;
  11055. char command [NAME_LENGTH+8];
  11056. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11057. player_name[NAME_LENGTH-1] = '\0';
  11058. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11059. is_atcommand(fd, sd, command, 1);
  11060. }
  11061. /// /recall (CZ_RECALL_SSO).
  11062. /// Request to summon a player with given account ID to own position.
  11063. /// 0842 <account id>.L
  11064. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11065. {
  11066. int account_id;
  11067. struct map_session_data* pl_sd;
  11068. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11069. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11070. char command[NAME_LENGTH+8];
  11071. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11072. is_atcommand(fd, sd, command, 1);
  11073. }
  11074. }
  11075. /// /item /monster (CZ_ITEM_CREATE).
  11076. /// Request to make items or spawn monsters.
  11077. /// 013f <item/mob name>.24B
  11078. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  11079. {
  11080. char *monster_item_name;
  11081. char command[NAME_LENGTH+10];
  11082. monster_item_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11083. monster_item_name[NAME_LENGTH-1] = '\0';
  11084. // FIXME: Should look for item first, then for monster.
  11085. // FIXME: /monster takes mob_db Sprite_Name as argument
  11086. if( mobdb_searchname(monster_item_name) ) {
  11087. safesnprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  11088. is_atcommand(fd, sd, command, 1);
  11089. return;
  11090. }
  11091. // FIXME: Stackables have a quantity of 20.
  11092. // FIXME: Equips are supposed to be unidentified.
  11093. if( itemdb_searchname(monster_item_name) ) {
  11094. safesnprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  11095. is_atcommand(fd, sd, command, 1);
  11096. return;
  11097. }
  11098. }
  11099. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11100. /// 019d <effect state>.L
  11101. /// effect state:
  11102. /// TODO: Any OPTION_* ?
  11103. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11104. char cmd[6];
  11105. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11106. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11107. is_atcommand(fd, sd, cmd, 1);
  11108. }
  11109. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11110. /// 0149 <account id>.L <type>.B <value>.W
  11111. /// type:
  11112. /// 0 = positive points
  11113. /// 1 = negative points
  11114. /// 2 = self mute (+10 minutes)
  11115. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11116. {
  11117. int id, type, value;
  11118. struct map_session_data *dstsd;
  11119. char command[NAME_LENGTH+15];
  11120. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11121. id = RFIFOL(fd,info->pos[0]);
  11122. type = RFIFOB(fd,info->pos[1]);
  11123. value = RFIFOW(fd,info->pos[2]);
  11124. if( type == 0 )
  11125. value = -value;
  11126. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11127. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11128. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11129. return;
  11130. dstsd = map_id2sd(id);
  11131. if( dstsd == NULL )
  11132. return;
  11133. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11134. is_atcommand(fd, sd, command, 1);
  11135. }
  11136. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11137. /// GM adjustment of a player's manner value by -60.
  11138. /// 0212 <char name>.24B
  11139. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11140. {
  11141. char command[NAME_LENGTH+15];
  11142. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11143. name[NAME_LENGTH-1] = '\0';
  11144. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11145. is_atcommand(fd, sd, command, 1);
  11146. }
  11147. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11148. /// 01e0 <account id>.L <account name>.24B
  11149. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  11150. {
  11151. int fd = sd->fd;
  11152. WFIFOHEAD(fd,packet_len(0x1e0));
  11153. WFIFOW(fd,0) = 0x1e0;
  11154. WFIFOL(fd,2) = account_id;
  11155. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11156. WFIFOSET(fd,packet_len(0x1e0));
  11157. }
  11158. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11159. /// 01df <account id>.L
  11160. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11161. {
  11162. char command[30];
  11163. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11164. //tmp get all display
  11165. safesnprintf(command,sizeof(command),"%caccinfo %d", atcommand_symbol, account_id);
  11166. is_atcommand(fd, sd, command, 1);
  11167. //clif_account_name(sd, account_id, ""); //! TODO request to login-serv
  11168. }
  11169. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11170. /// GM single cell type change request.
  11171. /// 0198 <x>.W <y>.W <type>.W
  11172. /// type:
  11173. /// 0 = not walkable
  11174. /// 1 = walkable
  11175. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11176. {
  11177. int x,y,type;
  11178. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11179. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11180. return;
  11181. x = RFIFOW(fd,info->pos[0]);
  11182. y = RFIFOW(fd,info->pos[1]);
  11183. type = RFIFOW(fd,info->pos[2]);
  11184. map_setgatcell(sd->bl.m,x,y,type);
  11185. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11186. //FIXME: once players leave the map, the client 'forgets' this information.
  11187. }
  11188. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11189. /// Request to allow/deny whispers from a nick.
  11190. /// 00cf <nick>.24B <type>.B
  11191. /// type:
  11192. /// 0 = (/ex nick) deny speech from nick
  11193. /// 1 = (/in nick) allow speech from nick
  11194. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11195. {
  11196. char* nick;
  11197. uint8 type;
  11198. int i;
  11199. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11200. nick = (char*)RFIFOP(fd,info->pos[0]);
  11201. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11202. type = RFIFOB(fd,info->pos[1]);
  11203. if( type == 0 ) { // Add name to ignore list (block)
  11204. if (strcmp(wisp_server_name, nick) == 0) {
  11205. clif_wisexin(sd, type, 1); // fail
  11206. return;
  11207. }
  11208. // try to find a free spot, while checking for duplicates at the same time
  11209. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11210. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11211. clif_wisexin(sd, type, 2); // too many blocks
  11212. return;
  11213. }
  11214. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11215. clif_wisexin(sd, type, 0); // Aegis reports success.
  11216. return;
  11217. }
  11218. //Insert in position i
  11219. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11220. } else { // Remove name from ignore list (unblock)
  11221. // find entry
  11222. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11223. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11224. clif_wisexin(sd, type, 1); // fail
  11225. return;
  11226. }
  11227. // move everything one place down to overwrite removed entry
  11228. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11229. // wipe last entry
  11230. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11231. }
  11232. clif_wisexin(sd, type, 0); // success
  11233. }
  11234. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11235. /// Request to allow/deny all whispers.
  11236. /// 00d0 <type>.B
  11237. /// type:
  11238. /// 0 = (/exall) deny all speech
  11239. /// 1 = (/inall) allow all speech
  11240. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11241. {
  11242. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11243. if( type == 0 ) {// Deny all
  11244. if( sd->state.ignoreAll ) {
  11245. flag = 1; // fail
  11246. } else {
  11247. sd->state.ignoreAll = 1;
  11248. flag = 0; // success
  11249. }
  11250. } else {//Unblock everyone
  11251. if( sd->state.ignoreAll ) {
  11252. sd->state.ignoreAll = 0;
  11253. flag = 0; // success
  11254. } else {
  11255. if (sd->ignore[0].name[0] != '\0')
  11256. { //Wipe the ignore list.
  11257. memset(sd->ignore, 0, sizeof(sd->ignore));
  11258. flag = 0; // success
  11259. } else {
  11260. flag = 1; // fail
  11261. }
  11262. }
  11263. }
  11264. clif_wisall(sd, type, flag);
  11265. }
  11266. /// Whisper ignore list (ZC_WHISPER_LIST).
  11267. /// 00d4 <packet len>.W { <char name>.24B }*
  11268. void clif_PMIgnoreList(struct map_session_data* sd)
  11269. {
  11270. int i, fd = sd->fd;
  11271. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11272. WFIFOW(fd,0) = 0xd4;
  11273. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11274. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11275. }
  11276. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11277. WFIFOSET(fd,WFIFOW(fd,2));
  11278. }
  11279. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11280. /// 00d3
  11281. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11282. {
  11283. clif_PMIgnoreList(sd);
  11284. }
  11285. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11286. /// 01e7
  11287. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11288. {
  11289. if (sd->state.doridori) return;
  11290. switch (sd->class_&MAPID_UPPERMASK) {
  11291. case MAPID_SOUL_LINKER:
  11292. case MAPID_STAR_GLADIATOR:
  11293. case MAPID_TAEKWON:
  11294. if (!sd->state.rest)
  11295. break;
  11296. case MAPID_SUPER_NOVICE:
  11297. sd->state.doridori=1;
  11298. break;
  11299. }
  11300. }
  11301. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11302. /// 01ed
  11303. /// Note: This packet is caused by 7 lines of any text, followed by
  11304. /// the prayer and an another line of any text. The prayer is
  11305. /// defined by lines 790~793 in data\msgstringtable.txt
  11306. /// "Dear angel, can you hear my voice?"
  11307. /// "I am" (space separated player name) "Super Novice~"
  11308. /// "Help me out~ Please~ T_T"
  11309. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11310. {
  11311. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  11312. unsigned int next = pc_nextbaseexp(sd);
  11313. if( next == 0 ) next = pc_thisbaseexp(sd);
  11314. if( next ) {
  11315. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11316. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11317. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  11318. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11319. }
  11320. }
  11321. }
  11322. }
  11323. /// Friends List
  11324. ///
  11325. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11326. /// 0206 <account id>.L <char id>.L <state>.B
  11327. /// state:
  11328. /// 0 = online
  11329. /// 1 = offline
  11330. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  11331. {
  11332. int i, fd = sd->fd;
  11333. //Seek friend.
  11334. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11335. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11336. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11337. return; //Not found
  11338. WFIFOHEAD(fd,packet_len(0x206));
  11339. WFIFOW(fd, 0) = 0x206;
  11340. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11341. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11342. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11343. WFIFOSET(fd, packet_len(0x206));
  11344. }
  11345. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11346. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11347. {
  11348. int account_id, char_id, online;
  11349. account_id = va_arg(ap, int);
  11350. char_id = va_arg(ap, int);
  11351. online = va_arg(ap, int);
  11352. clif_friendslist_toggle(sd, account_id, char_id, online);
  11353. return 0;
  11354. }
  11355. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11356. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11357. void clif_friendslist_send(struct map_session_data *sd)
  11358. {
  11359. int i = 0, n, fd = sd->fd;
  11360. // Send friends list
  11361. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11362. WFIFOW(fd, 0) = 0x201;
  11363. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11364. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11365. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11366. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11367. }
  11368. if (i) {
  11369. WFIFOW(fd,2) = 4 + 32 * i;
  11370. WFIFOSET(fd, WFIFOW(fd,2));
  11371. }
  11372. for (n = 0; n < i; n++) { //Sending the online players
  11373. if (map_charid2sd(sd->status.friends[n].char_id))
  11374. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11375. }
  11376. }
  11377. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11378. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11379. /// result:
  11380. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11381. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11382. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11383. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11384. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11385. {
  11386. int fd;
  11387. nullpo_retv(sd);
  11388. fd = sd->fd;
  11389. WFIFOHEAD(fd,packet_len(0x209));
  11390. WFIFOW(fd,0) = 0x209;
  11391. WFIFOW(fd,2) = type;
  11392. if (f_sd) {
  11393. WFIFOL(fd,4) = f_sd->status.account_id;
  11394. WFIFOL(fd,8) = f_sd->status.char_id;
  11395. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11396. }
  11397. WFIFOSET(fd, packet_len(0x209));
  11398. }
  11399. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11400. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11401. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  11402. {
  11403. int fd = sd->fd;
  11404. WFIFOHEAD(fd,packet_len(0x207));
  11405. WFIFOW(fd,0) = 0x207;
  11406. WFIFOL(fd,2) = account_id;
  11407. WFIFOL(fd,6) = char_id;
  11408. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11409. WFIFOSET(fd,packet_len(0x207));
  11410. }
  11411. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11412. /// 0202 <name>.24B
  11413. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11414. {
  11415. struct map_session_data *f_sd;
  11416. int i;
  11417. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11418. // ensure that the request player's friend list is not full
  11419. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11420. if( i == MAX_FRIENDS ) {
  11421. clif_friendslist_reqack(sd, f_sd, 2);
  11422. return;
  11423. }
  11424. // Friend doesn't exist (no player with this name)
  11425. if (f_sd == NULL) {
  11426. clif_displaymessage(fd, msg_txt(sd,3));
  11427. return;
  11428. }
  11429. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11430. return;
  11431. }
  11432. // @noask [LuzZza]
  11433. if(f_sd->state.noask) {
  11434. clif_noask_sub(sd, f_sd, 5);
  11435. return;
  11436. }
  11437. // Friend already exists
  11438. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11439. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11440. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11441. return;
  11442. }
  11443. }
  11444. f_sd->friend_req = sd->status.char_id;
  11445. sd->friend_req = f_sd->status.char_id;
  11446. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11447. }
  11448. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11449. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11450. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11451. /// reply:
  11452. /// 0 = rejected
  11453. /// 1 = accepted
  11454. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11455. {
  11456. struct map_session_data *f_sd;
  11457. int account_id;
  11458. char reply;
  11459. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11460. account_id = RFIFOL(fd,info->pos[0]);
  11461. //char_id = RFIFOL(fd,info->pos[1]);
  11462. if(sd->packet_ver < 6)
  11463. reply = RFIFOB(fd,info->pos[2]);
  11464. else
  11465. reply = RFIFOL(fd,info->pos[2]);
  11466. if( sd->bl.id == account_id ) {// adding oneself as friend
  11467. return;
  11468. }
  11469. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11470. if (f_sd == NULL)
  11471. return;
  11472. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11473. clif_friendslist_reqack(f_sd, sd, 1);
  11474. else {
  11475. int i;
  11476. // Find an empty slot
  11477. for (i = 0; i < MAX_FRIENDS; i++)
  11478. if (f_sd->status.friends[i].char_id == 0)
  11479. break;
  11480. if (i == MAX_FRIENDS) {
  11481. clif_friendslist_reqack(f_sd, sd, 2);
  11482. return;
  11483. }
  11484. f_sd->status.friends[i].account_id = sd->status.account_id;
  11485. f_sd->status.friends[i].char_id = sd->status.char_id;
  11486. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11487. clif_friendslist_reqack(f_sd, sd, 0);
  11488. if (battle_config.friend_auto_add) {
  11489. // Also add f_sd to sd's friendlist.
  11490. for (i = 0; i < MAX_FRIENDS; i++) {
  11491. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11492. return; //No need to add anything.
  11493. if (sd->status.friends[i].char_id == 0)
  11494. break;
  11495. }
  11496. if (i == MAX_FRIENDS) {
  11497. clif_friendslist_reqack(sd, f_sd, 2);
  11498. return;
  11499. }
  11500. sd->status.friends[i].account_id = f_sd->status.account_id;
  11501. sd->status.friends[i].char_id = f_sd->status.char_id;
  11502. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11503. clif_friendslist_reqack(sd, f_sd, 0);
  11504. }
  11505. }
  11506. }
  11507. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11508. /// 0203 <account id>.L <char id>.L
  11509. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11510. {
  11511. struct map_session_data *f_sd = NULL;
  11512. int account_id, char_id;
  11513. int i, j;
  11514. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11515. account_id = RFIFOL(fd,info->pos[0]);
  11516. char_id = RFIFOL(fd,info->pos[1]);
  11517. // Search friend
  11518. for (i = 0; i < MAX_FRIENDS &&
  11519. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11520. if (i == MAX_FRIENDS) {
  11521. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11522. return;
  11523. }
  11524. //remove from friend's list first
  11525. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11526. for (i = 0; i < MAX_FRIENDS &&
  11527. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11528. if (i != MAX_FRIENDS) {
  11529. // move all chars up
  11530. for(j = i + 1; j < MAX_FRIENDS; j++)
  11531. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11532. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11533. //should the guy be notified of some message? we should add it here if so
  11534. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11535. WFIFOW(f_sd->fd,0) = 0x20a;
  11536. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11537. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11538. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11539. }
  11540. } else { //friend not online -- ask char server to delete from his friendlist
  11541. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11542. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11543. return;
  11544. }
  11545. }
  11546. // We can now delete from original requester
  11547. for (i = 0; i < MAX_FRIENDS &&
  11548. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11549. // move all chars up
  11550. for(j = i + 1; j < MAX_FRIENDS; j++)
  11551. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11552. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11553. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11554. WFIFOHEAD(fd,packet_len(0x20a));
  11555. WFIFOW(fd,0) = 0x20a;
  11556. WFIFOL(fd,2) = account_id;
  11557. WFIFOL(fd,6) = char_id;
  11558. WFIFOSET(fd, packet_len(0x20a));
  11559. }
  11560. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11561. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11562. void clif_PVPInfo(struct map_session_data* sd)
  11563. {
  11564. int fd = sd->fd;
  11565. WFIFOHEAD(fd,packet_len(0x210));
  11566. WFIFOW(fd,0) = 0x210;
  11567. WFIFOL(fd,2) = sd->status.char_id;
  11568. WFIFOL(fd,6) = sd->status.account_id;
  11569. WFIFOL(fd,10) = sd->pvp_won; // times won
  11570. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11571. WFIFOL(fd,18) = sd->pvp_point;
  11572. WFIFOSET(fd, packet_len(0x210));
  11573. }
  11574. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11575. /// 020f <char id>.L <account id>.L
  11576. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11577. {
  11578. // TODO: Is there a way to use this on an another player (char/acc id)?
  11579. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11580. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11581. clif_PVPInfo(sd);
  11582. }
  11583. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11584. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11585. void clif_blacksmith(struct map_session_data* sd)
  11586. {
  11587. int i, fd = sd->fd;
  11588. const char* name;
  11589. WFIFOHEAD(fd,packet_len(0x219));
  11590. WFIFOW(fd,0) = 0x219;
  11591. //Packet size limits this list to 10 elements. [Skotlex]
  11592. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11593. if (smith_fame_list[i].id > 0) {
  11594. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11595. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11596. {
  11597. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11598. } else
  11599. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11600. } else
  11601. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11602. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11603. }
  11604. for(;i < 10; i++) { //In case the MAX is less than 10.
  11605. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11606. WFIFOL(fd, 242 + i * 4) = 0;
  11607. }
  11608. WFIFOSET(fd, packet_len(0x219));
  11609. }
  11610. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11611. /// 0217
  11612. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11613. {
  11614. clif_blacksmith(sd);
  11615. }
  11616. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11617. /// 021b <points>.L <total points>.L
  11618. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11619. {
  11620. int fd = sd->fd;
  11621. WFIFOHEAD(fd,packet_len(0x21b));
  11622. WFIFOW(fd,0) = 0x21b;
  11623. WFIFOL(fd,2) = points;
  11624. WFIFOL(fd,6) = sd->status.fame;
  11625. WFIFOSET(fd, packet_len(0x21b));
  11626. }
  11627. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11628. /// 021a { <name>.24B }*10 { <point>.L }*10
  11629. void clif_alchemist(struct map_session_data* sd)
  11630. {
  11631. int i, fd = sd->fd;
  11632. const char* name;
  11633. WFIFOHEAD(fd,packet_len(0x21a));
  11634. WFIFOW(fd,0) = 0x21a;
  11635. //Packet size limits this list to 10 elements. [Skotlex]
  11636. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11637. if (chemist_fame_list[i].id > 0) {
  11638. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11639. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11640. {
  11641. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11642. } else
  11643. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11644. } else
  11645. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11646. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11647. }
  11648. for(;i < 10; i++) { //In case the MAX is less than 10.
  11649. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11650. WFIFOL(fd, 242 + i * 4) = 0;
  11651. }
  11652. WFIFOSET(fd, packet_len(0x21a));
  11653. }
  11654. /// /alchemist (CZ_ALCHEMIST_RANK).
  11655. /// 0218
  11656. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11657. {
  11658. clif_alchemist(sd);
  11659. }
  11660. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11661. /// 021c <points>.L <total points>.L
  11662. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11663. {
  11664. int fd = sd->fd;
  11665. WFIFOHEAD(fd,packet_len(0x21c));
  11666. WFIFOW(fd,0) = 0x21c;
  11667. WFIFOL(fd,2) = points;
  11668. WFIFOL(fd,6) = sd->status.fame;
  11669. WFIFOSET(fd, packet_len(0x21c));
  11670. }
  11671. /// /taekwon list (ZC_TAEKWON_RANK).
  11672. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11673. void clif_taekwon(struct map_session_data* sd)
  11674. {
  11675. int i, fd = sd->fd;
  11676. const char* name;
  11677. WFIFOHEAD(fd,packet_len(0x226));
  11678. WFIFOW(fd,0) = 0x226;
  11679. //Packet size limits this list to 10 elements. [Skotlex]
  11680. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11681. if (taekwon_fame_list[i].id > 0) {
  11682. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11683. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11684. {
  11685. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11686. } else
  11687. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11688. } else
  11689. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11690. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11691. }
  11692. for(;i < 10; i++) { //In case the MAX is less than 10.
  11693. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11694. WFIFOL(fd, 242 + i * 4) = 0;
  11695. }
  11696. WFIFOSET(fd, packet_len(0x226));
  11697. }
  11698. /// /taekwon (CZ_TAEKWON_RANK).
  11699. /// 0225
  11700. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11701. {
  11702. clif_taekwon(sd);
  11703. }
  11704. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11705. /// 0224 <points>.L <total points>.L
  11706. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11707. {
  11708. int fd = sd->fd;
  11709. WFIFOHEAD(fd,packet_len(0x224));
  11710. WFIFOW(fd,0) = 0x224;
  11711. WFIFOL(fd,2) = points;
  11712. WFIFOL(fd,6) = sd->status.fame;
  11713. WFIFOSET(fd, packet_len(0x224));
  11714. }
  11715. /// /pk list (ZC_KILLER_RANK).
  11716. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11717. void clif_ranking_pk(struct map_session_data* sd)
  11718. {
  11719. int i, fd = sd->fd;
  11720. WFIFOHEAD(fd,packet_len(0x238));
  11721. WFIFOW(fd,0) = 0x238;
  11722. for(i=0;i<10;i++){
  11723. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11724. WFIFOL(fd,i*4+242) = 0;
  11725. }
  11726. WFIFOSET(fd, packet_len(0x238));
  11727. }
  11728. /// /pk (CZ_KILLER_RANK).
  11729. /// 0237
  11730. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11731. {
  11732. clif_ranking_pk(sd);
  11733. }
  11734. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11735. /// 0254 <which>.B
  11736. /// which: (unused atm for security purpose)
  11737. /// 0 = sun
  11738. /// 1 = moon
  11739. /// 2 = star
  11740. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11741. {
  11742. int i;
  11743. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11744. if (sd->menuskill_id != SG_FEEL)
  11745. return;
  11746. i = sd->menuskill_val-1;
  11747. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11748. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11749. sd->feel_map[i].m = sd->bl.m;
  11750. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11751. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11752. // clif_misceffect2(&sd->bl, 0x1b0);
  11753. // clif_misceffect2(&sd->bl, 0x21f);
  11754. clif_feel_info(sd, i, 0);
  11755. clif_menuskill_clear(sd);
  11756. }
  11757. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11758. /// 0253 <which>.B
  11759. /// which:
  11760. /// 0 = sun
  11761. /// 1 = moon
  11762. /// 2 = star
  11763. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11764. {
  11765. WFIFOHEAD(fd,packet_len(0x253));
  11766. WFIFOW(fd,0)=0x253;
  11767. WFIFOB(fd,2)=TOB(skill_lv-1);
  11768. WFIFOSET(fd, packet_len(0x253));
  11769. sd->menuskill_id = SG_FEEL;
  11770. sd->menuskill_val = skill_lv;
  11771. }
  11772. /// Request to change homunculus' name (CZ_RENAME_MER).
  11773. /// 0231 <name>.24B
  11774. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11775. merc_hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11776. }
  11777. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11778. /// 0234 <id>.L
  11779. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11780. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11781. struct block_list *bl = NULL;
  11782. struct unit_data *ud = NULL;
  11783. if( sd->md && sd->md->bl.id == id )
  11784. bl = &sd->md->bl;
  11785. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11786. bl = &sd->hd->bl; // Moving Homunculus
  11787. else
  11788. return;
  11789. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11790. ud = unit_bl2ud(bl);
  11791. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11792. }
  11793. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11794. /// 0232 <id>.L <position data>.3B
  11795. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11796. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11797. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11798. struct block_list *bl = NULL;
  11799. short x, y;
  11800. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11801. if( sd->md && sd->md->bl.id == id )
  11802. bl = &sd->md->bl; // Moving Mercenary
  11803. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11804. bl = &sd->hd->bl; // Moving Homunculus
  11805. else
  11806. return;
  11807. unit_walktoxy(bl, x, y, 4);
  11808. }
  11809. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11810. /// 0233 <id>.L <target id>.L <action>.B
  11811. /// action:
  11812. /// always 0
  11813. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11814. {
  11815. struct block_list *bl = NULL;
  11816. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11817. int id = RFIFOL(fd,info->pos[0]);
  11818. int target_id = RFIFOL(fd,info->pos[1]);
  11819. int action_type = RFIFOB(fd,info->pos[2]);
  11820. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11821. bl = &sd->hd->bl;
  11822. else if( sd->md && sd->md->bl.id == id )
  11823. bl = &sd->md->bl;
  11824. else return;
  11825. unit_stop_attack(bl);
  11826. unit_attack(bl, target_id, action_type != 0);
  11827. }
  11828. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11829. /// 022d <type>.W <command>.B
  11830. /// type:
  11831. /// always 0
  11832. /// command:
  11833. /// 0 = homunculus information
  11834. /// 1 = feed
  11835. /// 2 = delete
  11836. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11837. { //[orn]
  11838. int cmd = RFIFOW(fd,0);
  11839. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11840. if(!merc_is_hom_active(sd->hd))
  11841. return;
  11842. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11843. }
  11844. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11845. /// 0292
  11846. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11847. {
  11848. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11849. if (item_position < 0)
  11850. return;
  11851. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11852. return;
  11853. if (!status_revive(&sd->bl, 100, 100))
  11854. return;
  11855. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11856. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11857. }
  11858. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11859. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11860. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11861. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11862. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11863. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11864. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11865. void clif_check(int fd, struct map_session_data* pl_sd)
  11866. {
  11867. WFIFOHEAD(fd,packet_len(0x214));
  11868. WFIFOW(fd, 0) = 0x214;
  11869. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11870. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11871. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11872. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11873. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11874. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11875. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11876. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11877. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11878. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11879. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11880. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11881. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11882. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11883. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11884. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11885. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11886. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11887. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11888. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11889. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11890. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11891. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11892. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11893. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11894. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11895. WFIFOSET(fd,packet_len(0x214));
  11896. }
  11897. /// /check (CZ_REQ_STATUS_GM).
  11898. /// Request character's status values.
  11899. /// 0213 <char name>.24B
  11900. void clif_parse_Check(int fd, struct map_session_data *sd)
  11901. {
  11902. char charname[NAME_LENGTH];
  11903. struct map_session_data* pl_sd;
  11904. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11905. return;
  11906. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11907. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11908. {
  11909. return;
  11910. }
  11911. clif_check(fd, pl_sd);
  11912. }
  11913. /// MAIL SYSTEM
  11914. /// By Zephyrus
  11915. ///
  11916. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11917. /// 0255 <index>.W <result>.B
  11918. /// result:
  11919. /// 0 = success
  11920. /// 1 = failure
  11921. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11922. {
  11923. WFIFOHEAD(fd,packet_len(0x255));
  11924. WFIFOW(fd,0) = 0x255;
  11925. WFIFOW(fd,2) = index;
  11926. WFIFOB(fd,4) = flag;
  11927. WFIFOSET(fd,packet_len(0x255));
  11928. }
  11929. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11930. /// 0245 <result>.B
  11931. /// result:
  11932. /// 0 = success
  11933. /// 1 = failure
  11934. /// 2 = too many items
  11935. void clif_Mail_getattachment(int fd, uint8 flag)
  11936. {
  11937. WFIFOHEAD(fd,packet_len(0x245));
  11938. WFIFOW(fd,0) = 0x245;
  11939. WFIFOB(fd,2) = flag;
  11940. WFIFOSET(fd,packet_len(0x245));
  11941. }
  11942. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11943. /// 0249 <result>.B
  11944. /// result:
  11945. /// 0 = success
  11946. /// 1 = recipinent does not exist
  11947. void clif_Mail_send(int fd, bool fail)
  11948. {
  11949. WFIFOHEAD(fd,packet_len(0x249));
  11950. WFIFOW(fd,0) = 0x249;
  11951. WFIFOB(fd,2) = fail;
  11952. WFIFOSET(fd,packet_len(0x249));
  11953. }
  11954. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11955. /// 0257 <mail id>.L <result>.W
  11956. /// result:
  11957. /// 0 = success
  11958. /// 1 = failure
  11959. void clif_Mail_delete(int fd, int mail_id, short fail)
  11960. {
  11961. WFIFOHEAD(fd, packet_len(0x257));
  11962. WFIFOW(fd,0) = 0x257;
  11963. WFIFOL(fd,2) = mail_id;
  11964. WFIFOW(fd,6) = fail;
  11965. WFIFOSET(fd, packet_len(0x257));
  11966. }
  11967. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11968. /// 0274 <mail id>.L <result>.W
  11969. /// result:
  11970. /// 0 = success
  11971. /// 1 = failure
  11972. void clif_Mail_return(int fd, int mail_id, short fail)
  11973. {
  11974. WFIFOHEAD(fd,packet_len(0x274));
  11975. WFIFOW(fd,0) = 0x274;
  11976. WFIFOL(fd,2) = mail_id;
  11977. WFIFOW(fd,6) = fail;
  11978. WFIFOSET(fd,packet_len(0x274));
  11979. }
  11980. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11981. /// 024a <mail id>.L <title>.40B <sender>.24B
  11982. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11983. {
  11984. WFIFOHEAD(fd,packet_len(0x24a));
  11985. WFIFOW(fd,0) = 0x24a;
  11986. WFIFOL(fd,2) = mail_id;
  11987. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11988. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11989. WFIFOSET(fd,packet_len(0x24a));
  11990. }
  11991. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11992. /// 0260 <type>.L
  11993. /// type:
  11994. /// 0 = open
  11995. /// 1 = close
  11996. void clif_Mail_window(int fd, int flag)
  11997. {
  11998. WFIFOHEAD(fd,packet_len(0x260));
  11999. WFIFOW(fd,0) = 0x260;
  12000. WFIFOL(fd,2) = flag;
  12001. WFIFOSET(fd,packet_len(0x260));
  12002. }
  12003. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12004. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12005. /// read:
  12006. /// 0 = unread
  12007. /// 1 = read
  12008. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12009. {
  12010. int fd = sd->fd;
  12011. struct mail_data *md = &sd->mail.inbox;
  12012. struct mail_message *msg;
  12013. int len, i, j;
  12014. len = 8 + (73 * md->amount);
  12015. WFIFOHEAD(fd,len);
  12016. WFIFOW(fd,0) = 0x240;
  12017. WFIFOW(fd,2) = len;
  12018. WFIFOL(fd,4) = md->amount;
  12019. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12020. {
  12021. msg = &md->msg[i];
  12022. if (msg->id < 1)
  12023. continue;
  12024. WFIFOL(fd,8+73*j) = msg->id;
  12025. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12026. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12027. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12028. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12029. j++;
  12030. }
  12031. WFIFOSET(fd,len);
  12032. if( md->full ) {// TODO: is this official?
  12033. char output[100];
  12034. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12035. clif_disp_onlyself(sd, output, strlen(output));
  12036. }
  12037. }
  12038. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12039. /// 023f
  12040. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12041. {
  12042. struct mail_data* md = &sd->mail.inbox;
  12043. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12044. intif_Mail_requestinbox(sd->status.char_id, 1);
  12045. else
  12046. clif_Mail_refreshinbox(sd);
  12047. mail_removeitem(sd, 0);
  12048. mail_removezeny(sd, 0);
  12049. }
  12050. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12051. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12052. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12053. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12054. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12055. {
  12056. int i, fd = sd->fd;
  12057. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12058. if( i == MAIL_MAX_INBOX ) {
  12059. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12060. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12061. return;
  12062. } else {
  12063. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12064. struct item *item = &msg->item;
  12065. struct item_data *data;
  12066. int msg_len = strlen(msg->body), len;
  12067. if( msg_len == 0 ) {
  12068. strcpy(msg->body, "(no message)");
  12069. msg_len = strlen(msg->body);
  12070. }
  12071. len = 101 + msg_len;
  12072. WFIFOHEAD(fd,len);
  12073. WFIFOW(fd,0) = 0x242;
  12074. WFIFOW(fd,2) = len;
  12075. WFIFOL(fd,4) = msg->id;
  12076. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12077. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12078. WFIFOL(fd,72) = 0;
  12079. WFIFOL(fd,76) = msg->zeny;
  12080. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12081. WFIFOL(fd,80) = item->amount;
  12082. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12083. WFIFOW(fd,86) = data->type;
  12084. WFIFOB(fd,88) = item->identify;
  12085. WFIFOB(fd,89) = item->attribute;
  12086. WFIFOB(fd,90) = item->refine;
  12087. WFIFOW(fd,91) = item->card[0];
  12088. WFIFOW(fd,93) = item->card[1];
  12089. WFIFOW(fd,95) = item->card[2];
  12090. WFIFOW(fd,97) = item->card[3];
  12091. } else // no item, set all to zero
  12092. memset(WFIFOP(fd,80), 0x00, 19);
  12093. WFIFOB(fd,99) = (unsigned char)msg_len;
  12094. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12095. WFIFOSET(fd,len);
  12096. if (msg->status == MAIL_UNREAD) {
  12097. msg->status = MAIL_READ;
  12098. intif_Mail_read(mail_id);
  12099. clif_parse_Mail_refreshinbox(fd, sd);
  12100. }
  12101. }
  12102. }
  12103. /// Request to open a mail (CZ_MAIL_OPEN).
  12104. /// 0241 <mail id>.L
  12105. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12106. {
  12107. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12108. if( mail_id <= 0 )
  12109. return;
  12110. if( mail_invalid_operation(sd) )
  12111. return;
  12112. clif_Mail_read(sd, mail_id);
  12113. }
  12114. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12115. /// 0244 <mail id>.L
  12116. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12117. {
  12118. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12119. int i;
  12120. bool fail = false;
  12121. if( !chrif_isconnected() )
  12122. return;
  12123. if( mail_id <= 0 )
  12124. return;
  12125. if( mail_invalid_operation(sd) )
  12126. return;
  12127. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12128. if( i == MAIL_MAX_INBOX )
  12129. return;
  12130. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12131. return;
  12132. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12133. clif_Mail_getattachment(fd, 1);
  12134. return;
  12135. }
  12136. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12137. struct item_data *data;
  12138. unsigned int weight;
  12139. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12140. return;
  12141. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12142. case CHKADDITEM_NEW:
  12143. fail = ( pc_inventoryblank(sd) == 0 );
  12144. break;
  12145. case CHKADDITEM_OVERAMOUNT:
  12146. fail = true;
  12147. }
  12148. if( fail ) {
  12149. clif_Mail_getattachment(fd, 1);
  12150. return;
  12151. }
  12152. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12153. if( sd->weight + weight > sd->max_weight ) {
  12154. clif_Mail_getattachment(fd, 2);
  12155. return;
  12156. }
  12157. }
  12158. sd->mail.inbox.msg[i].zeny = 0;
  12159. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12160. clif_Mail_read(sd, mail_id);
  12161. intif_Mail_getattach(sd->status.char_id, mail_id);
  12162. }
  12163. /// Request to delete a mail (CZ_MAIL_DELETE).
  12164. /// 0243 <mail id>.L
  12165. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12166. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12167. int i;
  12168. if( !chrif_isconnected() )
  12169. return;
  12170. if( mail_id <= 0 )
  12171. return;
  12172. if( mail_invalid_operation(sd) )
  12173. return;
  12174. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12175. if (i < MAIL_MAX_INBOX) {
  12176. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12177. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12178. clif_Mail_delete(sd->fd, mail_id, 1);
  12179. return;
  12180. }
  12181. intif_Mail_delete(sd->status.char_id, mail_id);
  12182. }
  12183. }
  12184. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12185. /// 0273 <mail id>.L <receive name>.24B
  12186. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12187. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12188. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12189. int i;
  12190. if( mail_id <= 0 )
  12191. return;
  12192. if( mail_invalid_operation(sd) )
  12193. return;
  12194. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12195. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12196. intif_Mail_return(sd->status.char_id, mail_id);
  12197. else
  12198. clif_Mail_return(sd->fd, mail_id, 1);
  12199. }
  12200. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12201. /// 0247 <index>.W <amount>.L
  12202. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12203. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12204. int idx = RFIFOW(fd,info->pos[0]);
  12205. int amount = RFIFOL(fd,info->pos[1]);
  12206. unsigned char flag;
  12207. if( !chrif_isconnected() )
  12208. return;
  12209. if (idx < 0 || amount < 0)
  12210. return;
  12211. flag = mail_setitem(sd, idx, amount);
  12212. clif_Mail_setattachment(fd,idx,flag);
  12213. }
  12214. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12215. /// 0246 <type>.W
  12216. /// type:
  12217. /// 0 = reset all
  12218. /// 1 = remove item
  12219. /// 2 = remove zeny
  12220. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12221. {
  12222. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12223. if (type == 0 || type == 1)
  12224. mail_removeitem(sd, 0);
  12225. if (type == 0 || type == 2)
  12226. mail_removezeny(sd, 0);
  12227. }
  12228. /// Request to send mail (CZ_MAIL_SEND).
  12229. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12230. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12231. {
  12232. struct mail_message msg;
  12233. int body_len;
  12234. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12235. if( !chrif_isconnected() )
  12236. return;
  12237. if( sd->state.trading )
  12238. return;
  12239. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12240. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12241. return;
  12242. }
  12243. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 ) {
  12244. clif_displaymessage(sd->fd,msg_txt(sd,675)); //"Cannot send mails too fast!!."
  12245. clif_Mail_send(fd, true); // fail
  12246. return;
  12247. }
  12248. body_len = RFIFOB(fd,info->pos[3]);
  12249. if (body_len > MAIL_BODY_LENGTH)
  12250. body_len = MAIL_BODY_LENGTH;
  12251. if( !mail_setattachment(sd, &msg) ) { // Invalid Append condition
  12252. clif_Mail_send(sd->fd, true); // fail
  12253. mail_removeitem(sd,0);
  12254. mail_removezeny(sd,0);
  12255. return;
  12256. }
  12257. msg.id = 0; // id will be assigned by charserver
  12258. msg.send_id = sd->status.char_id;
  12259. msg.dest_id = 0; // will attempt to resolve name
  12260. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  12261. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,info->pos[1]), NAME_LENGTH);
  12262. safestrncpy(msg.title, (char*)RFIFOP(fd,info->pos[2]), MAIL_TITLE_LENGTH);
  12263. if (msg.title[0] == '\0') {
  12264. return; // Message has no length and somehow client verification was skipped.
  12265. }
  12266. if (body_len)
  12267. safestrncpy(msg.body, (char*)RFIFOP(fd,info->pos[4]), body_len + 1);
  12268. else
  12269. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  12270. msg.timestamp = time(NULL);
  12271. if( !intif_Mail_send(sd->status.account_id, &msg) )
  12272. mail_deliveryfail(sd, &msg);
  12273. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  12274. }
  12275. /// AUCTION SYSTEM
  12276. /// By Zephyrus
  12277. ///
  12278. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12279. /// 025f <type>.L
  12280. /// type:
  12281. /// 0 = open
  12282. /// 1 = close
  12283. void clif_Auction_openwindow(struct map_session_data *sd)
  12284. {
  12285. int fd = sd->fd;
  12286. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12287. return;
  12288. WFIFOHEAD(fd,packet_len(0x25f));
  12289. WFIFOW(fd,0) = 0x25f;
  12290. WFIFOL(fd,2) = 0;
  12291. WFIFOSET(fd,packet_len(0x25f));
  12292. }
  12293. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12294. /// 0252 <packet len>.W <pages>.L <count>.L { <auction id>.L <seller name>.24B <name id>.W <type>.L <amount>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <now price>.L <max price>.L <buyer name>.24B <delete time>.L }*
  12295. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12296. {
  12297. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12298. struct auction_data auction;
  12299. struct item_data *item;
  12300. int k;
  12301. WFIFOHEAD(fd,12 + (count * 83));
  12302. WFIFOW(fd,0) = 0x252;
  12303. WFIFOW(fd,2) = 12 + (count * 83);
  12304. WFIFOL(fd,4) = pages;
  12305. WFIFOL(fd,8) = count;
  12306. for( i = 0; i < count; i++ ) {
  12307. memcpy(&auction, RBUFP(buf,i * len), len);
  12308. k = 12 + (i * 83);
  12309. WFIFOL(fd,k) = auction.auction_id;
  12310. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12311. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12312. WFIFOW(fd,28+k) = item->view_id;
  12313. else
  12314. WFIFOW(fd,28+k) = auction.item.nameid;
  12315. WFIFOL(fd,30+k) = auction.type;
  12316. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12317. WFIFOB(fd,36+k) = auction.item.identify;
  12318. WFIFOB(fd,37+k) = auction.item.attribute;
  12319. WFIFOB(fd,38+k) = auction.item.refine;
  12320. WFIFOW(fd,39+k) = auction.item.card[0];
  12321. WFIFOW(fd,41+k) = auction.item.card[1];
  12322. WFIFOW(fd,43+k) = auction.item.card[2];
  12323. WFIFOW(fd,45+k) = auction.item.card[3];
  12324. WFIFOL(fd,47+k) = auction.price;
  12325. WFIFOL(fd,51+k) = auction.buynow;
  12326. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12327. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12328. }
  12329. WFIFOSET(fd,WFIFOW(fd,2));
  12330. }
  12331. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12332. /// 0256 <index>.W <result>.B
  12333. /// result:
  12334. /// 0 = success
  12335. /// 1 = failure
  12336. static void clif_Auction_setitem(int fd, int index, bool fail)
  12337. {
  12338. WFIFOHEAD(fd,packet_len(0x256));
  12339. WFIFOW(fd,0) = 0x256;
  12340. WFIFOW(fd,2) = index;
  12341. WFIFOB(fd,4) = fail;
  12342. WFIFOSET(fd,packet_len(0x256));
  12343. }
  12344. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12345. /// 024b <type>.W
  12346. /// type:
  12347. /// 0 = create (any other action in auction window)
  12348. /// 1 = cancel (cancel pressed on register tab)
  12349. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12350. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12351. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12352. if( sd->auction.amount > 0 )
  12353. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12354. sd->auction.amount = 0;
  12355. }
  12356. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12357. /// 024c <index>.W <count>.L
  12358. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12359. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12360. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12361. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12362. struct item_data *item;
  12363. if( sd->auction.amount > 0 )
  12364. sd->auction.amount = 0;
  12365. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12366. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12367. return;
  12368. }
  12369. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12370. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12371. return;
  12372. }
  12373. if( (item = itemdb_exists(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 || item->type == IT_SHADOWGEAR) )
  12374. { // Consumable or pets are not allowed
  12375. clif_Auction_setitem(sd->fd, idx, true);
  12376. return;
  12377. }
  12378. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12379. !sd->status.inventory[idx].identify ||
  12380. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12381. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  12382. clif_Auction_setitem(sd->fd, idx, true);
  12383. return;
  12384. }
  12385. sd->auction.index = idx;
  12386. sd->auction.amount = amount;
  12387. clif_Auction_setitem(fd, idx + 2, false);
  12388. }
  12389. /// Result from an auction action (ZC_AUCTION_RESULT).
  12390. /// 0250 <result>.B
  12391. /// result:
  12392. /// 0 = You have failed to bid into the auction
  12393. /// 1 = You have successfully bid in the auction
  12394. /// 2 = The auction has been canceled
  12395. /// 3 = An auction with at least one bidder cannot be canceled
  12396. /// 4 = You cannot register more than 5 items in an auction at a time
  12397. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12398. /// 6 = You have won the auction
  12399. /// 7 = You have failed to win the auction
  12400. /// 8 = You do not have enough Zeny
  12401. /// 9 = You cannot place more than 5 bids at a time
  12402. void clif_Auction_message(int fd, unsigned char flag)
  12403. {
  12404. WFIFOHEAD(fd,packet_len(0x250));
  12405. WFIFOW(fd,0) = 0x250;
  12406. WFIFOB(fd,2) = flag;
  12407. WFIFOSET(fd,packet_len(0x250));
  12408. }
  12409. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12410. /// 025e <result>.W
  12411. /// result:
  12412. /// 0 = You have ended the auction
  12413. /// 1 = You cannot end the auction
  12414. /// 2 = Auction ID is incorrect
  12415. void clif_Auction_close(int fd, unsigned char flag)
  12416. {
  12417. WFIFOHEAD(fd,packet_len(0x25e));
  12418. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12419. WFIFOW(fd,2) = flag;
  12420. WFIFOSET(fd,packet_len(0x25e));
  12421. }
  12422. /// Request to add an auction (CZ_AUCTION_ADD).
  12423. /// 024d <now money>.L <max money>.L <delete hour>.W
  12424. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12425. {
  12426. struct auction_data auction;
  12427. struct item_data *item;
  12428. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12429. auction.price = RFIFOL(fd,info->pos[0]);
  12430. auction.buynow = RFIFOL(fd,info->pos[1]);
  12431. auction.hours = RFIFOW(fd,info->pos[2]);
  12432. // Invalid Situations...
  12433. if( sd->auction.amount < 1 ) {
  12434. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12435. return;
  12436. }
  12437. if( auction.price >= auction.buynow ) {
  12438. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12439. return;
  12440. }
  12441. if( auction.hours < 1 || auction.hours > 48 ) {
  12442. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12443. return;
  12444. }
  12445. // Auction checks...
  12446. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12447. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12448. clif_Auction_message(fd, 2); // The auction has been canceled
  12449. return;
  12450. }
  12451. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12452. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12453. return;
  12454. }
  12455. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12456. auction.buynow = battle_config.auction_maximumprice;
  12457. if( auction.price >= auction.buynow )
  12458. auction.price = auction.buynow - 1;
  12459. }
  12460. auction.auction_id = 0;
  12461. auction.seller_id = sd->status.char_id;
  12462. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12463. auction.buyer_id = 0;
  12464. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12465. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12466. {
  12467. clif_Auction_message(fd, 2); // The auction has been canceled
  12468. return;
  12469. }
  12470. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12471. { // Just in case
  12472. clif_Auction_message(fd, 2); // The auction has been canceled
  12473. return;
  12474. }
  12475. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12476. auction.type = item->type;
  12477. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12478. auction.item.amount = 1;
  12479. auction.timestamp = 0;
  12480. if( !intif_Auction_register(&auction) )
  12481. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12482. else
  12483. {
  12484. int zeny = auction.hours*battle_config.auction_feeperhour;
  12485. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12486. sd->auction.amount = 0;
  12487. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12488. }
  12489. }
  12490. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12491. /// 024e <auction id>.L
  12492. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12493. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12494. intif_Auction_cancel(sd->status.char_id, auction_id);
  12495. }
  12496. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12497. /// 025d <auction id>.L
  12498. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12499. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12500. intif_Auction_close(sd->status.char_id, auction_id);
  12501. }
  12502. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12503. /// 024f <auction id>.L <money>.L
  12504. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12505. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12506. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12507. int bid = RFIFOL(fd,info->pos[1]);
  12508. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12509. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12510. return;
  12511. }
  12512. if( bid <= 0 )
  12513. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12514. else if( bid > sd->status.zeny )
  12515. clif_Auction_message(fd, 8); // You do not have enough zeny
  12516. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12517. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12518. else {
  12519. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12520. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12521. }
  12522. }
  12523. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12524. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12525. /// search type:
  12526. /// 0 = armor
  12527. /// 1 = weapon
  12528. /// 2 = card
  12529. /// 3 = misc
  12530. /// 4 = name search
  12531. /// 5 = auction id search
  12532. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12533. char search_text[NAME_LENGTH];
  12534. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12535. short type = RFIFOW(fd,info->pos[0]);
  12536. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12537. int page = RFIFOW(fd,info->pos[3]);
  12538. clif_parse_Auction_cancelreg(fd, sd);
  12539. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12540. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12541. }
  12542. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12543. /// 025c <type>.W
  12544. /// type:
  12545. /// 0 = sell (own auctions)
  12546. /// 1 = buy (own bids)
  12547. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12548. {
  12549. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12550. clif_parse_Auction_cancelreg(fd, sd);
  12551. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12552. }
  12553. /// CASH/POINT SHOP
  12554. ///
  12555. void clif_cashshop_open( struct map_session_data* sd ){
  12556. WFIFOHEAD( sd->fd, 10 );
  12557. WFIFOW( sd->fd, 0 ) = 0x845;
  12558. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12559. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12560. WFIFOSET( sd->fd, 10 );
  12561. }
  12562. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12563. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12564. clif_cashshop_open( sd );
  12565. }
  12566. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12567. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12568. // No need to do anything here
  12569. }
  12570. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12571. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12572. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12573. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12574. int j;
  12575. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12576. return;
  12577. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12578. WFIFOW(fd, 0) = 0x8c0;
  12579. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12580. WFIFOL(fd, 4) = tab;
  12581. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12582. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12583. WFIFOW(fd, 10 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->nameid;
  12584. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12585. }
  12586. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12587. }
  12588. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12589. void clif_cashshop_list( int fd ){
  12590. int tab;
  12591. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12592. int length = 8 + cash_shop_items[tab].count * 6;
  12593. int i, offset;
  12594. WFIFOHEAD( fd, length );
  12595. WFIFOW( fd, 0 ) = 0x8ca;
  12596. WFIFOW( fd, 2 ) = length;
  12597. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12598. WFIFOW( fd, 6 ) = tab;
  12599. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12600. WFIFOW( fd, offset ) = cash_shop_items[tab].item[i]->nameid;
  12601. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12602. }
  12603. WFIFOSET( fd, length );
  12604. }
  12605. }
  12606. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12607. if( !sd->status.cashshop_sent ) {
  12608. clif_cashshop_list( fd );
  12609. sd->status.cashshop_sent = true;
  12610. }
  12611. }
  12612. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12613. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12614. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12615. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12616. {
  12617. int fd,i;
  12618. #if PACKETVER < 20070711
  12619. const int offset = 8;
  12620. #else
  12621. const int offset = 12;
  12622. #endif
  12623. nullpo_retv(sd);
  12624. nullpo_retv(nd);
  12625. fd = sd->fd;
  12626. sd->npc_shopid = nd->bl.id;
  12627. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12628. WFIFOW(fd,0) = 0x287;
  12629. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12630. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12631. #if PACKETVER >= 20070711
  12632. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12633. #endif
  12634. for( i = 0; i < nd->u.shop.count; i++ ) {
  12635. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12636. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12637. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12638. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12639. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12640. }
  12641. WFIFOSET(fd,WFIFOW(fd,2));
  12642. }
  12643. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12644. /// 0289 <cash point>.L <error>.W
  12645. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12646. /// error:
  12647. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12648. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12649. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12650. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12651. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12652. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12653. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12654. /// 7 = You can purchase up to 10 items.
  12655. /// 8 = Some items could not be purchased.
  12656. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12657. {
  12658. int fd = sd->fd;
  12659. WFIFOHEAD(fd, packet_len(0x289));
  12660. WFIFOW(fd,0) = 0x289;
  12661. WFIFOL(fd,2) = sd->cashPoints;
  12662. #if PACKETVER < 20070711
  12663. WFIFOW(fd,6) = TOW(error);
  12664. #else
  12665. WFIFOL(fd,6) = sd->kafraPoints;
  12666. WFIFOW(fd,10) = TOW(error);
  12667. #endif
  12668. WFIFOSET(fd, packet_len(0x289));
  12669. }
  12670. void clif_cashshop_result( struct map_session_data *sd, uint16 item_id, uint16 result ){
  12671. WFIFOHEAD( sd->fd, 16 );
  12672. WFIFOW( sd->fd, 0 ) = 0x849;
  12673. WFIFOL( sd->fd, 2 ) = item_id;
  12674. WFIFOW( sd->fd, 6 ) = result;
  12675. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12676. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12677. WFIFOSET( sd->fd, 16 );
  12678. }
  12679. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12680. /// 0288 <name id>.W <amount>.W
  12681. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12682. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12683. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (PACKETVER >= 20130000)
  12684. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  12685. struct s_packet_db* info;
  12686. int cmd = RFIFOW(fd,0);
  12687. nullpo_retv(sd);
  12688. info = &packet_db[sd->packet_ver][cmd];
  12689. if( sd->state.trading || !sd->npc_shopid ) {
  12690. clif_cashshop_ack(sd,1);
  12691. return;
  12692. }
  12693. else {
  12694. #if PACKETVER < 20101116
  12695. short nameid = RFIFOW(fd,info->pos[0]);
  12696. short amount = RFIFOW(fd,info->pos[1]);
  12697. int points = RFIFOL(fd,info->pos[2]);
  12698. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  12699. #else
  12700. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12701. int len = RFIFOW(fd,info->pos[0]);
  12702. int points = RFIFOL(fd,info->pos[1]);
  12703. int count = RFIFOW(fd,info->pos[2]);
  12704. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12705. if( len < 10 || len != 10 + count * s_itl){
  12706. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12707. return;
  12708. }
  12709. if(cmd==0x848){
  12710. if (cashshop_buylist( sd, points, count, item_list))
  12711. clif_cashshop_ack(sd,0);
  12712. return;
  12713. } else {
  12714. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  12715. return;
  12716. }
  12717. #endif
  12718. }
  12719. }
  12720. /// Adoption System
  12721. ///
  12722. /// Adoption message (ZC_BABYMSG).
  12723. /// 0216 <msg>.L
  12724. /// msg:
  12725. /// 0 = "You cannot adopt more than 1 child."
  12726. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12727. /// 2 = "You cannot adopt a married person."
  12728. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12729. {
  12730. int fd = sd->fd;
  12731. WFIFOHEAD(fd,6);
  12732. WFIFOW(fd,0) = 0x216;
  12733. WFIFOL(fd,2) = type;
  12734. WFIFOSET(fd,6);
  12735. }
  12736. /// Adoption confirmation (ZC_REQ_BABY).
  12737. /// 01f6 <account id>.L <char id>.L <name>.B
  12738. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12739. {
  12740. int fd = sd->fd;
  12741. WFIFOHEAD(fd,34);
  12742. WFIFOW(fd,0) = 0x1f6;
  12743. WFIFOL(fd,2) = src->status.account_id;
  12744. WFIFOL(fd,6) = p_id;
  12745. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12746. WFIFOSET(fd,34);
  12747. }
  12748. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12749. /// 01f9 <account id>.L
  12750. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12751. {
  12752. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12753. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12754. if( pc_can_Adopt(sd, p_sd, tsd) )
  12755. {
  12756. tsd->adopt_invite = sd->status.account_id;
  12757. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12758. }
  12759. }
  12760. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12761. /// 01f7 <account id>.L <char id>.L <answer>.L
  12762. /// answer:
  12763. /// 0 = rejected
  12764. /// 1 = accepted
  12765. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12766. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12767. int p1_id = RFIFOL(fd,info->pos[0]);
  12768. int p2_id = RFIFOL(fd,info->pos[1]);
  12769. int result = RFIFOL(fd,info->pos[2]);
  12770. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12771. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12772. int pid = sd->adopt_invite;
  12773. sd->adopt_invite = 0;
  12774. if( p1_sd == NULL || p2_sd == NULL )
  12775. return; // Both players need to be online
  12776. if( pid != p1_sd->status.account_id )
  12777. return; // Incorrect values
  12778. if( result == 0 )
  12779. return; // Rejected
  12780. pc_adoption(p1_sd, p2_sd, sd);
  12781. }
  12782. /// Convex Mirror (ZC_BOSS_INFO).
  12783. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12784. /// infoType:
  12785. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12786. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12787. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12788. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12789. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12790. {
  12791. WFIFOHEAD(fd,70);
  12792. memset(WFIFOP(fd,0),0,70);
  12793. WFIFOW(fd,0) = 0x293;
  12794. if( md != NULL ) {
  12795. if( md->bl.prev != NULL ) { // Boss on This Map
  12796. if( flag ) {
  12797. WFIFOB(fd,2) = 1;
  12798. WFIFOL(fd,3) = md->bl.x;
  12799. WFIFOL(fd,7) = md->bl.y;
  12800. } else
  12801. WFIFOB(fd,2) = 2; // First Time
  12802. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12803. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12804. unsigned int seconds;
  12805. int hours, minutes;
  12806. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12807. hours = seconds / (60 * 60);
  12808. seconds = seconds - (60 * 60 * hours);
  12809. minutes = seconds / 60;
  12810. WFIFOB(fd,2) = 3;
  12811. WFIFOW(fd,11) = hours; // Hours
  12812. WFIFOW(fd,13) = minutes; // Minutes
  12813. }
  12814. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12815. }
  12816. WFIFOSET(fd,70);
  12817. }
  12818. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12819. /// 02d6 <account id>.L
  12820. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12821. {
  12822. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12823. struct map_session_data* tsd = map_id2sd(aid);
  12824. if (!tsd)
  12825. return;
  12826. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12827. clif_viewequip_ack(sd, tsd);
  12828. else
  12829. clif_msg(sd, VIEW_EQUIP_FAIL);
  12830. }
  12831. /// Request to change equip window tick (CZ_CONFIG).
  12832. /// 02d8 <type>.L <flag>.L
  12833. /// type:
  12834. /// 0 = open equip window
  12835. /// flag:
  12836. /// 0 = disabled
  12837. /// 1 = enabled
  12838. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12839. {
  12840. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12841. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12842. sd->status.show_equip = flag;
  12843. clif_equiptickack(sd, flag);
  12844. }
  12845. /// Questlog System [Kevin] [Inkfish]
  12846. ///
  12847. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12848. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12849. void clif_quest_send_list(struct map_session_data * sd)
  12850. {
  12851. int fd = sd->fd;
  12852. int i;
  12853. int len = sd->avail_quests*5+8;
  12854. WFIFOHEAD(fd,len);
  12855. WFIFOW(fd, 0) = 0x2b1;
  12856. WFIFOW(fd, 2) = len;
  12857. WFIFOL(fd, 4) = sd->avail_quests;
  12858. for( i = 0; i < sd->avail_quests; i++ ) {
  12859. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12860. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12861. }
  12862. WFIFOSET(fd, len);
  12863. }
  12864. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12865. /// 02b2 <packet len>.W <num>.L { <quest id>.L <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 }*num
  12866. void clif_quest_send_mission(struct map_session_data * sd)
  12867. {
  12868. int fd = sd->fd;
  12869. int i, j;
  12870. int len = sd->avail_quests*104+8;
  12871. struct mob_db *mob;
  12872. WFIFOHEAD(fd, len);
  12873. WFIFOW(fd, 0) = 0x2b2;
  12874. WFIFOW(fd, 2) = len;
  12875. WFIFOL(fd, 4) = sd->avail_quests;
  12876. for( i = 0; i < sd->avail_quests; i++ ) {
  12877. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12878. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12879. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12880. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12881. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ ) {
  12882. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12883. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12884. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12885. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12886. }
  12887. }
  12888. WFIFOSET(fd, len);
  12889. }
  12890. /// Notification about a new quest (ZC_ADD_QUEST).
  12891. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12892. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12893. {
  12894. int fd = sd->fd;
  12895. int i;
  12896. struct mob_db *mob;
  12897. WFIFOHEAD(fd, packet_len(0x2b3));
  12898. WFIFOW(fd, 0) = 0x2b3;
  12899. WFIFOL(fd, 2) = qd->quest_id;
  12900. WFIFOB(fd, 6) = qd->state;
  12901. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12902. WFIFOL(fd, 11) = qd->time;
  12903. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12904. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12905. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12906. WFIFOW(fd, i*30+21) = qd->count[i];
  12907. mob = mob_db(quest_db[index].mob[i]);
  12908. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12909. }
  12910. WFIFOSET(fd, packet_len(0x2b3));
  12911. }
  12912. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12913. /// 02b4 <quest id>.L
  12914. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12915. {
  12916. int fd = sd->fd;
  12917. WFIFOHEAD(fd, packet_len(0x2b4));
  12918. WFIFOW(fd, 0) = 0x2b4;
  12919. WFIFOL(fd, 2) = quest_id;
  12920. WFIFOSET(fd, packet_len(0x2b4));
  12921. }
  12922. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12923. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12924. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12925. {
  12926. int fd = sd->fd;
  12927. int i;
  12928. int len = quest_db[index].num_objectives*12+6;
  12929. WFIFOHEAD(fd, len);
  12930. WFIFOW(fd, 0) = 0x2b5;
  12931. WFIFOW(fd, 2) = len;
  12932. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12933. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12934. WFIFOL(fd, i*12+6) = qd->quest_id;
  12935. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12936. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12937. WFIFOW(fd, i*12+16) = qd->count[i];
  12938. }
  12939. WFIFOSET(fd, len);
  12940. }
  12941. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12942. /// 02b6 <quest id>.L <active>.B
  12943. void clif_parse_questStateAck(int fd, struct map_session_data * sd){
  12944. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12945. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  12946. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  12947. }
  12948. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12949. /// 02b7 <quest id>.L <active>.B
  12950. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12951. {
  12952. int fd = sd->fd;
  12953. WFIFOHEAD(fd, packet_len(0x2b7));
  12954. WFIFOW(fd, 0) = 0x2b7;
  12955. WFIFOL(fd, 2) = quest_id;
  12956. WFIFOB(fd, 6) = active;
  12957. WFIFOSET(fd, packet_len(0x2b7));
  12958. }
  12959. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12960. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12961. /// effect:
  12962. /// 0 = none
  12963. /// 1 = exclamation mark icon
  12964. /// 2 = question mark icon
  12965. /// type:
  12966. /// 0 = yellow
  12967. /// 1 = orange
  12968. /// 2 = green
  12969. /// 3 = purple
  12970. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12971. {
  12972. #if PACKETVER >= 20090218
  12973. int fd = sd->fd;
  12974. WFIFOHEAD(fd, packet_len(0x446));
  12975. WFIFOW(fd, 0) = 0x446;
  12976. WFIFOL(fd, 2) = bl->id;
  12977. WFIFOW(fd, 6) = bl->x;
  12978. WFIFOW(fd, 8) = bl->y;
  12979. WFIFOW(fd, 10) = state;
  12980. WFIFOW(fd, 12) = color;
  12981. WFIFOSET(fd, packet_len(0x446));
  12982. #endif
  12983. }
  12984. /// Mercenary System
  12985. ///
  12986. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12987. /// 02a2 <var id>.W <value>.L
  12988. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12989. {
  12990. struct mercenary_data *md;
  12991. struct status_data *status;
  12992. int fd;
  12993. if( sd == NULL || (md = sd->md) == NULL )
  12994. return;
  12995. fd = sd->fd;
  12996. status = &md->battle_status;
  12997. WFIFOHEAD(fd,packet_len(0x2a2));
  12998. WFIFOW(fd,0) = 0x2a2;
  12999. WFIFOW(fd,2) = type;
  13000. switch( type ) {
  13001. case SP_ATK1:
  13002. {
  13003. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13004. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13005. }
  13006. break;
  13007. case SP_MATK1:
  13008. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  13009. break;
  13010. case SP_HIT:
  13011. WFIFOL(fd,4) = status->hit;
  13012. break;
  13013. case SP_CRITICAL:
  13014. WFIFOL(fd,4) = status->cri/10;
  13015. break;
  13016. case SP_DEF1:
  13017. WFIFOL(fd,4) = status->def;
  13018. break;
  13019. case SP_MDEF1:
  13020. WFIFOL(fd,4) = status->mdef;
  13021. break;
  13022. case SP_MERCFLEE:
  13023. WFIFOL(fd,4) = status->flee;
  13024. break;
  13025. case SP_ASPD:
  13026. WFIFOL(fd,4) = status->amotion;
  13027. break;
  13028. case SP_HP:
  13029. WFIFOL(fd,4) = status->hp;
  13030. break;
  13031. case SP_MAXHP:
  13032. WFIFOL(fd,4) = status->max_hp;
  13033. break;
  13034. case SP_SP:
  13035. WFIFOL(fd,4) = status->sp;
  13036. break;
  13037. case SP_MAXSP:
  13038. WFIFOL(fd,4) = status->max_sp;
  13039. break;
  13040. case SP_MERCKILLS:
  13041. WFIFOL(fd,4) = md->mercenary.kill_count;
  13042. break;
  13043. case SP_MERCFAITH:
  13044. WFIFOL(fd,4) = mercenary_get_faith(md);
  13045. break;
  13046. }
  13047. WFIFOSET(fd,packet_len(0x2a2));
  13048. }
  13049. /// Mercenary base status data (ZC_MER_INIT).
  13050. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13051. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13052. /// <calls>.L <kills>.L <atk range>.W
  13053. void clif_mercenary_info(struct map_session_data *sd)
  13054. {
  13055. int fd;
  13056. struct mercenary_data *md;
  13057. struct status_data *status;
  13058. int atk;
  13059. if( sd == NULL || (md = sd->md) == NULL )
  13060. return;
  13061. fd = sd->fd;
  13062. status = &md->battle_status;
  13063. WFIFOHEAD(fd,packet_len(0x29b));
  13064. WFIFOW(fd,0) = 0x29b;
  13065. WFIFOL(fd,2) = md->bl.id;
  13066. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13067. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13068. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13069. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  13070. WFIFOW(fd,10) = status->hit;
  13071. WFIFOW(fd,12) = status->cri/10;
  13072. WFIFOW(fd,14) = status->def;
  13073. WFIFOW(fd,16) = status->mdef;
  13074. WFIFOW(fd,18) = status->flee;
  13075. WFIFOW(fd,20) = status->amotion;
  13076. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13077. WFIFOW(fd,46) = md->db->lv;
  13078. WFIFOL(fd,48) = status->hp;
  13079. WFIFOL(fd,52) = status->max_hp;
  13080. WFIFOL(fd,56) = status->sp;
  13081. WFIFOL(fd,60) = status->max_sp;
  13082. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13083. WFIFOW(fd,68) = mercenary_get_faith(md);
  13084. WFIFOL(fd,70) = mercenary_get_calls(md);
  13085. WFIFOL(fd,74) = md->mercenary.kill_count;
  13086. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13087. WFIFOSET(fd,packet_len(0x29b));
  13088. }
  13089. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13090. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13091. void clif_mercenary_skillblock(struct map_session_data *sd)
  13092. {
  13093. struct mercenary_data *md;
  13094. int fd, i, len = 4, id, j;
  13095. if( sd == NULL || (md = sd->md) == NULL )
  13096. return;
  13097. fd = sd->fd;
  13098. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13099. WFIFOW(fd,0) = 0x29d;
  13100. for( i = 0; i < MAX_MERCSKILL; i++ )
  13101. {
  13102. if( (id = md->db->skill[i].id) == 0 )
  13103. continue;
  13104. j = id - MC_SKILLBASE;
  13105. WFIFOW(fd,len) = id;
  13106. WFIFOL(fd,len+2) = skill_get_inf(id);
  13107. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13108. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13109. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13110. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13111. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13112. len += 37;
  13113. }
  13114. WFIFOW(fd,2) = len;
  13115. WFIFOSET(fd,len);
  13116. }
  13117. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13118. /// 029f <command>.B
  13119. /// 1 = mercenary information
  13120. /// 2 = delete
  13121. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13122. {
  13123. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13124. if( sd->md == NULL )
  13125. return;
  13126. if( option == 2 ) merc_delete(sd->md, 2);
  13127. }
  13128. /// Mercenary Message
  13129. /// message:
  13130. /// 0 = Mercenary soldier's duty hour is over.
  13131. /// 1 = Your mercenary soldier has been killed.
  13132. /// 2 = Your mercenary soldier has been fired.
  13133. /// 3 = Your mercenary soldier has ran away.
  13134. void clif_mercenary_message(struct map_session_data* sd, int message){
  13135. clif_msg(sd, MERC_MSG_BASE + message);
  13136. }
  13137. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13138. /// 0298 <name id>.W <seconds>.L
  13139. void clif_rental_time(int fd, int nameid, int seconds)
  13140. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13141. WFIFOHEAD(fd,packet_len(0x298));
  13142. WFIFOW(fd,0) = 0x298;
  13143. WFIFOW(fd,2) = nameid;
  13144. WFIFOL(fd,4) = seconds;
  13145. WFIFOSET(fd,packet_len(0x298));
  13146. }
  13147. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13148. /// 0299 <index>.W <name id>.W
  13149. void clif_rental_expired(int fd, int index, int nameid)
  13150. { // '<ItemName>' item has been deleted from the Inventory
  13151. WFIFOHEAD(fd,packet_len(0x299));
  13152. WFIFOW(fd,0) = 0x299;
  13153. WFIFOW(fd,2) = index+2;
  13154. WFIFOW(fd,4) = nameid;
  13155. WFIFOSET(fd,packet_len(0x299));
  13156. }
  13157. /// Book Reading (ZC_READ_BOOK).
  13158. /// 0294 <book id>.L <page>.L
  13159. void clif_readbook(int fd, int book_id, int page)
  13160. {
  13161. WFIFOHEAD(fd,packet_len(0x294));
  13162. WFIFOW(fd,0) = 0x294;
  13163. WFIFOL(fd,2) = book_id;
  13164. WFIFOL(fd,6) = page;
  13165. WFIFOSET(fd,packet_len(0x294));
  13166. }
  13167. /// Battlegrounds
  13168. ///
  13169. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13170. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13171. void clif_bg_hp(struct map_session_data *sd)
  13172. {
  13173. unsigned char buf[34];
  13174. const int cmd = 0x2e0;
  13175. nullpo_retv(sd);
  13176. WBUFW(buf,0) = cmd;
  13177. WBUFL(buf,2) = sd->status.account_id;
  13178. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13179. if( sd->battle_status.max_hp > INT16_MAX )
  13180. { // To correctly display the %hp bar. [Skotlex]
  13181. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13182. WBUFW(buf,32) = 100;
  13183. }
  13184. else
  13185. {
  13186. WBUFW(buf,30) = sd->battle_status.hp;
  13187. WBUFW(buf,32) = sd->battle_status.max_hp;
  13188. }
  13189. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13190. }
  13191. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13192. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13193. void clif_bg_xy(struct map_session_data *sd)
  13194. {
  13195. unsigned char buf[36];
  13196. nullpo_retv(sd);
  13197. WBUFW(buf,0)=0x2df;
  13198. WBUFL(buf,2)=sd->status.account_id;
  13199. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13200. WBUFW(buf,30)=sd->status.class_;
  13201. WBUFW(buf,32)=sd->bl.x;
  13202. WBUFW(buf,34)=sd->bl.y;
  13203. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13204. }
  13205. void clif_bg_xy_remove(struct map_session_data *sd)
  13206. {
  13207. unsigned char buf[36];
  13208. nullpo_retv(sd);
  13209. WBUFW(buf,0)=0x2df;
  13210. WBUFL(buf,2)=sd->status.account_id;
  13211. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13212. WBUFW(buf,30)=0;
  13213. WBUFW(buf,32)=-1;
  13214. WBUFW(buf,34)=-1;
  13215. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13216. }
  13217. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13218. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13219. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13220. {
  13221. struct map_session_data *sd;
  13222. unsigned char *buf;
  13223. if( (sd = bg_getavailablesd(bg)) == NULL )
  13224. return;
  13225. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13226. WBUFW(buf,0) = 0x2dc;
  13227. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13228. WBUFL(buf,4) = src_id;
  13229. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13230. memcpy(WBUFP(buf,32), mes, len);
  13231. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13232. if( buf )
  13233. aFree(buf);
  13234. }
  13235. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13236. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13237. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13238. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13239. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13240. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13241. char *name, *message;
  13242. int namelen, messagelen;
  13243. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13244. return;
  13245. if( is_atcommand(fd, sd, message, 1) )
  13246. return;
  13247. if (sd->sc.cant.chat)
  13248. return; //no "chatting" while muted.
  13249. if( battle_config.min_chat_delay ) {
  13250. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13251. return;
  13252. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13253. }
  13254. // Reset idle time when using battleground chat.
  13255. sd->idletime = last_tick;
  13256. bg_send_message(sd, text, textlen);
  13257. }
  13258. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13259. /// 02de <camp A points>.W <camp B points>.W
  13260. void clif_bg_updatescore(int16 m)
  13261. {
  13262. struct block_list bl;
  13263. unsigned char buf[6];
  13264. bl.id = 0;
  13265. bl.type = BL_NUL;
  13266. bl.m = m;
  13267. WBUFW(buf,0) = 0x2de;
  13268. WBUFW(buf,2) = map[m].bgscore_lion;
  13269. WBUFW(buf,4) = map[m].bgscore_eagle;
  13270. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13271. }
  13272. void clif_bg_updatescore_single(struct map_session_data *sd)
  13273. {
  13274. int fd;
  13275. nullpo_retv(sd);
  13276. fd = sd->fd;
  13277. WFIFOHEAD(fd,packet_len(0x2de));
  13278. WFIFOW(fd,0) = 0x2de;
  13279. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13280. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13281. WFIFOSET(fd,packet_len(0x2de));
  13282. }
  13283. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13284. /// 02dd <account id>.L <name>.24B <camp>.W
  13285. void clif_sendbgemblem_area(struct map_session_data *sd)
  13286. {
  13287. unsigned char buf[33];
  13288. nullpo_retv(sd);
  13289. WBUFW(buf, 0) = 0x2dd;
  13290. WBUFL(buf,2) = sd->bl.id;
  13291. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13292. WBUFW(buf,30) = sd->bg_id;
  13293. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13294. }
  13295. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13296. {
  13297. nullpo_retv(sd);
  13298. WFIFOHEAD(fd,32);
  13299. WFIFOW(fd,0) = 0x2dd;
  13300. WFIFOL(fd,2) = sd->bl.id;
  13301. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13302. WFIFOW(fd,30) = sd->bg_id;
  13303. WFIFOSET(fd,packet_len(0x2dd));
  13304. }
  13305. /// Custom Fonts (ZC_NOTIFY_FONT).
  13306. /// 02ef <account_id>.L <font id>.W
  13307. void clif_font(struct map_session_data *sd)
  13308. {
  13309. #if PACKETVER >= 20080102
  13310. unsigned char buf[8];
  13311. nullpo_retv(sd);
  13312. WBUFW(buf,0) = 0x2ef;
  13313. WBUFL(buf,2) = sd->bl.id;
  13314. WBUFW(buf,6) = sd->user_font;
  13315. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13316. #endif
  13317. }
  13318. /*==========================================
  13319. * Notifies party members of instance change
  13320. *------------------------------------------*/
  13321. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13322. {
  13323. #if PACKETVER >= 20071128
  13324. unsigned char buf[65];
  13325. if(!sd) return;
  13326. WBUFW(buf,0) = 0x2cb;
  13327. safestrncpy( WBUFP(buf,2), name, 62 );
  13328. WBUFW(buf,63) = num;
  13329. if(flag) // A timer has changed or been added
  13330. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13331. else // No notification
  13332. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13333. #endif
  13334. return;
  13335. }
  13336. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13337. {
  13338. #if PACKETVER >= 20071128
  13339. unsigned char buf[4];
  13340. if(!sd) return;
  13341. WBUFW(buf,0) = 0x2cc;
  13342. WBUFW(buf,2) = num;
  13343. if(flag) // A timer has changed or been added
  13344. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13345. else // No notification
  13346. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13347. #endif
  13348. return;
  13349. }
  13350. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13351. {
  13352. #if PACKETVER >= 20071128
  13353. unsigned char buf[71];
  13354. if(!sd) return; //party_getavailablesd can return NULL
  13355. WBUFW(buf,0) = 0x2cd;
  13356. safestrncpy( WBUFP(buf,2), name, 62 );
  13357. WBUFL(buf,63) = limit1;
  13358. WBUFL(buf,67) = limit2;
  13359. if(flag) // A timer has changed or been added
  13360. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13361. else // No notification
  13362. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13363. #endif
  13364. return;
  13365. }
  13366. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13367. {
  13368. #if PACKETVER >= 20071128
  13369. unsigned char buf[10];
  13370. if(!sd) return;
  13371. WBUFW(buf,0) = 0x2ce;
  13372. WBUFL(buf,2) = type;
  13373. WBUFL(buf,6) = limit;
  13374. if(flag) // A timer has changed or been added
  13375. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13376. else // No notification
  13377. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13378. #endif
  13379. return;
  13380. }
  13381. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13382. /// 02b8 <account id>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B
  13383. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13384. {
  13385. #if PACKETVER >= 20071002
  13386. unsigned char buf[22];
  13387. struct item_data* id = itemdb_search(item_data->nameid);
  13388. WBUFW(buf,0) = 0x2b8;
  13389. WBUFL(buf,2) = sd->status.account_id;
  13390. WBUFW(buf,6) = item_data->nameid;
  13391. WBUFB(buf,8) = item_data->identify;
  13392. WBUFB(buf,9) = item_data->attribute;
  13393. WBUFB(buf,10) = item_data->refine;
  13394. clif_addcards(WBUFP(buf,11), item_data);
  13395. WBUFW(buf,19) = id->equip; // equip location
  13396. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13397. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13398. #endif
  13399. }
  13400. /// Display gained exp (ZC_NOTIFY_EXP).
  13401. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13402. /// var id:
  13403. /// SP_BASEEXP, SP_JOBEXP
  13404. /// exp type:
  13405. /// 0 = normal exp gain/loss
  13406. /// 1 = quest exp gain/loss
  13407. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13408. {
  13409. int fd;
  13410. nullpo_retv(sd);
  13411. fd = sd->fd;
  13412. WFIFOHEAD(fd, packet_len(0x7f6));
  13413. WFIFOW(fd,0) = 0x7f6;
  13414. WFIFOL(fd,2) = sd->bl.id;
  13415. WFIFOL(fd,6) = exp;
  13416. WFIFOW(fd,10) = type;
  13417. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13418. WFIFOSET(fd,packet_len(0x7f6));
  13419. }
  13420. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13421. /// type:
  13422. /// 0 = Displays 'value' for 5 seconds.
  13423. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13424. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13425. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13426. /// value:
  13427. /// Except for type 3 it is interpreted as seconds for displaying as DD:HH:MM:SS, HH:MM:SS, MM:SS or SS (leftmost '00' is not displayed).
  13428. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13429. {
  13430. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13431. WFIFOW(sd->fd,0) = 0x1b1;
  13432. WFIFOB(sd->fd,2) = type;
  13433. WFIFOL(sd->fd,3) = value;
  13434. WFIFOSET(sd->fd, packet_len(0x1b1));
  13435. }
  13436. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13437. /// 021d <state>.L
  13438. /// state:
  13439. /// 0 = Full effects
  13440. /// 1 = Reduced effects
  13441. ///
  13442. /// NOTE: The state is used on Aegis for sending skill unit packet
  13443. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13444. /// whenever possible. Due to the way the decision check is
  13445. /// constructed, this state tracking was rendered useless,
  13446. /// as the only skill unit, that is sent with 0x1c9 is
  13447. /// Graffiti.
  13448. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13449. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13450. sd->state.lesseffect = ( isLess != 0 );
  13451. }
  13452. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13453. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13454. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13455. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13456. int type = RFIFOL(fd,info->pos[1]);
  13457. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13458. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13459. if( sd->state.trading || sd->npc_shopid )
  13460. return;
  13461. if( flag == 0 || n == 0) {
  13462. clif_menuskill_clear(sd);
  13463. return; // Canceled by player.
  13464. }
  13465. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13466. clif_menuskill_clear(sd);
  13467. return; // Prevent hacking.
  13468. }
  13469. switch( type ) {
  13470. case 0: // Change Material
  13471. skill_changematerial(sd,n,item_list);
  13472. break;
  13473. case 1: // Level 1: Pure to Rough
  13474. case 2: // Level 2: Rough to Pure
  13475. skill_elementalanalysis(sd,n,type,item_list);
  13476. break;
  13477. }
  13478. clif_menuskill_clear(sd);
  13479. return;
  13480. }
  13481. /*==========================================
  13482. * Elemental System
  13483. *==========================================*/
  13484. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13485. struct elemental_data *ed;
  13486. struct status_data *status;
  13487. int fd;
  13488. if( sd == NULL || (ed = sd->ed) == NULL )
  13489. return;
  13490. fd = sd->fd;
  13491. status = &ed->battle_status;
  13492. WFIFOHEAD(fd,8);
  13493. WFIFOW(fd,0) = 0x81e;
  13494. WFIFOW(fd,2) = type;
  13495. switch( type ) {
  13496. case SP_HP:
  13497. WFIFOL(fd,4) = status->hp;
  13498. break;
  13499. case SP_MAXHP:
  13500. WFIFOL(fd,4) = status->max_hp;
  13501. break;
  13502. case SP_SP:
  13503. WFIFOL(fd,4) = status->sp;
  13504. break;
  13505. case SP_MAXSP:
  13506. WFIFOL(fd,4) = status->max_sp;
  13507. break;
  13508. }
  13509. WFIFOSET(fd,8);
  13510. }
  13511. void clif_elemental_info(struct map_session_data *sd) {
  13512. int fd;
  13513. struct elemental_data *ed;
  13514. struct status_data *status;
  13515. if( sd == NULL || (ed = sd->ed) == NULL )
  13516. return;
  13517. fd = sd->fd;
  13518. status = &ed->battle_status;
  13519. WFIFOHEAD(fd,22);
  13520. WFIFOW(fd, 0) = 0x81d;
  13521. WFIFOL(fd, 2) = ed->bl.id;
  13522. WFIFOL(fd, 6) = status->hp;
  13523. WFIFOL(fd,10) = status->max_hp;
  13524. WFIFOL(fd,14) = status->sp;
  13525. WFIFOL(fd,18) = status->max_sp;
  13526. WFIFOSET(fd,22);
  13527. }
  13528. /// Buying Store System
  13529. ///
  13530. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13531. /// 0810 <slots>.B
  13532. void clif_buyingstore_open(struct map_session_data* sd)
  13533. {
  13534. int fd = sd->fd;
  13535. WFIFOHEAD(fd,packet_len(0x810));
  13536. WFIFOW(fd,0) = 0x810;
  13537. WFIFOB(fd,2) = sd->buyingstore.slots;
  13538. WFIFOSET(fd,packet_len(0x810));
  13539. }
  13540. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13541. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13542. /// result:
  13543. /// 0 = cancel
  13544. /// 1 = open
  13545. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13546. {
  13547. const unsigned int blocksize = 8;
  13548. uint8* itemlist;
  13549. char storename[MESSAGE_SIZE];
  13550. unsigned char result;
  13551. int zenylimit;
  13552. unsigned int count, packet_len;
  13553. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13554. packet_len = RFIFOW(fd,info->pos[0]);
  13555. // TODO: Make this check global for all variable length packets.
  13556. if( packet_len < 89 )
  13557. {// minimum packet length
  13558. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13559. return;
  13560. }
  13561. zenylimit = RFIFOL(fd,info->pos[1]);
  13562. result = RFIFOL(fd,info->pos[2]);
  13563. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13564. itemlist = RFIFOP(fd,info->pos[4]);
  13565. // so that buyingstore_create knows, how many elements it has access to
  13566. packet_len-= info->pos[4];
  13567. if( packet_len%blocksize )
  13568. {
  13569. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13570. return;
  13571. }
  13572. count = packet_len/blocksize;
  13573. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13574. }
  13575. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13576. /// 0812 <result>.W <total weight>.L
  13577. /// result:
  13578. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13579. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13580. /// 8 = "No sale (purchase) information available." (0x705)
  13581. /// ? = nothing
  13582. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13583. {
  13584. int fd = sd->fd;
  13585. WFIFOHEAD(fd,packet_len(0x812));
  13586. WFIFOW(fd,0) = 0x812;
  13587. WFIFOW(fd,2) = result;
  13588. WFIFOL(fd,4) = weight;
  13589. WFIFOSET(fd,packet_len(0x812));
  13590. }
  13591. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13592. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13593. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13594. {
  13595. int fd = sd->fd;
  13596. unsigned int i;
  13597. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13598. WFIFOW(fd,0) = 0x813;
  13599. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13600. WFIFOL(fd,4) = sd->bl.id;
  13601. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13602. for( i = 0; i < sd->buyingstore.slots; i++ )
  13603. {
  13604. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13605. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13606. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13607. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13608. }
  13609. WFIFOSET(fd,WFIFOW(fd,2));
  13610. }
  13611. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13612. /// 0814 <account id>.L <store name>.80B
  13613. void clif_buyingstore_entry(struct map_session_data* sd)
  13614. {
  13615. uint8 buf[86];
  13616. WBUFW(buf,0) = 0x814;
  13617. WBUFL(buf,2) = sd->bl.id;
  13618. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13619. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13620. }
  13621. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13622. {
  13623. int fd = sd->fd;
  13624. WFIFOHEAD(fd,packet_len(0x814));
  13625. WFIFOW(fd,0) = 0x814;
  13626. WFIFOL(fd,2) = pl_sd->bl.id;
  13627. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13628. WFIFOSET(fd,packet_len(0x814));
  13629. }
  13630. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13631. /// 0815
  13632. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13633. {
  13634. buyingstore_close(sd);
  13635. }
  13636. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13637. /// 0816 <account id>.L
  13638. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13639. {
  13640. uint8 buf[6];
  13641. WBUFW(buf,0) = 0x816;
  13642. WBUFL(buf,2) = sd->bl.id;
  13643. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13644. }
  13645. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13646. {
  13647. int fd = sd->fd;
  13648. WFIFOHEAD(fd,packet_len(0x816));
  13649. WFIFOW(fd,0) = 0x816;
  13650. WFIFOL(fd,2) = pl_sd->bl.id;
  13651. WFIFOSET(fd,packet_len(0x816));
  13652. }
  13653. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13654. /// 0817 <account id>.L
  13655. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13656. {
  13657. int account_id;
  13658. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13659. buyingstore_open(sd, account_id);
  13660. }
  13661. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13662. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13663. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13664. {
  13665. int fd = sd->fd;
  13666. unsigned int i;
  13667. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13668. WFIFOW(fd,0) = 0x818;
  13669. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13670. WFIFOL(fd,4) = pl_sd->bl.id;
  13671. WFIFOL(fd,8) = pl_sd->buyer_id;
  13672. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13673. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13674. {
  13675. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13676. WFIFOW(fd,20+i*9) = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  13677. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  13678. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13679. }
  13680. WFIFOSET(fd,WFIFOW(fd,2));
  13681. }
  13682. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13683. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13684. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13685. {
  13686. const unsigned int blocksize = 6;
  13687. uint8* itemlist;
  13688. int account_id;
  13689. unsigned int count, packet_len, buyer_id;
  13690. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13691. packet_len = RFIFOW(fd,info->pos[0]);
  13692. if( packet_len < 12 )
  13693. {// minimum packet length
  13694. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13695. return;
  13696. }
  13697. account_id = RFIFOL(fd,info->pos[1]);
  13698. buyer_id = RFIFOL(fd,info->pos[2]);
  13699. itemlist = RFIFOP(fd,info->pos[3]);
  13700. // so that buyingstore_trade knows, how many elements it has access to
  13701. packet_len-= info->pos[3];
  13702. if( packet_len%blocksize )
  13703. {
  13704. ShowError("clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%d, block size=%u)\n", packet_len, sd->bl.id, account_id, blocksize);
  13705. return;
  13706. }
  13707. count = packet_len/blocksize;
  13708. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13709. }
  13710. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13711. /// 081a <result>.W
  13712. /// result:
  13713. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13714. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13715. /// ? = nothing
  13716. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13717. {
  13718. int fd = sd->fd;
  13719. WFIFOHEAD(fd,packet_len(0x81a));
  13720. WFIFOW(fd,0) = 0x81a;
  13721. WFIFOW(fd,2) = result;
  13722. WFIFOSET(fd,packet_len(0x81a));
  13723. }
  13724. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13725. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13726. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13727. {
  13728. int fd = sd->fd;
  13729. WFIFOHEAD(fd,packet_len(0x81b));
  13730. WFIFOW(fd,0) = 0x81b;
  13731. WFIFOW(fd,2) = nameid;
  13732. WFIFOW(fd,4) = amount; // amount of nameid received
  13733. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13734. WFIFOSET(fd,packet_len(0x81b));
  13735. }
  13736. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13737. /// 081c <index>.W <amount>.W <price>.L
  13738. /// message:
  13739. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13740. ///
  13741. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13742. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13743. {
  13744. int fd = sd->fd;
  13745. WFIFOHEAD(fd,packet_len(0x81c));
  13746. WFIFOW(fd,0) = 0x81c;
  13747. WFIFOW(fd,2) = index+2;
  13748. WFIFOW(fd,4) = amount;
  13749. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13750. WFIFOSET(fd,packet_len(0x81c));
  13751. }
  13752. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13753. /// 0824 <result>.W <name id>.W
  13754. /// result:
  13755. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13756. /// 6 = "The trade failed, because the entered amount of item %s is higher, than the buyer is willing to buy." (0x6d3, MSI_BUYINGSTORE_TRADE_OVERCOUNT)
  13757. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13758. /// ? = nothing
  13759. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13760. {
  13761. int fd = sd->fd;
  13762. WFIFOHEAD(fd,packet_len(0x824));
  13763. WFIFOW(fd,0) = 0x824;
  13764. WFIFOW(fd,2) = result;
  13765. WFIFOW(fd,4) = nameid;
  13766. WFIFOSET(fd,packet_len(0x824));
  13767. }
  13768. /// Search Store Info System
  13769. ///
  13770. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13771. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13772. /// type:
  13773. /// 0 = Vending
  13774. /// 1 = Buying Store
  13775. ///
  13776. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13777. /// amount of card slots. If the client does not know about the item it
  13778. /// cannot be searched.
  13779. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13780. {
  13781. const unsigned int blocksize = 2;
  13782. const uint8* itemlist;
  13783. const uint8* cardlist;
  13784. unsigned char type;
  13785. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13786. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13787. packet_len = RFIFOW(fd,info->pos[0]);
  13788. if( packet_len < 15 )
  13789. {// minimum packet length
  13790. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13791. return;
  13792. }
  13793. type = RFIFOB(fd,info->pos[1]);
  13794. max_price = RFIFOL(fd,info->pos[2]);
  13795. min_price = RFIFOL(fd,info->pos[3]);
  13796. item_count = RFIFOB(fd,info->pos[4]);
  13797. card_count = RFIFOB(fd,info->pos[5]);
  13798. itemlist = RFIFOP(fd,info->pos[6]);
  13799. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13800. // check, if there is enough data for the claimed count of items
  13801. packet_len-= info->pos[6];
  13802. if( packet_len%blocksize )
  13803. {
  13804. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13805. return;
  13806. }
  13807. count = packet_len/blocksize;
  13808. if( count < item_count+card_count )
  13809. {
  13810. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13811. return;
  13812. }
  13813. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13814. }
  13815. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13816. /// 0836 <packet len>.W <is first page>.B <is next page>.B <remaining uses>.B { <store id>.L <account id>.L <shop name>.80B <nameid>.W <item type>.B <price>.L <amount>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  13817. /// is first page:
  13818. /// 0 = appends to existing results
  13819. /// 1 = clears previous results before displaying this result set
  13820. /// is next page:
  13821. /// 0 = no "next" label
  13822. /// 1 = "next" label to retrieve more results
  13823. void clif_search_store_info_ack(struct map_session_data* sd)
  13824. {
  13825. const unsigned int blocksize = MESSAGE_SIZE+26;
  13826. int fd = sd->fd;
  13827. unsigned int i, start, end;
  13828. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13829. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13830. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13831. WFIFOW(fd,0) = 0x836;
  13832. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13833. WFIFOB(fd,4) = !sd->searchstore.pages;
  13834. WFIFOB(fd,5) = searchstore_querynext(sd);
  13835. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13836. for( i = start; i < end; i++ ) {
  13837. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13838. struct item it;
  13839. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13840. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13841. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13842. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13843. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  13844. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13845. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13846. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13847. // make-up an item for clif_addcards
  13848. memset(&it, 0, sizeof(it));
  13849. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13850. it.nameid = ssitem->nameid;
  13851. it.amount = ssitem->amount;
  13852. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13853. }
  13854. WFIFOSET(fd,WFIFOW(fd,2));
  13855. }
  13856. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13857. /// 0837 <reason>.B
  13858. /// reason:
  13859. /// 0 = "No matching stores were found." (0x70b)
  13860. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13861. /// 2 = "You cannot search anymore." (0x706)
  13862. /// 3 = "You cannot search yet." (0x708)
  13863. /// 4 = "No sale (purchase) information available." (0x705)
  13864. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13865. {
  13866. int fd = sd->fd;
  13867. WFIFOHEAD(fd,packet_len(0x837));
  13868. WFIFOW(fd,0) = 0x837;
  13869. WFIFOB(fd,2) = reason;
  13870. WFIFOSET(fd,packet_len(0x837));
  13871. }
  13872. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13873. /// 0838
  13874. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13875. {
  13876. searchstore_next(sd);
  13877. }
  13878. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13879. /// 083a <type>.W <remaining uses>.B
  13880. /// type:
  13881. /// 0 = Search Stores
  13882. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13883. void clif_open_search_store_info(struct map_session_data* sd)
  13884. {
  13885. int fd = sd->fd;
  13886. WFIFOHEAD(fd,packet_len(0x83a));
  13887. WFIFOW(fd,0) = 0x83a;
  13888. WFIFOW(fd,2) = sd->searchstore.effect;
  13889. #if PACKETVER > 20100701
  13890. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13891. #endif
  13892. WFIFOSET(fd,packet_len(0x83a));
  13893. }
  13894. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13895. /// 083b
  13896. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13897. {
  13898. searchstore_close(sd);
  13899. }
  13900. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13901. /// 083c <account id>.L <store id>.L <nameid>.W
  13902. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13903. {
  13904. unsigned short nameid;
  13905. int account_id, store_id;
  13906. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13907. account_id = RFIFOL(fd,info->pos[0]);
  13908. store_id = RFIFOL(fd,info->pos[1]);
  13909. nameid = RFIFOW(fd,info->pos[2]);
  13910. searchstore_click(sd, account_id, store_id, nameid);
  13911. }
  13912. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13913. /// 083d <xPos>.W <yPos>.W
  13914. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13915. {
  13916. int fd = sd->fd;
  13917. WFIFOHEAD(fd,packet_len(0x83d));
  13918. WFIFOW(fd,0) = 0x83d;
  13919. WFIFOW(fd,2) = x;
  13920. WFIFOW(fd,4) = y;
  13921. WFIFOSET(fd,packet_len(0x83d));
  13922. }
  13923. /// Parse function for packet debugging.
  13924. void clif_parse_debug(int fd,struct map_session_data *sd)
  13925. {
  13926. int cmd, packet_len;
  13927. // clif_parse ensures, that there is at least 2 bytes of data
  13928. cmd = RFIFOW(fd,0);
  13929. if( sd ) {
  13930. packet_len = packet_db[sd->packet_ver][cmd].len;
  13931. if( packet_len == 0 )
  13932. {// unknown
  13933. packet_len = RFIFOREST(fd);
  13934. }
  13935. else if( packet_len == -1 )
  13936. {// variable length
  13937. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13938. }
  13939. ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  13940. }
  13941. else
  13942. {
  13943. packet_len = RFIFOREST(fd);
  13944. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13945. }
  13946. ShowDump(RFIFOP(fd,0), packet_len);
  13947. }
  13948. /*==========================================
  13949. * Server tells client to display a window similar to Magnifier (item) one
  13950. * Server populates the window with avilable elemental converter options according to player's inventory
  13951. *------------------------------------------*/
  13952. int clif_elementalconverter_list(struct map_session_data *sd) {
  13953. int i,c,view,fd;
  13954. nullpo_ret(sd);
  13955. /// Main client packet processing function
  13956. fd=sd->fd;
  13957. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13958. WFIFOW(fd, 0)=0x1ad;
  13959. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13960. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13961. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13962. WFIFOW(fd,c*2+ 4)= view;
  13963. else
  13964. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13965. c++;
  13966. }
  13967. }
  13968. WFIFOW(fd,2) = c*2+4;
  13969. WFIFOSET(fd, WFIFOW(fd,2));
  13970. if (c > 0) {
  13971. sd->menuskill_id = SA_CREATECON;
  13972. sd->menuskill_val = c;
  13973. }
  13974. return 0;
  13975. }
  13976. /**
  13977. * Rune Knight
  13978. **/
  13979. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13980. #if PACKETVER >= 20081217
  13981. unsigned char buf[10];
  13982. WBUFW(buf,0) = 0x440;
  13983. WBUFL(buf,2) = sd->bl.id;
  13984. WBUFW(buf,6) = shields;
  13985. WBUFW(buf,8) = 0;
  13986. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13987. #endif
  13988. }
  13989. /**
  13990. * Warlock
  13991. **/
  13992. /*==========================================
  13993. * Spellbook list [LimitLine/3CeAM]
  13994. *------------------------------------------*/
  13995. int clif_spellbook_list(struct map_session_data *sd)
  13996. {
  13997. int i, c;
  13998. int fd;
  13999. nullpo_ret(sd);
  14000. fd = sd->fd;
  14001. WFIFOHEAD(fd, 8 * 8 + 8);
  14002. WFIFOW(fd,0) = 0x1ad;
  14003. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14004. {
  14005. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  14006. {
  14007. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14008. c ++;
  14009. }
  14010. }
  14011. if( c > 0 )
  14012. {
  14013. WFIFOW(fd,2) = c * 2 + 4;
  14014. WFIFOSET(fd, WFIFOW(fd, 2));
  14015. sd->menuskill_id = WL_READING_SB;
  14016. sd->menuskill_val = c;
  14017. }
  14018. else{
  14019. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14020. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14021. }
  14022. return 1;
  14023. }
  14024. /**
  14025. * Mechanic
  14026. **/
  14027. /*==========================================
  14028. * Magic Decoy Material List
  14029. *------------------------------------------*/
  14030. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14031. int i, c;
  14032. int fd;
  14033. nullpo_ret(sd);
  14034. fd = sd->fd;
  14035. WFIFOHEAD(fd, 8 * 8 + 8);
  14036. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14037. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14038. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14039. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14040. c ++;
  14041. }
  14042. }
  14043. if( c > 0 ) {
  14044. sd->menuskill_id = NC_MAGICDECOY;
  14045. sd->menuskill_val = skill_lv;
  14046. sd->sc.comet_x = x;
  14047. sd->sc.comet_y = y;
  14048. WFIFOW(fd,2) = c * 2 + 4;
  14049. WFIFOSET(fd, WFIFOW(fd, 2));
  14050. } else {
  14051. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14052. return 0;
  14053. }
  14054. return 1;
  14055. }
  14056. /*==========================================
  14057. * Guillotine Cross Poisons List
  14058. *------------------------------------------*/
  14059. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14060. int i, c;
  14061. int fd;
  14062. nullpo_ret(sd);
  14063. fd = sd->fd;
  14064. WFIFOHEAD(fd, 8 * 8 + 8);
  14065. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14066. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14067. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14068. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14069. c ++;
  14070. }
  14071. }
  14072. if( c > 0 ) {
  14073. sd->menuskill_id = GC_POISONINGWEAPON;
  14074. sd->menuskill_val = skill_lv;
  14075. WFIFOW(fd,2) = c * 2 + 4;
  14076. WFIFOSET(fd, WFIFOW(fd, 2));
  14077. } else {
  14078. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14079. return 0;
  14080. }
  14081. return 1;
  14082. }
  14083. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14084. int fd, i, c;
  14085. nullpo_ret(sd);
  14086. fd = sd->fd;
  14087. if( !fd ) return 0;
  14088. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14089. return 0;
  14090. WFIFOHEAD(fd, 2 * 6 + 4);
  14091. WFIFOW(fd,0) = 0x442;
  14092. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14093. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14094. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14095. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14096. {
  14097. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14098. c++;
  14099. }
  14100. if( c > 0 ) {
  14101. WFIFOW(fd,2) = 8 + c * 2;
  14102. WFIFOL(fd,4) = c;
  14103. WFIFOSET(fd,WFIFOW(fd,2));
  14104. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14105. sd->menuskill_val = c;
  14106. } else {
  14107. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14108. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14109. }
  14110. return 1;
  14111. }
  14112. /*===========================================
  14113. * Skill list for Four Elemental Analysis
  14114. * and Change Material skills.
  14115. *------------------------------------------*/
  14116. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14117. {
  14118. #if PACKETVER >= 20090922
  14119. int fd;
  14120. nullpo_ret(sd);
  14121. sd->menuskill_id = skill_id; // To prevent hacking.
  14122. sd->menuskill_val = skill_lv;
  14123. if( skill_id == GN_CHANGEMATERIAL )
  14124. skill_lv = 0; // Changematerial
  14125. fd = sd->fd;
  14126. WFIFOHEAD(fd,packet_len(0x7e3));
  14127. WFIFOW(fd,0) = 0x7e3;
  14128. WFIFOL(fd,2) = skill_lv;
  14129. WFIFOL(fd,4) = 0;
  14130. WFIFOSET(fd,packet_len(0x7e3));
  14131. #endif
  14132. return 1;
  14133. }
  14134. /**
  14135. * Sends a new status without a tick (currently used by the new mounts)
  14136. **/
  14137. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  14138. unsigned char buf[32];
  14139. nullpo_ret(bl);
  14140. WBUFW(buf,0)=0x043f;
  14141. WBUFW(buf,2)=type;
  14142. WBUFL(buf,4)=bl->id;
  14143. WBUFB(buf,8)=flag;
  14144. WBUFL(buf,9) = 0;
  14145. WBUFL(buf,13) = val1;
  14146. WBUFL(buf,17) = val2;
  14147. WBUFL(buf,21) = val3;
  14148. clif_send(buf,packet_len(0x043f),bl,AREA);
  14149. return 0;
  14150. }
  14151. //Notifies FD of ID's type
  14152. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  14153. WFIFOHEAD(fd, packet_len(0x043f));
  14154. WFIFOW(fd,0)=0x043f;
  14155. WFIFOW(fd,2)=type;
  14156. WFIFOL(fd,4)=id;
  14157. WFIFOB(fd,8)=flag;
  14158. WFIFOL(fd,9) = 0;
  14159. WFIFOL(fd,13) = val1;
  14160. WFIFOL(fd,17) = val2;
  14161. WFIFOL(fd,21) = val3;
  14162. WFIFOSET(fd, packet_len(0x043f));
  14163. return 0;
  14164. }
  14165. // msgstringtable.txt
  14166. // 0x291 <line>.W
  14167. void clif_msgtable(int fd, int line) {
  14168. WFIFOHEAD(fd, packet_len(0x291));
  14169. WFIFOW(fd, 0) = 0x291;
  14170. WFIFOW(fd, 2) = line;
  14171. WFIFOSET(fd, packet_len(0x291));
  14172. }
  14173. // msgstringtable.txt
  14174. // 0x7e2 <line>.W <value>.L
  14175. void clif_msgtable_num(int fd, int line, int num) {
  14176. #if PACKETVER >= 20090805
  14177. WFIFOHEAD(fd, packet_len(0x7e2));
  14178. WFIFOW(fd, 0) = 0x7e2;
  14179. WFIFOW(fd, 2) = line;
  14180. WFIFOL(fd, 4) = num;
  14181. WFIFOSET(fd, packet_len(0x7e2));
  14182. #endif
  14183. }
  14184. /*==========================================
  14185. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14186. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14187. * RFIFOL(fd,2) - type (currently not used)
  14188. *------------------------------------------*/
  14189. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14190. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14191. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14192. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14193. return;
  14194. if( pc_istrading(sd) ) {
  14195. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14196. clif_menuskill_clear(sd);
  14197. return;
  14198. }
  14199. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14200. clif_menuskill_clear(sd);
  14201. }
  14202. /*==========================================
  14203. * Kagerou/Oboro amulet spirit
  14204. *------------------------------------------*/
  14205. void clif_talisman(struct map_session_data *sd,short type)
  14206. {
  14207. unsigned char buf[10];
  14208. nullpo_retv(sd);
  14209. WBUFW(buf,0)=0x08cf;
  14210. WBUFL(buf,2)=sd->bl.id;
  14211. WBUFW(buf,6)=type;
  14212. WBUFW(buf,8)=sd->talisman[type];
  14213. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14214. }
  14215. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14216. /// 0907 <index>.W
  14217. ///
  14218. /// R 0908 <index>.w <type>.b
  14219. /// type:
  14220. /// 0 = move item to personal tab
  14221. /// 1 = move item to normal tab
  14222. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14223. #if PACKETVER >= 20111122
  14224. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14225. int index = RFIFOW(fd,info->pos[0])-2;
  14226. int type = RFIFOB(fd, info->pos[1]);
  14227. /* can't move while dead. */
  14228. if(pc_isdead(sd)) {
  14229. return;
  14230. }
  14231. if (index < 0 || index >= MAX_INVENTORY)
  14232. return;
  14233. if ( sd->status.inventory[index].favorite && type == 1 )
  14234. sd->status.inventory[index].favorite = 0;
  14235. else if( type == 0 )
  14236. sd->status.inventory[index].favorite = 1;
  14237. else
  14238. return;/* nothing to do. */
  14239. clif_favorite_item(sd, index);
  14240. #endif
  14241. }
  14242. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14243. /// 0900 <index>.W <favorite>.B
  14244. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14245. int fd = sd->fd;
  14246. WFIFOHEAD(fd,packet_len(0x908));
  14247. WFIFOW(fd,0) = 0x908;
  14248. WFIFOW(fd,2) = index+2;
  14249. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14250. WFIFOSET(fd,packet_len(0x908));
  14251. }
  14252. void clif_snap( struct block_list *bl, short x, short y ) {
  14253. unsigned char buf[10];
  14254. WBUFW(buf,0) = 0x8d2;
  14255. WBUFL(buf,2) = bl->id;
  14256. WBUFW(buf,6) = x;
  14257. WBUFW(buf,8) = y;
  14258. clif_send(buf,packet_len(0x8d2),bl,AREA);
  14259. }
  14260. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14261. #if PACKETVER >= 20120404
  14262. WFIFOHEAD(fd,packet_len(0x977));
  14263. WFIFOW(fd,0) = 0x977;
  14264. WFIFOL(fd,2) = md->bl.id;
  14265. WFIFOL(fd,6) = md->status.hp;
  14266. WFIFOL(fd,10) = md->status.max_hp;
  14267. WFIFOSET(fd,packet_len(0x977));
  14268. #endif
  14269. }
  14270. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14271. /// 0979 <world name>.24B <char name>.24B
  14272. void clif_ackworldinfo(struct map_session_data* sd) {
  14273. int fd;
  14274. nullpo_retv(sd);
  14275. fd = sd->fd;
  14276. WFIFOHEAD(fd,packet_len(0x979));
  14277. WFIFOW(fd,0)=0x979;
  14278. //AID -> world name ?
  14279. safestrncpy((char*)WFIFOP(fd,2), '\0' /* World name */, 24);
  14280. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14281. WFIFOSET(fd,packet_len(0x979));
  14282. }
  14283. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14284. /// 0978 <AID>.L
  14285. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14286. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14287. if(sd) clif_ackworldinfo(sd);
  14288. }
  14289. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14290. /// 0447
  14291. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14292. //if(sd)
  14293. ;
  14294. }
  14295. /// req world info (CZ_CLIENT_VERSION)
  14296. /// 044A <version>.L
  14297. void clif_parse_client_version(int fd,struct map_session_data *sd){
  14298. //if(sd)
  14299. ;
  14300. }
  14301. /// Ranking list
  14302. /// ranking pointlist { <name>.24B <point>.L }*10
  14303. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14304. const char* name;
  14305. struct fame_list* list;
  14306. int i, skip=0;
  14307. switch(rankingtype+1) //to keep the same case as char.c
  14308. {
  14309. case 1: list = smith_fame_list; break;
  14310. case 2: list = chemist_fame_list; break;
  14311. case 3: list = taekwon_fame_list; break;
  14312. default: skip=1; break;
  14313. }
  14314. if(!skip){
  14315. //Packet size limits this list to 10 elements. [Skotlex]
  14316. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14317. if (list[i].id > 0) {
  14318. if (strcmp(list[i].name, "-") == 0 &&
  14319. (name = map_charid2nick(list[i].id)) != NULL)
  14320. {
  14321. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14322. } else {
  14323. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14324. }
  14325. } else {
  14326. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14327. }
  14328. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14329. }
  14330. for(;i < 10; i++) { //In case the MAX is less than 10.
  14331. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14332. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14333. }
  14334. }
  14335. }
  14336. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14337. void clif_ranklist(struct map_session_data *sd, int16 rankingType){
  14338. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14339. int mypoint=0;
  14340. WBUFW(buf,0) = 0x97d;
  14341. WBUFW(buf,2) = rankingType;
  14342. clif_sub_ranklist(buf,4,sd,rankingType);
  14343. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14344. case MAPID_BLACKSMITH:
  14345. case MAPID_ALCHEMIST:
  14346. case MAPID_TAEKWON:
  14347. mypoint = sd->status.fame;
  14348. }
  14349. WBUFL(buf,284) = mypoint; //mypoint
  14350. clif_send(buf, 288, &sd->bl, SELF);
  14351. }
  14352. /*
  14353. * 097c <type> (CZ_REQ_RANKING)
  14354. * type
  14355. * 0: /blacksmith
  14356. * 1: /alchemist
  14357. * 2: /taekwon
  14358. * 3: /pk
  14359. * */
  14360. void clif_parse_ranklist(int fd,struct map_session_data *sd){
  14361. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14362. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14363. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14364. }
  14365. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14366. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point){
  14367. #if PACKETVER < 20130710
  14368. switch(rankingtype){
  14369. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14370. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14371. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14372. }
  14373. #else
  14374. int fd=sd->fd;
  14375. WFIFOHEAD(fd,14);
  14376. WFIFOW(fd,0) = 0x97e;
  14377. WFIFOW(fd,2) = rankingtype;
  14378. WFIFOL(fd,4) = point;
  14379. WFIFOL(fd,8) = sd->status.fame;
  14380. WFIFOSET(fd,12);
  14381. #endif
  14382. }
  14383. /**
  14384. * Transmit personal information to player. (rates)
  14385. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14386. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14387. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14388. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14389. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14390. * FIXME!
  14391. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14392. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14393. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14394. */
  14395. #ifdef VIP_ENABLE
  14396. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14397. if (sd) {
  14398. struct s_packet_db* info;
  14399. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14400. int cmd = 0, fd, i = 0;
  14401. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14402. int details_bexp[PINFO_MAX];
  14403. int details_drop[PINFO_MAX];
  14404. int details_penalty[PINFO_MAX];
  14405. int penalty_const;
  14406. /**
  14407. * Set for EXP
  14408. */
  14409. //0:PCRoom
  14410. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14411. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14412. details_bexp[0] = 0;
  14413. else {
  14414. if (details_bexp[0] < 100) {
  14415. details_bexp[0] = 100 - details_bexp[0];
  14416. details_bexp[0] = 0 - details_bexp[0];
  14417. }
  14418. else
  14419. details_bexp[0] = details_bexp[0] - 100;
  14420. }
  14421. //1:Premium
  14422. if (pc_isvip(sd)) {
  14423. details_bexp[1] = battle_config.vip_base_exp_increase;
  14424. if (details_bexp[1] < 0)
  14425. details_bexp[1] = 0 - details_bexp[1];
  14426. }
  14427. else
  14428. details_bexp[1] = 0;
  14429. //2:Server
  14430. details_bexp[2] = battle_config.base_exp_rate;
  14431. if (details_bexp[2] == 100)
  14432. details_bexp[2] = 0;
  14433. else {
  14434. if (details_bexp[2] < 100) {
  14435. details_bexp[2] = 100 - details_bexp[2];
  14436. details_bexp[2] = 0 - details_bexp[2];
  14437. }
  14438. else
  14439. details_bexp[2] = details_bexp[2] - 100;
  14440. }
  14441. //3:TPLUS
  14442. details_bexp[3] = 0;
  14443. /* End - EXP set*/
  14444. /**
  14445. * Set for Drop rate
  14446. */
  14447. //0:PCRoom
  14448. details_drop[0] = 0;
  14449. //1:Premium
  14450. details_drop[1] = battle_config.vip_drop_increase;
  14451. if (pc_isvip(sd)) {
  14452. if (details_drop[1] < 0)
  14453. details_drop[1] = 0 - details_drop[1];
  14454. }
  14455. else
  14456. details_drop[1] = 0;
  14457. //2:Server
  14458. details_drop[2] = battle_config.item_rate_common;
  14459. if (details_drop[2] == 100)
  14460. details_drop[2] = 0;
  14461. else {
  14462. if (details_drop[2] < 100) {
  14463. details_drop[2] = 100 - details_drop[2];
  14464. details_drop[2] = 0 - details_drop[2];
  14465. }
  14466. else
  14467. details_drop[2] = details_drop[2] - 100;
  14468. }
  14469. //3:TPLUS
  14470. details_drop[3] = 0;
  14471. /* End - Drop set*/
  14472. /**
  14473. * Set for Penalty rate
  14474. */
  14475. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14476. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14477. //0:PCRoom
  14478. details_penalty[0] = 0;
  14479. //1:Premium
  14480. if (pc_isvip(sd)) {
  14481. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14482. if (details_penalty[1] == 100)
  14483. details_penalty[1] = 0;
  14484. else {
  14485. if (details_penalty[1] < 100) {
  14486. details_penalty[1] = 100 - details_penalty[1];
  14487. details_penalty[1] = 0 - details_penalty[1];
  14488. }
  14489. else
  14490. details_penalty[1] = details_penalty[1] - 100;
  14491. }
  14492. }
  14493. else
  14494. details_penalty[1] = 0;
  14495. //2:Server
  14496. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14497. if (details_penalty[2] == 100)
  14498. details_penalty[2] = 0;
  14499. else {
  14500. if (details_penalty[2] < 100) {
  14501. details_penalty[2] = 100 - details_penalty[2];
  14502. details_penalty[2] = 0 - details_penalty[2];
  14503. }
  14504. else
  14505. details_penalty[2] = details_penalty[2] - 100;
  14506. }
  14507. //3:TPLUS
  14508. details_penalty[3] = 0;
  14509. /* End - Penalty set*/
  14510. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14511. info = &packet_db[sd->packet_ver][cmd];
  14512. len = info->len; //this is the base len without details
  14513. if(!len) return; //version as packet disable
  14514. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14515. szdetails = 7;
  14516. factor = 1;
  14517. }
  14518. else if (cmd == 0x097b) {
  14519. tot_baseexp *= factor;
  14520. tot_drop *= factor;
  14521. tot_penalty *= factor;
  14522. }
  14523. fd = sd->fd;
  14524. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14525. WFIFOW(fd,0) = cmd;
  14526. for (i = 0; i < maxinfotype; i++) {
  14527. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14528. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14529. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14530. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14531. tot_baseexp += details_bexp[i]*factor;
  14532. tot_drop += details_penalty[i]*factor;
  14533. tot_penalty += details_drop[i]*factor;
  14534. len += szdetails;
  14535. }
  14536. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14537. if (cmd == 0x08cb) { //0x08cb version
  14538. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14539. WFIFOW(fd,info->pos[2]) = tot_drop;
  14540. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14541. }
  14542. else { //2013-08-07aRagexe uses 0x097b
  14543. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14544. WFIFOL(fd,info->pos[2]) = tot_drop;
  14545. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14546. }
  14547. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14548. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14549. WFIFOSET(fd,len);
  14550. }
  14551. }
  14552. #endif
  14553. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14554. char cmd[30];
  14555. int t_aid = RFIFOL(fd,2);
  14556. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14557. is_atcommand(fd, sd, cmd, 1);
  14558. }
  14559. ///TODO: Special item that obtained, must be broadcasted by this packet
  14560. //void clif_broadcast_obtain_special_item() {}
  14561. #ifdef DUMP_UNKNOWN_PACKET
  14562. void DumpUnknow(int fd,TBL_PC *sd,int cmd,int packet_len){
  14563. const char* packet_txt = "save/packet.txt";
  14564. FILE* fp;
  14565. time_t time_server;
  14566. struct tm *datetime;
  14567. char datestr[512];
  14568. time(&time_server); // get time in seconds since 1/1/1970
  14569. datetime = localtime(&time_server); // convert seconds in structure
  14570. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14571. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14572. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14573. if( sd ) {
  14574. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s \n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14575. } else {
  14576. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14577. }
  14578. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14579. fprintf(fp, "\n");
  14580. fclose(fp);
  14581. } else {
  14582. ShowError("Failed to write '%s'.\n", packet_txt);
  14583. // Dump on console instead
  14584. if( sd ) {
  14585. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  14586. } else {
  14587. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14588. }
  14589. ShowDump(RFIFOP(fd,0), packet_len);
  14590. }
  14591. }
  14592. #endif
  14593. /*==========================================
  14594. * Main client packet processing function
  14595. *------------------------------------------*/
  14596. static int clif_parse(int fd)
  14597. {
  14598. int cmd, packet_ver, packet_len, err;
  14599. TBL_PC* sd;
  14600. int pnum;
  14601. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14602. // Note: "click masters" can do 80+ clicks in 10 seconds
  14603. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS] -- This actually aids packet spammers, but stuff like /str+ gets slow without it [Ai4rei]
  14604. { // begin main client packet processing loop
  14605. sd = (TBL_PC *)session[fd]->session_data;
  14606. if (session[fd]->flag.eof) {
  14607. if (sd) {
  14608. if (sd->state.autotrade) {
  14609. //Disassociate character from the socket connection.
  14610. session[fd]->session_data = NULL;
  14611. sd->fd = 0;
  14612. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14613. } else
  14614. if (sd->state.active) {
  14615. // Player logout display [Valaris]
  14616. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14617. clif_quitsave(fd, sd);
  14618. } else {
  14619. //Unusual logout (during log on/off/map-changer procedure)
  14620. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14621. map_quit(sd);
  14622. }
  14623. } else {
  14624. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14625. }
  14626. do_close(fd);
  14627. return 0;
  14628. }
  14629. if (RFIFOREST(fd) < 2)
  14630. return 0;
  14631. cmd = RFIFOW(fd,0);
  14632. // identify client's packet version
  14633. if (sd) {
  14634. packet_ver = sd->packet_ver;
  14635. } else {
  14636. // check authentification packet to know packet version
  14637. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14638. if( err ) {// failed to identify packet version
  14639. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14640. err == 1 ? "" :
  14641. err == 2 ? ", possibly for having an invalid account_id" :
  14642. err == 3 ? ", possibly for having an invalid char_id." :
  14643. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14644. err == 4 ? ", possibly for having an invalid login_id1." :
  14645. err == 5 ? ", possibly for having an invalid client_tick." :
  14646. */
  14647. err == 6 ? ", possibly for having an invalid sex." :
  14648. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14649. WFIFOHEAD(fd,packet_len(0x6a));
  14650. WFIFOW(fd,0) = 0x6a;
  14651. WFIFOB(fd,2) = 3; // Rejected from Server
  14652. WFIFOSET(fd,packet_len(0x6a));
  14653. #ifdef DUMP_INVALID_PACKET
  14654. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14655. #endif
  14656. RFIFOSKIP(fd, RFIFOREST(fd));
  14657. set_eof(fd);
  14658. return 0;
  14659. }
  14660. }
  14661. // filter out invalid / unsupported packets
  14662. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14663. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14664. #ifdef DUMP_INVALID_PACKET
  14665. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14666. #endif
  14667. set_eof(fd);
  14668. return 0;
  14669. }
  14670. // determine real packet length
  14671. packet_len = packet_db[packet_ver][cmd].len;
  14672. if (packet_len == -1) { // variable-length packet
  14673. if (RFIFOREST(fd) < 4)
  14674. return 0;
  14675. packet_len = RFIFOW(fd,2);
  14676. if (packet_len < 4 || packet_len > 32768) {
  14677. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14678. #ifdef DUMP_INVALID_PACKET
  14679. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14680. #endif
  14681. set_eof(fd);
  14682. return 0;
  14683. }
  14684. }
  14685. if ((int)RFIFOREST(fd) < packet_len)
  14686. return 0; // not enough data received to form the packet
  14687. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14688. packet_db[packet_ver][cmd].func(fd, sd);
  14689. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14690. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14691. ; //Only valid packet when there is no session
  14692. else
  14693. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14694. ; //Only valid packet when player is not on a map
  14695. else
  14696. packet_db[packet_ver][cmd].func(fd, sd);
  14697. }
  14698. #ifdef DUMP_UNKNOWN_PACKET
  14699. else DumpUnknow(fd,sd,cmd,packet_len);
  14700. #endif
  14701. RFIFOSKIP(fd, packet_len);
  14702. }; // main loop end
  14703. return 0;
  14704. }
  14705. /*==========================================
  14706. * Reads packet_db.txt and setups its array reference
  14707. *------------------------------------------*/
  14708. void packetdb_readdb(void)
  14709. {
  14710. FILE *fp;
  14711. char line[1024];
  14712. int ln=0, entries=0;
  14713. int cmd,i,j,packet_ver;
  14714. int max_cmd=-1;
  14715. bool skip_ver = false;
  14716. int warned = 0;
  14717. char *str[64],*p,*str2[64],*p2,w1[256],w2[256];
  14718. int packet_len_table[MAX_PACKET_DB] = {
  14719. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14723. //#0x0040
  14724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14726. #if PACKETVER <= 20081217
  14727. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14728. #else
  14729. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14730. #endif
  14731. #if PACKETVER < 2
  14732. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14733. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14734. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14735. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14736. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14737. #else
  14738. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14739. #endif
  14740. //#0x0080
  14741. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14742. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14743. #if PACKETVER <= 20100622
  14744. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14745. #else
  14746. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14747. #endif
  14748. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14749. //#0x00C0
  14750. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14751. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14752. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14753. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14754. //#0x0100
  14755. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14756. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14757. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14758. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14759. //#0x0140
  14760. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14761. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14762. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14763. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14764. //#0x0180
  14765. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14766. #if PACKETVER < 1
  14767. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14768. #else // 196 comodo icon status display for later
  14769. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14770. #endif
  14771. #if PACKETVER < 20081126
  14772. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14773. #else // 0x1a2 changed (35->37)
  14774. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14775. #endif
  14776. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14777. //#0x01C0, Set 0x1d5=-1
  14778. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14779. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14780. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14781. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14782. //#0x0200
  14783. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14784. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14785. #if PACKETVER < 20071106
  14786. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14787. #else // 0x22c changed
  14788. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14789. #endif
  14790. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14791. //#0x0240
  14792. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14793. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14794. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14795. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14796. //#0x0280
  14797. #if PACKETVER < 20070711
  14798. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14799. #else
  14800. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14801. #endif
  14802. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14803. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14804. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14805. //#0x02C0
  14806. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14807. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14808. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14809. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14810. //#0x0300
  14811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14815. //#0x0340
  14816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14820. //#0x0380
  14821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14825. //#0x03C0
  14826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14830. //#0x0400
  14831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14835. //#0x0440
  14836. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14840. //#0x0480
  14841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14845. //#0x04C0
  14846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14850. //#0x0500
  14851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14855. //#0x0540
  14856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14860. //#0x0580
  14861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14865. //#0x05C0
  14866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14870. //#0x0600
  14871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14875. //#0x0640
  14876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14880. //#0x0680
  14881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14885. //#0x06C0
  14886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14890. //#0x0700
  14891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14895. //#0x0740
  14896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14900. //#0x0780
  14901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14905. //#0x07C0
  14906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14907. #if PACKETVER < 20090617
  14908. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  14909. #else // 0x7d9 changed
  14910. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  14911. #endif
  14912. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  14913. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  14914. //#0x0800
  14915. #if PACKETVER < 20091229
  14916. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  14917. #else // for Party booking ( PACKETVER >= 20091229 )
  14918. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  14919. #endif
  14920. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  14921. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14922. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  14923. //#0x0840
  14924. #if PACKETVER < 20130000
  14925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14926. #else
  14927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  14928. #endif
  14929. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  14930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14932. //#0x0880
  14933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14937. //#0x08C0
  14938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  14939. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14942. //#0x0900
  14943. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14947. //#0x0940
  14948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14951. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  14952. //#0x0980
  14953. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14954. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 0,
  14955. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  14956. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  14957. };
  14958. struct {
  14959. void (*func)(int, struct map_session_data *);
  14960. char *name;
  14961. } clif_parse_func[]={
  14962. {clif_parse_WantToConnection,"wanttoconnection"},
  14963. {clif_parse_LoadEndAck,"loadendack"},
  14964. {clif_parse_TickSend,"ticksend"},
  14965. {clif_parse_WalkToXY,"walktoxy"},
  14966. {clif_parse_QuitGame,"quitgame"},
  14967. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14968. {clif_parse_GlobalMessage,"globalmessage"},
  14969. {clif_parse_MapMove,"mapmove"},
  14970. {clif_parse_ChangeDir,"changedir"},
  14971. {clif_parse_Emotion,"emotion"},
  14972. {clif_parse_HowManyConnections,"howmanyconnections"},
  14973. {clif_parse_ActionRequest,"actionrequest"},
  14974. {clif_parse_Restart,"restart"},
  14975. {clif_parse_WisMessage,"wis"},
  14976. {clif_parse_Broadcast,"broadcast"},
  14977. {clif_parse_TakeItem,"takeitem"},
  14978. {clif_parse_DropItem,"dropitem"},
  14979. {clif_parse_UseItem,"useitem"},
  14980. {clif_parse_EquipItem,"equipitem"},
  14981. {clif_parse_UnequipItem,"unequipitem"},
  14982. {clif_parse_NpcClicked,"npcclicked"},
  14983. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14984. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14985. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14986. {clif_parse_CreateChatRoom,"createchatroom"},
  14987. {clif_parse_ChatAddMember,"chataddmember"},
  14988. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14989. {clif_parse_ChangeChatOwner,"changechatowner"},
  14990. {clif_parse_KickFromChat,"kickfromchat"},
  14991. {clif_parse_ChatLeave,"chatleave"},
  14992. {clif_parse_TradeRequest,"traderequest"},
  14993. {clif_parse_TradeAck,"tradeack"},
  14994. {clif_parse_TradeAddItem,"tradeadditem"},
  14995. {clif_parse_TradeOk,"tradeok"},
  14996. {clif_parse_TradeCancel,"tradecancel"},
  14997. {clif_parse_TradeCommit,"tradecommit"},
  14998. {clif_parse_StopAttack,"stopattack"},
  14999. {clif_parse_PutItemToCart,"putitemtocart"},
  15000. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15001. {clif_parse_RemoveOption,"removeoption"},
  15002. {clif_parse_ChangeCart,"changecart"},
  15003. {clif_parse_StatusUp,"statusup"},
  15004. {clif_parse_SkillUp,"skillup"},
  15005. {clif_parse_UseSkillToId,"useskilltoid"},
  15006. {clif_parse_UseSkillToPos,"useskilltopos"},
  15007. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15008. {clif_parse_UseSkillMap,"useskillmap"},
  15009. {clif_parse_RequestMemo,"requestmemo"},
  15010. {clif_parse_ProduceMix,"producemix"},
  15011. {clif_parse_Cooking,"cooking"},
  15012. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15013. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15014. {clif_parse_NpcAmountInput,"npcamountinput"},
  15015. {clif_parse_NpcStringInput,"npcstringinput"},
  15016. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15017. {clif_parse_ItemIdentify,"itemidentify"},
  15018. {clif_parse_SelectArrow,"selectarrow"},
  15019. {clif_parse_AutoSpell,"autospell"},
  15020. {clif_parse_UseCard,"usecard"},
  15021. {clif_parse_InsertCard,"insertcard"},
  15022. {clif_parse_RepairItem,"repairitem"},
  15023. {clif_parse_WeaponRefine,"weaponrefine"},
  15024. {clif_parse_SolveCharName,"solvecharname"},
  15025. {clif_parse_ResetChar,"resetchar"},
  15026. {clif_parse_LocalBroadcast,"localbroadcast"},
  15027. {clif_parse_MoveToKafra,"movetokafra"},
  15028. {clif_parse_MoveFromKafra,"movefromkafra"},
  15029. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15030. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15031. {clif_parse_CloseKafra,"closekafra"},
  15032. {clif_parse_CreateParty,"createparty"},
  15033. {clif_parse_CreateParty2,"createparty2"},
  15034. {clif_parse_PartyInvite,"partyinvite"},
  15035. {clif_parse_PartyInvite2,"partyinvite2"},
  15036. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15037. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15038. {clif_parse_LeaveParty,"leaveparty"},
  15039. {clif_parse_RemovePartyMember,"removepartymember"},
  15040. {clif_parse_PartyChangeOption,"partychangeoption"},
  15041. {clif_parse_PartyMessage,"partymessage"},
  15042. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15043. {clif_parse_CloseVending,"closevending"},
  15044. {clif_parse_VendingListReq,"vendinglistreq"},
  15045. {clif_parse_PurchaseReq,"purchasereq"},
  15046. {clif_parse_PurchaseReq2,"purchasereq2"},
  15047. {clif_parse_OpenVending,"openvending"},
  15048. {clif_parse_CreateGuild,"createguild"},
  15049. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15050. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15051. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15052. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15053. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15054. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15055. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15056. {clif_parse_GuildInvite,"guildinvite"},
  15057. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15058. {clif_parse_GuildLeave,"guildleave"},
  15059. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15060. {clif_parse_GuildMessage,"guildmessage"},
  15061. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15062. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15063. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15064. {clif_parse_GuildOpposition,"guildopposition"},
  15065. {clif_parse_GuildBreak,"guildbreak"},
  15066. {clif_parse_PetMenu,"petmenu"},
  15067. {clif_parse_CatchPet,"catchpet"},
  15068. {clif_parse_SelectEgg,"selectegg"},
  15069. {clif_parse_SendEmotion,"sendemotion"},
  15070. {clif_parse_ChangePetName,"changepetname"},
  15071. {clif_parse_GMKick,"gmkick"},
  15072. {clif_parse_GMHide,"gmhide"},
  15073. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15074. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15075. {clif_parse_GMKickAll,"killall"},
  15076. {clif_parse_GMRecall,"recall"},
  15077. {clif_parse_GMRecall,"summon"},
  15078. {clif_parse_GM_Monster_Item,"itemmonster"},
  15079. {clif_parse_GMShift,"remove"},
  15080. {clif_parse_GMShift,"shift"},
  15081. {clif_parse_GMChangeMapType,"changemaptype"},
  15082. {clif_parse_GMRc,"rc"},
  15083. {clif_parse_GMRecall2,"recall2"},
  15084. {clif_parse_GMRemove2,"remove2"},
  15085. {clif_parse_GMFullStrip,"gmfullstrip"},
  15086. {clif_parse_NoviceDoriDori,"sndoridori"},
  15087. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15088. {clif_parse_PMIgnore,"wisexin"},
  15089. {clif_parse_PMIgnoreList,"wisexlist"},
  15090. {clif_parse_PMIgnoreAll,"wisall"},
  15091. {clif_parse_FriendsListAdd,"friendslistadd"},
  15092. {clif_parse_FriendsListRemove,"friendslistremove"},
  15093. {clif_parse_FriendsListReply,"friendslistreply"},
  15094. {clif_parse_Blacksmith,"blacksmith"},
  15095. {clif_parse_Alchemist,"alchemist"},
  15096. {clif_parse_Taekwon,"taekwon"},
  15097. {clif_parse_RankingPk,"rankingpk"},
  15098. {clif_parse_FeelSaveOk,"feelsaveok"},
  15099. {clif_parse_debug,"debug"},
  15100. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15101. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15102. {clif_parse_HomMoveTo,"hommoveto"},
  15103. {clif_parse_HomAttack,"homattack"},
  15104. {clif_parse_HomMenu,"hommenu"},
  15105. {clif_parse_StoragePassword,"storagepassword"},
  15106. {clif_parse_Hotkey,"hotkey"},
  15107. {clif_parse_AutoRevive,"autorevive"},
  15108. {clif_parse_Check,"check"},
  15109. {clif_parse_Adopt_request,"adoptrequest"},
  15110. {clif_parse_Adopt_reply,"adoptreply"},
  15111. // MAIL SYSTEM
  15112. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15113. {clif_parse_Mail_read,"mailread"},
  15114. {clif_parse_Mail_getattach,"mailgetattach"},
  15115. {clif_parse_Mail_delete,"maildelete"},
  15116. {clif_parse_Mail_return,"mailreturn"},
  15117. {clif_parse_Mail_setattach,"mailsetattach"},
  15118. {clif_parse_Mail_winopen,"mailwinopen"},
  15119. {clif_parse_Mail_send,"mailsend"},
  15120. // AUCTION SYSTEM
  15121. {clif_parse_Auction_search,"auctionsearch"},
  15122. {clif_parse_Auction_buysell,"auctionbuysell"},
  15123. {clif_parse_Auction_setitem,"auctionsetitem"},
  15124. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15125. {clif_parse_Auction_register,"auctionregister"},
  15126. {clif_parse_Auction_cancel,"auctioncancel"},
  15127. {clif_parse_Auction_close,"auctionclose"},
  15128. {clif_parse_Auction_bid,"auctionbid"},
  15129. // Quest Log System
  15130. {clif_parse_questStateAck,"queststate"},
  15131. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15132. {clif_parse_EquipTick,"equiptickbox"},
  15133. {clif_parse_BattleChat,"battlechat"},
  15134. {clif_parse_mercenary_action,"mermenu"},
  15135. {clif_parse_progressbar,"progressbar"},
  15136. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15137. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15138. #if PACKETVER >= 20091229
  15139. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15140. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15141. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15142. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15143. #endif
  15144. {clif_parse_BankCheck,"bankcheck"},
  15145. {clif_parse_BankDeposit,"bankdeposit"},
  15146. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15147. {clif_parse_BankOpen,"bankopen"},
  15148. {clif_parse_BankClose,"bankclose"},
  15149. {clif_parse_PVPInfo,"pvpinfo"},
  15150. {clif_parse_LessEffect,"lesseffect"},
  15151. // Buying Store
  15152. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15153. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15154. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15155. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15156. // Store Search
  15157. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15158. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15159. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15160. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15161. // Cashshop
  15162. { clif_parse_cashshop_open_request, "cashshopopen" },
  15163. { clif_parse_cashshop_close, "cashshopclose" },
  15164. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15165. { clif_parse_cashshop_buy, "cashshopbuy" },
  15166. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15167. /* */
  15168. { clif_parse_MoveItem , "moveitem" },
  15169. { clif_parse_GuildInvite2 , "guildinvite2" },
  15170. { clif_parse_reqworldinfo, "reqworldinfo"},
  15171. { clif_parse_client_version, "clientversion"},
  15172. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15173. { clif_parse_ranklist, "ranklist"},
  15174. {NULL,NULL}
  15175. };
  15176. struct {
  15177. char *name; //function name
  15178. int funcidx; //
  15179. } clif_ack_func[]={ //hash
  15180. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15181. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15182. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15183. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15184. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15185. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15186. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15187. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15188. };
  15189. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15190. int f;
  15191. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15192. memset(packet_db,0,sizeof(packet_db));
  15193. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15194. packet_len(i) = packet_len_table[i];
  15195. clif_config.packet_db_ver = MAX_PACKET_VER;
  15196. for(f = 0; f<ARRAYLENGTH(filename); f++){
  15197. entries = 0;
  15198. sprintf(line, "%s/%s", db_path,filename[f]);
  15199. if( (fp=fopen(line,"r"))==NULL ){
  15200. if(f==0) {
  15201. ShowFatalError("Can't read %s\n", line);
  15202. exit(EXIT_FAILURE);
  15203. }
  15204. return;
  15205. }
  15206. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15207. while( fgets(line, sizeof(line), fp) )
  15208. {
  15209. ln++;
  15210. if(line[0]=='/' && line[1]=='/')
  15211. continue;
  15212. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2)
  15213. {
  15214. if(strcmpi(w1,"packet_ver")==0) {
  15215. int prev_ver = packet_ver;
  15216. skip_ver = 0;
  15217. packet_ver = atoi(w2);
  15218. if ( packet_ver > MAX_PACKET_VER )
  15219. { //Check to avoid overflowing. [Skotlex]
  15220. if( (warned&1) == 0 )
  15221. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15222. warned &= 1;
  15223. skip_ver = true;
  15224. }
  15225. else if( packet_ver < 0 )
  15226. {
  15227. if( (warned&2) == 0 )
  15228. ShowWarning("Negative packet versions are not supported.\n");
  15229. warned &= 2;
  15230. skip_ver = true;
  15231. }
  15232. else if( packet_ver == SERVER )
  15233. {
  15234. if( (warned&4) == 0 )
  15235. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15236. warned &= 4;
  15237. skip_ver = true;
  15238. }
  15239. if( skip_ver )
  15240. {
  15241. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15242. packet_ver = prev_ver;
  15243. continue;
  15244. }
  15245. // copy from previous version into new version and continue
  15246. // - indicating all following packets should be read into the newer version
  15247. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15248. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15249. continue;
  15250. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15251. if(strcmpi(w2,"default")==0) //This is the preferred version.
  15252. clif_config.packet_db_ver = MAX_PACKET_VER;
  15253. else // to manually set the packet DB version
  15254. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15255. continue;
  15256. }
  15257. }
  15258. if( skip_ver )
  15259. continue; // Skipping current packet version
  15260. memset(str,0,sizeof(str));
  15261. for(j=0,p=line;j<4 && p; ++j)
  15262. {
  15263. str[j]=p;
  15264. p=strchr(p,',');
  15265. if(p) *p++=0;
  15266. }
  15267. if(str[0]==NULL)
  15268. continue;
  15269. cmd=strtol(str[0],(char **)NULL,0);
  15270. if(max_cmd < cmd)
  15271. max_cmd = cmd;
  15272. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15273. continue;
  15274. if(str[1]==NULL){
  15275. ShowError("packet_db: packet len error\n");
  15276. continue;
  15277. }
  15278. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15279. if(str[2]==NULL){
  15280. packet_db[packet_ver][cmd].func = NULL;
  15281. ln++;
  15282. continue;
  15283. }
  15284. // look up processing function by name
  15285. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15286. if( j < ARRAYLENGTH(clif_parse_func) )
  15287. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15288. else { //search if it's a mapped ack func
  15289. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15290. if( j < ARRAYLENGTH(clif_ack_func)) {
  15291. int fidx = clif_ack_func[j].funcidx;
  15292. packet_db_ack[packet_ver][fidx] = cmd;
  15293. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15294. }
  15295. }
  15296. // set the identifying cmd for the packet_db version
  15297. if (strcmp(str[2],"wanttoconnection")==0)
  15298. clif_config.connect_cmd[packet_ver] = cmd;
  15299. if(str[3]==NULL){
  15300. ShowError("packet_db: packet error\n");
  15301. exit(EXIT_FAILURE);
  15302. }
  15303. for(j=0,p2=str[3];p2;j++){
  15304. short k;
  15305. str2[j]=p2;
  15306. p2=strchr(p2,':');
  15307. if(p2) *p2++=0;
  15308. k = atoi(str2[j]);
  15309. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15310. if( j >= MAX_PACKET_POS )
  15311. {
  15312. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15313. break;
  15314. }
  15315. packet_db[packet_ver][cmd].pos[j] = k;
  15316. }
  15317. entries++;
  15318. }
  15319. fclose(fp);
  15320. if(max_cmd > MAX_PACKET_DB)
  15321. {
  15322. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15323. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15324. }
  15325. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  15326. { //Locate the nearest version that we still support. [Skotlex]
  15327. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15328. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15329. }
  15330. sprintf(line, "%s/%s", db_path,filename[f]);
  15331. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  15332. }
  15333. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15334. }
  15335. /*==========================================
  15336. *
  15337. *------------------------------------------*/
  15338. int do_init_clif(void) {
  15339. const char* colors[COLOR_MAX] = { "0xFF0000" };
  15340. int i;
  15341. /**
  15342. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15343. **/
  15344. for(i = 0; i < COLOR_MAX; i++) {
  15345. color_table[i] = strtoul(colors[i],NULL,0);
  15346. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15347. }
  15348. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15349. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15350. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15351. packetdb_readdb();
  15352. set_defaultparse(clif_parse);
  15353. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15354. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15355. exit(EXIT_FAILURE);
  15356. }
  15357. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15358. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15359. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15360. return 0;
  15361. }
  15362. void do_final_clif(void) {
  15363. ers_destroy(delay_clearunit_ers);
  15364. }