clif.c 521 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211
  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(unsigned short 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 pcdb_checkid(status_get_viewdata(bl)->class_)?0x0: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->status.font;
  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_COSTUME)
  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->status.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->status.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. struct status_change *sc = status_get_sc(bl);
  1170. int len;
  1171. vd = status_get_viewdata(bl);
  1172. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1173. return 0;
  1174. /**
  1175. * Hide NPC from maya purple card.
  1176. **/
  1177. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1178. return 0;
  1179. len = clif_set_unit_idle(bl, buf,true);
  1180. clif_send(buf, len, bl, AREA_WOS);
  1181. if (disguised(bl))
  1182. clif_setdisguise(bl, buf, len);
  1183. if (vd->cloth_color)
  1184. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1185. switch (bl->type)
  1186. {
  1187. case BL_PC:
  1188. {
  1189. TBL_PC *sd = ((TBL_PC*)bl);
  1190. int i;
  1191. if (sd->spiritball > 0)
  1192. clif_spiritball(&sd->bl);
  1193. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1194. clif_specialeffect(bl,423,AREA);
  1195. else if(sd->state.size==SZ_MEDIUM)
  1196. clif_specialeffect(bl,421,AREA);
  1197. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1198. clif_sendbgemblem_area(sd);
  1199. for(i = 1; i < 5; i++){
  1200. if( sd->talisman[i] > 0 )
  1201. clif_talisman(sd, i);
  1202. }
  1203. for (i = 0; i < sd->sc_display_count; i++) {
  1204. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1205. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1206. else
  1207. clif_status_change2(&sd->bl,sd->bl.id,AREA,StatusIconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3);
  1208. }
  1209. if (sd->status.robe)
  1210. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1211. }
  1212. break;
  1213. case BL_MOB:
  1214. {
  1215. TBL_MOB *md = ((TBL_MOB*)bl);
  1216. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1217. clif_specialeffect(&md->bl,423,AREA);
  1218. else if(md->special_state.size==SZ_MEDIUM)
  1219. clif_specialeffect(&md->bl,421,AREA);
  1220. }
  1221. break;
  1222. case BL_NPC:
  1223. {
  1224. TBL_NPC *nd = ((TBL_NPC*)bl);
  1225. if( nd->size == SZ_BIG )
  1226. clif_specialeffect(&nd->bl,423,AREA);
  1227. else if( nd->size == SZ_MEDIUM )
  1228. clif_specialeffect(&nd->bl,421,AREA);
  1229. }
  1230. break;
  1231. case BL_PET:
  1232. if (vd->head_bottom)
  1233. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1234. break;
  1235. }
  1236. return 0;
  1237. }
  1238. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1239. /// 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
  1240. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1241. {
  1242. struct status_data *status;
  1243. unsigned char buf[128];
  1244. int htype;
  1245. nullpo_retv(hd);
  1246. status = &hd->battle_status;
  1247. htype = hom_class2type(hd->homunculus.class_);
  1248. memset(buf,0,packet_len(0x22e));
  1249. WBUFW(buf,0)=0x22e;
  1250. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1251. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1252. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1253. WBUFW(buf,27)=hd->homunculus.level;
  1254. WBUFW(buf,29)=hd->homunculus.hunger;
  1255. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1256. WBUFW(buf,33)=0; // equip id
  1257. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1258. WBUFW(buf,37)=min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1259. WBUFW(buf,39)=status->hit;
  1260. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1261. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1262. else
  1263. WBUFW(buf,41)=status->cri/10;
  1264. WBUFW(buf,43)=status->def + status->vit ;
  1265. WBUFW(buf,45)=status->mdef;
  1266. WBUFW(buf,47)=status->flee;
  1267. WBUFW(buf,49)=(flag)?0:status->amotion;
  1268. if (status->max_hp > INT16_MAX) {
  1269. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1270. WBUFW(buf,53) = 100;
  1271. } else {
  1272. WBUFW(buf,51)=status->hp;
  1273. WBUFW(buf,53)=status->max_hp;
  1274. }
  1275. if (status->max_sp > INT16_MAX) {
  1276. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1277. WBUFW(buf,57) = 100;
  1278. } else {
  1279. WBUFW(buf,55)=status->sp;
  1280. WBUFW(buf,57)=status->max_sp;
  1281. }
  1282. WBUFL(buf,59)=hd->homunculus.exp;
  1283. WBUFL(buf,63)=hd->exp_next;
  1284. switch( htype ) {
  1285. case HT_REG:
  1286. case HT_EVO:
  1287. if( hd->homunculus.level >= battle_config.hom_max_level )
  1288. WBUFL(buf,63)=0;
  1289. break;
  1290. case HT_S:
  1291. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1292. WBUFL(buf,63)=0;
  1293. break;
  1294. }
  1295. WBUFW(buf,67)=hd->homunculus.skillpts;
  1296. WBUFW(buf,69)=status_get_range(&hd->bl);
  1297. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1298. }
  1299. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1300. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1301. /// type:
  1302. /// unused
  1303. /// state:
  1304. /// 0 = pre-init
  1305. /// 1 = intimacy
  1306. /// 2 = hunger
  1307. /// 3 = accessory?
  1308. /// ? = ignored
  1309. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1310. { //[orn]
  1311. int fd = sd->fd;
  1312. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1313. hom_calc_skilltree(sd->hd, 0);
  1314. WFIFOHEAD(fd, packet_len(0x230));
  1315. WFIFOW(fd,0)=0x230;
  1316. WFIFOB(fd,2)=0;
  1317. WFIFOB(fd,3)=state;
  1318. WFIFOL(fd,4)=sd->hd->bl.id;
  1319. WFIFOL(fd,8)=param;
  1320. WFIFOSET(fd,packet_len(0x230));
  1321. }
  1322. int clif_homskillinfoblock(struct map_session_data *sd)
  1323. { //[orn]
  1324. struct homun_data *hd;
  1325. int fd = sd->fd;
  1326. int i,j,len=4;
  1327. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1328. hd = sd->hd;
  1329. if ( !hd )
  1330. return 0 ;
  1331. WFIFOW(fd,0)=0x235;
  1332. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1333. int id = hd->homunculus.hskill[i].id;
  1334. if( id != 0 ){
  1335. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1336. j = id - HM_SKILLBASE;
  1337. WFIFOW(fd,len ) = id;
  1338. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1339. WFIFOW(fd,len+4) = 0;
  1340. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1341. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1342. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1343. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1344. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < hom_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1345. len+=37;
  1346. }
  1347. }
  1348. WFIFOW(fd,2)=len;
  1349. WFIFOSET(fd,len);
  1350. return 0;
  1351. }
  1352. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1353. { //[orn]
  1354. struct homun_data *hd;
  1355. int fd, idx;
  1356. nullpo_retv(sd);
  1357. idx = skill_id - HM_SKILLBASE;
  1358. fd=sd->fd;
  1359. hd=sd->hd;
  1360. WFIFOHEAD(fd, packet_len(0x239));
  1361. WFIFOW(fd,0) = 0x239;
  1362. WFIFOW(fd,2) = skill_id;
  1363. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1364. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1365. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1366. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1367. WFIFOSET(fd,packet_len(0x239));
  1368. }
  1369. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1370. {
  1371. int fd=sd->fd;
  1372. WFIFOHEAD(fd,packet_len(0x22f));
  1373. WFIFOW(fd,0)=0x22f;
  1374. WFIFOB(fd,2)=fail;
  1375. WFIFOW(fd,3)=foodid;
  1376. WFIFOSET(fd,packet_len(0x22f));
  1377. return 0;
  1378. }
  1379. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1380. /// 0087 <walk start time>.L <walk data>.6B
  1381. void clif_walkok(struct map_session_data *sd)
  1382. {
  1383. int fd=sd->fd;
  1384. WFIFOHEAD(fd, packet_len(0x87));
  1385. WFIFOW(fd,0)=0x87;
  1386. WFIFOL(fd,2)=gettick();
  1387. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1388. WFIFOSET(fd,packet_len(0x87));
  1389. }
  1390. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1391. {
  1392. uint8 buf[128];
  1393. int len;
  1394. struct status_change *sc = NULL;
  1395. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1396. clif_ally_only = true;
  1397. len = clif_set_unit_walking(bl,ud,buf);
  1398. clif_send(buf,len,bl,AREA_WOS);
  1399. if (disguised(bl))
  1400. clif_setdisguise(bl, buf, len);
  1401. if(vd->cloth_color)
  1402. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1403. switch(bl->type) {
  1404. case BL_PC:
  1405. {
  1406. TBL_PC *sd = ((TBL_PC*)bl);
  1407. // clif_movepc(sd);
  1408. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1409. clif_specialeffect(&sd->bl,423,AREA);
  1410. else if(sd->state.size==SZ_MEDIUM)
  1411. clif_specialeffect(&sd->bl,421,AREA);
  1412. }
  1413. break;
  1414. case BL_MOB:
  1415. {
  1416. TBL_MOB *md = ((TBL_MOB*)bl);
  1417. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1418. clif_specialeffect(&md->bl,423,AREA);
  1419. else if(md->special_state.size==SZ_MEDIUM)
  1420. clif_specialeffect(&md->bl,421,AREA);
  1421. }
  1422. break;
  1423. case BL_PET:
  1424. if(vd->head_bottom) // needed to display pet equip properly
  1425. clif_pet_equip_area((TBL_PET*)bl);
  1426. break;
  1427. }
  1428. clif_ally_only = false;
  1429. }
  1430. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1431. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1432. /// Note: unit must not be self
  1433. void clif_move(struct unit_data *ud)
  1434. {
  1435. unsigned char buf[16];
  1436. struct view_data* vd;
  1437. struct block_list* bl = ud->bl;
  1438. struct status_change *sc = NULL;
  1439. vd = status_get_viewdata(bl);
  1440. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1441. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1442. /**
  1443. * Hide NPC from maya purple card.
  1444. **/
  1445. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1446. return;
  1447. if (ud->state.speed_changed) {
  1448. // Since we don't know how to update the speed of other objects,
  1449. // use the old walk packet to update the data.
  1450. ud->state.speed_changed = 0;
  1451. clif_move2(bl, vd, ud);
  1452. return;
  1453. }
  1454. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1455. clif_ally_only = true;
  1456. WBUFW(buf,0)=0x86;
  1457. WBUFL(buf,2)=bl->id;
  1458. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1459. WBUFL(buf,12)=gettick();
  1460. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1461. if (disguised(bl)) {
  1462. WBUFL(buf,2)=-bl->id;
  1463. clif_send(buf, packet_len(0x86), bl, SELF);
  1464. }
  1465. clif_ally_only = false;
  1466. }
  1467. /*==========================================
  1468. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1469. *------------------------------------------*/
  1470. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1471. {
  1472. struct map_session_data *sd = NULL;
  1473. //Remove player from map server
  1474. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1475. map_quit(sd);
  1476. return 0;
  1477. }
  1478. /*==========================================
  1479. *
  1480. *------------------------------------------*/
  1481. void clif_quitsave(int fd,struct map_session_data *sd) {
  1482. if (!battle_config.prevent_logout ||
  1483. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1484. map_quit(sd);
  1485. else if (sd->fd) {
  1486. //Disassociate session from player (session is deleted after this function was called)
  1487. //And set a timer to make him quit later.
  1488. session[sd->fd]->session_data = NULL;
  1489. sd->fd = 0;
  1490. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1491. }
  1492. }
  1493. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1494. /// 0091 <map name>.16B <x>.W <y>.W
  1495. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1496. {
  1497. int fd;
  1498. nullpo_retv(sd);
  1499. fd = sd->fd;
  1500. WFIFOHEAD(fd,packet_len(0x91));
  1501. WFIFOW(fd,0) = 0x91;
  1502. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1503. WFIFOW(fd,18) = x;
  1504. WFIFOW(fd,20) = y;
  1505. WFIFOSET(fd,packet_len(0x91));
  1506. }
  1507. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1508. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1509. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1510. {
  1511. int fd;
  1512. nullpo_retv(sd);
  1513. fd = sd->fd;
  1514. WFIFOHEAD(fd,packet_len(0x92));
  1515. WFIFOW(fd,0) = 0x92;
  1516. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1517. WFIFOW(fd,18) = x;
  1518. WFIFOW(fd,20) = y;
  1519. WFIFOL(fd,22) = htonl(ip);
  1520. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1521. WFIFOSET(fd,packet_len(0x92));
  1522. }
  1523. void clif_blown(struct block_list *bl)
  1524. {
  1525. clif_slide(bl, bl->x, bl->y);
  1526. //clif_fixpos(bl); //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1527. }
  1528. /// Visually moves(slides) a character to x,y. If the target cell
  1529. /// isn't walkable, the char doesn't move at all. If the char is
  1530. /// sitting it will stand up (ZC_STOPMOVE).
  1531. /// 0088 <id>.L <x>.W <y>.W
  1532. void clif_fixpos(struct block_list *bl)
  1533. {
  1534. unsigned char buf[10];
  1535. nullpo_retv(bl);
  1536. WBUFW(buf,0) = 0x88;
  1537. WBUFL(buf,2) = bl->id;
  1538. WBUFW(buf,6) = bl->x;
  1539. WBUFW(buf,8) = bl->y;
  1540. clif_send(buf, packet_len(0x88), bl, AREA);
  1541. if( disguised(bl) ) {
  1542. WBUFL(buf,2) = -bl->id;
  1543. clif_send(buf, packet_len(0x88), bl, SELF);
  1544. }
  1545. }
  1546. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1547. /// 00c4 <shop id>.L
  1548. void clif_npcbuysell(struct map_session_data* sd, int id)
  1549. {
  1550. int fd;
  1551. nullpo_retv(sd);
  1552. fd=sd->fd;
  1553. WFIFOHEAD(fd, packet_len(0xc4));
  1554. WFIFOW(fd,0)=0xc4;
  1555. WFIFOL(fd,2)=id;
  1556. WFIFOSET(fd,packet_len(0xc4));
  1557. }
  1558. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1559. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1560. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1561. {
  1562. int fd,i,c;
  1563. bool discount;
  1564. nullpo_retv(sd);
  1565. nullpo_retv(nd);
  1566. fd = sd->fd;
  1567. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1568. WFIFOW(fd,0) = 0xc6;
  1569. c = 0;
  1570. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1571. for( i = 0; i < nd->u.shop.count; i++ )
  1572. {
  1573. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1574. int val = nd->u.shop.shop_item[i].value;
  1575. if( id == NULL )
  1576. continue;
  1577. WFIFOL(fd, 4+c*11) = val;
  1578. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1579. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1580. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1581. c++;
  1582. }
  1583. WFIFOW(fd,2) = 4 + c*11;
  1584. WFIFOSET(fd,WFIFOW(fd,2));
  1585. }
  1586. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1587. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1588. void clif_selllist(struct map_session_data *sd)
  1589. {
  1590. int fd,i,c=0,val;
  1591. nullpo_retv(sd);
  1592. fd=sd->fd;
  1593. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1594. WFIFOW(fd,0)=0xc7;
  1595. for( i = 0; i < MAX_INVENTORY; i++ )
  1596. {
  1597. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1598. {
  1599. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1600. continue;
  1601. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1602. continue; // Cannot Sell Rental Items or Account Bounded Items
  1603. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1604. continue; // Don't allow sale of bound items
  1605. val=sd->inventory_data[i]->value_sell;
  1606. if( val < 0 )
  1607. continue;
  1608. WFIFOW(fd,4+c*10)=i+2;
  1609. WFIFOL(fd,6+c*10)=val;
  1610. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1611. c++;
  1612. }
  1613. }
  1614. WFIFOW(fd,2)=c*10+4;
  1615. WFIFOSET(fd,WFIFOW(fd,2));
  1616. }
  1617. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1618. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1619. /// Client behavior (dialog window):
  1620. /// - disable mouse targeting
  1621. /// - open the dialog window
  1622. /// - set npcid of dialog window (0 by default)
  1623. /// - if set to clear on next mes, clear contents
  1624. /// - append this text
  1625. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1626. {
  1627. int fd = sd->fd;
  1628. int slen = strlen(mes) + 9;
  1629. WFIFOHEAD(fd, slen);
  1630. WFIFOW(fd,0)=0xb4;
  1631. WFIFOW(fd,2)=slen;
  1632. WFIFOL(fd,4)=npcid;
  1633. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1634. WFIFOSET(fd,WFIFOW(fd,2));
  1635. }
  1636. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1637. /// 00b5 <npc id>.L
  1638. /// Client behavior (dialog window):
  1639. /// - disable mouse targeting
  1640. /// - open the dialog window
  1641. /// - add 'next' button
  1642. /// When 'next' is pressed:
  1643. /// - 00B9 <npcid of dialog window>.L
  1644. /// - set to clear on next mes
  1645. /// - remove 'next' button
  1646. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1647. {
  1648. int fd;
  1649. nullpo_retv(sd);
  1650. fd=sd->fd;
  1651. WFIFOHEAD(fd, packet_len(0xb5));
  1652. WFIFOW(fd,0)=0xb5;
  1653. WFIFOL(fd,2)=npcid;
  1654. WFIFOSET(fd,packet_len(0xb5));
  1655. }
  1656. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1657. /// 00b6 <npc id>.L
  1658. /// Client behavior:
  1659. /// - if dialog window is open:
  1660. /// - remove 'next' button
  1661. /// - add 'close' button
  1662. /// - else:
  1663. /// - enable mouse targeting
  1664. /// - close the dialog window
  1665. /// - close the menu window
  1666. /// When 'close' is pressed:
  1667. /// - enable mouse targeting
  1668. /// - close the dialog window
  1669. /// - close the menu window
  1670. /// - 0146 <npcid of dialog window>.L
  1671. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1672. {
  1673. int fd;
  1674. nullpo_retv(sd);
  1675. fd=sd->fd;
  1676. WFIFOHEAD(fd, packet_len(0xb6));
  1677. WFIFOW(fd,0)=0xb6;
  1678. WFIFOL(fd,2)=npcid;
  1679. WFIFOSET(fd,packet_len(0xb6));
  1680. }
  1681. /**
  1682. * Close script when player is idle
  1683. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1684. * @author [Ind/Hercules]
  1685. * @param sd : player pointer
  1686. * @param npcid : npc gid to close
  1687. */
  1688. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1689. {
  1690. struct s_packet_db* info;
  1691. int16 len;
  1692. int cmd = 0;
  1693. int fd;
  1694. nullpo_retv(sd);
  1695. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1696. if(!cmd) cmd = 0x8d6; //default
  1697. info = &packet_db[sd->packet_ver][cmd];
  1698. len = info->len;
  1699. fd = sd->fd;
  1700. WFIFOHEAD(fd, len);
  1701. WFIFOW(fd,0)=0x8d6;
  1702. WFIFOL(fd,info->pos[0])=npcid;
  1703. WFIFOSET(fd,len);
  1704. }
  1705. /*==========================================
  1706. *
  1707. *------------------------------------------*/
  1708. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1709. unsigned char *buf;
  1710. int fd = sd->fd;
  1711. sd->state.using_fake_npc = 1;
  1712. WFIFOHEAD(fd, packet_len(0x78));
  1713. buf = WFIFOP(fd,0);
  1714. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1715. WBUFW(buf,0)=0x78;
  1716. #if PACKETVER >= 20071106
  1717. WBUFB(buf,2) = 0; // object type
  1718. buf = WFIFOP(fd,1);
  1719. #endif
  1720. WBUFL(buf,2)=npcid;
  1721. WBUFW(buf,14)=111;
  1722. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1723. WBUFB(buf,49)=5;
  1724. WBUFB(buf,50)=5;
  1725. WFIFOSET(fd, packet_len(0x78));
  1726. }
  1727. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1728. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1729. /// Client behavior:
  1730. /// - disable mouse targeting
  1731. /// - close the menu window
  1732. /// - open the menu window
  1733. /// - add options to the menu (separated in the text by ":")
  1734. /// - set npcid of menu window
  1735. /// - if dialog window is open:
  1736. /// - remove 'next' button
  1737. /// When 'ok' is pressed:
  1738. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1739. /// - close the menu window
  1740. /// When 'cancel' is pressed:
  1741. /// - 00B8 <npcid of menu window>.L <-1>.B
  1742. /// - enable mouse targeting
  1743. /// - close a bunch of windows...
  1744. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1745. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1746. /// TODO investigate behavior of other windows [FlavioJS]
  1747. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1748. {
  1749. int fd = sd->fd;
  1750. int slen = strlen(mes) + 9;
  1751. struct block_list *bl = NULL;
  1752. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1753. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1754. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1755. clif_sendfakenpc(sd, npcid);
  1756. WFIFOHEAD(fd, slen);
  1757. WFIFOW(fd,0)=0xb7;
  1758. WFIFOW(fd,2)=slen;
  1759. WFIFOL(fd,4)=npcid;
  1760. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1761. WFIFOSET(fd,WFIFOW(fd,2));
  1762. }
  1763. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1764. /// 0142 <npc id>.L
  1765. /// Client behavior (inputnum window):
  1766. /// - if npcid exists in the client:
  1767. /// - open the inputnum window
  1768. /// - set npcid of inputnum window
  1769. /// When 'ok' is pressed:
  1770. /// - if inputnum window has text:
  1771. /// - if npcid exists in the client:
  1772. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1773. /// - close inputnum window
  1774. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1775. {
  1776. int fd;
  1777. struct block_list *bl = NULL;
  1778. nullpo_retv(sd);
  1779. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1780. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1781. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1782. clif_sendfakenpc(sd, npcid);
  1783. fd=sd->fd;
  1784. WFIFOHEAD(fd, packet_len(0x142));
  1785. WFIFOW(fd,0)=0x142;
  1786. WFIFOL(fd,2)=npcid;
  1787. WFIFOSET(fd,packet_len(0x142));
  1788. }
  1789. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1790. /// 01d4 <npc id>.L
  1791. /// Client behavior (inputstr window):
  1792. /// - if npcid is 0 or npcid exists in the client:
  1793. /// - open the inputstr window
  1794. /// - set npcid of inputstr window
  1795. /// When 'ok' is pressed:
  1796. /// - if inputstr window has text and isn't an insult(manner.txt):
  1797. /// - if npcid is 0 or npcid exists in the client:
  1798. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1799. /// - close inputstr window
  1800. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1801. {
  1802. int fd;
  1803. struct block_list *bl = NULL;
  1804. nullpo_retv(sd);
  1805. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1806. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1807. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1808. clif_sendfakenpc(sd, npcid);
  1809. fd=sd->fd;
  1810. WFIFOHEAD(fd, packet_len(0x1d4));
  1811. WFIFOW(fd,0)=0x1d4;
  1812. WFIFOL(fd,2)=npcid;
  1813. WFIFOSET(fd,packet_len(0x1d4));
  1814. }
  1815. /// Marks a position on client's minimap (ZC_COMPASS).
  1816. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1817. /// npc id:
  1818. /// is ignored in the client
  1819. /// type:
  1820. /// 0 = display mark for 15 seconds
  1821. /// 1 = display mark until dead or teleported
  1822. /// 2 = remove mark
  1823. /// color:
  1824. /// 0x00RRGGBB
  1825. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1826. {
  1827. int fd;
  1828. nullpo_retv(sd);
  1829. fd=sd->fd;
  1830. WFIFOHEAD(fd, packet_len(0x144));
  1831. WFIFOW(fd,0)=0x144;
  1832. WFIFOL(fd,2)=npc_id;
  1833. WFIFOL(fd,6)=type;
  1834. WFIFOL(fd,10)=x;
  1835. WFIFOL(fd,14)=y;
  1836. WFIFOB(fd,18)=id;
  1837. WFIFOL(fd,19)=color;
  1838. WFIFOSET(fd,packet_len(0x144));
  1839. }
  1840. /// Displays an illustration image.
  1841. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1842. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1843. /// type:
  1844. /// 0 = bottom left corner
  1845. /// 1 = bottom middle
  1846. /// 2 = bottom right corner
  1847. /// 3 = middle of screen, inside a movable window
  1848. /// 4 = middle of screen, movable with a close button, chrome-less
  1849. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1850. {
  1851. int fd;
  1852. nullpo_retv(sd);
  1853. fd=sd->fd;
  1854. WFIFOHEAD(fd, packet_len(0x1b3));
  1855. WFIFOW(fd,0)=0x1b3;
  1856. strncpy((char*)WFIFOP(fd,2),image,64);
  1857. WFIFOB(fd,66)=type;
  1858. WFIFOSET(fd,packet_len(0x1b3));
  1859. }
  1860. /*==========================================
  1861. * Fills in card data from the given item and into the buffer. [Skotlex]
  1862. *------------------------------------------*/
  1863. static void clif_addcards(unsigned char* buf, struct item* item)
  1864. {
  1865. int i=0,j;
  1866. if( item == NULL ) { //Blank data
  1867. WBUFW(buf,0) = 0;
  1868. WBUFW(buf,2) = 0;
  1869. WBUFW(buf,4) = 0;
  1870. WBUFW(buf,6) = 0;
  1871. return;
  1872. }
  1873. if( item->card[0] == CARD0_PET ) { //pet eggs
  1874. WBUFW(buf,0) = 0;
  1875. WBUFW(buf,2) = 0;
  1876. WBUFW(buf,4) = 0;
  1877. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1878. return;
  1879. }
  1880. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1881. WBUFW(buf,0) = item->card[0];
  1882. WBUFW(buf,2) = item->card[1];
  1883. WBUFW(buf,4) = item->card[2];
  1884. WBUFW(buf,6) = item->card[3];
  1885. return;
  1886. }
  1887. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1888. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1889. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1890. //Normal items.
  1891. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1892. WBUFW(buf,0) = j;
  1893. else
  1894. WBUFW(buf,0) = item->card[i];
  1895. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1896. WBUFW(buf,2) = j;
  1897. else
  1898. WBUFW(buf,2) = item->card[i];
  1899. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1900. WBUFW(buf,4) = j;
  1901. else
  1902. WBUFW(buf,4) = item->card[i];
  1903. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1904. WBUFW(buf,6) = j;
  1905. else
  1906. WBUFW(buf,6) = item->card[i];
  1907. }
  1908. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1909. /// 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)
  1910. /// 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)
  1911. /// 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)
  1912. /// 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)
  1913. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  1914. {
  1915. int fd, header, offs=0;
  1916. #if PACKETVER < 20061218
  1917. header = 0xa0;
  1918. #elif PACKETVER < 20071002
  1919. header = 0x29a;
  1920. #elif PACKETVER < 20120925
  1921. header = 0x2d4;
  1922. #else
  1923. header = 0x990;
  1924. #endif
  1925. nullpo_retv(sd);
  1926. fd = sd->fd;
  1927. if( !session_isActive(fd) ) //Sasuke-
  1928. return;
  1929. WFIFOHEAD(fd,packet_len(header));
  1930. if( fail )
  1931. {
  1932. WFIFOW(fd,offs+0)=header;
  1933. WFIFOW(fd,offs+2)=n+2;
  1934. WFIFOW(fd,offs+4)=amount;
  1935. WFIFOW(fd,offs+6)=0;
  1936. WFIFOB(fd,offs+8)=0;
  1937. WFIFOB(fd,offs+9)=0;
  1938. WFIFOB(fd,offs+10)=0;
  1939. WFIFOW(fd,offs+11)=0;
  1940. WFIFOW(fd,offs+13)=0;
  1941. WFIFOW(fd,offs+15)=0;
  1942. WFIFOW(fd,offs+17)=0;
  1943. #if PACKETVER < 20120925
  1944. WFIFOW(fd,offs+19)=0;
  1945. #else
  1946. WFIFOL(fd,offs+19)=0;
  1947. offs += 2;
  1948. #endif
  1949. WFIFOB(fd,offs+21)=0;
  1950. WFIFOB(fd,offs+22)=fail;
  1951. #if PACKETVER >= 20061218
  1952. WFIFOL(fd,offs+23)=0;
  1953. #endif
  1954. #if PACKETVER >= 20071002
  1955. WFIFOW(fd,offs+27)=0; // HireExpireDate
  1956. #endif
  1957. }
  1958. else
  1959. {
  1960. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1961. return;
  1962. WFIFOW(fd,offs+0)=header;
  1963. WFIFOW(fd,offs+2)=n+2;
  1964. WFIFOW(fd,offs+4)=amount;
  1965. if (sd->inventory_data[n]->view_id > 0)
  1966. WFIFOW(fd,offs+6)=sd->inventory_data[n]->view_id;
  1967. else
  1968. WFIFOW(fd,offs+6)=sd->status.inventory[n].nameid;
  1969. WFIFOB(fd,offs+8)=sd->status.inventory[n].identify;
  1970. WFIFOB(fd,offs+9)=sd->status.inventory[n].attribute;
  1971. WFIFOB(fd,offs+10)=sd->status.inventory[n].refine;
  1972. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  1973. #if PACKETVER < 20120925
  1974. WFIFOW(fd,offs+19)=pc_equippoint(sd,n);
  1975. #else
  1976. WFIFOL(fd,offs+19)=pc_equippoint(sd,n);
  1977. offs += 2;
  1978. #endif
  1979. WFIFOB(fd,offs+21)=itemtype(sd->inventory_data[n]->nameid);
  1980. WFIFOB(fd,offs+22)=fail;
  1981. #if PACKETVER >= 20061218
  1982. WFIFOL(fd,offs+23)=sd->status.inventory[n].expire_time;
  1983. #endif
  1984. #if PACKETVER >= 20071002
  1985. /* Yellow color only for non-stackable item */
  1986. WFIFOW(fd,offs+27)=(sd->status.inventory[n].bound && !itemdb_isstackable(sd->status.inventory[n].nameid)) ? BOUND_DISPYELLOW : 0;
  1987. #endif
  1988. }
  1989. WFIFOSET(fd,packet_len(header));
  1990. }
  1991. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1992. /// 00af <index>.W <amount>.W
  1993. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1994. {
  1995. int fd;
  1996. nullpo_retv(sd);
  1997. fd=sd->fd;
  1998. WFIFOHEAD(fd, packet_len(0xaf));
  1999. WFIFOW(fd,0)=0xaf;
  2000. WFIFOW(fd,2)=n+2;
  2001. WFIFOW(fd,4)=amount;
  2002. WFIFOSET(fd,packet_len(0xaf));
  2003. }
  2004. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2005. /// 07fa <delete type>.W <index>.W <amount>.W
  2006. /// delete type:
  2007. /// 0 = Normal
  2008. /// 1 = Item used for a skill
  2009. /// 2 = Refine failed
  2010. /// 3 = Material changed
  2011. /// 4 = Moved to storage
  2012. /// 5 = Moved to cart
  2013. /// 6 = Item sold
  2014. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2015. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2016. {
  2017. #if PACKETVER < 20091117
  2018. clif_dropitem(sd,n,amount);
  2019. #else
  2020. int fd;
  2021. nullpo_retv(sd);
  2022. fd=sd->fd;
  2023. WFIFOHEAD(fd, packet_len(0x7fa));
  2024. WFIFOW(fd,0)=0x7fa;
  2025. WFIFOW(fd,2)=reason;
  2026. WFIFOW(fd,4)=n+2;
  2027. WFIFOW(fd,6)=amount;
  2028. WFIFOSET(fd,packet_len(0x7fa));
  2029. #endif
  2030. }
  2031. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2032. char normal = (equip < 0);
  2033. WBUFW(buf,n) = idx; //index
  2034. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2035. WBUFB(buf,n+4) = itemtype(id->nameid);
  2036. if (!normal){ //equip 31B
  2037. WBUFL(buf,n+5) = equip; //location
  2038. WBUFL(buf,n+9) = it->equip; //wear state
  2039. WBUFB(buf,n+13) = it->refine; //refine lvl
  2040. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2041. WBUFL(buf,n+22) = it->expire_time;
  2042. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : 0; //bindOnEquipType
  2043. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2044. //V5_ITEM_flag
  2045. WBUFB(buf,n+30) = it->identify; //0x1 IsIdentified
  2046. WBUFB(buf,n+30) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2047. WBUFB(buf,n+30) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2048. }
  2049. else { //normal 24B
  2050. WBUFW(buf,n+5) = it->amount;
  2051. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2052. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2053. WBUFL(buf,n+19) = it->expire_time;
  2054. //V5_ITEM_flag
  2055. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2056. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2057. }
  2058. }
  2059. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2060. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2061. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2062. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2063. #if PACKETVER >= 20120925
  2064. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2065. #else
  2066. WBUFW(buf,n) = idx; //index
  2067. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2068. WBUFB(buf,n+4) = itemtype(id->nameid);
  2069. WBUFB(buf,n+5) = it->identify;
  2070. if (equip >= 0) { //Equippable item 28.B
  2071. WBUFW(buf,n+6) = equip;
  2072. WBUFW(buf,n+8) = it->equip;
  2073. WBUFB(buf,n+10) = it->attribute;
  2074. WBUFB(buf,n+11) = it->refine;
  2075. clif_addcards(WBUFP(buf, n+12), it); //8B
  2076. #if PACKETVER >= 20071002
  2077. WBUFL(buf,n+20) = it->expire_time;
  2078. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : 0;
  2079. #endif
  2080. #if PACKETVER >= 20100629
  2081. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2082. #endif
  2083. } else { //Stackable item. 22.B
  2084. WBUFW(buf,n+6) = it->amount;
  2085. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2086. clif_addcards(WBUFP(buf, n+10), it); //8B
  2087. #if PACKETVER >= 20071002
  2088. WBUFL(buf,n+18) = it->expire_time;
  2089. #endif
  2090. }
  2091. #endif
  2092. }
  2093. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2094. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2095. void clif_inventorylist(struct map_session_data *sd) {
  2096. int i,n,ne,arrow=-1;
  2097. unsigned char *buf;
  2098. unsigned char *bufe;
  2099. #if PACKETVER < 5
  2100. const int s = 10; //Entry size
  2101. #elif PACKETVER < 20080102
  2102. const int s = 18;
  2103. #elif PACKETVER < 20120925
  2104. const int s = 22;
  2105. #else
  2106. const int s = 24;
  2107. #endif
  2108. #if PACKETVER < 20071002
  2109. const int se = 20;
  2110. #elif PACKETVER < 20100629
  2111. const int se = 26;
  2112. #elif PACKETVER < 20120925
  2113. const int se = 28;
  2114. #else
  2115. const int se = 31;
  2116. #endif
  2117. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2118. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2119. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2120. {
  2121. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2122. continue;
  2123. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2124. { //Non-stackable (Equippable)
  2125. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2126. ne++;
  2127. }
  2128. else { //Stackable.
  2129. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2130. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2131. arrow=i;
  2132. n++;
  2133. }
  2134. }
  2135. if( n )
  2136. {
  2137. #if PACKETVER < 5
  2138. WBUFW(buf,0)=0xa3;
  2139. #elif PACKETVER < 20080102
  2140. WBUFW(buf,0)=0x1ee;
  2141. #elif PACKETVER < 20120925
  2142. WBUFW(buf,0)=0x2e8;
  2143. #else
  2144. WBUFW(buf,0)=0x991;
  2145. #endif
  2146. WBUFW(buf,2)=4+n*s;
  2147. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2148. }
  2149. if( arrow >= 0 )
  2150. clif_arrowequip(sd,arrow);
  2151. if( ne ) {
  2152. #if PACKETVER < 20071002
  2153. WBUFW(bufe,0)=0xa4;
  2154. #elif PACKETVER < 20120925
  2155. WBUFW(bufe,0)=0x2d0;
  2156. #else
  2157. WBUFW(bufe,0)=0x992;
  2158. #endif
  2159. WBUFW(bufe,2)=4+ne*se;
  2160. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2161. }
  2162. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2163. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2164. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2165. continue;
  2166. if ( sd->status.inventory[i].favorite )
  2167. clif_favorite_item(sd, i);
  2168. }
  2169. #endif
  2170. if( buf ) aFree(buf);
  2171. if( bufe ) aFree(bufe);
  2172. }
  2173. //Required when items break/get-repaired. Only sends equippable item list.
  2174. void clif_equiplist(struct map_session_data *sd)
  2175. {
  2176. int i,n,fd = sd->fd;
  2177. unsigned char *buf;
  2178. #if PACKETVER < 20071002
  2179. const int cmd = 20;
  2180. #elif PACKETVER < 20100629
  2181. const int cmd = 26;
  2182. #elif PACKETVER < 20120925
  2183. const int cmd = 28;
  2184. #else
  2185. const int cmd = 31;
  2186. #endif
  2187. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2188. buf = WFIFOP(fd,0);
  2189. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2190. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2191. continue;
  2192. if(itemdb_isstackable2(sd->inventory_data[i]))
  2193. continue;
  2194. //Equippable
  2195. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2196. n++;
  2197. }
  2198. if (n) {
  2199. #if PACKETVER < 20071002
  2200. WBUFW(buf,0)=0xa4;
  2201. #elif PACKETVER < 20120925
  2202. WBUFW(buf,0)=0x2d0;
  2203. #else
  2204. WBUFW(buf,0)=0x992;
  2205. #endif
  2206. WBUFW(buf,2)=4+n*cmd;
  2207. WFIFOSET(fd,WFIFOW(fd,2));
  2208. }
  2209. }
  2210. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2211. {
  2212. static const int client_buf = 0x5000; // Max buffer to send
  2213. struct item_data *id;
  2214. int i,n,ne,nn;
  2215. unsigned char *buf;
  2216. unsigned char *bufe;
  2217. #if PACKETVER < 5
  2218. const int s = 10; //Entry size.normal item
  2219. const int sidx=4; //start itemlist idx
  2220. const int cmd = 0xa5;
  2221. #elif PACKETVER < 20080102
  2222. const int s = 18;
  2223. const int sidx=4;
  2224. const int cmd = 0x1f0;
  2225. #elif PACKETVER < 20120925
  2226. const int s = 22;
  2227. const int sidx=4;
  2228. const int cmd = 0x2ea;
  2229. #else
  2230. const int s = 24;
  2231. const int sidx = 4+24;
  2232. const int cmd = 0x995;
  2233. #endif
  2234. #if PACKETVER < 20071002
  2235. const int se = 20; //entry size equip
  2236. const int sidxe = 4; //start itemlist idx
  2237. const int cmde = 0xa6;
  2238. #elif PACKETVER < 20100629
  2239. const int se = 26;
  2240. const int sidxe = 4;
  2241. const int cmde = 0x2d1;
  2242. #elif PACKETVER < 20120925
  2243. const int se = 28;
  2244. const int sidxe = 4;
  2245. const int cmde = 0x2d1;
  2246. #else
  2247. const int se = 31;
  2248. const int sidxe = 4+24;
  2249. const int cmde = 0x996;
  2250. #endif
  2251. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2252. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2253. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2254. {
  2255. if( items[i].nameid <= 0 )
  2256. continue;
  2257. id = itemdb_search(items[i].nameid);
  2258. if( !itemdb_isstackable2(id) ) { //Equippable
  2259. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2260. ne++;
  2261. }
  2262. else { //Stackable
  2263. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2264. n++;
  2265. }
  2266. }
  2267. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2268. {
  2269. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2270. WFIFOHEAD(sd->fd,sidx+nn*s);
  2271. WFIFOW(sd->fd,0)=cmd;
  2272. WFIFOW(sd->fd,2)=sidx+nn*s;
  2273. #if PACKETVER >= 20120925
  2274. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2275. #endif
  2276. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2277. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2278. }
  2279. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2280. {
  2281. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2282. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2283. WFIFOW(sd->fd,0)=cmde;
  2284. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2285. #if PACKETVER >= 20120925
  2286. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2287. #endif
  2288. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2289. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2290. }
  2291. if( buf ) aFree(buf);
  2292. if( bufe ) aFree(bufe);
  2293. }
  2294. void clif_cartlist(struct map_session_data *sd)
  2295. {
  2296. struct item_data *id;
  2297. int i,n,ne;
  2298. unsigned char *buf;
  2299. unsigned char *bufe;
  2300. #if PACKETVER < 5
  2301. const int s = 10; //Entry size.
  2302. #elif PACKETVER < 20080102
  2303. const int s = 18;
  2304. #elif PACKETVER < 20120925
  2305. const int s = 22;
  2306. #else
  2307. const int s = 24;
  2308. #endif
  2309. #if PACKETVER < 20071002
  2310. const int cmd = 20;
  2311. #elif PACKETVER < 20100629
  2312. const int cmd = 26;
  2313. #elif PACKETVER < 20120925
  2314. const int cmd = 28;
  2315. #else
  2316. const int cmd = 31;
  2317. #endif
  2318. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2319. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2320. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2321. {
  2322. if( sd->status.cart[i].nameid <= 0 )
  2323. continue;
  2324. id = itemdb_search(sd->status.cart[i].nameid);
  2325. if( !itemdb_isstackable2(id) ) { //Equippable
  2326. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2327. ne++;
  2328. }
  2329. else { //Stackable
  2330. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2331. n++;
  2332. }
  2333. }
  2334. if( n )
  2335. {
  2336. #if PACKETVER < 5
  2337. WBUFW(buf,0)=0x123;
  2338. #elif PACKETVER < 20080102
  2339. WBUFW(buf,0)=0x1ef;
  2340. #elif PACKETVER < 20120925
  2341. WBUFW(buf,0)=0x2e9;
  2342. #else
  2343. WBUFW(buf,0)=0x993;
  2344. #endif
  2345. WBUFW(buf,2)=4+n*s;
  2346. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2347. }
  2348. if( ne )
  2349. {
  2350. #if PACKETVER < 20071002
  2351. WBUFW(bufe,0)=0x122;
  2352. #elif PACKETVER < 20120925
  2353. WBUFW(bufe,0)=0x2d2;
  2354. #else
  2355. WBUFW(bufe,0)=0x994;
  2356. #endif
  2357. WBUFW(bufe,2)=4+ne*cmd;
  2358. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2359. }
  2360. if( buf ) aFree(buf);
  2361. if( bufe ) aFree(bufe);
  2362. }
  2363. /// Removes cart (ZC_CARTOFF).
  2364. /// 012b
  2365. /// Client behaviour:
  2366. /// Closes the cart storage and removes all it's items from memory.
  2367. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2368. void clif_clearcart(int fd)
  2369. {
  2370. WFIFOHEAD(fd, packet_len(0x12b));
  2371. WFIFOW(fd,0) = 0x12b;
  2372. WFIFOSET(fd, packet_len(0x12b));
  2373. }
  2374. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2375. /// 01eb <account id>.L <x>.W <y>.W
  2376. void clif_guild_xy(struct map_session_data *sd)
  2377. {
  2378. unsigned char buf[10];
  2379. nullpo_retv(sd);
  2380. WBUFW(buf,0)=0x1eb;
  2381. WBUFL(buf,2)=sd->status.account_id;
  2382. WBUFW(buf,6)=sd->bl.x;
  2383. WBUFW(buf,8)=sd->bl.y;
  2384. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2385. }
  2386. /*==========================================
  2387. * Sends x/y dot to a single fd. [Skotlex]
  2388. *------------------------------------------*/
  2389. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2390. {
  2391. if( sd->bg_id )
  2392. return;
  2393. WFIFOHEAD(fd,packet_len(0x1eb));
  2394. WFIFOW(fd,0)=0x1eb;
  2395. WFIFOL(fd,2)=sd->status.account_id;
  2396. WFIFOW(fd,6)=sd->bl.x;
  2397. WFIFOW(fd,8)=sd->bl.y;
  2398. WFIFOSET(fd,packet_len(0x1eb));
  2399. }
  2400. // Guild XY locators [Valaris]
  2401. void clif_guild_xy_remove(struct map_session_data *sd)
  2402. {
  2403. unsigned char buf[10];
  2404. nullpo_retv(sd);
  2405. WBUFW(buf,0)=0x1eb;
  2406. WBUFL(buf,2)=sd->status.account_id;
  2407. WBUFW(buf,6)=-1;
  2408. WBUFW(buf,8)=-1;
  2409. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2410. }
  2411. /*==========================================
  2412. *
  2413. *------------------------------------------*/
  2414. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2415. {
  2416. struct map_session_data *sd, *tsd;
  2417. #if PACKETVER < 20100126
  2418. const int cmd = 0x106;
  2419. #else
  2420. const int cmd = 0x80e;
  2421. #endif
  2422. sd = va_arg(ap, struct map_session_data *);
  2423. tsd = (TBL_PC *)bl;
  2424. nullpo_ret(sd);
  2425. nullpo_ret(tsd);
  2426. if( !tsd->fd || tsd == sd )
  2427. return 0;
  2428. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2429. return 0;
  2430. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2431. WFIFOW(tsd->fd,0) = cmd;
  2432. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2433. #if PACKETVER < 20100126
  2434. if( sd->battle_status.max_hp > INT16_MAX )
  2435. { //To correctly display the %hp bar. [Skotlex]
  2436. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2437. WFIFOW(tsd->fd,8) = 100;
  2438. } else {
  2439. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2440. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2441. }
  2442. #else
  2443. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2444. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2445. #endif
  2446. WFIFOSET(tsd->fd,packet_len(cmd));
  2447. return 0;
  2448. }
  2449. /*==========================================
  2450. * Server tells all players that are allowed to view HP bars
  2451. * and are nearby 'sd' that 'sd' hp bar was updated.
  2452. *------------------------------------------*/
  2453. static int clif_hpmeter(struct map_session_data *sd)
  2454. {
  2455. nullpo_ret(sd);
  2456. 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);
  2457. return 0;
  2458. }
  2459. /// Notifies client of a character parameter change.
  2460. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2461. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2462. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2463. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2464. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2465. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2466. /// TODO: Extract individual packets.
  2467. /// FIXME: Packet lengths from packet_len(cmd)
  2468. void clif_updatestatus(struct map_session_data *sd,int type)
  2469. {
  2470. int fd,len=8;
  2471. nullpo_retv(sd);
  2472. fd=sd->fd;
  2473. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2474. return;
  2475. WFIFOHEAD(fd, 14);
  2476. WFIFOW(fd,0)=0xb0;
  2477. WFIFOW(fd,2)=type;
  2478. switch(type){
  2479. // 00b0
  2480. case SP_WEIGHT:
  2481. pc_updateweightstatus(sd);
  2482. WFIFOHEAD(fd,14);
  2483. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2484. WFIFOW(fd,2)=type;
  2485. WFIFOL(fd,4)=sd->weight;
  2486. break;
  2487. case SP_MAXWEIGHT:
  2488. WFIFOL(fd,4)=sd->max_weight;
  2489. break;
  2490. case SP_SPEED:
  2491. WFIFOL(fd,4)=sd->battle_status.speed;
  2492. break;
  2493. case SP_BASELEVEL:
  2494. WFIFOL(fd,4)=sd->status.base_level;
  2495. break;
  2496. case SP_JOBLEVEL:
  2497. WFIFOL(fd,4)=sd->status.job_level;
  2498. break;
  2499. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2500. WFIFOL(fd,4)=sd->status.karma;
  2501. break;
  2502. case SP_MANNER:
  2503. WFIFOL(fd,4)=sd->status.manner;
  2504. break;
  2505. case SP_STATUSPOINT:
  2506. WFIFOL(fd,4)=sd->status.status_point;
  2507. break;
  2508. case SP_SKILLPOINT:
  2509. WFIFOL(fd,4)=sd->status.skill_point;
  2510. break;
  2511. case SP_HIT:
  2512. WFIFOL(fd,4)=sd->battle_status.hit;
  2513. break;
  2514. case SP_FLEE1:
  2515. WFIFOL(fd,4)=sd->battle_status.flee;
  2516. break;
  2517. case SP_FLEE2:
  2518. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2519. break;
  2520. case SP_MAXHP:
  2521. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2522. break;
  2523. case SP_MAXSP:
  2524. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2525. break;
  2526. case SP_HP:
  2527. WFIFOL(fd,4)=sd->battle_status.hp;
  2528. // TODO: Won't these overwrite the current packet?
  2529. if( map[sd->bl.m].hpmeter_visible )
  2530. clif_hpmeter(sd);
  2531. if( !battle_config.party_hp_mode && sd->status.party_id )
  2532. clif_party_hp(sd);
  2533. if( sd->bg_id )
  2534. clif_bg_hp(sd);
  2535. break;
  2536. case SP_SP:
  2537. WFIFOL(fd,4)=sd->battle_status.sp;
  2538. break;
  2539. case SP_ASPD:
  2540. WFIFOL(fd,4)=sd->battle_status.amotion;
  2541. break;
  2542. case SP_ATK1:
  2543. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2544. break;
  2545. case SP_DEF1:
  2546. WFIFOL(fd,4)=pc_leftside_def(sd);
  2547. break;
  2548. case SP_MDEF1:
  2549. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2550. break;
  2551. case SP_ATK2:
  2552. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2553. break;
  2554. case SP_DEF2:
  2555. WFIFOL(fd,4)=pc_rightside_def(sd);
  2556. break;
  2557. case SP_MDEF2: {
  2558. //negative check (in case you have something like Berserk active)
  2559. int mdef2 = pc_rightside_mdef(sd);
  2560. WFIFOL(fd,4)=
  2561. #ifndef RENEWAL
  2562. ( mdef2 < 0 ) ? 0 :
  2563. #endif
  2564. mdef2;
  2565. }
  2566. break;
  2567. case SP_CRITICAL:
  2568. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2569. break;
  2570. case SP_MATK1:
  2571. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2572. break;
  2573. case SP_MATK2:
  2574. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2575. break;
  2576. case SP_ZENY:
  2577. WFIFOW(fd,0)=0xb1;
  2578. WFIFOL(fd,4)=sd->status.zeny;
  2579. break;
  2580. case SP_BASEEXP:
  2581. WFIFOW(fd,0)=0xb1;
  2582. WFIFOL(fd,4)=sd->status.base_exp;
  2583. break;
  2584. case SP_JOBEXP:
  2585. WFIFOW(fd,0)=0xb1;
  2586. WFIFOL(fd,4)=sd->status.job_exp;
  2587. break;
  2588. case SP_NEXTBASEEXP:
  2589. WFIFOW(fd,0)=0xb1;
  2590. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2591. break;
  2592. case SP_NEXTJOBEXP:
  2593. WFIFOW(fd,0)=0xb1;
  2594. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2595. break;
  2596. /**
  2597. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2598. **/
  2599. case SP_USTR:
  2600. case SP_UAGI:
  2601. case SP_UVIT:
  2602. case SP_UINT:
  2603. case SP_UDEX:
  2604. case SP_ULUK:
  2605. WFIFOW(fd,0)=0xbe;
  2606. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2607. len=5;
  2608. break;
  2609. /**
  2610. * Tells the client how far it is allowed to attack (weapon range)
  2611. **/
  2612. case SP_ATTACKRANGE:
  2613. WFIFOW(fd,0)=0x13a;
  2614. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2615. len=4;
  2616. break;
  2617. case SP_STR:
  2618. WFIFOW(fd,0)=0x141;
  2619. WFIFOL(fd,2)=type;
  2620. WFIFOL(fd,6)=sd->status.str;
  2621. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2622. len=14;
  2623. break;
  2624. case SP_AGI:
  2625. WFIFOW(fd,0)=0x141;
  2626. WFIFOL(fd,2)=type;
  2627. WFIFOL(fd,6)=sd->status.agi;
  2628. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2629. len=14;
  2630. break;
  2631. case SP_VIT:
  2632. WFIFOW(fd,0)=0x141;
  2633. WFIFOL(fd,2)=type;
  2634. WFIFOL(fd,6)=sd->status.vit;
  2635. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2636. len=14;
  2637. break;
  2638. case SP_INT:
  2639. WFIFOW(fd,0)=0x141;
  2640. WFIFOL(fd,2)=type;
  2641. WFIFOL(fd,6)=sd->status.int_;
  2642. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2643. len=14;
  2644. break;
  2645. case SP_DEX:
  2646. WFIFOW(fd,0)=0x141;
  2647. WFIFOL(fd,2)=type;
  2648. WFIFOL(fd,6)=sd->status.dex;
  2649. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2650. len=14;
  2651. break;
  2652. case SP_LUK:
  2653. WFIFOW(fd,0)=0x141;
  2654. WFIFOL(fd,2)=type;
  2655. WFIFOL(fd,6)=sd->status.luk;
  2656. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2657. len=14;
  2658. break;
  2659. case SP_CARTINFO:
  2660. WFIFOW(fd,0)=0x121;
  2661. WFIFOW(fd,2)=sd->cart_num;
  2662. WFIFOW(fd,4)=MAX_CART;
  2663. WFIFOL(fd,6)=sd->cart_weight;
  2664. WFIFOL(fd,10)=sd->cart_weight_max;
  2665. len=14;
  2666. break;
  2667. default:
  2668. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2669. return;
  2670. }
  2671. WFIFOSET(fd,len);
  2672. }
  2673. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2674. /// 01ab <account id>.L <var id>.W <value>.L
  2675. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2676. {
  2677. unsigned char buf[12];
  2678. nullpo_retv(sd);
  2679. WBUFW(buf,0)=0x1ab;
  2680. WBUFL(buf,2)=sd->bl.id;
  2681. WBUFW(buf,6)=type;
  2682. switch(type)
  2683. {
  2684. case SP_MANNER:
  2685. WBUFL(buf,8)=val;
  2686. break;
  2687. default:
  2688. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2689. return;
  2690. }
  2691. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2692. }
  2693. /// Updates sprite/style properties of an object.
  2694. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2695. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2696. void clif_changelook(struct block_list *bl,int type,int val)
  2697. {
  2698. unsigned char buf[16];
  2699. struct map_session_data* sd;
  2700. struct status_change* sc;
  2701. struct view_data* vd;
  2702. enum send_target target = AREA;
  2703. nullpo_retv(bl);
  2704. sd = BL_CAST(BL_PC, bl);
  2705. sc = status_get_sc(bl);
  2706. vd = status_get_viewdata(bl);
  2707. //nullpo_ret(vd);
  2708. if( vd ) //temp hack to let Warp Portal change appearance
  2709. switch(type)
  2710. {
  2711. case LOOK_WEAPON:
  2712. if (sd)
  2713. {
  2714. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2715. val = vd->weapon;
  2716. }
  2717. else vd->weapon = val;
  2718. break;
  2719. case LOOK_SHIELD:
  2720. if (sd)
  2721. {
  2722. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2723. val = vd->shield;
  2724. }
  2725. else vd->shield = val;
  2726. break;
  2727. case LOOK_BASE:
  2728. if (!sd) break;
  2729. if (sd->sc.option&OPTION_COSTUME)
  2730. vd->weapon = vd->shield = 0;
  2731. if (!vd->cloth_color)
  2732. break;
  2733. if (sd) {
  2734. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2735. vd->cloth_color = 0;
  2736. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2737. vd->cloth_color = 0;
  2738. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2739. vd->cloth_color = 0;
  2740. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2741. vd->cloth_color = 0;
  2742. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2743. vd->cloth_color = 0;
  2744. }
  2745. break;
  2746. case LOOK_HAIR:
  2747. vd->hair_style = val;
  2748. break;
  2749. case LOOK_HEAD_BOTTOM:
  2750. vd->head_bottom = val;
  2751. break;
  2752. case LOOK_HEAD_TOP:
  2753. vd->head_top = val;
  2754. break;
  2755. case LOOK_HEAD_MID:
  2756. vd->head_mid = val;
  2757. break;
  2758. case LOOK_HAIR_COLOR:
  2759. vd->hair_color = val;
  2760. break;
  2761. case LOOK_CLOTHES_COLOR:
  2762. if (val && sd) {
  2763. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2764. val = 0;
  2765. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2766. val = 0;
  2767. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2768. val = 0;
  2769. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2770. val = 0;
  2771. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2772. val = 0;
  2773. }
  2774. vd->cloth_color = val;
  2775. break;
  2776. case LOOK_SHOES:
  2777. #if PACKETVER > 3
  2778. if (sd) {
  2779. int n;
  2780. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2781. if(sd->inventory_data[n]->view_id > 0)
  2782. val = sd->inventory_data[n]->view_id;
  2783. else
  2784. val = sd->status.inventory[n].nameid;
  2785. } else
  2786. val = 0;
  2787. }
  2788. #endif
  2789. //Shoes? No packet uses this....
  2790. break;
  2791. case LOOK_BODY:
  2792. // unknown purpose
  2793. break;
  2794. case LOOK_ROBE:
  2795. #if PACKETVER < 20110111
  2796. return;
  2797. #else
  2798. vd->robe = val;
  2799. #endif
  2800. break;
  2801. }
  2802. // prevent leaking the presence of GM-hidden objects
  2803. if( sc && sc->option&OPTION_INVISIBLE )
  2804. target = SELF;
  2805. #if PACKETVER < 4
  2806. WBUFW(buf,0)=0xc3;
  2807. WBUFL(buf,2)=bl->id;
  2808. WBUFB(buf,6)=type;
  2809. WBUFB(buf,7)=val;
  2810. clif_send(buf,packet_len(0xc3),bl,target);
  2811. #else
  2812. WBUFW(buf,0)=0x1d7;
  2813. WBUFL(buf,2)=bl->id;
  2814. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2815. WBUFB(buf,6)=LOOK_WEAPON;
  2816. WBUFW(buf,7)=vd->weapon;
  2817. WBUFW(buf,9)=vd->shield;
  2818. } else {
  2819. WBUFB(buf,6)=type;
  2820. WBUFL(buf,7)=val;
  2821. }
  2822. clif_send(buf,packet_len(0x1d7),bl,target);
  2823. #endif
  2824. }
  2825. //Sends a change-base-look packet required for traps as they are triggered.
  2826. void clif_changetraplook(struct block_list *bl,int val)
  2827. {
  2828. unsigned char buf[32];
  2829. #if PACKETVER < 4
  2830. WBUFW(buf,0)=0xc3;
  2831. WBUFL(buf,2)=bl->id;
  2832. WBUFB(buf,6)=LOOK_BASE;
  2833. WBUFB(buf,7)=val;
  2834. clif_send(buf,packet_len(0xc3),bl,AREA);
  2835. #else
  2836. WBUFW(buf,0)=0x1d7;
  2837. WBUFL(buf,2)=bl->id;
  2838. WBUFB(buf,6)=LOOK_BASE;
  2839. WBUFW(buf,7)=val;
  2840. WBUFW(buf,9)=0;
  2841. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2842. #endif
  2843. }
  2844. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2845. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2846. {
  2847. unsigned char buf[32];
  2848. #if PACKETVER < 4
  2849. WBUFW(buf,0)=0xc3;
  2850. WBUFL(buf,2)=id;
  2851. WBUFB(buf,6)=type;
  2852. WBUFB(buf,7)=val;
  2853. clif_send(buf,packet_len(0xc3),bl,target);
  2854. #else
  2855. WBUFW(buf,0)=0x1d7;
  2856. WBUFL(buf,2)=id;
  2857. WBUFB(buf,6)=type;
  2858. WBUFW(buf,7)=val;
  2859. WBUFW(buf,9)=0;
  2860. clif_send(buf,packet_len(0x1d7),bl,target);
  2861. #endif
  2862. }
  2863. /// Character status (ZC_STATUS).
  2864. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2865. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2866. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2867. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2868. void clif_initialstatus(struct map_session_data *sd) {
  2869. int fd, mdef2;
  2870. unsigned char *buf;
  2871. nullpo_retv(sd);
  2872. fd=sd->fd;
  2873. WFIFOHEAD(fd,packet_len(0xbd));
  2874. buf=WFIFOP(fd,0);
  2875. WBUFW(buf,0)=0xbd;
  2876. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2877. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2878. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2879. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2880. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2881. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2882. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2883. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2884. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2885. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2886. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2887. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2888. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2889. WBUFW(buf,16) = pc_leftside_atk(sd);
  2890. WBUFW(buf,18) = pc_rightside_atk(sd);
  2891. WBUFW(buf,20) = pc_rightside_matk(sd);
  2892. WBUFW(buf,22) = pc_leftside_matk(sd);
  2893. WBUFW(buf,24) = pc_leftside_def(sd);
  2894. WBUFW(buf,26) = pc_rightside_def(sd);
  2895. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2896. mdef2 = pc_rightside_mdef(sd);
  2897. WBUFW(buf,30) =
  2898. #ifndef RENEWAL
  2899. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2900. #endif
  2901. mdef2;
  2902. WBUFW(buf,32) = sd->battle_status.hit;
  2903. WBUFW(buf,34) = sd->battle_status.flee;
  2904. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2905. WBUFW(buf,38) = sd->battle_status.cri/10;
  2906. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2907. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2908. WFIFOSET(fd,packet_len(0xbd));
  2909. clif_updatestatus(sd,SP_STR);
  2910. clif_updatestatus(sd,SP_AGI);
  2911. clif_updatestatus(sd,SP_VIT);
  2912. clif_updatestatus(sd,SP_INT);
  2913. clif_updatestatus(sd,SP_DEX);
  2914. clif_updatestatus(sd,SP_LUK);
  2915. clif_updatestatus(sd,SP_ATTACKRANGE);
  2916. clif_updatestatus(sd,SP_ASPD);
  2917. }
  2918. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2919. /// 013c <index>.W
  2920. void clif_arrowequip(struct map_session_data *sd,int val)
  2921. {
  2922. int fd;
  2923. nullpo_retv(sd);
  2924. #if PACKETVER >= 20121128
  2925. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2926. #endif
  2927. fd=sd->fd;
  2928. WFIFOHEAD(fd, packet_len(0x013c));
  2929. WFIFOW(fd,0)=0x013c;
  2930. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2931. WFIFOSET(fd,packet_len(0x013c));
  2932. }
  2933. /// Ammunition action message (ZC_ACTION_FAILURE).
  2934. /// 013b <type>.W
  2935. /// type:
  2936. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2937. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2938. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2939. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2940. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2941. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2942. void clif_arrow_fail(struct map_session_data *sd,int type)
  2943. {
  2944. int fd;
  2945. nullpo_retv(sd);
  2946. fd=sd->fd;
  2947. WFIFOHEAD(fd, packet_len(0x013b));
  2948. WFIFOW(fd,0)=0x013b;
  2949. WFIFOW(fd,2)=type;
  2950. WFIFOSET(fd,packet_len(0x013b));
  2951. }
  2952. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2953. /// 01ad <packet len>.W { <name id>.W }*
  2954. void clif_arrow_create_list(struct map_session_data *sd)
  2955. {
  2956. int i, c;
  2957. int fd;
  2958. nullpo_retv(sd);
  2959. fd = sd->fd;
  2960. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2961. WFIFOW(fd,0) = 0x1ad;
  2962. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2963. short j, nameid = skill_arrow_db[i].nameid;
  2964. if (nameid > 0 && itemdb_exists(nameid) &&
  2965. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  2966. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2967. {
  2968. if ((j = itemdb_viewid(nameid)) > 0)
  2969. WFIFOW(fd,c*2+4) = j;
  2970. else
  2971. WFIFOW(fd,c*2+4) = nameid;
  2972. c++;
  2973. }
  2974. }
  2975. WFIFOW(fd,2) = c*2+4;
  2976. WFIFOSET(fd, WFIFOW(fd,2));
  2977. if (c > 0) {
  2978. sd->menuskill_id = AC_MAKINGARROW;
  2979. sd->menuskill_val = c;
  2980. }
  2981. }
  2982. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2983. /// 00bc <status id>.W <result>.B <value>.B
  2984. /// status id:
  2985. /// SP_STR ~ SP_LUK
  2986. /// result:
  2987. /// 0 = failure
  2988. /// 1 = success
  2989. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2990. {
  2991. int fd;
  2992. nullpo_retv(sd);
  2993. fd=sd->fd;
  2994. WFIFOHEAD(fd,packet_len(0xbc));
  2995. WFIFOW(fd,0)=0xbc;
  2996. WFIFOW(fd,2)=type;
  2997. WFIFOB(fd,4)=ok;
  2998. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2999. WFIFOSET(fd,packet_len(0xbc));
  3000. }
  3001. /// Notifies the client about the result of a request to equip an item.
  3002. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3003. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3004. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3005. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3006. /// @ok: //inversed forv2 v5
  3007. /// 0 = failure
  3008. /// 1 = success
  3009. /// 2 = failure due to low level
  3010. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3011. {
  3012. int fd,header,offs=0,success;
  3013. #if PACKETVER < 20110824
  3014. header = 0xaa;
  3015. success = (ok==1);
  3016. #elif PACKETVER < 20120925
  3017. header = 0x8d0;
  3018. success = ok ? 0:1;
  3019. #else
  3020. header = 0x999;
  3021. success = ok ? 0:1;
  3022. #endif
  3023. nullpo_retv(sd);
  3024. fd=sd->fd;
  3025. WFIFOHEAD(fd,packet_len(header));
  3026. WFIFOW(fd,offs+0)=header;
  3027. WFIFOW(fd,offs+2)=n+2;
  3028. #if PACKETVER >= 20120925
  3029. WFIFOL(fd,offs+4)=pos;
  3030. offs+=2;
  3031. #else
  3032. WFIFOW(fd,offs+4)=(int)pos;
  3033. #endif
  3034. #if PACKETVER < 20100629
  3035. WFIFOB(fd,offs+6)=success;
  3036. #else
  3037. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3038. WFIFOW(fd,offs+6)=sd->inventory_data[n]->look;
  3039. else
  3040. WFIFOW(fd,offs+6)=0;
  3041. WFIFOB(fd,offs+8)=success;
  3042. #endif
  3043. WFIFOSET(fd,packet_len(header));
  3044. }
  3045. /// Notifies the client about the result of a request to take off an item.
  3046. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3047. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3048. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3049. /// @ok : //inversed for v2 v5
  3050. /// 0 = failure
  3051. /// 1 = success
  3052. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3053. {
  3054. int fd,header,offs=0;
  3055. #if PACKETVER >= 20130000
  3056. header = 0x99a;
  3057. ok = ok ? 0:1;
  3058. #elif PACKETVER >= 20110824
  3059. header = 0x8d1;
  3060. ok = ok ? 0:1;
  3061. #else
  3062. header = 0xac;
  3063. #endif
  3064. nullpo_retv(sd);
  3065. fd=sd->fd;
  3066. WFIFOHEAD(fd,packet_len(header));
  3067. WFIFOW(fd,offs+0)=header;
  3068. WFIFOW(fd,offs+2)=n+2;
  3069. #if PACKETVER >= 20130000
  3070. WFIFOL(fd,offs+4)=pos;
  3071. offs +=2;
  3072. #else
  3073. WFIFOW(fd,offs+4)=pos;
  3074. #endif
  3075. WFIFOB(fd,offs+6)=ok;
  3076. WFIFOSET(fd,packet_len(header));
  3077. }
  3078. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3079. /// 019b <id>.L <effect id>.L
  3080. /// effect id:
  3081. /// 0 = base level up
  3082. /// 1 = job level up
  3083. /// 2 = refine failure
  3084. /// 3 = refine success
  3085. /// 4 = game over
  3086. /// 5 = pharmacy success
  3087. /// 6 = pharmacy failure
  3088. /// 7 = base level up (super novice)
  3089. /// 8 = job level up (super novice)
  3090. /// 9 = base level up (taekwon)
  3091. void clif_misceffect(struct block_list* bl,int type)
  3092. {
  3093. unsigned char buf[32];
  3094. nullpo_retv(bl);
  3095. WBUFW(buf,0) = 0x19b;
  3096. WBUFL(buf,2) = bl->id;
  3097. WBUFL(buf,6) = type;
  3098. clif_send(buf,packet_len(0x19b),bl,AREA);
  3099. }
  3100. /// Notifies clients in the area of a state change.
  3101. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3102. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3103. void clif_changeoption(struct block_list* bl)
  3104. {
  3105. unsigned char buf[32];
  3106. struct status_change *sc;
  3107. struct map_session_data* sd;
  3108. nullpo_retv(bl);
  3109. sc = status_get_sc(bl);
  3110. if (!sc) return; //How can an option change if there's no sc?
  3111. sd = BL_CAST(BL_PC, bl);
  3112. #if PACKETVER >= 7
  3113. WBUFW(buf,0) = 0x229;
  3114. WBUFL(buf,2) = bl->id;
  3115. WBUFW(buf,6) = sc->opt1;
  3116. WBUFW(buf,8) = sc->opt2;
  3117. WBUFL(buf,10) = sc->option;
  3118. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3119. if(disguised(bl)) {
  3120. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3121. WBUFL(buf,2) = -bl->id;
  3122. clif_send(buf,packet_len(0x229),bl,SELF);
  3123. WBUFL(buf,2) = bl->id;
  3124. WBUFL(buf,10) = OPTION_INVISIBLE;
  3125. clif_send(buf,packet_len(0x229),bl,SELF);
  3126. } else
  3127. clif_send(buf,packet_len(0x229),bl,AREA);
  3128. #else
  3129. WBUFW(buf,0) = 0x119;
  3130. WBUFL(buf,2) = bl->id;
  3131. WBUFW(buf,6) = sc->opt1;
  3132. WBUFW(buf,8) = sc->opt2;
  3133. WBUFW(buf,10) = sc->option;
  3134. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3135. if(disguised(bl)) {
  3136. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3137. WBUFL(buf,2) = -bl->id;
  3138. clif_send(buf,packet_len(0x119),bl,SELF);
  3139. WBUFL(buf,2) = bl->id;
  3140. WBUFW(buf,10) = OPTION_INVISIBLE;
  3141. clif_send(buf,packet_len(0x119),bl,SELF);
  3142. } else
  3143. clif_send(buf,packet_len(0x119),bl,AREA);
  3144. #endif
  3145. }
  3146. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3147. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3148. void clif_changeoption2(struct block_list* bl)
  3149. {
  3150. unsigned char buf[20];
  3151. struct status_change *sc;
  3152. sc = status_get_sc(bl);
  3153. if (!sc) return; //How can an option change if there's no sc?
  3154. WBUFW(buf,0) = 0x28a;
  3155. WBUFL(buf,2) = bl->id;
  3156. WBUFL(buf,6) = sc->option;
  3157. WBUFL(buf,10) = clif_setlevel(bl);
  3158. WBUFL(buf,14) = sc->opt3;
  3159. if(disguised(bl)) {
  3160. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3161. WBUFL(buf,2) = -bl->id;
  3162. clif_send(buf,packet_len(0x28a),bl,SELF);
  3163. WBUFL(buf,2) = bl->id;
  3164. WBUFL(buf,6) = OPTION_INVISIBLE;
  3165. clif_send(buf,packet_len(0x28a),bl,SELF);
  3166. } else
  3167. clif_send(buf,packet_len(0x28a),bl,AREA);
  3168. }
  3169. /// Notifies the client about the result of an item use request.
  3170. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3171. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3172. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3173. {
  3174. nullpo_retv(sd);
  3175. if(!ok) {
  3176. int fd=sd->fd;
  3177. WFIFOHEAD(fd,packet_len(0xa8));
  3178. WFIFOW(fd,0)=0xa8;
  3179. WFIFOW(fd,2)=index+2;
  3180. WFIFOW(fd,4)=amount;
  3181. WFIFOB(fd,6)=ok;
  3182. WFIFOSET(fd,packet_len(0xa8));
  3183. }
  3184. else {
  3185. #if PACKETVER < 3
  3186. int fd=sd->fd;
  3187. WFIFOHEAD(fd,packet_len(0xa8));
  3188. WFIFOW(fd,0)=0xa8;
  3189. WFIFOW(fd,2)=index+2;
  3190. WFIFOW(fd,4)=amount;
  3191. WFIFOB(fd,6)=ok;
  3192. WFIFOSET(fd,packet_len(0xa8));
  3193. #else
  3194. unsigned char buf[32];
  3195. WBUFW(buf,0)=0x1c8;
  3196. WBUFW(buf,2)=index+2;
  3197. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3198. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3199. else
  3200. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3201. WBUFL(buf,6)=sd->bl.id;
  3202. WBUFW(buf,10)=amount;
  3203. WBUFB(buf,12)=ok;
  3204. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3205. #endif
  3206. }
  3207. }
  3208. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3209. /// 00d6 <flag>.B
  3210. /// flag:
  3211. /// 0 = Room has been successfully created (opens chat room)
  3212. /// 1 = Room limit exceeded
  3213. /// 2 = Same room already exists
  3214. void clif_createchat(struct map_session_data* sd, int flag)
  3215. {
  3216. int fd;
  3217. nullpo_retv(sd);
  3218. fd = sd->fd;
  3219. WFIFOHEAD(fd,packet_len(0xd6));
  3220. WFIFOW(fd,0) = 0xd6;
  3221. WFIFOB(fd,2) = flag;
  3222. WFIFOSET(fd,packet_len(0xd6));
  3223. }
  3224. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3225. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3226. /// type:
  3227. /// 0 = private (password protected)
  3228. /// 1 = public
  3229. /// 2 = arena (npc waiting room)
  3230. /// 3 = PK zone (non-clickable)
  3231. void clif_dispchat(struct chat_data* cd, int fd)
  3232. {
  3233. unsigned char buf[128];
  3234. uint8 type;
  3235. if( cd == NULL || cd->owner == NULL )
  3236. return;
  3237. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3238. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3239. : 1;
  3240. WBUFW(buf, 0) = 0xd7;
  3241. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3242. WBUFL(buf, 4) = cd->owner->id;
  3243. WBUFL(buf, 8) = cd->bl.id;
  3244. WBUFW(buf,12) = cd->limit;
  3245. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3246. WBUFB(buf,16) = type;
  3247. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3248. if( fd ) {
  3249. WFIFOHEAD(fd,WBUFW(buf,2));
  3250. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3251. WFIFOSET(fd,WBUFW(buf,2));
  3252. } else {
  3253. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3254. }
  3255. }
  3256. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3257. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3258. /// type:
  3259. /// 0 = private (password protected)
  3260. /// 1 = public
  3261. /// 2 = arena (npc waiting room)
  3262. /// 3 = PK zone (non-clickable)
  3263. void clif_changechatstatus(struct chat_data* cd)
  3264. {
  3265. unsigned char buf[128];
  3266. uint8 type;
  3267. if( cd == NULL || cd->usersd[0] == NULL )
  3268. return;
  3269. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3270. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3271. : 1;
  3272. WBUFW(buf, 0) = 0xdf;
  3273. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3274. WBUFL(buf, 4) = cd->owner->id;
  3275. WBUFL(buf, 8) = cd->bl.id;
  3276. WBUFW(buf,12) = cd->limit;
  3277. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3278. WBUFB(buf,16) = type;
  3279. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3280. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3281. }
  3282. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3283. /// 00d8 <chat id>.L
  3284. void clif_clearchat(struct chat_data *cd,int fd)
  3285. {
  3286. unsigned char buf[32];
  3287. nullpo_retv(cd);
  3288. WBUFW(buf,0) = 0xd8;
  3289. WBUFL(buf,2) = cd->bl.id;
  3290. if( fd ) {
  3291. WFIFOHEAD(fd,packet_len(0xd8));
  3292. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3293. WFIFOSET(fd,packet_len(0xd8));
  3294. } else {
  3295. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3296. }
  3297. }
  3298. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3299. /// 00da <result>.B
  3300. /// result:
  3301. /// 0 = room full
  3302. /// 1 = wrong password
  3303. /// 2 = kicked
  3304. /// 3 = success (no message)
  3305. /// 4 = no enough zeny
  3306. /// 5 = too low level
  3307. /// 6 = too high level
  3308. /// 7 = unsuitable job class
  3309. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3310. {
  3311. int fd;
  3312. nullpo_retv(sd);
  3313. fd = sd->fd;
  3314. WFIFOHEAD(fd,packet_len(0xda));
  3315. WFIFOW(fd,0) = 0xda;
  3316. WFIFOB(fd,2) = flag;
  3317. WFIFOSET(fd,packet_len(0xda));
  3318. }
  3319. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3320. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3321. /// role:
  3322. /// 0 = owner (menu)
  3323. /// 1 = normal
  3324. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3325. {
  3326. int fd;
  3327. int i,t;
  3328. nullpo_retv(sd);
  3329. nullpo_retv(cd);
  3330. fd = sd->fd;
  3331. if (!session_isActive(fd))
  3332. return;
  3333. t = (int)(cd->owner->type == BL_NPC);
  3334. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3335. WFIFOW(fd, 0) = 0xdb;
  3336. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3337. WFIFOL(fd, 4) = cd->bl.id;
  3338. if(cd->owner->type == BL_NPC){
  3339. WFIFOL(fd, 30) = 1;
  3340. WFIFOL(fd, 8) = 0;
  3341. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3342. for (i = 0; i < cd->users; i++) {
  3343. WFIFOL(fd, 8+(i+1)*28) = 1;
  3344. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3345. }
  3346. } else
  3347. for (i = 0; i < cd->users; i++) {
  3348. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3349. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3350. }
  3351. WFIFOSET(fd, WFIFOW(fd, 2));
  3352. }
  3353. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3354. /// 00dc <users>.W <name>.24B
  3355. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3356. {
  3357. unsigned char buf[29];
  3358. nullpo_retv(sd);
  3359. nullpo_retv(cd);
  3360. WBUFW(buf, 0) = 0xdc;
  3361. WBUFW(buf, 2) = cd->users;
  3362. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3363. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3364. }
  3365. /// Announce the new owner (ZC_ROLE_CHANGE).
  3366. /// 00e1 <role>.L <nick>.24B
  3367. /// role:
  3368. /// 0 = owner (menu)
  3369. /// 1 = normal
  3370. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3371. {
  3372. unsigned char buf[64];
  3373. nullpo_retv(sd);
  3374. nullpo_retv(cd);
  3375. WBUFW(buf, 0) = 0xe1;
  3376. WBUFL(buf, 2) = 1;
  3377. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3378. WBUFW(buf,30) = 0xe1;
  3379. WBUFL(buf,32) = 0;
  3380. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3381. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3382. }
  3383. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3384. /// 00dd <users>.W <nick>.24B <flag>.B
  3385. /// flag:
  3386. /// 0 = left
  3387. /// 1 = kicked
  3388. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3389. {
  3390. unsigned char buf[32];
  3391. nullpo_retv(sd);
  3392. nullpo_retv(cd);
  3393. WBUFW(buf, 0) = 0xdd;
  3394. WBUFW(buf, 2) = cd->users-1;
  3395. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3396. WBUFB(buf,28) = flag;
  3397. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3398. }
  3399. /// Opens a trade request window from char 'name'.
  3400. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3401. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3402. void clif_traderequest(struct map_session_data* sd, const char* name)
  3403. {
  3404. int fd = sd->fd;
  3405. #if PACKETVER < 6
  3406. WFIFOHEAD(fd,packet_len(0xe5));
  3407. WFIFOW(fd,0) = 0xe5;
  3408. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3409. WFIFOSET(fd,packet_len(0xe5));
  3410. #else
  3411. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3412. if( !tsd ) return;
  3413. WFIFOHEAD(fd,packet_len(0x1f4));
  3414. WFIFOW(fd,0) = 0x1f4;
  3415. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3416. WFIFOL(fd,26) = tsd->status.char_id;
  3417. WFIFOW(fd,30) = tsd->status.base_level;
  3418. WFIFOSET(fd,packet_len(0x1f4));
  3419. #endif
  3420. }
  3421. /// Reply to a trade-request.
  3422. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3423. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3424. /// result:
  3425. /// 0 = Char is too far
  3426. /// 1 = Character does not exist
  3427. /// 2 = Trade failed
  3428. /// 3 = Accept
  3429. /// 4 = Cancel
  3430. /// 5 = Busy
  3431. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3432. {
  3433. int fd = sd->fd;
  3434. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3435. if( PACKETVER < 6 || !tsd ) {
  3436. WFIFOHEAD(fd,packet_len(0xe7));
  3437. WFIFOW(fd,0) = 0xe7;
  3438. WFIFOB(fd,2) = type;
  3439. WFIFOSET(fd,packet_len(0xe7));
  3440. } else {
  3441. WFIFOHEAD(fd,packet_len(0x1f5));
  3442. WFIFOW(fd,0) = 0x1f5;
  3443. WFIFOB(fd,2) = type;
  3444. WFIFOL(fd,3) = tsd->status.char_id;
  3445. WFIFOW(fd,7) = tsd->status.base_level;
  3446. WFIFOSET(fd,packet_len(0x1f5));
  3447. }
  3448. }
  3449. /// Notifies the client about an item from other player in current trade.
  3450. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3451. /// 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)
  3452. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3453. {
  3454. int fd;
  3455. unsigned char *buf;
  3456. #if PACKETVER < 20100223
  3457. const int cmd = 0xe9;
  3458. #else
  3459. const int cmd = 0x80f;
  3460. #endif
  3461. nullpo_retv(sd);
  3462. nullpo_retv(tsd);
  3463. fd = tsd->fd;
  3464. buf = WFIFOP(fd,0);
  3465. WFIFOHEAD(fd,packet_len(cmd));
  3466. WBUFW(buf,0) = cmd;
  3467. if( index == 0 )
  3468. {
  3469. #if PACKETVER < 20100223
  3470. WBUFL(buf,2) = amount; //amount
  3471. WBUFW(buf,6) = 0; // type id
  3472. #else
  3473. WBUFW(buf,2) = 0; // type id
  3474. WBUFB(buf,4) = 0; // item type
  3475. WBUFL(buf,5) = amount; // amount
  3476. buf = WBUFP(buf,1); //Advance 1B
  3477. #endif
  3478. WBUFB(buf,8) = 0; //identify flag
  3479. WBUFB(buf,9) = 0; // attribute
  3480. WBUFB(buf,10)= 0; //refine
  3481. WBUFW(buf,11)= 0; //card (4w)
  3482. WBUFW(buf,13)= 0; //card (4w)
  3483. WBUFW(buf,15)= 0; //card (4w)
  3484. WBUFW(buf,17)= 0; //card (4w)
  3485. }
  3486. else
  3487. {
  3488. index -= 2; //index fix
  3489. #if PACKETVER < 20100223
  3490. WBUFL(buf,2) = amount; //amount
  3491. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3492. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3493. else
  3494. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3495. #else
  3496. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3497. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3498. else
  3499. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3500. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3501. WBUFL(buf,5) = amount; // amount
  3502. buf = WBUFP(buf,1); //Advance 1B
  3503. #endif
  3504. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3505. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3506. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3507. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3508. }
  3509. WFIFOSET(fd,packet_len(cmd));
  3510. }
  3511. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3512. /// 00ea <index>.W <result>.B
  3513. /// result:
  3514. /// 0 = success
  3515. /// 1 = overweight
  3516. /// 2 = trade canceled
  3517. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3518. {
  3519. int fd;
  3520. nullpo_retv(sd);
  3521. fd = sd->fd;
  3522. WFIFOHEAD(fd,packet_len(0xea));
  3523. WFIFOW(fd,0) = 0xea;
  3524. WFIFOW(fd,2) = index;
  3525. WFIFOB(fd,4) = fail;
  3526. WFIFOSET(fd,packet_len(0xea));
  3527. }
  3528. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3529. /// 00ec <who>.B
  3530. /// who:
  3531. /// 0 = self
  3532. /// 1 = other player
  3533. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3534. {
  3535. int fd;
  3536. nullpo_retv(sd);
  3537. fd = sd->fd;
  3538. WFIFOHEAD(fd,packet_len(0xec));
  3539. WFIFOW(fd,0) = 0xec;
  3540. WFIFOB(fd,2) = fail;
  3541. WFIFOSET(fd,packet_len(0xec));
  3542. }
  3543. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3544. /// 00ee
  3545. void clif_tradecancelled(struct map_session_data* sd)
  3546. {
  3547. int fd;
  3548. nullpo_retv(sd);
  3549. fd = sd->fd;
  3550. WFIFOHEAD(fd,packet_len(0xee));
  3551. WFIFOW(fd,0) = 0xee;
  3552. WFIFOSET(fd,packet_len(0xee));
  3553. }
  3554. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3555. /// 00f0 <result>.B
  3556. /// result:
  3557. /// 0 = success
  3558. /// 1 = failure
  3559. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3560. {
  3561. int fd;
  3562. nullpo_retv(sd);
  3563. fd = sd->fd;
  3564. WFIFOHEAD(fd,packet_len(0xf0));
  3565. WFIFOW(fd,0) = 0xf0;
  3566. WFIFOB(fd,2) = fail;
  3567. WFIFOSET(fd,packet_len(0xf0));
  3568. }
  3569. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3570. /// 00f1
  3571. /// NOTE: Unknown purpose. Items are not removed until the window is
  3572. /// refreshed (ex. by putting another item in there).
  3573. void clif_tradeundo(struct map_session_data* sd)
  3574. {
  3575. int fd = sd->fd;
  3576. WFIFOHEAD(fd,packet_len(0xf1));
  3577. WFIFOW(fd,0) = 0xf1;
  3578. WFIFOSET(fd,packet_len(0xf1));
  3579. }
  3580. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3581. /// 00f2 <current count>.W <max count>.W
  3582. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3583. {
  3584. int fd;
  3585. nullpo_retv(sd);
  3586. fd=sd->fd;
  3587. WFIFOHEAD(fd,packet_len(0xf2));
  3588. WFIFOW(fd,0) = 0xf2;
  3589. WFIFOW(fd,2) = amount;
  3590. WFIFOW(fd,4) = max_amount;
  3591. WFIFOSET(fd,packet_len(0xf2));
  3592. }
  3593. /// Notifies the client of an item being added to the storage.
  3594. /// 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)
  3595. /// 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)
  3596. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3597. {
  3598. int view,fd;
  3599. nullpo_retv(sd);
  3600. nullpo_retv(i);
  3601. fd=sd->fd;
  3602. view = itemdb_viewid(i->nameid);
  3603. #if PACKETVER < 5
  3604. WFIFOHEAD(fd,packet_len(0xf4));
  3605. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3606. WFIFOW(fd, 2) = index+1; // index
  3607. WFIFOL(fd, 4) = amount; // amount
  3608. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3609. WFIFOB(fd,10) = i->identify; //identify flag
  3610. WFIFOB(fd,11) = i->attribute; // attribute
  3611. WFIFOB(fd,12) = i->refine; //refine
  3612. clif_addcards(WFIFOP(fd,13), i);
  3613. WFIFOSET(fd,packet_len(0xf4));
  3614. #else
  3615. WFIFOHEAD(fd,packet_len(0x1c4));
  3616. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3617. WFIFOW(fd, 2) = index+1; // index
  3618. WFIFOL(fd, 4) = amount; // amount
  3619. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3620. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3621. WFIFOB(fd,11) = i->identify; //identify flag
  3622. WFIFOB(fd,12) = i->attribute; // attribute
  3623. WFIFOB(fd,13) = i->refine; //refine
  3624. clif_addcards(WFIFOP(fd,14), i);
  3625. WFIFOSET(fd,packet_len(0x1c4));
  3626. #endif
  3627. }
  3628. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3629. /// 00f6 <index>.W <amount>.L
  3630. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3631. {
  3632. int fd;
  3633. nullpo_retv(sd);
  3634. fd=sd->fd;
  3635. WFIFOHEAD(fd,packet_len(0xf6));
  3636. WFIFOW(fd,0)=0xf6; // Storage item removed
  3637. WFIFOW(fd,2)=index+1;
  3638. WFIFOL(fd,4)=amount;
  3639. WFIFOSET(fd,packet_len(0xf6));
  3640. }
  3641. /// Closes storage (ZC_CLOSE_STORE).
  3642. /// 00f8
  3643. void clif_storageclose(struct map_session_data* sd)
  3644. {
  3645. int fd;
  3646. nullpo_retv(sd);
  3647. fd=sd->fd;
  3648. WFIFOHEAD(fd,packet_len(0xf8));
  3649. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3650. WFIFOSET(fd,packet_len(0xf8));
  3651. }
  3652. /*==========================================
  3653. * Server tells 'sd' player client the abouts of 'dstsd' player
  3654. *------------------------------------------*/
  3655. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3656. {
  3657. struct block_list *d_bl;
  3658. int i;
  3659. if( dstsd->chatID ) {
  3660. struct chat_data *cd = NULL;
  3661. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3662. clif_dispchat(cd,sd->fd);
  3663. } else if( dstsd->state.vending )
  3664. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3665. else if( dstsd->state.buyingstore )
  3666. clif_buyingstore_entry_single(sd, dstsd);
  3667. if(dstsd->spiritball > 0)
  3668. clif_spiritball_single(sd->fd, dstsd);
  3669. for(i = 1; i < 5; i++){
  3670. if( dstsd->talisman[i] > 0 )
  3671. clif_talisman_single(sd->fd, dstsd, i);
  3672. }
  3673. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3674. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3675. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3676. else
  3677. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, StatusIconChangeTable[dstsd->sc_display[i]->type], dstsd->sc_display[i]->val1, dstsd->sc_display[i]->val2, dstsd->sc_display[i]->val3);
  3678. }
  3679. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3680. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3681. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3682. )
  3683. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3684. // display link (sd - dstsd) to sd
  3685. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3686. if( i < MAX_DEVOTION )
  3687. clif_devotion(&sd->bl, sd);
  3688. // display links (dstsd - devotees) to sd
  3689. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3690. if( i < MAX_DEVOTION )
  3691. clif_devotion(&dstsd->bl, sd);
  3692. // display link (dstsd - crusader) to sd
  3693. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3694. clif_devotion(d_bl, sd);
  3695. }
  3696. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3697. {
  3698. uint8 buf[128];
  3699. struct unit_data *ud;
  3700. struct view_data *vd;
  3701. int len;
  3702. vd = status_get_viewdata(bl);
  3703. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3704. return;
  3705. /**
  3706. * Hide NPC from maya purple card.
  3707. **/
  3708. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3709. return;
  3710. ud = unit_bl2ud(bl);
  3711. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3712. clif_send(buf,len,&sd->bl,SELF);
  3713. if (vd->cloth_color)
  3714. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3715. switch (bl->type)
  3716. {
  3717. case BL_PC:
  3718. {
  3719. TBL_PC* tsd = (TBL_PC*)bl;
  3720. clif_getareachar_pc(sd, tsd);
  3721. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3722. clif_specialeffect_single(bl,423,sd->fd);
  3723. else if(tsd->state.size==SZ_MEDIUM)
  3724. clif_specialeffect_single(bl,421,sd->fd);
  3725. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3726. clif_sendbgemblem_single(sd->fd,tsd);
  3727. if ( tsd->status.robe )
  3728. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3729. if (!&tsd->sc)
  3730. break;
  3731. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3732. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3733. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3734. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3735. if( tsd->sc.data[SC_MOONSTAR] )
  3736. clif_status_load(bl,SI_MOONSTAR,1);
  3737. if( tsd->sc.data[SC_SUPER_STAR] )
  3738. clif_status_load(bl,SI_SUPER_STAR,1);
  3739. if( tsd->sc.data[SC_ALL_RIDING] )
  3740. clif_status_load(bl,SI_ALL_RIDING,1);
  3741. }
  3742. break;
  3743. case BL_MER: // Devotion Effects
  3744. if( ((TBL_MER*)bl)->devotion_flag )
  3745. clif_devotion(bl, sd);
  3746. break;
  3747. case BL_NPC:
  3748. {
  3749. TBL_NPC* nd = (TBL_NPC*)bl;
  3750. if( nd->chat_id )
  3751. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3752. if( nd->size == SZ_BIG )
  3753. clif_specialeffect_single(bl,423,sd->fd);
  3754. else if( nd->size == SZ_MEDIUM )
  3755. clif_specialeffect_single(bl,421,sd->fd);
  3756. }
  3757. break;
  3758. case BL_MOB:
  3759. {
  3760. TBL_MOB* md = (TBL_MOB*)bl;
  3761. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3762. clif_specialeffect_single(bl,423,sd->fd);
  3763. else if(md->special_state.size==SZ_MEDIUM)
  3764. clif_specialeffect_single(bl,421,sd->fd);
  3765. #if PACKETVER >= 20120404
  3766. if( !(md->status.mode&MD_BOSS) ){
  3767. int i;
  3768. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3769. if( md->dmglog[i].id == sd->status.char_id )
  3770. clif_monster_hp_bar(md, sd->fd);
  3771. }
  3772. #endif
  3773. }
  3774. break;
  3775. case BL_PET:
  3776. if (vd->head_bottom)
  3777. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3778. break;
  3779. }
  3780. }
  3781. //Modifies the type of damage according to status changes [Skotlex]
  3782. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3783. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  3784. {
  3785. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  3786. }
  3787. /*==========================================
  3788. * Estimates walk delay based on the damage criteria. [Skotlex]
  3789. *------------------------------------------*/
  3790. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  3791. {
  3792. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  3793. return 0;
  3794. if (bl->type == BL_PC) {
  3795. if (battle_config.pc_walk_delay_rate != 100)
  3796. delay = delay*battle_config.pc_walk_delay_rate/100;
  3797. } else
  3798. if (battle_config.walk_delay_rate != 100)
  3799. delay = delay*battle_config.walk_delay_rate/100;
  3800. if (div_ > 1) //Multi-hit skills mean higher delays.
  3801. delay += battle_config.multihit_delay*(div_-1);
  3802. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3803. }
  3804. /// Sends a 'damage' packet (src performs action on dst)
  3805. /// 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)
  3806. /// 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)
  3807. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3) //! TODO
  3808. /// type:
  3809. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3810. /// 1 = pick up item
  3811. /// 2 = sit down
  3812. /// 3 = stand up
  3813. /// 4 = damage (endure)
  3814. /// 5 = (splash?)
  3815. /// 6 = (skill?)
  3816. /// 7 = (repeat damage?)
  3817. /// 8 = multi-hit damage
  3818. /// 9 = multi-hit damage (endure)
  3819. /// 10 = critical hit
  3820. /// 11 = lucky dodge
  3821. /// 12 = (touch skill?)
  3822. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2)
  3823. {
  3824. unsigned char buf[33];
  3825. struct status_change *sc;
  3826. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3827. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3828. #if PACKETVER < 20071113
  3829. const int cmd = 0x8a;
  3830. #else
  3831. const int cmd = 0x2e1;
  3832. #endif
  3833. nullpo_ret(src);
  3834. nullpo_ret(dst);
  3835. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3836. sc = status_get_sc(dst);
  3837. if(sc && sc->count) {
  3838. if(sc->data[SC_HALLUCINATION]) {
  3839. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3840. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3841. }
  3842. }
  3843. WBUFW(buf,0)=cmd;
  3844. WBUFL(buf,2)=src->id;
  3845. WBUFL(buf,6)=dst->id;
  3846. WBUFL(buf,10)=tick;
  3847. WBUFL(buf,14)=sdelay;
  3848. WBUFL(buf,18)=ddelay;
  3849. #if PACKETVER < 20071113
  3850. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3851. WBUFW(buf,22)=damage?div:0;
  3852. WBUFW(buf,27)=damage2?div:0;
  3853. } else {
  3854. WBUFW(buf,22)=min(damage, INT16_MAX);
  3855. WBUFW(buf,27)=damage2;
  3856. }
  3857. WBUFW(buf,24)=div;
  3858. WBUFB(buf,26)=type;
  3859. #else
  3860. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3861. WBUFL(buf,22)=damage?div:0;
  3862. WBUFL(buf,29)=damage2?div:0;
  3863. } else {
  3864. WBUFL(buf,22)=damage;
  3865. WBUFL(buf,29)=damage2;
  3866. }
  3867. WBUFW(buf,26)=div;
  3868. WBUFB(buf,28)=type;
  3869. #endif
  3870. if(disguised(dst)) {
  3871. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3872. WBUFL(buf,6) = -dst->id;
  3873. clif_send(buf,packet_len(cmd),dst,SELF);
  3874. } else
  3875. clif_send(buf,packet_len(cmd),dst,AREA);
  3876. if(disguised(src)) {
  3877. WBUFL(buf,2) = -src->id;
  3878. if (disguised(dst))
  3879. WBUFL(buf,6) = dst->id;
  3880. #if PACKETVER < 20071113
  3881. if(damage > 0) WBUFW(buf,22) = -1;
  3882. if(damage2 > 0) WBUFW(buf,27) = -1;
  3883. #else
  3884. if(damage > 0) WBUFL(buf,22) = -1;
  3885. if(damage2 > 0) WBUFL(buf,29) = -1;
  3886. #endif
  3887. clif_send(buf,packet_len(cmd),src,SELF);
  3888. }
  3889. if(src == dst) {
  3890. unit_setdir(src,unit_getdir(src));
  3891. }
  3892. //Return adjusted can't walk delay for further processing.
  3893. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3894. }
  3895. /*==========================================
  3896. * src picks up dst
  3897. *------------------------------------------*/
  3898. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3899. {
  3900. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  3901. unsigned char buf[32];
  3902. nullpo_retv(src);
  3903. nullpo_retv(dst);
  3904. WBUFW(buf, 0) = 0x8a;
  3905. WBUFL(buf, 2) = src->id;
  3906. WBUFL(buf, 6) = dst->id;
  3907. WBUFB(buf,26) = 1;
  3908. clif_send(buf, packet_len(0x8a), src, AREA);
  3909. }
  3910. /*==========================================
  3911. * inform clients in area that `bl` is sitting
  3912. *------------------------------------------*/
  3913. void clif_sitting(struct block_list* bl)
  3914. {
  3915. unsigned char buf[32];
  3916. nullpo_retv(bl);
  3917. WBUFW(buf, 0) = 0x8a;
  3918. WBUFL(buf, 2) = bl->id;
  3919. WBUFB(buf,26) = 2;
  3920. clif_send(buf, packet_len(0x8a), bl, AREA);
  3921. if(disguised(bl)) {
  3922. WBUFL(buf, 2) = - bl->id;
  3923. clif_send(buf, packet_len(0x8a), bl, SELF);
  3924. }
  3925. }
  3926. /*==========================================
  3927. * inform clients in area that `bl` is standing
  3928. *------------------------------------------*/
  3929. void clif_standing(struct block_list* bl)
  3930. {
  3931. unsigned char buf[32];
  3932. nullpo_retv(bl);
  3933. WBUFW(buf, 0) = 0x8a;
  3934. WBUFL(buf, 2) = bl->id;
  3935. WBUFB(buf,26) = 3;
  3936. clif_send(buf, packet_len(0x8a), bl, AREA);
  3937. if(disguised(bl)) {
  3938. WBUFL(buf, 2) = - bl->id;
  3939. clif_send(buf, packet_len(0x8a), bl, SELF);
  3940. }
  3941. }
  3942. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3943. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3944. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3945. {
  3946. unsigned char buf[32];
  3947. WBUFW(buf,0) = 0x192;
  3948. WBUFW(buf,2) = x;
  3949. WBUFW(buf,4) = y;
  3950. WBUFW(buf,6) = type;
  3951. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  3952. if( fd )
  3953. {
  3954. WFIFOHEAD(fd,packet_len(0x192));
  3955. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3956. WFIFOSET(fd,packet_len(0x192));
  3957. }
  3958. else
  3959. {
  3960. struct block_list dummy_bl;
  3961. dummy_bl.type = BL_NUL;
  3962. dummy_bl.x = x;
  3963. dummy_bl.y = y;
  3964. dummy_bl.m = m;
  3965. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3966. }
  3967. }
  3968. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3969. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3970. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3971. {
  3972. int view,fd;
  3973. fd=sd->fd;
  3974. WFIFOHEAD(fd,packet_len(0x9d));
  3975. WFIFOW(fd,0)=0x9d;
  3976. WFIFOL(fd,2)=fitem->bl.id;
  3977. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3978. WFIFOW(fd,6)=view;
  3979. else
  3980. WFIFOW(fd,6)=fitem->item_data.nameid;
  3981. WFIFOB(fd,8)=fitem->item_data.identify;
  3982. WFIFOW(fd,9)=fitem->bl.x;
  3983. WFIFOW(fd,11)=fitem->bl.y;
  3984. WFIFOW(fd,13)=fitem->item_data.amount;
  3985. WFIFOB(fd,15)=fitem->subx;
  3986. WFIFOB(fd,16)=fitem->suby;
  3987. WFIFOSET(fd,packet_len(0x9d));
  3988. }
  3989. /// Notifes client about Graffiti
  3990. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3991. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  3992. unsigned char buf[128];
  3993. nullpo_retv(bl);
  3994. nullpo_retv(unit);
  3995. WBUFW(buf, 0) = 0x1c9;
  3996. WBUFL(buf, 2) = unit->bl.id;
  3997. WBUFL(buf, 6) = unit->group->src_id;
  3998. WBUFW(buf,10) = unit->bl.x;
  3999. WBUFW(buf,12) = unit->bl.y;
  4000. WBUFB(buf,14) = unit->group->unit_id;
  4001. WBUFB(buf,15) = 1;
  4002. WBUFB(buf,16) = 1;
  4003. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4004. clif_send(buf,packet_len(0x1c9),bl,target);
  4005. }
  4006. /// Notifies the client of a skill unit.
  4007. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4008. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4009. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4010. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4011. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4012. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4013. unsigned char buf[128];
  4014. nullpo_retv(bl);
  4015. nullpo_retv(unit);
  4016. if (bl->type == BL_PC)
  4017. fd = ((TBL_PC*)bl)->fd;
  4018. if (unit->group->state.guildaura)
  4019. return;
  4020. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  4021. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for traps.
  4022. else if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4023. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4024. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4025. unit_id = UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  4026. else
  4027. unit_id = unit->group->unit_id;
  4028. #if PACKETVER >= 3
  4029. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4030. clif_graffiti(bl, unit, target);
  4031. return;
  4032. }
  4033. #endif
  4034. #if PACKETVER <= 20120702
  4035. header = 0x011f;
  4036. //#if PACKETVER < 20110718
  4037. // header = 0x011f;
  4038. //#elif PACKETVER < 20121212
  4039. // header = 0x08c7;
  4040. #elif PACKETVER < 20130731
  4041. header = 0x099f;
  4042. #else
  4043. header = 0x09ca;
  4044. #endif
  4045. len = packet_len(header);
  4046. WBUFW(buf,pos) = header;
  4047. if (header != 0x011f) {
  4048. WBUFW(buf, pos+2) = len;
  4049. pos += 2;
  4050. }
  4051. WBUFL(buf,pos+2) = unit->bl.id;
  4052. WBUFL(buf,pos+6) = unit->group->src_id;
  4053. WBUFW(buf,pos+10) = unit->bl.x;
  4054. WBUFW(buf,pos+12) = unit->bl.y;
  4055. switch (header) {
  4056. case 0x011f:
  4057. WBUFB(buf,pos+14) = unit_id;
  4058. WBUFB(buf,pos+15) = 1;
  4059. break;
  4060. case 0x08c7:
  4061. WBUFB(buf,pos+14) = unit_id;
  4062. WBUFW(buf,pos+15) = unit->range;
  4063. WBUFB(buf,pos+17) = 1;
  4064. break;
  4065. case 0x099f:
  4066. WBUFL(buf,pos+14) = unit_id;
  4067. WBUFW(buf,pos+18) = unit->range;
  4068. WBUFB(buf,pos+20) = 1;
  4069. break;
  4070. case 0x09ca:
  4071. WBUFL(buf,pos+14) = unit_id;
  4072. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4073. WBUFB(buf,pos+19) = 1;
  4074. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4075. break;
  4076. }
  4077. clif_send(buf, len, bl, target);
  4078. if (unit->group->skill_id == WZ_ICEWALL)
  4079. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4080. }
  4081. /*==========================================
  4082. * Server tells client to remove unit of id 'unit->bl.id'
  4083. *------------------------------------------*/
  4084. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4085. {
  4086. nullpo_retv(unit);
  4087. WFIFOHEAD(fd,packet_len(0x120));
  4088. WFIFOW(fd, 0)=0x120;
  4089. WFIFOL(fd, 2)=unit->bl.id;
  4090. WFIFOSET(fd,packet_len(0x120));
  4091. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4092. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4093. }
  4094. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4095. /// 0120 <id>.L
  4096. void clif_skill_delunit(struct skill_unit *unit)
  4097. {
  4098. unsigned char buf[16];
  4099. nullpo_retv(unit);
  4100. WBUFW(buf, 0)=0x120;
  4101. WBUFL(buf, 2)=unit->bl.id;
  4102. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4103. }
  4104. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4105. /// 01ac <id>.L
  4106. /// Only affects units with class [139,153] client-side.
  4107. void clif_skillunit_update(struct block_list* bl)
  4108. {
  4109. unsigned char buf[6];
  4110. nullpo_retv(bl);
  4111. WBUFW(buf,0) = 0x1ac;
  4112. WBUFL(buf,2) = bl->id;
  4113. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4114. }
  4115. /*==========================================
  4116. *
  4117. *------------------------------------------*/
  4118. static int clif_getareachar(struct block_list* bl,va_list ap)
  4119. {
  4120. struct map_session_data *sd;
  4121. nullpo_ret(bl);
  4122. sd=va_arg(ap,struct map_session_data*);
  4123. if (sd == NULL || !sd->fd)
  4124. return 0;
  4125. switch(bl->type){
  4126. case BL_ITEM:
  4127. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4128. break;
  4129. case BL_SKILL:
  4130. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF);
  4131. break;
  4132. default:
  4133. if(&sd->bl == bl)
  4134. break;
  4135. clif_getareachar_unit(sd,bl);
  4136. break;
  4137. }
  4138. return 0;
  4139. }
  4140. /*==========================================
  4141. * tbl has gone out of view-size of bl
  4142. *------------------------------------------*/
  4143. int clif_outsight(struct block_list *bl,va_list ap)
  4144. {
  4145. struct block_list *tbl;
  4146. struct view_data *vd;
  4147. TBL_PC *sd, *tsd;
  4148. tbl=va_arg(ap,struct block_list*);
  4149. if(bl == tbl) return 0;
  4150. sd = BL_CAST(BL_PC, bl);
  4151. tsd = BL_CAST(BL_PC, tbl);
  4152. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4153. switch(bl->type){
  4154. case BL_PC:
  4155. if (sd->vd.class_ != INVISIBLE_CLASS)
  4156. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4157. if(sd->chatID){
  4158. struct chat_data *cd;
  4159. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4160. if(cd->usersd[0]==sd)
  4161. clif_dispchat(cd,tsd->fd);
  4162. }
  4163. if( sd->state.vending )
  4164. clif_closevendingboard(bl,tsd->fd);
  4165. if( sd->state.buyingstore )
  4166. clif_buyingstore_disappear_entry_single(tsd, sd);
  4167. break;
  4168. case BL_ITEM:
  4169. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4170. break;
  4171. case BL_SKILL:
  4172. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4173. break;
  4174. case BL_NPC:
  4175. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4176. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4177. break;
  4178. default:
  4179. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4180. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4181. break;
  4182. }
  4183. }
  4184. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4185. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4186. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4187. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4188. }
  4189. return 0;
  4190. }
  4191. /*==========================================
  4192. * tbl has come into view of bl
  4193. *------------------------------------------*/
  4194. int clif_insight(struct block_list *bl,va_list ap)
  4195. {
  4196. struct block_list *tbl;
  4197. TBL_PC *sd, *tsd;
  4198. tbl=va_arg(ap,struct block_list*);
  4199. if (bl == tbl) return 0;
  4200. sd = BL_CAST(BL_PC, bl);
  4201. tsd = BL_CAST(BL_PC, tbl);
  4202. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4203. switch(bl->type){
  4204. case BL_ITEM:
  4205. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4206. break;
  4207. case BL_SKILL:
  4208. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF);
  4209. break;
  4210. default:
  4211. clif_getareachar_unit(tsd,bl);
  4212. break;
  4213. }
  4214. }
  4215. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4216. clif_getareachar_unit(sd,tbl);
  4217. }
  4218. return 0;
  4219. }
  4220. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4221. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4222. void clif_skillinfoblock(struct map_session_data *sd)
  4223. {
  4224. int fd;
  4225. int i,len,id;
  4226. nullpo_retv(sd);
  4227. fd=sd->fd;
  4228. if (!fd) return;
  4229. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4230. WFIFOW(fd,0) = 0x10f;
  4231. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4232. {
  4233. if( (id = sd->status.skill[i].id) != 0 )
  4234. {
  4235. // workaround for bugreport:5348
  4236. if (len + 37 > 8192)
  4237. break;
  4238. WFIFOW(fd,len) = id;
  4239. WFIFOL(fd,len+2) = skill_get_inf(id);
  4240. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4241. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4242. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4243. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4244. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4245. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4246. else
  4247. WFIFOB(fd,len+36) = 0;
  4248. len += 37;
  4249. }
  4250. }
  4251. WFIFOW(fd,2)=len;
  4252. WFIFOSET(fd,len);
  4253. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4254. for ( ; i < MAX_SKILL; i++)
  4255. {
  4256. if( (id = sd->status.skill[i].id) != 0 )
  4257. {
  4258. clif_addskill(sd, id);
  4259. clif_skillinfo(sd, id, 0);
  4260. }
  4261. }
  4262. }
  4263. /**
  4264. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4265. **/
  4266. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4267. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4268. void clif_addskill(struct map_session_data *sd, int id)
  4269. {
  4270. int fd;
  4271. nullpo_retv(sd);
  4272. fd = sd->fd;
  4273. if (!fd) return;
  4274. if( sd->status.skill[id].id <= 0 )
  4275. return;
  4276. WFIFOHEAD(fd, packet_len(0x111));
  4277. WFIFOW(fd,0) = 0x111;
  4278. WFIFOW(fd,2) = id;
  4279. WFIFOL(fd,4) = skill_get_inf(id);
  4280. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4281. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4282. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4283. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4284. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4285. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4286. else
  4287. WFIFOB(fd,38) = 0;
  4288. WFIFOSET(fd,packet_len(0x111));
  4289. }
  4290. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4291. /// 0441 <skill id>.W
  4292. void clif_deleteskill(struct map_session_data *sd, int id)
  4293. {
  4294. #if PACKETVER >= 20081217
  4295. int fd;
  4296. nullpo_retv(sd);
  4297. fd = sd->fd;
  4298. if( !fd ) return;
  4299. WFIFOHEAD(fd,packet_len(0x441));
  4300. WFIFOW(fd,0) = 0x441;
  4301. WFIFOW(fd,2) = id;
  4302. WFIFOSET(fd,packet_len(0x441));
  4303. #endif
  4304. clif_skillinfoblock(sd);
  4305. }
  4306. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4307. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4308. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4309. int fd;
  4310. nullpo_retv(sd);
  4311. fd = sd->fd;
  4312. WFIFOHEAD(fd, packet_len(0x10e));
  4313. WFIFOW(fd, 0) = 0x10e;
  4314. WFIFOW(fd, 2) = skill_id;
  4315. WFIFOW(fd, 4) = lv;
  4316. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4317. WFIFOW(fd, 8) = range;
  4318. WFIFOB(fd, 10) = upgradable;
  4319. WFIFOSET(fd, packet_len(0x10e));
  4320. }
  4321. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4322. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4323. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4324. {
  4325. const int fd = sd->fd;
  4326. WFIFOHEAD(fd,packet_len(0x7e1));
  4327. WFIFOW(fd,0) = 0x7e1;
  4328. WFIFOW(fd,2) = skill;
  4329. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4330. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4331. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4332. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4333. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4334. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4335. else
  4336. WFIFOB(fd,14) = 0;
  4337. WFIFOSET(fd,packet_len(0x7e1));
  4338. }
  4339. /// Notifies clients in area, that an object is about to use a skill.
  4340. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4341. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4342. /// property:
  4343. /// 0 = Yellow cast aura
  4344. /// 1 = Water elemental cast aura
  4345. /// 2 = Earth elemental cast aura
  4346. /// 3 = Fire elemental cast aura
  4347. /// 4 = Wind elemental cast aura
  4348. /// 5 = Poison elemental cast aura
  4349. /// 6 = Holy elemental cast aura
  4350. /// ? = like 0
  4351. /// is disposable:
  4352. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4353. /// 1 = no text
  4354. 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)
  4355. {
  4356. #if PACKETVER < 20091124
  4357. const int cmd = 0x13e;
  4358. #else
  4359. const int cmd = 0x7fb;
  4360. #endif
  4361. unsigned char buf[32];
  4362. WBUFW(buf,0) = cmd;
  4363. WBUFL(buf,2) = src_id;
  4364. WBUFL(buf,6) = dst_id;
  4365. WBUFW(buf,10) = dst_x;
  4366. WBUFW(buf,12) = dst_y;
  4367. WBUFW(buf,14) = skill_id;
  4368. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4369. WBUFL(buf,20) = casttime;
  4370. #if PACKETVER >= 20091124
  4371. WBUFB(buf,24) = 0; // isDisposable
  4372. #endif
  4373. if (disguised(bl)) {
  4374. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4375. WBUFL(buf,2) = -src_id;
  4376. clif_send(buf,packet_len(cmd), bl, SELF);
  4377. } else
  4378. clif_send(buf,packet_len(cmd), bl, AREA);
  4379. }
  4380. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4381. /// 01b9 <id>.L
  4382. void clif_skillcastcancel(struct block_list* bl)
  4383. {
  4384. unsigned char buf[16];
  4385. nullpo_retv(bl);
  4386. WBUFW(buf,0) = 0x1b9;
  4387. WBUFL(buf,2) = bl->id;
  4388. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4389. }
  4390. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4391. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4392. /// num (only used when skill id = NV_BASIC and cause = 0):
  4393. /// 0 = "skill failed" MsgStringTable[159]
  4394. /// 1 = "no emotions" MsgStringTable[160]
  4395. /// 2 = "no sit" MsgStringTable[161]
  4396. /// 3 = "no chat" MsgStringTable[162]
  4397. /// 4 = "no party" MsgStringTable[163]
  4398. /// 5 = "no shout" MsgStringTable[164]
  4399. /// 6 = "no PKing" MsgStringTable[165]
  4400. /// 7 = "no alligning" MsgStringTable[383]
  4401. /// ? = ignored
  4402. /// cause:
  4403. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4404. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4405. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4406. /// "skill failed" MsgStringTable[204] (otherwise)
  4407. /// ... = @see enum useskill_fail_cause
  4408. /// ? = ignored
  4409. ///
  4410. /// if(result!=0) doesn't display any of the previous messages
  4411. /// Note: when this packet is received an unknown flag is always set to 0,
  4412. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4413. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4414. {
  4415. int fd;
  4416. if (!sd) { //Since this is the most common nullpo....
  4417. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4418. return;
  4419. }
  4420. fd=sd->fd;
  4421. if (!fd) return;
  4422. if(battle_config.display_skill_fail&1)
  4423. return; //Disable all skill failed messages
  4424. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4425. return; //Disable delay failed messages
  4426. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4427. return;
  4428. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4429. return;
  4430. WFIFOHEAD(fd,packet_len(0x110));
  4431. WFIFOW(fd,0) = 0x110;
  4432. WFIFOW(fd,2) = skill_id;
  4433. WFIFOL(fd,4) = btype;
  4434. WFIFOB(fd,8) = 0;// success
  4435. WFIFOB(fd,9) = cause;
  4436. WFIFOSET(fd,packet_len(0x110));
  4437. }
  4438. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4439. /// 043d <skill ID>.W <tick>.L
  4440. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4441. {
  4442. #if PACKETVER>=20081112
  4443. int fd;
  4444. nullpo_retv(sd);
  4445. fd=sd->fd;
  4446. WFIFOHEAD(fd,packet_len(0x43d));
  4447. WFIFOW(fd,0) = 0x43d;
  4448. WFIFOW(fd,2) = skill_id;
  4449. WFIFOL(fd,4) = tick;
  4450. WFIFOSET(fd,packet_len(0x43d));
  4451. #endif
  4452. }
  4453. /// Skill attack effect and damage.
  4454. /// 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)
  4455. /// 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)
  4456. 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)
  4457. {
  4458. unsigned char buf[64];
  4459. struct status_change *sc;
  4460. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4461. nullpo_ret(src);
  4462. nullpo_ret(dst);
  4463. type = clif_calc_delay(type,div,damage,ddelay);
  4464. sc = status_get_sc(dst);
  4465. if(sc && sc->count) {
  4466. if(sc->data[SC_HALLUCINATION] && damage)
  4467. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4468. }
  4469. #if PACKETVER < 3
  4470. WBUFW(buf,0)=0x114;
  4471. WBUFW(buf,2)=skill_id;
  4472. WBUFL(buf,4)=src->id;
  4473. WBUFL(buf,8)=dst->id;
  4474. WBUFL(buf,12)=tick;
  4475. WBUFL(buf,16)=sdelay;
  4476. WBUFL(buf,20)=ddelay;
  4477. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4478. WBUFW(buf,24)=damage?div:0;
  4479. } else {
  4480. WBUFW(buf,24)=damage;
  4481. }
  4482. WBUFW(buf,26)=skill_lv;
  4483. WBUFW(buf,28)=div;
  4484. WBUFB(buf,30)=type;
  4485. if (disguised(dst)) {
  4486. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4487. WBUFL(buf,8)=-dst->id;
  4488. clif_send(buf,packet_len(0x114),dst,SELF);
  4489. } else
  4490. clif_send(buf,packet_len(0x114),dst,AREA);
  4491. if(disguised(src)) {
  4492. WBUFL(buf,4)=-src->id;
  4493. if (disguised(dst))
  4494. WBUFL(buf,8)=dst->id;
  4495. if(damage > 0)
  4496. WBUFW(buf,24)=-1;
  4497. clif_send(buf,packet_len(0x114),src,SELF);
  4498. }
  4499. #else
  4500. WBUFW(buf,0)=0x1de;
  4501. WBUFW(buf,2)=skill_id;
  4502. WBUFL(buf,4)=src->id;
  4503. WBUFL(buf,8)=dst->id;
  4504. WBUFL(buf,12)=tick;
  4505. WBUFL(buf,16)=sdelay;
  4506. WBUFL(buf,20)=ddelay;
  4507. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4508. WBUFL(buf,24)=damage?div:0;
  4509. } else {
  4510. WBUFL(buf,24)=damage;
  4511. }
  4512. WBUFW(buf,28)=skill_lv;
  4513. WBUFW(buf,30)=div;
  4514. WBUFB(buf,32)=type;
  4515. if (disguised(dst)) {
  4516. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4517. WBUFL(buf,8)=-dst->id;
  4518. clif_send(buf,packet_len(0x1de),dst,SELF);
  4519. } else
  4520. clif_send(buf,packet_len(0x1de),dst,AREA);
  4521. if(disguised(src)) {
  4522. WBUFL(buf,4)=-src->id;
  4523. if (disguised(dst))
  4524. WBUFL(buf,8)=dst->id;
  4525. if(damage > 0)
  4526. WBUFL(buf,24)=-1;
  4527. clif_send(buf,packet_len(0x1de),src,SELF);
  4528. }
  4529. #endif
  4530. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4531. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4532. }
  4533. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4534. /// 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
  4535. /*
  4536. 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)
  4537. {
  4538. unsigned char buf[64];
  4539. struct status_change *sc;
  4540. nullpo_ret(src);
  4541. nullpo_ret(dst);
  4542. type = (type>0)?type:skill_get_hit(skill_id);
  4543. type = clif_calc_delay(type,div,damage,ddelay);
  4544. sc = status_get_sc(dst);
  4545. if(sc && sc->count) {
  4546. if(sc->data[SC_HALLUCINATION] && damage)
  4547. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4548. }
  4549. WBUFW(buf,0)=0x115;
  4550. WBUFW(buf,2)=skill_id;
  4551. WBUFL(buf,4)=src->id;
  4552. WBUFL(buf,8)=dst->id;
  4553. WBUFL(buf,12)=tick;
  4554. WBUFL(buf,16)=sdelay;
  4555. WBUFL(buf,20)=ddelay;
  4556. WBUFW(buf,24)=dst->x;
  4557. WBUFW(buf,26)=dst->y;
  4558. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4559. WBUFW(buf,28)=damage?div:0;
  4560. } else {
  4561. WBUFW(buf,28)=damage;
  4562. }
  4563. WBUFW(buf,30)=skill_lv;
  4564. WBUFW(buf,32)=div;
  4565. WBUFB(buf,34)=type;
  4566. clif_send(buf,packet_len(0x115),src,AREA);
  4567. if(disguised(src)) {
  4568. WBUFL(buf,4)=-src->id;
  4569. if(damage > 0)
  4570. WBUFW(buf,28)=-1;
  4571. clif_send(buf,packet_len(0x115),src,SELF);
  4572. }
  4573. if (disguised(dst)) {
  4574. WBUFL(buf,8)=-dst->id;
  4575. if (disguised(src))
  4576. WBUFL(buf,4)=src->id;
  4577. else if(damage > 0)
  4578. WBUFW(buf,28)=-1;
  4579. clif_send(buf,packet_len(0x115),dst,SELF);
  4580. }
  4581. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4582. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4583. }
  4584. */
  4585. /// Non-damaging skill effect (ZC_USE_SKILL).
  4586. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4587. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4588. {
  4589. unsigned char buf[32];
  4590. nullpo_ret(dst);
  4591. WBUFW(buf,0)=0x11a;
  4592. WBUFW(buf,2)=skill_id;
  4593. WBUFW(buf,4)=min(heal, INT16_MAX);
  4594. WBUFL(buf,6)=dst->id;
  4595. WBUFL(buf,10)=src?src->id:0;
  4596. WBUFB(buf,14)=fail;
  4597. if (disguised(dst)) {
  4598. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4599. WBUFL(buf,6)=-dst->id;
  4600. clif_send(buf,packet_len(0x11a),dst,SELF);
  4601. } else
  4602. clif_send(buf,packet_len(0x11a),dst,AREA);
  4603. if(src && disguised(src)) {
  4604. WBUFL(buf,10)=-src->id;
  4605. if (disguised(dst))
  4606. WBUFL(buf,6)=dst->id;
  4607. clif_send(buf,packet_len(0x11a),src,SELF);
  4608. }
  4609. return fail;
  4610. }
  4611. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4612. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4613. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4614. {
  4615. unsigned char buf[32];
  4616. nullpo_retv(src);
  4617. WBUFW(buf,0)=0x117;
  4618. WBUFW(buf,2)=skill_id;
  4619. WBUFL(buf,4)=src->id;
  4620. WBUFW(buf,8)=val;
  4621. WBUFW(buf,10)=x;
  4622. WBUFW(buf,12)=y;
  4623. WBUFL(buf,14)=tick;
  4624. if(disguised(src)) {
  4625. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4626. WBUFL(buf,4)=-src->id;
  4627. clif_send(buf,packet_len(0x117),src,SELF);
  4628. } else
  4629. clif_send(buf,packet_len(0x117),src,AREA);
  4630. }
  4631. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4632. /// 011c <skill id>.W { <map name>.16B }*4
  4633. 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)
  4634. {
  4635. int fd;
  4636. nullpo_retv(sd);
  4637. fd = sd->fd;
  4638. WFIFOHEAD(fd,packet_len(0x11c));
  4639. WFIFOW(fd,0) = 0x11c;
  4640. WFIFOW(fd,2) = skill_id;
  4641. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4642. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4643. else // normal map name
  4644. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4645. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4646. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4647. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4648. WFIFOSET(fd,packet_len(0x11c));
  4649. sd->menuskill_id = skill_id;
  4650. if (skill_id == AL_WARP)
  4651. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4652. else
  4653. sd->menuskill_val = skill_lv;
  4654. }
  4655. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4656. /// 011e <type>.B
  4657. /// type:
  4658. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4659. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4660. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4661. ///
  4662. /// @param sd Who receives the message
  4663. /// @param type What message
  4664. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4665. {
  4666. int fd;
  4667. nullpo_retv(sd);
  4668. fd=sd->fd;
  4669. WFIFOHEAD(fd,packet_len(0x11e));
  4670. WFIFOW(fd,0)=0x11e;
  4671. WFIFOB(fd,2)=type;
  4672. WFIFOSET(fd,packet_len(0x11e));
  4673. }
  4674. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4675. /// 0189 <type>.W
  4676. /// type:
  4677. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4678. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4679. ///
  4680. /// @param sd Who receives the message
  4681. /// @param type What message
  4682. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4683. {
  4684. int fd;
  4685. nullpo_retv(sd);
  4686. fd=sd->fd;
  4687. WFIFOHEAD(fd,packet_len(0x189));
  4688. WFIFOW(fd,0)=0x189;
  4689. WFIFOW(fd,2)=type;
  4690. WFIFOSET(fd,packet_len(0x189));
  4691. }
  4692. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4693. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4694. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4695. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4696. {
  4697. struct status_data *status;
  4698. unsigned char buf[64];
  4699. int i;//, fix;
  4700. nullpo_retv(sd);
  4701. nullpo_retv(dst);
  4702. if( dst->type != BL_MOB )
  4703. return;
  4704. status = status_get_status_data(dst);
  4705. WBUFW(buf, 0)=0x18c;
  4706. WBUFW(buf, 2)=status_get_class(dst);
  4707. WBUFW(buf, 4)=status_get_lv(dst);
  4708. WBUFW(buf, 6)=status->size;
  4709. WBUFL(buf, 8)=status->hp;
  4710. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4711. +(battle_config.estimation_type&2?status->def2:0);
  4712. WBUFW(buf,14)=status->race;
  4713. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4714. +(battle_config.estimation_type&2?status->mdef2:0);
  4715. WBUFW(buf,18)= status->def_ele;
  4716. for(i=0;i<9;i++)
  4717. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4718. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4719. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4720. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4721. }
  4722. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4723. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4724. /// material id:
  4725. /// unused by the client
  4726. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4727. {
  4728. int i,c,view,fd;
  4729. nullpo_retv(sd);
  4730. if (sd->menuskill_id == skill_id)
  4731. return; //Avoid resending the menu twice or more times...
  4732. if (skill_id == GC_CREATENEWPOISON)
  4733. skill_id = GC_RESEARCHNEWPOISON;
  4734. fd = sd->fd;
  4735. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4736. WFIFOW(fd, 0) = 0x18d;
  4737. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  4738. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4739. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  4740. )
  4741. {
  4742. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4743. WFIFOW(fd,c*8+ 4) = view;
  4744. else
  4745. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  4746. WFIFOW(fd,c*8+ 6) = 0;
  4747. WFIFOW(fd,c*8+ 8) = 0;
  4748. WFIFOW(fd,c*8+10) = 0;
  4749. c++;
  4750. }
  4751. }
  4752. WFIFOW(fd, 2) = c*8+8;
  4753. WFIFOSET(fd,WFIFOW(fd,2));
  4754. if (c > 0) {
  4755. sd->menuskill_id = skill_id;
  4756. sd->menuskill_val = trigger;
  4757. return;
  4758. }
  4759. }
  4760. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4761. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4762. /// mk type:
  4763. /// 1 = cooking
  4764. /// 2 = arrow
  4765. /// 3 = elemental
  4766. /// 4 = GN_MIX_COOKING
  4767. /// 5 = GN_MAKEBOMB
  4768. /// 6 = GN_S_PHARMACY
  4769. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4770. {
  4771. int fd;
  4772. int i, c;
  4773. int view;
  4774. nullpo_retv(sd);
  4775. fd = sd->fd;
  4776. if(sd->menuskill_id == skill_id)
  4777. return; //Avoid resending the menu twice or more times...
  4778. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4779. WFIFOW(fd,0) = 0x25a;
  4780. WFIFOW(fd,4) = list_type; // list type
  4781. c = 0;
  4782. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4783. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4784. continue;
  4785. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4786. WFIFOW(fd, 6 + 2 * c) = view;
  4787. else
  4788. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4789. c++;
  4790. }
  4791. if( c > 0 || skill_id == AM_PHARMACY) {
  4792. sd->menuskill_id = skill_id;
  4793. sd->menuskill_val = trigger;
  4794. sd->menuskill_val2 = qty; // amount.
  4795. WFIFOW(fd,2) = 6 + 2 * c;
  4796. WFIFOSET(fd,WFIFOW(fd,2));
  4797. } else {
  4798. clif_menuskill_clear(sd);
  4799. #if PACKETVER >= 20090922
  4800. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  4801. #else
  4802. WFIFOW(fd,2) = 6 + 2 * c;
  4803. WFIFOSET(fd,WFIFOW(fd,2));
  4804. #endif
  4805. }
  4806. }
  4807. /// Notifies clients of a status change.
  4808. /// 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)]
  4809. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4810. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  4811. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4812. {
  4813. unsigned char buf[32];
  4814. struct map_session_data *sd;
  4815. if (type == SI_BLANK) //It shows nothing on the client...
  4816. return;
  4817. nullpo_retv(bl);
  4818. sd = BL_CAST(BL_PC, bl);
  4819. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4820. return;
  4821. #if PACKETVER >= 20120618
  4822. if(flag && battle_config.display_status_timers && sd)
  4823. WBUFW(buf,0)=0x983;
  4824. else
  4825. #elif PACKETVER >= 20090121
  4826. if(flag && battle_config.display_status_timers && sd)
  4827. WBUFW(buf,0)=0x43f;
  4828. else
  4829. #endif
  4830. WBUFW(buf,0)=0x196;
  4831. WBUFW(buf,2)=type;
  4832. WBUFL(buf,4)=bl->id;
  4833. WBUFB(buf,8)=flag;
  4834. #if PACKETVER >= 20120618
  4835. if(flag && battle_config.display_status_timers && sd) {
  4836. if (tick <= 0)
  4837. tick = 9999; // this is indeed what official servers do
  4838. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4839. WBUFL(buf,13)=tick;
  4840. WBUFL(buf,17) = val1;
  4841. WBUFL(buf,21) = val2;
  4842. WBUFL(buf,25) = val3;
  4843. }
  4844. #elif PACKETVER >= 20090121
  4845. if(flag && battle_config.display_status_timers && sd) {
  4846. if (tick <= 0)
  4847. tick = 9999; // this is indeed what official servers do
  4848. WBUFL(buf,9) = tick;
  4849. WBUFL(buf,13) = val1;
  4850. WBUFL(buf,17) = val2;
  4851. WBUFL(buf,21) = val3;
  4852. }
  4853. #endif
  4854. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4855. }
  4856. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  4857. unsigned char buf[32];
  4858. if (type == SI_BLANK) //It shows nothing on the client
  4859. return;
  4860. nullpo_retv(bl);
  4861. WBUFW(buf,0) = 0x43f;
  4862. WBUFW(buf,2) = type;
  4863. WBUFL(buf,4) = tid;
  4864. WBUFB(buf,8) = 1;
  4865. WBUFL(buf,9) = 9999;
  4866. WBUFL(buf,13) = val1;
  4867. WBUFL(buf,17) = val2;
  4868. WBUFL(buf,21) = val3;
  4869. clif_send(buf,packet_len(0x43f),bl,target);
  4870. }
  4871. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  4872. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  4873. //! TODO
  4874. //void clif_efst_enter();
  4875. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4876. /// 008e <packet len>.W <message>.?B
  4877. void clif_displaymessage(const int fd, const char* mes)
  4878. {
  4879. nullpo_retv(mes);
  4880. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4881. if (fd == 0)
  4882. ;
  4883. else {
  4884. char *message, *line;
  4885. message = aStrdup(mes);
  4886. line = strtok(message, "\n");
  4887. while(line != NULL) {
  4888. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4889. int len = strnlen(line, 255);
  4890. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4891. WFIFOHEAD(fd, 5 + len);
  4892. WFIFOW(fd,0) = 0x8e;
  4893. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4894. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4895. WFIFOSET(fd, 5 + len);
  4896. }
  4897. line = strtok(NULL, "\n");
  4898. }
  4899. aFree(message);
  4900. }
  4901. }
  4902. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4903. /// 009a <packet len>.W <message>.?B
  4904. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4905. {
  4906. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  4907. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4908. WBUFW(buf,0) = 0x9a;
  4909. WBUFW(buf,2) = 4 + lp + len;
  4910. if (type&BC_BLUE)
  4911. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4912. else if (type&BC_WOE)
  4913. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4914. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4915. clif_send(buf, WBUFW(buf,2), bl, target);
  4916. if (buf)
  4917. aFree(buf);
  4918. }
  4919. /*==========================================
  4920. * Displays a message on a 'bl' to all it's nearby clients
  4921. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4922. *------------------------------------------*/
  4923. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4924. char buf[100];
  4925. int len;
  4926. nullpo_retv(bl);
  4927. if(!message)
  4928. return;
  4929. len = strlen(message)+1;
  4930. if( len > sizeof(buf)-8 ) {
  4931. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4932. len = sizeof(buf)-8;
  4933. }
  4934. WBUFW(buf,0)=0x8d;
  4935. WBUFW(buf,2)=len+8;
  4936. WBUFL(buf,4)=bl->id;
  4937. safestrncpy((char *) WBUFP(buf,8),message,len);
  4938. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4939. }
  4940. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4941. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4942. 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)
  4943. {
  4944. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4945. WBUFW(buf,0) = 0x1c3;
  4946. WBUFW(buf,2) = len + 16;
  4947. WBUFL(buf,4) = fontColor;
  4948. WBUFW(buf,8) = fontType;
  4949. WBUFW(buf,10) = fontSize;
  4950. WBUFW(buf,12) = fontAlign;
  4951. WBUFW(buf,14) = fontY;
  4952. memcpy(WBUFP(buf,16), mes, len);
  4953. clif_send(buf, WBUFW(buf,2), bl, target);
  4954. if (buf)
  4955. aFree(buf);
  4956. }
  4957. /*
  4958. * Display *msg from *sd to all *users in channel
  4959. */
  4960. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4961. DBIterator *iter;
  4962. struct map_session_data *user;
  4963. unsigned short msg_len = strlen(msg) + 1;
  4964. WFIFOHEAD(sd->fd,msg_len + 12);
  4965. WFIFOW(sd->fd,0) = 0x2C1;
  4966. WFIFOW(sd->fd,2) = msg_len + 12;
  4967. WFIFOL(sd->fd,4) = 0;
  4968. WFIFOL(sd->fd,8) = channel_config.colors[color];
  4969. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4970. iter = db_iterator(channel->users);
  4971. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4972. if( user->fd == sd->fd )
  4973. continue;
  4974. WFIFOHEAD(user->fd,msg_len + 12);
  4975. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4976. WFIFOSET(user->fd, msg_len + 12);
  4977. }
  4978. dbi_destroy(iter);
  4979. WFIFOSET(sd->fd, msg_len + 12);
  4980. }
  4981. /// Displays heal effect (ZC_RECOVERY).
  4982. /// 013d <var id>.W <amount>.W
  4983. /// var id:
  4984. /// 5 = HP (SP_HP)
  4985. /// 7 = SP (SP_SP)
  4986. /// ? = ignored
  4987. void clif_heal(int fd,int type,int val)
  4988. {
  4989. WFIFOHEAD(fd,packet_len(0x13d));
  4990. WFIFOW(fd,0)=0x13d;
  4991. WFIFOW(fd,2)=type;
  4992. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4993. WFIFOSET(fd,packet_len(0x13d));
  4994. }
  4995. /// Displays resurrection effect (ZC_RESURRECTION).
  4996. /// 0148 <id>.L <type>.W
  4997. /// type:
  4998. /// ignored
  4999. void clif_resurrection(struct block_list *bl,int type)
  5000. {
  5001. unsigned char buf[16];
  5002. nullpo_retv(bl);
  5003. WBUFW(buf,0)=0x148;
  5004. WBUFL(buf,2)=bl->id;
  5005. WBUFW(buf,6)=0;
  5006. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5007. if (disguised(bl))
  5008. clif_spawn(bl);
  5009. }
  5010. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5011. /// 0199 <type>.W
  5012. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5013. {
  5014. int fd;
  5015. nullpo_retv(sd);
  5016. fd=sd->fd;
  5017. WFIFOHEAD(fd,packet_len(0x199));
  5018. WFIFOW(fd,0)=0x199;
  5019. WFIFOW(fd,2)=property;
  5020. WFIFOSET(fd,packet_len(0x199));
  5021. }
  5022. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5023. #if PACKETVER >= 20121010
  5024. unsigned char buf[8];
  5025. unsigned int NotifyProperty =
  5026. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5027. ((map_flag_gvg(bl->m)?1:0)<<1)| // GUILD - Show attack cursor on non-guild members (GvG)
  5028. ((map_flag_gvg2(bl->m)?1:0)<<2)| // SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5029. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5030. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5031. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5032. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5033. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5034. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5035. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5036. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5037. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5038. WBUFW(buf,0)=0x99b;
  5039. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5040. WBUFL(buf,4)=NotifyProperty;
  5041. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5042. clif_send(buf,packet_len(0x99b),bl,t);
  5043. #endif
  5044. }
  5045. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5046. /// 01d6 <type>.W
  5047. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5048. {
  5049. int fd;
  5050. nullpo_retv(sd);
  5051. fd=sd->fd;
  5052. WFIFOHEAD(fd,packet_len(0x1D6));
  5053. WFIFOW(fd,0)=0x1D6;
  5054. WFIFOW(fd,2)=type;
  5055. WFIFOSET(fd,packet_len(0x1D6));
  5056. }
  5057. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5058. /// 019a <id>.L <ranking>.L <total>.L
  5059. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5060. {
  5061. if(type == 2) {
  5062. int fd = sd->fd;
  5063. WFIFOHEAD(fd,packet_len(0x19a));
  5064. WFIFOW(fd,0) = 0x19a;
  5065. WFIFOL(fd,2) = sd->bl.id;
  5066. WFIFOL(fd,6) = pvprank;
  5067. WFIFOL(fd,10) = pvpnum;
  5068. WFIFOSET(fd,packet_len(0x19a));
  5069. } else {
  5070. unsigned char buf[32];
  5071. WBUFW(buf,0) = 0x19a;
  5072. WBUFL(buf,2) = sd->bl.id;
  5073. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5074. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5075. else
  5076. WBUFL(buf,6) = pvprank;
  5077. WBUFL(buf,10) = pvpnum;
  5078. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5079. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5080. else if(!type)
  5081. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5082. else
  5083. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5084. }
  5085. }
  5086. /*==========================================
  5087. *
  5088. *------------------------------------------*/
  5089. void clif_map_property_mapall(int map_idx, enum map_property property)
  5090. {
  5091. struct block_list bl;
  5092. unsigned char buf[16];
  5093. bl.id = 0;
  5094. bl.type = BL_NUL;
  5095. bl.m = map_idx;
  5096. WBUFW(buf,0)=0x199;
  5097. WBUFW(buf,2)=property;
  5098. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5099. }
  5100. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5101. /// 0188 <result>.W <index>.W <refine>.W
  5102. /// result:
  5103. /// 0 = success
  5104. /// 1 = failure
  5105. /// 2 = downgrade
  5106. void clif_refine(int fd, int fail, int index, int val)
  5107. {
  5108. WFIFOHEAD(fd,packet_len(0x188));
  5109. WFIFOW(fd,0)=0x188;
  5110. WFIFOW(fd,2)=fail;
  5111. WFIFOW(fd,4)=index+2;
  5112. WFIFOW(fd,6)=val;
  5113. WFIFOSET(fd,packet_len(0x188));
  5114. }
  5115. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5116. /// 0223 <result>.L <nameid>.W
  5117. /// result:
  5118. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5119. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5120. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5121. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5122. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5123. {
  5124. WFIFOHEAD(fd,packet_len(0x223));
  5125. WFIFOW(fd,0)=0x223;
  5126. WFIFOL(fd,2)=result;
  5127. WFIFOW(fd,6)=item_id;
  5128. WFIFOSET(fd,packet_len(0x223));
  5129. }
  5130. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5131. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5132. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5133. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5134. {
  5135. #if PACKETVER < 20091104
  5136. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5137. WFIFOW(fd,0) = 0x97;
  5138. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5139. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5140. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5141. WFIFOSET(fd,WFIFOW(fd,2));
  5142. #else
  5143. struct map_session_data *ssd = map_nick2sd(nick);
  5144. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5145. WFIFOW(fd,0) = 0x97;
  5146. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5147. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5148. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5149. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5150. WFIFOSET(fd,WFIFOW(fd,2));
  5151. #endif
  5152. }
  5153. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5154. /// 0098 <result>.B
  5155. /// result:
  5156. /// 0 = success to send wisper
  5157. /// 1 = target character is not loged in
  5158. /// 2 = ignored by target
  5159. /// 3 = everyone ignored by target
  5160. void clif_wis_end(int fd, int result)
  5161. {
  5162. struct map_session_data *sd = (session_isValid(fd) ? session[fd]->session_data : NULL);
  5163. if (!sd)
  5164. return;
  5165. #if PACKETVER >= 20131223
  5166. WFIFOHEAD(fd,packet_len(0x9df));
  5167. WFIFOW(fd,0) = 0x9df;
  5168. WFIFOB(fd,2) = (char)result;
  5169. WFIFOL(fd,3) = 0;
  5170. WFIFOSET(fd,packet_len(0x9df));
  5171. #else
  5172. WFIFOHEAD(fd,packet_len(0x98));
  5173. WFIFOW(fd,0) = 0x98;
  5174. WFIFOB(fd,2) = (char)result;
  5175. WFIFOSET(fd,packet_len(0x98));
  5176. #endif
  5177. }
  5178. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5179. /// 0194 <char id>.L <name>.24B
  5180. void clif_solved_charname(int fd, int charid, const char* name)
  5181. {
  5182. WFIFOHEAD(fd,packet_len(0x194));
  5183. WFIFOW(fd,0)=0x194;
  5184. WFIFOL(fd,2)=charid;
  5185. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5186. WFIFOSET(fd,packet_len(0x194));
  5187. }
  5188. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5189. /// 017b <packet len>.W { <name id>.W }*
  5190. void clif_use_card(struct map_session_data *sd,int idx)
  5191. {
  5192. int i,c,ep;
  5193. int fd=sd->fd;
  5194. nullpo_retv(sd);
  5195. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5196. return;
  5197. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5198. return; //Avoid parsing invalid item indexes (no card/no item)
  5199. ep=sd->inventory_data[idx]->equip;
  5200. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5201. WFIFOW(fd,0)=0x17b;
  5202. for(i=c=0;i<MAX_INVENTORY;i++){
  5203. int j;
  5204. if(sd->inventory_data[i] == NULL)
  5205. continue;
  5206. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5207. continue;
  5208. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5209. continue;
  5210. if(sd->status.inventory[i].identify==0 ) //Not identified
  5211. continue;
  5212. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5213. continue;
  5214. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5215. continue;
  5216. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5217. if( j == sd->inventory_data[i]->slot ) // No room
  5218. continue;
  5219. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5220. continue;
  5221. WFIFOW(fd,4+c*2)=i+2;
  5222. c++;
  5223. }
  5224. if( !c ) return; // no item is available for card insertion
  5225. WFIFOW(fd,2)=4+c*2;
  5226. WFIFOSET(fd,WFIFOW(fd,2));
  5227. }
  5228. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5229. /// 017d <equip index>.W <card index>.W <result>.B
  5230. /// result:
  5231. /// 0 = success
  5232. /// 1 = failure
  5233. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5234. {
  5235. int fd;
  5236. nullpo_retv(sd);
  5237. fd=sd->fd;
  5238. WFIFOHEAD(fd,packet_len(0x17d));
  5239. WFIFOW(fd,0)=0x17d;
  5240. WFIFOW(fd,2)=idx_equip+2;
  5241. WFIFOW(fd,4)=idx_card+2;
  5242. WFIFOB(fd,6)=flag;
  5243. WFIFOSET(fd,packet_len(0x17d));
  5244. }
  5245. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5246. /// 0177 <packet len>.W { <name id>.W }*
  5247. void clif_item_identify_list(struct map_session_data *sd)
  5248. {
  5249. int i,c;
  5250. int fd;
  5251. nullpo_retv(sd);
  5252. fd=sd->fd;
  5253. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5254. WFIFOW(fd,0)=0x177;
  5255. for(i=c=0;i<MAX_INVENTORY;i++){
  5256. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5257. WFIFOW(fd,c*2+4)=i+2;
  5258. c++;
  5259. }
  5260. }
  5261. if(c > 0) {
  5262. WFIFOW(fd,2)=c*2+4;
  5263. WFIFOSET(fd,WFIFOW(fd,2));
  5264. sd->menuskill_id = MC_IDENTIFY;
  5265. sd->menuskill_val = c;
  5266. }
  5267. }
  5268. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5269. /// 0179 <index>.W <result>.B
  5270. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5271. {
  5272. int fd;
  5273. nullpo_retv(sd);
  5274. fd=sd->fd;
  5275. WFIFOHEAD(fd,packet_len(0x179));
  5276. WFIFOW(fd, 0)=0x179;
  5277. WFIFOW(fd, 2)=idx+2;
  5278. WFIFOB(fd, 4)=flag;
  5279. WFIFOSET(fd,packet_len(0x179));
  5280. }
  5281. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5282. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5283. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5284. {
  5285. int i,c;
  5286. int fd;
  5287. nullpo_retv(sd);
  5288. nullpo_retv(dstsd);
  5289. fd=sd->fd;
  5290. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5291. WFIFOW(fd,0)=0x1fc;
  5292. for(i=c=0;i<MAX_INVENTORY;i++){
  5293. unsigned short nameid;
  5294. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5295. WFIFOW(fd,c*13+4) = i;
  5296. WFIFOW(fd,c*13+6) = nameid;
  5297. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5298. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5299. c++;
  5300. }
  5301. }
  5302. if(c > 0) {
  5303. WFIFOW(fd,2)=c*13+4;
  5304. WFIFOSET(fd,WFIFOW(fd,2));
  5305. sd->menuskill_id = BS_REPAIRWEAPON;
  5306. sd->menuskill_val = dstsd->bl.id;
  5307. sd->menuskill_val2 = lv;
  5308. }else
  5309. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5310. }
  5311. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5312. /// 01fe <index>.W <result>.B
  5313. /// index:
  5314. /// ignored (inventory index)
  5315. /// result:
  5316. /// 0 = Item repair success.
  5317. /// 1 = Item repair failure.
  5318. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5319. {
  5320. int fd;
  5321. nullpo_retv(sd);
  5322. fd = sd->fd;
  5323. WFIFOHEAD(fd,packet_len(0x1fe));
  5324. WFIFOW(fd, 0)=0x1fe;
  5325. WFIFOW(fd, 2)=idx+2;
  5326. WFIFOB(fd, 4)=flag;
  5327. WFIFOSET(fd,packet_len(0x1fe));
  5328. }
  5329. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5330. /// 02bb <equip location>.W <account id>.L
  5331. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5332. {
  5333. int fd = sd->fd;
  5334. WFIFOHEAD(fd,packet_len(0x2bb));
  5335. WFIFOW(fd,0) = 0x2bb;
  5336. WFIFOW(fd,2) = position;
  5337. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5338. WFIFOSET(fd,packet_len(0x2bb));
  5339. }
  5340. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5341. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5342. void clif_item_refine_list(struct map_session_data *sd)
  5343. {
  5344. int i,c;
  5345. int fd;
  5346. uint16 skill_lv;
  5347. int refine_item[5];
  5348. nullpo_retv(sd);
  5349. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5350. fd=sd->fd;
  5351. refine_item[0] = -1;
  5352. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5353. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5354. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5355. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5356. WFIFOW(fd,0)=0x221;
  5357. for(i=c=0;i<MAX_INVENTORY;i++){
  5358. unsigned char wlv;
  5359. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5360. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5361. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5362. WFIFOW(fd,c*13+ 4)=i+2;
  5363. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5364. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5365. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5366. c++;
  5367. }
  5368. }
  5369. WFIFOW(fd,2)=c*13+4;
  5370. WFIFOSET(fd,WFIFOW(fd,2));
  5371. if (c > 0) {
  5372. sd->menuskill_id = WS_WEAPONREFINE;
  5373. sd->menuskill_val = skill_lv;
  5374. }
  5375. }
  5376. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5377. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5378. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5379. {
  5380. int fd;
  5381. nullpo_retv(sd);
  5382. fd=sd->fd;
  5383. WFIFOHEAD(fd,packet_len(0x147));
  5384. WFIFOW(fd, 0)=0x147;
  5385. WFIFOW(fd, 2)=skill_id;
  5386. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5387. WFIFOW(fd, 6)=0;
  5388. WFIFOW(fd, 8)=skill_lv;
  5389. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5390. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5391. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5392. WFIFOB(fd,38)=0;
  5393. WFIFOSET(fd,packet_len(0x147));
  5394. }
  5395. /// Adds an item to character's cart.
  5396. /// 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)
  5397. /// 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)
  5398. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5399. {
  5400. int view,fd;
  5401. unsigned char *buf;
  5402. nullpo_retv(sd);
  5403. fd=sd->fd;
  5404. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5405. return;
  5406. #if PACKETVER < 5
  5407. WFIFOHEAD(fd,packet_len(0x124));
  5408. buf=WFIFOP(fd,0);
  5409. WBUFW(buf,0)=0x124;
  5410. WBUFW(buf,2)=n+2;
  5411. WBUFL(buf,4)=amount;
  5412. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5413. WBUFW(buf,8)=view;
  5414. else
  5415. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5416. WBUFB(buf,10)=sd->status.cart[n].identify;
  5417. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5418. WBUFB(buf,12)=sd->status.cart[n].refine;
  5419. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5420. WFIFOSET(fd,packet_len(0x124));
  5421. #else
  5422. WFIFOHEAD(fd,packet_len(0x1c5));
  5423. buf=WFIFOP(fd,0);
  5424. WBUFW(buf,0)=0x1c5;
  5425. WBUFW(buf,2)=n+2;
  5426. WBUFL(buf,4)=amount;
  5427. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5428. WBUFW(buf,8)=view;
  5429. else
  5430. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5431. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5432. WBUFB(buf,11)=sd->status.cart[n].identify;
  5433. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5434. WBUFB(buf,13)=sd->status.cart[n].refine;
  5435. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5436. WFIFOSET(fd,packet_len(0x1c5));
  5437. #endif
  5438. }
  5439. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5440. /* Acknowledge an item have been added to cart
  5441. * 012c <result>B
  5442. * result :
  5443. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5444. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5445. */
  5446. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5447. {
  5448. int fd;
  5449. unsigned char *buf;
  5450. nullpo_retv(sd);
  5451. fd = sd->fd;
  5452. buf = WFIFOP(fd,0);
  5453. WBUFW(buf,0) = 0x12c;
  5454. WBUFB(buf,2) = flag;
  5455. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5456. }
  5457. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5458. void clif_bank_open(struct map_session_data *sd){
  5459. int fd;
  5460. nullpo_retv(sd);
  5461. fd = sd->fd;
  5462. WFIFOHEAD(fd,4);
  5463. WFIFOW(fd,0) = 0x09b7;
  5464. WFIFOW(fd,2) = 0;
  5465. WFIFOSET(fd,4);
  5466. }
  5467. /*
  5468. * Request to Open the banking system
  5469. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5470. */
  5471. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5472. //TODO check if preventing trade or stuff like that
  5473. //also mark something in case char ain't available for saving, should we check now ?
  5474. nullpo_retv(sd);
  5475. if( !battle_config.feature_banking ) {
  5476. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5477. return;
  5478. }
  5479. else {
  5480. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5481. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5482. if(sd->status.account_id == aid){
  5483. sd->state.banking = 1;
  5484. //request save ?
  5485. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5486. //on succes open bank ?
  5487. clif_bank_open(sd);
  5488. }
  5489. }
  5490. }
  5491. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5492. void clif_bank_close(struct map_session_data *sd){
  5493. int fd;
  5494. nullpo_retv(sd);
  5495. fd = sd->fd;
  5496. WFIFOHEAD(fd,4);
  5497. WFIFOW(fd,0) = 0x09B9;
  5498. WFIFOW(fd,2) = 0;
  5499. WFIFOSET(fd,4);
  5500. }
  5501. /*
  5502. * Request to close the banking system
  5503. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5504. */
  5505. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5506. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5507. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5508. nullpo_retv(sd);
  5509. if( !battle_config.feature_banking ) {
  5510. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5511. //still allow to go trough to not stuck player if we have disable it while they was in
  5512. }
  5513. if(sd->status.account_id == aid){
  5514. sd->state.banking = 0;
  5515. clif_bank_close(sd);
  5516. }
  5517. }
  5518. /*
  5519. * Display how much we got in bank (I suppose)
  5520. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5521. */
  5522. void clif_Bank_Check(struct map_session_data* sd) {
  5523. unsigned char buf[13];
  5524. struct s_packet_db* info;
  5525. int16 len;
  5526. int cmd = 0;
  5527. nullpo_retv(sd);
  5528. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5529. if(!cmd) cmd = 0x09A6; //default
  5530. info = &packet_db[sd->packet_ver][cmd];
  5531. len = info->len;
  5532. if(!len) return; //version as packet disable
  5533. // sd->state.banking = 1; //mark opening and closing
  5534. WBUFW(buf,0) = cmd;
  5535. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5536. WBUFW(buf,info->pos[1]) = 0; //reason
  5537. clif_send(buf,len,&sd->bl,SELF);
  5538. }
  5539. /*
  5540. * Requesting the data in bank
  5541. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5542. */
  5543. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5544. nullpo_retv(sd);
  5545. if( !battle_config.feature_banking ) {
  5546. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5547. return;
  5548. }
  5549. else {
  5550. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5551. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5552. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5553. clif_Bank_Check(sd);
  5554. }
  5555. }
  5556. /*
  5557. * Acknowledge of deposit some money in bank
  5558. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5559. */
  5560. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5561. unsigned char buf[17];
  5562. struct s_packet_db* info;
  5563. int16 len;
  5564. int cmd =0;
  5565. nullpo_retv(sd);
  5566. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5567. if(!cmd) cmd = 0x09A8;
  5568. info = &packet_db[sd->packet_ver][cmd];
  5569. len = info->len;
  5570. if(!len) return; //version as packet disable
  5571. WBUFW(buf,0) = cmd;
  5572. WBUFW(buf,info->pos[0]) = (short)reason;
  5573. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5574. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5575. clif_send(buf,len,&sd->bl,SELF);
  5576. }
  5577. /*
  5578. * Request saving some money in bank
  5579. * @author : original [Yommy/Hercules]
  5580. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5581. */
  5582. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5583. nullpo_retv(sd);
  5584. if( !battle_config.feature_banking ) {
  5585. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5586. return;
  5587. }
  5588. else {
  5589. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5590. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5591. int money = RFIFOL(fd,info->pos[1]);
  5592. if(sd->status.account_id == aid){
  5593. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5594. clif_bank_deposit(sd,reason);
  5595. }
  5596. }
  5597. }
  5598. /*
  5599. * Acknowledge of withdrawing some money from bank
  5600. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5601. */
  5602. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5603. unsigned char buf[17];
  5604. struct s_packet_db* info;
  5605. int16 len;
  5606. int cmd;
  5607. nullpo_retv(sd);
  5608. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5609. if(!cmd) cmd = 0x09AA;
  5610. info = &packet_db[sd->packet_ver][cmd];
  5611. len = info->len;
  5612. if(!len) return; //version as packet disable
  5613. WBUFW(buf,0) = cmd;
  5614. WBUFW(buf,info->pos[0]) = (short)reason;
  5615. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5616. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5617. clif_send(buf,len,&sd->bl,SELF);
  5618. }
  5619. /*
  5620. * Request Withdrawing some money from bank
  5621. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5622. */
  5623. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5624. nullpo_retv(sd);
  5625. if( !battle_config.feature_banking ) {
  5626. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5627. return;
  5628. }
  5629. else {
  5630. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5631. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5632. int money = RFIFOL(fd,info->pos[1]);
  5633. if(sd->status.account_id == aid){
  5634. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5635. clif_bank_withdraw(sd,reason);
  5636. }
  5637. }
  5638. }
  5639. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5640. /// 0125 <index>.W <amount>.L
  5641. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5642. {
  5643. int fd;
  5644. nullpo_retv(sd);
  5645. fd=sd->fd;
  5646. WFIFOHEAD(fd,packet_len(0x125));
  5647. WFIFOW(fd,0)=0x125;
  5648. WFIFOW(fd,2)=n+2;
  5649. WFIFOL(fd,4)=amount;
  5650. WFIFOSET(fd,packet_len(0x125));
  5651. }
  5652. /// Opens the shop creation menu (ZC_OPENSTORE).
  5653. /// 012d <num>.W
  5654. /// num:
  5655. /// number of allowed item slots
  5656. void clif_openvendingreq(struct map_session_data* sd, int num)
  5657. {
  5658. int fd;
  5659. nullpo_retv(sd);
  5660. fd = sd->fd;
  5661. WFIFOHEAD(fd,packet_len(0x12d));
  5662. WFIFOW(fd,0) = 0x12d;
  5663. WFIFOW(fd,2) = num;
  5664. WFIFOSET(fd,packet_len(0x12d));
  5665. }
  5666. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5667. /// 0131 <owner id>.L <message>.80B
  5668. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5669. {
  5670. unsigned char buf[128];
  5671. nullpo_retv(bl);
  5672. WBUFW(buf,0) = 0x131;
  5673. WBUFL(buf,2) = bl->id;
  5674. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5675. if( fd ) {
  5676. WFIFOHEAD(fd,packet_len(0x131));
  5677. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5678. WFIFOSET(fd,packet_len(0x131));
  5679. } else {
  5680. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5681. }
  5682. }
  5683. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5684. /// 0132 <owner id>.L
  5685. void clif_closevendingboard(struct block_list* bl, int fd)
  5686. {
  5687. unsigned char buf[16];
  5688. nullpo_retv(bl);
  5689. WBUFW(buf,0) = 0x132;
  5690. WBUFL(buf,2) = bl->id;
  5691. if( fd ) {
  5692. WFIFOHEAD(fd,packet_len(0x132));
  5693. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5694. WFIFOSET(fd,packet_len(0x132));
  5695. } else {
  5696. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5697. }
  5698. }
  5699. /// Sends a list of items in a shop.
  5700. /// 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)
  5701. /// 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)
  5702. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5703. {
  5704. int i,fd;
  5705. int count;
  5706. struct map_session_data* vsd;
  5707. #if PACKETVER < 20100105
  5708. const int cmd = 0x133;
  5709. const int offset = 8;
  5710. #else
  5711. const int cmd = 0x800;
  5712. const int offset = 12;
  5713. #endif
  5714. nullpo_retv(sd);
  5715. nullpo_retv(vending);
  5716. nullpo_retv(vsd=map_id2sd(id));
  5717. fd = sd->fd;
  5718. count = vsd->vend_num;
  5719. WFIFOHEAD(fd, offset+count*22);
  5720. WFIFOW(fd,0) = cmd;
  5721. WFIFOW(fd,2) = offset+count*22;
  5722. WFIFOL(fd,4) = id;
  5723. #if PACKETVER >= 20100105
  5724. WFIFOL(fd,8) = vsd->vender_id;
  5725. #endif
  5726. for( i = 0; i < count; i++ )
  5727. {
  5728. int index = vending[i].index;
  5729. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5730. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5731. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5732. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5733. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5734. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5735. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5736. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5737. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5738. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5739. }
  5740. WFIFOSET(fd,WFIFOW(fd,2));
  5741. }
  5742. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5743. /// 0135 <index>.W <amount>.W <result>.B
  5744. /// result:
  5745. /// 0 = success
  5746. /// 1 = not enough zeny
  5747. /// 2 = overweight
  5748. /// 4 = out of stock
  5749. /// 5 = "cannot use an npc shop while in a trade"
  5750. /// 6 = Because the store information was incorrect the item was not purchased.
  5751. /// 7 = No sales information.
  5752. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5753. {
  5754. int fd;
  5755. nullpo_retv(sd);
  5756. fd = sd->fd;
  5757. WFIFOHEAD(fd,packet_len(0x135));
  5758. WFIFOW(fd,0) = 0x135;
  5759. WFIFOW(fd,2) = index+2;
  5760. WFIFOW(fd,4) = amount;
  5761. WFIFOB(fd,6) = fail;
  5762. WFIFOSET(fd,packet_len(0x135));
  5763. }
  5764. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5765. /// 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 }*
  5766. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5767. {
  5768. int i,fd;
  5769. int count;
  5770. nullpo_retv(sd);
  5771. fd = sd->fd;
  5772. count = sd->vend_num;
  5773. WFIFOHEAD(fd, 8+count*22);
  5774. WFIFOW(fd,0) = 0x136;
  5775. WFIFOW(fd,2) = 8+count*22;
  5776. WFIFOL(fd,4) = id;
  5777. for( i = 0; i < count; i++ ) {
  5778. int index = vending[i].index;
  5779. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5780. WFIFOL(fd, 8+i*22) = vending[i].value;
  5781. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5782. WFIFOW(fd,14+i*22) = vending[i].amount;
  5783. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5784. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5785. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5786. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5787. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5788. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5789. }
  5790. WFIFOSET(fd,WFIFOW(fd,2));
  5791. }
  5792. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5793. /// 0137 <index>.W <amount>.W
  5794. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5795. {
  5796. int fd;
  5797. nullpo_retv(sd);
  5798. fd = sd->fd;
  5799. WFIFOHEAD(fd,packet_len(0x137));
  5800. WFIFOW(fd,0) = 0x137;
  5801. WFIFOW(fd,2) = index+2;
  5802. WFIFOW(fd,4) = amount;
  5803. WFIFOSET(fd,packet_len(0x137));
  5804. }
  5805. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5806. /// 00fa <result>.B
  5807. /// result:
  5808. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5809. /// 1 = MsgStringTable[78]="party name already exists"
  5810. /// 2 = MsgStringTable[79]="already in a party"
  5811. /// 3 = cannot organize parties on this map
  5812. /// ? = nothing
  5813. void clif_party_created(struct map_session_data *sd,int result)
  5814. {
  5815. int fd;
  5816. nullpo_retv(sd);
  5817. fd=sd->fd;
  5818. WFIFOHEAD(fd,packet_len(0xfa));
  5819. WFIFOW(fd,0)=0xfa;
  5820. WFIFOB(fd,2)=result;
  5821. WFIFOSET(fd,packet_len(0xfa));
  5822. }
  5823. /// Adds new member to a party.
  5824. /// 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)
  5825. /// 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)
  5826. /// role:
  5827. /// 0 = leader
  5828. /// 1 = normal
  5829. /// state:
  5830. /// 0 = connected
  5831. /// 1 = disconnected
  5832. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5833. {
  5834. unsigned char buf[81];
  5835. int i;
  5836. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5837. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5838. } else {
  5839. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5840. }
  5841. if (i >= MAX_PARTY) return; //Should never happen...
  5842. sd = p->data[i].sd;
  5843. WBUFW(buf, 0) = 0x1e9;
  5844. WBUFL(buf, 2) = sd->status.account_id;
  5845. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5846. WBUFW(buf,10) = sd->bl.x;
  5847. WBUFW(buf,12) = sd->bl.y;
  5848. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5849. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5850. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5851. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  5852. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5853. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5854. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5855. }
  5856. /// Sends party information (ZC_GROUP_LIST).
  5857. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5858. /// role:
  5859. /// 0 = leader
  5860. /// 1 = normal
  5861. /// state:
  5862. /// 0 = connected
  5863. /// 1 = disconnected
  5864. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5865. {
  5866. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5867. struct map_session_data* party_sd = NULL;
  5868. int i, c;
  5869. nullpo_retv(p);
  5870. WBUFW(buf,0) = 0xfb;
  5871. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5872. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5873. {
  5874. struct party_member* m = &p->party.member[i];
  5875. if(!m->account_id) continue;
  5876. if(party_sd == NULL) party_sd = p->data[i].sd;
  5877. WBUFL(buf,28+c*46) = m->account_id;
  5878. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5879. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5880. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5881. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5882. c++;
  5883. }
  5884. WBUFW(buf,2) = 28+c*46;
  5885. if(sd) { // send only to self
  5886. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5887. } else if (party_sd) { // send to whole party
  5888. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5889. }
  5890. }
  5891. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5892. /// 02c9 <flag>.B
  5893. /// flag:
  5894. /// 0 = allow party invites
  5895. /// 1 = auto-deny party invites
  5896. void clif_partyinvitationstate(struct map_session_data* sd)
  5897. {
  5898. int fd;
  5899. nullpo_retv(sd);
  5900. fd = sd->fd;
  5901. WFIFOHEAD(fd, packet_len(0x2c9));
  5902. WFIFOW(fd, 0) = 0x2c9;
  5903. WFIFOB(fd, 2) = 0; // not implemented
  5904. WFIFOSET(fd, packet_len(0x2c9));
  5905. }
  5906. /// Party invitation request.
  5907. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5908. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5909. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5910. {
  5911. #if PACKETVER < 20070821
  5912. const int cmd = 0xfe;
  5913. #else
  5914. const int cmd = 0x2c6;
  5915. #endif
  5916. int fd;
  5917. struct party_data *p;
  5918. nullpo_retv(sd);
  5919. nullpo_retv(tsd);
  5920. fd=tsd->fd;
  5921. if( (p=party_search(sd->status.party_id))==NULL )
  5922. return;
  5923. WFIFOHEAD(fd,packet_len(cmd));
  5924. WFIFOW(fd,0)=cmd;
  5925. WFIFOL(fd,2)=sd->status.party_id;
  5926. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5927. WFIFOSET(fd,packet_len(cmd));
  5928. }
  5929. /// Party invite result.
  5930. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5931. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5932. /// result=0 : char is already in a party -> MsgStringTable[80]
  5933. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5934. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5935. /// result=3 : party is full -> MsgStringTable[83]
  5936. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5937. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5938. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5939. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5940. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5941. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5942. {
  5943. int fd;
  5944. nullpo_retv(sd);
  5945. fd=sd->fd;
  5946. #if PACKETVER < 20070904
  5947. if( result == 7 ) {
  5948. clif_displaymessage(fd, msg_txt(sd,3));
  5949. return;
  5950. }
  5951. #endif
  5952. #if PACKETVER < 20070821
  5953. WFIFOHEAD(fd,packet_len(0xfd));
  5954. WFIFOW(fd,0) = 0xfd;
  5955. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5956. WFIFOB(fd,26) = result;
  5957. WFIFOSET(fd,packet_len(0xfd));
  5958. #else
  5959. WFIFOHEAD(fd,packet_len(0x2c5));
  5960. WFIFOW(fd,0) = 0x2c5;
  5961. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5962. WFIFOL(fd,26) = result;
  5963. WFIFOSET(fd,packet_len(0x2c5));
  5964. #endif
  5965. }
  5966. /// Updates party settings.
  5967. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5968. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5969. /// exp option:
  5970. /// 0 = exp sharing disabled
  5971. /// 1 = exp sharing enabled
  5972. /// 2 = cannot change exp sharing
  5973. ///
  5974. /// flag:
  5975. /// 0 = send to party
  5976. /// 1 = send to sd
  5977. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5978. {
  5979. unsigned char buf[16];
  5980. #if PACKETVER < 20090603
  5981. const int cmd = 0x101;
  5982. #else
  5983. const int cmd = 0x7d8;
  5984. #endif
  5985. nullpo_retv(p);
  5986. if(!sd && flag==0){
  5987. int i;
  5988. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5989. if (i < MAX_PARTY)
  5990. sd = p->data[i].sd;
  5991. }
  5992. if(!sd) return;
  5993. WBUFW(buf,0)=cmd;
  5994. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5995. #if PACKETVER >= 20090603
  5996. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5997. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5998. #endif
  5999. if(flag==0)
  6000. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6001. else
  6002. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6003. }
  6004. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6005. /// result:
  6006. /// 0 = leave
  6007. /// 1 = expel
  6008. /// 2 = cannot leave party on this map
  6009. /// 3 = cannot expel from party on this map
  6010. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  6011. {
  6012. unsigned char buf[64];
  6013. nullpo_retv(p);
  6014. if(!sd && (flag&0xf0)==0)
  6015. {
  6016. int i;
  6017. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6018. if (i < MAX_PARTY)
  6019. sd = p->data[i].sd;
  6020. }
  6021. if(!sd) return;
  6022. WBUFW(buf,0)=0x105;
  6023. WBUFL(buf,2)=account_id;
  6024. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6025. WBUFB(buf,30)=flag&0x0f;
  6026. if((flag&0xf0)==0)
  6027. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6028. else
  6029. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6030. }
  6031. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6032. /// 0109 <packet len>.W <account id>.L <message>.?B
  6033. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  6034. {
  6035. struct map_session_data *sd;
  6036. int i;
  6037. nullpo_retv(p);
  6038. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6039. if(i < MAX_PARTY){
  6040. unsigned char buf[1024];
  6041. if( len > sizeof(buf)-8 )
  6042. {
  6043. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6044. len = sizeof(buf)-8;
  6045. }
  6046. sd = p->data[i].sd;
  6047. WBUFW(buf,0)=0x109;
  6048. WBUFW(buf,2)=len+8;
  6049. WBUFL(buf,4)=account_id;
  6050. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6051. clif_send(buf,len+8,&sd->bl,PARTY);
  6052. }
  6053. }
  6054. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6055. /// 0107 <account id>.L <x>.W <y>.W
  6056. void clif_party_xy(struct map_session_data *sd)
  6057. {
  6058. unsigned char buf[16];
  6059. nullpo_retv(sd);
  6060. WBUFW(buf,0)=0x107;
  6061. WBUFL(buf,2)=sd->status.account_id;
  6062. WBUFW(buf,6)=sd->bl.x;
  6063. WBUFW(buf,8)=sd->bl.y;
  6064. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6065. }
  6066. /*==========================================
  6067. * Sends x/y dot to a single fd. [Skotlex]
  6068. *------------------------------------------*/
  6069. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6070. {
  6071. WFIFOHEAD(fd,packet_len(0x107));
  6072. WFIFOW(fd,0)=0x107;
  6073. WFIFOL(fd,2)=sd->status.account_id;
  6074. WFIFOW(fd,6)=sd->bl.x;
  6075. WFIFOW(fd,8)=sd->bl.y;
  6076. WFIFOSET(fd,packet_len(0x107));
  6077. }
  6078. /// Updates HP bar of a party member.
  6079. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6080. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6081. void clif_party_hp(struct map_session_data *sd)
  6082. {
  6083. unsigned char buf[16];
  6084. #if PACKETVER < 20100126
  6085. const int cmd = 0x106;
  6086. #else
  6087. const int cmd = 0x80e;
  6088. #endif
  6089. nullpo_retv(sd);
  6090. WBUFW(buf,0)=cmd;
  6091. WBUFL(buf,2)=sd->status.account_id;
  6092. #if PACKETVER < 20100126
  6093. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6094. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6095. WBUFW(buf,8) = 100;
  6096. } else {
  6097. WBUFW(buf,6) = sd->battle_status.hp;
  6098. WBUFW(buf,8) = sd->battle_status.max_hp;
  6099. }
  6100. #else
  6101. WBUFL(buf,6) = sd->battle_status.hp;
  6102. WBUFL(buf,10) = sd->battle_status.max_hp;
  6103. #endif
  6104. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6105. }
  6106. /*==========================================
  6107. * Sends HP bar to a single fd. [Skotlex]
  6108. *------------------------------------------*/
  6109. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6110. {
  6111. #if PACKETVER < 20100126
  6112. const int cmd = 0x106;
  6113. #else
  6114. const int cmd = 0x80e;
  6115. #endif
  6116. WFIFOHEAD(fd,packet_len(cmd));
  6117. WFIFOW(fd,0) = cmd;
  6118. WFIFOL(fd,2) = id;
  6119. #if PACKETVER < 20100126
  6120. if( maxhp > INT16_MAX )
  6121. {// To correctly display the %hp bar. [Skotlex]
  6122. WFIFOW(fd,6) = hp/(maxhp/100);
  6123. WFIFOW(fd,8) = 100;
  6124. } else {
  6125. WFIFOW(fd,6) = hp;
  6126. WFIFOW(fd,8) = maxhp;
  6127. }
  6128. #else
  6129. WFIFOL(fd,6) = hp;
  6130. WFIFOL(fd,10) = maxhp;
  6131. #endif
  6132. WFIFOSET(fd, packet_len(cmd));
  6133. }
  6134. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6135. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6136. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6137. {
  6138. int fd;
  6139. nullpo_retv(sd);
  6140. nullpo_retv(bl);
  6141. fd=sd->fd;
  6142. WFIFOHEAD(fd,packet_len(0x139));
  6143. WFIFOW(fd, 0)=0x139;
  6144. WFIFOL(fd, 2)=bl->id;
  6145. WFIFOW(fd, 6)=bl->x;
  6146. WFIFOW(fd, 8)=bl->y;
  6147. WFIFOW(fd,10)=sd->bl.x;
  6148. WFIFOW(fd,12)=sd->bl.y;
  6149. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6150. WFIFOSET(fd,packet_len(0x139));
  6151. }
  6152. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6153. /// 018f <result>.W <name id>.W
  6154. /// result:
  6155. /// 0 = success
  6156. /// 1 = failure
  6157. /// 2 = success (alchemist)
  6158. /// 3 = failure (alchemist)
  6159. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6160. {
  6161. int view,fd;
  6162. nullpo_retv(sd);
  6163. fd = sd->fd;
  6164. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6165. WFIFOHEAD(fd,packet_len(0x18f));
  6166. WFIFOW(fd, 0)=0x18f;
  6167. WFIFOW(fd, 2)=flag;
  6168. if((view = itemdb_viewid(nameid)) > 0)
  6169. WFIFOW(fd, 4)=view;
  6170. else
  6171. WFIFOW(fd, 4)=nameid;
  6172. WFIFOSET(fd,packet_len(0x18f));
  6173. }
  6174. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6175. /// 019e
  6176. void clif_catch_process(struct map_session_data *sd)
  6177. {
  6178. int fd;
  6179. nullpo_retv(sd);
  6180. fd=sd->fd;
  6181. WFIFOHEAD(fd,packet_len(0x19e));
  6182. WFIFOW(fd,0)=0x19e;
  6183. WFIFOSET(fd,packet_len(0x19e));
  6184. }
  6185. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6186. /// 01a0 <result>.B
  6187. /// 0 = failure
  6188. /// 1 = success
  6189. void clif_pet_roulette(struct map_session_data *sd,int data)
  6190. {
  6191. int fd;
  6192. nullpo_retv(sd);
  6193. fd=sd->fd;
  6194. WFIFOHEAD(fd,packet_len(0x1a0));
  6195. WFIFOW(fd,0)=0x1a0;
  6196. WFIFOB(fd,2)=data;
  6197. WFIFOSET(fd,packet_len(0x1a0));
  6198. }
  6199. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6200. /// 01a6 <packet len>.W { <index>.W }*
  6201. void clif_sendegg(struct map_session_data *sd)
  6202. {
  6203. int i,n=0,fd;
  6204. nullpo_retv(sd);
  6205. fd=sd->fd;
  6206. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6207. clif_displaymessage(fd, msg_txt(sd,666));
  6208. return;
  6209. }
  6210. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6211. WFIFOW(fd,0)=0x1a6;
  6212. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6213. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6214. sd->inventory_data[i]->type!=IT_PETEGG ||
  6215. sd->status.inventory[i].amount<=0)
  6216. continue;
  6217. WFIFOW(fd,n*2+4)=i+2;
  6218. n++;
  6219. }
  6220. WFIFOW(fd,2)=4+n*2;
  6221. WFIFOSET(fd,WFIFOW(fd,2));
  6222. sd->menuskill_id = SA_TAMINGMONSTER;
  6223. sd->menuskill_val = -1;
  6224. }
  6225. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6226. /// 01a4 <type>.B <id>.L <data>.L
  6227. /// type:
  6228. /// 0 = pre-init (data = 0)
  6229. /// 1 = intimacy (data = 0~4)
  6230. /// 2 = hunger (data = 0~4)
  6231. /// 3 = accessory
  6232. /// 4 = performance (data = 1~3: normal, 4: special)
  6233. /// 5 = hairstyle
  6234. ///
  6235. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6236. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6237. {
  6238. uint8 buf[16];
  6239. nullpo_retv(pd);
  6240. WBUFW(buf,0) = 0x1a4;
  6241. WBUFB(buf,2) = type;
  6242. WBUFL(buf,3) = pd->bl.id;
  6243. WBUFL(buf,7) = param;
  6244. if (sd)
  6245. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6246. else
  6247. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6248. }
  6249. /// Pet's base data (ZC_PROPERTY_PET).
  6250. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6251. void clif_send_petstatus(struct map_session_data *sd)
  6252. {
  6253. int fd;
  6254. struct s_pet *pet;
  6255. nullpo_retv(sd);
  6256. nullpo_retv(sd->pd);
  6257. fd=sd->fd;
  6258. pet = &sd->pd->pet;
  6259. WFIFOHEAD(fd,packet_len(0x1a2));
  6260. WFIFOW(fd,0)=0x1a2;
  6261. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6262. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6263. WFIFOW(fd,27)=pet->level;
  6264. WFIFOW(fd,29)=pet->hungry;
  6265. WFIFOW(fd,31)=pet->intimate;
  6266. WFIFOW(fd,33)=pet->equip;
  6267. #if PACKETVER >= 20081126
  6268. WFIFOW(fd,35)=pet->class_;
  6269. #endif
  6270. WFIFOSET(fd,packet_len(0x1a2));
  6271. }
  6272. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6273. /// 01aa <id>.L <data>.L
  6274. /// data:
  6275. /// @see CZ_PET_ACT.
  6276. void clif_pet_emotion(struct pet_data *pd,int param)
  6277. {
  6278. unsigned char buf[16];
  6279. nullpo_retv(pd);
  6280. memset(buf,0,packet_len(0x1aa));
  6281. WBUFW(buf,0)=0x1aa;
  6282. WBUFL(buf,2)=pd->bl.id;
  6283. if(param >= 100 && pd->petDB->talk_convert_class) {
  6284. if(pd->petDB->talk_convert_class < 0)
  6285. return;
  6286. else if(pd->petDB->talk_convert_class > 0) {
  6287. // replace mob_id component of talk/act data
  6288. param -= (pd->pet.class_ - 100)*100;
  6289. param += (pd->petDB->talk_convert_class - 100)*100;
  6290. }
  6291. }
  6292. WBUFL(buf,6)=param;
  6293. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6294. }
  6295. /// Result of request to feed a pet (ZC_FEED_PET).
  6296. /// 01a3 <result>.B <name id>.W
  6297. /// result:
  6298. /// 0 = failure
  6299. /// 1 = success
  6300. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6301. {
  6302. int fd;
  6303. nullpo_retv(sd);
  6304. fd=sd->fd;
  6305. WFIFOHEAD(fd,packet_len(0x1a3));
  6306. WFIFOW(fd,0)=0x1a3;
  6307. WFIFOB(fd,2)=fail;
  6308. WFIFOW(fd,3)=foodid;
  6309. WFIFOSET(fd,packet_len(0x1a3));
  6310. }
  6311. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6312. /// 01cd { <skill id>.L }*7
  6313. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6314. {
  6315. int fd;
  6316. nullpo_retv(sd);
  6317. fd=sd->fd;
  6318. WFIFOHEAD(fd,packet_len(0x1cd));
  6319. WFIFOW(fd, 0)=0x1cd;
  6320. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6321. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6322. else
  6323. WFIFOL(fd,2)= 0x00000000;
  6324. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6325. WFIFOL(fd,6)= MG_COLDBOLT;
  6326. else
  6327. WFIFOL(fd,6)= 0x00000000;
  6328. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6329. WFIFOL(fd,10)= MG_FIREBOLT;
  6330. else
  6331. WFIFOL(fd,10)= 0x00000000;
  6332. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6333. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6334. else
  6335. WFIFOL(fd,14)= 0x00000000;
  6336. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6337. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6338. else
  6339. WFIFOL(fd,18)= 0x00000000;
  6340. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6341. WFIFOL(fd,22)= MG_FIREBALL;
  6342. else
  6343. WFIFOL(fd,22)= 0x00000000;
  6344. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6345. WFIFOL(fd,26)= MG_FROSTDIVER;
  6346. else
  6347. WFIFOL(fd,26)= 0x00000000;
  6348. WFIFOSET(fd,packet_len(0x1cd));
  6349. sd->menuskill_id = SA_AUTOSPELL;
  6350. sd->menuskill_val = skill_lv;
  6351. }
  6352. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6353. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6354. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6355. {
  6356. unsigned char buf[56];
  6357. nullpo_retv(src);
  6358. memset(buf,0,packet_len(0x1cf));
  6359. WBUFW(buf,0) = 0x1cf;
  6360. WBUFL(buf,2) = src->id;
  6361. if( src->type == BL_MER )
  6362. {
  6363. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6364. if( md && md->master && md->devotion_flag )
  6365. WBUFL(buf,6) = md->master->bl.id;
  6366. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6367. }
  6368. else
  6369. {
  6370. int i;
  6371. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6372. if( sd == NULL )
  6373. return;
  6374. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6375. WBUFL(buf,6+4*i) = sd->devotion[i];
  6376. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6377. }
  6378. if( tsd )
  6379. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6380. else
  6381. clif_send(buf, packet_len(0x1cf), src, AREA);
  6382. }
  6383. /*==========================================
  6384. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6385. * Notifies clients in an area of an object's spirits.
  6386. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6387. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6388. *------------------------------------------*/
  6389. void clif_spiritball(struct block_list *bl) {
  6390. unsigned char buf[16];
  6391. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6392. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6393. nullpo_retv(bl);
  6394. WBUFW(buf, 0) = 0x1d0;
  6395. WBUFL(buf, 2) = bl->id;
  6396. WBUFW(buf, 6) = 0; //init to 0
  6397. switch(bl->type){
  6398. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6399. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6400. }
  6401. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6402. }
  6403. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6404. /// 01d2 <account id>.L <delay>.L
  6405. void clif_combo_delay(struct block_list *bl,int wait)
  6406. {
  6407. unsigned char buf[32];
  6408. nullpo_retv(bl);
  6409. WBUFW(buf,0)=0x1d2;
  6410. WBUFL(buf,2)=bl->id;
  6411. WBUFL(buf,6)=wait;
  6412. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6413. }
  6414. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6415. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6416. /// flag:
  6417. /// 0 = inactive
  6418. /// 1 = active
  6419. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6420. {
  6421. unsigned char buf[32];
  6422. nullpo_retv(src);
  6423. WBUFW(buf,0)=0x1d1;
  6424. WBUFL(buf,2)=src->id;
  6425. WBUFL(buf,6)=dst_id;
  6426. WBUFL(buf,10)=active;
  6427. clif_send(buf,packet_len(0x1d1),src,AREA);
  6428. }
  6429. /// MVP effect (ZC_MVP).
  6430. /// 010c <account id>.L
  6431. void clif_mvp_effect(struct map_session_data *sd)
  6432. {
  6433. unsigned char buf[16];
  6434. nullpo_retv(sd);
  6435. WBUFW(buf,0)=0x10c;
  6436. WBUFL(buf,2)=sd->bl.id;
  6437. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6438. }
  6439. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6440. /// 010a <name id>.W
  6441. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6442. {
  6443. int view,fd;
  6444. nullpo_retv(sd);
  6445. fd=sd->fd;
  6446. WFIFOHEAD(fd,packet_len(0x10a));
  6447. WFIFOW(fd,0)=0x10a;
  6448. if((view = itemdb_viewid(nameid)) > 0)
  6449. WFIFOW(fd,2)=view;
  6450. else
  6451. WFIFOW(fd,2)=nameid;
  6452. WFIFOSET(fd,packet_len(0x10a));
  6453. }
  6454. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6455. /// 010b <exp>.L
  6456. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6457. {
  6458. int fd;
  6459. nullpo_retv(sd);
  6460. fd=sd->fd;
  6461. WFIFOHEAD(fd,packet_len(0x10b));
  6462. WFIFOW(fd,0)=0x10b;
  6463. WFIFOL(fd,2)=min(exp,UINT32_MAX);
  6464. WFIFOSET(fd,packet_len(0x10b));
  6465. }
  6466. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6467. /// 010d
  6468. ///
  6469. /// "You are the MVP, but cannot obtain the reward because
  6470. /// you are overweight."
  6471. void clif_mvp_noitem(struct map_session_data* sd)
  6472. {
  6473. int fd = sd->fd;
  6474. WFIFOHEAD(fd,packet_len(0x10d));
  6475. WFIFOW(fd,0) = 0x10d;
  6476. WFIFOSET(fd,packet_len(0x10d));
  6477. }
  6478. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6479. /// 0167 <result>.B
  6480. /// result:
  6481. /// 0 = "Guild has been created."
  6482. /// 1 = "You are already in a Guild."
  6483. /// 2 = "That Guild Name already exists."
  6484. /// 3 = "You need the neccessary item to create a Guild."
  6485. void clif_guild_created(struct map_session_data *sd,int flag)
  6486. {
  6487. int fd;
  6488. nullpo_retv(sd);
  6489. fd=sd->fd;
  6490. WFIFOHEAD(fd,packet_len(0x167));
  6491. WFIFOW(fd,0)=0x167;
  6492. WFIFOB(fd,2)=flag;
  6493. WFIFOSET(fd,packet_len(0x167));
  6494. }
  6495. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6496. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6497. /// mode:
  6498. /// &0x01 = allow invite
  6499. /// &0x10 = allow expel
  6500. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6501. {
  6502. int ps,fd;
  6503. nullpo_retv(sd);
  6504. nullpo_retv(g);
  6505. fd=sd->fd;
  6506. ps=guild_getposition(g,sd);
  6507. WFIFOHEAD(fd,packet_len(0x16c));
  6508. WFIFOW(fd,0)=0x16c;
  6509. WFIFOL(fd,2)=g->guild_id;
  6510. WFIFOL(fd,6)=g->emblem_id;
  6511. WFIFOL(fd,10)=g->position[ps].mode;
  6512. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6513. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6514. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6515. WFIFOSET(fd,packet_len(0x16c));
  6516. }
  6517. /// Guild member login notice.
  6518. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6519. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6520. /// status:
  6521. /// 0 = offline
  6522. /// 1 = online
  6523. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6524. {
  6525. unsigned char buf[64];
  6526. struct map_session_data* sd;
  6527. nullpo_retv(g);
  6528. WBUFW(buf, 0)=0x1f2;
  6529. WBUFL(buf, 2)=g->member[idx].account_id;
  6530. WBUFL(buf, 6)=g->member[idx].char_id;
  6531. WBUFL(buf,10)=flag;
  6532. if( ( sd = g->member[idx].sd ) != NULL )
  6533. {
  6534. WBUFW(buf,14) = sd->status.sex;
  6535. WBUFW(buf,16) = sd->status.hair;
  6536. WBUFW(buf,18) = sd->status.hair_color;
  6537. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6538. }
  6539. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6540. {
  6541. WBUFW(buf,14) = 0;
  6542. WBUFW(buf,16) = 0;
  6543. WBUFW(buf,18) = 0;
  6544. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6545. }
  6546. }
  6547. // Function `clif_guild_memberlogin_notice` sends info about
  6548. // logins and logouts of a guild member to the rest members.
  6549. // But at the 1st time (after a player login or map changing)
  6550. // the client won't show the message.
  6551. // So I suggest use this function for sending "first-time-info"
  6552. // to some player on entering the game or changing location.
  6553. // At next time the client would always show the message.
  6554. // The function sends all the statuses in the single packet
  6555. // to economize traffic. [LuzZza]
  6556. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6557. {
  6558. struct guild *g;
  6559. unsigned char buf[14*128];
  6560. int i, count=0, p_len;
  6561. nullpo_retv(sd);
  6562. p_len = packet_len(0x16d);
  6563. if(!(g = sd->guild))
  6564. return;
  6565. for(i=0; i<g->max_member; i++) {
  6566. if(g->member[i].account_id > 0 &&
  6567. g->member[i].account_id != sd->status.account_id) {
  6568. WBUFW(buf,count*p_len) = 0x16d;
  6569. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6570. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6571. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6572. count++;
  6573. }
  6574. }
  6575. clif_send(buf, p_len*count, &sd->bl, SELF);
  6576. }
  6577. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6578. /// 014e <menu flag>.L
  6579. /// menu flag:
  6580. /// 0x00 = Basic Info (always on)
  6581. /// &0x01 = Member manager
  6582. /// &0x02 = Positions
  6583. /// &0x04 = Skills
  6584. /// &0x10 = Expulsion list
  6585. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6586. /// &0x80 = Notice
  6587. void clif_guild_masterormember(struct map_session_data *sd)
  6588. {
  6589. int fd;
  6590. nullpo_retv(sd);
  6591. fd=sd->fd;
  6592. WFIFOHEAD(fd,packet_len(0x14e));
  6593. WFIFOW(fd,0) = 0x14e;
  6594. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6595. WFIFOSET(fd,packet_len(0x14e));
  6596. }
  6597. /// Guild basic information (Territories [Valaris])
  6598. /// 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)
  6599. /// 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)
  6600. void clif_guild_basicinfo(struct map_session_data *sd) {
  6601. int fd;
  6602. struct guild *g;
  6603. nullpo_retv(sd);
  6604. fd = sd->fd;
  6605. if( (g = sd->guild) == NULL )
  6606. return;
  6607. WFIFOHEAD(fd,packet_len(0x1b6));
  6608. WFIFOW(fd, 0)=0x1b6;//0x150;
  6609. WFIFOL(fd, 2)=g->guild_id;
  6610. WFIFOL(fd, 6)=g->guild_lv;
  6611. WFIFOL(fd,10)=g->connect_member;
  6612. WFIFOL(fd,14)=g->max_member;
  6613. WFIFOL(fd,18)=g->average_lv;
  6614. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6615. WFIFOL(fd,26)=g->next_exp;
  6616. WFIFOL(fd,30)=0; // Tax Points
  6617. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6618. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6619. WFIFOL(fd,42)=g->emblem_id;
  6620. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6621. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6622. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6623. WFIFOL(fd,110) = 0; // zeny
  6624. WFIFOSET(fd,packet_len(0x1b6));
  6625. }
  6626. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6627. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6628. void clif_guild_allianceinfo(struct map_session_data *sd)
  6629. {
  6630. int fd,i,c;
  6631. struct guild *g;
  6632. nullpo_retv(sd);
  6633. if( (g = sd->guild) == NULL )
  6634. return;
  6635. fd = sd->fd;
  6636. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6637. WFIFOW(fd, 0)=0x14c;
  6638. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6639. struct guild_alliance *a=&g->alliance[i];
  6640. if(a->guild_id>0){
  6641. WFIFOL(fd,c*32+4)=a->opposition;
  6642. WFIFOL(fd,c*32+8)=a->guild_id;
  6643. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6644. c++;
  6645. }
  6646. }
  6647. WFIFOW(fd, 2)=c*32+4;
  6648. WFIFOSET(fd,WFIFOW(fd,2));
  6649. }
  6650. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6651. /// 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 }*
  6652. /// state:
  6653. /// 0 = offline
  6654. /// 1 = online
  6655. /// memo:
  6656. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6657. void clif_guild_memberlist(struct map_session_data *sd)
  6658. {
  6659. int fd;
  6660. int i,c;
  6661. struct guild *g;
  6662. nullpo_retv(sd);
  6663. if( (fd = sd->fd) == 0 )
  6664. return;
  6665. if( (g = sd->guild) == NULL )
  6666. return;
  6667. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6668. WFIFOW(fd, 0)=0x154;
  6669. for(i=0,c=0;i<g->max_member;i++){
  6670. struct guild_member *m=&g->member[i];
  6671. if(m->account_id==0)
  6672. continue;
  6673. WFIFOL(fd,c*104+ 4)=m->account_id;
  6674. WFIFOL(fd,c*104+ 8)=m->char_id;
  6675. WFIFOW(fd,c*104+12)=m->hair;
  6676. WFIFOW(fd,c*104+14)=m->hair_color;
  6677. WFIFOW(fd,c*104+16)=m->gender;
  6678. WFIFOW(fd,c*104+18)=m->class_;
  6679. WFIFOW(fd,c*104+20)=m->lv;
  6680. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6681. WFIFOL(fd,c*104+26)=m->online;
  6682. WFIFOL(fd,c*104+30)=m->position;
  6683. 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.
  6684. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6685. c++;
  6686. }
  6687. WFIFOW(fd, 2)=c*104+4;
  6688. WFIFOSET(fd,WFIFOW(fd,2));
  6689. }
  6690. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6691. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6692. void clif_guild_positionnamelist(struct map_session_data *sd)
  6693. {
  6694. int i,fd;
  6695. struct guild *g;
  6696. nullpo_retv(sd);
  6697. if( (g = sd->guild) == NULL )
  6698. return;
  6699. fd = sd->fd;
  6700. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6701. WFIFOW(fd, 0)=0x166;
  6702. for(i=0;i<MAX_GUILDPOSITION;i++){
  6703. WFIFOL(fd,i*28+4)=i;
  6704. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6705. }
  6706. WFIFOW(fd,2)=i*28+4;
  6707. WFIFOSET(fd,WFIFOW(fd,2));
  6708. }
  6709. /// Guild position information (ZC_POSITION_INFO).
  6710. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6711. /// mode:
  6712. /// &0x01 = allow invite
  6713. /// &0x10 = allow expel
  6714. /// ranking:
  6715. /// TODO
  6716. void clif_guild_positioninfolist(struct map_session_data *sd)
  6717. {
  6718. int i,fd;
  6719. struct guild *g;
  6720. nullpo_retv(sd);
  6721. if( (g = sd->guild) == NULL )
  6722. return;
  6723. fd = sd->fd;
  6724. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6725. WFIFOW(fd, 0)=0x160;
  6726. for(i=0;i<MAX_GUILDPOSITION;i++){
  6727. struct guild_position *p=&g->position[i];
  6728. WFIFOL(fd,i*16+ 4)=i;
  6729. WFIFOL(fd,i*16+ 8)=p->mode;
  6730. WFIFOL(fd,i*16+12)=i;
  6731. WFIFOL(fd,i*16+16)=p->exp_mode;
  6732. }
  6733. WFIFOW(fd, 2)=i*16+4;
  6734. WFIFOSET(fd,WFIFOW(fd,2));
  6735. }
  6736. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6737. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6738. /// mode:
  6739. /// &0x01 = allow invite
  6740. /// &0x10 = allow expel
  6741. /// ranking:
  6742. /// TODO
  6743. void clif_guild_positionchanged(struct guild *g,int idx)
  6744. {
  6745. // FIXME: This packet is intended to update the clients after a
  6746. // commit of position info changes, not sending one packet per
  6747. // position.
  6748. struct map_session_data *sd;
  6749. unsigned char buf[128];
  6750. nullpo_retv(g);
  6751. WBUFW(buf, 0)=0x174;
  6752. WBUFW(buf, 2)=44; // packet len
  6753. // GUILD_REG_POSITION_INFO{
  6754. WBUFL(buf, 4)=idx;
  6755. WBUFL(buf, 8)=g->position[idx].mode;
  6756. WBUFL(buf,12)=idx;
  6757. WBUFL(buf,16)=g->position[idx].exp_mode;
  6758. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6759. // }*
  6760. if( (sd=guild_getavailablesd(g))!=NULL )
  6761. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6762. }
  6763. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6764. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6765. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6766. {
  6767. // FIXME: This packet is intended to update the clients after a
  6768. // commit of member position assignment changes, not sending one
  6769. // packet per position.
  6770. struct map_session_data *sd;
  6771. unsigned char buf[64];
  6772. nullpo_retv(g);
  6773. WBUFW(buf, 0)=0x156;
  6774. WBUFW(buf, 2)=16; // packet len
  6775. // MEMBER_POSITION_INFO{
  6776. WBUFL(buf, 4)=g->member[idx].account_id;
  6777. WBUFL(buf, 8)=g->member[idx].char_id;
  6778. WBUFL(buf,12)=g->member[idx].position;
  6779. // }*
  6780. if( (sd=guild_getavailablesd(g))!=NULL )
  6781. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6782. }
  6783. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6784. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6785. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6786. {
  6787. int fd;
  6788. nullpo_retv(sd);
  6789. nullpo_retv(g);
  6790. fd = sd->fd;
  6791. if( g->emblem_len <= 0 )
  6792. return;
  6793. WFIFOHEAD(fd,g->emblem_len+12);
  6794. WFIFOW(fd,0)=0x152;
  6795. WFIFOW(fd,2)=g->emblem_len+12;
  6796. WFIFOL(fd,4)=g->guild_id;
  6797. WFIFOL(fd,8)=g->emblem_id;
  6798. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6799. WFIFOSET(fd,WFIFOW(fd,2));
  6800. }
  6801. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6802. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6803. void clif_guild_emblem_area(struct block_list* bl)
  6804. {
  6805. uint8 buf[12];
  6806. nullpo_retv(bl);
  6807. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6808. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6809. WBUFW(buf,0) = 0x1b4;
  6810. WBUFL(buf,2) = bl->id;
  6811. WBUFL(buf,6) = status_get_guild_id(bl);
  6812. WBUFW(buf,10) = status_get_emblem_id(bl);
  6813. clif_send(buf, 12, bl, AREA_WOS);
  6814. }
  6815. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6816. /// 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 }*
  6817. void clif_guild_skillinfo(struct map_session_data* sd)
  6818. {
  6819. int fd;
  6820. struct guild* g;
  6821. int i,c;
  6822. nullpo_retv(sd);
  6823. if( (g = sd->guild) == NULL )
  6824. return;
  6825. fd = sd->fd;
  6826. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6827. WFIFOW(fd,0) = 0x0162;
  6828. WFIFOW(fd,4) = g->skill_point;
  6829. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6830. {
  6831. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6832. {
  6833. int id = g->skill[i].id;
  6834. int p = 6 + c*37;
  6835. WFIFOW(fd,p+0) = id;
  6836. WFIFOL(fd,p+2) = skill_get_inf(id);
  6837. WFIFOW(fd,p+6) = g->skill[i].lv;
  6838. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6839. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6840. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6841. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6842. c++;
  6843. }
  6844. }
  6845. WFIFOW(fd,2) = 6 + c*37;
  6846. WFIFOSET(fd,WFIFOW(fd,2));
  6847. }
  6848. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6849. /// 016f <subject>.60B <notice>.120B
  6850. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6851. {
  6852. int fd;
  6853. nullpo_retv(sd);
  6854. nullpo_retv(g);
  6855. fd = sd->fd;
  6856. if ( !session_isActive(fd) )
  6857. return;
  6858. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6859. return;
  6860. WFIFOHEAD(fd,packet_len(0x16f));
  6861. WFIFOW(fd,0) = 0x16f;
  6862. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6863. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6864. WFIFOSET(fd,packet_len(0x16f));
  6865. }
  6866. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6867. /// 016a <guild id>.L <guild name>.24B
  6868. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6869. {
  6870. int fd;
  6871. nullpo_retv(sd);
  6872. nullpo_retv(g);
  6873. fd=sd->fd;
  6874. WFIFOHEAD(fd,packet_len(0x16a));
  6875. WFIFOW(fd,0)=0x16a;
  6876. WFIFOL(fd,2)=g->guild_id;
  6877. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6878. WFIFOSET(fd,packet_len(0x16a));
  6879. }
  6880. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6881. /// 0169 <answer>.B
  6882. /// answer:
  6883. /// 0 = Already in guild.
  6884. /// 1 = Offer rejected.
  6885. /// 2 = Offer accepted.
  6886. /// 3 = Guild full.
  6887. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6888. {
  6889. int fd;
  6890. nullpo_retv(sd);
  6891. fd=sd->fd;
  6892. WFIFOHEAD(fd,packet_len(0x169));
  6893. WFIFOW(fd,0)=0x169;
  6894. WFIFOB(fd,2)=flag;
  6895. WFIFOSET(fd,packet_len(0x169));
  6896. }
  6897. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6898. /// 015a <char name>.24B <reason>.40B
  6899. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6900. {
  6901. unsigned char buf[128];
  6902. nullpo_retv(sd);
  6903. WBUFW(buf, 0)=0x15a;
  6904. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6905. memcpy(WBUFP(buf,26),mes,40);
  6906. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6907. }
  6908. /// Notifies clients of a guild of an expelled member.
  6909. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6910. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6911. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6912. {
  6913. unsigned char buf[128];
  6914. #if PACKETVER < 20100803
  6915. const unsigned short cmd = 0x15c;
  6916. #else
  6917. const unsigned short cmd = 0x839;
  6918. #endif
  6919. nullpo_retv(sd);
  6920. WBUFW(buf,0) = cmd;
  6921. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6922. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6923. #if PACKETVER < 20100803
  6924. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6925. #endif
  6926. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6927. }
  6928. /// Guild expulsion list (ZC_BAN_LIST).
  6929. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6930. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6931. void clif_guild_expulsionlist(struct map_session_data* sd)
  6932. {
  6933. #if PACKETVER < 20100803
  6934. const int offset = NAME_LENGTH*2+40;
  6935. #else
  6936. const int offset = NAME_LENGTH+40;
  6937. #endif
  6938. int fd, i, c = 0;
  6939. struct guild* g;
  6940. nullpo_retv(sd);
  6941. if( (g = sd->guild) == NULL )
  6942. return;
  6943. fd = sd->fd;
  6944. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6945. WFIFOW(fd,0) = 0x163;
  6946. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6947. {
  6948. struct guild_expulsion* e = &g->expulsion[i];
  6949. if( e->account_id > 0 )
  6950. {
  6951. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6952. #if PACKETVER < 20100803
  6953. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6954. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6955. #else
  6956. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6957. #endif
  6958. c++;
  6959. }
  6960. }
  6961. WFIFOW(fd,2) = 4 + c*offset;
  6962. WFIFOSET(fd,WFIFOW(fd,2));
  6963. }
  6964. /// Guild chat message (ZC_GUILD_CHAT).
  6965. /// 017f <packet len>.W <message>.?B
  6966. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6967. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6968. struct map_session_data *sd;
  6969. uint8 buf[256];
  6970. if( len == 0 )
  6971. {
  6972. return;
  6973. }
  6974. else if( len > sizeof(buf)-5 )
  6975. {
  6976. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6977. len = sizeof(buf)-5;
  6978. }
  6979. WBUFW(buf, 0) = 0x17f;
  6980. WBUFW(buf, 2) = len + 5;
  6981. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6982. if ((sd = guild_getavailablesd(g)) != NULL)
  6983. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6984. }
  6985. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6986. /// 0171 <inviter account id>.L <guild name>.24B
  6987. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6988. {
  6989. int fd;
  6990. nullpo_retv(sd);
  6991. fd=sd->fd;
  6992. WFIFOHEAD(fd,packet_len(0x171));
  6993. WFIFOW(fd,0)=0x171;
  6994. WFIFOL(fd,2)=account_id;
  6995. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6996. WFIFOSET(fd,packet_len(0x171));
  6997. }
  6998. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6999. /// 0173 <answer>.B
  7000. /// answer:
  7001. /// 0 = Already allied.
  7002. /// 1 = You rejected the offer.
  7003. /// 2 = You accepted the offer.
  7004. /// 3 = They have too any alliances.
  7005. /// 4 = You have too many alliances.
  7006. /// 5 = Alliances are disabled.
  7007. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7008. {
  7009. int fd;
  7010. nullpo_retv(sd);
  7011. fd=sd->fd;
  7012. WFIFOHEAD(fd,packet_len(0x173));
  7013. WFIFOW(fd,0)=0x173;
  7014. WFIFOL(fd,2)=flag;
  7015. WFIFOSET(fd,packet_len(0x173));
  7016. }
  7017. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7018. /// 0184 <other guild id>.L <relation>.L
  7019. /// relation:
  7020. /// 0 = Ally
  7021. /// 1 = Enemy
  7022. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7023. {
  7024. int fd;
  7025. nullpo_retv(sd);
  7026. fd = sd->fd;
  7027. if (fd <= 0)
  7028. return;
  7029. WFIFOHEAD(fd,packet_len(0x184));
  7030. WFIFOW(fd,0)=0x184;
  7031. WFIFOL(fd,2)=guild_id;
  7032. WFIFOL(fd,6)=flag;
  7033. WFIFOSET(fd,packet_len(0x184));
  7034. }
  7035. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7036. /// 0181 <result>.B
  7037. /// result:
  7038. /// 0 = Antagonist has been set.
  7039. /// 1 = Guild has too many Antagonists.
  7040. /// 2 = Already set as an Antagonist.
  7041. /// 3 = Antagonists are disabled.
  7042. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7043. {
  7044. int fd;
  7045. nullpo_retv(sd);
  7046. fd=sd->fd;
  7047. WFIFOHEAD(fd,packet_len(0x181));
  7048. WFIFOW(fd,0)=0x181;
  7049. WFIFOB(fd,2)=flag;
  7050. WFIFOSET(fd,packet_len(0x181));
  7051. }
  7052. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7053. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7054. /*
  7055. void clif_guild_allianceadded(struct guild *g,int idx)
  7056. {
  7057. unsigned char buf[64];
  7058. WBUFW(buf,0)=0x185;
  7059. WBUFL(buf,2)=g->alliance[idx].opposition;
  7060. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7061. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7062. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7063. }
  7064. */
  7065. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7066. /// 015e <reason>.L
  7067. /// 0 = success
  7068. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7069. /// 2 = there are still members in the guild
  7070. void clif_guild_broken(struct map_session_data *sd,int flag)
  7071. {
  7072. int fd;
  7073. nullpo_retv(sd);
  7074. fd=sd->fd;
  7075. WFIFOHEAD(fd,packet_len(0x15e));
  7076. WFIFOW(fd,0)=0x15e;
  7077. WFIFOL(fd,2)=flag;
  7078. WFIFOSET(fd,packet_len(0x15e));
  7079. }
  7080. /// Displays emotion on an object (ZC_EMOTION).
  7081. /// 00c0 <id>.L <type>.B
  7082. /// type:
  7083. /// enum emotion_type
  7084. void clif_emotion(struct block_list *bl,int type)
  7085. {
  7086. unsigned char buf[8];
  7087. nullpo_retv(bl);
  7088. WBUFW(buf,0)=0xc0;
  7089. WBUFL(buf,2)=bl->id;
  7090. WBUFB(buf,6)=type;
  7091. clif_send(buf,packet_len(0xc0),bl,AREA);
  7092. }
  7093. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7094. /// 0191 <id>.L <contents>.80B
  7095. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7096. {
  7097. unsigned char buf[MESSAGE_SIZE+6];
  7098. nullpo_retv(bl);
  7099. WBUFW(buf,0) = 0x191;
  7100. WBUFL(buf,2) = bl->id;
  7101. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7102. clif_send(buf,packet_len(0x191),bl,AREA);
  7103. }
  7104. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7105. /// 01ea <id>.L
  7106. void clif_wedding_effect(struct block_list *bl)
  7107. {
  7108. unsigned char buf[6];
  7109. nullpo_retv(bl);
  7110. WBUFW(buf,0) = 0x1ea;
  7111. WBUFL(buf,2) = bl->id;
  7112. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7113. }
  7114. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7115. /// 01e6 <partner name>.24B
  7116. void clif_callpartner(struct map_session_data *sd)
  7117. {
  7118. unsigned char buf[26];
  7119. nullpo_retv(sd);
  7120. WBUFW(buf,0) = 0x1e6;
  7121. if( sd->status.partner_id ) {
  7122. const char *p = map_charid2nick(sd->status.partner_id);
  7123. struct map_session_data *p_sd = pc_get_partner(sd);
  7124. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7125. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7126. else
  7127. WBUFB(buf,2) = 0;
  7128. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7129. WBUFB(buf,2) = 0;
  7130. }
  7131. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7132. }
  7133. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7134. /// 01e4
  7135. /// This packet while still implemented by the client is no longer being officially used.
  7136. /*
  7137. void clif_marriage_process(struct map_session_data *sd)
  7138. {
  7139. int fd;
  7140. nullpo_retv(sd);
  7141. fd=sd->fd;
  7142. WFIFOHEAD(fd,packet_len(0x1e4));
  7143. WFIFOW(fd,0)=0x1e4;
  7144. WFIFOSET(fd,packet_len(0x1e4));
  7145. }
  7146. */
  7147. /// Notice of divorce (ZC_DIVORCE).
  7148. /// 0205 <partner name>.24B
  7149. void clif_divorced(struct map_session_data* sd, const char* name)
  7150. {
  7151. int fd;
  7152. nullpo_retv(sd);
  7153. fd=sd->fd;
  7154. WFIFOHEAD(fd,packet_len(0x205));
  7155. WFIFOW(fd,0)=0x205;
  7156. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7157. WFIFOSET(fd, packet_len(0x205));
  7158. }
  7159. /// Marriage proposal (ZC_REQ_COUPLE).
  7160. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7161. /// This packet while still implemented by the client is no longer being officially used.
  7162. /*
  7163. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7164. {
  7165. nullpo_retv(sd);
  7166. WFIFOHEAD(fd,packet_len(0x1e2));
  7167. WFIFOW(fd,0) = 0x1e2;
  7168. WFIFOL(fd,2) = ssd->status.account_id;
  7169. WFIFOL(fd,6) = ssd->status.char_id;
  7170. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7171. WFIFOSET(fd, packet_len(0x1e2));
  7172. }
  7173. */
  7174. /*==========================================
  7175. *
  7176. *------------------------------------------*/
  7177. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7178. {
  7179. clif_disp_message(&sd->bl, mes, len, SELF);
  7180. }
  7181. /*==========================================
  7182. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7183. *------------------------------------------*/
  7184. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7185. {
  7186. unsigned char buf[256];
  7187. if( len == 0 ) {
  7188. return;
  7189. } else if( len > sizeof(buf)-5 ) {
  7190. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7191. len = sizeof(buf)-5;
  7192. }
  7193. WBUFW(buf, 0) = 0x17f;
  7194. WBUFW(buf, 2) = len + 5;
  7195. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7196. clif_send(buf, WBUFW(buf,2), src, target);
  7197. }
  7198. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7199. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7200. /// 00cd <result>.B
  7201. /// result:
  7202. /// 0 = failure
  7203. /// 1 = success
  7204. void clif_GM_kickack(struct map_session_data *sd, int id)
  7205. {
  7206. int fd;
  7207. nullpo_retv(sd);
  7208. fd = sd->fd;
  7209. WFIFOHEAD(fd,packet_len(0xcd));
  7210. WFIFOW(fd,0) = 0xcd;
  7211. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7212. WFIFOSET(fd, packet_len(0xcd));
  7213. }
  7214. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7215. {
  7216. int fd = tsd->fd;
  7217. if( fd > 0 )
  7218. clif_authfail_fd(fd, 15);
  7219. else {
  7220. // Close vending/buyingstore
  7221. if (sd) {
  7222. if (tsd->state.vending)
  7223. vending_closevending(tsd);
  7224. else if (tsd->state.buyingstore)
  7225. buyingstore_close(tsd);
  7226. }
  7227. map_quit(tsd);
  7228. }
  7229. if( sd )
  7230. clif_GM_kickack(sd,tsd->status.account_id);
  7231. }
  7232. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7233. /// 014a <result>.L
  7234. /// result:
  7235. /// 0 = "A manner point has been successfully aligned."
  7236. /// 1 = MP_FAILURE_EXHAUST
  7237. /// 2 = MP_FAILURE_ALREADY_GIVING
  7238. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7239. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7240. /// 5 = "You got a good point from %s."
  7241. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7242. {
  7243. int fd;
  7244. nullpo_retv(sd);
  7245. fd = sd->fd;
  7246. WFIFOHEAD(fd,packet_len(0x14a));
  7247. WFIFOW(fd,0) = 0x14a;
  7248. WFIFOL(fd,2) = type;
  7249. WFIFOSET(fd, packet_len(0x14a));
  7250. }
  7251. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7252. /// 014b <type>.B <GM name>.24B
  7253. /// type:
  7254. /// 0 = positive (unmute)
  7255. /// 1 = negative (mute)
  7256. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7257. {
  7258. int fd;
  7259. nullpo_retv(sd);
  7260. nullpo_retv(tsd);
  7261. fd = tsd->fd;
  7262. WFIFOHEAD(fd,packet_len(0x14b));
  7263. WFIFOW(fd,0) = 0x14b;
  7264. WFIFOB(fd,2) = type;
  7265. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7266. WFIFOSET(fd, packet_len(0x14b));
  7267. }
  7268. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7269. /// 00d1 <type>.B <result>.B
  7270. /// type:
  7271. /// 0 = /ex (deny)
  7272. /// 1 = /in (allow)
  7273. /// result:
  7274. /// 0 = success
  7275. /// 1 = failure
  7276. /// 2 = too many blocks
  7277. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7278. {
  7279. int fd;
  7280. nullpo_retv(sd);
  7281. fd=sd->fd;
  7282. WFIFOHEAD(fd,packet_len(0xd1));
  7283. WFIFOW(fd,0)=0xd1;
  7284. WFIFOB(fd,2)=type;
  7285. WFIFOB(fd,3)=flag;
  7286. WFIFOSET(fd,packet_len(0xd1));
  7287. }
  7288. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7289. /// 00d2 <type>.B <result>.B
  7290. /// type:
  7291. /// 0 = /exall (deny)
  7292. /// 1 = /inall (allow)
  7293. /// result:
  7294. /// 0 = success
  7295. /// 1 = failure
  7296. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7297. {
  7298. int fd;
  7299. nullpo_retv(sd);
  7300. fd=sd->fd;
  7301. WFIFOHEAD(fd,packet_len(0xd2));
  7302. WFIFOW(fd,0)=0xd2;
  7303. WFIFOB(fd,2)=type;
  7304. WFIFOB(fd,3)=flag;
  7305. WFIFOSET(fd,packet_len(0xd2));
  7306. }
  7307. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7308. /// 07fe <bgm>.24B
  7309. void clif_playBGM(struct map_session_data* sd, const char* name)
  7310. {
  7311. int fd;
  7312. nullpo_retv(sd);
  7313. fd = sd->fd;
  7314. WFIFOHEAD(fd,packet_len(0x7fe));
  7315. WFIFOW(fd,0) = 0x7fe;
  7316. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7317. WFIFOSET(fd,packet_len(0x7fe));
  7318. }
  7319. /// Plays/stops a wave sound (ZC_SOUND).
  7320. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7321. /// file name:
  7322. /// relative to data\wav
  7323. /// act:
  7324. /// 0 = play (once)
  7325. /// 1 = play (repeat, does not work)
  7326. /// 2 = stops all sound instances of file name (does not work)
  7327. /// term:
  7328. /// unknown purpose, only relevant to act = 1
  7329. /// npc id:
  7330. /// The accustic direction of the sound is determined by the
  7331. /// relative position of the NPC to the player (3D sound).
  7332. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7333. {
  7334. int fd;
  7335. nullpo_retv(sd);
  7336. nullpo_retv(bl);
  7337. fd = sd->fd;
  7338. WFIFOHEAD(fd,packet_len(0x1d3));
  7339. WFIFOW(fd,0) = 0x1d3;
  7340. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7341. WFIFOB(fd,26) = type;
  7342. WFIFOL(fd,27) = 0;
  7343. WFIFOL(fd,31) = bl->id;
  7344. WFIFOSET(fd,packet_len(0x1d3));
  7345. }
  7346. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7347. {
  7348. unsigned char buf[40];
  7349. nullpo_retv(bl);
  7350. WBUFW(buf,0) = 0x1d3;
  7351. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7352. WBUFB(buf,26) = type;
  7353. WBUFL(buf,27) = 0;
  7354. WBUFL(buf,31) = bl->id;
  7355. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7356. }
  7357. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7358. /// 01f3 <id>.L <effect id>.L
  7359. /// effect id:
  7360. /// @see doc/effect_list.txt
  7361. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7362. {
  7363. unsigned char buf[24];
  7364. nullpo_retv(bl);
  7365. memset(buf, 0, packet_len(0x1f3));
  7366. WBUFW(buf,0) = 0x1f3;
  7367. WBUFL(buf,2) = bl->id;
  7368. WBUFL(buf,6) = type;
  7369. clif_send(buf, packet_len(0x1f3), bl, target);
  7370. if (disguised(bl)) {
  7371. WBUFL(buf,2) = -bl->id;
  7372. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7373. }
  7374. }
  7375. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7376. {
  7377. WFIFOHEAD(fd,10);
  7378. WFIFOW(fd,0) = 0x1f3;
  7379. WFIFOL(fd,2) = bl->id;
  7380. WFIFOL(fd,6) = type;
  7381. WFIFOSET(fd,10);
  7382. }
  7383. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7384. /// 0284 <id>.L <effect id>.L <num data>.L
  7385. /// effect id:
  7386. /// @see doc/effect_list.txt
  7387. /// num data:
  7388. /// effect-dependent value
  7389. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7390. {
  7391. uint8 buf[14];
  7392. WBUFW(buf,0) = 0x284;
  7393. WBUFL(buf,2) = bl->id;
  7394. WBUFL(buf,6) = effect_id;
  7395. WBUFL(buf,10) = num;
  7396. clif_send(buf, packet_len(0x284), bl, target);
  7397. if( disguised(bl) )
  7398. {
  7399. WBUFL(buf,2) = -bl->id;
  7400. clif_send(buf, packet_len(0x284), bl, SELF);
  7401. }
  7402. }
  7403. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7404. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7405. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7406. unsigned short msg_len = strlen(msg) + 1;
  7407. WFIFOHEAD(sd->fd,msg_len + 12);
  7408. WFIFOW(sd->fd,0) = 0x2C1;
  7409. WFIFOW(sd->fd,2) = msg_len + 12;
  7410. WFIFOL(sd->fd,4) = 0;
  7411. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7412. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7413. WFIFOSET(sd->fd, msg_len + 12);
  7414. return 0;
  7415. }
  7416. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7417. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7418. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7419. unsigned short msg_len = strlen(msg) + 1;
  7420. uint8 buf[256];
  7421. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7422. nullpo_retv(bl);
  7423. if( msg_len > sizeof(buf)-12 ) {
  7424. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7425. msg_len = sizeof(buf)-12;
  7426. }
  7427. WBUFW(buf,0) = 0x2C1;
  7428. WBUFW(buf,2) = msg_len + 12;
  7429. WBUFL(buf,4) = bl->id;
  7430. WBUFL(buf,8) = color;
  7431. memcpy(WBUFP(buf,12), msg, msg_len);
  7432. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7433. }
  7434. /**
  7435. * Notifies the client that the storage window is still open
  7436. *
  7437. * Should only be used in cases where the client closed the
  7438. * storage window without server's consent
  7439. */
  7440. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7441. // Notify the client that the storage is open
  7442. if( sd->state.storage_flag == 1 ) {
  7443. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7444. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7445. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7446. }
  7447. // Notify the client that the gstorage is open otherwise it will
  7448. // remain locked forever and nobody will be able to access it
  7449. if( sd->state.storage_flag == 2 ) {
  7450. struct guild_storage *gstor = guild2storage2(sd->status.guild_id);
  7451. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7452. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7453. else {
  7454. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7455. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7456. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7457. }
  7458. }
  7459. }
  7460. // refresh the client's screen, getting rid of any effects
  7461. void clif_refresh(struct map_session_data *sd)
  7462. {
  7463. int i;
  7464. nullpo_retv(sd);
  7465. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7466. clif_inventorylist(sd);
  7467. if(pc_iscarton(sd)) {
  7468. clif_cartlist(sd);
  7469. clif_updatestatus(sd,SP_CARTINFO);
  7470. }
  7471. clif_updatestatus(sd,SP_WEIGHT);
  7472. clif_updatestatus(sd,SP_MAXWEIGHT);
  7473. clif_updatestatus(sd,SP_STR);
  7474. clif_updatestatus(sd,SP_AGI);
  7475. clif_updatestatus(sd,SP_VIT);
  7476. clif_updatestatus(sd,SP_INT);
  7477. clif_updatestatus(sd,SP_DEX);
  7478. clif_updatestatus(sd,SP_LUK);
  7479. if (sd->spiritball)
  7480. clif_spiritball_single(sd->fd, sd);
  7481. for(i = 1; i < 5; i++){
  7482. if( sd->talisman[i] > 0 )
  7483. clif_talisman_single(sd->fd, sd, i);
  7484. }
  7485. if (sd->vd.cloth_color)
  7486. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7487. if(hom_is_active(sd->hd))
  7488. clif_send_homdata(sd,SP_ACK,0);
  7489. if( sd->md ) {
  7490. clif_mercenary_info(sd);
  7491. clif_mercenary_skillblock(sd);
  7492. }
  7493. if( sd->ed )
  7494. clif_elemental_info(sd);
  7495. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7496. clif_weather_check(sd);
  7497. if( sd->chatID )
  7498. chat_leavechat(sd,0);
  7499. if( sd->state.vending )
  7500. clif_openvending(sd, sd->bl.id, sd->vending);
  7501. if( pc_issit(sd) )
  7502. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7503. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7504. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7505. else
  7506. clif_changed_dir(&sd->bl, SELF);
  7507. // unlike vending, resuming buyingstore crashes the client.
  7508. buyingstore_close(sd);
  7509. mail_clear(sd);
  7510. if( disguised(&sd->bl) ) {/* refresh-da */
  7511. short disguise = sd->disguise;
  7512. pc_disguise(sd, 0);
  7513. pc_disguise(sd, disguise);
  7514. }
  7515. clif_refresh_storagewindow(sd);
  7516. }
  7517. /// Updates the object's (bl) name on client.
  7518. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7519. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7520. void clif_charnameack (int fd, struct block_list *bl)
  7521. {
  7522. unsigned char buf[103];
  7523. int cmd = 0x95;
  7524. nullpo_retv(bl);
  7525. WBUFW(buf,0) = cmd;
  7526. WBUFL(buf,2) = bl->id;
  7527. switch( bl->type )
  7528. {
  7529. case BL_PC:
  7530. {
  7531. struct map_session_data *ssd = (struct map_session_data *)bl;
  7532. struct party_data *p = NULL;
  7533. struct guild *g = NULL;
  7534. int ps = -1;
  7535. //Requesting your own "shadow" name. [Skotlex]
  7536. if (ssd->fd == fd && ssd->disguise)
  7537. WBUFL(buf,2) = -bl->id;
  7538. if( ssd->fakename[0] ) {
  7539. WBUFW(buf, 0) = cmd = 0x195;
  7540. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7541. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7542. break;
  7543. }
  7544. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7545. if( ssd->status.party_id ) {
  7546. p = party_search(ssd->status.party_id);
  7547. }
  7548. if( ssd->status.guild_id ) {
  7549. if( ( g = ssd->guild ) != NULL ) {
  7550. int i;
  7551. 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);
  7552. if( i < g->max_member ) ps = g->member[i].position;
  7553. }
  7554. }
  7555. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7556. p = NULL;
  7557. }
  7558. if (p == NULL && g == NULL)
  7559. break;
  7560. WBUFW(buf, 0) = cmd = 0x195;
  7561. if (p)
  7562. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7563. else
  7564. WBUFB(buf,30) = 0;
  7565. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7566. {
  7567. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7568. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7569. } else { //Assume no guild.
  7570. WBUFB(buf,54) = 0;
  7571. WBUFB(buf,78) = 0;
  7572. }
  7573. }
  7574. break;
  7575. //[blackhole89]
  7576. case BL_HOM:
  7577. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7578. break;
  7579. case BL_MER:
  7580. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7581. break;
  7582. case BL_PET:
  7583. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7584. break;
  7585. case BL_NPC:
  7586. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7587. break;
  7588. case BL_MOB:
  7589. {
  7590. struct mob_data *md = (struct mob_data *)bl;
  7591. nullpo_retv(md);
  7592. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7593. if( md->guardian_data && md->guardian_data->guild_id )
  7594. {
  7595. WBUFW(buf, 0) = cmd = 0x195;
  7596. WBUFB(buf,30) = 0;
  7597. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7598. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7599. }
  7600. else if( battle_config.show_mob_info )
  7601. {
  7602. char mobhp[50], *str_p = mobhp;
  7603. WBUFW(buf, 0) = cmd = 0x195;
  7604. if( battle_config.show_mob_info&4 )
  7605. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7606. if( battle_config.show_mob_info&1 )
  7607. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7608. if( battle_config.show_mob_info&2 )
  7609. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7610. //Even thought mobhp ain't a name, we send it as one so the client
  7611. //can parse it. [Skotlex]
  7612. if( str_p != mobhp )
  7613. {
  7614. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7615. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7616. WBUFB(buf,54) = 0;
  7617. WBUFB(buf,78) = 0;
  7618. }
  7619. }
  7620. }
  7621. break;
  7622. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7623. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7624. // break;
  7625. return;
  7626. case BL_ELEM:
  7627. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7628. break;
  7629. default:
  7630. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7631. return;
  7632. }
  7633. // if no receipient specified just update nearby clients
  7634. if (fd == 0)
  7635. clif_send(buf, packet_len(cmd), bl, AREA);
  7636. else {
  7637. WFIFOHEAD(fd, packet_len(cmd));
  7638. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7639. WFIFOSET(fd, packet_len(cmd));
  7640. }
  7641. }
  7642. //Used to update when a char leaves a party/guild. [Skotlex]
  7643. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7644. void clif_charnameupdate (struct map_session_data *ssd)
  7645. {
  7646. unsigned char buf[103];
  7647. int cmd = 0x195, ps = -1;
  7648. struct party_data *p = NULL;
  7649. struct guild *g = NULL;
  7650. nullpo_retv(ssd);
  7651. if( ssd->fakename[0] )
  7652. return; //No need to update as the party/guild was not displayed anyway.
  7653. WBUFW(buf,0) = cmd;
  7654. WBUFL(buf,2) = ssd->bl.id;
  7655. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7656. if (!battle_config.display_party_name) {
  7657. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7658. p = party_search(ssd->status.party_id);
  7659. }else{
  7660. if (ssd->status.party_id > 0)
  7661. p = party_search(ssd->status.party_id);
  7662. }
  7663. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7664. {
  7665. int i;
  7666. 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);
  7667. if( i < g->max_member ) ps = g->member[i].position;
  7668. }
  7669. if( p )
  7670. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7671. else
  7672. WBUFB(buf,30) = 0;
  7673. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7674. {
  7675. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7676. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7677. }
  7678. else
  7679. {
  7680. WBUFB(buf,54) = 0;
  7681. WBUFB(buf,78) = 0;
  7682. }
  7683. // Update nearby clients
  7684. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7685. }
  7686. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7687. /// 01ff <id>.L <x>.W <y>.W
  7688. ///
  7689. /// Visually moves(instant) a character to x,y. The char moves even
  7690. /// when the target cell isn't walkable. If the char is sitting it
  7691. /// stays that way.
  7692. void clif_slide(struct block_list *bl, int x, int y)
  7693. {
  7694. unsigned char buf[10];
  7695. nullpo_retv(bl);
  7696. WBUFW(buf, 0) = 0x01ff;
  7697. WBUFL(buf, 2) = bl->id;
  7698. WBUFW(buf, 6) = x;
  7699. WBUFW(buf, 8) = y;
  7700. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7701. if( disguised(bl) )
  7702. {
  7703. WBUFL(buf,2) = -bl->id;
  7704. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7705. }
  7706. }
  7707. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7708. /// 008d <packet len>.W <id>.L <message>.?B
  7709. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7710. {
  7711. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7712. int len_mes = strlen(mes)+1; //Account for \0
  7713. if (len_mes > sizeof(buf)-8) {
  7714. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7715. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7716. }
  7717. // send message to others
  7718. WBUFW(buf,0) = 0x8d;
  7719. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7720. WBUFL(buf,4) = bl->id;
  7721. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7722. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7723. // send back message to the speaker
  7724. if( bl->type == BL_PC ) {
  7725. WBUFW(buf,0) = 0x8e;
  7726. WBUFW(buf, 2) = len_mes + 4;
  7727. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7728. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7729. }
  7730. }
  7731. /*==========================
  7732. * Minimap fix [Kevin]
  7733. * Remove dot from minimap
  7734. *--------------------------*/
  7735. void clif_party_xy_remove(struct map_session_data *sd)
  7736. {
  7737. unsigned char buf[16];
  7738. nullpo_retv(sd);
  7739. WBUFW(buf,0)=0x107;
  7740. WBUFL(buf,2)=sd->status.account_id;
  7741. WBUFW(buf,6)=-1;
  7742. WBUFW(buf,8)=-1;
  7743. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7744. }
  7745. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7746. /// 0215 <msg id>.L
  7747. /// msg id:
  7748. /// 0x15 = End all negative status (PA_GOSPEL)
  7749. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7750. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7751. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7752. /// 0x19 = All stats +20 (PA_GOSPEL)
  7753. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7754. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7755. /// 0x1e = DEF +25% (PA_GOSPEL)
  7756. /// 0x1f = ATK +100% (PA_GOSPEL)
  7757. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7758. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7759. /// ? = nothing
  7760. void clif_gospel_info(struct map_session_data *sd, int type)
  7761. {
  7762. int fd=sd->fd;
  7763. WFIFOHEAD(fd,packet_len(0x215));
  7764. WFIFOW(fd,0)=0x215;
  7765. WFIFOL(fd,2)=type;
  7766. WFIFOSET(fd, packet_len(0x215));
  7767. }
  7768. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7769. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7770. /// result:
  7771. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7772. /// star:
  7773. /// 0 = Place of the Sun
  7774. /// 1 = Place of the Moon
  7775. /// 2 = Place of the Stars
  7776. /// 1 = Star Gladiator %s's %s: <mapname>
  7777. /// star:
  7778. /// 0 = Place of the Sun
  7779. /// 1 = Place of the Moon
  7780. /// 2 = Place of the Stars
  7781. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7782. /// star:
  7783. /// 0 = Target of the Sun
  7784. /// 1 = Target of the Moon
  7785. /// 2 = Target of the Stars
  7786. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7787. /// star:
  7788. /// 0 = Monster of the Sun
  7789. /// 1 = Monster of the Moon
  7790. /// 2 = Monster of the Stars
  7791. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7792. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7793. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7794. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7795. /// 40 = Target HP : <monster_id used as HP>
  7796. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7797. {
  7798. int fd = sd->fd;
  7799. WFIFOHEAD(fd,packet_len(0x20e));
  7800. WFIFOW(fd,0) = 0x20e;
  7801. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7802. WFIFOL(fd,26) = monster_id;
  7803. WFIFOB(fd,30) = star;
  7804. WFIFOB(fd,31) = result;
  7805. WFIFOSET(fd,packet_len(0x20e));
  7806. }
  7807. /*==========================================
  7808. * Info about Star Glaldiator save map [Komurka]
  7809. * type: 1: Information, 0: Map registered
  7810. *------------------------------------------*/
  7811. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7812. {
  7813. char mapname[MAP_NAME_LENGTH_EXT];
  7814. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7815. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7816. }
  7817. /*==========================================
  7818. * Info about Star Glaldiator hate mob [Komurka]
  7819. * type: 1: Register mob, 0: Information.
  7820. *------------------------------------------*/
  7821. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7822. {
  7823. if( pcdb_checkid(class_) ) {
  7824. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7825. } else if( mobdb_checkid(class_) ) {
  7826. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7827. } else {
  7828. 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);
  7829. }
  7830. }
  7831. /*==========================================
  7832. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7833. *------------------------------------------*/
  7834. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7835. {
  7836. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7837. }
  7838. /*==========================================
  7839. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7840. *------------------------------------------*/
  7841. void clif_feel_hate_reset(struct map_session_data *sd)
  7842. {
  7843. clif_starskill(sd, "", 0, 0, 30);
  7844. }
  7845. /// Equip window (un)tick ack (ZC_CONFIG).
  7846. /// 02d9 <type>.L <value>.L
  7847. /// type:
  7848. /// 0 = open equip window
  7849. /// value:
  7850. /// 0 = disabled
  7851. /// 1 = enabled
  7852. void clif_equiptickack(struct map_session_data* sd, int flag)
  7853. {
  7854. int fd;
  7855. nullpo_retv(sd);
  7856. fd = sd->fd;
  7857. WFIFOHEAD(fd, packet_len(0x2d9));
  7858. WFIFOW(fd, 0) = 0x2d9;
  7859. WFIFOL(fd, 2) = 0;
  7860. WFIFOL(fd, 6) = flag;
  7861. WFIFOSET(fd, packet_len(0x2d9));
  7862. }
  7863. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7864. /// 02da <open equip window>.B
  7865. /// open equip window:
  7866. /// 0 = disabled
  7867. /// 1 = enabled
  7868. void clif_equipcheckbox(struct map_session_data* sd)
  7869. {
  7870. int fd;
  7871. nullpo_retv(sd);
  7872. fd = sd->fd;
  7873. WFIFOHEAD(fd, packet_len(0x2da));
  7874. WFIFOW(fd, 0) = 0x2da;
  7875. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7876. WFIFOSET(fd, packet_len(0x2da));
  7877. }
  7878. /// Sends info about a player's equipped items.
  7879. /// 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)
  7880. /// 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)
  7881. /// 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)
  7882. /// 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)
  7883. /// 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)
  7884. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7885. {
  7886. uint8* buf;
  7887. int i, n, fd, offset = 0;
  7888. #if PACKETVER < 20100629
  7889. const int s = 26;
  7890. #elif PACKETVER < 20120925
  7891. const int s = 28;
  7892. #else
  7893. const int s = 31;
  7894. #endif
  7895. nullpo_retv(sd);
  7896. nullpo_retv(tsd);
  7897. fd = sd->fd;
  7898. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7899. buf = WFIFOP(fd,0);
  7900. #if PACKETVER < 20101124
  7901. WBUFW(buf, 0) = 0x2d7;
  7902. #elif PACKETVER < 20120925
  7903. WBUFW(buf, 0) = 0x859;
  7904. #else
  7905. WBUFW(buf, 0) = 0x997;
  7906. #endif
  7907. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7908. WBUFW(buf,28) = tsd->status.class_;
  7909. WBUFW(buf,30) = tsd->vd.hair_style;
  7910. WBUFW(buf,32) = tsd->vd.head_bottom;
  7911. WBUFW(buf,34) = tsd->vd.head_mid;
  7912. WBUFW(buf,36) = tsd->vd.head_top;
  7913. #if PACKETVER >= 20110111
  7914. WBUFW(buf,38) = tsd->vd.robe;
  7915. offset+= 2;
  7916. buf = WBUFP(buf,2);
  7917. #endif
  7918. WBUFW(buf,38) = tsd->vd.hair_color;
  7919. WBUFW(buf,40) = tsd->vd.cloth_color;
  7920. WBUFB(buf,42) = tsd->vd.sex;
  7921. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7922. {
  7923. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7924. continue;
  7925. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7926. continue;
  7927. // Add item info : refine, identify flag, element, etc.
  7928. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7929. n++;
  7930. }
  7931. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7932. WFIFOSET(fd, WFIFOW(fd, 2));
  7933. }
  7934. /// Display msgstringtable.txt string (ZC_MSG).
  7935. /// 0291 <message>.W
  7936. void clif_msg(struct map_session_data* sd, unsigned short id)
  7937. {
  7938. int fd;
  7939. nullpo_retv(sd);
  7940. fd = sd->fd;
  7941. WFIFOHEAD(fd, packet_len(0x291));
  7942. WFIFOW(fd, 0) = 0x291;
  7943. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7944. WFIFOSET(fd, packet_len(0x291));
  7945. }
  7946. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7947. /// 0x7e2 <message>.W <value>.L
  7948. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7949. {
  7950. int fd = sd->fd;
  7951. WFIFOHEAD(fd, packet_len(0x7e2));
  7952. WFIFOW(fd,0) = 0x7e2;
  7953. WFIFOW(fd,2) = id;
  7954. WFIFOL(fd,4) = value;
  7955. WFIFOSET(fd, packet_len(0x7e2));
  7956. }
  7957. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7958. /// 07e6 <skill id>.W <msg id>.L
  7959. ///
  7960. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7961. /// "[SkillName] Message"
  7962. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7963. {
  7964. int fd = sd->fd;
  7965. WFIFOHEAD(fd, packet_len(0x7e6));
  7966. WFIFOW(fd,0) = 0x7e6;
  7967. WFIFOW(fd,2) = skill_id;
  7968. WFIFOL(fd,4) = msg_id;
  7969. WFIFOSET(fd, packet_len(0x7e6));
  7970. }
  7971. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7972. /// Returns true if the packet was parsed successfully.
  7973. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7974. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7975. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7976. {
  7977. char *text, *name, *message;
  7978. unsigned int packetlen, textlen, namelen, messagelen;
  7979. int fd = sd->fd;
  7980. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  7981. *name_ = NULL;
  7982. *namelen_ = 0;
  7983. *message_ = NULL;
  7984. *messagelen_ = 0;
  7985. packetlen = RFIFOW(fd,info->pos[0]);
  7986. // basic structure checks
  7987. if( packetlen < 4 + 1 )
  7988. { // 4-byte header and at least an empty string is expected
  7989. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7990. return false;
  7991. }
  7992. text = (char*)RFIFOP(fd,info->pos[1]);
  7993. textlen = packetlen - 4;
  7994. // process <name> part of the packet
  7995. if( format == 0 )
  7996. {// name and message are separated by ' : '
  7997. // validate name
  7998. name = text;
  7999. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8000. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8001. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8002. {
  8003. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8004. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8005. set_eof(fd); // Just kick them out to correct it.
  8006. return false;
  8007. }
  8008. message = name + namelen + 3;
  8009. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8010. }
  8011. else
  8012. {// name has fixed width
  8013. if( textlen < NAME_LENGTH + 1 )
  8014. {
  8015. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8016. return false;
  8017. }
  8018. // validate name
  8019. name = text;
  8020. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8021. if( name[namelen] != '\0' )
  8022. { // only restriction is that the name must be zero-terminated
  8023. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8024. return false;
  8025. }
  8026. message = name + NAME_LENGTH;
  8027. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8028. }
  8029. if( messagelen != strnlen(message, messagelen)+1 )
  8030. { // the declared length must match real length
  8031. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8032. return false;
  8033. }
  8034. // verify <message> part of the packet
  8035. if( message[messagelen-1] != '\0' )
  8036. { // message must be zero-terminated
  8037. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8038. return false;
  8039. }
  8040. if( messagelen > CHAT_SIZE_MAX-1 )
  8041. { // messages mustn't be too long
  8042. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8043. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8044. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8045. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8046. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8047. return false;
  8048. }
  8049. *name_ = name;
  8050. *namelen_ = namelen;
  8051. *message_ = message;
  8052. *messagelen_ = messagelen;
  8053. return true;
  8054. }
  8055. // ---------------------
  8056. // clif_guess_PacketVer
  8057. // ---------------------
  8058. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8059. // error codes:
  8060. // 0 - Success
  8061. // 1 - Unknown packet_ver
  8062. // 2 - Invalid account_id
  8063. // 3 - Invalid char_id
  8064. // 4 - Invalid login_id1 (reserved)
  8065. // 5 - Invalid client_tick (reserved)
  8066. // 6 - Invalid sex
  8067. // Only the first 'invalid' error that appears is used.
  8068. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8069. {
  8070. static int err = 1;
  8071. static int packet_ver = -1;
  8072. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  8073. if (get_previous)
  8074. {//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]
  8075. if( error )
  8076. *error = err;
  8077. return packet_ver;
  8078. }
  8079. //By default, start searching on the default one.
  8080. err = 1;
  8081. packet_ver = clif_config.packet_db_ver;
  8082. cmd = RFIFOW(fd,0);
  8083. packet_len = RFIFOREST(fd);
  8084. #define SET_ERROR(n) \
  8085. if( err == 1 )\
  8086. err = n;\
  8087. //define SET_ERROR
  8088. // FIXME: If the packet is not received at once, this will FAIL.
  8089. // Figure out, when it happens, that only part of the packet is
  8090. // received, or fix the function to be able to deal with that
  8091. // case.
  8092. #define CHECK_PACKET_VER() \
  8093. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8094. ;/* not wanttoconnection or wrong length */\
  8095. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8096. { SET_ERROR(2); }/* invalid account_id */\
  8097. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8098. { SET_ERROR(3); }/* invalid char_id */\
  8099. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8100. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8101. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8102. { SET_ERROR(6); }/* invalid sex */\
  8103. else\
  8104. {\
  8105. err = 0;\
  8106. if( error )\
  8107. *error = 0;\
  8108. return packet_ver;\
  8109. }\
  8110. //define CHECK_PACKET_VER
  8111. CHECK_PACKET_VER();//Default packet version found.
  8112. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8113. CHECK_PACKET_VER();
  8114. }
  8115. if( error )
  8116. *error = err;
  8117. packet_ver = -1;
  8118. return -1;
  8119. #undef SET_ERROR
  8120. #undef CHECK_PACKET_VER
  8121. }
  8122. // ------------
  8123. // clif_parse_*
  8124. // ------------
  8125. // Parses incoming (player) connection
  8126. /// Request to connect to map-server.
  8127. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8128. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8129. /// There are various variants of this packet, some of them have padding between fields.
  8130. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8131. {
  8132. struct block_list* bl;
  8133. struct auth_node* node;
  8134. int cmd, account_id, char_id, login_id1, sex;
  8135. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8136. 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])
  8137. if (sd) {
  8138. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8139. return;
  8140. }
  8141. // Only valid packet version get here
  8142. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8143. cmd = RFIFOW(fd,0);
  8144. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8145. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8146. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8147. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8148. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8149. if( packet_ver < 5 || // reject really old client versions
  8150. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8151. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8152. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8153. {// packet version rejected
  8154. 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));
  8155. WFIFOHEAD(fd,packet_len(0x6a));
  8156. WFIFOW(fd,0) = 0x6a;
  8157. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8158. WFIFOSET(fd,packet_len(0x6a));
  8159. set_eof(fd);
  8160. return;
  8161. }
  8162. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8163. clif_authfail_fd(fd,1);// server closed
  8164. return;
  8165. }
  8166. //Check for double login.
  8167. bl = map_id2bl(account_id);
  8168. if(bl && bl->type != BL_PC) {
  8169. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8170. WFIFOHEAD(fd,packet_len(0x6a));
  8171. WFIFOW(fd,0) = 0x6a;
  8172. WFIFOB(fd,2) = 3; // Rejected by server
  8173. WFIFOSET(fd,packet_len(0x6a));
  8174. set_eof(fd);
  8175. return;
  8176. }
  8177. if (bl ||
  8178. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8179. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8180. {
  8181. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8182. return;
  8183. }
  8184. CREATE(sd, TBL_PC, 1);
  8185. sd->fd = fd;
  8186. sd->packet_ver = packet_ver;
  8187. session[fd]->session_data = sd;
  8188. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8189. #if PACKETVER < 20070521
  8190. WFIFOHEAD(fd,4);
  8191. WFIFOL(fd,0) = sd->bl.id;
  8192. WFIFOSET(fd,4);
  8193. #else
  8194. WFIFOHEAD(fd,packet_len(0x283));
  8195. WFIFOW(fd,0) = 0x283;
  8196. WFIFOL(fd,2) = sd->bl.id;
  8197. WFIFOSET(fd,packet_len(0x283));
  8198. #endif
  8199. chrif_authreq(sd,false);
  8200. }
  8201. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8202. /// 007d
  8203. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8204. {
  8205. int i;
  8206. bool guild_notice = false;
  8207. if(sd->bl.prev != NULL)
  8208. return;
  8209. if (!sd->state.active) { //Character loading is not complete yet!
  8210. //Let pc_reg_received reinvoke this when ready.
  8211. sd->state.connect_new = 0;
  8212. return;
  8213. }
  8214. if (sd->state.rewarp) { //Rewarp player.
  8215. sd->state.rewarp = 0;
  8216. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8217. return;
  8218. }
  8219. sd->state.warping = 0;
  8220. // look
  8221. #if PACKETVER < 4
  8222. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8223. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8224. #else
  8225. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8226. #endif
  8227. if(sd->vd.cloth_color)
  8228. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8229. // item
  8230. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8231. pc_checkitem(sd);
  8232. // cart
  8233. if(pc_iscarton(sd)) {
  8234. clif_cartlist(sd);
  8235. clif_updatestatus(sd,SP_CARTINFO);
  8236. }
  8237. // weight
  8238. clif_updatestatus(sd,SP_WEIGHT);
  8239. clif_updatestatus(sd,SP_MAXWEIGHT);
  8240. // guild
  8241. // (needs to go before clif_spawn() to show guild emblems correctly)
  8242. if(sd->status.guild_id)
  8243. guild_send_memberinfoshort(sd,1);
  8244. if(battle_config.pc_invincible_time > 0) {
  8245. if(map_flag_gvg(sd->bl.m))
  8246. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8247. else
  8248. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8249. }
  8250. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8251. map_spawnmobs(sd->bl.m);
  8252. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8253. map[sd->bl.m].users_pvp++;
  8254. }
  8255. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8256. // reset the callshop flag if the player changes map
  8257. sd->state.callshop = 0;
  8258. if(map_addblock(&sd->bl))
  8259. return;
  8260. clif_spawn(&sd->bl);
  8261. // Party
  8262. // (needs to go after clif_spawn() to show hp bars correctly)
  8263. if(sd->status.party_id) {
  8264. party_send_movemap(sd);
  8265. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8266. }
  8267. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8268. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8269. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8270. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8271. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8272. sd->pvp_rank = 0;
  8273. sd->pvp_lastusers = 0;
  8274. sd->pvp_point = 5;
  8275. sd->pvp_won = 0;
  8276. sd->pvp_lost = 0;
  8277. }
  8278. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8279. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8280. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8281. if (map[sd->bl.m].flag.gvg_dungeon)
  8282. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8283. if( map_flag_gvg(sd->bl.m) )
  8284. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8285. // info about nearby objects
  8286. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8287. 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);
  8288. // pet
  8289. if( sd->pd ) {
  8290. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8291. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8292. pet_menu(sd, 3); //Option 3 is return to egg.
  8293. } else {
  8294. if(map_addblock(&sd->pd->bl))
  8295. return;
  8296. clif_spawn(&sd->pd->bl);
  8297. clif_send_petdata(sd,sd->pd,0,0);
  8298. clif_send_petstatus(sd);
  8299. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8300. }
  8301. }
  8302. //homunculus [blackhole89]
  8303. if( hom_is_active(sd->hd) ) {
  8304. if(map_addblock(&sd->hd->bl))
  8305. return;
  8306. clif_spawn(&sd->hd->bl);
  8307. clif_send_homdata(sd,SP_ACK,0);
  8308. clif_hominfo(sd,sd->hd,1);
  8309. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8310. clif_homskillinfoblock(sd);
  8311. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8312. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8313. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8314. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8315. }
  8316. if( sd->md ) {
  8317. if(map_addblock(&sd->md->bl))
  8318. return;
  8319. clif_spawn(&sd->md->bl);
  8320. clif_mercenary_info(sd);
  8321. clif_mercenary_skillblock(sd);
  8322. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8323. }
  8324. if( sd->ed ) {
  8325. map_addblock(&sd->ed->bl);
  8326. clif_spawn(&sd->ed->bl);
  8327. clif_elemental_info(sd);
  8328. clif_elemental_updatestatus(sd,SP_HP);
  8329. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8330. clif_elemental_updatestatus(sd,SP_SP);
  8331. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8332. }
  8333. if(sd->state.connect_new) {
  8334. int lv;
  8335. guild_notice = true;
  8336. sd->state.connect_new = 0;
  8337. clif_skillinfoblock(sd);
  8338. clif_hotkeys_send(sd);
  8339. clif_updatestatus(sd,SP_BASEEXP);
  8340. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8341. clif_updatestatus(sd,SP_JOBEXP);
  8342. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8343. clif_updatestatus(sd,SP_SKILLPOINT);
  8344. clif_initialstatus(sd);
  8345. if (sd->sc.option&OPTION_FALCON)
  8346. clif_status_load(&sd->bl, SI_FALCON, 1);
  8347. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8348. clif_status_load(&sd->bl, SI_RIDING, 1);
  8349. else if (sd->sc.option&OPTION_WUGRIDER)
  8350. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8351. else if (sd->sc.data[SC_ALL_RIDING])
  8352. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8353. if(sd->status.manner < 0)
  8354. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8355. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8356. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8357. if(sd->bl.m == sd->feel_map[0].m
  8358. || sd->bl.m == sd->feel_map[1].m
  8359. || sd->bl.m == sd->feel_map[2].m)
  8360. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8361. }
  8362. if(sd->pd && sd->pd->pet.intimate > 900)
  8363. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8364. if(hom_is_active(sd->hd))
  8365. hom_init_timers(sd->hd);
  8366. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8367. sd->state.night = 1;
  8368. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8369. }
  8370. // Notify everyone that this char logged in [Skotlex].
  8371. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8372. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8373. //Login Event
  8374. npc_script_event(sd, NPCE_LOGIN);
  8375. }
  8376. } else {
  8377. //For some reason the client "loses" these on warp/map-change.
  8378. clif_updatestatus(sd,SP_STR);
  8379. clif_updatestatus(sd,SP_AGI);
  8380. clif_updatestatus(sd,SP_VIT);
  8381. clif_updatestatus(sd,SP_INT);
  8382. clif_updatestatus(sd,SP_DEX);
  8383. clif_updatestatus(sd,SP_LUK);
  8384. // abort currently running script
  8385. sd->state.using_fake_npc = 0;
  8386. sd->state.menu_or_input = 0;
  8387. sd->npc_menu = 0;
  8388. if(sd->npc_id)
  8389. npc_event_dequeue(sd);
  8390. }
  8391. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8392. #if PACKETVER >= 20070918
  8393. clif_partyinvitationstate(sd);
  8394. clif_equipcheckbox(sd);
  8395. #endif
  8396. #ifdef VIP_ENABLE
  8397. if (!sd->disableshowrate) {
  8398. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8399. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8400. }
  8401. #endif
  8402. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8403. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8404. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8405. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8406. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8407. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8408. { //Display night.
  8409. if( !sd->state.night )
  8410. {
  8411. sd->state.night = 1;
  8412. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8413. }
  8414. }
  8415. else if( sd->state.night )
  8416. { //Clear night display.
  8417. sd->state.night = 0;
  8418. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8419. }
  8420. if( map[sd->bl.m].flag.battleground )
  8421. {
  8422. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8423. if( map[sd->bl.m].flag.battleground == 2 )
  8424. clif_bg_updatescore_single(sd);
  8425. }
  8426. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8427. {
  8428. char output[128];
  8429. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8430. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8431. }
  8432. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8433. map[sd->bl.m].hpmeter_visible++;
  8434. sd->state.hpmeter_visible = 1;
  8435. }
  8436. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8437. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8438. sd->state.changemap = false;
  8439. // Instances do not need their own channels
  8440. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8441. channel_mjoin(sd); //join new map
  8442. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8443. clif_guild_notice(sd, sd->guild); // Displays at end
  8444. mail_clear(sd);
  8445. clif_maptypeproperty2(&sd->bl,SELF);
  8446. /* Guild Aura Init */
  8447. if( sd->state.gmaster_flag ) {
  8448. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8449. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8450. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8451. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8452. }
  8453. if( sd->state.vending ) { /* show we have a vending */
  8454. clif_openvending(sd,sd->bl.id,sd->vending);
  8455. clif_showvendingboard(&sd->bl,sd->message,0);
  8456. }
  8457. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8458. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8459. npc_script_event(sd, NPCE_LOADMAP);
  8460. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8461. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8462. if (sd->sc.opt2) //Client loses these on warp.
  8463. clif_changeoption(&sd->bl);
  8464. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8465. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8466. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8467. }
  8468. clif_weather_check(sd);
  8469. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8470. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8471. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8472. else
  8473. sd->areanpc_id = 0;
  8474. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8475. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8476. pc_setdead(sd);
  8477. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8478. if(pc_isdead(sd))
  8479. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8480. else {
  8481. skill_usave_trigger(sd);
  8482. if (battle_config.spawn_direction)
  8483. clif_changed_dir(&sd->bl, SELF);
  8484. }
  8485. // Trigger skill effects if you appear standing on them
  8486. if(!battle_config.pc_invincible_time)
  8487. skill_unit_move(&sd->bl,gettick(),1);
  8488. // NPC Quest / Event Icon Check [Kisuka]
  8489. #if PACKETVER >= 20090218
  8490. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8491. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8492. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8493. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8494. if( sd->class_ == qi->job )
  8495. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8496. } else {
  8497. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8498. }
  8499. }
  8500. }
  8501. #endif
  8502. }
  8503. /// Server's tick (ZC_NOTIFY_TIME).
  8504. /// 007f <time>.L
  8505. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8506. {
  8507. int fd = sd->fd;
  8508. WFIFOHEAD(fd,packet_len(0x7f));
  8509. WFIFOW(fd,0) = 0x7f;
  8510. WFIFOL(fd,2) = time;
  8511. WFIFOSET(fd,packet_len(0x7f));
  8512. }
  8513. /// Request for server's tick.
  8514. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8515. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8516. /// There are various variants of this packet, some of them have padding between fields.
  8517. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8518. {
  8519. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8520. clif_notify_time(sd, gettick());
  8521. }
  8522. /// Sends hotkey bar.
  8523. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8524. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8525. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8526. void clif_hotkeys_send(struct map_session_data *sd) {
  8527. #ifdef HOTKEY_SAVING
  8528. const int fd = sd->fd;
  8529. int i;
  8530. #if PACKETVER < 20090603
  8531. const int cmd = 0x2b9;
  8532. #else
  8533. const int cmd = 0x7d9;
  8534. #endif
  8535. if (!fd) return;
  8536. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8537. WFIFOW(fd, 0) = cmd;
  8538. for(i = 0; i < MAX_HOTKEYS; i++) {
  8539. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8540. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8541. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8542. }
  8543. WFIFOSET(fd, packet_len(cmd));
  8544. #endif
  8545. }
  8546. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8547. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8548. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8549. #ifdef HOTKEY_SAVING
  8550. unsigned short idx;
  8551. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8552. idx = RFIFOW(fd, info->pos[0]);
  8553. if (idx >= MAX_HOTKEYS) return;
  8554. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8555. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8556. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8557. #endif
  8558. }
  8559. /// Displays cast-like progress bar (ZC_PROGRESS).
  8560. /// 02f0 <color>.L <time>.L
  8561. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8562. {
  8563. int fd = sd->fd;
  8564. WFIFOHEAD(fd,packet_len(0x2f0));
  8565. WFIFOW(fd,0) = 0x2f0;
  8566. WFIFOL(fd,2) = color;
  8567. WFIFOL(fd,6) = second;
  8568. WFIFOSET(fd,packet_len(0x2f0));
  8569. }
  8570. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8571. /// 02f2
  8572. void clif_progressbar_abort(struct map_session_data * sd)
  8573. {
  8574. int fd = sd->fd;
  8575. WFIFOHEAD(fd,packet_len(0x2f2));
  8576. WFIFOW(fd,0) = 0x2f2;
  8577. WFIFOSET(fd,packet_len(0x2f2));
  8578. }
  8579. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8580. /// 02f1
  8581. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8582. {
  8583. int npc_id = sd->progressbar.npc_id;
  8584. if( gettick() < sd->progressbar.timeout && sd->st )
  8585. sd->st->state = END;
  8586. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8587. npc_scriptcont(sd, npc_id, false);
  8588. }
  8589. /// Request to walk to a certain position on the current map.
  8590. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8591. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8592. /// There are various variants of this packet, some of them have padding between fields.
  8593. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8594. {
  8595. short x, y;
  8596. if (pc_isdead(sd)) {
  8597. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8598. return;
  8599. }
  8600. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8601. ; //You CAN walk on this OPT1 value.
  8602. else if( sd->progressbar.npc_id )
  8603. clif_progressbar_abort(sd);
  8604. else if (pc_cant_act(sd))
  8605. return;
  8606. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8607. return;
  8608. // Cloaking wall check is actually updated when you click to process next movement
  8609. // not when you move each cell. This is official behaviour.
  8610. if (sd->sc.data[SC_CLOAKING])
  8611. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8612. pc_delinvincibletimer(sd);
  8613. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8614. //Set last idle time... [Skotlex]
  8615. if (battle_config.idletime_option&IDLE_WALK)
  8616. sd->idletime = last_tick;
  8617. unit_walktoxy(&sd->bl, x, y, 4);
  8618. }
  8619. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8620. /// 018b <result>.W
  8621. /// result:
  8622. /// 0 = disconnect (quit)
  8623. /// 1 = cannot disconnect (wait 10 seconds)
  8624. /// ? = ignored
  8625. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8626. {
  8627. int fd = sd->fd;
  8628. WFIFOHEAD(fd,packet_len(0x18b));
  8629. WFIFOW(fd,0) = 0x18b;
  8630. WFIFOW(fd,2) = result;
  8631. WFIFOSET(fd,packet_len(0x18b));
  8632. }
  8633. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8634. /// 018a <type>.W
  8635. /// type:
  8636. /// 0 = quit
  8637. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8638. {
  8639. /* Rovert's prevent logout option fixed [Valaris] */
  8640. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8641. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8642. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8643. {
  8644. set_eof(fd);
  8645. pc_damage_log_clear(sd,0);
  8646. clif_disconnect_ack(sd, 0);
  8647. } else {
  8648. clif_disconnect_ack(sd, 1);
  8649. }
  8650. }
  8651. /// Requesting unit's name.
  8652. /// 0094 <id>.L (CZ_REQNAME)
  8653. /// 0368 <id>.L (CZ_REQNAME2)
  8654. /// There are various variants of this packet, some of them have padding between fields.
  8655. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8656. {
  8657. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8658. struct block_list* bl;
  8659. //struct status_change *sc;
  8660. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8661. id = sd->bl.id;
  8662. bl = map_id2bl(id);
  8663. if( bl == NULL )
  8664. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8665. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8666. return; // Block namerequests past view range
  8667. // 'see people in GM hide' cheat detection
  8668. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8669. sc = status_get_sc(bl);
  8670. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8671. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8672. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8673. ) {
  8674. char gm_msg[256];
  8675. 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);
  8676. ShowWarning(gm_msg);
  8677. // information is sent to all online GMs
  8678. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8679. return;
  8680. }
  8681. */
  8682. clif_charnameack(fd, bl);
  8683. }
  8684. /// Validates and processes global messages
  8685. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8686. /// There are various variants of this packet.
  8687. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8688. {
  8689. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8690. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8691. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8692. char *name, *message, *fakename = NULL;
  8693. int namelen, messagelen;
  8694. bool is_fake;
  8695. // validate packet and retrieve name and message
  8696. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8697. return;
  8698. if( is_atcommand(fd, sd, message, 1) )
  8699. return;
  8700. if (sd->sc.cant.chat)
  8701. return; //no "chatting" while muted.
  8702. if( battle_config.min_chat_delay ) { //[Skotlex]
  8703. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8704. return;
  8705. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8706. }
  8707. if (battle_config.idletime_option&IDLE_CHAT)
  8708. sd->idletime = last_tick;
  8709. if( sd->gcbind ) {
  8710. channel_send(sd->gcbind,sd,message);
  8711. return;
  8712. }
  8713. /**
  8714. * Fake Name Design by FatalEror (bug report #9)
  8715. **/
  8716. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8717. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8718. strcpy(fakename, sd->fakename);
  8719. strcat(fakename, " : ");
  8720. strcat(fakename, message);
  8721. textlen = strlen(fakename) + 1;
  8722. }
  8723. // send message to others (using the send buffer for temp. storage)
  8724. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8725. // send back message to the speaker
  8726. if( is_fake ) {
  8727. WFIFOW(fd,0) = 0x8e;
  8728. WFIFOW(fd,2) = textlen + 4;
  8729. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8730. aFree(fakename);
  8731. } else {
  8732. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8733. WFIFOW(fd,0) = 0x8e;
  8734. }
  8735. WFIFOSET(fd, WFIFOW(fd,2));
  8736. #ifdef PCRE_SUPPORT
  8737. // trigger listening npcs
  8738. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8739. #endif
  8740. // Chat logging type 'O' / Global Chat
  8741. 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);
  8742. }
  8743. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8744. /// Request to warp to a map on given coordinates.
  8745. /// 0140 <map name>.16B <x>.W <y>.W
  8746. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8747. {
  8748. char command[MAP_NAME_LENGTH_EXT+25];
  8749. char* map_name;
  8750. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8751. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8752. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8753. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8754. RFIFOW(fd,info->pos[1]), //x
  8755. RFIFOW(fd,info->pos[2])); //y
  8756. is_atcommand(fd, sd, command, 1);
  8757. }
  8758. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8759. /// 009c <id>.L <head dir>.W <dir>.B
  8760. /// head dir:
  8761. /// 0 = straight
  8762. /// 1 = turned CW
  8763. /// 2 = turned CCW
  8764. /// dir:
  8765. /// 0 = north
  8766. /// 1 = northwest
  8767. /// 2 = west
  8768. /// 3 = southwest
  8769. /// 4 = south
  8770. /// 5 = southeast
  8771. /// 6 = east
  8772. /// 7 = northeast
  8773. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8774. {
  8775. unsigned char buf[64];
  8776. WBUFW(buf,0) = 0x9c;
  8777. WBUFL(buf,2) = bl->id;
  8778. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8779. WBUFB(buf,8) = unit_getdir(bl);
  8780. clif_send(buf, packet_len(0x9c), bl, target);
  8781. if (disguised(bl)) {
  8782. WBUFL(buf,2) = -bl->id;
  8783. WBUFW(buf,6) = 0;
  8784. clif_send(buf, packet_len(0x9c), bl, SELF);
  8785. }
  8786. }
  8787. /// Request to change own body and head direction.
  8788. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8789. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8790. /// There are various variants of this packet, some of them have padding between fields.
  8791. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8792. {
  8793. unsigned char headdir, dir;
  8794. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8795. headdir = RFIFOB(fd,info->pos[0]);
  8796. dir = RFIFOB(fd,info->pos[1]);
  8797. pc_setdir(sd, dir, headdir);
  8798. clif_changed_dir(&sd->bl, AREA_WOS);
  8799. }
  8800. /// Request to show an emotion (CZ_REQ_EMOTION).
  8801. /// 00bf <type>.B
  8802. /// type:
  8803. /// @see enum emotion_type
  8804. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8805. {
  8806. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8807. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8808. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8809. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8810. return;
  8811. }
  8812. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8813. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8814. sd->emotionlasttime = time(NULL);
  8815. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8816. return;
  8817. }
  8818. sd->emotionlasttime = time(NULL);
  8819. if (battle_config.idletime_option&IDLE_EMOTION)
  8820. sd->idletime = last_tick;
  8821. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8822. emoticon = rnd()%6+E_DICE1;
  8823. }
  8824. clif_emotion(&sd->bl, emoticon);
  8825. } else
  8826. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8827. }
  8828. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8829. /// 00c2 <count>.L
  8830. void clif_user_count(struct map_session_data* sd, int count)
  8831. {
  8832. int fd = sd->fd;
  8833. WFIFOHEAD(fd,packet_len(0xc2));
  8834. WFIFOW(fd,0) = 0xc2;
  8835. WFIFOL(fd,2) = count;
  8836. WFIFOSET(fd,packet_len(0xc2));
  8837. }
  8838. /// /w /who (CZ_REQ_USER_COUNT).
  8839. /// Request to display amount of currently connected players.
  8840. /// 00c1
  8841. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8842. {
  8843. clif_user_count(sd, map_getusers());
  8844. }
  8845. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8846. {
  8847. if (pc_isdead(sd)) {
  8848. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8849. return;
  8850. }
  8851. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  8852. // (not all are included in pc_can_attack)
  8853. if (sd->sc.count &&
  8854. (sd->sc.data[SC_TRICKDEAD] ||
  8855. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  8856. sd->sc.data[SC_BLADESTOP] ||
  8857. sd->sc.data[SC__MANHOLE] ))
  8858. return;
  8859. pc_stop_walking(sd, 1);
  8860. pc_stop_attack(sd);
  8861. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8862. target_id = sd->bl.id;
  8863. switch(action_type)
  8864. {
  8865. case 0x00: // once attack
  8866. case 0x07: // continuous attack
  8867. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8868. return;
  8869. if( sd->sc.option&OPTION_COSTUME )
  8870. return;
  8871. if( sd->sc.option&OPTION_COSTUME )
  8872. return;
  8873. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8874. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8875. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8876. return;
  8877. }
  8878. }
  8879. pc_delinvincibletimer(sd);
  8880. if (battle_config.idletime_option&IDLE_ATTACK)
  8881. sd->idletime = last_tick;
  8882. unit_attack(&sd->bl, target_id, action_type != 0);
  8883. break;
  8884. case 0x02: // sitdown
  8885. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8886. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8887. break;
  8888. }
  8889. if(pc_issit(sd)) {
  8890. //Bugged client? Just refresh them.
  8891. clif_sitting(&sd->bl);
  8892. return;
  8893. }
  8894. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8895. break;
  8896. if (sd->sc.count && (
  8897. sd->sc.data[SC_DANCING] ||
  8898. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8899. )) //No sitting during these states either.
  8900. break;
  8901. if (battle_config.idletime_option&IDLE_SIT)
  8902. sd->idletime = last_tick;
  8903. skill_sit(sd, 1);
  8904. pc_setsit(sd);
  8905. clif_sitting(&sd->bl);
  8906. break;
  8907. case 0x03: // standup
  8908. if (!pc_issit(sd)) {
  8909. //Bugged client? Just refresh them.
  8910. clif_standing(&sd->bl);
  8911. return;
  8912. }
  8913. if (pc_setstand(sd, false)) {
  8914. if (battle_config.idletime_option&IDLE_SIT)
  8915. sd->idletime = last_tick;
  8916. skill_sit(sd, 0);
  8917. clif_standing(&sd->bl);
  8918. }
  8919. break;
  8920. }
  8921. }
  8922. /// Request for an action.
  8923. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8924. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8925. /// action:
  8926. /// 0 = attack
  8927. /// 1 = pick up item
  8928. /// 2 = sit down
  8929. /// 3 = stand up
  8930. /// 7 = continous attack
  8931. /// 12 = (touch skill?)
  8932. /// There are various variants of this packet, some of them have padding between fields.
  8933. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8934. {
  8935. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8936. clif_parse_ActionRequest_sub(sd,
  8937. RFIFOB(fd,info->pos[1]),
  8938. RFIFOL(fd,info->pos[0]),
  8939. gettick()
  8940. );
  8941. }
  8942. /// Response to the death/system menu (CZ_RESTART).
  8943. /// 00b2 <type>.B
  8944. /// type:
  8945. /// 0 = restart (respawn)
  8946. /// 1 = char-select (disconnect)
  8947. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8948. {
  8949. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8950. case 0x00:
  8951. pc_respawn(sd,CLR_OUTSIGHT);
  8952. break;
  8953. case 0x01:
  8954. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8955. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8956. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8957. { //Send to char-server for character selection.
  8958. pc_damage_log_clear(sd,0);
  8959. chrif_charselectreq(sd, session[fd]->client_addr);
  8960. } else {
  8961. clif_disconnect_ack(sd, 1);
  8962. }
  8963. break;
  8964. }
  8965. }
  8966. /// Validates and processes whispered messages (CZ_WHISPER).
  8967. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8968. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8969. {
  8970. struct map_session_data* dstsd;
  8971. int i;
  8972. char *target, *message;
  8973. int namelen, messagelen;
  8974. // validate packet and retrieve name and message
  8975. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8976. return;
  8977. if ( is_atcommand(fd, sd, message, 1) )
  8978. return;
  8979. if (sd->sc.cant.chat)
  8980. return; //no "chatting" while muted.
  8981. if (battle_config.min_chat_delay) { //[Skotlex]
  8982. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8983. return;
  8984. }
  8985. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8986. }
  8987. if (battle_config.idletime_option&IDLE_CHAT)
  8988. sd->idletime = last_tick;
  8989. // Chat logging type 'W' / Whisper
  8990. 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);
  8991. //-------------------------------------------------------//
  8992. // Lordalfa - Paperboy - To whisper NPC commands //
  8993. //-------------------------------------------------------//
  8994. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8995. {
  8996. char* str = target+4; //Skip the NPC: string part.
  8997. struct npc_data* npc;
  8998. if ((npc = npc_name2id(str))) {
  8999. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9000. char *split;
  9001. char output[256];
  9002. str = message;
  9003. // skip codepage indicator, if detected
  9004. if( str[0] == '|' && strlen(str) >= 4 )
  9005. str += 3;
  9006. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9007. split = strchr(str,'#');
  9008. if( split == NULL ) { // use the remaining string
  9009. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9010. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9011. split_data[i][0] = '\0';
  9012. break;
  9013. }
  9014. *split = '\0';
  9015. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9016. str = split+1;
  9017. }
  9018. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9019. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9020. set_var(sd,output,(char *) split_data[i]);
  9021. }
  9022. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9023. npc_event(sd,output,0); // Calls the NPC label
  9024. return;
  9025. }
  9026. } else if( target[0] == '#' ) {
  9027. struct Channel *channel = NULL;
  9028. char* chname = target;
  9029. channel = channel_name2channel(chname,sd,3);
  9030. if(channel){
  9031. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9032. channel_send(channel,sd,message);
  9033. }
  9034. else if( channel->pass[0] == '\0') { //no pass needed
  9035. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9036. }
  9037. else {
  9038. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9039. }
  9040. return;
  9041. }
  9042. }
  9043. // searching destination character
  9044. dstsd = map_nick2sd(target);
  9045. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9046. // player is not on this map-server
  9047. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9048. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9049. // and if we ask for 'Test', we must not contact 'test' player
  9050. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9051. intif_wis_message(sd, target, message, messagelen);
  9052. return;
  9053. }
  9054. // if player ignores everyone
  9055. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9056. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9057. clif_wis_end(fd, 1); // 1: target character is not logged in
  9058. else
  9059. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9060. return;
  9061. }
  9062. // if player is autotrading
  9063. if (dstsd->state.autotrade == 1) {
  9064. char output[256];
  9065. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9066. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9067. return;
  9068. }
  9069. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9070. // if player ignores the source character
  9071. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9072. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9073. clif_wis_end(fd, 2); // 2: ignored by target
  9074. return;
  9075. }
  9076. }
  9077. // notify sender of success
  9078. clif_wis_end(fd, 0); // 0: success to send wisper
  9079. // Normal message
  9080. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9081. }
  9082. /// /b /nb (CZ_BROADCAST).
  9083. /// Request to broadcast a message on whole server.
  9084. /// 0099 <packet len>.W <text>.?B 00
  9085. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9086. char command[CHAT_SIZE_MAX+11];
  9087. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9088. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9089. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9090. // as the length varies depending on the command used, just block unreasonably long strings
  9091. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9092. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9093. is_atcommand(fd, sd, command, 1);
  9094. }
  9095. /// Request to pick up an item.
  9096. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9097. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9098. /// There are various variants of this packet, some of them have padding between fields.
  9099. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9100. {
  9101. struct flooritem_data *fitem;
  9102. int map_object_id;
  9103. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9104. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9105. do {
  9106. if (pc_isdead(sd)) {
  9107. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9108. break;
  9109. }
  9110. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9111. break;
  9112. if (pc_cant_act(sd))
  9113. break;
  9114. if (!pc_takeitem(sd, fitem))
  9115. break;
  9116. return;
  9117. } while (0);
  9118. // Client REQUIRES a fail packet or you can no longer pick items.
  9119. clif_additem(sd,0,0,6);
  9120. }
  9121. /// Request to drop an item.
  9122. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9123. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9124. /// There are various variants of this packet, some of them have padding between fields.
  9125. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9126. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9127. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9128. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9129. for(;;) {
  9130. if (pc_isdead(sd))
  9131. break;
  9132. if (pc_cant_act2(sd) || sd->npc_id)
  9133. break;
  9134. if (sd->sc.count && (
  9135. sd->sc.data[SC_AUTOCOUNTER] ||
  9136. sd->sc.data[SC_BLADESTOP] ||
  9137. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9138. ))
  9139. break;
  9140. if (!pc_dropitem(sd, item_index, item_amount))
  9141. break;
  9142. if (battle_config.idletime_option&IDLE_DROPITEM)
  9143. sd->idletime = last_tick;
  9144. return;
  9145. }
  9146. //Because the client does not like being ignored.
  9147. clif_dropitem(sd, item_index,0);
  9148. }
  9149. /// Request to use an item.
  9150. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9151. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9152. /// There are various variants of this packet, some of them have padding between fields.
  9153. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9154. {
  9155. int n;
  9156. if (pc_isdead(sd)) {
  9157. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9158. return;
  9159. }
  9160. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9161. return;
  9162. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9163. if (battle_config.idletime_option&IDLE_USEITEM)
  9164. sd->idletime = last_tick;
  9165. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9166. if(n <0 || n >= MAX_INVENTORY)
  9167. return;
  9168. if (!pc_useitem(sd,n))
  9169. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9170. }
  9171. /// Request to equip an item
  9172. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9173. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9174. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9175. {
  9176. int index;
  9177. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9178. if(pc_isdead(sd)) {
  9179. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9180. return;
  9181. }
  9182. index = RFIFOW(fd,info->pos[0])-2;
  9183. if (index < 0 || index >= MAX_INVENTORY)
  9184. return; //Out of bounds check.
  9185. if(sd->npc_id && !sd->npc_item_flag) {
  9186. return;
  9187. } else if (sd->state.storage_flag || sd->sc.opt1)
  9188. ; //You can equip/unequip stuff while storage is open/under status changes
  9189. else if (pc_cant_act2(sd))
  9190. return;
  9191. if(!sd->status.inventory[index].identify) {
  9192. clif_equipitemack(sd,index,0,0); // fail
  9193. return;
  9194. }
  9195. if(!sd->inventory_data[index])
  9196. return;
  9197. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9198. pet_equipitem(sd,index);
  9199. return;
  9200. }
  9201. if (battle_config.idletime_option&IDLE_USEITEM)
  9202. sd->idletime = last_tick;
  9203. //Client doesn't send the position for ammo.
  9204. if(sd->inventory_data[index]->type == IT_AMMO)
  9205. pc_equipitem(sd,index,EQP_AMMO);
  9206. else {
  9207. int req_pos;
  9208. #if PACKETVER >= 20120925
  9209. req_pos = RFIFOL(fd,info->pos[1]);
  9210. #else
  9211. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9212. #endif
  9213. pc_equipitem(sd,index,req_pos);
  9214. }
  9215. }
  9216. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9217. /// 00ab <index>.W
  9218. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9219. {
  9220. int index;
  9221. if(pc_isdead(sd)) {
  9222. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9223. return;
  9224. }
  9225. if (sd->npc_id && !sd->npc_item_flag) {
  9226. return;
  9227. } else if (sd->state.storage_flag || sd->sc.opt1)
  9228. ; //You can equip/unequip stuff while storage is open/under status changes
  9229. else if (pc_cant_act2(sd))
  9230. return;
  9231. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9232. if (battle_config.idletime_option&IDLE_USEITEM)
  9233. sd->idletime = last_tick;
  9234. pc_unequipitem(sd,index,1);
  9235. }
  9236. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9237. /// 0090 <id>.L <type>.B
  9238. /// type:
  9239. /// 1 = click
  9240. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9241. {
  9242. struct block_list *bl;
  9243. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9244. if(pc_isdead(sd)) {
  9245. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9246. return;
  9247. }
  9248. if (pc_cant_act2(sd) || sd->npc_id)
  9249. return;
  9250. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9251. //type = RFIFOB(fd,info->pos[1]);
  9252. if (!bl) return;
  9253. switch (bl->type) {
  9254. case BL_MOB:
  9255. case BL_PC:
  9256. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9257. break;
  9258. case BL_NPC:
  9259. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9260. npc_click(sd,(TBL_NPC*)bl);
  9261. break;
  9262. }
  9263. }
  9264. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9265. /// 00c5 <id>.L <type>.B
  9266. /// type:
  9267. /// 0 = buy
  9268. /// 1 = sell
  9269. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9270. {
  9271. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9272. if (sd->state.trading)
  9273. return;
  9274. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9275. }
  9276. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9277. /// 00ca <result>.B
  9278. /// result:
  9279. /// 0 = "The deal has successfully completed."
  9280. /// 1 = "You do not have enough zeny."
  9281. /// 2 = "You are over your Weight Limit."
  9282. /// 3 = "Out of the maximum capacity, you have too many items."
  9283. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9284. {
  9285. int fd = sd->fd;
  9286. WFIFOHEAD(fd,packet_len(0xca));
  9287. WFIFOW(fd,0) = 0xca;
  9288. WFIFOB(fd,2) = result;
  9289. WFIFOSET(fd,packet_len(0xca));
  9290. }
  9291. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9292. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9293. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9294. {
  9295. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9296. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9297. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9298. int result;
  9299. if( sd->state.trading || !sd->npc_shopid )
  9300. result = 1;
  9301. else
  9302. result = npc_buylist(sd,n,item_list);
  9303. sd->npc_shopid = 0; //Clear shop data.
  9304. clif_npc_buy_result(sd, result);
  9305. }
  9306. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9307. /// 00cb <result>.B
  9308. /// result:
  9309. /// 0 = "The deal has successfully completed."
  9310. /// 1 = "The deal has failed."
  9311. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9312. {
  9313. int fd = sd->fd;
  9314. WFIFOHEAD(fd,packet_len(0xcb));
  9315. WFIFOW(fd,0) = 0xcb;
  9316. WFIFOB(fd,2) = result;
  9317. WFIFOSET(fd,packet_len(0xcb));
  9318. }
  9319. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9320. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9321. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9322. {
  9323. int fail=0,n;
  9324. unsigned short *item_list;
  9325. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9326. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9327. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9328. if (sd->state.trading || !sd->npc_shopid)
  9329. fail = 1;
  9330. else
  9331. fail = npc_selllist(sd,n,item_list);
  9332. sd->npc_shopid = 0; //Clear shop data.
  9333. clif_npc_sell_result(sd, fail);
  9334. }
  9335. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9336. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9337. /// type:
  9338. /// 0 = private
  9339. /// 1 = public
  9340. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9341. {
  9342. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9343. int len = RFIFOW(fd,info->pos[0])-15;
  9344. int limit = RFIFOW(fd,info->pos[1]);
  9345. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9346. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9347. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9348. char s_password[CHATROOM_PASS_SIZE];
  9349. char s_title[CHATROOM_TITLE_SIZE];
  9350. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9351. return;
  9352. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9353. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9354. return;
  9355. }
  9356. if( npc_isnear(&sd->bl) ) {
  9357. // uncomment to send msg_txt.
  9358. //char output[150];
  9359. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9360. //clif_displaymessage(sd->fd, output);
  9361. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9362. return;
  9363. }
  9364. if( len <= 0 )
  9365. return; // invalid input
  9366. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9367. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9368. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9369. }
  9370. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9371. /// 00d9 <chat ID>.L <passwd>.8B
  9372. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9373. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9374. int chatid = RFIFOL(fd,info->pos[0]);
  9375. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9376. chat_joinchat(sd,chatid,password);
  9377. }
  9378. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9379. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9380. /// type:
  9381. /// 0 = private
  9382. /// 1 = public
  9383. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9384. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9385. int len = RFIFOW(fd,info->pos[0])-15;
  9386. int limit = RFIFOW(fd,info->pos[1]);
  9387. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9388. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9389. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9390. char s_password[CHATROOM_PASS_SIZE];
  9391. char s_title[CHATROOM_TITLE_SIZE];
  9392. if( len <= 0 )
  9393. return; // invalid input
  9394. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9395. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9396. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9397. }
  9398. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9399. /// 00e0 <role>.L <nick>.24B
  9400. /// role:
  9401. /// 0 = owner
  9402. /// 1 = normal
  9403. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9404. {
  9405. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9406. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9407. }
  9408. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9409. /// 00e2 <name>.24B
  9410. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9411. {
  9412. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9413. }
  9414. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9415. /// 00e3
  9416. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9417. {
  9418. chat_leavechat(sd,0);
  9419. }
  9420. //Handles notifying asker and rejecter of what has just ocurred.
  9421. //Type is used to determine the correct msg_txt to use:
  9422. //0:
  9423. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9424. {
  9425. const char* msg;
  9426. char output[256];
  9427. // Your request has been rejected by autoreject option.
  9428. msg = msg_txt(sd,392);
  9429. clif_disp_onlyself(sd, msg, strlen(msg));
  9430. //Notice that a request was rejected.
  9431. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9432. clif_disp_onlyself(tsd, output, strlen(output));
  9433. }
  9434. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9435. /// 00e4 <account id>.L
  9436. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9437. {
  9438. struct map_session_data *t_sd;
  9439. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9440. if(!sd->chatID && pc_cant_act(sd))
  9441. return; //You can trade while in a chatroom.
  9442. // @noask [LuzZza]
  9443. if(t_sd && t_sd->state.noask) {
  9444. clif_noask_sub(sd, t_sd, 0);
  9445. return;
  9446. }
  9447. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9448. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9449. return;
  9450. }
  9451. trade_traderequest(sd,t_sd);
  9452. }
  9453. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9454. /// 00e6 <result>.B
  9455. /// result:
  9456. /// 3 = accepted
  9457. /// 4 = rejected
  9458. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9459. {
  9460. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9461. }
  9462. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9463. /// 00e8 <index>.W <amount>.L
  9464. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9465. {
  9466. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9467. short index = RFIFOW(fd,info->pos[0]);
  9468. int amount = RFIFOL(fd,info->pos[1]);
  9469. if( index == 0 )
  9470. trade_tradeaddzeny(sd, amount);
  9471. else
  9472. trade_tradeadditem(sd, index, (short)amount);
  9473. }
  9474. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9475. /// 00eb
  9476. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9477. {
  9478. trade_tradeok(sd);
  9479. }
  9480. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9481. /// 00ed
  9482. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9483. {
  9484. trade_tradecancel(sd);
  9485. }
  9486. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9487. /// 00ef
  9488. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9489. {
  9490. trade_tradecommit(sd);
  9491. }
  9492. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9493. /// 0118
  9494. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9495. {
  9496. pc_stop_attack(sd);
  9497. }
  9498. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9499. /// 0126 <index>.W <amount>.L
  9500. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9501. {
  9502. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9503. if (pc_istrading(sd))
  9504. return;
  9505. if (!pc_iscarton(sd))
  9506. return;
  9507. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9508. }
  9509. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9510. /// 0127 <index>.W <amount>.L
  9511. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9512. {
  9513. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9514. if (!pc_iscarton(sd))
  9515. return;
  9516. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9517. }
  9518. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9519. /// 012a
  9520. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9521. {
  9522. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9523. #ifdef NEW_CARTS
  9524. && sd->sc.data[SC_PUSH_CART] )
  9525. pc_setcart(sd,0);
  9526. #else
  9527. )
  9528. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9529. #endif
  9530. else // priority to remove this option before we can clear cart
  9531. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9532. }
  9533. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9534. /// 01af <num>.W
  9535. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9536. {// TODO: State tracking?
  9537. int type;
  9538. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9539. return;
  9540. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9541. #ifdef NEW_CARTS
  9542. if( (type == 9 && sd->status.base_level > 131) ||
  9543. (type == 8 && sd->status.base_level > 121) ||
  9544. (type == 7 && sd->status.base_level > 111) ||
  9545. (type == 6 && sd->status.base_level > 101) ||
  9546. (type == 5 && sd->status.base_level > 90) ||
  9547. (type == 4 && sd->status.base_level > 80) ||
  9548. (type == 3 && sd->status.base_level > 65) ||
  9549. (type == 2 && sd->status.base_level > 40) ||
  9550. (type == 1))
  9551. #else
  9552. if( (type == 5 && sd->status.base_level > 90) ||
  9553. (type == 4 && sd->status.base_level > 80) ||
  9554. (type == 3 && sd->status.base_level > 65) ||
  9555. (type == 2 && sd->status.base_level > 40) ||
  9556. (type == 1))
  9557. #endif
  9558. pc_setcart(sd,type);
  9559. }
  9560. /// Request to increase status (CZ_STATUS_CHANGE).
  9561. /// 00bb <status id>.W <amount>.B
  9562. /// status id:
  9563. /// SP_STR ~ SP_LUK
  9564. /// amount:
  9565. /// Old clients always send 1 for this, even when using /str+ and the like.
  9566. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9567. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9568. {
  9569. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9570. if( increase_amount < 0 ) {
  9571. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9572. fd, increase_amount);
  9573. }
  9574. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9575. }
  9576. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9577. /// 0112 <skill id>.W
  9578. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9579. {
  9580. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9581. }
  9582. 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)
  9583. {
  9584. int lv;
  9585. if( !hd )
  9586. return;
  9587. if( skill_isNotOk_hom(skill_id, hd) )
  9588. return;
  9589. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9590. target_id = hd->bl.id;
  9591. if( hd->ud.skilltimer != INVALID_TIMER )
  9592. {
  9593. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9594. }
  9595. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9596. return;
  9597. lv = hom_checkskill(hd, skill_id);
  9598. if( skill_lv > lv )
  9599. skill_lv = lv;
  9600. if( skill_lv )
  9601. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9602. }
  9603. 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)
  9604. {
  9605. int lv;
  9606. if( !hd )
  9607. return;
  9608. if( skill_isNotOk_hom(skill_id, hd) )
  9609. return;
  9610. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9611. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9612. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9613. return;
  9614. if( hd->sc.data[SC_BASILICA] )
  9615. return;
  9616. lv = hom_checkskill(hd, skill_id);
  9617. if( skill_lv > lv )
  9618. skill_lv = lv;
  9619. if( skill_lv )
  9620. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9621. }
  9622. 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)
  9623. {
  9624. int lv;
  9625. if( !md )
  9626. return;
  9627. if( skill_isNotOk_mercenary(skill_id, md) )
  9628. return;
  9629. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9630. target_id = md->bl.id;
  9631. if( md->ud.skilltimer != INVALID_TIMER )
  9632. {
  9633. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9634. }
  9635. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9636. return;
  9637. lv = mercenary_checkskill(md, skill_id);
  9638. if( skill_lv > lv )
  9639. skill_lv = lv;
  9640. if( skill_lv )
  9641. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9642. }
  9643. 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)
  9644. {
  9645. int lv;
  9646. if( !md )
  9647. return;
  9648. if( skill_isNotOk_mercenary(skill_id, md) )
  9649. return;
  9650. if( md->ud.skilltimer != INVALID_TIMER )
  9651. return;
  9652. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9653. {
  9654. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9655. return;
  9656. }
  9657. if( md->sc.data[SC_BASILICA] )
  9658. return;
  9659. lv = mercenary_checkskill(md, skill_id);
  9660. if( skill_lv > lv )
  9661. skill_lv = lv;
  9662. if( skill_lv )
  9663. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9664. }
  9665. /// Request to use a targeted skill.
  9666. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9667. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9668. /// There are various variants of this packet, some of them have padding between fields.
  9669. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9670. {
  9671. uint16 skill_id, skill_lv;
  9672. int tmp, target_id;
  9673. unsigned int tick = gettick();
  9674. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9675. skill_lv = RFIFOW(fd,info->pos[0]);
  9676. skill_id = RFIFOW(fd,info->pos[1]);
  9677. target_id = RFIFOL(fd,info->pos[2]);
  9678. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9679. tmp = skill_get_inf(skill_id);
  9680. if (tmp&INF_GROUND_SKILL || !tmp)
  9681. return; //Using a ground/passive skill on a target? WRONG.
  9682. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9683. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9684. return;
  9685. }
  9686. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9687. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9688. return;
  9689. }
  9690. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9691. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  9692. sd->idletime = last_tick;
  9693. if( sd->npc_id ){
  9694. #ifdef RENEWAL
  9695. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9696. return;
  9697. #else
  9698. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9699. return;
  9700. #endif
  9701. }
  9702. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9703. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9704. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9705. return;
  9706. if( pc_issit(sd) )
  9707. return;
  9708. if( skill_isNotOk(skill_id, sd) )
  9709. return;
  9710. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9711. target_id = sd->bl.id; // never trust the client
  9712. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9713. target_id = sd->bl.id;
  9714. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9715. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9716. return;
  9717. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9718. if( sd->skillitem != skill_id ) {
  9719. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9720. return;
  9721. }
  9722. }
  9723. if( sd->sc.option&OPTION_COSTUME )
  9724. return;
  9725. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9726. return; // On basilica only caster can use Basilica again to stop it.
  9727. if( sd->menuskill_id ) {
  9728. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9729. clif_menuskill_clear(sd); //Cancel pet capture.
  9730. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9731. return; //Can't use skills while a menu is open.
  9732. }
  9733. if( sd->skillitem == skill_id ) {
  9734. if( skill_lv != sd->skillitemlv )
  9735. skill_lv = sd->skillitemlv;
  9736. if( !(tmp&INF_SELF_SKILL) )
  9737. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9738. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9739. return;
  9740. }
  9741. sd->skillitem = sd->skillitemlv = 0;
  9742. if( skill_id >= GD_SKILLBASE ) {
  9743. if( sd->state.gmaster_flag )
  9744. skill_lv = guild_checkskill(sd->guild, skill_id);
  9745. else
  9746. skill_lv = 0;
  9747. } else {
  9748. tmp = pc_checkskill(sd, skill_id);
  9749. if( skill_lv > tmp )
  9750. skill_lv = tmp;
  9751. }
  9752. pc_delinvincibletimer(sd);
  9753. if( skill_lv )
  9754. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9755. }
  9756. /*==========================================
  9757. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9758. *------------------------------------------*/
  9759. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9760. {
  9761. unsigned int tick = gettick();
  9762. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9763. return; //Using a target skill on the ground? WRONG.
  9764. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9765. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9766. return;
  9767. }
  9768. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9769. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9770. return;
  9771. }
  9772. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9773. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  9774. sd->idletime = last_tick;
  9775. if( skill_isNotOk(skill_id, sd) )
  9776. return;
  9777. if( skillmoreinfo != -1 ) {
  9778. if( pc_issit(sd) ) {
  9779. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9780. return;
  9781. }
  9782. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9783. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9784. }
  9785. if( sd->ud.skilltimer != INVALID_TIMER )
  9786. return;
  9787. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9788. if( sd->skillitem != skill_id ) {
  9789. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9790. return;
  9791. }
  9792. }
  9793. if( sd->sc.option&OPTION_COSTUME )
  9794. return;
  9795. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9796. return; // On basilica only caster can use Basilica again to stop it.
  9797. if( sd->menuskill_id ) {
  9798. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9799. clif_menuskill_clear(sd); //Cancel pet capture.
  9800. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9801. return; //Can't use skills while a menu is open.
  9802. }
  9803. pc_delinvincibletimer(sd);
  9804. if( sd->skillitem == skill_id ) {
  9805. if( skill_lv != sd->skillitemlv )
  9806. skill_lv = sd->skillitemlv;
  9807. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9808. } else {
  9809. int lv;
  9810. sd->skillitem = sd->skillitemlv = 0;
  9811. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9812. if( skill_lv > lv )
  9813. skill_lv = lv;
  9814. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9815. }
  9816. }
  9817. }
  9818. /// Request to use a ground skill.
  9819. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9820. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9821. /// There are various variants of this packet, some of them have padding between fields.
  9822. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9823. {
  9824. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9825. if (pc_cant_act(sd))
  9826. return;
  9827. if (pc_issit(sd))
  9828. return;
  9829. clif_parse_UseSkillToPosSub(fd, sd,
  9830. RFIFOW(fd,info->pos[0]), //skill lv
  9831. RFIFOW(fd,info->pos[1]), //skill num
  9832. RFIFOW(fd,info->pos[2]), //pos x
  9833. RFIFOW(fd,info->pos[3]), //pos y
  9834. -1 //Skill more info.
  9835. );
  9836. }
  9837. /// Request to use a ground skill with text.
  9838. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9839. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9840. /// There are various variants of this packet, some of them have padding between fields.
  9841. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9842. {
  9843. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9844. if (pc_cant_act(sd))
  9845. return;
  9846. if (pc_issit(sd))
  9847. return;
  9848. clif_parse_UseSkillToPosSub(fd, sd,
  9849. RFIFOW(fd,info->pos[0]), //Skill lv
  9850. RFIFOW(fd,info->pos[1]), //Skill num
  9851. RFIFOW(fd,info->pos[2]), //pos x
  9852. RFIFOW(fd,info->pos[3]), //pos y
  9853. info->pos[4] //skill more info
  9854. );
  9855. }
  9856. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9857. /// 011b <skill id>.W <map name>.16B
  9858. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9859. {
  9860. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9861. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9862. char map_name[MAP_NAME_LENGTH];
  9863. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9864. if(skill_id != sd->menuskill_id)
  9865. return;
  9866. //It is possible to use teleport with the storage window open bugreport:8027
  9867. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  9868. clif_menuskill_clear(sd);
  9869. return;
  9870. }
  9871. pc_delinvincibletimer(sd);
  9872. skill_castend_map(sd,skill_id,map_name);
  9873. }
  9874. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9875. /// 011d
  9876. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9877. {
  9878. if (!pc_isdead(sd))
  9879. pc_memo(sd,-1);
  9880. }
  9881. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9882. /// 018e <name id>.W { <material id>.W }*3
  9883. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9884. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9885. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  9886. int slot1 = RFIFOW(fd,info->pos[1]);
  9887. int slot2 = RFIFOW(fd,info->pos[2]);
  9888. int slot3 = RFIFOW(fd,info->pos[3]);
  9889. switch( sd->menuskill_id ) {
  9890. case -1:
  9891. case AM_PHARMACY:
  9892. case RK_RUNEMASTERY:
  9893. case GC_RESEARCHNEWPOISON:
  9894. break;
  9895. default:
  9896. return;
  9897. }
  9898. if (pc_istrading(sd)) {
  9899. //Make it fail to avoid shop exploits where you sell something different than you see.
  9900. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9901. clif_menuskill_clear(sd);
  9902. return;
  9903. }
  9904. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9905. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9906. clif_menuskill_clear(sd);
  9907. }
  9908. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9909. /// 025b <mk type>.W <name id>.W
  9910. /// mk type:
  9911. /// 1 = cooking
  9912. /// 2 = arrow
  9913. /// 3 = elemental
  9914. /// 4 = GN_MIX_COOKING
  9915. /// 5 = GN_MAKEBOMB
  9916. /// 6 = GN_S_PHARMACY
  9917. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9918. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9919. int type = RFIFOW(fd,info->pos[0]);
  9920. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  9921. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  9922. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9923. return;
  9924. if (pc_istrading(sd)) {
  9925. //Make it fail to avoid shop exploits where you sell something different than you see.
  9926. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9927. clif_menuskill_clear(sd);
  9928. return;
  9929. }
  9930. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9931. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9932. clif_menuskill_clear(sd);
  9933. }
  9934. /// Answer to repair weapon item selection dialog
  9935. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9936. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9937. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9938. {
  9939. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9940. return;
  9941. if (pc_istrading(sd)) {
  9942. //Make it fail to avoid shop exploits where you sell something different than you see.
  9943. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9944. clif_menuskill_clear(sd);
  9945. return;
  9946. }
  9947. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9948. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9949. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9950. //for(i = 0; i<MAX_SLOTS; i++)
  9951. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9952. clif_menuskill_clear(sd);
  9953. }
  9954. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9955. /// 0222 <index>.L
  9956. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9957. {
  9958. int idx;
  9959. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9960. return;
  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. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9968. skill_weaponrefine(sd, idx-2);
  9969. clif_menuskill_clear(sd);
  9970. }
  9971. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9972. /// 00b8 <npc id>.L <choice>.B
  9973. /// choice:
  9974. /// 1~254 = menu item
  9975. /// 255 = cancel
  9976. /// NOTE: If there were more than 254 items in the list, choice
  9977. /// overflows to choice%256.
  9978. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  9979. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9980. int npc_id = RFIFOL(fd,info->pos[0]);
  9981. uint8 select = RFIFOB(fd,info->pos[1]);
  9982. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9983. #ifdef SECURE_NPCTIMEOUT
  9984. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9985. #endif
  9986. TBL_NPC* nd = map_id2nd(npc_id);
  9987. 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);
  9988. clif_GM_kick(NULL,sd);
  9989. #ifdef SECURE_NPCTIMEOUT
  9990. }
  9991. #endif
  9992. return;
  9993. }
  9994. sd->npc_menu = select;
  9995. npc_scriptcont(sd,npc_id, false);
  9996. }
  9997. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9998. /// 00b9 <npc id>.L
  9999. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10000. {
  10001. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10002. }
  10003. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10004. /// 0143 <npc id>.L <value>.L
  10005. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10006. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10007. int npcid = RFIFOL(fd,info->pos[0]);
  10008. int amount = (int)RFIFOL(fd,info->pos[1]);
  10009. sd->npc_amount = amount;
  10010. npc_scriptcont(sd, npcid, false);
  10011. }
  10012. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10013. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10014. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10015. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10016. int message_len = RFIFOW(fd,info->pos[0])-8;
  10017. int npcid = RFIFOL(fd,info->pos[1]);
  10018. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10019. if( message_len <= 0 )
  10020. return; // invalid input
  10021. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10022. npc_scriptcont(sd, npcid, false);
  10023. }
  10024. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10025. /// 0146 <npc id>.L
  10026. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10027. {
  10028. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10029. return;
  10030. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10031. }
  10032. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10033. /// 0178 <index>.W
  10034. /// index:
  10035. /// -1 = cancel
  10036. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10037. {
  10038. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10039. if (sd->menuskill_id != MC_IDENTIFY)
  10040. return;
  10041. if( idx == -1 ) {// cancel pressed
  10042. clif_menuskill_clear(sd);
  10043. return;
  10044. }
  10045. skill_identify(sd,idx-2);
  10046. clif_menuskill_clear(sd);
  10047. }
  10048. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10049. /// 01ae <name id>.W
  10050. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10051. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10052. if (pc_istrading(sd)) {
  10053. //Make it fail to avoid shop exploits where you sell something different than you see.
  10054. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10055. clif_menuskill_clear(sd);
  10056. return;
  10057. }
  10058. switch (sd->menuskill_id) {
  10059. case AC_MAKINGARROW:
  10060. skill_arrow_create(sd,nameid);
  10061. break;
  10062. case SA_CREATECON:
  10063. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  10064. break;
  10065. case WL_READING_SB:
  10066. skill_spellbook(sd,nameid);
  10067. break;
  10068. case GC_POISONINGWEAPON:
  10069. skill_poisoningweapon(sd,nameid);
  10070. break;
  10071. case NC_MAGICDECOY:
  10072. skill_magicdecoy(sd,nameid);
  10073. break;
  10074. }
  10075. clif_menuskill_clear(sd);
  10076. }
  10077. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10078. /// 01ce <skill id>.L
  10079. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10080. {
  10081. if (sd->menuskill_id != SA_AUTOSPELL)
  10082. return;
  10083. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10084. clif_menuskill_clear(sd);
  10085. }
  10086. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10087. /// 017a <card index>.W
  10088. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10089. {
  10090. if (sd->state.trading != 0)
  10091. return;
  10092. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10093. }
  10094. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10095. /// 017c <card index>.W <equip index>.W
  10096. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10097. {
  10098. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10099. if (sd->state.trading != 0)
  10100. return;
  10101. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10102. }
  10103. /// Request of character's name by char ID.
  10104. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10105. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10106. /// There are various variants of this packet, some of them have padding between fields.
  10107. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10108. {
  10109. int charid;
  10110. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10111. map_reqnickdb(sd, charid);
  10112. }
  10113. /// /resetskill /resetstate (CZ_RESET).
  10114. /// Request to reset stats or skills.
  10115. /// 0197 <type>.W
  10116. /// type:
  10117. /// 0 = state
  10118. /// 1 = skill
  10119. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10120. char cmd[15];
  10121. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10122. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10123. else
  10124. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10125. is_atcommand(fd, sd, cmd, 1);
  10126. }
  10127. /// /lb /nlb (CZ_LOCALBROADCAST).
  10128. /// Request to broadcast a message on current map.
  10129. /// 019c <packet len>.W <text>.?B
  10130. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10131. {
  10132. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10133. char command[CHAT_SIZE_MAX+16];
  10134. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10135. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10136. // as the length varies depending on the command used, just block unreasonably long strings
  10137. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10138. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10139. is_atcommand(fd, sd, command, 1);
  10140. }
  10141. /// Request to move an item from inventory to storage.
  10142. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10143. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10144. /// There are various variants of this packet, some of them have padding between fields.
  10145. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10146. {
  10147. int item_index, item_amount;
  10148. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10149. if (pc_istrading(sd))
  10150. return;
  10151. item_index = RFIFOW(fd,info->pos[0])-2;
  10152. item_amount = RFIFOL(fd,info->pos[1]);
  10153. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10154. return;
  10155. if (sd->state.storage_flag == 1)
  10156. storage_storageadd(sd, item_index, item_amount);
  10157. else
  10158. if (sd->state.storage_flag == 2)
  10159. storage_guild_storageadd(sd, item_index, item_amount);
  10160. }
  10161. /// Request to move an item from storage to inventory.
  10162. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10163. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10164. /// There are various variants of this packet, some of them have padding between fields.
  10165. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10166. {
  10167. int item_index, item_amount;
  10168. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10169. item_index = RFIFOW(fd,info->pos[0])-1;
  10170. item_amount = RFIFOL(fd,info->pos[1]);
  10171. if (sd->state.storage_flag == 1)
  10172. storage_storageget(sd, item_index, item_amount);
  10173. else if(sd->state.storage_flag == 2)
  10174. storage_guild_storageget(sd, item_index, item_amount);
  10175. }
  10176. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10177. /// 0129 <index>.W <amount>.L
  10178. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10179. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10180. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10181. int amount = RFIFOL(fd,info->pos[1]);
  10182. if( sd->state.vending )
  10183. return;
  10184. if (!pc_iscarton(sd))
  10185. return;
  10186. if (sd->state.storage_flag == 1)
  10187. storage_storageaddfromcart(sd, idx, amount);
  10188. else if (sd->state.storage_flag == 2)
  10189. storage_guild_storageaddfromcart(sd, idx, amount);
  10190. }
  10191. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10192. /// 0128 <index>.W <amount>.L
  10193. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10194. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10195. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10196. int amount = RFIFOL(fd,info->pos[1]);
  10197. if( sd->state.vending )
  10198. return;
  10199. if (!pc_iscarton(sd))
  10200. return;
  10201. if (sd->state.storage_flag == 1)
  10202. storage_storagegettocart(sd, idx, amount);
  10203. else
  10204. if (sd->state.storage_flag == 2)
  10205. storage_guild_storagegettocart(sd, idx, amount);
  10206. }
  10207. /// Request to close storage (CZ_CLOSE_STORE).
  10208. /// 00f7
  10209. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10210. {
  10211. if( sd->state.storage_flag == 1 )
  10212. storage_storageclose(sd);
  10213. else
  10214. if( sd->state.storage_flag == 2 )
  10215. storage_guild_storageclose(sd);
  10216. }
  10217. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10218. /// 023a <info>.W
  10219. /// info:
  10220. /// 0 = password has not been set yet
  10221. /// 1 = storage is password-protected
  10222. /// 8 = too many wrong passwords
  10223. /// ? = ignored
  10224. /// NOTE: This packet is only available on certain non-kRO clients.
  10225. void clif_storagepassword(struct map_session_data* sd, short info)
  10226. {
  10227. int fd = sd->fd;
  10228. WFIFOHEAD(fd,packet_len(0x23a));
  10229. WFIFOW(fd,0) = 0x23a;
  10230. WFIFOW(fd,2) = info;
  10231. WFIFOSET(fd,packet_len(0x23a));
  10232. }
  10233. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10234. /// 023b <type>.W <password>.16B <new password>.16B
  10235. /// type:
  10236. /// 2 = change password
  10237. /// 3 = check password
  10238. /// NOTE: This packet is only available on certain non-kRO clients.
  10239. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10240. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10241. // int type = RFIFOW(fd,info->pos[0]);
  10242. // char* password = RFIFOP(fd,info->pos[1]);
  10243. // char* new_password = RFIFOP(fd,info->pos[2]);
  10244. // storage_changepass(sd,password,new_password);
  10245. }
  10246. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10247. /// 023c <result>.W <error count>.W
  10248. /// result:
  10249. /// 4 = password change success
  10250. /// 5 = password change failure
  10251. /// 6 = password check success
  10252. /// 7 = password check failure
  10253. /// 8 = too many wrong passwords
  10254. /// ? = ignored
  10255. /// NOTE: This packet is only available on certain non-kRO clients.
  10256. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10257. {
  10258. int fd = sd->fd;
  10259. WFIFOHEAD(fd,packet_len(0x23c));
  10260. WFIFOW(fd,0) = 0x23c;
  10261. WFIFOW(fd,2) = result;
  10262. WFIFOW(fd,4) = error_count;
  10263. WFIFOSET(fd,packet_len(0x23c));
  10264. }
  10265. /// Party creation request
  10266. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10267. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10268. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10269. name[NAME_LENGTH-1] = '\0';
  10270. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10271. clif_displaymessage(fd, msg_txt(sd,227));
  10272. return;
  10273. }
  10274. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10275. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10276. return;
  10277. }
  10278. party_create(sd,name,0,0);
  10279. }
  10280. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10281. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10282. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10283. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10284. int item1 = RFIFOB(fd,info->pos[1]);
  10285. int item2 = RFIFOB(fd,info->pos[2]);
  10286. name[NAME_LENGTH-1] = '\0';
  10287. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10288. clif_displaymessage(fd, msg_txt(sd,227));
  10289. return;
  10290. }
  10291. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10292. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10293. return;
  10294. }
  10295. party_create(sd,name,item1,item2);
  10296. }
  10297. /// Party invitation request
  10298. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10299. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10300. {
  10301. struct map_session_data *t_sd;
  10302. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10303. clif_displaymessage(fd, msg_txt(sd,227));
  10304. return;
  10305. }
  10306. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10307. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10308. clif_noask_sub(sd, t_sd, 1);
  10309. return;
  10310. }
  10311. party_invite(sd, t_sd);
  10312. }
  10313. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10314. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10315. struct map_session_data *t_sd;
  10316. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10317. name[NAME_LENGTH-1] = '\0';
  10318. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10319. clif_displaymessage(fd, msg_txt(sd,227));
  10320. return;
  10321. }
  10322. t_sd = map_nick2sd(name);
  10323. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10324. clif_noask_sub(sd, t_sd, 1);
  10325. return;
  10326. }
  10327. party_invite(sd, t_sd);
  10328. }
  10329. /// Party invitation reply
  10330. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10331. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10332. /// flag:
  10333. /// 0 = reject
  10334. /// 1 = accept
  10335. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10336. {
  10337. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10338. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10339. RFIFOL(fd,info->pos[1]));
  10340. }
  10341. //(CZ_PARTY_JOIN_REQ_ACK)
  10342. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10343. {
  10344. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10345. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10346. RFIFOB(fd,info->pos[1]));
  10347. }
  10348. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10349. /// 0100
  10350. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10351. {
  10352. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10353. clif_displaymessage(fd, msg_txt(sd,227));
  10354. return;
  10355. }
  10356. party_leave(sd);
  10357. }
  10358. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10359. /// 0103 <account id>.L <char name>.24B
  10360. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10361. {
  10362. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10363. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10364. clif_displaymessage(fd, msg_txt(sd,227));
  10365. return;
  10366. }
  10367. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10368. (char*)RFIFOP(fd,info->pos[1]));
  10369. }
  10370. /// Request to change party options.
  10371. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10372. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10373. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10374. {
  10375. struct party_data *p;
  10376. int i,expflag;
  10377. int cmd = RFIFOW(fd,0);
  10378. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10379. if( !sd->status.party_id )
  10380. return;
  10381. p = party_search(sd->status.party_id);
  10382. if( p == NULL )
  10383. return;
  10384. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10385. if( i == MAX_PARTY )
  10386. return; //Shouldn't happen
  10387. if( !p->party.member[i].leader )
  10388. return;
  10389. expflag = RFIFOL(fd,info->pos[0]);
  10390. if(cmd == 0x0102){ //Client can't change the item-field
  10391. party_changeoption(sd, expflag, p->party.item);
  10392. }
  10393. else {
  10394. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10395. party_changeoption(sd, expflag, itemflag);
  10396. }
  10397. }
  10398. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10399. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10400. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10401. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10402. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10403. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10404. char *name, *message;
  10405. int namelen, messagelen;
  10406. // validate packet and retrieve name and message
  10407. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10408. return;
  10409. if( is_atcommand(fd, sd, message, 1) )
  10410. return;
  10411. if (sd->sc.cant.chat)
  10412. return; //no "chatting" while muted.
  10413. if( battle_config.min_chat_delay )
  10414. { //[Skotlex]
  10415. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10416. return;
  10417. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10418. }
  10419. if (battle_config.idletime_option&IDLE_CHAT)
  10420. sd->idletime = last_tick;
  10421. party_send_message(sd, text, textlen);
  10422. }
  10423. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10424. /// 07da <account id>.L
  10425. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10426. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10427. }
  10428. /// Party Booking in KRO [Spiria]
  10429. ///
  10430. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10431. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10432. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10433. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10434. short level = RFIFOW(fd,info->pos[0]);
  10435. short mapid = RFIFOW(fd,info->pos[1]);
  10436. int idxpbj = info->pos[2];
  10437. short job[PARTY_BOOKING_JOBS];
  10438. int i;
  10439. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10440. job[i] = RFIFOB(fd,idxpbj+i*2);
  10441. party_booking_register(sd, level, mapid, job);
  10442. }
  10443. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10444. /// 0803 <result>.W
  10445. /// result:
  10446. /// 0 = success
  10447. /// 1 = failure
  10448. /// 2 = already registered
  10449. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10450. {
  10451. int fd = sd->fd;
  10452. WFIFOHEAD(fd,packet_len(0x803));
  10453. WFIFOW(fd,0) = 0x803;
  10454. WFIFOW(fd,2) = flag;
  10455. WFIFOSET(fd,packet_len(0x803));
  10456. }
  10457. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10458. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10459. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10460. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10461. short level = RFIFOW(fd,info->pos[0]);
  10462. short mapid = RFIFOW(fd,info->pos[1]);
  10463. short job = RFIFOW(fd,info->pos[2]);
  10464. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10465. short resultcount = RFIFOW(fd,info->pos[4]);
  10466. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10467. }
  10468. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10469. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10470. /// more results:
  10471. /// 0 = no
  10472. /// 1 = yes
  10473. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10474. {
  10475. int i, j;
  10476. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10477. struct party_booking_ad_info *pb_ad;
  10478. WFIFOHEAD(fd,size*count + 5);
  10479. WFIFOW(fd,0) = 0x805;
  10480. WFIFOW(fd,2) = size*count + 5;
  10481. WFIFOB(fd,4) = more_result;
  10482. for(i=0; i<count; i++)
  10483. {
  10484. pb_ad = results[i];
  10485. WFIFOL(fd,i*size+5) = pb_ad->index;
  10486. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10487. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10488. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10489. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10490. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10491. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10492. }
  10493. WFIFOSET(fd,WFIFOW(fd,2));
  10494. }
  10495. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10496. /// 0806
  10497. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10498. {
  10499. if(party_booking_delete(sd))
  10500. clif_PartyBookingDeleteAck(sd, 0);
  10501. }
  10502. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10503. /// 0807 <result>.W
  10504. /// result:
  10505. /// 0 = success
  10506. /// 1 = success (auto-removed expired ad)
  10507. /// 2 = failure
  10508. /// 3 = nothing registered
  10509. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10510. {
  10511. int fd = sd->fd;
  10512. WFIFOHEAD(fd,packet_len(0x807));
  10513. WFIFOW(fd,0) = 0x807;
  10514. WFIFOW(fd,2) = flag;
  10515. WFIFOSET(fd,packet_len(0x807));
  10516. }
  10517. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10518. /// 0808 { <job>.W }*6
  10519. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10520. {
  10521. short job[PARTY_BOOKING_JOBS];
  10522. int i;
  10523. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10524. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10525. job[i] = RFIFOW(fd,idxpbu+i*2);
  10526. party_booking_update(sd, job);
  10527. }
  10528. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10529. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10530. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10531. {
  10532. int i;
  10533. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10534. if(pb_ad == NULL) return;
  10535. WBUFW(buf,0) = 0x809;
  10536. WBUFL(buf,2) = pb_ad->index;
  10537. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10538. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10539. WBUFW(buf,34) = pb_ad->p_detail.level;
  10540. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10541. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10542. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10543. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10544. }
  10545. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10546. /// 080a <index>.L { <job>.W }*6
  10547. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10548. {
  10549. int i;
  10550. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10551. if(pb_ad == NULL) return;
  10552. WBUFW(buf,0) = 0x80a;
  10553. WBUFL(buf,2) = pb_ad->index;
  10554. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10555. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10556. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10557. }
  10558. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10559. /// 080b <index>.L
  10560. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10561. {
  10562. uint8 buf[6];
  10563. WBUFW(buf,0) = 0x80b;
  10564. WBUFL(buf,2) = index;
  10565. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10566. }
  10567. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10568. /// 012e
  10569. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10570. {
  10571. vending_closevending(sd);
  10572. }
  10573. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10574. /// 0130 <account id>.L
  10575. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10576. {
  10577. if( sd->npc_id ) {// using an NPC
  10578. return;
  10579. }
  10580. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10581. }
  10582. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10583. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10584. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10585. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10586. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10587. int id = (int)RFIFOL(fd,info->pos[1]);
  10588. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10589. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10590. // whether it fails or not, the buy window is closed
  10591. sd->vended_id = 0;
  10592. }
  10593. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10594. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10595. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10596. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10597. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10598. int aid = (int)RFIFOL(fd,info->pos[1]);
  10599. int uid = (int)RFIFOL(fd,info->pos[2]);
  10600. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10601. vending_purchasereq(sd, aid, uid, data, len/4);
  10602. // whether it fails or not, the buy window is closed
  10603. sd->vended_id = 0;
  10604. }
  10605. /// Confirm or cancel the shop preparation window.
  10606. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10607. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10608. /// result:
  10609. /// 0 = canceled
  10610. /// 1 = open
  10611. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10612. int cmd = RFIFOW(fd,0);
  10613. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10614. short len = (short)RFIFOW(fd,info->pos[0]);
  10615. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10616. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10617. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10618. len -= 84;
  10619. }
  10620. else { //(CZ_REQ_OPENSTORE2)
  10621. bool flag;
  10622. len -= 85;
  10623. flag = (bool)RFIFOB(fd,info->pos[2]);
  10624. if( !flag )
  10625. sd->state.prevend = 0;
  10626. }
  10627. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10628. return;
  10629. if( map[sd->bl.m].flag.novending ) {
  10630. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10631. return;
  10632. }
  10633. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10634. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10635. return;
  10636. }
  10637. if( message[0] == '\0' ) // invalid input
  10638. return;
  10639. vending_openvending(sd, message, data, len/8);
  10640. }
  10641. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10642. /// 0165 <char id>.L <guild name>.24B
  10643. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10644. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10645. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10646. name[NAME_LENGTH-1] = '\0';
  10647. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10648. clif_displaymessage(fd, msg_txt(sd,228));
  10649. return;
  10650. }
  10651. guild_create(sd, name);
  10652. }
  10653. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10654. /// 014d
  10655. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10656. {
  10657. clif_guild_masterormember(sd);
  10658. }
  10659. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10660. /// 014f <type>.L
  10661. /// type:
  10662. /// 0 = basic info
  10663. /// 1 = member manager
  10664. /// 2 = positions
  10665. /// 3 = skills
  10666. /// 4 = expulsion list
  10667. /// 5 = unknown (GM_ALLGUILDLIST)
  10668. /// 6 = notice
  10669. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10670. {
  10671. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10672. if( !sd->status.guild_id && !sd->bg_id )
  10673. return;
  10674. switch( type )
  10675. {
  10676. case 0: // Basic Information Guild, hostile alliance information
  10677. clif_guild_basicinfo(sd);
  10678. clif_guild_allianceinfo(sd);
  10679. break;
  10680. case 1: // Members list, list job title
  10681. clif_guild_positionnamelist(sd);
  10682. clif_guild_memberlist(sd);
  10683. break;
  10684. case 2: // List job title, title information list
  10685. clif_guild_positionnamelist(sd);
  10686. clif_guild_positioninfolist(sd);
  10687. break;
  10688. case 3: // Skill list
  10689. clif_guild_skillinfo(sd);
  10690. break;
  10691. case 4: // Expulsion list
  10692. clif_guild_expulsionlist(sd);
  10693. break;
  10694. default:
  10695. ShowError("clif: guild request info: unknown type %d\n", type);
  10696. break;
  10697. }
  10698. }
  10699. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10700. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10701. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10702. {
  10703. int i;
  10704. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10705. int len = RFIFOW(fd,info->pos[0]);
  10706. int idxgpos = info->pos[1];
  10707. if(!sd->state.gmaster_flag)
  10708. return;
  10709. for(i = idxgpos; i < len; i += 40 ){
  10710. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10711. }
  10712. }
  10713. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10714. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10715. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10716. {
  10717. int i;
  10718. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10719. int len = RFIFOW(fd,info->pos[0]);
  10720. int idxgpos = info->pos[1];
  10721. if(!sd->state.gmaster_flag)
  10722. return;
  10723. for(i=idxgpos;i<len;i+=12){
  10724. guild_change_memberposition(sd->status.guild_id,
  10725. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10726. }
  10727. }
  10728. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10729. /// 0151 <guild id>.L
  10730. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10731. {
  10732. struct guild* g;
  10733. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10734. if( (g = guild_search(guild_id)) != NULL )
  10735. clif_guild_emblem(sd,g);
  10736. }
  10737. /// Validates data of a guild emblem (compressed bitmap)
  10738. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10739. {
  10740. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10741. unsigned long buf_len = sizeof(buf);
  10742. int offset = 0;
  10743. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10744. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10745. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10746. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10747. ))
  10748. return -1;
  10749. if(battle_config.emblem_transparency_limit != 100) {
  10750. int i, transcount = 1, tmp[3];
  10751. for(i = offset; i < buf_len-1; i++) {
  10752. int j = i%3;
  10753. tmp[j] = RBUFL(buf,i);
  10754. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10755. transcount++;
  10756. }
  10757. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10758. return -2;
  10759. }
  10760. return 0;
  10761. }
  10762. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10763. /// 0153 <packet len>.W <emblem data>.?B
  10764. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10765. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10766. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10767. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10768. int emb_val=0;
  10769. if( !emblem_len || !sd->state.gmaster_flag )
  10770. return;
  10771. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10772. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10773. return;
  10774. }
  10775. emb_val = clif_validate_emblem(emblem, emblem_len);
  10776. if(emb_val ==-1 ){
  10777. 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);
  10778. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10779. return;
  10780. } else if(emb_val == -2){
  10781. char output[128];
  10782. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10783. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10784. return;
  10785. }
  10786. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10787. }
  10788. /// Guild notice update request (CZ_GUILD_NOTICE).
  10789. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10790. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10791. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10792. int guild_id = RFIFOL(fd,info->pos[0]);
  10793. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10794. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10795. if(!sd->state.gmaster_flag)
  10796. return;
  10797. // compensate for some client defects when using multilanguage mode
  10798. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10799. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10800. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10801. guild_change_notice(sd, guild_id, msg1, msg2);
  10802. }
  10803. // Helper function for guild invite functions
  10804. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10805. {
  10806. if (t_sd == NULL) // not online or does not exist
  10807. return 1;
  10808. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10809. clif_displaymessage(fd, msg_txt(sd,228));
  10810. return 1;
  10811. }
  10812. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10813. clif_noask_sub(sd, t_sd, 2);
  10814. return 1;
  10815. }
  10816. guild_invite(sd, t_sd);
  10817. return 0;
  10818. }
  10819. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10820. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10821. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10822. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10823. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10824. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10825. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10826. if (clif_sub_guild_invite(fd, sd, t_sd))
  10827. return;
  10828. }
  10829. /// Guild invite request (/guildinvite)
  10830. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10831. void
  10832. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10833. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10834. if (clif_sub_guild_invite(fd, sd, t_sd))
  10835. return;
  10836. }
  10837. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10838. /// 016b <guild id>.L <answer>.L
  10839. /// answer:
  10840. /// 0 = refuse
  10841. /// 1 = accept
  10842. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10843. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10844. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10845. RFIFOL(fd,info->pos[1]));
  10846. }
  10847. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10848. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10849. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10850. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10851. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10852. clif_displaymessage(fd, msg_txt(sd,228));
  10853. return;
  10854. }
  10855. if( sd->bg_id ) {
  10856. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10857. return;
  10858. }
  10859. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10860. RFIFOL(fd,info->pos[1]),
  10861. RFIFOL(fd,info->pos[2]),
  10862. (char*)RFIFOP(fd,info->pos[3]));
  10863. }
  10864. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10865. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10866. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10867. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10868. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10869. { // Guild locked.
  10870. clif_displaymessage(fd, msg_txt(sd,228));
  10871. return;
  10872. }
  10873. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10874. RFIFOL(fd,info->pos[1]),
  10875. RFIFOL(fd,info->pos[2]),
  10876. (char*)RFIFOP(fd,info->pos[3]));
  10877. }
  10878. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10879. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10880. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10881. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10882. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10883. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10884. char *name, *message;
  10885. int namelen, messagelen;
  10886. // validate packet and retrieve name and message
  10887. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10888. return;
  10889. if( is_atcommand(fd, sd, message, 1) )
  10890. return;
  10891. if (sd->sc.cant.chat)
  10892. return; //no "chatting" while muted.
  10893. if( battle_config.min_chat_delay )
  10894. { //[Skotlex]
  10895. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10896. return;
  10897. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10898. }
  10899. if (battle_config.idletime_option&IDLE_CHAT)
  10900. sd->idletime = last_tick;
  10901. if( sd->bg_id )
  10902. bg_send_message(sd, text, textlen);
  10903. else
  10904. guild_send_message(sd, text, textlen);
  10905. }
  10906. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10907. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10908. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10909. {
  10910. struct map_session_data *t_sd;
  10911. if(!sd->state.gmaster_flag)
  10912. return;
  10913. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10914. clif_displaymessage(fd, msg_txt(sd,228));
  10915. return;
  10916. }
  10917. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10918. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10919. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10920. // @noask [LuzZza]
  10921. if(t_sd && t_sd->state.noask) {
  10922. clif_noask_sub(sd, t_sd, 3);
  10923. return;
  10924. }
  10925. guild_reqalliance(sd,t_sd);
  10926. }
  10927. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10928. /// 0172 <inviter account id>.L <answer>.L
  10929. /// answer:
  10930. /// 0 = refuse
  10931. /// 1 = accept
  10932. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10933. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10934. guild_reply_reqalliance(sd,
  10935. RFIFOL(fd,info->pos[0]),
  10936. RFIFOL(fd,info->pos[1]));
  10937. }
  10938. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10939. /// 0183 <opponent guild id>.L <relation>.L
  10940. /// relation:
  10941. /// 0 = Ally
  10942. /// 1 = Enemy
  10943. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10944. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10945. if(!sd->state.gmaster_flag)
  10946. return;
  10947. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10948. clif_displaymessage(fd, msg_txt(sd,228));
  10949. return;
  10950. }
  10951. guild_delalliance(sd,
  10952. RFIFOL(fd,info->pos[0]),
  10953. RFIFOL(fd,info->pos[1]));
  10954. }
  10955. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10956. /// 0180 <account id>.L
  10957. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10958. {
  10959. struct map_session_data *t_sd;
  10960. if(!sd->state.gmaster_flag)
  10961. return;
  10962. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10963. clif_displaymessage(fd, msg_txt(sd,228));
  10964. return;
  10965. }
  10966. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10967. // @noask [LuzZza]
  10968. if(t_sd && t_sd->state.noask) {
  10969. clif_noask_sub(sd, t_sd, 4);
  10970. return;
  10971. }
  10972. guild_opposition(sd,t_sd);
  10973. }
  10974. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10975. /// 015d <key>.40B
  10976. /// key:
  10977. /// now guild name; might have been (intended) email, since the
  10978. /// field name and size is same as the one in CH_DELETE_CHAR.
  10979. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10980. {
  10981. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10982. clif_displaymessage(fd, msg_txt(sd,228));
  10983. return;
  10984. }
  10985. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10986. }
  10987. /// Pet
  10988. ///
  10989. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10990. /// 01a1 <type>.B
  10991. /// type:
  10992. /// 0 = pet information
  10993. /// 1 = feed
  10994. /// 2 = performance
  10995. /// 3 = return to egg
  10996. /// 4 = unequip accessory
  10997. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  10998. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10999. }
  11000. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11001. /// 019f <id>.L
  11002. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11003. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11004. }
  11005. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11006. /// 01a7 <index>.W
  11007. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11008. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11009. return;
  11010. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11011. clif_menuskill_clear(sd);
  11012. }
  11013. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11014. /// 01a9 <data>.L
  11015. /// data:
  11016. /// is either emotion (@see enum emotion_type) or a compound value
  11017. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11018. /// entry (given in parentheses) in data\pettalktable.xml
  11019. /// act id:
  11020. /// 0 = feeding
  11021. /// 1 = hunting
  11022. /// 2 = danger
  11023. /// 3 = dead
  11024. /// 4 = normal (stand)
  11025. /// 5 = special performance (perfor_s)
  11026. /// 6 = level up (levelup)
  11027. /// 7 = performance 1 (perfor_1)
  11028. /// 8 = performance 2 (perfor_2)
  11029. /// 9 = performance 3 (perfor_3)
  11030. /// 10 = log-in greeting (connect)
  11031. /// hungry value:
  11032. /// 0 = very hungry (hungry)
  11033. /// 1 = hungry (bit_hungry)
  11034. /// 2 = satisfied (noting)
  11035. /// 3 = stuffed (full)
  11036. /// 4 = full (so_full)
  11037. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11038. {
  11039. if(sd->pd)
  11040. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11041. }
  11042. /// Request to change pet's name (CZ_RENAME_PET).
  11043. /// 01a5 <name>.24B
  11044. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11045. {
  11046. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11047. }
  11048. /// /kill (CZ_DISCONNECT_CHARACTER).
  11049. /// Request to disconnect a character.
  11050. /// 00cc <account id>.L
  11051. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11052. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11053. {
  11054. struct block_list *target;
  11055. int tid;
  11056. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11057. target = map_id2bl(tid);
  11058. if (!target) {
  11059. clif_GM_kickack(sd, 0);
  11060. return;
  11061. }
  11062. switch (target->type) {
  11063. case BL_PC:
  11064. {
  11065. char command[NAME_LENGTH+6];
  11066. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11067. is_atcommand(fd, sd, command, 1);
  11068. }
  11069. break;
  11070. /**
  11071. * This one does not invoke any atcommand, so we need to check for permissions.
  11072. */
  11073. case BL_MOB:
  11074. {
  11075. char command[100];
  11076. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11077. clif_GM_kickack(sd, 0);
  11078. return;
  11079. }
  11080. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11081. log_atcommand(sd, command);
  11082. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11083. }
  11084. break;
  11085. case BL_NPC:
  11086. {
  11087. struct npc_data* nd = (struct npc_data *)target;
  11088. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11089. npc_unload_duplicates(nd);
  11090. npc_unload(nd,true);
  11091. npc_read_event_script();
  11092. }
  11093. }
  11094. break;
  11095. default:
  11096. clif_GM_kickack(sd, 0);
  11097. }
  11098. }
  11099. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11100. /// Request to disconnect all characters.
  11101. /// 00ce
  11102. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11103. char cmd[15];
  11104. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11105. is_atcommand(fd, sd, cmd, 1);
  11106. }
  11107. /// /remove (CZ_REMOVE_AID).
  11108. /// Request to warp to a character with given login ID.
  11109. /// 01ba <account name>.24B
  11110. /// /shift (CZ_SHIFT).
  11111. /// Request to warp to a character with given name.
  11112. /// 01bb <char name>.24B
  11113. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11114. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11115. char *player_name;
  11116. char command[NAME_LENGTH+8];
  11117. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11118. player_name[NAME_LENGTH-1] = '\0';
  11119. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11120. is_atcommand(fd, sd, command, 1);
  11121. }
  11122. /// /remove (CZ_REMOVE_AID_SSO).
  11123. /// Request to warp to a character with given account ID.
  11124. /// 0843 <account id>.L
  11125. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11126. {
  11127. int account_id;
  11128. struct map_session_data* pl_sd;
  11129. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11130. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11131. char command[NAME_LENGTH+8];
  11132. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11133. is_atcommand(fd, sd, command, 1);
  11134. }
  11135. }
  11136. /// /recall (CZ_RECALL).
  11137. /// Request to summon a player with given login ID to own position.
  11138. /// 01bc <account name>.24B
  11139. /// /summon (CZ_RECALL_GID).
  11140. /// Request to summon a player with given name to own position.
  11141. /// 01bd <char name>.24B
  11142. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11143. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11144. char *player_name;
  11145. char command [NAME_LENGTH+8];
  11146. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11147. player_name[NAME_LENGTH-1] = '\0';
  11148. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11149. is_atcommand(fd, sd, command, 1);
  11150. }
  11151. /// /recall (CZ_RECALL_SSO).
  11152. /// Request to summon a player with given account ID to own position.
  11153. /// 0842 <account id>.L
  11154. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11155. {
  11156. int account_id;
  11157. struct map_session_data* pl_sd;
  11158. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11159. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11160. char command[NAME_LENGTH+8];
  11161. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11162. is_atcommand(fd, sd, command, 1);
  11163. }
  11164. }
  11165. /// /item /monster (CZ_ITEM_CREATE).
  11166. /// Request to execute GM commands.
  11167. /// Usage:
  11168. /// /item n - summon n monster or acquire n item/s
  11169. /// /item money - grants 2147483647 zenies
  11170. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11171. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11172. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11173. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11174. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11175. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11176. /// 013f <item/mob name>.24B
  11177. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11178. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11179. {
  11180. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11181. int mob_id = 0;
  11182. struct item_data *id = NULL;
  11183. struct mob_db *mob = NULL;
  11184. StringBuf command;
  11185. char *str;
  11186. //#if PACKETVER >= 20131218
  11187. // char str[100];
  11188. //#else
  11189. // char str[24];
  11190. //#endif
  11191. str = (char*)RFIFOP(fd,info->pos[0]);
  11192. if (!str || str[0] == '\0')
  11193. return;
  11194. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11195. return;
  11196. trim(str);
  11197. // Zeny
  11198. if( strcmpi(str, "money") == 0 ) {
  11199. StringBuf_Init(&command);
  11200. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11201. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11202. StringBuf_Destroy(&command);
  11203. return;
  11204. }
  11205. // Item
  11206. if( (id = itemdb_searchname(str)) ) {
  11207. StringBuf_Init(&command);
  11208. if( id->type == IT_WEAPON || id->type == IT_ARMOR ) //Nonstackable
  11209. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11210. else
  11211. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11212. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11213. StringBuf_Destroy(&command);
  11214. return;
  11215. }
  11216. // Monster
  11217. if ((mob_id = mobdb_searchname(str)) == 0)
  11218. mob_id = mobdb_checkid(atoi(str));
  11219. if( (mob = mob_db(mob_id)) ) {
  11220. StringBuf_Init(&command);
  11221. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11222. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11223. StringBuf_Destroy(&command);
  11224. return;
  11225. }
  11226. }
  11227. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11228. /// 019d <effect state>.L
  11229. /// effect state:
  11230. /// TODO: Any OPTION_* ?
  11231. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11232. char cmd[6];
  11233. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11234. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11235. is_atcommand(fd, sd, cmd, 1);
  11236. }
  11237. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11238. /// 0149 <account id>.L <type>.B <value>.W
  11239. /// type:
  11240. /// 0 = positive points
  11241. /// 1 = negative points
  11242. /// 2 = self mute (+10 minutes)
  11243. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11244. {
  11245. int id, type, value;
  11246. struct map_session_data *dstsd;
  11247. char command[NAME_LENGTH+15];
  11248. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11249. id = RFIFOL(fd,info->pos[0]);
  11250. type = RFIFOB(fd,info->pos[1]);
  11251. value = RFIFOW(fd,info->pos[2]);
  11252. if( type == 0 )
  11253. value = -value;
  11254. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11255. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11256. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11257. return;
  11258. dstsd = map_id2sd(id);
  11259. if( dstsd == NULL )
  11260. return;
  11261. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11262. is_atcommand(fd, sd, command, 1);
  11263. }
  11264. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11265. /// GM adjustment of a player's manner value by -60.
  11266. /// 0212 <char name>.24B
  11267. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11268. {
  11269. char command[NAME_LENGTH+15];
  11270. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11271. name[NAME_LENGTH-1] = '\0';
  11272. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11273. is_atcommand(fd, sd, command, 1);
  11274. }
  11275. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11276. /// 01e0 <account id>.L <account name>.24B
  11277. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  11278. {
  11279. int fd = sd->fd;
  11280. WFIFOHEAD(fd,packet_len(0x1e0));
  11281. WFIFOW(fd,0) = 0x1e0;
  11282. WFIFOL(fd,2) = account_id;
  11283. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11284. WFIFOSET(fd,packet_len(0x1e0));
  11285. }
  11286. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11287. /// 01df <account id>.L
  11288. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11289. {
  11290. if (sd->bl.type&BL_PC) { // Only show for players
  11291. char command[30];
  11292. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11293. //tmp get all display
  11294. safesnprintf(command,sizeof(command),"%caccinfo %d", atcommand_symbol, account_id);
  11295. is_atcommand(fd, sd, command, 1);
  11296. //clif_account_name(sd, account_id, ""); //! TODO request to login-serv
  11297. }
  11298. }
  11299. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11300. /// GM single cell type change request.
  11301. /// 0198 <x>.W <y>.W <type>.W
  11302. /// type:
  11303. /// 0 = not walkable
  11304. /// 1 = walkable
  11305. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11306. {
  11307. int x,y,type;
  11308. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11309. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11310. return;
  11311. x = RFIFOW(fd,info->pos[0]);
  11312. y = RFIFOW(fd,info->pos[1]);
  11313. type = RFIFOW(fd,info->pos[2]);
  11314. map_setgatcell(sd->bl.m,x,y,type);
  11315. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11316. //FIXME: once players leave the map, the client 'forgets' this information.
  11317. }
  11318. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11319. /// Request to allow/deny whispers from a nick.
  11320. /// 00cf <nick>.24B <type>.B
  11321. /// type:
  11322. /// 0 = (/ex nick) deny speech from nick
  11323. /// 1 = (/in nick) allow speech from nick
  11324. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11325. {
  11326. char* nick;
  11327. uint8 type;
  11328. int i;
  11329. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11330. nick = (char*)RFIFOP(fd,info->pos[0]);
  11331. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11332. type = RFIFOB(fd,info->pos[1]);
  11333. if( type == 0 ) { // Add name to ignore list (block)
  11334. if (strcmp(wisp_server_name, nick) == 0) {
  11335. clif_wisexin(sd, type, 1); // fail
  11336. return;
  11337. }
  11338. // try to find a free spot, while checking for duplicates at the same time
  11339. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11340. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11341. clif_wisexin(sd, type, 2); // too many blocks
  11342. return;
  11343. }
  11344. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11345. clif_wisexin(sd, type, 0); // Aegis reports success.
  11346. return;
  11347. }
  11348. //Insert in position i
  11349. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11350. } else { // Remove name from ignore list (unblock)
  11351. // find entry
  11352. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11353. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11354. clif_wisexin(sd, type, 1); // fail
  11355. return;
  11356. }
  11357. // move everything one place down to overwrite removed entry
  11358. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11359. // wipe last entry
  11360. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11361. }
  11362. clif_wisexin(sd, type, 0); // success
  11363. }
  11364. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11365. /// Request to allow/deny all whispers.
  11366. /// 00d0 <type>.B
  11367. /// type:
  11368. /// 0 = (/exall) deny all speech
  11369. /// 1 = (/inall) allow all speech
  11370. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11371. {
  11372. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11373. if( type == 0 ) {// Deny all
  11374. if( sd->state.ignoreAll ) {
  11375. flag = 1; // fail
  11376. } else {
  11377. sd->state.ignoreAll = 1;
  11378. flag = 0; // success
  11379. }
  11380. } else {//Unblock everyone
  11381. if( sd->state.ignoreAll ) {
  11382. sd->state.ignoreAll = 0;
  11383. flag = 0; // success
  11384. } else {
  11385. if (sd->ignore[0].name[0] != '\0')
  11386. { //Wipe the ignore list.
  11387. memset(sd->ignore, 0, sizeof(sd->ignore));
  11388. flag = 0; // success
  11389. } else {
  11390. flag = 1; // fail
  11391. }
  11392. }
  11393. }
  11394. clif_wisall(sd, type, flag);
  11395. }
  11396. /// Whisper ignore list (ZC_WHISPER_LIST).
  11397. /// 00d4 <packet len>.W { <char name>.24B }*
  11398. void clif_PMIgnoreList(struct map_session_data* sd)
  11399. {
  11400. int i, fd = sd->fd;
  11401. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11402. WFIFOW(fd,0) = 0xd4;
  11403. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11404. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11405. }
  11406. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11407. WFIFOSET(fd,WFIFOW(fd,2));
  11408. }
  11409. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11410. /// 00d3
  11411. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11412. {
  11413. clif_PMIgnoreList(sd);
  11414. }
  11415. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11416. /// 01e7
  11417. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11418. {
  11419. if (sd->state.doridori) return;
  11420. switch (sd->class_&MAPID_UPPERMASK) {
  11421. case MAPID_SOUL_LINKER:
  11422. case MAPID_STAR_GLADIATOR:
  11423. case MAPID_TAEKWON:
  11424. if (!sd->state.rest)
  11425. break;
  11426. case MAPID_SUPER_NOVICE:
  11427. sd->state.doridori=1;
  11428. break;
  11429. }
  11430. }
  11431. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11432. /// 01ed
  11433. /// Note: This packet is caused by 7 lines of any text, followed by
  11434. /// the prayer and an another line of any text. The prayer is
  11435. /// defined by lines 790~793 in data\msgstringtable.txt
  11436. /// "Dear angel, can you hear my voice?"
  11437. /// "I am" (space separated player name) "Super Novice~"
  11438. /// "Help me out~ Please~ T_T"
  11439. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11440. {
  11441. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  11442. unsigned int next = pc_nextbaseexp(sd);
  11443. if( next == 0 ) next = pc_thisbaseexp(sd);
  11444. if( next ) {
  11445. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11446. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11447. 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]
  11448. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11449. }
  11450. }
  11451. }
  11452. }
  11453. /// Friends List
  11454. ///
  11455. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11456. /// 0206 <account id>.L <char id>.L <state>.B
  11457. /// state:
  11458. /// 0 = online
  11459. /// 1 = offline
  11460. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  11461. {
  11462. int i, fd = sd->fd;
  11463. //Seek friend.
  11464. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11465. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11466. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11467. return; //Not found
  11468. WFIFOHEAD(fd,packet_len(0x206));
  11469. WFIFOW(fd, 0) = 0x206;
  11470. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11471. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11472. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11473. WFIFOSET(fd, packet_len(0x206));
  11474. }
  11475. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11476. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11477. {
  11478. int account_id, char_id, online;
  11479. account_id = va_arg(ap, int);
  11480. char_id = va_arg(ap, int);
  11481. online = va_arg(ap, int);
  11482. clif_friendslist_toggle(sd, account_id, char_id, online);
  11483. return 0;
  11484. }
  11485. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11486. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11487. void clif_friendslist_send(struct map_session_data *sd)
  11488. {
  11489. int i = 0, n, fd = sd->fd;
  11490. // Send friends list
  11491. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11492. WFIFOW(fd, 0) = 0x201;
  11493. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11494. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11495. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11496. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11497. }
  11498. if (i) {
  11499. WFIFOW(fd,2) = 4 + 32 * i;
  11500. WFIFOSET(fd, WFIFOW(fd,2));
  11501. }
  11502. for (n = 0; n < i; n++) { //Sending the online players
  11503. if (map_charid2sd(sd->status.friends[n].char_id))
  11504. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11505. }
  11506. }
  11507. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11508. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11509. /// result:
  11510. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11511. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11512. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11513. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11514. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11515. {
  11516. int fd;
  11517. nullpo_retv(sd);
  11518. fd = sd->fd;
  11519. WFIFOHEAD(fd,packet_len(0x209));
  11520. WFIFOW(fd,0) = 0x209;
  11521. WFIFOW(fd,2) = type;
  11522. if (f_sd) {
  11523. WFIFOL(fd,4) = f_sd->status.account_id;
  11524. WFIFOL(fd,8) = f_sd->status.char_id;
  11525. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11526. }
  11527. WFIFOSET(fd, packet_len(0x209));
  11528. }
  11529. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11530. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11531. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  11532. {
  11533. int fd = sd->fd;
  11534. WFIFOHEAD(fd,packet_len(0x207));
  11535. WFIFOW(fd,0) = 0x207;
  11536. WFIFOL(fd,2) = account_id;
  11537. WFIFOL(fd,6) = char_id;
  11538. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11539. WFIFOSET(fd,packet_len(0x207));
  11540. }
  11541. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11542. /// 0202 <name>.24B
  11543. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11544. {
  11545. struct map_session_data *f_sd;
  11546. int i;
  11547. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11548. // ensure that the request player's friend list is not full
  11549. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11550. if( i == MAX_FRIENDS ) {
  11551. clif_friendslist_reqack(sd, f_sd, 2);
  11552. return;
  11553. }
  11554. // Friend doesn't exist (no player with this name)
  11555. if (f_sd == NULL) {
  11556. clif_displaymessage(fd, msg_txt(sd,3));
  11557. return;
  11558. }
  11559. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11560. return;
  11561. }
  11562. // @noask [LuzZza]
  11563. if(f_sd->state.noask) {
  11564. clif_noask_sub(sd, f_sd, 5);
  11565. return;
  11566. }
  11567. // Friend already exists
  11568. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11569. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11570. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11571. return;
  11572. }
  11573. }
  11574. f_sd->friend_req = sd->status.char_id;
  11575. sd->friend_req = f_sd->status.char_id;
  11576. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11577. }
  11578. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11579. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11580. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11581. /// reply:
  11582. /// 0 = rejected
  11583. /// 1 = accepted
  11584. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11585. {
  11586. struct map_session_data *f_sd;
  11587. int account_id;
  11588. char reply;
  11589. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11590. account_id = RFIFOL(fd,info->pos[0]);
  11591. //char_id = RFIFOL(fd,info->pos[1]);
  11592. if(sd->packet_ver < 6)
  11593. reply = RFIFOB(fd,info->pos[2]);
  11594. else
  11595. reply = RFIFOL(fd,info->pos[2]);
  11596. if( sd->bl.id == account_id ) {// adding oneself as friend
  11597. return;
  11598. }
  11599. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11600. if (f_sd == NULL)
  11601. return;
  11602. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11603. clif_friendslist_reqack(f_sd, sd, 1);
  11604. else {
  11605. int i;
  11606. // Find an empty slot
  11607. for (i = 0; i < MAX_FRIENDS; i++)
  11608. if (f_sd->status.friends[i].char_id == 0)
  11609. break;
  11610. if (i == MAX_FRIENDS) {
  11611. clif_friendslist_reqack(f_sd, sd, 2);
  11612. return;
  11613. }
  11614. f_sd->status.friends[i].account_id = sd->status.account_id;
  11615. f_sd->status.friends[i].char_id = sd->status.char_id;
  11616. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11617. clif_friendslist_reqack(f_sd, sd, 0);
  11618. if (battle_config.friend_auto_add) {
  11619. // Also add f_sd to sd's friendlist.
  11620. for (i = 0; i < MAX_FRIENDS; i++) {
  11621. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11622. return; //No need to add anything.
  11623. if (sd->status.friends[i].char_id == 0)
  11624. break;
  11625. }
  11626. if (i == MAX_FRIENDS) {
  11627. clif_friendslist_reqack(sd, f_sd, 2);
  11628. return;
  11629. }
  11630. sd->status.friends[i].account_id = f_sd->status.account_id;
  11631. sd->status.friends[i].char_id = f_sd->status.char_id;
  11632. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11633. clif_friendslist_reqack(sd, f_sd, 0);
  11634. }
  11635. }
  11636. }
  11637. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11638. /// 0203 <account id>.L <char id>.L
  11639. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11640. {
  11641. struct map_session_data *f_sd = NULL;
  11642. int account_id, char_id;
  11643. int i, j;
  11644. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11645. account_id = RFIFOL(fd,info->pos[0]);
  11646. char_id = RFIFOL(fd,info->pos[1]);
  11647. // Search friend
  11648. for (i = 0; i < MAX_FRIENDS &&
  11649. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11650. if (i == MAX_FRIENDS) {
  11651. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11652. return;
  11653. }
  11654. //remove from friend's list first
  11655. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11656. for (i = 0; i < MAX_FRIENDS &&
  11657. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11658. if (i != MAX_FRIENDS) {
  11659. // move all chars up
  11660. for(j = i + 1; j < MAX_FRIENDS; j++)
  11661. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11662. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11663. //should the guy be notified of some message? we should add it here if so
  11664. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11665. WFIFOW(f_sd->fd,0) = 0x20a;
  11666. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11667. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11668. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11669. }
  11670. } else { //friend not online -- ask char server to delete from his friendlist
  11671. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11672. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11673. return;
  11674. }
  11675. }
  11676. // We can now delete from original requester
  11677. for (i = 0; i < MAX_FRIENDS &&
  11678. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11679. // move all chars up
  11680. for(j = i + 1; j < MAX_FRIENDS; j++)
  11681. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11682. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11683. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11684. WFIFOHEAD(fd,packet_len(0x20a));
  11685. WFIFOW(fd,0) = 0x20a;
  11686. WFIFOL(fd,2) = account_id;
  11687. WFIFOL(fd,6) = char_id;
  11688. WFIFOSET(fd, packet_len(0x20a));
  11689. }
  11690. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11691. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11692. void clif_PVPInfo(struct map_session_data* sd)
  11693. {
  11694. int fd = sd->fd;
  11695. WFIFOHEAD(fd,packet_len(0x210));
  11696. WFIFOW(fd,0) = 0x210;
  11697. WFIFOL(fd,2) = sd->status.char_id;
  11698. WFIFOL(fd,6) = sd->status.account_id;
  11699. WFIFOL(fd,10) = sd->pvp_won; // times won
  11700. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11701. WFIFOL(fd,18) = sd->pvp_point;
  11702. WFIFOSET(fd, packet_len(0x210));
  11703. }
  11704. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11705. /// 020f <char id>.L <account id>.L
  11706. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11707. {
  11708. // TODO: Is there a way to use this on an another player (char/acc id)?
  11709. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11710. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11711. clif_PVPInfo(sd);
  11712. }
  11713. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11714. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11715. void clif_blacksmith(struct map_session_data* sd)
  11716. {
  11717. int i, fd = sd->fd;
  11718. const char* name;
  11719. WFIFOHEAD(fd,packet_len(0x219));
  11720. WFIFOW(fd,0) = 0x219;
  11721. //Packet size limits this list to 10 elements. [Skotlex]
  11722. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11723. if (smith_fame_list[i].id > 0) {
  11724. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11725. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11726. {
  11727. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11728. } else
  11729. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11730. } else
  11731. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11732. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11733. }
  11734. for(;i < 10; i++) { //In case the MAX is less than 10.
  11735. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11736. WFIFOL(fd, 242 + i * 4) = 0;
  11737. }
  11738. WFIFOSET(fd, packet_len(0x219));
  11739. }
  11740. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11741. /// 0217
  11742. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11743. {
  11744. clif_blacksmith(sd);
  11745. }
  11746. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11747. /// 021b <points>.L <total points>.L
  11748. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11749. {
  11750. int fd = sd->fd;
  11751. WFIFOHEAD(fd,packet_len(0x21b));
  11752. WFIFOW(fd,0) = 0x21b;
  11753. WFIFOL(fd,2) = points;
  11754. WFIFOL(fd,6) = sd->status.fame;
  11755. WFIFOSET(fd, packet_len(0x21b));
  11756. }
  11757. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11758. /// 021a { <name>.24B }*10 { <point>.L }*10
  11759. void clif_alchemist(struct map_session_data* sd)
  11760. {
  11761. int i, fd = sd->fd;
  11762. const char* name;
  11763. WFIFOHEAD(fd,packet_len(0x21a));
  11764. WFIFOW(fd,0) = 0x21a;
  11765. //Packet size limits this list to 10 elements. [Skotlex]
  11766. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11767. if (chemist_fame_list[i].id > 0) {
  11768. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11769. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11770. {
  11771. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11772. } else
  11773. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11774. } else
  11775. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11776. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11777. }
  11778. for(;i < 10; i++) { //In case the MAX is less than 10.
  11779. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11780. WFIFOL(fd, 242 + i * 4) = 0;
  11781. }
  11782. WFIFOSET(fd, packet_len(0x21a));
  11783. }
  11784. /// /alchemist (CZ_ALCHEMIST_RANK).
  11785. /// 0218
  11786. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11787. {
  11788. clif_alchemist(sd);
  11789. }
  11790. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11791. /// 021c <points>.L <total points>.L
  11792. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11793. {
  11794. int fd = sd->fd;
  11795. WFIFOHEAD(fd,packet_len(0x21c));
  11796. WFIFOW(fd,0) = 0x21c;
  11797. WFIFOL(fd,2) = points;
  11798. WFIFOL(fd,6) = sd->status.fame;
  11799. WFIFOSET(fd, packet_len(0x21c));
  11800. }
  11801. /// /taekwon list (ZC_TAEKWON_RANK).
  11802. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11803. void clif_taekwon(struct map_session_data* sd)
  11804. {
  11805. int i, fd = sd->fd;
  11806. const char* name;
  11807. WFIFOHEAD(fd,packet_len(0x226));
  11808. WFIFOW(fd,0) = 0x226;
  11809. //Packet size limits this list to 10 elements. [Skotlex]
  11810. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11811. if (taekwon_fame_list[i].id > 0) {
  11812. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11813. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11814. {
  11815. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11816. } else
  11817. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11818. } else
  11819. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11820. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11821. }
  11822. for(;i < 10; i++) { //In case the MAX is less than 10.
  11823. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11824. WFIFOL(fd, 242 + i * 4) = 0;
  11825. }
  11826. WFIFOSET(fd, packet_len(0x226));
  11827. }
  11828. /// /taekwon (CZ_TAEKWON_RANK).
  11829. /// 0225
  11830. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11831. {
  11832. clif_taekwon(sd);
  11833. }
  11834. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11835. /// 0224 <points>.L <total points>.L
  11836. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11837. {
  11838. int fd = sd->fd;
  11839. WFIFOHEAD(fd,packet_len(0x224));
  11840. WFIFOW(fd,0) = 0x224;
  11841. WFIFOL(fd,2) = points;
  11842. WFIFOL(fd,6) = sd->status.fame;
  11843. WFIFOSET(fd, packet_len(0x224));
  11844. }
  11845. /// /pk list (ZC_KILLER_RANK).
  11846. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11847. void clif_ranking_pk(struct map_session_data* sd)
  11848. {
  11849. int i, fd = sd->fd;
  11850. WFIFOHEAD(fd,packet_len(0x238));
  11851. WFIFOW(fd,0) = 0x238;
  11852. for(i=0;i<10;i++){
  11853. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11854. WFIFOL(fd,i*4+242) = 0;
  11855. }
  11856. WFIFOSET(fd, packet_len(0x238));
  11857. }
  11858. /// /pk (CZ_KILLER_RANK).
  11859. /// 0237
  11860. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11861. {
  11862. clif_ranking_pk(sd);
  11863. }
  11864. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11865. /// 0254 <which>.B
  11866. /// which: (unused atm for security purpose)
  11867. /// 0 = sun
  11868. /// 1 = moon
  11869. /// 2 = star
  11870. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11871. {
  11872. int i;
  11873. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11874. if (sd->menuskill_id != SG_FEEL)
  11875. return;
  11876. i = sd->menuskill_val-1;
  11877. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11878. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11879. sd->feel_map[i].m = sd->bl.m;
  11880. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11881. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11882. // clif_misceffect2(&sd->bl, 0x1b0);
  11883. // clif_misceffect2(&sd->bl, 0x21f);
  11884. clif_feel_info(sd, i, 0);
  11885. clif_menuskill_clear(sd);
  11886. }
  11887. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11888. /// 0253 <which>.B
  11889. /// which:
  11890. /// 0 = sun
  11891. /// 1 = moon
  11892. /// 2 = star
  11893. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11894. {
  11895. WFIFOHEAD(fd,packet_len(0x253));
  11896. WFIFOW(fd,0)=0x253;
  11897. WFIFOB(fd,2)=TOB(skill_lv-1);
  11898. WFIFOSET(fd, packet_len(0x253));
  11899. sd->menuskill_id = SG_FEEL;
  11900. sd->menuskill_val = skill_lv;
  11901. }
  11902. /// Request to change homunculus' name (CZ_RENAME_MER).
  11903. /// 0231 <name>.24B
  11904. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11905. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11906. }
  11907. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11908. /// 0234 <id>.L
  11909. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11910. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11911. struct block_list *bl = NULL;
  11912. struct unit_data *ud = NULL;
  11913. if( sd->md && sd->md->bl.id == id )
  11914. bl = &sd->md->bl;
  11915. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11916. bl = &sd->hd->bl; // Moving Homunculus
  11917. else
  11918. return;
  11919. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11920. ud = unit_bl2ud(bl);
  11921. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11922. }
  11923. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11924. /// 0232 <id>.L <position data>.3B
  11925. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11926. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11927. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11928. struct block_list *bl = NULL;
  11929. short x, y;
  11930. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11931. if( sd->md && sd->md->bl.id == id )
  11932. bl = &sd->md->bl; // Moving Mercenary
  11933. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11934. bl = &sd->hd->bl; // Moving Homunculus
  11935. else
  11936. return;
  11937. unit_walktoxy(bl, x, y, 4);
  11938. }
  11939. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11940. /// 0233 <id>.L <target id>.L <action>.B
  11941. /// action:
  11942. /// always 0
  11943. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11944. {
  11945. struct block_list *bl = NULL;
  11946. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11947. int id = RFIFOL(fd,info->pos[0]);
  11948. int target_id = RFIFOL(fd,info->pos[1]);
  11949. int action_type = RFIFOB(fd,info->pos[2]);
  11950. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11951. bl = &sd->hd->bl;
  11952. else if( sd->md && sd->md->bl.id == id )
  11953. bl = &sd->md->bl;
  11954. else return;
  11955. unit_stop_attack(bl);
  11956. unit_attack(bl, target_id, action_type != 0);
  11957. }
  11958. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11959. /// 022d <type>.W <command>.B
  11960. /// type:
  11961. /// always 0
  11962. /// command:
  11963. /// 0 = homunculus information
  11964. /// 1 = feed
  11965. /// 2 = delete
  11966. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11967. { //[orn]
  11968. int cmd = RFIFOW(fd,0);
  11969. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11970. if(!hom_is_active(sd->hd))
  11971. return;
  11972. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11973. }
  11974. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11975. /// 0292
  11976. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11977. {
  11978. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11979. int hpsp = 100;
  11980. if (item_position < 0) {
  11981. if (sd->sc.data[SC_LIGHT_OF_REGENE])
  11982. hpsp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  11983. else
  11984. return;
  11985. }
  11986. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11987. return;
  11988. if (!status_revive(&sd->bl, hpsp, hpsp))
  11989. return;
  11990. if (item_position < 0)
  11991. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  11992. else
  11993. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11994. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  11995. }
  11996. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11997. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11998. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11999. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12000. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12001. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12002. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12003. void clif_check(int fd, struct map_session_data* pl_sd)
  12004. {
  12005. WFIFOHEAD(fd,packet_len(0x214));
  12006. WFIFOW(fd, 0) = 0x214;
  12007. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12008. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12009. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12010. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12011. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12012. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12013. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12014. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12015. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12016. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12017. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12018. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12019. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12020. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12021. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12022. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12023. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12024. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12025. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12026. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12027. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12028. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12029. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12030. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12031. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12032. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12033. WFIFOSET(fd,packet_len(0x214));
  12034. }
  12035. /// /check (CZ_REQ_STATUS_GM).
  12036. /// Request character's status values.
  12037. /// 0213 <char name>.24B
  12038. void clif_parse_Check(int fd, struct map_session_data *sd)
  12039. {
  12040. char charname[NAME_LENGTH];
  12041. struct map_session_data* pl_sd;
  12042. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12043. return;
  12044. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12045. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12046. {
  12047. return;
  12048. }
  12049. clif_check(fd, pl_sd);
  12050. }
  12051. /// MAIL SYSTEM
  12052. /// By Zephyrus
  12053. ///
  12054. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12055. /// 0255 <index>.W <result>.B
  12056. /// result:
  12057. /// 0 = success
  12058. /// 1 = failure
  12059. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12060. {
  12061. WFIFOHEAD(fd,packet_len(0x255));
  12062. WFIFOW(fd,0) = 0x255;
  12063. WFIFOW(fd,2) = index;
  12064. WFIFOB(fd,4) = flag;
  12065. WFIFOSET(fd,packet_len(0x255));
  12066. }
  12067. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12068. /// 0245 <result>.B
  12069. /// result:
  12070. /// 0 = success
  12071. /// 1 = failure
  12072. /// 2 = too many items
  12073. void clif_Mail_getattachment(int fd, uint8 flag)
  12074. {
  12075. WFIFOHEAD(fd,packet_len(0x245));
  12076. WFIFOW(fd,0) = 0x245;
  12077. WFIFOB(fd,2) = flag;
  12078. WFIFOSET(fd,packet_len(0x245));
  12079. }
  12080. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12081. /// 0249 <result>.B
  12082. /// result:
  12083. /// 0 = success
  12084. /// 1 = recipinent does not exist
  12085. void clif_Mail_send(int fd, bool fail)
  12086. {
  12087. WFIFOHEAD(fd,packet_len(0x249));
  12088. WFIFOW(fd,0) = 0x249;
  12089. WFIFOB(fd,2) = fail;
  12090. WFIFOSET(fd,packet_len(0x249));
  12091. }
  12092. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12093. /// 0257 <mail id>.L <result>.W
  12094. /// result:
  12095. /// 0 = success
  12096. /// 1 = failure
  12097. void clif_Mail_delete(int fd, int mail_id, short fail)
  12098. {
  12099. WFIFOHEAD(fd, packet_len(0x257));
  12100. WFIFOW(fd,0) = 0x257;
  12101. WFIFOL(fd,2) = mail_id;
  12102. WFIFOW(fd,6) = fail;
  12103. WFIFOSET(fd, packet_len(0x257));
  12104. }
  12105. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12106. /// 0274 <mail id>.L <result>.W
  12107. /// result:
  12108. /// 0 = success
  12109. /// 1 = failure
  12110. void clif_Mail_return(int fd, int mail_id, short fail)
  12111. {
  12112. WFIFOHEAD(fd,packet_len(0x274));
  12113. WFIFOW(fd,0) = 0x274;
  12114. WFIFOL(fd,2) = mail_id;
  12115. WFIFOW(fd,6) = fail;
  12116. WFIFOSET(fd,packet_len(0x274));
  12117. }
  12118. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12119. /// 024a <mail id>.L <title>.40B <sender>.24B
  12120. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12121. {
  12122. WFIFOHEAD(fd,packet_len(0x24a));
  12123. WFIFOW(fd,0) = 0x24a;
  12124. WFIFOL(fd,2) = mail_id;
  12125. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12126. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12127. WFIFOSET(fd,packet_len(0x24a));
  12128. }
  12129. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12130. /// 0260 <type>.L
  12131. /// type:
  12132. /// 0 = open
  12133. /// 1 = close
  12134. void clif_Mail_window(int fd, int flag)
  12135. {
  12136. WFIFOHEAD(fd,packet_len(0x260));
  12137. WFIFOW(fd,0) = 0x260;
  12138. WFIFOL(fd,2) = flag;
  12139. WFIFOSET(fd,packet_len(0x260));
  12140. }
  12141. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12142. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12143. /// read:
  12144. /// 0 = unread
  12145. /// 1 = read
  12146. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12147. {
  12148. int fd = sd->fd;
  12149. struct mail_data *md = &sd->mail.inbox;
  12150. struct mail_message *msg;
  12151. int len, i, j;
  12152. len = 8 + (73 * md->amount);
  12153. WFIFOHEAD(fd,len);
  12154. WFIFOW(fd,0) = 0x240;
  12155. WFIFOW(fd,2) = len;
  12156. WFIFOL(fd,4) = md->amount;
  12157. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12158. {
  12159. msg = &md->msg[i];
  12160. if (msg->id < 1)
  12161. continue;
  12162. WFIFOL(fd,8+73*j) = msg->id;
  12163. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12164. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12165. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12166. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12167. j++;
  12168. }
  12169. WFIFOSET(fd,len);
  12170. if( md->full ) {// TODO: is this official?
  12171. char output[100];
  12172. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12173. clif_disp_onlyself(sd, output, strlen(output));
  12174. }
  12175. }
  12176. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12177. /// 023f
  12178. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12179. {
  12180. struct mail_data* md = &sd->mail.inbox;
  12181. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12182. intif_Mail_requestinbox(sd->status.char_id, 1);
  12183. else
  12184. clif_Mail_refreshinbox(sd);
  12185. mail_removeitem(sd, 0);
  12186. mail_removezeny(sd, 0);
  12187. }
  12188. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12189. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12190. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12191. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12192. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12193. {
  12194. int i, fd = sd->fd;
  12195. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12196. if( i == MAIL_MAX_INBOX ) {
  12197. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12198. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12199. return;
  12200. } else {
  12201. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12202. struct item *item = &msg->item;
  12203. struct item_data *data;
  12204. int msg_len = strlen(msg->body), len;
  12205. if( msg_len == 0 ) {
  12206. strcpy(msg->body, "(no message)");
  12207. msg_len = strlen(msg->body);
  12208. }
  12209. len = 101 + msg_len;
  12210. WFIFOHEAD(fd,len);
  12211. WFIFOW(fd,0) = 0x242;
  12212. WFIFOW(fd,2) = len;
  12213. WFIFOL(fd,4) = msg->id;
  12214. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12215. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12216. WFIFOL(fd,72) = 0;
  12217. WFIFOL(fd,76) = msg->zeny;
  12218. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12219. WFIFOL(fd,80) = item->amount;
  12220. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12221. WFIFOW(fd,86) = data->type;
  12222. WFIFOB(fd,88) = item->identify;
  12223. WFIFOB(fd,89) = item->attribute;
  12224. WFIFOB(fd,90) = item->refine;
  12225. WFIFOW(fd,91) = item->card[0];
  12226. WFIFOW(fd,93) = item->card[1];
  12227. WFIFOW(fd,95) = item->card[2];
  12228. WFIFOW(fd,97) = item->card[3];
  12229. } else // no item, set all to zero
  12230. memset(WFIFOP(fd,80), 0x00, 19);
  12231. WFIFOB(fd,99) = (unsigned char)msg_len;
  12232. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12233. WFIFOSET(fd,len);
  12234. if (msg->status == MAIL_UNREAD) {
  12235. msg->status = MAIL_READ;
  12236. intif_Mail_read(mail_id);
  12237. clif_parse_Mail_refreshinbox(fd, sd);
  12238. }
  12239. }
  12240. }
  12241. /// Request to open a mail (CZ_MAIL_OPEN).
  12242. /// 0241 <mail id>.L
  12243. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12244. {
  12245. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12246. if( mail_id <= 0 )
  12247. return;
  12248. if( mail_invalid_operation(sd) )
  12249. return;
  12250. clif_Mail_read(sd, mail_id);
  12251. }
  12252. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12253. /// 0244 <mail id>.L
  12254. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12255. {
  12256. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12257. int i;
  12258. bool fail = false;
  12259. if( !chrif_isconnected() )
  12260. return;
  12261. if( mail_id <= 0 )
  12262. return;
  12263. if( mail_invalid_operation(sd) )
  12264. return;
  12265. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12266. if( i == MAIL_MAX_INBOX )
  12267. return;
  12268. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12269. return;
  12270. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12271. clif_Mail_getattachment(fd, 1);
  12272. return;
  12273. }
  12274. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12275. struct item_data *data;
  12276. unsigned int weight;
  12277. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12278. return;
  12279. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12280. case CHKADDITEM_NEW:
  12281. fail = ( pc_inventoryblank(sd) == 0 );
  12282. break;
  12283. case CHKADDITEM_OVERAMOUNT:
  12284. fail = true;
  12285. }
  12286. if( fail ) {
  12287. clif_Mail_getattachment(fd, 1);
  12288. return;
  12289. }
  12290. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12291. if( sd->weight + weight > sd->max_weight ) {
  12292. clif_Mail_getattachment(fd, 2);
  12293. return;
  12294. }
  12295. }
  12296. sd->mail.inbox.msg[i].zeny = 0;
  12297. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12298. clif_Mail_read(sd, mail_id);
  12299. intif_Mail_getattach(sd->status.char_id, mail_id);
  12300. }
  12301. /// Request to delete a mail (CZ_MAIL_DELETE).
  12302. /// 0243 <mail id>.L
  12303. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12304. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12305. int i;
  12306. if( !chrif_isconnected() )
  12307. return;
  12308. if( mail_id <= 0 )
  12309. return;
  12310. if( mail_invalid_operation(sd) )
  12311. return;
  12312. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12313. if (i < MAIL_MAX_INBOX) {
  12314. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12315. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12316. clif_Mail_delete(sd->fd, mail_id, 1);
  12317. return;
  12318. }
  12319. intif_Mail_delete(sd->status.char_id, mail_id);
  12320. }
  12321. }
  12322. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12323. /// 0273 <mail id>.L <receive name>.24B
  12324. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12325. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12326. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12327. int i;
  12328. if( mail_id <= 0 )
  12329. return;
  12330. if( mail_invalid_operation(sd) )
  12331. return;
  12332. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12333. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12334. intif_Mail_return(sd->status.char_id, mail_id);
  12335. else
  12336. clif_Mail_return(sd->fd, mail_id, 1);
  12337. }
  12338. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12339. /// 0247 <index>.W <amount>.L
  12340. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12341. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12342. int idx = RFIFOW(fd,info->pos[0]);
  12343. int amount = RFIFOL(fd,info->pos[1]);
  12344. unsigned char flag;
  12345. if( !chrif_isconnected() )
  12346. return;
  12347. if (idx < 0 || amount < 0)
  12348. return;
  12349. flag = mail_setitem(sd, idx, amount);
  12350. clif_Mail_setattachment(fd,idx,!flag);
  12351. }
  12352. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12353. /// 0246 <type>.W
  12354. /// type:
  12355. /// 0 = reset all
  12356. /// 1 = remove item
  12357. /// 2 = remove zeny
  12358. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12359. {
  12360. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12361. if (type == 0 || type == 1)
  12362. mail_removeitem(sd, 0);
  12363. if (type == 0 || type == 2)
  12364. mail_removezeny(sd, 0);
  12365. }
  12366. /// Request to send mail (CZ_MAIL_SEND).
  12367. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12368. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12369. {
  12370. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12371. if( !chrif_isconnected() )
  12372. return;
  12373. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12374. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12375. return;
  12376. }
  12377. mail_send(sd, (char*)RFIFOP(fd,info->pos[1]), (char*)RFIFOP(fd,info->pos[2]), (char*)RFIFOP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  12378. }
  12379. /// AUCTION SYSTEM
  12380. /// By Zephyrus
  12381. ///
  12382. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12383. /// 025f <type>.L
  12384. /// type:
  12385. /// 0 = open
  12386. /// 1 = close
  12387. void clif_Auction_openwindow(struct map_session_data *sd)
  12388. {
  12389. int fd = sd->fd;
  12390. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12391. return;
  12392. if( !battle_config.feature_auction )
  12393. return;
  12394. WFIFOHEAD(fd,packet_len(0x25f));
  12395. WFIFOW(fd,0) = 0x25f;
  12396. WFIFOL(fd,2) = 0;
  12397. WFIFOSET(fd,packet_len(0x25f));
  12398. }
  12399. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12400. /// 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 }*
  12401. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12402. {
  12403. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12404. struct auction_data auction;
  12405. struct item_data *item;
  12406. WFIFOHEAD(fd,12 + (count * 83));
  12407. WFIFOW(fd,0) = 0x252;
  12408. WFIFOW(fd,2) = 12 + (count * 83);
  12409. WFIFOL(fd,4) = pages;
  12410. WFIFOL(fd,8) = count;
  12411. for( i = 0; i < count; i++ ) {
  12412. int k = 12 + (i * 83);
  12413. memcpy(&auction, RBUFP(buf,i * len), len);
  12414. WFIFOL(fd,k) = auction.auction_id;
  12415. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12416. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12417. WFIFOW(fd,28+k) = item->view_id;
  12418. else
  12419. WFIFOW(fd,28+k) = auction.item.nameid;
  12420. WFIFOL(fd,30+k) = auction.type;
  12421. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12422. WFIFOB(fd,36+k) = auction.item.identify;
  12423. WFIFOB(fd,37+k) = auction.item.attribute;
  12424. WFIFOB(fd,38+k) = auction.item.refine;
  12425. WFIFOW(fd,39+k) = auction.item.card[0];
  12426. WFIFOW(fd,41+k) = auction.item.card[1];
  12427. WFIFOW(fd,43+k) = auction.item.card[2];
  12428. WFIFOW(fd,45+k) = auction.item.card[3];
  12429. WFIFOL(fd,47+k) = auction.price;
  12430. WFIFOL(fd,51+k) = auction.buynow;
  12431. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12432. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12433. }
  12434. WFIFOSET(fd,WFIFOW(fd,2));
  12435. }
  12436. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12437. /// 0256 <index>.W <result>.B
  12438. /// result:
  12439. /// 0 = success
  12440. /// 1 = failure
  12441. static void clif_Auction_setitem(int fd, int index, bool fail)
  12442. {
  12443. WFIFOHEAD(fd,packet_len(0x256));
  12444. WFIFOW(fd,0) = 0x256;
  12445. WFIFOW(fd,2) = index;
  12446. WFIFOB(fd,4) = fail;
  12447. WFIFOSET(fd,packet_len(0x256));
  12448. }
  12449. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12450. /// 024b <type>.W
  12451. /// type:
  12452. /// 0 = create (any other action in auction window)
  12453. /// 1 = cancel (cancel pressed on register tab)
  12454. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12455. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12456. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12457. if( sd->auction.amount > 0 )
  12458. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12459. sd->auction.amount = 0;
  12460. }
  12461. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12462. /// 024c <index>.W <count>.L
  12463. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12464. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12465. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12466. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12467. struct item_data *item;
  12468. if( !battle_config.feature_auction )
  12469. return;
  12470. if( sd->auction.amount > 0 )
  12471. sd->auction.amount = 0;
  12472. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12473. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12474. return;
  12475. }
  12476. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12477. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12478. return;
  12479. }
  12480. 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) )
  12481. { // Consumable or pets are not allowed
  12482. clif_Auction_setitem(sd->fd, idx, true);
  12483. return;
  12484. }
  12485. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12486. !sd->status.inventory[idx].identify ||
  12487. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12488. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12489. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12490. ) {
  12491. clif_Auction_setitem(sd->fd, idx, true);
  12492. return;
  12493. }
  12494. sd->auction.index = idx;
  12495. sd->auction.amount = amount;
  12496. clif_Auction_setitem(fd, idx + 2, false);
  12497. }
  12498. /// Result from an auction action (ZC_AUCTION_RESULT).
  12499. /// 0250 <result>.B
  12500. /// result:
  12501. /// 0 = You have failed to bid into the auction
  12502. /// 1 = You have successfully bid in the auction
  12503. /// 2 = The auction has been canceled
  12504. /// 3 = An auction with at least one bidder cannot be canceled
  12505. /// 4 = You cannot register more than 5 items in an auction at a time
  12506. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12507. /// 6 = You have won the auction
  12508. /// 7 = You have failed to win the auction
  12509. /// 8 = You do not have enough Zeny
  12510. /// 9 = You cannot place more than 5 bids at a time
  12511. void clif_Auction_message(int fd, unsigned char flag)
  12512. {
  12513. WFIFOHEAD(fd,packet_len(0x250));
  12514. WFIFOW(fd,0) = 0x250;
  12515. WFIFOB(fd,2) = flag;
  12516. WFIFOSET(fd,packet_len(0x250));
  12517. }
  12518. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12519. /// 025e <result>.W
  12520. /// result:
  12521. /// 0 = You have ended the auction
  12522. /// 1 = You cannot end the auction
  12523. /// 2 = Auction ID is incorrect
  12524. void clif_Auction_close(int fd, unsigned char flag)
  12525. {
  12526. WFIFOHEAD(fd,packet_len(0x25e));
  12527. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12528. WFIFOW(fd,2) = flag;
  12529. WFIFOSET(fd,packet_len(0x25e));
  12530. }
  12531. /// Request to add an auction (CZ_AUCTION_ADD).
  12532. /// 024d <now money>.L <max money>.L <delete hour>.W
  12533. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12534. {
  12535. struct auction_data auction;
  12536. struct item_data *item;
  12537. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12538. if( !battle_config.feature_auction )
  12539. return;
  12540. auction.price = RFIFOL(fd,info->pos[0]);
  12541. auction.buynow = RFIFOL(fd,info->pos[1]);
  12542. auction.hours = RFIFOW(fd,info->pos[2]);
  12543. // Invalid Situations...
  12544. if( sd->auction.amount < 1 ) {
  12545. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12546. return;
  12547. }
  12548. if( auction.price >= auction.buynow ) {
  12549. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12550. return;
  12551. }
  12552. if( auction.hours < 1 || auction.hours > 48 ) {
  12553. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12554. return;
  12555. }
  12556. // Auction checks...
  12557. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12558. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12559. clif_Auction_message(fd, 2); // The auction has been canceled
  12560. return;
  12561. }
  12562. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12563. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12564. return;
  12565. }
  12566. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12567. auction.buynow = battle_config.auction_maximumprice;
  12568. if( auction.price >= auction.buynow )
  12569. auction.price = auction.buynow - 1;
  12570. }
  12571. auction.auction_id = 0;
  12572. auction.seller_id = sd->status.char_id;
  12573. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12574. auction.buyer_id = 0;
  12575. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12576. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12577. {
  12578. clif_Auction_message(fd, 2); // The auction has been canceled
  12579. return;
  12580. }
  12581. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12582. { // Just in case
  12583. clif_Auction_message(fd, 2); // The auction has been canceled
  12584. return;
  12585. }
  12586. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12587. auction.type = item->type;
  12588. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12589. auction.item.amount = 1;
  12590. auction.timestamp = 0;
  12591. if( !intif_Auction_register(&auction) )
  12592. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12593. else
  12594. {
  12595. int zeny = auction.hours*battle_config.auction_feeperhour;
  12596. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12597. sd->auction.amount = 0;
  12598. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12599. }
  12600. }
  12601. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12602. /// 024e <auction id>.L
  12603. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12604. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12605. intif_Auction_cancel(sd->status.char_id, auction_id);
  12606. }
  12607. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12608. /// 025d <auction id>.L
  12609. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12610. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12611. intif_Auction_close(sd->status.char_id, auction_id);
  12612. }
  12613. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12614. /// 024f <auction id>.L <money>.L
  12615. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12616. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12617. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12618. int bid = RFIFOL(fd,info->pos[1]);
  12619. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12620. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12621. return;
  12622. }
  12623. if( bid <= 0 )
  12624. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12625. else if( bid > sd->status.zeny )
  12626. clif_Auction_message(fd, 8); // You do not have enough zeny
  12627. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12628. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12629. else {
  12630. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12631. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12632. }
  12633. }
  12634. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12635. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12636. /// search type:
  12637. /// 0 = armor
  12638. /// 1 = weapon
  12639. /// 2 = card
  12640. /// 3 = misc
  12641. /// 4 = name search
  12642. /// 5 = auction id search
  12643. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12644. char search_text[NAME_LENGTH];
  12645. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12646. short type = RFIFOW(fd,info->pos[0]);
  12647. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12648. int page = RFIFOW(fd,info->pos[3]);
  12649. if( !battle_config.feature_auction )
  12650. return;
  12651. clif_parse_Auction_cancelreg(fd, sd);
  12652. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12653. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12654. }
  12655. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12656. /// 025c <type>.W
  12657. /// type:
  12658. /// 0 = sell (own auctions)
  12659. /// 1 = buy (own bids)
  12660. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12661. {
  12662. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12663. if( !battle_config.feature_auction )
  12664. return;
  12665. clif_parse_Auction_cancelreg(fd, sd);
  12666. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12667. }
  12668. /// CASH/POINT SHOP
  12669. ///
  12670. void clif_cashshop_open( struct map_session_data* sd ){
  12671. WFIFOHEAD( sd->fd, 10 );
  12672. WFIFOW( sd->fd, 0 ) = 0x845;
  12673. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12674. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12675. WFIFOSET( sd->fd, 10 );
  12676. }
  12677. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12678. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12679. clif_cashshop_open( sd );
  12680. }
  12681. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12682. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12683. // No need to do anything here
  12684. }
  12685. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12686. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12687. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12688. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12689. int j;
  12690. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12691. return;
  12692. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12693. WFIFOW(fd, 0) = 0x8c0;
  12694. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12695. WFIFOL(fd, 4) = tab;
  12696. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12697. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12698. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  12699. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  12700. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12701. }
  12702. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12703. }
  12704. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12705. void clif_cashshop_list( int fd ){
  12706. int tab;
  12707. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12708. int length = 8 + cash_shop_items[tab].count * 6;
  12709. int i, offset;
  12710. WFIFOHEAD( fd, length );
  12711. WFIFOW( fd, 0 ) = 0x8ca;
  12712. WFIFOW( fd, 2 ) = length;
  12713. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12714. WFIFOW( fd, 6 ) = tab;
  12715. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12716. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  12717. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  12718. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12719. }
  12720. WFIFOSET( fd, length );
  12721. }
  12722. }
  12723. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12724. if( !sd->status.cashshop_sent ) {
  12725. clif_cashshop_list( fd );
  12726. sd->status.cashshop_sent = true;
  12727. }
  12728. }
  12729. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12730. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12731. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12732. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12733. {
  12734. int fd,i;
  12735. #if PACKETVER < 20070711
  12736. const int offset = 8;
  12737. #else
  12738. const int offset = 12;
  12739. #endif
  12740. nullpo_retv(sd);
  12741. nullpo_retv(nd);
  12742. fd = sd->fd;
  12743. sd->npc_shopid = nd->bl.id;
  12744. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12745. WFIFOW(fd,0) = 0x287;
  12746. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12747. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12748. #if PACKETVER >= 20070711
  12749. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12750. #endif
  12751. for( i = 0; i < nd->u.shop.count; i++ ) {
  12752. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12753. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12754. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12755. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12756. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12757. }
  12758. WFIFOSET(fd,WFIFOW(fd,2));
  12759. }
  12760. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12761. /// 0289 <cash point>.L <error>.W
  12762. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12763. /// error:
  12764. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12765. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12766. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12767. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12768. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12769. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12770. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12771. /// 7 = You can purchase up to 10 items.
  12772. /// 8 = Some items could not be purchased.
  12773. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12774. {
  12775. int fd = sd->fd;
  12776. WFIFOHEAD(fd, packet_len(0x289));
  12777. WFIFOW(fd,0) = 0x289;
  12778. WFIFOL(fd,2) = sd->cashPoints;
  12779. #if PACKETVER < 20070711
  12780. WFIFOW(fd,6) = TOW(error);
  12781. #else
  12782. WFIFOL(fd,6) = sd->kafraPoints;
  12783. WFIFOW(fd,10) = TOW(error);
  12784. #endif
  12785. WFIFOSET(fd, packet_len(0x289));
  12786. }
  12787. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  12788. WFIFOHEAD( sd->fd, 16 );
  12789. WFIFOW( sd->fd, 0 ) = 0x849;
  12790. WFIFOL( sd->fd, 2 ) = item_id;
  12791. WFIFOW( sd->fd, 6 ) = result;
  12792. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12793. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12794. WFIFOSET( sd->fd, 16 );
  12795. }
  12796. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12797. /// 0288 <name id>.W <amount>.W
  12798. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12799. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12800. /// 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)
  12801. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  12802. struct s_packet_db* info;
  12803. int cmd = RFIFOW(fd,0);
  12804. nullpo_retv(sd);
  12805. info = &packet_db[sd->packet_ver][cmd];
  12806. if( sd->state.trading || !sd->npc_shopid ) {
  12807. clif_cashshop_ack(sd,1);
  12808. return;
  12809. } else {
  12810. #if PACKETVER < 20101116
  12811. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  12812. short amount = RFIFOW(fd,info->pos[1]);
  12813. int points = RFIFOL(fd,info->pos[2]);
  12814. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  12815. #else
  12816. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12817. int len = RFIFOW(fd,info->pos[0]);
  12818. int points = RFIFOL(fd,info->pos[1]);
  12819. int count = RFIFOW(fd,info->pos[2]);
  12820. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12821. if( len < 10 || len != 10 + count * s_itl) {
  12822. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12823. return;
  12824. }
  12825. if(cmd == 0x848) {
  12826. if (cashshop_buylist( sd, points, count, item_list))
  12827. clif_cashshop_ack(sd,0);
  12828. return;
  12829. } else {
  12830. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  12831. return;
  12832. }
  12833. #endif
  12834. }
  12835. }
  12836. /// Adoption System
  12837. ///
  12838. /// Adoption message (ZC_BABYMSG).
  12839. /// 0216 <msg>.L
  12840. /// msg:
  12841. /// 0 = "You cannot adopt more than 1 child."
  12842. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12843. /// 2 = "You cannot adopt a married person."
  12844. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12845. {
  12846. int fd = sd->fd;
  12847. WFIFOHEAD(fd,6);
  12848. WFIFOW(fd,0) = 0x216;
  12849. WFIFOL(fd,2) = type;
  12850. WFIFOSET(fd,6);
  12851. }
  12852. /// Adoption confirmation (ZC_REQ_BABY).
  12853. /// 01f6 <account id>.L <char id>.L <name>.B
  12854. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12855. {
  12856. int fd = sd->fd;
  12857. WFIFOHEAD(fd,34);
  12858. WFIFOW(fd,0) = 0x1f6;
  12859. WFIFOL(fd,2) = src->status.account_id;
  12860. WFIFOL(fd,6) = p_id;
  12861. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12862. WFIFOSET(fd,34);
  12863. }
  12864. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12865. /// 01f9 <account id>.L
  12866. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12867. {
  12868. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12869. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12870. if( pc_can_Adopt(sd, p_sd, tsd) )
  12871. {
  12872. tsd->adopt_invite = sd->status.account_id;
  12873. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12874. }
  12875. }
  12876. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12877. /// 01f7 <account id>.L <char id>.L <answer>.L
  12878. /// answer:
  12879. /// 0 = rejected
  12880. /// 1 = accepted
  12881. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12882. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12883. int p1_id = RFIFOL(fd,info->pos[0]);
  12884. int p2_id = RFIFOL(fd,info->pos[1]);
  12885. int result = RFIFOL(fd,info->pos[2]);
  12886. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12887. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12888. int pid = sd->adopt_invite;
  12889. sd->adopt_invite = 0;
  12890. if( p1_sd == NULL || p2_sd == NULL )
  12891. return; // Both players need to be online
  12892. if( pid != p1_sd->status.account_id )
  12893. return; // Incorrect values
  12894. if( result == 0 )
  12895. return; // Rejected
  12896. pc_adoption(p1_sd, p2_sd, sd);
  12897. }
  12898. /// Convex Mirror (ZC_BOSS_INFO).
  12899. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12900. /// infoType:
  12901. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12902. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12903. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12904. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12905. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12906. {
  12907. WFIFOHEAD(fd,70);
  12908. memset(WFIFOP(fd,0),0,70);
  12909. WFIFOW(fd,0) = 0x293;
  12910. if( md != NULL ) {
  12911. if( md->bl.prev != NULL ) { // Boss on This Map
  12912. if( flag ) {
  12913. WFIFOB(fd,2) = 1;
  12914. WFIFOL(fd,3) = md->bl.x;
  12915. WFIFOL(fd,7) = md->bl.y;
  12916. } else
  12917. WFIFOB(fd,2) = 2; // First Time
  12918. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12919. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12920. unsigned int seconds;
  12921. int hours, minutes;
  12922. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12923. hours = seconds / (60 * 60);
  12924. seconds = seconds - (60 * 60 * hours);
  12925. minutes = seconds / 60;
  12926. WFIFOB(fd,2) = 3;
  12927. WFIFOW(fd,11) = hours; // Hours
  12928. WFIFOW(fd,13) = minutes; // Minutes
  12929. }
  12930. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12931. }
  12932. WFIFOSET(fd,70);
  12933. }
  12934. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12935. /// 02d6 <account id>.L
  12936. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12937. {
  12938. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12939. struct map_session_data* tsd = map_id2sd(aid);
  12940. if (!tsd)
  12941. return;
  12942. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12943. clif_viewequip_ack(sd, tsd);
  12944. else
  12945. clif_msg(sd, VIEW_EQUIP_FAIL);
  12946. }
  12947. /// Request to change equip window tick (CZ_CONFIG).
  12948. /// 02d8 <type>.L <flag>.L
  12949. /// type:
  12950. /// 0 = open equip window
  12951. /// flag:
  12952. /// 0 = disabled
  12953. /// 1 = enabled
  12954. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12955. {
  12956. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12957. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12958. sd->status.show_equip = flag;
  12959. clif_equiptickack(sd, flag);
  12960. }
  12961. /// Request to change party invitation tick.
  12962. /// value:
  12963. /// 0 = disabled
  12964. /// 1 = enabled
  12965. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  12966. {
  12967. bool flag = RFIFOB(fd,6) ? true : false;
  12968. sd->status.allow_party = flag;
  12969. clif_partytickack(sd, flag);
  12970. }
  12971. /// Questlog System [Kevin] [Inkfish]
  12972. ///
  12973. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12974. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12975. void clif_quest_send_list(struct map_session_data * sd)
  12976. {
  12977. int fd = sd->fd;
  12978. int i;
  12979. int len = sd->avail_quests*5+8;
  12980. WFIFOHEAD(fd,len);
  12981. WFIFOW(fd, 0) = 0x2b1;
  12982. WFIFOW(fd, 2) = len;
  12983. WFIFOL(fd, 4) = sd->avail_quests;
  12984. for( i = 0; i < sd->avail_quests; i++ ) {
  12985. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12986. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12987. }
  12988. WFIFOSET(fd, len);
  12989. }
  12990. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12991. /// 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
  12992. void clif_quest_send_mission(struct map_session_data * sd)
  12993. {
  12994. int fd = sd->fd;
  12995. int i, j;
  12996. int len = sd->avail_quests*104+8;
  12997. struct mob_db *mob;
  12998. WFIFOHEAD(fd, len);
  12999. WFIFOW(fd, 0) = 0x2b2;
  13000. WFIFOW(fd, 2) = len;
  13001. WFIFOL(fd, 4) = sd->avail_quests;
  13002. for( i = 0; i < sd->avail_quests; i++ ) {
  13003. struct quest_db *qi = quest_db(sd->quest_log[i].quest_id);
  13004. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13005. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13006. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13007. WFIFOW(fd, i*104+20) = qi->num_objectives;
  13008. for( j = 0 ; j < qi->num_objectives; j++ ) {
  13009. WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
  13010. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13011. mob = mob_db(qi->mob[j]);
  13012. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13013. }
  13014. }
  13015. WFIFOSET(fd, len);
  13016. }
  13017. /// Notification about a new quest (ZC_ADD_QUEST).
  13018. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13019. void clif_quest_add(struct map_session_data * sd, struct quest * qd)
  13020. {
  13021. int fd = sd->fd;
  13022. int i;
  13023. struct quest_db *qi = quest_db(qd->quest_id);
  13024. WFIFOHEAD(fd, packet_len(0x2b3));
  13025. WFIFOW(fd, 0) = 0x2b3;
  13026. WFIFOL(fd, 2) = qd->quest_id;
  13027. WFIFOB(fd, 6) = qd->state;
  13028. WFIFOB(fd, 7) = qi->time;
  13029. WFIFOL(fd, 11) = qd->time;
  13030. WFIFOW(fd, 15) = qi->num_objectives;
  13031. for( i = 0; i < qi->num_objectives; i++ ) {
  13032. struct mob_db *mob;
  13033. WFIFOL(fd, i*30+17) = qi->mob[i];
  13034. WFIFOW(fd, i*30+21) = qd->count[i];
  13035. mob = mob_db(qi->mob[i]);
  13036. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13037. }
  13038. WFIFOSET(fd, packet_len(0x2b3));
  13039. }
  13040. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13041. /// 02b4 <quest id>.L
  13042. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  13043. {
  13044. int fd = sd->fd;
  13045. WFIFOHEAD(fd, packet_len(0x2b4));
  13046. WFIFOW(fd, 0) = 0x2b4;
  13047. WFIFOL(fd, 2) = quest_id;
  13048. WFIFOSET(fd, packet_len(0x2b4));
  13049. }
  13050. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13051. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13052. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd)
  13053. {
  13054. int fd = sd->fd;
  13055. int i;
  13056. struct quest_db *qi = quest_db(qd->quest_id);
  13057. int len = qi->num_objectives * 12 + 6;
  13058. WFIFOHEAD(fd, len);
  13059. WFIFOW(fd, 0) = 0x2b5;
  13060. WFIFOW(fd, 2) = len;
  13061. WFIFOW(fd, 4) = qi->num_objectives;
  13062. for( i = 0; i < qi->num_objectives; i++ ) {
  13063. WFIFOL(fd, i*12+6) = qd->quest_id;
  13064. WFIFOL(fd, i*12+10) = qi->mob[i];
  13065. WFIFOW(fd, i*12+14) = qi->count[i];
  13066. WFIFOW(fd, i*12+16) = qd->count[i];
  13067. }
  13068. WFIFOSET(fd, len);
  13069. }
  13070. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13071. /// 02b6 <quest id>.L <active>.B
  13072. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  13073. {
  13074. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13075. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13076. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13077. }
  13078. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13079. /// 02b7 <quest id>.L <active>.B
  13080. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  13081. {
  13082. int fd = sd->fd;
  13083. WFIFOHEAD(fd, packet_len(0x2b7));
  13084. WFIFOW(fd, 0) = 0x2b7;
  13085. WFIFOL(fd, 2) = quest_id;
  13086. WFIFOB(fd, 6) = active;
  13087. WFIFOSET(fd, packet_len(0x2b7));
  13088. }
  13089. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13090. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13091. /// effect:
  13092. /// 0 = none
  13093. /// 1 = exclamation mark icon
  13094. /// 2 = question mark icon
  13095. /// type:
  13096. /// 0 = yellow
  13097. /// 1 = orange
  13098. /// 2 = green
  13099. /// 3 = purple
  13100. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13101. {
  13102. #if PACKETVER >= 20090218
  13103. int fd = sd->fd;
  13104. WFIFOHEAD(fd, packet_len(0x446));
  13105. WFIFOW(fd, 0) = 0x446;
  13106. WFIFOL(fd, 2) = bl->id;
  13107. WFIFOW(fd, 6) = bl->x;
  13108. WFIFOW(fd, 8) = bl->y;
  13109. WFIFOW(fd, 10) = state;
  13110. WFIFOW(fd, 12) = color;
  13111. WFIFOSET(fd, packet_len(0x446));
  13112. #endif
  13113. }
  13114. /// Mercenary System
  13115. ///
  13116. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13117. /// 02a2 <var id>.W <value>.L
  13118. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13119. {
  13120. struct mercenary_data *md;
  13121. struct status_data *status;
  13122. int fd;
  13123. if( sd == NULL || (md = sd->md) == NULL )
  13124. return;
  13125. fd = sd->fd;
  13126. status = &md->battle_status;
  13127. WFIFOHEAD(fd,packet_len(0x2a2));
  13128. WFIFOW(fd,0) = 0x2a2;
  13129. WFIFOW(fd,2) = type;
  13130. switch( type ) {
  13131. case SP_ATK1:
  13132. {
  13133. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13134. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13135. }
  13136. break;
  13137. case SP_MATK1:
  13138. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13139. break;
  13140. case SP_HIT:
  13141. WFIFOL(fd,4) = status->hit;
  13142. break;
  13143. case SP_CRITICAL:
  13144. WFIFOL(fd,4) = status->cri/10;
  13145. break;
  13146. case SP_DEF1:
  13147. WFIFOL(fd,4) = status->def;
  13148. break;
  13149. case SP_MDEF1:
  13150. WFIFOL(fd,4) = status->mdef;
  13151. break;
  13152. case SP_MERCFLEE:
  13153. WFIFOL(fd,4) = status->flee;
  13154. break;
  13155. case SP_ASPD:
  13156. WFIFOL(fd,4) = status->amotion;
  13157. break;
  13158. case SP_HP:
  13159. WFIFOL(fd,4) = status->hp;
  13160. break;
  13161. case SP_MAXHP:
  13162. WFIFOL(fd,4) = status->max_hp;
  13163. break;
  13164. case SP_SP:
  13165. WFIFOL(fd,4) = status->sp;
  13166. break;
  13167. case SP_MAXSP:
  13168. WFIFOL(fd,4) = status->max_sp;
  13169. break;
  13170. case SP_MERCKILLS:
  13171. WFIFOL(fd,4) = md->mercenary.kill_count;
  13172. break;
  13173. case SP_MERCFAITH:
  13174. WFIFOL(fd,4) = mercenary_get_faith(md);
  13175. break;
  13176. }
  13177. WFIFOSET(fd,packet_len(0x2a2));
  13178. }
  13179. /// Mercenary base status data (ZC_MER_INIT).
  13180. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13181. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13182. /// <calls>.L <kills>.L <atk range>.W
  13183. void clif_mercenary_info(struct map_session_data *sd)
  13184. {
  13185. int fd;
  13186. struct mercenary_data *md;
  13187. struct status_data *status;
  13188. int atk;
  13189. if( sd == NULL || (md = sd->md) == NULL )
  13190. return;
  13191. fd = sd->fd;
  13192. status = &md->battle_status;
  13193. WFIFOHEAD(fd,packet_len(0x29b));
  13194. WFIFOW(fd,0) = 0x29b;
  13195. WFIFOL(fd,2) = md->bl.id;
  13196. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13197. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13198. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13199. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13200. WFIFOW(fd,10) = status->hit;
  13201. WFIFOW(fd,12) = status->cri/10;
  13202. WFIFOW(fd,14) = status->def;
  13203. WFIFOW(fd,16) = status->mdef;
  13204. WFIFOW(fd,18) = status->flee;
  13205. WFIFOW(fd,20) = status->amotion;
  13206. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13207. WFIFOW(fd,46) = md->db->lv;
  13208. WFIFOL(fd,48) = status->hp;
  13209. WFIFOL(fd,52) = status->max_hp;
  13210. WFIFOL(fd,56) = status->sp;
  13211. WFIFOL(fd,60) = status->max_sp;
  13212. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13213. WFIFOW(fd,68) = mercenary_get_faith(md);
  13214. WFIFOL(fd,70) = mercenary_get_calls(md);
  13215. WFIFOL(fd,74) = md->mercenary.kill_count;
  13216. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13217. WFIFOSET(fd,packet_len(0x29b));
  13218. }
  13219. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13220. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13221. void clif_mercenary_skillblock(struct map_session_data *sd)
  13222. {
  13223. struct mercenary_data *md;
  13224. int fd, i, len = 4;
  13225. if( sd == NULL || (md = sd->md) == NULL )
  13226. return;
  13227. fd = sd->fd;
  13228. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13229. WFIFOW(fd,0) = 0x29d;
  13230. for( i = 0; i < MAX_MERCSKILL; i++ )
  13231. {
  13232. int id, j;
  13233. if( (id = md->db->skill[i].id) == 0 )
  13234. continue;
  13235. j = id - MC_SKILLBASE;
  13236. WFIFOW(fd,len) = id;
  13237. WFIFOL(fd,len+2) = skill_get_inf(id);
  13238. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13239. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13240. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13241. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13242. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13243. len += 37;
  13244. }
  13245. WFIFOW(fd,2) = len;
  13246. WFIFOSET(fd,len);
  13247. }
  13248. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13249. /// 029f <command>.B
  13250. /// 1 = mercenary information
  13251. /// 2 = delete
  13252. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13253. {
  13254. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13255. if( sd->md == NULL )
  13256. return;
  13257. if( option == 2 ) mercenary_delete(sd->md, 2);
  13258. }
  13259. /// Mercenary Message
  13260. /// message:
  13261. /// 0 = Mercenary soldier's duty hour is over.
  13262. /// 1 = Your mercenary soldier has been killed.
  13263. /// 2 = Your mercenary soldier has been fired.
  13264. /// 3 = Your mercenary soldier has ran away.
  13265. void clif_mercenary_message(struct map_session_data* sd, int message){
  13266. clif_msg(sd, MERC_MSG_BASE + message);
  13267. }
  13268. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13269. /// 0298 <name id>.W <seconds>.L
  13270. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13271. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13272. WFIFOHEAD(fd,packet_len(0x298));
  13273. WFIFOW(fd,0) = 0x298;
  13274. WFIFOW(fd,2) = nameid;
  13275. WFIFOL(fd,4) = seconds;
  13276. WFIFOSET(fd,packet_len(0x298));
  13277. }
  13278. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13279. /// 0299 <index>.W <name id>.W
  13280. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13281. { // '<ItemName>' item has been deleted from the Inventory
  13282. WFIFOHEAD(fd,packet_len(0x299));
  13283. WFIFOW(fd,0) = 0x299;
  13284. WFIFOW(fd,2) = index+2;
  13285. WFIFOW(fd,4) = nameid;
  13286. WFIFOSET(fd,packet_len(0x299));
  13287. }
  13288. /// Book Reading (ZC_READ_BOOK).
  13289. /// 0294 <book id>.L <page>.L
  13290. void clif_readbook(int fd, int book_id, int page)
  13291. {
  13292. WFIFOHEAD(fd,packet_len(0x294));
  13293. WFIFOW(fd,0) = 0x294;
  13294. WFIFOL(fd,2) = book_id;
  13295. WFIFOL(fd,6) = page;
  13296. WFIFOSET(fd,packet_len(0x294));
  13297. }
  13298. /// Battlegrounds
  13299. ///
  13300. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13301. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13302. void clif_bg_hp(struct map_session_data *sd)
  13303. {
  13304. unsigned char buf[34];
  13305. const int cmd = 0x2e0;
  13306. nullpo_retv(sd);
  13307. WBUFW(buf,0) = cmd;
  13308. WBUFL(buf,2) = sd->status.account_id;
  13309. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13310. if( sd->battle_status.max_hp > INT16_MAX )
  13311. { // To correctly display the %hp bar. [Skotlex]
  13312. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13313. WBUFW(buf,32) = 100;
  13314. }
  13315. else
  13316. {
  13317. WBUFW(buf,30) = sd->battle_status.hp;
  13318. WBUFW(buf,32) = sd->battle_status.max_hp;
  13319. }
  13320. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13321. }
  13322. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13323. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13324. void clif_bg_xy(struct map_session_data *sd)
  13325. {
  13326. unsigned char buf[36];
  13327. nullpo_retv(sd);
  13328. WBUFW(buf,0)=0x2df;
  13329. WBUFL(buf,2)=sd->status.account_id;
  13330. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13331. WBUFW(buf,30)=sd->status.class_;
  13332. WBUFW(buf,32)=sd->bl.x;
  13333. WBUFW(buf,34)=sd->bl.y;
  13334. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13335. }
  13336. void clif_bg_xy_remove(struct map_session_data *sd)
  13337. {
  13338. unsigned char buf[36];
  13339. nullpo_retv(sd);
  13340. WBUFW(buf,0)=0x2df;
  13341. WBUFL(buf,2)=sd->status.account_id;
  13342. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13343. WBUFW(buf,30)=0;
  13344. WBUFW(buf,32)=-1;
  13345. WBUFW(buf,34)=-1;
  13346. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13347. }
  13348. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13349. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13350. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13351. {
  13352. struct map_session_data *sd;
  13353. unsigned char *buf;
  13354. if( (sd = bg_getavailablesd(bg)) == NULL )
  13355. return;
  13356. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13357. WBUFW(buf,0) = 0x2dc;
  13358. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13359. WBUFL(buf,4) = src_id;
  13360. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13361. memcpy(WBUFP(buf,32), mes, len);
  13362. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13363. if( buf )
  13364. aFree(buf);
  13365. }
  13366. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13367. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13368. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13369. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13370. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13371. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13372. char *name, *message;
  13373. int namelen, messagelen;
  13374. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13375. return;
  13376. if( is_atcommand(fd, sd, message, 1) )
  13377. return;
  13378. if (sd->sc.cant.chat)
  13379. return; //no "chatting" while muted.
  13380. if( battle_config.min_chat_delay ) {
  13381. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13382. return;
  13383. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13384. }
  13385. if (battle_config.idletime_option&IDLE_CHAT)
  13386. sd->idletime = last_tick;
  13387. bg_send_message(sd, text, textlen);
  13388. }
  13389. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13390. /// 02de <camp A points>.W <camp B points>.W
  13391. void clif_bg_updatescore(int16 m)
  13392. {
  13393. struct block_list bl;
  13394. unsigned char buf[6];
  13395. bl.id = 0;
  13396. bl.type = BL_NUL;
  13397. bl.m = m;
  13398. WBUFW(buf,0) = 0x2de;
  13399. WBUFW(buf,2) = map[m].bgscore_lion;
  13400. WBUFW(buf,4) = map[m].bgscore_eagle;
  13401. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13402. }
  13403. void clif_bg_updatescore_single(struct map_session_data *sd)
  13404. {
  13405. int fd;
  13406. nullpo_retv(sd);
  13407. fd = sd->fd;
  13408. WFIFOHEAD(fd,packet_len(0x2de));
  13409. WFIFOW(fd,0) = 0x2de;
  13410. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13411. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13412. WFIFOSET(fd,packet_len(0x2de));
  13413. }
  13414. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13415. /// 02dd <account id>.L <name>.24B <camp>.W
  13416. void clif_sendbgemblem_area(struct map_session_data *sd)
  13417. {
  13418. unsigned char buf[33];
  13419. nullpo_retv(sd);
  13420. WBUFW(buf, 0) = 0x2dd;
  13421. WBUFL(buf,2) = sd->bl.id;
  13422. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13423. WBUFW(buf,30) = sd->bg_id;
  13424. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13425. }
  13426. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13427. {
  13428. nullpo_retv(sd);
  13429. WFIFOHEAD(fd,32);
  13430. WFIFOW(fd,0) = 0x2dd;
  13431. WFIFOL(fd,2) = sd->bl.id;
  13432. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13433. WFIFOW(fd,30) = sd->bg_id;
  13434. WFIFOSET(fd,packet_len(0x2dd));
  13435. }
  13436. /// Custom Fonts (ZC_NOTIFY_FONT).
  13437. /// 02ef <account_id>.L <font id>.W
  13438. void clif_font(struct map_session_data *sd)
  13439. {
  13440. #if PACKETVER >= 20080102
  13441. unsigned char buf[8];
  13442. nullpo_retv(sd);
  13443. WBUFW(buf,0) = 0x2ef;
  13444. WBUFL(buf,2) = sd->bl.id;
  13445. WBUFW(buf,6) = sd->status.font;
  13446. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13447. #endif
  13448. }
  13449. /*==========================================
  13450. * Notifies party members of instance change
  13451. *------------------------------------------*/
  13452. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13453. {
  13454. #if PACKETVER >= 20071128
  13455. unsigned char buf[65];
  13456. if(!sd) return;
  13457. WBUFW(buf,0) = 0x2cb;
  13458. memcpy( WBUFP(buf,2), name, 62 );
  13459. WBUFW(buf,63) = num;
  13460. if(flag) // A timer has changed or been added
  13461. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13462. else // No notification
  13463. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13464. #endif
  13465. return;
  13466. }
  13467. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13468. {
  13469. #if PACKETVER >= 20071128
  13470. unsigned char buf[4];
  13471. if(!sd) return;
  13472. WBUFW(buf,0) = 0x2cc;
  13473. WBUFW(buf,2) = num;
  13474. if(flag) // A timer has changed or been added
  13475. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13476. else // No notification
  13477. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13478. #endif
  13479. return;
  13480. }
  13481. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13482. {
  13483. #if PACKETVER >= 20071128
  13484. unsigned char buf[71];
  13485. if(!sd) return; //party_getavailablesd can return NULL
  13486. WBUFW(buf,0) = 0x2cd;
  13487. memcpy( WBUFP(buf,2), name, 62 );
  13488. WBUFL(buf,63) = limit1;
  13489. WBUFL(buf,67) = limit2;
  13490. if(flag) // A timer has changed or been added
  13491. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13492. else // No notification
  13493. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13494. #endif
  13495. return;
  13496. }
  13497. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13498. {
  13499. #if PACKETVER >= 20071128
  13500. unsigned char buf[10];
  13501. if(!sd) return;
  13502. WBUFW(buf,0) = 0x2ce;
  13503. WBUFL(buf,2) = type;
  13504. WBUFL(buf,6) = limit;
  13505. if(flag) // A timer has changed or been added
  13506. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13507. else // No notification
  13508. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13509. #endif
  13510. return;
  13511. }
  13512. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13513. /// 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
  13514. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13515. {
  13516. #if PACKETVER >= 20071002
  13517. unsigned char buf[22];
  13518. struct item_data* id = itemdb_search(item_data->nameid);
  13519. WBUFW(buf,0) = 0x2b8;
  13520. WBUFL(buf,2) = sd->status.account_id;
  13521. WBUFW(buf,6) = item_data->nameid;
  13522. WBUFB(buf,8) = item_data->identify;
  13523. WBUFB(buf,9) = item_data->attribute;
  13524. WBUFB(buf,10) = item_data->refine;
  13525. clif_addcards(WBUFP(buf,11), item_data);
  13526. WBUFW(buf,19) = id->equip; // equip location
  13527. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13528. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13529. #endif
  13530. }
  13531. /// Display gained exp (ZC_NOTIFY_EXP).
  13532. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13533. /// var id:
  13534. /// SP_BASEEXP, SP_JOBEXP
  13535. /// exp type:
  13536. /// 0 = normal exp gain/loss
  13537. /// 1 = quest exp gain/loss
  13538. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13539. {
  13540. int fd;
  13541. nullpo_retv(sd);
  13542. fd = sd->fd;
  13543. WFIFOHEAD(fd, packet_len(0x7f6));
  13544. WFIFOW(fd,0) = 0x7f6;
  13545. WFIFOL(fd,2) = sd->bl.id;
  13546. WFIFOL(fd,6) = exp;
  13547. WFIFOW(fd,10) = type;
  13548. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13549. WFIFOSET(fd,packet_len(0x7f6));
  13550. }
  13551. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13552. /// type:
  13553. /// 0 = Displays 'value' for 5 seconds.
  13554. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13555. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13556. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13557. /// value:
  13558. /// 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).
  13559. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13560. {
  13561. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13562. WFIFOW(sd->fd,0) = 0x1b1;
  13563. WFIFOB(sd->fd,2) = type;
  13564. WFIFOL(sd->fd,3) = value;
  13565. WFIFOSET(sd->fd, packet_len(0x1b1));
  13566. }
  13567. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13568. /// 021d <state>.L
  13569. /// state:
  13570. /// 0 = Full effects
  13571. /// 1 = Reduced effects
  13572. ///
  13573. /// NOTE: The state is used on Aegis for sending skill unit packet
  13574. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13575. /// whenever possible. Due to the way the decision check is
  13576. /// constructed, this state tracking was rendered useless,
  13577. /// as the only skill unit, that is sent with 0x1c9 is
  13578. /// Graffiti.
  13579. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13580. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13581. sd->state.lesseffect = ( isLess != 0 );
  13582. }
  13583. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13584. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13585. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13586. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13587. int type = RFIFOL(fd,info->pos[1]);
  13588. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13589. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13590. if( sd->state.trading || sd->npc_shopid )
  13591. return;
  13592. if( flag == 0 || n == 0) {
  13593. clif_menuskill_clear(sd);
  13594. return; // Canceled by player.
  13595. }
  13596. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13597. clif_menuskill_clear(sd);
  13598. return; // Prevent hacking.
  13599. }
  13600. switch( type ) {
  13601. case 0: // Change Material
  13602. skill_changematerial(sd,n,item_list);
  13603. break;
  13604. case 1: // Level 1: Pure to Rough
  13605. case 2: // Level 2: Rough to Pure
  13606. skill_elementalanalysis(sd,n,type,item_list);
  13607. break;
  13608. }
  13609. clif_menuskill_clear(sd);
  13610. return;
  13611. }
  13612. /*==========================================
  13613. * Elemental System
  13614. *==========================================*/
  13615. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13616. struct elemental_data *ed;
  13617. struct status_data *status;
  13618. int fd;
  13619. if( sd == NULL || (ed = sd->ed) == NULL )
  13620. return;
  13621. fd = sd->fd;
  13622. status = &ed->battle_status;
  13623. WFIFOHEAD(fd,8);
  13624. WFIFOW(fd,0) = 0x81e;
  13625. WFIFOW(fd,2) = type;
  13626. switch( type ) {
  13627. case SP_HP:
  13628. WFIFOL(fd,4) = status->hp;
  13629. break;
  13630. case SP_MAXHP:
  13631. WFIFOL(fd,4) = status->max_hp;
  13632. break;
  13633. case SP_SP:
  13634. WFIFOL(fd,4) = status->sp;
  13635. break;
  13636. case SP_MAXSP:
  13637. WFIFOL(fd,4) = status->max_sp;
  13638. break;
  13639. }
  13640. WFIFOSET(fd,8);
  13641. }
  13642. void clif_elemental_info(struct map_session_data *sd) {
  13643. int fd;
  13644. struct elemental_data *ed;
  13645. struct status_data *status;
  13646. if( sd == NULL || (ed = sd->ed) == NULL )
  13647. return;
  13648. fd = sd->fd;
  13649. status = &ed->battle_status;
  13650. WFIFOHEAD(fd,22);
  13651. WFIFOW(fd, 0) = 0x81d;
  13652. WFIFOL(fd, 2) = ed->bl.id;
  13653. WFIFOL(fd, 6) = status->hp;
  13654. WFIFOL(fd,10) = status->max_hp;
  13655. WFIFOL(fd,14) = status->sp;
  13656. WFIFOL(fd,18) = status->max_sp;
  13657. WFIFOSET(fd,22);
  13658. }
  13659. /// Buying Store System
  13660. ///
  13661. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13662. /// 0810 <slots>.B
  13663. void clif_buyingstore_open(struct map_session_data* sd)
  13664. {
  13665. int fd = sd->fd;
  13666. WFIFOHEAD(fd,packet_len(0x810));
  13667. WFIFOW(fd,0) = 0x810;
  13668. WFIFOB(fd,2) = sd->buyingstore.slots;
  13669. WFIFOSET(fd,packet_len(0x810));
  13670. }
  13671. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13672. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13673. /// result:
  13674. /// 0 = cancel
  13675. /// 1 = open
  13676. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13677. {
  13678. const unsigned int blocksize = 8;
  13679. uint8* itemlist;
  13680. char storename[MESSAGE_SIZE];
  13681. unsigned char result;
  13682. int zenylimit;
  13683. unsigned int count, packet_len;
  13684. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13685. packet_len = RFIFOW(fd,info->pos[0]);
  13686. // TODO: Make this check global for all variable length packets.
  13687. if( packet_len < 89 )
  13688. {// minimum packet length
  13689. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13690. return;
  13691. }
  13692. zenylimit = RFIFOL(fd,info->pos[1]);
  13693. result = RFIFOL(fd,info->pos[2]);
  13694. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13695. itemlist = RFIFOP(fd,info->pos[4]);
  13696. // so that buyingstore_create knows, how many elements it has access to
  13697. packet_len-= info->pos[4];
  13698. if( packet_len%blocksize )
  13699. {
  13700. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13701. return;
  13702. }
  13703. count = packet_len/blocksize;
  13704. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13705. }
  13706. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13707. /// 0812 <result>.W <total weight>.L
  13708. /// result:
  13709. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13710. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13711. /// 8 = "No sale (purchase) information available." (0x705)
  13712. /// ? = nothing
  13713. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13714. {
  13715. int fd = sd->fd;
  13716. WFIFOHEAD(fd,packet_len(0x812));
  13717. WFIFOW(fd,0) = 0x812;
  13718. WFIFOW(fd,2) = result;
  13719. WFIFOL(fd,4) = weight;
  13720. WFIFOSET(fd,packet_len(0x812));
  13721. }
  13722. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13723. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13724. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13725. {
  13726. int fd = sd->fd;
  13727. unsigned int i;
  13728. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13729. WFIFOW(fd,0) = 0x813;
  13730. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13731. WFIFOL(fd,4) = sd->bl.id;
  13732. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13733. for( i = 0; i < sd->buyingstore.slots; i++ )
  13734. {
  13735. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13736. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13737. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13738. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13739. }
  13740. WFIFOSET(fd,WFIFOW(fd,2));
  13741. }
  13742. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13743. /// 0814 <account id>.L <store name>.80B
  13744. void clif_buyingstore_entry(struct map_session_data* sd)
  13745. {
  13746. uint8 buf[86];
  13747. WBUFW(buf,0) = 0x814;
  13748. WBUFL(buf,2) = sd->bl.id;
  13749. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13750. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13751. }
  13752. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13753. {
  13754. int fd = sd->fd;
  13755. WFIFOHEAD(fd,packet_len(0x814));
  13756. WFIFOW(fd,0) = 0x814;
  13757. WFIFOL(fd,2) = pl_sd->bl.id;
  13758. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13759. WFIFOSET(fd,packet_len(0x814));
  13760. }
  13761. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13762. /// 0815
  13763. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13764. {
  13765. buyingstore_close(sd);
  13766. }
  13767. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13768. /// 0816 <account id>.L
  13769. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13770. {
  13771. uint8 buf[6];
  13772. WBUFW(buf,0) = 0x816;
  13773. WBUFL(buf,2) = sd->bl.id;
  13774. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13775. }
  13776. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13777. {
  13778. int fd = sd->fd;
  13779. WFIFOHEAD(fd,packet_len(0x816));
  13780. WFIFOW(fd,0) = 0x816;
  13781. WFIFOL(fd,2) = pl_sd->bl.id;
  13782. WFIFOSET(fd,packet_len(0x816));
  13783. }
  13784. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13785. /// 0817 <account id>.L
  13786. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13787. {
  13788. int account_id;
  13789. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13790. buyingstore_open(sd, account_id);
  13791. }
  13792. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13793. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13794. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13795. {
  13796. int fd = sd->fd;
  13797. unsigned int i;
  13798. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13799. WFIFOW(fd,0) = 0x818;
  13800. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13801. WFIFOL(fd,4) = pl_sd->bl.id;
  13802. WFIFOL(fd,8) = pl_sd->buyer_id;
  13803. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13804. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13805. {
  13806. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13807. 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.
  13808. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  13809. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13810. }
  13811. WFIFOSET(fd,WFIFOW(fd,2));
  13812. }
  13813. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13814. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13815. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13816. {
  13817. const unsigned int blocksize = 6;
  13818. uint8* itemlist;
  13819. int account_id;
  13820. unsigned int count, packet_len, buyer_id;
  13821. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13822. packet_len = RFIFOW(fd,info->pos[0]);
  13823. if( packet_len < 12 )
  13824. {// minimum packet length
  13825. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13826. return;
  13827. }
  13828. account_id = RFIFOL(fd,info->pos[1]);
  13829. buyer_id = RFIFOL(fd,info->pos[2]);
  13830. itemlist = RFIFOP(fd,info->pos[3]);
  13831. // so that buyingstore_trade knows, how many elements it has access to
  13832. packet_len-= info->pos[3];
  13833. if( packet_len%blocksize )
  13834. {
  13835. 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);
  13836. return;
  13837. }
  13838. count = packet_len/blocksize;
  13839. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13840. }
  13841. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13842. /// 081a <result>.W
  13843. /// result:
  13844. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13845. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13846. /// ? = nothing
  13847. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13848. {
  13849. int fd = sd->fd;
  13850. WFIFOHEAD(fd,packet_len(0x81a));
  13851. WFIFOW(fd,0) = 0x81a;
  13852. WFIFOW(fd,2) = result;
  13853. WFIFOSET(fd,packet_len(0x81a));
  13854. }
  13855. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13856. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13857. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13858. {
  13859. int fd = sd->fd;
  13860. WFIFOHEAD(fd,packet_len(0x81b));
  13861. WFIFOW(fd,0) = 0x81b;
  13862. WFIFOW(fd,2) = nameid;
  13863. WFIFOW(fd,4) = amount; // amount of nameid received
  13864. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13865. WFIFOSET(fd,packet_len(0x81b));
  13866. }
  13867. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13868. /// 081c <index>.W <amount>.W <price>.L
  13869. /// message:
  13870. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13871. ///
  13872. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13873. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13874. {
  13875. int fd = sd->fd;
  13876. WFIFOHEAD(fd,packet_len(0x81c));
  13877. WFIFOW(fd,0) = 0x81c;
  13878. WFIFOW(fd,2) = index+2;
  13879. WFIFOW(fd,4) = amount;
  13880. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13881. WFIFOSET(fd,packet_len(0x81c));
  13882. }
  13883. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13884. /// 0824 <result>.W <name id>.W
  13885. /// result:
  13886. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13887. /// 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)
  13888. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13889. /// ? = nothing
  13890. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13891. {
  13892. int fd = sd->fd;
  13893. WFIFOHEAD(fd,packet_len(0x824));
  13894. WFIFOW(fd,0) = 0x824;
  13895. WFIFOW(fd,2) = result;
  13896. WFIFOW(fd,4) = nameid;
  13897. WFIFOSET(fd,packet_len(0x824));
  13898. }
  13899. /// Search Store Info System
  13900. ///
  13901. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13902. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13903. /// type:
  13904. /// 0 = Vending
  13905. /// 1 = Buying Store
  13906. ///
  13907. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13908. /// amount of card slots. If the client does not know about the item it
  13909. /// cannot be searched.
  13910. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13911. {
  13912. const unsigned int blocksize = 2;
  13913. const uint8* itemlist;
  13914. const uint8* cardlist;
  13915. unsigned char type;
  13916. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13917. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13918. packet_len = RFIFOW(fd,info->pos[0]);
  13919. if( packet_len < 15 )
  13920. {// minimum packet length
  13921. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13922. return;
  13923. }
  13924. type = RFIFOB(fd,info->pos[1]);
  13925. max_price = RFIFOL(fd,info->pos[2]);
  13926. min_price = RFIFOL(fd,info->pos[3]);
  13927. item_count = RFIFOB(fd,info->pos[4]);
  13928. card_count = RFIFOB(fd,info->pos[5]);
  13929. itemlist = RFIFOP(fd,info->pos[6]);
  13930. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13931. // check, if there is enough data for the claimed count of items
  13932. packet_len-= info->pos[6];
  13933. if( packet_len%blocksize )
  13934. {
  13935. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13936. return;
  13937. }
  13938. count = packet_len/blocksize;
  13939. if( count < item_count+card_count )
  13940. {
  13941. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13942. return;
  13943. }
  13944. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13945. }
  13946. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13947. /// 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 }*
  13948. /// is first page:
  13949. /// 0 = appends to existing results
  13950. /// 1 = clears previous results before displaying this result set
  13951. /// is next page:
  13952. /// 0 = no "next" label
  13953. /// 1 = "next" label to retrieve more results
  13954. void clif_search_store_info_ack(struct map_session_data* sd)
  13955. {
  13956. const unsigned int blocksize = MESSAGE_SIZE+26;
  13957. int fd = sd->fd;
  13958. unsigned int i, start, end;
  13959. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13960. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13961. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13962. WFIFOW(fd,0) = 0x836;
  13963. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13964. WFIFOB(fd,4) = !sd->searchstore.pages;
  13965. WFIFOB(fd,5) = searchstore_querynext(sd);
  13966. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13967. for( i = start; i < end; i++ ) {
  13968. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13969. struct item it;
  13970. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13971. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13972. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13973. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13974. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  13975. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13976. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13977. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13978. // make-up an item for clif_addcards
  13979. memset(&it, 0, sizeof(it));
  13980. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13981. it.nameid = ssitem->nameid;
  13982. it.amount = ssitem->amount;
  13983. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13984. }
  13985. WFIFOSET(fd,WFIFOW(fd,2));
  13986. }
  13987. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13988. /// 0837 <reason>.B
  13989. /// reason:
  13990. /// 0 = "No matching stores were found." (0x70b)
  13991. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13992. /// 2 = "You cannot search anymore." (0x706)
  13993. /// 3 = "You cannot search yet." (0x708)
  13994. /// 4 = "No sale (purchase) information available." (0x705)
  13995. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13996. {
  13997. int fd = sd->fd;
  13998. WFIFOHEAD(fd,packet_len(0x837));
  13999. WFIFOW(fd,0) = 0x837;
  14000. WFIFOB(fd,2) = reason;
  14001. WFIFOSET(fd,packet_len(0x837));
  14002. }
  14003. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14004. /// 0838
  14005. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14006. {
  14007. searchstore_next(sd);
  14008. }
  14009. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14010. /// 083a <type>.W <remaining uses>.B
  14011. /// type:
  14012. /// 0 = Search Stores
  14013. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14014. void clif_open_search_store_info(struct map_session_data* sd)
  14015. {
  14016. int fd = sd->fd;
  14017. WFIFOHEAD(fd,packet_len(0x83a));
  14018. WFIFOW(fd,0) = 0x83a;
  14019. WFIFOW(fd,2) = sd->searchstore.effect;
  14020. #if PACKETVER > 20100701
  14021. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14022. #endif
  14023. WFIFOSET(fd,packet_len(0x83a));
  14024. }
  14025. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14026. /// 083b
  14027. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14028. {
  14029. searchstore_close(sd);
  14030. }
  14031. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14032. /// 083c <account id>.L <store id>.L <nameid>.W
  14033. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14034. {
  14035. unsigned short nameid;
  14036. int account_id, store_id;
  14037. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14038. account_id = RFIFOL(fd,info->pos[0]);
  14039. store_id = RFIFOL(fd,info->pos[1]);
  14040. nameid = RFIFOW(fd,info->pos[2]);
  14041. searchstore_click(sd, account_id, store_id, nameid);
  14042. }
  14043. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14044. /// 083d <xPos>.W <yPos>.W
  14045. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14046. {
  14047. int fd = sd->fd;
  14048. WFIFOHEAD(fd,packet_len(0x83d));
  14049. WFIFOW(fd,0) = 0x83d;
  14050. WFIFOW(fd,2) = x;
  14051. WFIFOW(fd,4) = y;
  14052. WFIFOSET(fd,packet_len(0x83d));
  14053. }
  14054. /// Parse function for packet debugging.
  14055. void clif_parse_debug(int fd,struct map_session_data *sd)
  14056. {
  14057. int cmd, packet_len;
  14058. // clif_parse ensures, that there is at least 2 bytes of data
  14059. cmd = RFIFOW(fd,0);
  14060. if( sd ) {
  14061. packet_len = packet_db[sd->packet_ver][cmd].len;
  14062. if( packet_len == 0 )
  14063. {// unknown
  14064. packet_len = RFIFOREST(fd);
  14065. }
  14066. else if( packet_len == -1 )
  14067. {// variable length
  14068. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14069. }
  14070. 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);
  14071. }
  14072. else
  14073. {
  14074. packet_len = RFIFOREST(fd);
  14075. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14076. }
  14077. ShowDump(RFIFOP(fd,0), packet_len);
  14078. }
  14079. /*==========================================
  14080. * Server tells client to display a window similar to Magnifier (item) one
  14081. * Server populates the window with avilable elemental converter options according to player's inventory
  14082. *------------------------------------------*/
  14083. int clif_elementalconverter_list(struct map_session_data *sd) {
  14084. int i,c,view,fd;
  14085. nullpo_ret(sd);
  14086. /// Main client packet processing function
  14087. fd=sd->fd;
  14088. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14089. WFIFOW(fd, 0)=0x1ad;
  14090. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14091. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14092. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14093. WFIFOW(fd,c*2+ 4)= view;
  14094. else
  14095. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14096. c++;
  14097. }
  14098. }
  14099. WFIFOW(fd,2) = c*2+4;
  14100. WFIFOSET(fd, WFIFOW(fd,2));
  14101. if (c > 0) {
  14102. sd->menuskill_id = SA_CREATECON;
  14103. sd->menuskill_val = c;
  14104. }
  14105. return 0;
  14106. }
  14107. /**
  14108. * Rune Knight
  14109. **/
  14110. void clif_millenniumshield(struct block_list *bl, short shields) {
  14111. #if PACKETVER >= 20081217
  14112. unsigned char buf[10];
  14113. WBUFW(buf,0) = 0x440;
  14114. WBUFL(buf,2) = bl->id;
  14115. WBUFW(buf,6) = shields;
  14116. WBUFW(buf,8) = 0;
  14117. clif_send(buf,packet_len(0x440),bl,AREA);
  14118. #endif
  14119. }
  14120. /**
  14121. * Warlock
  14122. **/
  14123. /*==========================================
  14124. * Spellbook list [LimitLine/3CeAM]
  14125. *------------------------------------------*/
  14126. int clif_spellbook_list(struct map_session_data *sd)
  14127. {
  14128. int i, c;
  14129. int fd;
  14130. nullpo_ret(sd);
  14131. fd = sd->fd;
  14132. WFIFOHEAD(fd, 8 * 8 + 8);
  14133. WFIFOW(fd,0) = 0x1ad;
  14134. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14135. {
  14136. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14137. {
  14138. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14139. c++;
  14140. }
  14141. }
  14142. if( c > 0 )
  14143. {
  14144. WFIFOW(fd,2) = c * 2 + 4;
  14145. WFIFOSET(fd, WFIFOW(fd, 2));
  14146. sd->menuskill_id = WL_READING_SB;
  14147. sd->menuskill_val = c;
  14148. }
  14149. else{
  14150. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14151. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14152. }
  14153. return 1;
  14154. }
  14155. /**
  14156. * Mechanic
  14157. **/
  14158. /*==========================================
  14159. * Magic Decoy Material List
  14160. *------------------------------------------*/
  14161. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14162. int i, c;
  14163. int fd;
  14164. nullpo_ret(sd);
  14165. fd = sd->fd;
  14166. WFIFOHEAD(fd, 8 * 8 + 8);
  14167. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14168. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14169. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14170. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14171. c ++;
  14172. }
  14173. }
  14174. if( c > 0 ) {
  14175. sd->menuskill_id = NC_MAGICDECOY;
  14176. sd->menuskill_val = skill_lv;
  14177. sd->sc.comet_x = x;
  14178. sd->sc.comet_y = y;
  14179. WFIFOW(fd,2) = c * 2 + 4;
  14180. WFIFOSET(fd, WFIFOW(fd, 2));
  14181. } else {
  14182. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14183. return 0;
  14184. }
  14185. return 1;
  14186. }
  14187. /*==========================================
  14188. * Guillotine Cross Poisons List
  14189. *------------------------------------------*/
  14190. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14191. int i, c;
  14192. int fd;
  14193. nullpo_ret(sd);
  14194. fd = sd->fd;
  14195. WFIFOHEAD(fd, 8 * 8 + 8);
  14196. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14197. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14198. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14199. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14200. c ++;
  14201. }
  14202. }
  14203. if( c > 0 ) {
  14204. sd->menuskill_id = GC_POISONINGWEAPON;
  14205. sd->menuskill_val = skill_lv;
  14206. WFIFOW(fd,2) = c * 2 + 4;
  14207. WFIFOSET(fd, WFIFOW(fd, 2));
  14208. } else {
  14209. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14210. return 0;
  14211. }
  14212. return 1;
  14213. }
  14214. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14215. int fd, i, c;
  14216. nullpo_ret(sd);
  14217. fd = sd->fd;
  14218. if( !fd ) return 0;
  14219. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14220. return 0;
  14221. WFIFOHEAD(fd, 2 * 6 + 4);
  14222. WFIFOW(fd,0) = 0x442;
  14223. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14224. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14225. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14226. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14227. {
  14228. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14229. c++;
  14230. }
  14231. if( c > 0 ) {
  14232. WFIFOW(fd,2) = 8 + c * 2;
  14233. WFIFOL(fd,4) = c;
  14234. WFIFOSET(fd,WFIFOW(fd,2));
  14235. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14236. sd->menuskill_val = c;
  14237. } else {
  14238. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14239. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14240. }
  14241. return 1;
  14242. }
  14243. /*===========================================
  14244. * Skill list for Four Elemental Analysis
  14245. * and Change Material skills.
  14246. *------------------------------------------*/
  14247. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14248. {
  14249. #if PACKETVER >= 20090922
  14250. int fd;
  14251. nullpo_ret(sd);
  14252. sd->menuskill_id = skill_id; // To prevent hacking.
  14253. sd->menuskill_val = skill_lv;
  14254. if( skill_id == GN_CHANGEMATERIAL )
  14255. skill_lv = 0; // Changematerial
  14256. fd = sd->fd;
  14257. WFIFOHEAD(fd,packet_len(0x7e3));
  14258. WFIFOW(fd,0) = 0x7e3;
  14259. WFIFOL(fd,2) = skill_lv;
  14260. WFIFOL(fd,4) = 0;
  14261. WFIFOSET(fd,packet_len(0x7e3));
  14262. #endif
  14263. return 1;
  14264. }
  14265. // msgstringtable.txt
  14266. // 0x291 <line>.W
  14267. void clif_msgtable(int fd, int line) {
  14268. WFIFOHEAD(fd, packet_len(0x291));
  14269. WFIFOW(fd, 0) = 0x291;
  14270. WFIFOW(fd, 2) = line;
  14271. WFIFOSET(fd, packet_len(0x291));
  14272. }
  14273. // msgstringtable.txt
  14274. // 0x7e2 <line>.W <value>.L
  14275. void clif_msgtable_num(int fd, int line, int num) {
  14276. #if PACKETVER >= 20090805
  14277. WFIFOHEAD(fd, packet_len(0x7e2));
  14278. WFIFOW(fd, 0) = 0x7e2;
  14279. WFIFOW(fd, 2) = line;
  14280. WFIFOL(fd, 4) = num;
  14281. WFIFOSET(fd, packet_len(0x7e2));
  14282. #endif
  14283. }
  14284. /*==========================================
  14285. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14286. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14287. * RFIFOL(fd,2) - type (currently not used)
  14288. *------------------------------------------*/
  14289. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14290. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14291. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14292. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14293. return;
  14294. if( pc_istrading(sd) ) {
  14295. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14296. clif_menuskill_clear(sd);
  14297. return;
  14298. }
  14299. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14300. clif_menuskill_clear(sd);
  14301. }
  14302. /*==========================================
  14303. * Kagerou/Oboro amulet spirit
  14304. *------------------------------------------*/
  14305. void clif_talisman(struct map_session_data *sd,short type)
  14306. {
  14307. unsigned char buf[10];
  14308. nullpo_retv(sd);
  14309. WBUFW(buf,0)=0x08cf;
  14310. WBUFL(buf,2)=sd->bl.id;
  14311. WBUFW(buf,6)=type;
  14312. WBUFW(buf,8)=sd->talisman[type];
  14313. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14314. }
  14315. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14316. /// 0907 <index>.W
  14317. ///
  14318. /// R 0908 <index>.w <type>.b
  14319. /// type:
  14320. /// 0 = move item to personal tab
  14321. /// 1 = move item to normal tab
  14322. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14323. #if PACKETVER >= 20111122
  14324. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14325. int index = RFIFOW(fd,info->pos[0])-2;
  14326. int type = RFIFOB(fd, info->pos[1]);
  14327. /* can't move while dead. */
  14328. if(pc_isdead(sd)) {
  14329. return;
  14330. }
  14331. if (index < 0 || index >= MAX_INVENTORY)
  14332. return;
  14333. if ( sd->status.inventory[index].favorite && type == 1 )
  14334. sd->status.inventory[index].favorite = 0;
  14335. else if( type == 0 )
  14336. sd->status.inventory[index].favorite = 1;
  14337. else
  14338. return;/* nothing to do. */
  14339. clif_favorite_item(sd, index);
  14340. #endif
  14341. }
  14342. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14343. /// 0900 <index>.W <favorite>.B
  14344. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14345. int fd = sd->fd;
  14346. WFIFOHEAD(fd,packet_len(0x908));
  14347. WFIFOW(fd,0) = 0x908;
  14348. WFIFOW(fd,2) = index+2;
  14349. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14350. WFIFOSET(fd,packet_len(0x908));
  14351. }
  14352. void clif_snap( struct block_list *bl, short x, short y ) {
  14353. unsigned char buf[10];
  14354. WBUFW(buf,0) = 0x8d2;
  14355. WBUFL(buf,2) = bl->id;
  14356. WBUFW(buf,6) = x;
  14357. WBUFW(buf,8) = y;
  14358. clif_send(buf,packet_len(0x8d2),bl,AREA);
  14359. }
  14360. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14361. #if PACKETVER >= 20120404
  14362. WFIFOHEAD(fd,packet_len(0x977));
  14363. WFIFOW(fd,0) = 0x977;
  14364. WFIFOL(fd,2) = md->bl.id;
  14365. WFIFOL(fd,6) = md->status.hp;
  14366. WFIFOL(fd,10) = md->status.max_hp;
  14367. WFIFOSET(fd,packet_len(0x977));
  14368. #endif
  14369. }
  14370. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14371. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14372. return;
  14373. }
  14374. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14375. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14376. WFIFOW(sd->fd,0) = 0x2c9;
  14377. WFIFOB(sd->fd,2) = flag;
  14378. WFIFOSET(sd->fd, packet_len(0x2c9));
  14379. }
  14380. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14381. /// 0979 <world name>.24B <char name>.24B
  14382. void clif_ackworldinfo(struct map_session_data* sd) {
  14383. int fd;
  14384. nullpo_retv(sd);
  14385. fd = sd->fd;
  14386. WFIFOHEAD(fd,packet_len(0x979));
  14387. WFIFOW(fd,0)=0x979;
  14388. //AID -> world name ?
  14389. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14390. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14391. WFIFOSET(fd,packet_len(0x979));
  14392. }
  14393. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14394. /// 0978 <AID>.L
  14395. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14396. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14397. if(sd) clif_ackworldinfo(sd);
  14398. }
  14399. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14400. /// 0447
  14401. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14402. //if(sd)
  14403. ;
  14404. }
  14405. /// req world info (CZ_CLIENT_VERSION)
  14406. /// 044A <version>.L
  14407. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14408. //if(sd)
  14409. ;
  14410. }
  14411. /// Ranking list
  14412. /// ranking pointlist { <name>.24B <point>.L }*10
  14413. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14414. struct fame_list* list;
  14415. int skip = 0;
  14416. switch(rankingtype+1) { //to keep the same case as char.c
  14417. case 1: list = smith_fame_list; break;
  14418. case 2: list = chemist_fame_list; break;
  14419. case 3: list = taekwon_fame_list; break;
  14420. default: skip=1; break;
  14421. }
  14422. if(!skip) {
  14423. int i;
  14424. //Packet size limits this list to 10 elements. [Skotlex]
  14425. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14426. if (list[i].id > 0) {
  14427. const char* name;
  14428. if (strcmp(list[i].name, "-") == 0 &&
  14429. (name = map_charid2nick(list[i].id)) != NULL)
  14430. {
  14431. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14432. } else {
  14433. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14434. }
  14435. } else {
  14436. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14437. }
  14438. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14439. }
  14440. for(;i < 10; i++) { //In case the MAX is less than 10.
  14441. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14442. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14443. }
  14444. }
  14445. }
  14446. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14447. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14448. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14449. int mypoint = 0;
  14450. WBUFW(buf,0) = 0x97d;
  14451. WBUFW(buf,2) = rankingType;
  14452. clif_sub_ranklist(buf,4,sd,rankingType);
  14453. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14454. case MAPID_BLACKSMITH:
  14455. case MAPID_ALCHEMIST:
  14456. case MAPID_TAEKWON:
  14457. mypoint = sd->status.fame;
  14458. }
  14459. WBUFL(buf,284) = mypoint; //mypoint
  14460. clif_send(buf, 288, &sd->bl, SELF);
  14461. }
  14462. /*
  14463. * 097c <type> (CZ_REQ_RANKING)
  14464. * type
  14465. * 0: /blacksmith
  14466. * 1: /alchemist
  14467. * 2: /taekwon
  14468. * 3: /pk
  14469. * */
  14470. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14471. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14472. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14473. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14474. }
  14475. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14476. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14477. #if PACKETVER < 20130710
  14478. switch(rankingtype){
  14479. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14480. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14481. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14482. }
  14483. #else
  14484. int fd=sd->fd;
  14485. WFIFOHEAD(fd,14);
  14486. WFIFOW(fd,0) = 0x97e;
  14487. WFIFOW(fd,2) = rankingtype;
  14488. WFIFOL(fd,4) = point;
  14489. WFIFOL(fd,8) = sd->status.fame;
  14490. WFIFOSET(fd,12);
  14491. #endif
  14492. }
  14493. /**
  14494. * Transmit personal information to player. (rates)
  14495. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14496. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14497. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14498. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14499. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14500. * FIXME!
  14501. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14502. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14503. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14504. */
  14505. #ifdef VIP_ENABLE
  14506. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14507. if (sd) {
  14508. struct s_packet_db* info;
  14509. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14510. int cmd = 0, fd, i = 0;
  14511. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14512. int details_bexp[PINFO_MAX];
  14513. int details_drop[PINFO_MAX];
  14514. int details_penalty[PINFO_MAX];
  14515. int penalty_const;
  14516. /**
  14517. * Set for EXP
  14518. */
  14519. //0:PCRoom
  14520. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14521. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14522. details_bexp[0] = 0;
  14523. else {
  14524. if (details_bexp[0] < 100) {
  14525. details_bexp[0] = 100 - details_bexp[0];
  14526. details_bexp[0] = 0 - details_bexp[0];
  14527. }
  14528. else
  14529. details_bexp[0] = details_bexp[0] - 100;
  14530. }
  14531. //1:Premium
  14532. if (pc_isvip(sd)) {
  14533. details_bexp[1] = battle_config.vip_base_exp_increase;
  14534. if (details_bexp[1] < 0)
  14535. details_bexp[1] = 0 - details_bexp[1];
  14536. }
  14537. else
  14538. details_bexp[1] = 0;
  14539. //2:Server
  14540. details_bexp[2] = battle_config.base_exp_rate;
  14541. if (details_bexp[2] == 100)
  14542. details_bexp[2] = 0;
  14543. else {
  14544. if (details_bexp[2] < 100) {
  14545. details_bexp[2] = 100 - details_bexp[2];
  14546. details_bexp[2] = 0 - details_bexp[2];
  14547. }
  14548. else
  14549. details_bexp[2] = details_bexp[2] - 100;
  14550. }
  14551. //3:TPLUS
  14552. details_bexp[3] = 0;
  14553. /* End - EXP set*/
  14554. /**
  14555. * Set for Drop rate
  14556. */
  14557. //0:PCRoom
  14558. details_drop[0] = 0;
  14559. //1:Premium
  14560. details_drop[1] = battle_config.vip_drop_increase;
  14561. if (pc_isvip(sd)) {
  14562. if (details_drop[1] < 0)
  14563. details_drop[1] = 0 - details_drop[1];
  14564. }
  14565. else
  14566. details_drop[1] = 0;
  14567. //2:Server
  14568. details_drop[2] = battle_config.item_rate_common;
  14569. if (details_drop[2] == 100)
  14570. details_drop[2] = 0;
  14571. else {
  14572. if (details_drop[2] < 100) {
  14573. details_drop[2] = 100 - details_drop[2];
  14574. details_drop[2] = 0 - details_drop[2];
  14575. }
  14576. else
  14577. details_drop[2] = details_drop[2] - 100;
  14578. }
  14579. //3:TPLUS
  14580. details_drop[3] = 0;
  14581. /* End - Drop set*/
  14582. /**
  14583. * Set for Penalty rate
  14584. */
  14585. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14586. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14587. //0:PCRoom
  14588. details_penalty[0] = 0;
  14589. //1:Premium
  14590. if (pc_isvip(sd)) {
  14591. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14592. if (details_penalty[1] == 100)
  14593. details_penalty[1] = 0;
  14594. else {
  14595. if (details_penalty[1] < 100) {
  14596. details_penalty[1] = 100 - details_penalty[1];
  14597. details_penalty[1] = 0 - details_penalty[1];
  14598. }
  14599. else
  14600. details_penalty[1] = details_penalty[1] - 100;
  14601. }
  14602. }
  14603. else
  14604. details_penalty[1] = 0;
  14605. //2:Server
  14606. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14607. if (details_penalty[2] == 100)
  14608. details_penalty[2] = 0;
  14609. else {
  14610. if (details_penalty[2] < 100) {
  14611. details_penalty[2] = 100 - details_penalty[2];
  14612. details_penalty[2] = 0 - details_penalty[2];
  14613. }
  14614. else
  14615. details_penalty[2] = details_penalty[2] - 100;
  14616. }
  14617. //3:TPLUS
  14618. details_penalty[3] = 0;
  14619. /* End - Penalty set*/
  14620. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14621. info = &packet_db[sd->packet_ver][cmd];
  14622. len = info->len; //this is the base len without details
  14623. if(!len) return; //version as packet disable
  14624. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14625. szdetails = 7;
  14626. factor = 1;
  14627. }
  14628. else if (cmd == 0x097b) {
  14629. tot_baseexp *= factor;
  14630. tot_drop *= factor;
  14631. tot_penalty *= factor;
  14632. }
  14633. fd = sd->fd;
  14634. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14635. WFIFOW(fd,0) = cmd;
  14636. for (i = 0; i < maxinfotype; i++) {
  14637. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14638. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14639. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14640. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14641. tot_baseexp += details_bexp[i]*factor;
  14642. tot_drop += details_penalty[i]*factor;
  14643. tot_penalty += details_drop[i]*factor;
  14644. len += szdetails;
  14645. }
  14646. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14647. if (cmd == 0x08cb) { //0x08cb version
  14648. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14649. WFIFOW(fd,info->pos[2]) = tot_drop;
  14650. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14651. }
  14652. else { //2013-08-07aRagexe uses 0x097b
  14653. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14654. WFIFOL(fd,info->pos[2]) = tot_drop;
  14655. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14656. }
  14657. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14658. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14659. WFIFOSET(fd,len);
  14660. }
  14661. }
  14662. #endif
  14663. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14664. char cmd[30];
  14665. int t_aid = RFIFOL(fd,2);
  14666. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14667. is_atcommand(fd, sd, cmd, 1);
  14668. }
  14669. /**
  14670. * Marks Crimson Marker target on mini-map to the caster
  14671. * TODO: Please, check the proper packet for Crimson Marker [Cydh]
  14672. * @param fd
  14673. * @param bl Crimson Marker target
  14674. * @param remove True remove the marker from map, false therwise
  14675. **/
  14676. void clif_crimson_marker(int fd, struct block_list *bl, bool remove) {
  14677. WFIFOHEAD(fd,packet_len(0x107));
  14678. WFIFOW(fd,0) = 0x107;
  14679. WFIFOL(fd,2) = bl->id;
  14680. WFIFOW(fd,6) = (remove) ? -1 : bl->x;
  14681. WFIFOW(fd,8) = (remove) ? -1 : bl->y;
  14682. WFIFOSET(fd,packet_len(0x107));
  14683. }
  14684. ///TODO: Special item that obtained, must be broadcasted by this packet
  14685. //void clif_broadcast_obtain_special_item() {}
  14686. #ifdef DUMP_UNKNOWN_PACKET
  14687. void DumpUnknow(int fd,TBL_PC *sd,int cmd,int packet_len){
  14688. const char* packet_txt = "save/packet.txt";
  14689. FILE* fp;
  14690. time_t time_server;
  14691. struct tm *datetime;
  14692. char datestr[512];
  14693. time(&time_server); // get time in seconds since 1/1/1970
  14694. datetime = localtime(&time_server); // convert seconds in structure
  14695. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14696. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14697. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14698. if( sd ) {
  14699. 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);
  14700. } else {
  14701. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14702. }
  14703. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14704. fprintf(fp, "\n");
  14705. fclose(fp);
  14706. } else {
  14707. ShowError("Failed to write '%s'.\n", packet_txt);
  14708. // Dump on console instead
  14709. if( sd ) {
  14710. 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);
  14711. } else {
  14712. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14713. }
  14714. ShowDump(RFIFOP(fd,0), packet_len);
  14715. }
  14716. }
  14717. #endif
  14718. /*==========================================
  14719. * Main client packet processing function
  14720. *------------------------------------------*/
  14721. static int clif_parse(int fd)
  14722. {
  14723. int cmd, packet_ver, packet_len, err;
  14724. TBL_PC* sd;
  14725. int pnum;
  14726. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14727. // Note: "click masters" can do 80+ clicks in 10 seconds
  14728. 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]
  14729. { // begin main client packet processing loop
  14730. sd = (TBL_PC *)session[fd]->session_data;
  14731. if (session[fd]->flag.eof) {
  14732. if (sd) {
  14733. if (sd->state.autotrade) {
  14734. //Disassociate character from the socket connection.
  14735. session[fd]->session_data = NULL;
  14736. sd->fd = 0;
  14737. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14738. } else
  14739. if (sd->state.active) {
  14740. // Player logout display [Valaris]
  14741. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14742. clif_quitsave(fd, sd);
  14743. } else {
  14744. //Unusual logout (during log on/off/map-changer procedure)
  14745. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14746. map_quit(sd);
  14747. }
  14748. } else {
  14749. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14750. }
  14751. do_close(fd);
  14752. return 0;
  14753. }
  14754. if (RFIFOREST(fd) < 2)
  14755. return 0;
  14756. cmd = RFIFOW(fd,0);
  14757. // identify client's packet version
  14758. if (sd) {
  14759. packet_ver = sd->packet_ver;
  14760. } else {
  14761. // check authentification packet to know packet version
  14762. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14763. if( err ) {// failed to identify packet version
  14764. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14765. err == 1 ? "" :
  14766. err == 2 ? ", possibly for having an invalid account_id" :
  14767. err == 3 ? ", possibly for having an invalid char_id." :
  14768. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14769. err == 4 ? ", possibly for having an invalid login_id1." :
  14770. err == 5 ? ", possibly for having an invalid client_tick." :
  14771. */
  14772. err == 6 ? ", possibly for having an invalid sex." :
  14773. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14774. WFIFOHEAD(fd,packet_len(0x6a));
  14775. WFIFOW(fd,0) = 0x6a;
  14776. WFIFOB(fd,2) = 3; // Rejected from Server
  14777. WFIFOSET(fd,packet_len(0x6a));
  14778. #ifdef DUMP_INVALID_PACKET
  14779. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14780. #endif
  14781. RFIFOSKIP(fd, RFIFOREST(fd));
  14782. set_eof(fd);
  14783. return 0;
  14784. }
  14785. }
  14786. // filter out invalid / unsupported packets
  14787. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14788. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14789. #ifdef DUMP_INVALID_PACKET
  14790. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14791. #endif
  14792. set_eof(fd);
  14793. return 0;
  14794. }
  14795. // determine real packet length
  14796. packet_len = packet_db[packet_ver][cmd].len;
  14797. if (packet_len == -1) { // variable-length packet
  14798. if (RFIFOREST(fd) < 4)
  14799. return 0;
  14800. packet_len = RFIFOW(fd,2);
  14801. if (packet_len < 4 || packet_len > 32768) {
  14802. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14803. #ifdef DUMP_INVALID_PACKET
  14804. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14805. #endif
  14806. set_eof(fd);
  14807. return 0;
  14808. }
  14809. }
  14810. if ((int)RFIFOREST(fd) < packet_len)
  14811. return 0; // not enough data received to form the packet
  14812. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14813. packet_db[packet_ver][cmd].func(fd, sd);
  14814. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14815. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14816. ; //Only valid packet when there is no session
  14817. else
  14818. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14819. ; //Only valid packet when player is not on a map
  14820. else
  14821. packet_db[packet_ver][cmd].func(fd, sd);
  14822. }
  14823. #ifdef DUMP_UNKNOWN_PACKET
  14824. else DumpUnknow(fd,sd,cmd,packet_len);
  14825. #endif
  14826. RFIFOSKIP(fd, packet_len);
  14827. }; // main loop end
  14828. return 0;
  14829. }
  14830. /*==========================================
  14831. * Reads packet_db.txt and setups its array reference
  14832. *------------------------------------------*/
  14833. void packetdb_readdb(void)
  14834. {
  14835. FILE *fp;
  14836. char line[1024];
  14837. int cmd,i,j;
  14838. int max_cmd=-1;
  14839. bool skip_ver = false;
  14840. int warned = 0;
  14841. char *str[64],*p,*str2[64],*p2,w1[256],w2[256];
  14842. int packet_len_table[MAX_PACKET_DB] = {
  14843. 10, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14847. //#0x0040
  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. #if PACKETVER <= 20081217
  14851. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14852. #else
  14853. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14854. #endif
  14855. #if PACKETVER < 2
  14856. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14857. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14858. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14859. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14860. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14861. #else
  14862. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14863. #endif
  14864. //#0x0080
  14865. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14866. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14867. #if PACKETVER <= 20100622
  14868. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14869. #else
  14870. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14871. #endif
  14872. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14873. //#0x00C0
  14874. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14875. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14876. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14877. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14878. //#0x0100
  14879. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14880. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14881. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14882. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14883. //#0x0140
  14884. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14885. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14886. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14887. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14888. //#0x0180
  14889. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14890. #if PACKETVER < 1
  14891. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14892. #else // 196 comodo icon status display for later
  14893. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14894. #endif
  14895. #if PACKETVER < 20081126
  14896. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14897. #else // 0x1a2 changed (35->37)
  14898. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14899. #endif
  14900. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14901. //#0x01C0, Set 0x1d5=-1
  14902. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14903. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14904. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14905. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14906. //#0x0200
  14907. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14908. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14909. #if PACKETVER < 20071106
  14910. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14911. #else // 0x22c changed
  14912. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14913. #endif
  14914. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14915. //#0x0240
  14916. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14917. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14918. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14919. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14920. //#0x0280
  14921. #if PACKETVER < 20070711
  14922. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14923. #else
  14924. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14925. #endif
  14926. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14927. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14928. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14929. //#0x02C0
  14930. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14931. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14932. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14933. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14934. //#0x0300
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14939. //#0x0340
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14944. //#0x0380
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14949. //#0x03C0
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14954. //#0x0400
  14955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14959. //#0x0440
  14960. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14964. //#0x0480
  14965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14969. //#0x04C0
  14970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14974. //#0x0500
  14975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14979. //#0x0540
  14980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14984. //#0x0580
  14985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14989. //#0x05C0
  14990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14994. //#0x0600
  14995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14999. //#0x0640
  15000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15004. //#0x0680
  15005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15009. //#0x06C0
  15010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15014. //#0x0700
  15015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15019. //#0x0740
  15020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15024. //#0x0780
  15025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15029. //#0x07C0
  15030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15031. #if PACKETVER < 20090617
  15032. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15033. #else // 0x7d9 changed
  15034. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15035. #endif
  15036. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15037. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  15038. //#0x0800
  15039. #if PACKETVER < 20091229
  15040. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15041. #else // for Party booking ( PACKETVER >= 20091229 )
  15042. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15043. #endif
  15044. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15045. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15046. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15047. //#0x0840
  15048. #if PACKETVER < 20130000
  15049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15050. #else
  15051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15052. #endif
  15053. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  15054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15056. //#0x0880
  15057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15061. //#0x08C0
  15062. 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10,
  15063. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15066. //#0x0900
  15067. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15071. //#0x0940
  15072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15075. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15076. //#0x0980
  15077. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15078. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  15079. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15080. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15081. //#0x09C0
  15082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  15083. 0, 0, 0, 0, 2, 0, -1, 0, 2, 0, 0, 0, 0, 0, 0, 7,
  15084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15086. };
  15087. struct {
  15088. void (*func)(int, struct map_session_data *);
  15089. char *name;
  15090. } clif_parse_func[]={
  15091. {clif_parse_WantToConnection,"wanttoconnection"},
  15092. {clif_parse_LoadEndAck,"loadendack"},
  15093. {clif_parse_TickSend,"ticksend"},
  15094. {clif_parse_WalkToXY,"walktoxy"},
  15095. {clif_parse_QuitGame,"quitgame"},
  15096. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15097. {clif_parse_GlobalMessage,"globalmessage"},
  15098. {clif_parse_MapMove,"mapmove"},
  15099. {clif_parse_ChangeDir,"changedir"},
  15100. {clif_parse_Emotion,"emotion"},
  15101. {clif_parse_HowManyConnections,"howmanyconnections"},
  15102. {clif_parse_ActionRequest,"actionrequest"},
  15103. {clif_parse_Restart,"restart"},
  15104. {clif_parse_WisMessage,"wis"},
  15105. {clif_parse_Broadcast,"broadcast"},
  15106. {clif_parse_TakeItem,"takeitem"},
  15107. {clif_parse_DropItem,"dropitem"},
  15108. {clif_parse_UseItem,"useitem"},
  15109. {clif_parse_EquipItem,"equipitem"},
  15110. {clif_parse_UnequipItem,"unequipitem"},
  15111. {clif_parse_NpcClicked,"npcclicked"},
  15112. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15113. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15114. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15115. {clif_parse_CreateChatRoom,"createchatroom"},
  15116. {clif_parse_ChatAddMember,"chataddmember"},
  15117. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15118. {clif_parse_ChangeChatOwner,"changechatowner"},
  15119. {clif_parse_KickFromChat,"kickfromchat"},
  15120. {clif_parse_ChatLeave,"chatleave"},
  15121. {clif_parse_TradeRequest,"traderequest"},
  15122. {clif_parse_TradeAck,"tradeack"},
  15123. {clif_parse_TradeAddItem,"tradeadditem"},
  15124. {clif_parse_TradeOk,"tradeok"},
  15125. {clif_parse_TradeCancel,"tradecancel"},
  15126. {clif_parse_TradeCommit,"tradecommit"},
  15127. {clif_parse_StopAttack,"stopattack"},
  15128. {clif_parse_PutItemToCart,"putitemtocart"},
  15129. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15130. {clif_parse_RemoveOption,"removeoption"},
  15131. {clif_parse_ChangeCart,"changecart"},
  15132. {clif_parse_StatusUp,"statusup"},
  15133. {clif_parse_SkillUp,"skillup"},
  15134. {clif_parse_UseSkillToId,"useskilltoid"},
  15135. {clif_parse_UseSkillToPos,"useskilltopos"},
  15136. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15137. {clif_parse_UseSkillMap,"useskillmap"},
  15138. {clif_parse_RequestMemo,"requestmemo"},
  15139. {clif_parse_ProduceMix,"producemix"},
  15140. {clif_parse_Cooking,"cooking"},
  15141. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15142. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15143. {clif_parse_NpcAmountInput,"npcamountinput"},
  15144. {clif_parse_NpcStringInput,"npcstringinput"},
  15145. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15146. {clif_parse_ItemIdentify,"itemidentify"},
  15147. {clif_parse_SelectArrow,"selectarrow"},
  15148. {clif_parse_AutoSpell,"autospell"},
  15149. {clif_parse_UseCard,"usecard"},
  15150. {clif_parse_InsertCard,"insertcard"},
  15151. {clif_parse_RepairItem,"repairitem"},
  15152. {clif_parse_WeaponRefine,"weaponrefine"},
  15153. {clif_parse_SolveCharName,"solvecharname"},
  15154. {clif_parse_ResetChar,"resetchar"},
  15155. {clif_parse_LocalBroadcast,"localbroadcast"},
  15156. {clif_parse_MoveToKafra,"movetokafra"},
  15157. {clif_parse_MoveFromKafra,"movefromkafra"},
  15158. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15159. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15160. {clif_parse_CloseKafra,"closekafra"},
  15161. {clif_parse_CreateParty,"createparty"},
  15162. {clif_parse_CreateParty2,"createparty2"},
  15163. {clif_parse_PartyInvite,"partyinvite"},
  15164. {clif_parse_PartyInvite2,"partyinvite2"},
  15165. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15166. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15167. {clif_parse_LeaveParty,"leaveparty"},
  15168. {clif_parse_RemovePartyMember,"removepartymember"},
  15169. {clif_parse_PartyChangeOption,"partychangeoption"},
  15170. {clif_parse_PartyMessage,"partymessage"},
  15171. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15172. {clif_parse_CloseVending,"closevending"},
  15173. {clif_parse_VendingListReq,"vendinglistreq"},
  15174. {clif_parse_PurchaseReq,"purchasereq"},
  15175. {clif_parse_PurchaseReq2,"purchasereq2"},
  15176. {clif_parse_OpenVending,"openvending"},
  15177. {clif_parse_CreateGuild,"createguild"},
  15178. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15179. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15180. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15181. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15182. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15183. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15184. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15185. {clif_parse_GuildInvite,"guildinvite"},
  15186. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15187. {clif_parse_GuildLeave,"guildleave"},
  15188. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15189. {clif_parse_GuildMessage,"guildmessage"},
  15190. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15191. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15192. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15193. {clif_parse_GuildOpposition,"guildopposition"},
  15194. {clif_parse_GuildBreak,"guildbreak"},
  15195. {clif_parse_PetMenu,"petmenu"},
  15196. {clif_parse_CatchPet,"catchpet"},
  15197. {clif_parse_SelectEgg,"selectegg"},
  15198. {clif_parse_SendEmotion,"sendemotion"},
  15199. {clif_parse_ChangePetName,"changepetname"},
  15200. {clif_parse_GMKick,"gmkick"},
  15201. {clif_parse_GMHide,"gmhide"},
  15202. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15203. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15204. {clif_parse_GMKickAll,"killall"},
  15205. {clif_parse_GMRecall,"recall"},
  15206. {clif_parse_GMRecall,"summon"},
  15207. {clif_parse_GM_Item_Monster,"itemmonster"},
  15208. {clif_parse_GMShift,"remove"},
  15209. {clif_parse_GMShift,"shift"},
  15210. {clif_parse_GMChangeMapType,"changemaptype"},
  15211. {clif_parse_GMRc,"rc"},
  15212. {clif_parse_GMRecall2,"recall2"},
  15213. {clif_parse_GMRemove2,"remove2"},
  15214. {clif_parse_GMFullStrip,"gmfullstrip"},
  15215. {clif_parse_NoviceDoriDori,"sndoridori"},
  15216. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15217. {clif_parse_PMIgnore,"wisexin"},
  15218. {clif_parse_PMIgnoreList,"wisexlist"},
  15219. {clif_parse_PMIgnoreAll,"wisall"},
  15220. {clif_parse_FriendsListAdd,"friendslistadd"},
  15221. {clif_parse_FriendsListRemove,"friendslistremove"},
  15222. {clif_parse_FriendsListReply,"friendslistreply"},
  15223. {clif_parse_Blacksmith,"blacksmith"},
  15224. {clif_parse_Alchemist,"alchemist"},
  15225. {clif_parse_Taekwon,"taekwon"},
  15226. {clif_parse_RankingPk,"rankingpk"},
  15227. {clif_parse_FeelSaveOk,"feelsaveok"},
  15228. {clif_parse_debug,"debug"},
  15229. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15230. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15231. {clif_parse_HomMoveTo,"hommoveto"},
  15232. {clif_parse_HomAttack,"homattack"},
  15233. {clif_parse_HomMenu,"hommenu"},
  15234. {clif_parse_StoragePassword,"storagepassword"},
  15235. {clif_parse_Hotkey,"hotkey"},
  15236. {clif_parse_AutoRevive,"autorevive"},
  15237. {clif_parse_Check,"check"},
  15238. {clif_parse_Adopt_request,"adoptrequest"},
  15239. {clif_parse_Adopt_reply,"adoptreply"},
  15240. // MAIL SYSTEM
  15241. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15242. {clif_parse_Mail_read,"mailread"},
  15243. {clif_parse_Mail_getattach,"mailgetattach"},
  15244. {clif_parse_Mail_delete,"maildelete"},
  15245. {clif_parse_Mail_return,"mailreturn"},
  15246. {clif_parse_Mail_setattach,"mailsetattach"},
  15247. {clif_parse_Mail_winopen,"mailwinopen"},
  15248. {clif_parse_Mail_send,"mailsend"},
  15249. // AUCTION SYSTEM
  15250. {clif_parse_Auction_search,"auctionsearch"},
  15251. {clif_parse_Auction_buysell,"auctionbuysell"},
  15252. {clif_parse_Auction_setitem,"auctionsetitem"},
  15253. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15254. {clif_parse_Auction_register,"auctionregister"},
  15255. {clif_parse_Auction_cancel,"auctioncancel"},
  15256. {clif_parse_Auction_close,"auctionclose"},
  15257. {clif_parse_Auction_bid,"auctionbid"},
  15258. // Quest Log System
  15259. {clif_parse_questStateAck,"queststate"},
  15260. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15261. {clif_parse_EquipTick,"equiptickbox"},
  15262. {clif_parse_BattleChat,"battlechat"},
  15263. {clif_parse_mercenary_action,"mermenu"},
  15264. {clif_parse_progressbar,"progressbar"},
  15265. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15266. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15267. #if PACKETVER >= 20091229
  15268. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15269. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15270. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15271. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15272. #endif
  15273. {clif_parse_BankCheck,"bankcheck"},
  15274. {clif_parse_BankDeposit,"bankdeposit"},
  15275. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15276. {clif_parse_BankOpen,"bankopen"},
  15277. {clif_parse_BankClose,"bankclose"},
  15278. {clif_parse_PVPInfo,"pvpinfo"},
  15279. {clif_parse_LessEffect,"lesseffect"},
  15280. // Buying Store
  15281. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15282. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15283. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15284. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15285. // Store Search
  15286. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15287. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15288. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15289. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15290. // Cashshop
  15291. { clif_parse_cashshop_open_request, "cashshopopen" },
  15292. { clif_parse_cashshop_close, "cashshopclose" },
  15293. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15294. { clif_parse_cashshop_buy, "cashshopbuy" },
  15295. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15296. /* */
  15297. { clif_parse_MoveItem , "moveitem" },
  15298. { clif_parse_PartyTick, "partytick" },
  15299. { clif_parse_dull, "dull" },
  15300. { clif_parse_GuildInvite2 , "guildinvite2" },
  15301. { clif_parse_reqworldinfo, "reqworldinfo"},
  15302. { clif_parse_client_version, "clientversion"},
  15303. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15304. { clif_parse_ranklist, "ranklist"},
  15305. {NULL,NULL}
  15306. };
  15307. struct {
  15308. char *name; //function name
  15309. int funcidx; //
  15310. } clif_ack_func[]={ //hash
  15311. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15312. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15313. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15314. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15315. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15316. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15317. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15318. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15319. };
  15320. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15321. int f;
  15322. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15323. memset(packet_db,0,sizeof(packet_db));
  15324. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15325. packet_len(i) = packet_len_table[i];
  15326. clif_config.packet_db_ver = MAX_PACKET_VER;
  15327. for(f = 0; f<ARRAYLENGTH(filename); f++){
  15328. int ln=0;
  15329. int entries = 0;
  15330. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15331. sprintf(line, "%s/%s", db_path,filename[f]);
  15332. if( (fp=fopen(line,"r"))==NULL ){
  15333. if(f==0) {
  15334. ShowFatalError("Can't read %s\n", line);
  15335. exit(EXIT_FAILURE);
  15336. }
  15337. return;
  15338. }
  15339. while( fgets(line, sizeof(line), fp) ) {
  15340. ln++;
  15341. if(line[0]=='/' && line[1]=='/')
  15342. continue;
  15343. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2)
  15344. {
  15345. if(strcmpi(w1,"packet_ver")==0) {
  15346. int prev_ver = packet_ver;
  15347. skip_ver = false;
  15348. packet_ver = atoi(w2);
  15349. if ( packet_ver > MAX_PACKET_VER )
  15350. { //Check to avoid overflowing. [Skotlex]
  15351. if( (warned&1) == 0 )
  15352. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15353. warned &= 1;
  15354. skip_ver = true;
  15355. }
  15356. else if( packet_ver < 0 )
  15357. {
  15358. if( (warned&2) == 0 )
  15359. ShowWarning("Negative packet versions are not supported.\n");
  15360. warned &= 2;
  15361. skip_ver = true;
  15362. }
  15363. else if( packet_ver == SERVER )
  15364. {
  15365. if( (warned&4) == 0 )
  15366. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15367. warned &= 4;
  15368. skip_ver = true;
  15369. }
  15370. if( skip_ver )
  15371. {
  15372. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15373. packet_ver = prev_ver;
  15374. continue;
  15375. }
  15376. // copy from previous version into new version and continue
  15377. // - indicating all following packets should be read into the newer version
  15378. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15379. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15380. continue;
  15381. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15382. if(strcmpi(w2,"default")==0) //This is the preferred version.
  15383. clif_config.packet_db_ver = MAX_PACKET_VER;
  15384. else // to manually set the packet DB version
  15385. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15386. continue;
  15387. }
  15388. }
  15389. if( skip_ver )
  15390. continue; // Skipping current packet version
  15391. memset(str,0,sizeof(str));
  15392. for(j=0,p=line;j<4 && p; ++j) {
  15393. str[j]=p;
  15394. p=strchr(p,',');
  15395. if(p) *p++=0;
  15396. }
  15397. if(str[0]==NULL)
  15398. continue;
  15399. cmd=strtol(str[0],(char **)NULL,0);
  15400. if(max_cmd < cmd)
  15401. max_cmd = cmd;
  15402. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15403. continue;
  15404. if(str[1]==NULL){
  15405. ShowError("packet_db: packet len error\n");
  15406. continue;
  15407. }
  15408. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15409. if(str[2]==NULL){
  15410. packet_db[packet_ver][cmd].func = NULL;
  15411. ln++;
  15412. continue;
  15413. }
  15414. // look up processing function by name
  15415. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15416. if( j < ARRAYLENGTH(clif_parse_func) )
  15417. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15418. else { //search if it's a mapped ack func
  15419. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15420. if( j < ARRAYLENGTH(clif_ack_func)) {
  15421. int fidx = clif_ack_func[j].funcidx;
  15422. packet_db_ack[packet_ver][fidx] = cmd;
  15423. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15424. }
  15425. }
  15426. // set the identifying cmd for the packet_db version
  15427. if (strcmp(str[2],"wanttoconnection")==0)
  15428. clif_config.connect_cmd[packet_ver] = cmd;
  15429. if(str[3]==NULL){
  15430. ShowError("packet_db: packet error\n");
  15431. exit(EXIT_FAILURE);
  15432. }
  15433. for(j=0,p2=str[3];p2;j++){
  15434. short k;
  15435. str2[j]=p2;
  15436. p2=strchr(p2,':');
  15437. if(p2) *p2++=0;
  15438. k = atoi(str2[j]);
  15439. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15440. if( j >= MAX_PACKET_POS )
  15441. {
  15442. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15443. break;
  15444. }
  15445. packet_db[packet_ver][cmd].pos[j] = k;
  15446. }
  15447. entries++;
  15448. }
  15449. fclose(fp);
  15450. if(max_cmd > MAX_PACKET_DB) {
  15451. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15452. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15453. }
  15454. //Locate the nearest version that we still support. [Skotlex]
  15455. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  15456. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15457. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15458. }
  15459. sprintf(line, "%s/%s", db_path,filename[f]);
  15460. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  15461. }
  15462. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15463. }
  15464. /*==========================================
  15465. *
  15466. *------------------------------------------*/
  15467. void do_init_clif(void) {
  15468. const char* colors[COLOR_MAX] = {
  15469. "0xFF0000",
  15470. "0xFFFFFF",
  15471. "0xFFFF00",
  15472. };
  15473. int i;
  15474. /**
  15475. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15476. **/
  15477. for(i = 0; i < COLOR_MAX; i++) {
  15478. color_table[i] = strtoul(colors[i],NULL,0);
  15479. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15480. }
  15481. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15482. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15483. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15484. packetdb_readdb();
  15485. set_defaultparse(clif_parse);
  15486. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15487. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15488. exit(EXIT_FAILURE);
  15489. }
  15490. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15491. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15492. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15493. }
  15494. void do_final_clif(void) {
  15495. ers_destroy(delay_clearunit_ers);
  15496. }