clif.c 562 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601
  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. #ifdef PACKET_OBFUSCATION
  62. static struct s_packet_keys *packet_keys[MAX_PACKET_VER + 1];
  63. static unsigned int clif_cryptKey[3]; // Used keys
  64. #endif
  65. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd);
  66. static bool clif_session_isValid(struct map_session_data *sd);
  67. /** Converts item type to display it on client if necessary.
  68. * @param nameid: Item ID
  69. * @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
  70. */
  71. static inline int itemtype(unsigned short nameid) {
  72. 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
  73. int type = id->type;
  74. if( type == IT_SHADOWGEAR ) {
  75. if( id->equip&EQP_SHADOW_WEAPON )
  76. return IT_WEAPON;
  77. else
  78. return IT_ARMOR;
  79. }
  80. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  81. }
  82. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  83. p += pos;
  84. p[0] = (uint8)(x>>2);
  85. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  86. p[2] = (uint8)((y<<4) | (dir&0xf));
  87. }
  88. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  89. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  90. p += pos;
  91. p[0] = (uint8)(x0>>2);
  92. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  93. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  94. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  95. p[4] = (uint8)y1;
  96. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  97. }
  98. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  99. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  100. }
  101. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  102. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  103. }
  104. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  105. p += pos;
  106. if( x ) {
  107. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  108. }
  109. if( y ) {
  110. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  111. }
  112. if( dir ) {
  113. dir[0] = ( p[2] & 0x0f );
  114. }
  115. }
  116. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  117. p += pos;
  118. if( x0 ) {
  119. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  120. }
  121. if( y0 ) {
  122. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  123. }
  124. if( x1 ) {
  125. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  126. }
  127. if( y1 ) {
  128. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  129. }
  130. if( sx0 ) {
  131. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  132. }
  133. if( sy0 ) {
  134. sy0[0] = ( p[5] & 0x0f ) >> 0;
  135. }
  136. }
  137. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  138. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  139. }
  140. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  141. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  142. }
  143. //To idenfity disguised characters.
  144. static inline bool disguised(struct block_list* bl) {
  145. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  146. }
  147. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  148. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  149. if( len > max )
  150. len = max;
  151. mes[len-1] = '\0';
  152. return len;
  153. }
  154. static char map_ip_str[128];
  155. static uint32 map_ip;
  156. static uint32 bind_ip = INADDR_ANY;
  157. static uint16 map_port = 5121;
  158. static bool clif_ally_only = false;
  159. int map_fd;
  160. static int clif_parse (int fd);
  161. /*==========================================
  162. * Ip setting of map-server
  163. *------------------------------------------*/
  164. int clif_setip(const char* ip) {
  165. char ip_str[16];
  166. map_ip = host2ip(ip);
  167. if (!map_ip) {
  168. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  169. return 0;
  170. }
  171. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  172. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  173. return 1;
  174. }
  175. void clif_setbindip(const char* ip)
  176. {
  177. bind_ip = host2ip(ip);
  178. if (bind_ip) {
  179. char ip_str[16];
  180. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  181. } else {
  182. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  183. }
  184. }
  185. /*==========================================
  186. * Sets map port to 'port'
  187. * is run from map.c upon loading map server configuration
  188. *------------------------------------------*/
  189. void clif_setport(uint16 port)
  190. {
  191. map_port = port;
  192. }
  193. /*==========================================
  194. * Returns map server IP
  195. *------------------------------------------*/
  196. uint32 clif_getip(void)
  197. {
  198. return map_ip;
  199. }
  200. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  201. uint32 clif_refresh_ip(void)
  202. {
  203. uint32 new_ip;
  204. new_ip = host2ip(map_ip_str);
  205. if (new_ip && new_ip != map_ip) {
  206. map_ip = new_ip;
  207. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  208. return map_ip;
  209. }
  210. return 0;
  211. }
  212. /*==========================================
  213. * Returns map port which is set by clif_setport()
  214. *------------------------------------------*/
  215. uint16 clif_getport(void)
  216. {
  217. return map_port;
  218. }
  219. #if PACKETVER >= 20071106
  220. static inline unsigned char clif_bl_type(struct block_list *bl) {
  221. switch (bl->type) {
  222. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  223. case BL_ITEM: return 0x2; //ITEM_TYPE
  224. case BL_SKILL: return 0x3; //SKILL_TYPE
  225. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  226. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  227. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  228. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  229. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  230. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  231. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  232. default: return 0x1; //NPC_TYPE
  233. }
  234. }
  235. #endif
  236. static bool clif_session_isValid(struct map_session_data *sd) {
  237. if (sd != NULL && sd->packet_ver <= MAX_PACKET_VER && session_isActive(sd->fd))
  238. return true;
  239. return false;
  240. }
  241. /*==========================================
  242. * sub process of clif_send
  243. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  244. * In order to send area-wise packets, such as:
  245. * - AREA : everyone nearby your area
  246. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  247. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  248. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  249. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  250. *------------------------------------------*/
  251. static int clif_send_sub(struct block_list *bl, va_list ap)
  252. {
  253. struct block_list *src_bl;
  254. struct map_session_data *sd;
  255. unsigned char *buf;
  256. int len, type, fd;
  257. nullpo_ret(bl);
  258. nullpo_ret(sd = (struct map_session_data *)bl);
  259. fd = sd->fd;
  260. if (!fd) //Don't send to disconnected clients.
  261. return 0;
  262. buf = va_arg(ap,unsigned char*);
  263. len = va_arg(ap,int);
  264. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  265. type = va_arg(ap,int);
  266. switch(type) {
  267. case AREA_WOS:
  268. if (bl == src_bl)
  269. return 0;
  270. break;
  271. case AREA_WOC:
  272. if (sd->chatID || bl == src_bl)
  273. return 0;
  274. break;
  275. case AREA_WOSC:
  276. {
  277. if(src_bl->type == BL_PC) {
  278. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  279. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  280. return 0;
  281. }
  282. else if(src_bl->type == BL_NPC) {
  283. struct npc_data *nd = (struct npc_data *)src_bl;
  284. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  285. return 0;
  286. }
  287. }
  288. break;
  289. }
  290. if (session[fd] == NULL)
  291. return 0;
  292. /* unless visible, hold it here */
  293. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  294. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  295. return 0;
  296. WFIFOHEAD(fd, len);
  297. if (WFIFOP(fd,0) == buf) {
  298. ShowError("WARNING: Invalid use of clif_send function\n");
  299. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  300. ShowError(" Please correct your code.\n");
  301. // don't send to not move the pointer of the packet for next sessions in the loop
  302. //WFIFOSET(fd,0);//## TODO is this ok?
  303. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  304. return 0;
  305. }
  306. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  307. memcpy(WFIFOP(fd,0), buf, len);
  308. WFIFOSET(fd,len);
  309. }
  310. return 0;
  311. }
  312. /*==========================================
  313. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  314. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  315. *------------------------------------------*/
  316. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  317. {
  318. int i;
  319. struct map_session_data *sd, *tsd;
  320. struct party_data *p = NULL;
  321. struct guild *g = NULL;
  322. struct battleground_data *bg = NULL;
  323. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  324. struct s_mapiterator* iter;
  325. if( type != ALL_CLIENT )
  326. nullpo_ret(bl);
  327. sd = BL_CAST(BL_PC, bl);
  328. switch(type) {
  329. case ALL_CLIENT: //All player clients.
  330. iter = mapit_getallusers();
  331. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  332. {
  333. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  334. { // packet must exist for the client version
  335. WFIFOHEAD(tsd->fd, len);
  336. memcpy(WFIFOP(tsd->fd,0), buf, len);
  337. WFIFOSET(tsd->fd,len);
  338. }
  339. }
  340. mapit_free(iter);
  341. break;
  342. case ALL_SAMEMAP: //All players on the same map
  343. iter = mapit_getallusers();
  344. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  345. {
  346. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  347. { // packet must exist for the client version
  348. WFIFOHEAD(tsd->fd, len);
  349. memcpy(WFIFOP(tsd->fd,0), buf, len);
  350. WFIFOSET(tsd->fd,len);
  351. }
  352. }
  353. mapit_free(iter);
  354. break;
  355. case AREA:
  356. case AREA_WOSC:
  357. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  358. clif_send (buf, len, bl, SELF);
  359. case AREA_WOC:
  360. case AREA_WOS:
  361. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  362. BL_PC, buf, len, bl, type);
  363. break;
  364. case AREA_CHAT_WOC:
  365. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  366. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  367. break;
  368. case CHAT:
  369. case CHAT_WOS:
  370. {
  371. struct chat_data *cd;
  372. if (sd) {
  373. cd = (struct chat_data*)map_id2bl(sd->chatID);
  374. } else if (bl->type == BL_CHAT) {
  375. cd = (struct chat_data*)bl;
  376. } else break;
  377. if (cd == NULL)
  378. break;
  379. for(i = 0; i < cd->users; i++) {
  380. if (type == CHAT_WOS && cd->usersd[i] == sd)
  381. continue;
  382. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  383. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  384. {
  385. WFIFOHEAD(fd,len);
  386. memcpy(WFIFOP(fd,0), buf, len);
  387. WFIFOSET(fd,len);
  388. }
  389. }
  390. }
  391. }
  392. break;
  393. case PARTY_AREA:
  394. case PARTY_AREA_WOS:
  395. x0 = bl->x - AREA_SIZE;
  396. y0 = bl->y - AREA_SIZE;
  397. x1 = bl->x + AREA_SIZE;
  398. y1 = bl->y + AREA_SIZE;
  399. case PARTY:
  400. case PARTY_WOS:
  401. case PARTY_SAMEMAP:
  402. case PARTY_SAMEMAP_WOS:
  403. if (sd && sd->status.party_id)
  404. p = party_search(sd->status.party_id);
  405. if (p) {
  406. for(i=0;i<MAX_PARTY;i++){
  407. if( (sd = p->data[i].sd) == NULL )
  408. continue;
  409. if( !(fd=sd->fd) )
  410. continue;
  411. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  412. continue;
  413. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  414. continue;
  415. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  416. continue;
  417. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  418. { // packet must exist for the client version
  419. WFIFOHEAD(fd,len);
  420. memcpy(WFIFOP(fd,0), buf, len);
  421. WFIFOSET(fd,len);
  422. }
  423. }
  424. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  425. break;
  426. iter = mapit_getallusers();
  427. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  428. {
  429. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  430. { // packet must exist for the client version
  431. WFIFOHEAD(tsd->fd, len);
  432. memcpy(WFIFOP(tsd->fd,0), buf, len);
  433. WFIFOSET(tsd->fd,len);
  434. }
  435. }
  436. mapit_free(iter);
  437. }
  438. break;
  439. case DUEL:
  440. case DUEL_WOS:
  441. if (!sd || !sd->duel_group) break; //Invalid usage.
  442. iter = mapit_getallusers();
  443. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  444. {
  445. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  446. continue;
  447. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  448. { // packet must exist for the client version
  449. WFIFOHEAD(tsd->fd, len);
  450. memcpy(WFIFOP(tsd->fd,0), buf, len);
  451. WFIFOSET(tsd->fd,len);
  452. }
  453. }
  454. mapit_free(iter);
  455. break;
  456. case SELF:
  457. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  458. WFIFOHEAD(fd,len);
  459. memcpy(WFIFOP(fd,0), buf, len);
  460. WFIFOSET(fd,len);
  461. }
  462. break;
  463. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  464. case GUILD_AREA:
  465. case GUILD_AREA_WOS:
  466. x0 = bl->x - AREA_SIZE;
  467. y0 = bl->y - AREA_SIZE;
  468. x1 = bl->x + AREA_SIZE;
  469. y1 = bl->y + AREA_SIZE;
  470. case GUILD_SAMEMAP:
  471. case GUILD_SAMEMAP_WOS:
  472. case GUILD:
  473. case GUILD_WOS:
  474. case GUILD_NOBG:
  475. if (sd && sd->status.guild_id)
  476. g = sd->guild;
  477. if (g) {
  478. for(i = 0; i < g->max_member; i++) {
  479. if( (sd = g->member[i].sd) != NULL )
  480. {
  481. if( !(fd=sd->fd) )
  482. continue;
  483. if( type == GUILD_NOBG && sd->bg_id )
  484. continue;
  485. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  486. continue;
  487. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  488. continue;
  489. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  490. continue;
  491. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  492. { // packet must exist for the client version
  493. WFIFOHEAD(fd,len);
  494. memcpy(WFIFOP(fd,0), buf, len);
  495. WFIFOSET(fd,len);
  496. }
  497. }
  498. }
  499. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  500. break;
  501. iter = mapit_getallusers();
  502. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  503. {
  504. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  505. { // packet must exist for the client version
  506. WFIFOHEAD(tsd->fd, len);
  507. memcpy(WFIFOP(tsd->fd,0), buf, len);
  508. WFIFOSET(tsd->fd,len);
  509. }
  510. }
  511. mapit_free(iter);
  512. }
  513. break;
  514. case BG_AREA:
  515. case BG_AREA_WOS:
  516. x0 = bl->x - AREA_SIZE;
  517. y0 = bl->y - AREA_SIZE;
  518. x1 = bl->x + AREA_SIZE;
  519. y1 = bl->y + AREA_SIZE;
  520. case BG_SAMEMAP:
  521. case BG_SAMEMAP_WOS:
  522. case BG:
  523. case BG_WOS:
  524. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  525. {
  526. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  527. {
  528. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  529. continue;
  530. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  531. continue;
  532. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  533. continue;
  534. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  535. continue;
  536. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  537. { // packet must exist for the client version
  538. WFIFOHEAD(fd,len);
  539. memcpy(WFIFOP(fd,0), buf, len);
  540. WFIFOSET(fd,len);
  541. }
  542. }
  543. }
  544. break;
  545. default:
  546. ShowError("clif_send: Unrecognized type %d\n",type);
  547. return -1;
  548. }
  549. return 0;
  550. }
  551. /// Notifies the client, that it's connection attempt was accepted.
  552. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  553. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  554. void clif_authok(struct map_session_data *sd)
  555. {
  556. #if PACKETVER < 20080102
  557. const int cmd = 0x73;
  558. #elif PACKETVER < 20141022
  559. const int cmd = 0x2eb;
  560. #else
  561. const int cmd = 0xa18;
  562. #endif
  563. int fd = sd->fd;
  564. WFIFOHEAD(fd,packet_len(cmd));
  565. WFIFOW(fd, 0) = cmd;
  566. WFIFOL(fd, 2) = gettick();
  567. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  568. WFIFOB(fd, 9) = 5; // ignored
  569. WFIFOB(fd,10) = 5; // ignored
  570. #if PACKETVER >= 20080102
  571. WFIFOW(fd,11) = sd->status.font;
  572. #endif
  573. #if PACKETVER >= 20141016
  574. WFIFOB(fd,13) = sd->status.sex;
  575. #endif
  576. WFIFOSET(fd,packet_len(cmd));
  577. }
  578. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  579. /// 0074 <error code>.B
  580. /// error code:
  581. /// 0 = client type mismatch
  582. /// 1 = ID mismatch
  583. /// 2 = mobile - out of available time
  584. /// 3 = mobile - already logged in
  585. /// 4 = mobile - waiting state
  586. void clif_authrefuse(int fd, uint8 error_code)
  587. {
  588. WFIFOHEAD(fd,packet_len(0x74));
  589. WFIFOW(fd,0) = 0x74;
  590. WFIFOB(fd,2) = error_code;
  591. WFIFOSET(fd,packet_len(0x74));
  592. }
  593. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  594. /// 0081 <error code>.B
  595. /// error code:
  596. /// 0 = BAN_UNFAIR
  597. /// 1 = server closed -> MsgStringTable[4]
  598. /// 2 = ID already logged in -> MsgStringTable[5]
  599. /// 3 = timeout/too much lag -> MsgStringTable[241]
  600. /// 4 = server full -> MsgStringTable[264]
  601. /// 5 = underaged -> MsgStringTable[305]
  602. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  603. /// 9 = too many connections from this ip -> MsgStringTable[529]
  604. /// 10 = out of available time paid for -> MsgStringTable[530]
  605. /// 11 = BAN_PAY_SUSPEND
  606. /// 12 = BAN_PAY_CHANGE
  607. /// 13 = BAN_PAY_WRONGIP
  608. /// 14 = BAN_PAY_PNGAMEROOM
  609. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  610. /// 16 = BAN_JAPAN_REFUSE1
  611. /// 17 = BAN_JAPAN_REFUSE2
  612. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  613. /// 100 = BAN_PC_IP_UNFAIR
  614. /// 101 = BAN_PC_IP_COUNT_ALL
  615. /// 102 = BAN_PC_IP_COUNT
  616. /// 103 = BAN_GRAVITY_MEM_AGREE
  617. /// 104 = BAN_GAME_MEM_AGREE
  618. /// 105 = BAN_HAN_VALID
  619. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  620. /// 107 = BAN_OVER_CHARACTER_LIST
  621. /// 108 = BAN_IP_BLOCK
  622. /// 109 = BAN_INVALID_PWD_CNT
  623. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  624. /// ? = disconnected -> MsgStringTable[3]
  625. void clif_authfail_fd(int fd, int type)
  626. {
  627. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  628. return;
  629. WFIFOHEAD(fd, packet_len(0x81));
  630. WFIFOW(fd,0) = 0x81;
  631. WFIFOB(fd,2) = type;
  632. WFIFOSET(fd,packet_len(0x81));
  633. set_eof(fd);
  634. }
  635. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  636. /// 00b3 <type>.B
  637. /// type:
  638. /// 1 = disconnect, char-select
  639. /// ? = nothing
  640. void clif_charselectok(int id, uint8 ok)
  641. {
  642. struct map_session_data* sd;
  643. int fd;
  644. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  645. return;
  646. fd = sd->fd;
  647. WFIFOHEAD(fd,packet_len(0xb3));
  648. WFIFOW(fd,0) = 0xb3;
  649. WFIFOB(fd,2) = ok;
  650. WFIFOSET(fd,packet_len(0xb3));
  651. }
  652. /// Makes an item appear on the ground.
  653. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  654. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  655. void clif_dropflooritem(struct flooritem_data* fitem)
  656. {
  657. #if PACKETVER >= 20130000
  658. uint8 buf[19];
  659. uint32 header=0x84b;
  660. #else
  661. uint8 buf[17];
  662. uint32 header=0x09e;
  663. #endif
  664. int view, offset=0;
  665. nullpo_retv(fitem);
  666. if (fitem->item.nameid == 0)
  667. return;
  668. WBUFW(buf, offset+0) = header;
  669. WBUFL(buf, offset+2) = fitem->bl.id;
  670. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  671. #if PACKETVER >= 20130000
  672. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  673. offset +=2;
  674. #endif
  675. WBUFB(buf, offset+8) = fitem->item.identify;
  676. WBUFW(buf, offset+9) = fitem->bl.x;
  677. WBUFW(buf, offset+11) = fitem->bl.y;
  678. WBUFB(buf, offset+13) = fitem->subx;
  679. WBUFB(buf, offset+14) = fitem->suby;
  680. WBUFW(buf, offset+15) = fitem->item.amount;
  681. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  682. }
  683. /// Makes an item disappear from the ground.
  684. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  685. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  686. {
  687. unsigned char buf[16];
  688. nullpo_retv(fitem);
  689. WBUFW(buf,0) = 0xa1;
  690. WBUFL(buf,2) = fitem->bl.id;
  691. if (fd == 0) {
  692. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  693. } else {
  694. WFIFOHEAD(fd,packet_len(0xa1));
  695. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  696. WFIFOSET(fd,packet_len(0xa1));
  697. }
  698. }
  699. /// Makes a unit (char, npc, mob, homun) disappear to one client (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_single(int id, clr_type type, int fd)
  708. {
  709. WFIFOHEAD(fd, packet_len(0x80));
  710. WFIFOW(fd,0) = 0x80;
  711. WFIFOL(fd,2) = id;
  712. WFIFOB(fd,6) = type;
  713. WFIFOSET(fd, packet_len(0x80));
  714. }
  715. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  716. /// 0080 <id>.L <type>.B
  717. /// type:
  718. /// 0 = out of sight
  719. /// 1 = died
  720. /// 2 = logged out
  721. /// 3 = teleport
  722. /// 4 = trickdead
  723. void clif_clearunit_area(struct block_list* bl, clr_type type)
  724. {
  725. unsigned char buf[8];
  726. nullpo_retv(bl);
  727. WBUFW(buf,0) = 0x80;
  728. WBUFL(buf,2) = bl->id;
  729. WBUFB(buf,6) = type;
  730. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  731. if(disguised(bl)) {
  732. WBUFL(buf,2) = -bl->id;
  733. clif_send(buf, packet_len(0x80), bl, SELF);
  734. }
  735. }
  736. /// Used to make monsters with player-sprites disappear after dying
  737. /// like normal monsters, because the client does not remove those
  738. /// automatically.
  739. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  740. {
  741. struct block_list *bl = (struct block_list *)data;
  742. clif_clearunit_area(bl, (clr_type) id);
  743. ers_free(delay_clearunit_ers,bl);
  744. return 0;
  745. }
  746. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  747. {
  748. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  749. memcpy (tbl, bl, sizeof (struct block_list));
  750. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  751. }
  752. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  753. {
  754. if(sd->sc.option&OPTION_COSTUME)
  755. {
  756. *rhand = *lhand = 0;
  757. return;
  758. }
  759. #if PACKETVER < 4
  760. *rhand = sd->status.weapon;
  761. *lhand = sd->status.shield;
  762. #else
  763. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  764. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  765. {
  766. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  767. if (id->view_id > 0)
  768. *rhand = id->view_id;
  769. else
  770. *rhand = id->nameid;
  771. } else
  772. *rhand = 0;
  773. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  774. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  775. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  776. {
  777. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  778. if (id->view_id > 0)
  779. *lhand = id->view_id;
  780. else
  781. *lhand = id->nameid;
  782. } else
  783. *lhand = 0;
  784. #endif
  785. }
  786. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  787. static int clif_setlevel_sub(int lv) {
  788. if( lv < battle_config.max_lv ) {
  789. ;
  790. } else if( lv < battle_config.aura_lv ) {
  791. lv = battle_config.max_lv - 1;
  792. } else {
  793. lv = battle_config.max_lv;
  794. }
  795. return lv;
  796. }
  797. static int clif_setlevel(struct block_list* bl) {
  798. int lv = status_get_lv(bl);
  799. if( battle_config.client_limit_unit_lv&bl->type )
  800. return clif_setlevel_sub(lv);
  801. switch( bl->type ) {
  802. case BL_NPC:
  803. case BL_PET:
  804. // npcs and pets do not have level
  805. return 0;
  806. }
  807. return lv;
  808. }
  809. /*==========================================
  810. * Prepares 'unit standing/spawning' packet
  811. *------------------------------------------*/
  812. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  813. {
  814. struct map_session_data* sd;
  815. struct status_change* sc = status_get_sc(bl);
  816. struct view_data* vd = status_get_viewdata(bl);
  817. unsigned char *buf = WBUFP(buffer, 0);
  818. #if PACKETVER < 20091103
  819. bool type = !pcdb_checkid(vd->class_);
  820. #endif
  821. unsigned short offset = 0;
  822. #if PACKETVER >= 20091103
  823. const char *name;
  824. #endif
  825. sd = BL_CAST(BL_PC, bl);
  826. #if PACKETVER < 20091103
  827. if(type)
  828. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  829. else
  830. #endif
  831. #if PACKETVER < 4
  832. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  833. #elif PACKETVER < 7
  834. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  835. #elif PACKETVER < 20080102
  836. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  837. #elif PACKETVER < 20091103
  838. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  839. #elif PACKETVER < 20101124
  840. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  841. #elif PACKETVER < 20120221
  842. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  843. #elif PACKETVER < 20131223
  844. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  845. #elif PACKETVER < 20150513
  846. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  847. #else
  848. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  849. #endif
  850. #if PACKETVER >= 20091103
  851. name = status_get_name(bl);
  852. #if PACKETVER < 20110111
  853. WBUFW(buf,2) = (spawn ? 62 : 63)+strlen(name);
  854. #elif PACKETVER < 20120221
  855. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  856. #elif PACKETVER < 20130807
  857. WBUFW(buf,2) = (spawn ? 77 : 78)+strlen(name);
  858. #else
  859. WBUFW(buf,2) = (spawn ? 79 : 80)+strlen(name);
  860. #endif
  861. WBUFB(buf,4) = clif_bl_type(bl);
  862. offset+=3;
  863. buf = WBUFP(buffer,offset);
  864. #elif PACKETVER >= 20071106
  865. if (type) { //Non-player packets
  866. WBUFB(buf,2) = clif_bl_type(bl);
  867. offset++;
  868. buf = WBUFP(buffer,offset);
  869. }
  870. #endif
  871. WBUFL(buf, 2) = bl->id;
  872. #if PACKETVER >= 20131223
  873. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  874. offset+=4;
  875. buf = WBUFP(buffer,offset);
  876. #endif
  877. WBUFW(buf, 6) = status_get_speed(bl);
  878. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  879. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  880. #if PACKETVER < 20091103
  881. if (type&&spawn) { //uses an older and different packet structure
  882. WBUFW(buf,12) = (sc)? sc->option : 0;
  883. WBUFW(buf,14) = vd->hair_style;
  884. WBUFW(buf,16) = vd->weapon;
  885. WBUFW(buf,18) = vd->head_bottom;
  886. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  887. WBUFW(buf,22) = vd->shield;
  888. } else {
  889. #endif
  890. #if PACKETVER >= 20091103
  891. WBUFL(buf,12) = (sc)? sc->option : 0;
  892. offset+=2;
  893. buf = WBUFP(buffer,offset);
  894. #elif PACKETVER >= 7
  895. if (!type) {
  896. WBUFL(buf,12) = (sc)? sc->option : 0;
  897. offset+=2;
  898. buf = WBUFP(buffer,offset);
  899. } else
  900. WBUFW(buf,12) = (sc)? sc->option : 0;
  901. #else
  902. WBUFW(buf,12) = (sc)? sc->option : 0;
  903. #endif
  904. WBUFW(buf,14) = vd->class_;
  905. WBUFW(buf,16) = vd->hair_style;
  906. WBUFW(buf,18) = vd->weapon;
  907. #if PACKETVER < 4
  908. WBUFW(buf,20) = vd->head_bottom;
  909. WBUFW(buf,22) = vd->shield;
  910. #else
  911. WBUFW(buf,20) = vd->shield;
  912. WBUFW(buf,22) = vd->head_bottom;
  913. #endif
  914. #if PACKETVER < 20091103
  915. }
  916. #endif
  917. WBUFW(buf,24) = vd->head_top;
  918. WBUFW(buf,26) = vd->head_mid;
  919. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  920. { //The hell, why flags work like this?
  921. WBUFW(buf,22) = status_get_emblem_id(bl);
  922. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  923. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  924. }
  925. WBUFW(buf,28) = vd->hair_color;
  926. WBUFW(buf,30) = vd->cloth_color;
  927. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  928. #if PACKETVER < 20091103
  929. if (type&&spawn) { //End of packet 0x7c
  930. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  931. WBUFB(buf,35) = vd->sex;
  932. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  933. WBUFB(buf,39) = 0;
  934. WBUFB(buf,40) = 0;
  935. return packet_len(0x7c);
  936. }
  937. #endif
  938. #if PACKETVER >= 20110111
  939. WBUFW(buf,34) = vd->robe;
  940. offset+= 2;
  941. buf = WBUFP(buffer,offset);
  942. #endif
  943. WBUFL(buf,34) = status_get_guild_id(bl);
  944. WBUFW(buf,38) = status_get_emblem_id(bl);
  945. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  946. #if PACKETVER >= 20091103
  947. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  948. offset+=2;
  949. buf = WBUFP(buffer,offset);
  950. #elif PACKETVER >= 7
  951. if (!type) {
  952. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  953. offset+=2;
  954. buf = WBUFP(buffer,offset);
  955. } else
  956. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  957. #else
  958. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  959. #endif
  960. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  961. WBUFB(buf,45) = vd->sex;
  962. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  963. WBUFB(buf,49) = (sd)? 5 : 0;
  964. WBUFB(buf,50) = (sd)? 5 : 0;
  965. if (!spawn) {
  966. WBUFB(buf,51) = vd->dead_sit;
  967. offset++;
  968. buf = WBUFP(buffer,offset);
  969. }
  970. WBUFW(buf,51) = clif_setlevel(bl);
  971. #if PACKETVER < 20091103
  972. if (type) //End for non-player packet
  973. return packet_len(WBUFW(buffer,0));
  974. #endif
  975. #if PACKETVER >= 20080102
  976. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  977. #endif
  978. #if PACKETVER >= 20120221
  979. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  980. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  981. WBUFL(buf,59) = status_get_hp(bl); // HP
  982. } else {
  983. WBUFL(buf,55) = -1; // maxHP
  984. WBUFL(buf,59) = -1; // HP
  985. }
  986. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  987. #endif
  988. #if PACKETVER >= 20150513
  989. WBUFW(buf,64) = vd->body_style; // body
  990. offset+= 2;
  991. buf = WBUFP(buffer,offset);
  992. #endif
  993. #if PACKETVER >= 20091103
  994. #if PACKETVER >= 20120221
  995. memcpy((char*)WBUFP(buf,64), name, NAME_LENGTH);
  996. #else
  997. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  998. #endif
  999. return WBUFW(buffer,2);
  1000. #else
  1001. return packet_len(WBUFW(buffer,0));
  1002. #endif
  1003. }
  1004. /*==========================================
  1005. * Prepares 'unit walking' packet
  1006. *------------------------------------------*/
  1007. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1008. {
  1009. struct map_session_data* sd;
  1010. struct status_change* sc = status_get_sc(bl);
  1011. struct view_data* vd = status_get_viewdata(bl);
  1012. unsigned char* buf = WBUFP(buffer,0);
  1013. #if PACKETVER >= 7
  1014. unsigned short offset = 0;
  1015. #endif
  1016. #if PACKETVER >= 20091103
  1017. const char *name;
  1018. #endif
  1019. sd = BL_CAST(BL_PC, bl);
  1020. #if PACKETVER < 4
  1021. WBUFW(buf, 0) = 0x7b;
  1022. #elif PACKETVER < 7
  1023. WBUFW(buf, 0) = 0x1da;
  1024. #elif PACKETVER < 20080102
  1025. WBUFW(buf, 0) = 0x22c;
  1026. #elif PACKETVER < 20091103
  1027. WBUFW(buf, 0) = 0x2ec;
  1028. #elif PACKETVER < 20101124
  1029. WBUFW(buf, 0) = 0x7f7;
  1030. #elif PACKETVER < 20120221
  1031. WBUFW(buf, 0) = 0x856;
  1032. #elif PACKETVER < 20131223
  1033. WBUFW(buf, 0) = 0x914;
  1034. #elif PACKETVER < 20150513
  1035. WBUFW(buf, 0) = 0x9db;
  1036. #else
  1037. WBUFW(buf, 0) = 0x9fd;
  1038. #endif
  1039. #if PACKETVER >= 20091103
  1040. name = status_get_name(bl);
  1041. #if PACKETVER < 20110111
  1042. WBUFW(buf, 2) = 69+strlen(name);
  1043. #elif PACKETVER < 20120221
  1044. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1045. #elif PACKETVER < 20130807
  1046. WBUFW(buf, 2) = 84+strlen(name);
  1047. #else
  1048. WBUFW(buf, 2) = 86+strlen(name);
  1049. #endif
  1050. offset+=2;
  1051. buf = WBUFP(buffer,offset);
  1052. #endif
  1053. #if PACKETVER >= 20071106
  1054. WBUFB(buf, 2) = clif_bl_type(bl);
  1055. offset++;
  1056. buf = WBUFP(buffer,offset);
  1057. #endif
  1058. WBUFL(buf, 2) = bl->id;
  1059. #if PACKETVER >= 20131223
  1060. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1061. offset+=4;
  1062. buf = WBUFP(buffer,offset);
  1063. #endif
  1064. WBUFW(buf, 6) = status_get_speed(bl);
  1065. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1066. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1067. #if PACKETVER < 7
  1068. WBUFW(buf,12) = (sc)? sc->option : 0;
  1069. #else
  1070. WBUFL(buf,12) = (sc)? sc->option : 0;
  1071. offset+=2; //Shift the rest of elements by 2 bytes.
  1072. buf = WBUFP(buffer,offset);
  1073. #endif
  1074. WBUFW(buf,14) = vd->class_;
  1075. WBUFW(buf,16) = vd->hair_style;
  1076. WBUFW(buf,18) = vd->weapon;
  1077. #if PACKETVER < 4
  1078. WBUFW(buf,20) = vd->head_bottom;
  1079. WBUFL(buf,22) = gettick();
  1080. WBUFW(buf,26) = vd->shield;
  1081. #else
  1082. WBUFW(buf,20) = vd->shield;
  1083. WBUFW(buf,22) = vd->head_bottom;
  1084. WBUFL(buf,24) = gettick();
  1085. #endif
  1086. WBUFW(buf,28) = vd->head_top;
  1087. WBUFW(buf,30) = vd->head_mid;
  1088. WBUFW(buf,32) = vd->hair_color;
  1089. WBUFW(buf,34) = vd->cloth_color;
  1090. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1091. #if PACKETVER >= 20110111
  1092. WBUFW(buf,38) = vd->robe;
  1093. offset+= 2;
  1094. buf = WBUFP(buffer,offset);
  1095. #endif
  1096. WBUFL(buf,38) = status_get_guild_id(bl);
  1097. WBUFW(buf,42) = status_get_emblem_id(bl);
  1098. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1099. #if PACKETVER < 7
  1100. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1101. #else
  1102. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1103. offset+=2; //Shift the rest of elements by 2 bytes.
  1104. buf = WBUFP(buffer,offset);
  1105. #endif
  1106. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1107. WBUFB(buf,49) = vd->sex;
  1108. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1109. WBUFB(buf,56) = (sd)? 5 : 0;
  1110. WBUFB(buf,57) = (sd)? 5 : 0;
  1111. WBUFW(buf,58) = clif_setlevel(bl);
  1112. #if PACKETVER >= 20080102
  1113. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1114. #endif
  1115. #if PACKETVER >= 20120221
  1116. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  1117. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1118. WBUFL(buf,66) = status_get_hp(bl); // HP
  1119. } else {
  1120. WBUFL(buf,62) = -1; // maxHP
  1121. WBUFL(buf,66) = -1; // HP
  1122. }
  1123. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1124. #endif
  1125. #if PACKETVER >= 20150513
  1126. WBUFW(buf,71) = vd->body_style; // body
  1127. offset+= 2;
  1128. buf = WBUFP(buffer,offset);
  1129. #endif
  1130. #if PACKETVER >= 20091103
  1131. #if PACKETVER >= 20120221
  1132. memcpy((char*)WBUFP(buf,71), name, NAME_LENGTH);
  1133. #else
  1134. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1135. #endif
  1136. return WBUFW(buffer,2);
  1137. #else
  1138. return packet_len(WBUFW(buffer,0));
  1139. #endif
  1140. }
  1141. //Modifies the buffer for disguise characters and sends it to self.
  1142. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1143. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1144. {
  1145. #if PACKETVER >= 20091103
  1146. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1147. WBUFL(buf,5)=-bl->id;
  1148. #elif PACKETVER >= 20071106
  1149. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1150. WBUFL(buf,3)=-bl->id;
  1151. #else
  1152. WBUFL(buf,2)=-bl->id;
  1153. #endif
  1154. clif_send(buf, len, bl, SELF);
  1155. }
  1156. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1157. /// 01b0 <id>.L <type>.B <value>.L
  1158. /// type:
  1159. /// unused
  1160. void clif_class_change(struct block_list *bl,int class_,int type)
  1161. {
  1162. nullpo_retv(bl);
  1163. if(!pcdb_checkid(class_))
  1164. {// player classes yield missing sprites
  1165. unsigned char buf[16];
  1166. WBUFW(buf,0)=0x1b0;
  1167. WBUFL(buf,2)=bl->id;
  1168. WBUFB(buf,6)=type;
  1169. WBUFL(buf,7)=class_;
  1170. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1171. }
  1172. }
  1173. /// Notifies the client of an object's spirits.
  1174. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1175. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1176. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1177. {
  1178. WFIFOHEAD(fd, packet_len(0x1e1));
  1179. WFIFOW(fd,0)=0x1e1;
  1180. WFIFOL(fd,2)=sd->bl.id;
  1181. WFIFOW(fd,6)=sd->spiritball;
  1182. WFIFOSET(fd, packet_len(0x1e1));
  1183. }
  1184. /*==========================================
  1185. * Kagerou/Oboro amulet spirit
  1186. *------------------------------------------*/
  1187. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1188. {
  1189. WFIFOHEAD(fd, packet_len(0x08cf));
  1190. WFIFOW(fd,0)=0x08cf;
  1191. WFIFOL(fd,2)=sd->bl.id;
  1192. WFIFOW(fd,6)=sd->spiritcharm_type;
  1193. WFIFOW(fd,8)=sd->spiritcharm;
  1194. WFIFOSET(fd, packet_len(0x08cf));
  1195. }
  1196. /*==========================================
  1197. * Run when player changes map / refreshes
  1198. * Tells its client to display all weather settings being used by this map
  1199. *------------------------------------------*/
  1200. static void clif_weather_check(struct map_session_data *sd)
  1201. {
  1202. int16 m = sd->bl.m;
  1203. int fd = sd->fd;
  1204. if (map[m].flag.snow
  1205. || map[m].flag.clouds
  1206. || map[m].flag.fog
  1207. || map[m].flag.fireworks
  1208. || map[m].flag.sakura
  1209. || map[m].flag.leaves
  1210. || map[m].flag.clouds2)
  1211. {
  1212. if (map[m].flag.snow)
  1213. clif_specialeffect_single(&sd->bl, 162, fd);
  1214. if (map[m].flag.clouds)
  1215. clif_specialeffect_single(&sd->bl, 233, fd);
  1216. if (map[m].flag.clouds2)
  1217. clif_specialeffect_single(&sd->bl, 516, fd);
  1218. if (map[m].flag.fog)
  1219. clif_specialeffect_single(&sd->bl, 515, fd);
  1220. if (map[m].flag.fireworks) {
  1221. clif_specialeffect_single(&sd->bl, 297, fd);
  1222. clif_specialeffect_single(&sd->bl, 299, fd);
  1223. clif_specialeffect_single(&sd->bl, 301, fd);
  1224. }
  1225. if (map[m].flag.sakura)
  1226. clif_specialeffect_single(&sd->bl, 163, fd);
  1227. if (map[m].flag.leaves)
  1228. clif_specialeffect_single(&sd->bl, 333, fd);
  1229. }
  1230. }
  1231. /**
  1232. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1233. **/
  1234. void clif_weather(int16 m)
  1235. {
  1236. struct s_mapiterator* iter;
  1237. struct map_session_data *sd=NULL;
  1238. iter = mapit_getallusers();
  1239. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1240. {
  1241. if( sd->bl.m == m )
  1242. clif_weather_check(sd);
  1243. }
  1244. mapit_free(iter);
  1245. }
  1246. /**
  1247. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1248. **/
  1249. int clif_spawn(struct block_list *bl)
  1250. {
  1251. unsigned char buf[128];
  1252. struct view_data *vd;
  1253. struct status_change *sc = status_get_sc(bl);
  1254. int len;
  1255. vd = status_get_viewdata(bl);
  1256. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1257. return 0;
  1258. /**
  1259. * Hide NPC from maya purple card.
  1260. **/
  1261. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1262. return 0;
  1263. len = clif_set_unit_idle(bl, buf,true);
  1264. clif_send(buf, len, bl, AREA_WOS);
  1265. if (disguised(bl))
  1266. clif_setdisguise(bl, buf, len);
  1267. if (vd->cloth_color)
  1268. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1269. if (vd->body_style)
  1270. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1271. switch (bl->type)
  1272. {
  1273. case BL_PC:
  1274. {
  1275. TBL_PC *sd = ((TBL_PC*)bl);
  1276. int i;
  1277. if (sd->spiritball > 0)
  1278. clif_spiritball(&sd->bl);
  1279. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1280. clif_specialeffect(bl,423,AREA);
  1281. else if(sd->state.size==SZ_MEDIUM)
  1282. clif_specialeffect(bl,421,AREA);
  1283. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1284. clif_sendbgemblem_area(sd);
  1285. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1286. clif_spiritcharm(sd);
  1287. for (i = 0; i < sd->sc_display_count; i++) {
  1288. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1289. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1290. else
  1291. 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);
  1292. }
  1293. if (sd->status.robe)
  1294. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1295. }
  1296. break;
  1297. case BL_MOB:
  1298. {
  1299. TBL_MOB *md = ((TBL_MOB*)bl);
  1300. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1301. clif_specialeffect(&md->bl,423,AREA);
  1302. else if(md->special_state.size==SZ_MEDIUM)
  1303. clif_specialeffect(&md->bl,421,AREA);
  1304. }
  1305. break;
  1306. case BL_NPC:
  1307. {
  1308. TBL_NPC *nd = ((TBL_NPC*)bl);
  1309. if( nd->size == SZ_BIG )
  1310. clif_specialeffect(&nd->bl,423,AREA);
  1311. else if( nd->size == SZ_MEDIUM )
  1312. clif_specialeffect(&nd->bl,421,AREA);
  1313. }
  1314. break;
  1315. case BL_PET:
  1316. if (vd->head_bottom)
  1317. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1318. break;
  1319. }
  1320. return 0;
  1321. }
  1322. /// Sends information about owned homunculus to the client . [orn]
  1323. /// 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 (ZC_PROPERTY_HOMUN)
  1324. /// 09f7 <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 (ZC_PROPERTY_HOMUN_2)
  1325. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1326. {
  1327. struct status_data *status;
  1328. unsigned char buf[128];
  1329. #if PACKETVER < 20141016
  1330. const int cmd = 0x22e;
  1331. int offset = 0;
  1332. #else
  1333. const int cmd = 0x9f7;
  1334. int offset = 2;
  1335. #endif
  1336. int htype;
  1337. nullpo_retv(hd);
  1338. if (!clif_session_isValid(sd))
  1339. return;
  1340. status = &hd->battle_status;
  1341. htype = hom_class2type(hd->homunculus.class_);
  1342. memset(buf,0,packet_len(cmd));
  1343. WBUFW(buf,0) = cmd;
  1344. memcpy(WBUFP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1345. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1346. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1347. WBUFW(buf,27) = hd->homunculus.level;
  1348. WBUFW(buf,29) = hd->homunculus.hunger;
  1349. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1350. WBUFW(buf,33) = 0; // equip id
  1351. #ifdef RENEWAL
  1352. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1353. #else
  1354. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1355. #endif
  1356. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1357. WBUFW(buf,39)=status->hit;
  1358. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1359. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1360. else
  1361. WBUFW(buf,41) = status->cri/10;
  1362. #ifdef RENEWAL
  1363. WBUFW(buf,43) = status->def + status->def2;
  1364. WBUFW(buf,45) = status->mdef + status->mdef2;
  1365. #else
  1366. WBUFW(buf,43) = status->def + status->vit;
  1367. WBUFW(buf,45) = status->mdef;
  1368. #endif
  1369. WBUFW(buf,47) = status->flee;
  1370. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1371. if (status->max_hp > INT16_MAX) {
  1372. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1373. WBUFW(buf,53+offset) = 100;
  1374. } else {
  1375. WBUFW(buf,51) = status->hp;
  1376. WBUFW(buf,53+offset) = status->max_hp;
  1377. }
  1378. #if PACKETVER >= 20141016
  1379. offset += 2;
  1380. #endif
  1381. if (status->max_sp > INT16_MAX) {
  1382. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1383. WBUFW(buf,57+offset) = 100;
  1384. } else {
  1385. WBUFW(buf,55+offset) = status->sp;
  1386. WBUFW(buf,57+offset) = status->max_sp;
  1387. }
  1388. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1389. WBUFL(buf,63+offset) = hd->exp_next;
  1390. switch( htype ) {
  1391. case HT_REG:
  1392. case HT_EVO:
  1393. if( hd->homunculus.level >= battle_config.hom_max_level )
  1394. WBUFL(buf,63+offset) = 0;
  1395. break;
  1396. case HT_S:
  1397. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1398. WBUFL(buf,63+offset) = 0;
  1399. break;
  1400. }
  1401. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1402. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1403. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1404. }
  1405. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1406. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1407. /// type:
  1408. /// unused
  1409. /// state:
  1410. /// 0 = pre-init
  1411. /// 1 = intimacy
  1412. /// 2 = hunger
  1413. /// 3 = accessory?
  1414. /// ? = ignored
  1415. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1416. { //[orn]
  1417. int fd = sd->fd;
  1418. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1419. hom_calc_skilltree(sd->hd, 0);
  1420. WFIFOHEAD(fd, packet_len(0x230));
  1421. WFIFOW(fd,0)=0x230;
  1422. WFIFOB(fd,2)=0;
  1423. WFIFOB(fd,3)=state;
  1424. WFIFOL(fd,4)=sd->hd->bl.id;
  1425. WFIFOL(fd,8)=param;
  1426. WFIFOSET(fd,packet_len(0x230));
  1427. }
  1428. int clif_homskillinfoblock(struct map_session_data *sd)
  1429. { //[orn]
  1430. struct homun_data *hd;
  1431. int fd = sd->fd;
  1432. int i, len=4;
  1433. nullpo_ret(sd);
  1434. hd = sd->hd;
  1435. if ( !hd )
  1436. return 0 ;
  1437. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1438. WFIFOW(fd,0)=0x235;
  1439. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1440. int id = hd->homunculus.hskill[i].id;
  1441. if( id != 0 ){
  1442. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1443. short idx = hom_skill_get_index(id);
  1444. if (idx == -1)
  1445. continue;
  1446. WFIFOW(fd,len ) = id;
  1447. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1448. WFIFOW(fd,len+4) = 0;
  1449. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1450. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1451. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[idx].lv);
  1452. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1453. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1454. len+=37;
  1455. }
  1456. }
  1457. WFIFOW(fd,2)=len;
  1458. WFIFOSET(fd,len);
  1459. return 0;
  1460. }
  1461. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1462. { //[orn]
  1463. struct homun_data *hd;
  1464. int fd;
  1465. short idx = -1;
  1466. nullpo_retv(sd);
  1467. if ((idx = hom_skill_get_index(skill_id) == -1))
  1468. return;
  1469. fd = sd->fd;
  1470. hd = sd->hd;
  1471. WFIFOHEAD(fd, packet_len(0x239));
  1472. WFIFOW(fd,0) = 0x239;
  1473. WFIFOW(fd,2) = skill_id;
  1474. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1475. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1476. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1477. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1478. WFIFOSET(fd,packet_len(0x239));
  1479. }
  1480. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1481. {
  1482. int fd=sd->fd;
  1483. WFIFOHEAD(fd,packet_len(0x22f));
  1484. WFIFOW(fd,0)=0x22f;
  1485. WFIFOB(fd,2)=fail;
  1486. WFIFOW(fd,3)=foodid;
  1487. WFIFOSET(fd,packet_len(0x22f));
  1488. return 0;
  1489. }
  1490. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1491. /// 0087 <walk start time>.L <walk data>.6B
  1492. void clif_walkok(struct map_session_data *sd)
  1493. {
  1494. int fd=sd->fd;
  1495. WFIFOHEAD(fd, packet_len(0x87));
  1496. WFIFOW(fd,0)=0x87;
  1497. WFIFOL(fd,2)=gettick();
  1498. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1499. WFIFOSET(fd,packet_len(0x87));
  1500. }
  1501. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1502. {
  1503. uint8 buf[128];
  1504. int len;
  1505. struct status_change *sc = NULL;
  1506. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1507. clif_ally_only = true;
  1508. len = clif_set_unit_walking(bl,ud,buf);
  1509. clif_send(buf,len,bl,AREA_WOS);
  1510. if (disguised(bl))
  1511. clif_setdisguise(bl, buf, len);
  1512. if(vd->cloth_color)
  1513. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1514. if(vd->body_style)
  1515. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1516. switch(bl->type) {
  1517. case BL_PC:
  1518. {
  1519. TBL_PC *sd = ((TBL_PC*)bl);
  1520. // clif_movepc(sd);
  1521. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1522. clif_specialeffect(&sd->bl,423,AREA);
  1523. else if(sd->state.size==SZ_MEDIUM)
  1524. clif_specialeffect(&sd->bl,421,AREA);
  1525. }
  1526. break;
  1527. case BL_MOB:
  1528. {
  1529. TBL_MOB *md = ((TBL_MOB*)bl);
  1530. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1531. clif_specialeffect(&md->bl,423,AREA);
  1532. else if(md->special_state.size==SZ_MEDIUM)
  1533. clif_specialeffect(&md->bl,421,AREA);
  1534. }
  1535. break;
  1536. case BL_PET:
  1537. if(vd->head_bottom) // needed to display pet equip properly
  1538. clif_pet_equip_area((TBL_PET*)bl);
  1539. break;
  1540. }
  1541. clif_ally_only = false;
  1542. }
  1543. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1544. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1545. /// Note: unit must not be self
  1546. void clif_move(struct unit_data *ud)
  1547. {
  1548. unsigned char buf[16];
  1549. struct view_data* vd;
  1550. struct block_list* bl = ud->bl;
  1551. struct status_change *sc = NULL;
  1552. vd = status_get_viewdata(bl);
  1553. if (!vd )
  1554. return;
  1555. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1556. else if( vd->class_ == INVISIBLE_CLASS ){
  1557. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1558. if(disguised(bl)) {
  1559. WBUFW(buf,0)=0x86;
  1560. WBUFL(buf,2)=-bl->id;
  1561. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1562. WBUFL(buf,12)=gettick();
  1563. clif_send(buf, packet_len(0x86), bl, SELF);
  1564. }
  1565. return;
  1566. }
  1567. /**
  1568. * Hide NPC from maya purple card.
  1569. **/
  1570. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1571. return;
  1572. if (ud->state.speed_changed) {
  1573. // Since we don't know how to update the speed of other objects,
  1574. // use the old walk packet to update the data.
  1575. ud->state.speed_changed = 0;
  1576. clif_move2(bl, vd, ud);
  1577. return;
  1578. }
  1579. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1580. clif_ally_only = true;
  1581. WBUFW(buf,0)=0x86;
  1582. WBUFL(buf,2)=bl->id;
  1583. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1584. WBUFL(buf,12)=gettick();
  1585. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1586. if (disguised(bl)) {
  1587. WBUFL(buf,2)=-bl->id;
  1588. clif_send(buf, packet_len(0x86), bl, SELF);
  1589. }
  1590. clif_ally_only = false;
  1591. }
  1592. /*==========================================
  1593. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1594. *------------------------------------------*/
  1595. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1596. {
  1597. struct map_session_data *sd = NULL;
  1598. //Remove player from map server
  1599. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1600. map_quit(sd);
  1601. return 0;
  1602. }
  1603. /*==========================================
  1604. *
  1605. *------------------------------------------*/
  1606. void clif_quitsave(int fd,struct map_session_data *sd) {
  1607. if (!battle_config.prevent_logout ||
  1608. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1609. map_quit(sd);
  1610. else if (sd->fd) {
  1611. //Disassociate session from player (session is deleted after this function was called)
  1612. //And set a timer to make him quit later.
  1613. session[sd->fd]->session_data = NULL;
  1614. sd->fd = 0;
  1615. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1616. }
  1617. }
  1618. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1619. /// 0091 <map name>.16B <x>.W <y>.W
  1620. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1621. {
  1622. int fd;
  1623. nullpo_retv(sd);
  1624. fd = sd->fd;
  1625. WFIFOHEAD(fd,packet_len(0x91));
  1626. WFIFOW(fd,0) = 0x91;
  1627. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1628. WFIFOW(fd,18) = x;
  1629. WFIFOW(fd,20) = y;
  1630. WFIFOSET(fd,packet_len(0x91));
  1631. }
  1632. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1633. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1634. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1635. {
  1636. int fd;
  1637. nullpo_retv(sd);
  1638. fd = sd->fd;
  1639. WFIFOHEAD(fd,packet_len(0x92));
  1640. WFIFOW(fd,0) = 0x92;
  1641. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1642. WFIFOW(fd,18) = x;
  1643. WFIFOW(fd,20) = y;
  1644. WFIFOL(fd,22) = htonl(ip);
  1645. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1646. WFIFOSET(fd,packet_len(0x92));
  1647. }
  1648. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1649. /// This function combines both calls and allows to simplify the calling code
  1650. void clif_blown(struct block_list *bl)
  1651. {
  1652. clif_slide(bl, bl->x, bl->y);
  1653. clif_fixpos(bl);
  1654. }
  1655. /// Visually moves(slides) a character to x,y. If the target cell
  1656. /// isn't walkable, the char doesn't move at all. If the char is
  1657. /// sitting it will stand up (ZC_STOPMOVE).
  1658. /// 0088 <id>.L <x>.W <y>.W
  1659. void clif_fixpos(struct block_list *bl)
  1660. {
  1661. unsigned char buf[10];
  1662. nullpo_retv(bl);
  1663. WBUFW(buf,0) = 0x88;
  1664. WBUFL(buf,2) = bl->id;
  1665. WBUFW(buf,6) = bl->x;
  1666. WBUFW(buf,8) = bl->y;
  1667. clif_send(buf, packet_len(0x88), bl, AREA);
  1668. if( disguised(bl) ) {
  1669. WBUFL(buf,2) = -bl->id;
  1670. clif_send(buf, packet_len(0x88), bl, SELF);
  1671. }
  1672. }
  1673. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1674. /// 00c4 <shop id>.L
  1675. void clif_npcbuysell(struct map_session_data* sd, int id)
  1676. {
  1677. int fd;
  1678. nullpo_retv(sd);
  1679. fd=sd->fd;
  1680. WFIFOHEAD(fd, packet_len(0xc4));
  1681. WFIFOW(fd,0)=0xc4;
  1682. WFIFOL(fd,2)=id;
  1683. WFIFOSET(fd,packet_len(0xc4));
  1684. }
  1685. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1686. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1687. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1688. {
  1689. int fd,i,c;
  1690. bool discount;
  1691. nullpo_retv(sd);
  1692. nullpo_retv(nd);
  1693. fd = sd->fd;
  1694. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1695. WFIFOW(fd,0) = 0xc6;
  1696. c = 0;
  1697. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1698. for( i = 0; i < nd->u.shop.count; i++ )
  1699. {
  1700. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1701. int val = nd->u.shop.shop_item[i].value;
  1702. if( id == NULL )
  1703. continue;
  1704. WFIFOL(fd, 4+c*11) = val;
  1705. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1706. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1707. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1708. c++;
  1709. }
  1710. WFIFOW(fd,2) = 4 + c*11;
  1711. WFIFOSET(fd,WFIFOW(fd,2));
  1712. }
  1713. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1714. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1715. void clif_selllist(struct map_session_data *sd)
  1716. {
  1717. int fd,i,c=0,val;
  1718. nullpo_retv(sd);
  1719. fd=sd->fd;
  1720. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1721. WFIFOW(fd,0)=0xc7;
  1722. for( i = 0; i < MAX_INVENTORY; i++ )
  1723. {
  1724. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1725. {
  1726. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1727. continue;
  1728. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1729. continue; // Cannot Sell Rental Items or Account Bounded Items
  1730. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1731. continue; // Don't allow sale of bound items
  1732. val=sd->inventory_data[i]->value_sell;
  1733. if( val < 0 )
  1734. continue;
  1735. WFIFOW(fd,4+c*10)=i+2;
  1736. WFIFOL(fd,6+c*10)=val;
  1737. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1738. c++;
  1739. }
  1740. }
  1741. WFIFOW(fd,2)=c*10+4;
  1742. WFIFOSET(fd,WFIFOW(fd,2));
  1743. }
  1744. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1745. /// 09d4
  1746. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1747. // TODO: State tracking?
  1748. sd->npc_shopid = 0;
  1749. }
  1750. /**
  1751. * Presents list of items, that can be sold to a Market shop.
  1752. * @author: Ind and Yommy
  1753. **/
  1754. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1755. #if PACKETVER >= 20131223
  1756. struct npc_item_list *shop = nd->u.shop.shop_item;
  1757. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1758. struct item_data *id = NULL;
  1759. struct s_packet_db *info;
  1760. int fd;
  1761. nullpo_retv(sd);
  1762. if (sd->state.trading)
  1763. return;
  1764. info = &packet_db[sd->packet_ver][cmd];
  1765. if (!info || info->len == 0)
  1766. return;
  1767. fd = sd->fd;
  1768. WFIFOHEAD(fd, 4 + shop_size * 13);
  1769. WFIFOW(fd,0) = cmd;
  1770. for (i = 0, c = 0; i < shop_size; i++) {
  1771. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1772. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1773. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1774. WFIFOL(fd, 7+c*13) = shop[i].value;
  1775. WFIFOL(fd,11+c*13) = shop[i].qty;
  1776. WFIFOW(fd,15+c*13) = (id->view_id > 0) ? id->view_id : id->nameid;
  1777. c++;
  1778. }
  1779. }
  1780. WFIFOW(fd,2) = 4 + c*13;
  1781. WFIFOSET(fd,WFIFOW(fd,2));
  1782. sd->state.trading = 1;
  1783. #endif
  1784. }
  1785. /// Closes the Market shop window.
  1786. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1787. nullpo_retv(sd);
  1788. sd->npc_shopid = 0;
  1789. sd->state.trading = 0;
  1790. }
  1791. /// Purchase item from Market shop.
  1792. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1793. #if PACKETVER >= 20131223
  1794. unsigned short cmd = 0x9d7, len = 0;
  1795. struct npc_data* nd;
  1796. uint8 result = (res == 0 ? 1 : 0);
  1797. int fd = 0;
  1798. struct s_packet_db *info;
  1799. nullpo_retv(sd);
  1800. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1801. info = &packet_db[sd->packet_ver][cmd];
  1802. if (!info || info->len == 0)
  1803. return;
  1804. fd = sd->fd;
  1805. len = 5 + 8*n;
  1806. WFIFOHEAD(fd, len);
  1807. WFIFOW(fd, 0) = cmd;
  1808. WFIFOW(fd, 2) = len;
  1809. if (result) {
  1810. uint8 i, j;
  1811. struct npc_item_list *shop = nd->u.shop.shop_item;
  1812. unsigned short count = nd->u.shop.count;
  1813. for (i = 0; i < n; i++) {
  1814. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1815. WFIFOW(fd, 7+i*8) = list[i].qty;
  1816. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1817. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1818. }
  1819. }
  1820. WFIFOB(fd, 4) = n;
  1821. WFIFOSET(fd, len);
  1822. #endif
  1823. }
  1824. /// Purchase item from Market shop.
  1825. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1826. #if PACKETVER >= 20131223
  1827. struct s_packet_db* info;
  1828. struct s_npc_buy_list *item_list;
  1829. uint16 len = 0, i = 0;
  1830. uint8 res = 0, n = 0;
  1831. nullpo_retv(sd);
  1832. if (!sd->npc_shopid)
  1833. return;
  1834. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  1835. if (!info || info->len == 0)
  1836. return;
  1837. len = RFIFOW(fd,info->pos[0]);
  1838. n = (len-4) / 6;
  1839. CREATE(item_list, struct s_npc_buy_list, n);
  1840. for (i = 0; i < n; i++) {
  1841. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1842. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1843. }
  1844. res = npc_buylist(sd, n, item_list);
  1845. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1846. aFree(item_list);
  1847. #endif
  1848. }
  1849. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1850. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1851. /// Client behavior (dialog window):
  1852. /// - disable mouse targeting
  1853. /// - open the dialog window
  1854. /// - set npcid of dialog window (0 by default)
  1855. /// - if set to clear on next mes, clear contents
  1856. /// - append this text
  1857. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1858. {
  1859. int fd = sd->fd;
  1860. int slen = strlen(mes) + 9;
  1861. WFIFOHEAD(fd, slen);
  1862. WFIFOW(fd,0)=0xb4;
  1863. WFIFOW(fd,2)=slen;
  1864. WFIFOL(fd,4)=npcid;
  1865. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1866. WFIFOSET(fd,WFIFOW(fd,2));
  1867. }
  1868. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1869. /// 00b5 <npc id>.L
  1870. /// Client behavior (dialog window):
  1871. /// - disable mouse targeting
  1872. /// - open the dialog window
  1873. /// - add 'next' button
  1874. /// When 'next' is pressed:
  1875. /// - 00B9 <npcid of dialog window>.L
  1876. /// - set to clear on next mes
  1877. /// - remove 'next' button
  1878. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1879. {
  1880. int fd;
  1881. nullpo_retv(sd);
  1882. fd=sd->fd;
  1883. WFIFOHEAD(fd, packet_len(0xb5));
  1884. WFIFOW(fd,0)=0xb5;
  1885. WFIFOL(fd,2)=npcid;
  1886. WFIFOSET(fd,packet_len(0xb5));
  1887. }
  1888. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1889. /// 00b6 <npc id>.L
  1890. /// Client behavior:
  1891. /// - if dialog window is open:
  1892. /// - remove 'next' button
  1893. /// - add 'close' button
  1894. /// - else:
  1895. /// - enable mouse targeting
  1896. /// - close the dialog window
  1897. /// - close the menu window
  1898. /// When 'close' is pressed:
  1899. /// - enable mouse targeting
  1900. /// - close the dialog window
  1901. /// - close the menu window
  1902. /// - 0146 <npcid of dialog window>.L
  1903. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1904. {
  1905. int fd;
  1906. nullpo_retv(sd);
  1907. fd=sd->fd;
  1908. WFIFOHEAD(fd, packet_len(0xb6));
  1909. WFIFOW(fd,0)=0xb6;
  1910. WFIFOL(fd,2)=npcid;
  1911. WFIFOSET(fd,packet_len(0xb6));
  1912. }
  1913. /**
  1914. * Close script when player is idle
  1915. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1916. * @author [Ind/Hercules]
  1917. * @param sd : player pointer
  1918. * @param npcid : npc gid to close
  1919. */
  1920. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1921. {
  1922. struct s_packet_db* info;
  1923. int16 len;
  1924. int cmd = 0;
  1925. int fd;
  1926. nullpo_retv(sd);
  1927. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1928. if(!cmd) cmd = 0x8d6; //default
  1929. info = &packet_db[sd->packet_ver][cmd];
  1930. len = info->len;
  1931. fd = sd->fd;
  1932. WFIFOHEAD(fd, len);
  1933. WFIFOW(fd,0)=0x8d6;
  1934. WFIFOL(fd,info->pos[0])=npcid;
  1935. WFIFOSET(fd,len);
  1936. }
  1937. /*==========================================
  1938. *
  1939. *------------------------------------------*/
  1940. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1941. unsigned char *buf;
  1942. int fd = sd->fd;
  1943. sd->state.using_fake_npc = 1;
  1944. WFIFOHEAD(fd, packet_len(0x78));
  1945. buf = WFIFOP(fd,0);
  1946. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1947. WBUFW(buf,0)=0x78;
  1948. #if PACKETVER >= 20071106
  1949. WBUFB(buf,2) = 0; // object type
  1950. buf = WFIFOP(fd,1);
  1951. #endif
  1952. WBUFL(buf,2)=npcid;
  1953. WBUFW(buf,14)=111;
  1954. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1955. WBUFB(buf,49)=5;
  1956. WBUFB(buf,50)=5;
  1957. WFIFOSET(fd, packet_len(0x78));
  1958. }
  1959. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1960. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1961. /// Client behavior:
  1962. /// - disable mouse targeting
  1963. /// - close the menu window
  1964. /// - open the menu window
  1965. /// - add options to the menu (separated in the text by ":")
  1966. /// - set npcid of menu window
  1967. /// - if dialog window is open:
  1968. /// - remove 'next' button
  1969. /// When 'ok' is pressed:
  1970. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1971. /// - close the menu window
  1972. /// When 'cancel' is pressed:
  1973. /// - 00B8 <npcid of menu window>.L <-1>.B
  1974. /// - enable mouse targeting
  1975. /// - close a bunch of windows...
  1976. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1977. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1978. /// TODO investigate behavior of other windows [FlavioJS]
  1979. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1980. {
  1981. int fd = sd->fd;
  1982. int slen = strlen(mes) + 9;
  1983. struct block_list *bl = NULL;
  1984. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1985. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1986. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1987. clif_sendfakenpc(sd, npcid);
  1988. WFIFOHEAD(fd, slen);
  1989. WFIFOW(fd,0)=0xb7;
  1990. WFIFOW(fd,2)=slen;
  1991. WFIFOL(fd,4)=npcid;
  1992. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1993. WFIFOSET(fd,WFIFOW(fd,2));
  1994. }
  1995. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1996. /// 0142 <npc id>.L
  1997. /// Client behavior (inputnum window):
  1998. /// - if npcid exists in the client:
  1999. /// - open the inputnum window
  2000. /// - set npcid of inputnum window
  2001. /// When 'ok' is pressed:
  2002. /// - if inputnum window has text:
  2003. /// - if npcid exists in the client:
  2004. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2005. /// - close inputnum window
  2006. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2007. {
  2008. int fd;
  2009. struct block_list *bl = NULL;
  2010. nullpo_retv(sd);
  2011. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2012. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2013. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2014. clif_sendfakenpc(sd, npcid);
  2015. fd=sd->fd;
  2016. WFIFOHEAD(fd, packet_len(0x142));
  2017. WFIFOW(fd,0)=0x142;
  2018. WFIFOL(fd,2)=npcid;
  2019. WFIFOSET(fd,packet_len(0x142));
  2020. }
  2021. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2022. /// 01d4 <npc id>.L
  2023. /// Client behavior (inputstr window):
  2024. /// - if npcid is 0 or npcid exists in the client:
  2025. /// - open the inputstr window
  2026. /// - set npcid of inputstr window
  2027. /// When 'ok' is pressed:
  2028. /// - if inputstr window has text and isn't an insult(manner.txt):
  2029. /// - if npcid is 0 or npcid exists in the client:
  2030. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2031. /// - close inputstr window
  2032. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2033. {
  2034. int fd;
  2035. struct block_list *bl = NULL;
  2036. nullpo_retv(sd);
  2037. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2038. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2039. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2040. clif_sendfakenpc(sd, npcid);
  2041. fd=sd->fd;
  2042. WFIFOHEAD(fd, packet_len(0x1d4));
  2043. WFIFOW(fd,0)=0x1d4;
  2044. WFIFOL(fd,2)=npcid;
  2045. WFIFOSET(fd,packet_len(0x1d4));
  2046. }
  2047. /// Marks a position on client's minimap (ZC_COMPASS).
  2048. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2049. /// npc id:
  2050. /// is ignored in the client
  2051. /// type:
  2052. /// 0 = display mark for 15 seconds
  2053. /// 1 = display mark until dead or teleported
  2054. /// 2 = remove mark
  2055. /// color:
  2056. /// 0x00RRGGBB
  2057. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2058. {
  2059. int fd;
  2060. nullpo_retv(sd);
  2061. fd=sd->fd;
  2062. WFIFOHEAD(fd, packet_len(0x144));
  2063. WFIFOW(fd,0)=0x144;
  2064. WFIFOL(fd,2)=npc_id;
  2065. WFIFOL(fd,6)=type;
  2066. WFIFOL(fd,10)=x;
  2067. WFIFOL(fd,14)=y;
  2068. WFIFOB(fd,18)=id;
  2069. WFIFOL(fd,19)=color;
  2070. WFIFOSET(fd,packet_len(0x144));
  2071. }
  2072. /// Displays an illustration image.
  2073. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2074. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2075. /// type:
  2076. /// 0 = bottom left corner
  2077. /// 1 = bottom middle
  2078. /// 2 = bottom right corner
  2079. /// 3 = middle of screen, inside a movable window
  2080. /// 4 = middle of screen, movable with a close button, chrome-less
  2081. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2082. {
  2083. int fd;
  2084. nullpo_retv(sd);
  2085. fd=sd->fd;
  2086. WFIFOHEAD(fd, packet_len(0x1b3));
  2087. WFIFOW(fd,0)=0x1b3;
  2088. strncpy((char*)WFIFOP(fd,2),image,64);
  2089. WFIFOB(fd,66)=type;
  2090. WFIFOSET(fd,packet_len(0x1b3));
  2091. }
  2092. /*==========================================
  2093. * Fills in card data from the given item and into the buffer. [Skotlex]
  2094. *------------------------------------------*/
  2095. static void clif_addcards(unsigned char* buf, struct item* item)
  2096. {
  2097. int i=0,j;
  2098. if( item == NULL ) { //Blank data
  2099. WBUFW(buf,0) = 0;
  2100. WBUFW(buf,2) = 0;
  2101. WBUFW(buf,4) = 0;
  2102. WBUFW(buf,6) = 0;
  2103. return;
  2104. }
  2105. if( item->card[0] == CARD0_PET ) { //pet eggs
  2106. WBUFW(buf,0) = 0;
  2107. WBUFW(buf,2) = 0;
  2108. WBUFW(buf,4) = 0;
  2109. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2110. return;
  2111. }
  2112. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2113. WBUFW(buf,0) = item->card[0];
  2114. WBUFW(buf,2) = item->card[1];
  2115. WBUFW(buf,4) = item->card[2];
  2116. WBUFW(buf,6) = item->card[3];
  2117. return;
  2118. }
  2119. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2120. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2121. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2122. //Normal items.
  2123. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2124. WBUFW(buf,0) = j;
  2125. else
  2126. WBUFW(buf,0) = item->card[i];
  2127. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2128. WBUFW(buf,2) = j;
  2129. else
  2130. WBUFW(buf,2) = item->card[i];
  2131. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2132. WBUFW(buf,4) = j;
  2133. else
  2134. WBUFW(buf,4) = item->card[i];
  2135. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2136. WBUFW(buf,6) = j;
  2137. else
  2138. WBUFW(buf,6) = item->card[i];
  2139. }
  2140. /// Fills in part of the item buffers that calls for variable bonuses data. [Rytech]
  2141. /// Dummy data used since this feature isnt supported yet (ITEM_RDM_OPT).
  2142. /// A max of 5 random options can be supported.
  2143. void clif_add_random_options(unsigned char* buf, struct item* item)
  2144. {
  2145. #if PACKETVER >= 20150226
  2146. int i;
  2147. for (i = 0; i < 5; i++){
  2148. WBUFW(buf,i*5+0) = 0; // OptIndex
  2149. WBUFW(buf,i*5+2) = 0; // Value
  2150. WBUFB(buf,i*5+4) = 0; // Param1
  2151. }
  2152. #endif
  2153. }
  2154. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2155. /// 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)
  2156. /// 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)
  2157. /// 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)
  2158. /// 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)
  2159. /// 0a0c <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_V6)
  2160. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2161. {
  2162. int fd, header, offs=0;
  2163. #if PACKETVER < 20061218
  2164. header = 0xa0;
  2165. #elif PACKETVER < 20071002
  2166. header = 0x29a;
  2167. #elif PACKETVER < 20120925
  2168. header = 0x2d4;
  2169. #elif PACKETVER < 20150226
  2170. header = 0x990;
  2171. #else
  2172. header = 0xa0c;
  2173. #endif
  2174. nullpo_retv(sd);
  2175. fd = sd->fd;
  2176. if( !session_isActive(fd) ) //Sasuke-
  2177. return;
  2178. WFIFOHEAD(fd,packet_len(header));
  2179. if( fail )
  2180. {
  2181. WFIFOW(fd,offs+0) = header;
  2182. WFIFOW(fd,offs+2) = n+2;
  2183. WFIFOW(fd,offs+4) = amount;
  2184. WFIFOW(fd,offs+6) = 0;
  2185. WFIFOB(fd,offs+8) = 0;
  2186. WFIFOB(fd,offs+9) = 0;
  2187. WFIFOB(fd,offs+10) = 0;
  2188. WFIFOW(fd,offs+11) = 0;
  2189. WFIFOW(fd,offs+13) = 0;
  2190. WFIFOW(fd,offs+15) = 0;
  2191. WFIFOW(fd,offs+17) = 0;
  2192. #if PACKETVER < 20120925
  2193. WFIFOW(fd,offs+19) = 0;
  2194. #else
  2195. WFIFOL(fd,offs+19) = 0;
  2196. offs += 2;
  2197. #endif
  2198. WFIFOB(fd,offs+21) = 0;
  2199. WFIFOB(fd,offs+22) = fail;
  2200. #if PACKETVER >= 20061218
  2201. WFIFOL(fd,offs+23) = 0;
  2202. #endif
  2203. #if PACKETVER >= 20071002
  2204. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2205. #if PACKETVER >= 20150226
  2206. clif_add_random_options(WFIFOP(fd,offs+31), &sd->status.inventory[n]);
  2207. #endif
  2208. #endif
  2209. }
  2210. else
  2211. {
  2212. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2213. return;
  2214. WFIFOW(fd,offs+0) = header;
  2215. WFIFOW(fd,offs+2) = n+2;
  2216. WFIFOW(fd,offs+4) = amount;
  2217. if (sd->inventory_data[n]->view_id > 0)
  2218. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2219. else
  2220. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  2221. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  2222. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  2223. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  2224. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  2225. #if PACKETVER < 20120925
  2226. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2227. #else
  2228. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2229. offs += 2;
  2230. #endif
  2231. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2232. WFIFOB(fd,offs+22) = fail;
  2233. #if PACKETVER >= 20061218
  2234. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  2235. #endif
  2236. #if PACKETVER >= 20071002
  2237. /* Yellow color only for non-stackable item */
  2238. WFIFOW(fd,offs+27) = (sd->status.inventory[n].bound && !itemdb_isstackable(sd->status.inventory[n].nameid)) ? BOUND_DISPYELLOW : sd->inventory_data[n]->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2239. #endif
  2240. #if PACKETVER >= 20150226
  2241. clif_add_random_options(WFIFOP(fd,31), &sd->status.inventory[n]);
  2242. #endif
  2243. }
  2244. WFIFOSET(fd,packet_len(header));
  2245. }
  2246. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2247. /// 00af <index>.W <amount>.W
  2248. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2249. {
  2250. int fd;
  2251. nullpo_retv(sd);
  2252. fd=sd->fd;
  2253. WFIFOHEAD(fd, packet_len(0xaf));
  2254. WFIFOW(fd,0)=0xaf;
  2255. WFIFOW(fd,2)=n+2;
  2256. WFIFOW(fd,4)=amount;
  2257. WFIFOSET(fd,packet_len(0xaf));
  2258. }
  2259. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2260. /// 07fa <delete type>.W <index>.W <amount>.W
  2261. /// delete type:
  2262. /// 0 = Normal
  2263. /// 1 = Item used for a skill
  2264. /// 2 = Refine failed
  2265. /// 3 = Material changed
  2266. /// 4 = Moved to storage
  2267. /// 5 = Moved to cart
  2268. /// 6 = Item sold
  2269. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2270. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2271. {
  2272. #if PACKETVER < 20091117
  2273. clif_dropitem(sd,n,amount);
  2274. #else
  2275. int fd;
  2276. nullpo_retv(sd);
  2277. fd=sd->fd;
  2278. WFIFOHEAD(fd, packet_len(0x7fa));
  2279. WFIFOW(fd,0)=0x7fa;
  2280. WFIFOW(fd,2)=reason;
  2281. WFIFOW(fd,4)=n+2;
  2282. WFIFOW(fd,6)=amount;
  2283. WFIFOSET(fd,packet_len(0x7fa));
  2284. #endif
  2285. }
  2286. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2287. char normal = (equip < 0);
  2288. int offset = 0;
  2289. WBUFW(buf,n) = idx; //index
  2290. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2291. WBUFB(buf,n+4) = itemtype(id->nameid);
  2292. if (!normal){ //equip 31B
  2293. WBUFL(buf,n+5) = equip; //location
  2294. WBUFL(buf,n+9) = it->equip; //wear state
  2295. WBUFB(buf,n+13) = it->refine; //refine lvl
  2296. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2297. WBUFL(buf,n+22) = it->expire_time;
  2298. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2299. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2300. #if PACKETVER >= 20150226
  2301. //V6_ITEM_Option
  2302. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2303. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2304. offset += 26;
  2305. #endif
  2306. //V5_ITEM_flag
  2307. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2308. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2309. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2310. }
  2311. else { //normal 24B
  2312. WBUFW(buf,n+5) = it->amount;
  2313. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2314. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2315. WBUFL(buf,n+19) = it->expire_time;
  2316. //V5_ITEM_flag
  2317. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2318. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2319. }
  2320. }
  2321. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2322. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2323. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2324. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2325. #if PACKETVER >= 20120925
  2326. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2327. #else
  2328. WBUFW(buf,n) = idx; //index
  2329. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2330. WBUFB(buf,n+4) = itemtype(id->nameid);
  2331. WBUFB(buf,n+5) = it->identify;
  2332. if (equip >= 0) { //Equippable item 28.B
  2333. WBUFW(buf,n+6) = equip;
  2334. WBUFW(buf,n+8) = it->equip;
  2335. WBUFB(buf,n+10) = it->attribute;
  2336. WBUFB(buf,n+11) = it->refine;
  2337. clif_addcards(WBUFP(buf, n+12), it); //8B
  2338. #if PACKETVER >= 20071002
  2339. WBUFL(buf,n+20) = it->expire_time;
  2340. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2341. #endif
  2342. #if PACKETVER >= 20100629
  2343. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2344. #endif
  2345. } else { //Stackable item. 22.B
  2346. WBUFW(buf,n+6) = it->amount;
  2347. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2348. clif_addcards(WBUFP(buf, n+10), it); //8B
  2349. #if PACKETVER >= 20071002
  2350. WBUFL(buf,n+18) = it->expire_time;
  2351. #endif
  2352. }
  2353. #endif
  2354. }
  2355. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2356. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2357. void clif_inventorylist(struct map_session_data *sd) {
  2358. int i,n,ne,arrow=-1;
  2359. unsigned char *buf;
  2360. unsigned char *bufe;
  2361. #if PACKETVER < 5
  2362. const int s = 10; //Entry size
  2363. #elif PACKETVER < 20080102
  2364. const int s = 18;
  2365. #elif PACKETVER < 20120925
  2366. const int s = 22;
  2367. #else
  2368. const int s = 24;
  2369. #endif
  2370. #if PACKETVER < 20071002
  2371. const int se = 20;
  2372. #elif PACKETVER < 20100629
  2373. const int se = 26;
  2374. #elif PACKETVER < 20120925
  2375. const int se = 28;
  2376. #elif PACKETVER < 20150226
  2377. const int se = 31;
  2378. #else
  2379. const int se = 57;
  2380. #endif
  2381. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2382. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2383. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2384. {
  2385. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2386. continue;
  2387. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2388. { //Non-stackable (Equippable)
  2389. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2390. ne++;
  2391. }
  2392. else { //Stackable.
  2393. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2394. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2395. arrow=i;
  2396. n++;
  2397. }
  2398. }
  2399. if( n )
  2400. {
  2401. #if PACKETVER < 5
  2402. WBUFW(buf,0)=0xa3;
  2403. #elif PACKETVER < 20080102
  2404. WBUFW(buf,0)=0x1ee;
  2405. #elif PACKETVER < 20120925
  2406. WBUFW(buf,0)=0x2e8;
  2407. #else
  2408. WBUFW(buf,0)=0x991;
  2409. #endif
  2410. WBUFW(buf,2)=4+n*s;
  2411. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2412. }
  2413. if( arrow >= 0 )
  2414. clif_arrowequip(sd,arrow);
  2415. if( ne ) {
  2416. #if PACKETVER < 20071002
  2417. WBUFW(bufe,0)=0xa4;
  2418. #elif PACKETVER < 20120925
  2419. WBUFW(bufe,0)=0x2d0;
  2420. #elif PACKETVER < 20150226
  2421. WBUFW(bufe,0)=0x992;
  2422. #else
  2423. WBUFW(bufe,0)=0xa0d;
  2424. #endif
  2425. WBUFW(bufe,2)=4+ne*se;
  2426. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2427. }
  2428. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2429. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2430. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2431. continue;
  2432. if ( sd->status.inventory[i].favorite )
  2433. clif_favorite_item(sd, i);
  2434. }
  2435. #endif
  2436. if( buf ) aFree(buf);
  2437. if( bufe ) aFree(bufe);
  2438. }
  2439. //Required when items break/get-repaired. Only sends equippable item list.
  2440. void clif_equiplist(struct map_session_data *sd)
  2441. {
  2442. int i,n,fd = sd->fd;
  2443. unsigned char *buf;
  2444. #if PACKETVER < 20071002
  2445. const int cmd = 20;
  2446. #elif PACKETVER < 20100629
  2447. const int cmd = 26;
  2448. #elif PACKETVER < 20120925
  2449. const int cmd = 28;
  2450. #elif PACKETVER < 20150226
  2451. const int cmd = 31;
  2452. #else
  2453. const int cmd = 57;
  2454. #endif
  2455. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2456. buf = WFIFOP(fd,0);
  2457. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2458. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2459. continue;
  2460. if(itemdb_isstackable2(sd->inventory_data[i]))
  2461. continue;
  2462. //Equippable
  2463. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2464. n++;
  2465. }
  2466. if (n) {
  2467. #if PACKETVER < 20071002
  2468. WBUFW(buf,0)=0xa4;
  2469. #elif PACKETVER < 20120925
  2470. WBUFW(buf,0)=0x2d0;
  2471. #elif PACKETVER < 20150226
  2472. WBUFW(buf,0)=0x992;
  2473. #else
  2474. WBUFW(buf,0)=0xa0d;
  2475. #endif
  2476. WBUFW(buf,2)=4+n*cmd;
  2477. WFIFOSET(fd,WFIFOW(fd,2));
  2478. }
  2479. }
  2480. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2481. {
  2482. static const int client_buf = 0x5000; // Max buffer to send
  2483. struct item_data *id;
  2484. int i,n,ne,nn;
  2485. unsigned char *buf;
  2486. unsigned char *bufe;
  2487. #if PACKETVER < 5
  2488. const int s = 10; //Entry size.normal item
  2489. const int sidx=4; //start itemlist idx
  2490. const int cmd = 0xa5;
  2491. #elif PACKETVER < 20080102
  2492. const int s = 18;
  2493. const int sidx=4;
  2494. const int cmd = 0x1f0;
  2495. #elif PACKETVER < 20120925
  2496. const int s = 22;
  2497. const int sidx=4;
  2498. const int cmd = 0x2ea;
  2499. #else
  2500. const int s = 24;
  2501. const int sidx = 4+24;
  2502. const int cmd = 0x995;
  2503. #endif
  2504. #if PACKETVER < 20071002
  2505. const int se = 20; //entry size equip
  2506. const int sidxe = 4; //start itemlist idx
  2507. const int cmde = 0xa6;
  2508. #elif PACKETVER < 20100629
  2509. const int se = 26;
  2510. const int sidxe = 4;
  2511. const int cmde = 0x2d1;
  2512. #elif PACKETVER < 20120925
  2513. const int se = 28;
  2514. const int sidxe = 4;
  2515. const int cmde = 0x2d1;
  2516. #elif PACKETVER < 20150226
  2517. const int se = 31;
  2518. const int sidxe = 4+24;
  2519. const int cmde = 0x996;
  2520. #else
  2521. const int se = 57;
  2522. const int sidxe = 4+24;
  2523. const int cmde = 0xa10;
  2524. #endif
  2525. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2526. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2527. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2528. {
  2529. if( items[i].nameid <= 0 )
  2530. continue;
  2531. id = itemdb_search(items[i].nameid);
  2532. if( !itemdb_isstackable2(id) ) { //Equippable
  2533. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2534. ne++;
  2535. }
  2536. else { //Stackable
  2537. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2538. n++;
  2539. }
  2540. }
  2541. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2542. {
  2543. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2544. WFIFOHEAD(sd->fd,sidx+nn*s);
  2545. WFIFOW(sd->fd,0)=cmd;
  2546. WFIFOW(sd->fd,2)=sidx+nn*s;
  2547. #if PACKETVER >= 20120925
  2548. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2549. #endif
  2550. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2551. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2552. }
  2553. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2554. {
  2555. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2556. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2557. WFIFOW(sd->fd,0)=cmde;
  2558. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2559. #if PACKETVER >= 20120925
  2560. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2561. #endif
  2562. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2563. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2564. }
  2565. if( buf ) aFree(buf);
  2566. if( bufe ) aFree(bufe);
  2567. }
  2568. void clif_cartlist(struct map_session_data *sd)
  2569. {
  2570. struct item_data *id;
  2571. int i,n,ne;
  2572. unsigned char *buf;
  2573. unsigned char *bufe;
  2574. #if PACKETVER < 5
  2575. const int s = 10; //Entry size.
  2576. #elif PACKETVER < 20080102
  2577. const int s = 18;
  2578. #elif PACKETVER < 20120925
  2579. const int s = 22;
  2580. #else
  2581. const int s = 24;
  2582. #endif
  2583. #if PACKETVER < 20071002
  2584. const int cmd = 20;
  2585. #elif PACKETVER < 20100629
  2586. const int cmd = 26;
  2587. #elif PACKETVER < 20120925
  2588. const int cmd = 28;
  2589. #elif PACKETVER < 20150226
  2590. const int cmd = 31;
  2591. #else
  2592. const int cmd = 57;
  2593. #endif
  2594. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2595. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2596. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2597. {
  2598. if( sd->status.cart[i].nameid <= 0 )
  2599. continue;
  2600. id = itemdb_search(sd->status.cart[i].nameid);
  2601. if( !itemdb_isstackable2(id) ) { //Equippable
  2602. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2603. ne++;
  2604. }
  2605. else { //Stackable
  2606. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2607. n++;
  2608. }
  2609. }
  2610. if( n )
  2611. {
  2612. #if PACKETVER < 5
  2613. WBUFW(buf,0)=0x123;
  2614. #elif PACKETVER < 20080102
  2615. WBUFW(buf,0)=0x1ef;
  2616. #elif PACKETVER < 20120925
  2617. WBUFW(buf,0)=0x2e9;
  2618. #else
  2619. WBUFW(buf,0)=0x993;
  2620. #endif
  2621. WBUFW(buf,2)=4+n*s;
  2622. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2623. }
  2624. if( ne )
  2625. {
  2626. #if PACKETVER < 20071002
  2627. WBUFW(bufe,0)=0x122;
  2628. #elif PACKETVER < 20120925
  2629. WBUFW(bufe,0)=0x2d2;
  2630. #elif PACKETVER < 20150226
  2631. WBUFW(bufe,0)=0x994;
  2632. #else
  2633. WBUFW(bufe,0)=0xa0f;
  2634. #endif
  2635. WBUFW(bufe,2)=4+ne*cmd;
  2636. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2637. }
  2638. if( buf ) aFree(buf);
  2639. if( bufe ) aFree(bufe);
  2640. }
  2641. /// Removes cart (ZC_CARTOFF).
  2642. /// 012b
  2643. /// Client behaviour:
  2644. /// Closes the cart storage and removes all it's items from memory.
  2645. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2646. void clif_clearcart(int fd)
  2647. {
  2648. WFIFOHEAD(fd, packet_len(0x12b));
  2649. WFIFOW(fd,0) = 0x12b;
  2650. WFIFOSET(fd, packet_len(0x12b));
  2651. }
  2652. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2653. /// 01eb <account id>.L <x>.W <y>.W
  2654. void clif_guild_xy(struct map_session_data *sd)
  2655. {
  2656. unsigned char buf[10];
  2657. nullpo_retv(sd);
  2658. WBUFW(buf,0)=0x1eb;
  2659. WBUFL(buf,2)=sd->status.account_id;
  2660. WBUFW(buf,6)=sd->bl.x;
  2661. WBUFW(buf,8)=sd->bl.y;
  2662. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2663. }
  2664. /*==========================================
  2665. * Sends x/y dot to a single fd. [Skotlex]
  2666. *------------------------------------------*/
  2667. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2668. {
  2669. if( sd->bg_id )
  2670. return;
  2671. WFIFOHEAD(fd,packet_len(0x1eb));
  2672. WFIFOW(fd,0)=0x1eb;
  2673. WFIFOL(fd,2)=sd->status.account_id;
  2674. WFIFOW(fd,6)=sd->bl.x;
  2675. WFIFOW(fd,8)=sd->bl.y;
  2676. WFIFOSET(fd,packet_len(0x1eb));
  2677. }
  2678. // Guild XY locators [Valaris]
  2679. void clif_guild_xy_remove(struct map_session_data *sd)
  2680. {
  2681. unsigned char buf[10];
  2682. nullpo_retv(sd);
  2683. WBUFW(buf,0)=0x1eb;
  2684. WBUFL(buf,2)=sd->status.account_id;
  2685. WBUFW(buf,6)=-1;
  2686. WBUFW(buf,8)=-1;
  2687. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2688. }
  2689. /*==========================================
  2690. *
  2691. *------------------------------------------*/
  2692. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2693. {
  2694. struct map_session_data *sd, *tsd;
  2695. #if PACKETVER < 20100126
  2696. const int cmd = 0x106;
  2697. #else
  2698. const int cmd = 0x80e;
  2699. #endif
  2700. sd = va_arg(ap, struct map_session_data *);
  2701. tsd = (TBL_PC *)bl;
  2702. nullpo_ret(sd);
  2703. nullpo_ret(tsd);
  2704. if( !tsd->fd || tsd == sd )
  2705. return 0;
  2706. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2707. return 0;
  2708. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2709. WFIFOW(tsd->fd,0) = cmd;
  2710. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2711. #if PACKETVER < 20100126
  2712. if( sd->battle_status.max_hp > INT16_MAX )
  2713. { //To correctly display the %hp bar. [Skotlex]
  2714. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2715. WFIFOW(tsd->fd,8) = 100;
  2716. } else {
  2717. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2718. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2719. }
  2720. #else
  2721. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2722. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2723. #endif
  2724. WFIFOSET(tsd->fd,packet_len(cmd));
  2725. return 0;
  2726. }
  2727. /*==========================================
  2728. * Server tells all players that are allowed to view HP bars
  2729. * and are nearby 'sd' that 'sd' hp bar was updated.
  2730. *------------------------------------------*/
  2731. static int clif_hpmeter(struct map_session_data *sd)
  2732. {
  2733. nullpo_ret(sd);
  2734. 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);
  2735. return 0;
  2736. }
  2737. /// Notifies client of a character parameter change.
  2738. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2739. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2740. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2741. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2742. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2743. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2744. /// TODO: Extract individual packets.
  2745. /// FIXME: Packet lengths from packet_len(cmd)
  2746. void clif_updatestatus(struct map_session_data *sd,int type)
  2747. {
  2748. int fd,len=8;
  2749. nullpo_retv(sd);
  2750. fd=sd->fd;
  2751. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2752. return;
  2753. WFIFOHEAD(fd, 14);
  2754. WFIFOW(fd,0)=0xb0;
  2755. WFIFOW(fd,2)=type;
  2756. switch(type){
  2757. // 00b0
  2758. case SP_WEIGHT:
  2759. pc_updateweightstatus(sd);
  2760. WFIFOHEAD(fd,14);
  2761. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2762. WFIFOW(fd,2)=type;
  2763. WFIFOL(fd,4)=sd->weight;
  2764. break;
  2765. case SP_MAXWEIGHT:
  2766. WFIFOL(fd,4)=sd->max_weight;
  2767. break;
  2768. case SP_SPEED:
  2769. WFIFOL(fd,4)=sd->battle_status.speed;
  2770. break;
  2771. case SP_BASELEVEL:
  2772. WFIFOL(fd,4)=sd->status.base_level;
  2773. break;
  2774. case SP_JOBLEVEL:
  2775. WFIFOL(fd,4)=sd->status.job_level;
  2776. break;
  2777. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2778. WFIFOL(fd,4)=sd->status.karma;
  2779. break;
  2780. case SP_MANNER:
  2781. WFIFOL(fd,4)=sd->status.manner;
  2782. break;
  2783. case SP_STATUSPOINT:
  2784. WFIFOL(fd,4)=sd->status.status_point;
  2785. break;
  2786. case SP_SKILLPOINT:
  2787. WFIFOL(fd,4)=sd->status.skill_point;
  2788. break;
  2789. case SP_HIT:
  2790. WFIFOL(fd,4)=sd->battle_status.hit;
  2791. break;
  2792. case SP_FLEE1:
  2793. WFIFOL(fd,4)=sd->battle_status.flee;
  2794. break;
  2795. case SP_FLEE2:
  2796. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2797. break;
  2798. case SP_MAXHP:
  2799. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2800. break;
  2801. case SP_MAXSP:
  2802. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2803. break;
  2804. case SP_HP:
  2805. // On officials the HP never go below 1, even if you die [Lemongrass]
  2806. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2807. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2808. // TODO: Won't these overwrite the current packet?
  2809. if( map[sd->bl.m].hpmeter_visible )
  2810. clif_hpmeter(sd);
  2811. if( !battle_config.party_hp_mode && sd->status.party_id )
  2812. clif_party_hp(sd);
  2813. if( sd->bg_id )
  2814. clif_bg_hp(sd);
  2815. break;
  2816. case SP_SP:
  2817. WFIFOL(fd,4)=sd->battle_status.sp;
  2818. break;
  2819. case SP_ASPD:
  2820. WFIFOL(fd,4)=sd->battle_status.amotion;
  2821. break;
  2822. case SP_ATK1:
  2823. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2824. break;
  2825. case SP_DEF1:
  2826. WFIFOL(fd,4)=pc_leftside_def(sd);
  2827. break;
  2828. case SP_MDEF1:
  2829. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2830. break;
  2831. case SP_ATK2:
  2832. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2833. break;
  2834. case SP_DEF2:
  2835. WFIFOL(fd,4)=pc_rightside_def(sd);
  2836. break;
  2837. case SP_MDEF2: {
  2838. //negative check (in case you have something like Berserk active)
  2839. int mdef2 = pc_rightside_mdef(sd);
  2840. WFIFOL(fd,4)=
  2841. #ifndef RENEWAL
  2842. ( mdef2 < 0 ) ? 0 :
  2843. #endif
  2844. mdef2;
  2845. }
  2846. break;
  2847. case SP_CRITICAL:
  2848. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2849. break;
  2850. case SP_MATK1:
  2851. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2852. break;
  2853. case SP_MATK2:
  2854. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2855. break;
  2856. case SP_ZENY:
  2857. WFIFOW(fd,0)=0xb1;
  2858. WFIFOL(fd,4)=sd->status.zeny;
  2859. break;
  2860. case SP_BASEEXP:
  2861. WFIFOW(fd,0)=0xb1;
  2862. WFIFOL(fd,4)=sd->status.base_exp;
  2863. break;
  2864. case SP_JOBEXP:
  2865. WFIFOW(fd,0)=0xb1;
  2866. WFIFOL(fd,4)=sd->status.job_exp;
  2867. break;
  2868. case SP_NEXTBASEEXP:
  2869. WFIFOW(fd,0)=0xb1;
  2870. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2871. break;
  2872. case SP_NEXTJOBEXP:
  2873. WFIFOW(fd,0)=0xb1;
  2874. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2875. break;
  2876. /**
  2877. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2878. **/
  2879. case SP_USTR:
  2880. case SP_UAGI:
  2881. case SP_UVIT:
  2882. case SP_UINT:
  2883. case SP_UDEX:
  2884. case SP_ULUK:
  2885. WFIFOW(fd,0)=0xbe;
  2886. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2887. len=5;
  2888. break;
  2889. /**
  2890. * Tells the client how far it is allowed to attack (weapon range)
  2891. **/
  2892. case SP_ATTACKRANGE:
  2893. WFIFOW(fd,0)=0x13a;
  2894. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2895. len=4;
  2896. break;
  2897. case SP_STR:
  2898. WFIFOW(fd,0)=0x141;
  2899. WFIFOL(fd,2)=type;
  2900. WFIFOL(fd,6)=sd->status.str;
  2901. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2902. len=14;
  2903. break;
  2904. case SP_AGI:
  2905. WFIFOW(fd,0)=0x141;
  2906. WFIFOL(fd,2)=type;
  2907. WFIFOL(fd,6)=sd->status.agi;
  2908. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2909. len=14;
  2910. break;
  2911. case SP_VIT:
  2912. WFIFOW(fd,0)=0x141;
  2913. WFIFOL(fd,2)=type;
  2914. WFIFOL(fd,6)=sd->status.vit;
  2915. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2916. len=14;
  2917. break;
  2918. case SP_INT:
  2919. WFIFOW(fd,0)=0x141;
  2920. WFIFOL(fd,2)=type;
  2921. WFIFOL(fd,6)=sd->status.int_;
  2922. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2923. len=14;
  2924. break;
  2925. case SP_DEX:
  2926. WFIFOW(fd,0)=0x141;
  2927. WFIFOL(fd,2)=type;
  2928. WFIFOL(fd,6)=sd->status.dex;
  2929. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2930. len=14;
  2931. break;
  2932. case SP_LUK:
  2933. WFIFOW(fd,0)=0x141;
  2934. WFIFOL(fd,2)=type;
  2935. WFIFOL(fd,6)=sd->status.luk;
  2936. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2937. len=14;
  2938. break;
  2939. case SP_CARTINFO:
  2940. WFIFOW(fd,0)=0x121;
  2941. WFIFOW(fd,2)=sd->cart_num;
  2942. WFIFOW(fd,4)=MAX_CART;
  2943. WFIFOL(fd,6)=sd->cart_weight;
  2944. WFIFOL(fd,10)=sd->cart_weight_max;
  2945. len=14;
  2946. break;
  2947. default:
  2948. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2949. return;
  2950. }
  2951. WFIFOSET(fd,len);
  2952. }
  2953. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2954. /// 01ab <account id>.L <var id>.W <value>.L
  2955. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2956. {
  2957. unsigned char buf[12];
  2958. nullpo_retv(sd);
  2959. WBUFW(buf,0)=0x1ab;
  2960. WBUFL(buf,2)=sd->bl.id;
  2961. WBUFW(buf,6)=type;
  2962. switch(type)
  2963. {
  2964. case SP_MANNER:
  2965. WBUFL(buf,8)=val;
  2966. break;
  2967. default:
  2968. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2969. return;
  2970. }
  2971. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2972. }
  2973. /// Updates sprite/style properties of an object.
  2974. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2975. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2976. void clif_changelook(struct block_list *bl,int type,int val)
  2977. {
  2978. unsigned char buf[16];
  2979. struct map_session_data* sd;
  2980. struct status_change* sc;
  2981. struct view_data* vd;
  2982. enum send_target target = AREA;
  2983. nullpo_retv(bl);
  2984. sd = BL_CAST(BL_PC, bl);
  2985. sc = status_get_sc(bl);
  2986. vd = status_get_viewdata(bl);
  2987. //nullpo_ret(vd);
  2988. if( vd ) //temp hack to let Warp Portal change appearance
  2989. switch(type)
  2990. {
  2991. case LOOK_WEAPON:
  2992. if (sd)
  2993. {
  2994. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2995. val = vd->weapon;
  2996. }
  2997. else vd->weapon = val;
  2998. break;
  2999. case LOOK_SHIELD:
  3000. if (sd)
  3001. {
  3002. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3003. val = vd->shield;
  3004. }
  3005. else vd->shield = val;
  3006. break;
  3007. case LOOK_BASE:
  3008. if (!sd) break;
  3009. if (sd->sc.option&OPTION_COSTUME)
  3010. vd->weapon = vd->shield = 0;
  3011. if (!vd->cloth_color)
  3012. break;
  3013. if (sd) {
  3014. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3015. vd->cloth_color = 0;
  3016. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3017. vd->cloth_color = 0;
  3018. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3019. vd->cloth_color = 0;
  3020. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3021. vd->cloth_color = 0;
  3022. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3023. vd->cloth_color = 0;
  3024. if (vd->body_style && (
  3025. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3026. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3027. sd->sc.option&OPTION_OKTOBERFEST))
  3028. vd->body_style = 0;
  3029. }
  3030. break;
  3031. case LOOK_HAIR:
  3032. vd->hair_style = val;
  3033. break;
  3034. case LOOK_HEAD_BOTTOM:
  3035. vd->head_bottom = val;
  3036. break;
  3037. case LOOK_HEAD_TOP:
  3038. vd->head_top = val;
  3039. break;
  3040. case LOOK_HEAD_MID:
  3041. vd->head_mid = val;
  3042. break;
  3043. case LOOK_HAIR_COLOR:
  3044. vd->hair_color = val;
  3045. break;
  3046. case LOOK_CLOTHES_COLOR:
  3047. if (val && sd) {
  3048. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3049. val = 0;
  3050. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3051. val = 0;
  3052. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3053. val = 0;
  3054. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3055. val = 0;
  3056. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3057. val = 0;
  3058. }
  3059. vd->cloth_color = val;
  3060. break;
  3061. case LOOK_SHOES:
  3062. #if PACKETVER > 3
  3063. if (sd) {
  3064. int n;
  3065. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3066. if(sd->inventory_data[n]->view_id > 0)
  3067. val = sd->inventory_data[n]->view_id;
  3068. else
  3069. val = sd->status.inventory[n].nameid;
  3070. } else
  3071. val = 0;
  3072. }
  3073. #endif
  3074. //Shoes? No packet uses this....
  3075. break;
  3076. case LOOK_BODY:
  3077. // unknown purpose
  3078. break;
  3079. case LOOK_ROBE:
  3080. #if PACKETVER < 20110111
  3081. return;
  3082. #else
  3083. vd->robe = val;
  3084. #endif
  3085. break;
  3086. case LOOK_BODY2:
  3087. #if PACKETVER < 20150513
  3088. return;
  3089. #else
  3090. if (val && (
  3091. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3092. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3093. sd->sc.option&OPTION_OKTOBERFEST))
  3094. val = 0;
  3095. vd->body_style = val;
  3096. #endif
  3097. break;
  3098. }
  3099. // prevent leaking the presence of GM-hidden objects
  3100. if( sc && sc->option&OPTION_INVISIBLE )
  3101. target = SELF;
  3102. #if PACKETVER < 4
  3103. WBUFW(buf,0)=0xc3;
  3104. WBUFL(buf,2)=bl->id;
  3105. WBUFB(buf,6)=type;
  3106. WBUFB(buf,7)=val;
  3107. clif_send(buf,packet_len(0xc3),bl,target);
  3108. #else
  3109. WBUFW(buf,0)=0x1d7;
  3110. WBUFL(buf,2)=bl->id;
  3111. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3112. WBUFB(buf,6)=LOOK_WEAPON;
  3113. WBUFW(buf,7)=vd->weapon;
  3114. WBUFW(buf,9)=vd->shield;
  3115. } else {
  3116. WBUFB(buf,6)=type;
  3117. WBUFL(buf,7)=val;
  3118. }
  3119. clif_send(buf,packet_len(0x1d7),bl,target);
  3120. #endif
  3121. }
  3122. //Sends a change-base-look packet required for traps as they are triggered.
  3123. void clif_changetraplook(struct block_list *bl,int val)
  3124. {
  3125. unsigned char buf[32];
  3126. #if PACKETVER < 4
  3127. WBUFW(buf,0)=0xc3;
  3128. WBUFL(buf,2)=bl->id;
  3129. WBUFB(buf,6)=LOOK_BASE;
  3130. WBUFB(buf,7)=val;
  3131. clif_send(buf,packet_len(0xc3),bl,AREA);
  3132. #else
  3133. WBUFW(buf,0)=0x1d7;
  3134. WBUFL(buf,2)=bl->id;
  3135. WBUFB(buf,6)=LOOK_BASE;
  3136. WBUFW(buf,7)=val;
  3137. WBUFW(buf,9)=0;
  3138. clif_send(buf,packet_len(0x1d7),bl,AREA);
  3139. #endif
  3140. }
  3141. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3142. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  3143. {
  3144. unsigned char buf[32];
  3145. #if PACKETVER < 4
  3146. WBUFW(buf,0)=0xc3;
  3147. WBUFL(buf,2)=id;
  3148. WBUFB(buf,6)=type;
  3149. WBUFB(buf,7)=val;
  3150. clif_send(buf,packet_len(0xc3),bl,target);
  3151. #else
  3152. WBUFW(buf,0)=0x1d7;
  3153. WBUFL(buf,2)=id;
  3154. WBUFB(buf,6)=type;
  3155. WBUFW(buf,7)=val;
  3156. WBUFW(buf,9)=0;
  3157. clif_send(buf,packet_len(0x1d7),bl,target);
  3158. #endif
  3159. }
  3160. /// Character status (ZC_STATUS).
  3161. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3162. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3163. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3164. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3165. void clif_initialstatus(struct map_session_data *sd) {
  3166. int fd, mdef2;
  3167. unsigned char *buf;
  3168. nullpo_retv(sd);
  3169. fd=sd->fd;
  3170. WFIFOHEAD(fd,packet_len(0xbd));
  3171. buf=WFIFOP(fd,0);
  3172. WBUFW(buf,0)=0xbd;
  3173. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  3174. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  3175. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  3176. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  3177. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  3178. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  3179. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  3180. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  3181. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  3182. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  3183. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  3184. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  3185. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  3186. WBUFW(buf,16) = pc_leftside_atk(sd);
  3187. WBUFW(buf,18) = pc_rightside_atk(sd);
  3188. WBUFW(buf,20) = pc_rightside_matk(sd);
  3189. WBUFW(buf,22) = pc_leftside_matk(sd);
  3190. WBUFW(buf,24) = pc_leftside_def(sd);
  3191. WBUFW(buf,26) = pc_rightside_def(sd);
  3192. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3193. mdef2 = pc_rightside_mdef(sd);
  3194. WBUFW(buf,30) =
  3195. #ifndef RENEWAL
  3196. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3197. #endif
  3198. mdef2;
  3199. WBUFW(buf,32) = sd->battle_status.hit;
  3200. WBUFW(buf,34) = sd->battle_status.flee;
  3201. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3202. WBUFW(buf,38) = sd->battle_status.cri/10;
  3203. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3204. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3205. WFIFOSET(fd,packet_len(0xbd));
  3206. clif_updatestatus(sd,SP_STR);
  3207. clif_updatestatus(sd,SP_AGI);
  3208. clif_updatestatus(sd,SP_VIT);
  3209. clif_updatestatus(sd,SP_INT);
  3210. clif_updatestatus(sd,SP_DEX);
  3211. clif_updatestatus(sd,SP_LUK);
  3212. clif_updatestatus(sd,SP_ATTACKRANGE);
  3213. clif_updatestatus(sd,SP_ASPD);
  3214. }
  3215. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3216. /// 013c <index>.W
  3217. void clif_arrowequip(struct map_session_data *sd,int val)
  3218. {
  3219. int fd;
  3220. nullpo_retv(sd);
  3221. #if PACKETVER >= 20121128
  3222. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3223. #endif
  3224. fd=sd->fd;
  3225. WFIFOHEAD(fd, packet_len(0x013c));
  3226. WFIFOW(fd,0)=0x013c;
  3227. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  3228. WFIFOSET(fd,packet_len(0x013c));
  3229. }
  3230. /// Ammunition action message (ZC_ACTION_FAILURE).
  3231. /// 013b <type>.W
  3232. /// type:
  3233. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3234. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3235. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3236. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3237. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3238. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3239. void clif_arrow_fail(struct map_session_data *sd,int type)
  3240. {
  3241. int fd;
  3242. nullpo_retv(sd);
  3243. fd=sd->fd;
  3244. WFIFOHEAD(fd, packet_len(0x013b));
  3245. WFIFOW(fd,0)=0x013b;
  3246. WFIFOW(fd,2)=type;
  3247. WFIFOSET(fd,packet_len(0x013b));
  3248. }
  3249. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3250. /// 01ad <packet len>.W { <name id>.W }*
  3251. void clif_arrow_create_list(struct map_session_data *sd)
  3252. {
  3253. int i, c;
  3254. int fd;
  3255. nullpo_retv(sd);
  3256. fd = sd->fd;
  3257. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3258. WFIFOW(fd,0) = 0x1ad;
  3259. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3260. short j, nameid = skill_arrow_db[i].nameid;
  3261. if (nameid > 0 && itemdb_exists(nameid) &&
  3262. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3263. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3264. {
  3265. if ((j = itemdb_viewid(nameid)) > 0)
  3266. WFIFOW(fd,c*2+4) = j;
  3267. else
  3268. WFIFOW(fd,c*2+4) = nameid;
  3269. c++;
  3270. }
  3271. }
  3272. WFIFOW(fd,2) = c*2+4;
  3273. WFIFOSET(fd, WFIFOW(fd,2));
  3274. if (c > 0) {
  3275. sd->menuskill_id = AC_MAKINGARROW;
  3276. sd->menuskill_val = c;
  3277. }
  3278. }
  3279. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3280. /// 00bc <status id>.W <result>.B <value>.B
  3281. /// status id:
  3282. /// SP_STR ~ SP_LUK
  3283. /// result:
  3284. /// 0 = failure
  3285. /// 1 = success
  3286. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3287. {
  3288. int fd;
  3289. nullpo_retv(sd);
  3290. fd=sd->fd;
  3291. WFIFOHEAD(fd,packet_len(0xbc));
  3292. WFIFOW(fd,0)=0xbc;
  3293. WFIFOW(fd,2)=type;
  3294. WFIFOB(fd,4)=ok;
  3295. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3296. WFIFOSET(fd,packet_len(0xbc));
  3297. }
  3298. /// Notifies the client about the result of a request to equip an item.
  3299. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3300. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3301. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3302. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3303. /// @ok: //inversed forv2 v5
  3304. /// 0 = failure
  3305. /// 1 = success
  3306. /// 2 = failure due to low level
  3307. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3308. {
  3309. int fd = 0, cmd = 0, look = 0;
  3310. struct s_packet_db *info = NULL;
  3311. nullpo_retv(sd);
  3312. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3313. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3314. return;
  3315. fd = sd->fd;
  3316. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3317. look = sd->inventory_data[n]->look;
  3318. WFIFOHEAD(fd, info->len);
  3319. WFIFOW(fd, 0) = cmd;
  3320. WFIFOW(fd, info->pos[0]) = n+2;
  3321. switch (cmd) {
  3322. case 0xaa:
  3323. WFIFOW(fd, info->pos[1]) = pos;
  3324. if (sd->packet_ver < date2version(20100629))
  3325. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3326. else {
  3327. WFIFOL(fd, info->pos[2]) = look;
  3328. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3329. }
  3330. break;
  3331. case 0x8d0:
  3332. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3333. flag = 1;
  3334. case 0x999:
  3335. if (cmd == 0x999)
  3336. WFIFOL(fd, info->pos[1]) = pos;
  3337. else
  3338. WFIFOW(fd, info->pos[1]) = pos;
  3339. WFIFOL(fd, info->pos[2]) = look;
  3340. WFIFOW(fd, info->pos[3]) = flag;
  3341. break;
  3342. }
  3343. WFIFOSET(fd, info->len);
  3344. }
  3345. /// Notifies the client about the result of a request to take off an item.
  3346. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3347. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3348. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3349. /// @ok : //inversed for v2 v5
  3350. /// 0 = failure
  3351. /// 1 = success
  3352. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3353. {
  3354. int fd,header,offs=0;
  3355. #if PACKETVER >= 20130000
  3356. header = 0x99a;
  3357. ok = ok ? 0:1;
  3358. #elif PACKETVER >= 20110824
  3359. header = 0x8d1;
  3360. ok = ok ? 0:1;
  3361. #else
  3362. header = 0xac;
  3363. #endif
  3364. nullpo_retv(sd);
  3365. fd=sd->fd;
  3366. WFIFOHEAD(fd,packet_len(header));
  3367. WFIFOW(fd,offs+0)=header;
  3368. WFIFOW(fd,offs+2)=n+2;
  3369. #if PACKETVER >= 20130000
  3370. WFIFOL(fd,offs+4)=pos;
  3371. offs +=2;
  3372. #else
  3373. WFIFOW(fd,offs+4)=pos;
  3374. #endif
  3375. WFIFOB(fd,offs+6)=ok;
  3376. WFIFOSET(fd,packet_len(header));
  3377. }
  3378. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3379. /// 019b <id>.L <effect id>.L
  3380. /// effect id:
  3381. /// 0 = base level up
  3382. /// 1 = job level up
  3383. /// 2 = refine failure
  3384. /// 3 = refine success
  3385. /// 4 = game over
  3386. /// 5 = pharmacy success
  3387. /// 6 = pharmacy failure
  3388. /// 7 = base level up (super novice)
  3389. /// 8 = job level up (super novice)
  3390. /// 9 = base level up (taekwon)
  3391. void clif_misceffect(struct block_list* bl,int type)
  3392. {
  3393. unsigned char buf[32];
  3394. nullpo_retv(bl);
  3395. WBUFW(buf,0) = 0x19b;
  3396. WBUFL(buf,2) = bl->id;
  3397. WBUFL(buf,6) = type;
  3398. clif_send(buf,packet_len(0x19b),bl,AREA);
  3399. }
  3400. /// Notifies clients in the area of a state change.
  3401. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3402. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3403. void clif_changeoption(struct block_list* bl)
  3404. {
  3405. unsigned char buf[32];
  3406. struct status_change *sc;
  3407. struct map_session_data* sd;
  3408. nullpo_retv(bl);
  3409. sc = status_get_sc(bl);
  3410. if (!sc) return; //How can an option change if there's no sc?
  3411. sd = BL_CAST(BL_PC, bl);
  3412. #if PACKETVER >= 7
  3413. WBUFW(buf,0) = 0x229;
  3414. WBUFL(buf,2) = bl->id;
  3415. WBUFW(buf,6) = sc->opt1;
  3416. WBUFW(buf,8) = sc->opt2;
  3417. WBUFL(buf,10) = sc->option;
  3418. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3419. if(disguised(bl)) {
  3420. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3421. WBUFL(buf,2) = -bl->id;
  3422. clif_send(buf,packet_len(0x229),bl,SELF);
  3423. WBUFL(buf,2) = bl->id;
  3424. WBUFL(buf,10) = OPTION_INVISIBLE;
  3425. clif_send(buf,packet_len(0x229),bl,SELF);
  3426. } else
  3427. clif_send(buf,packet_len(0x229),bl,AREA);
  3428. #else
  3429. WBUFW(buf,0) = 0x119;
  3430. WBUFL(buf,2) = bl->id;
  3431. WBUFW(buf,6) = sc->opt1;
  3432. WBUFW(buf,8) = sc->opt2;
  3433. WBUFW(buf,10) = sc->option;
  3434. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3435. if(disguised(bl)) {
  3436. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3437. WBUFL(buf,2) = -bl->id;
  3438. clif_send(buf,packet_len(0x119),bl,SELF);
  3439. WBUFL(buf,2) = bl->id;
  3440. WBUFW(buf,10) = OPTION_INVISIBLE;
  3441. clif_send(buf,packet_len(0x119),bl,SELF);
  3442. } else
  3443. clif_send(buf,packet_len(0x119),bl,AREA);
  3444. #endif
  3445. }
  3446. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3447. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3448. void clif_changeoption2(struct block_list* bl)
  3449. {
  3450. unsigned char buf[20];
  3451. struct status_change *sc;
  3452. sc = status_get_sc(bl);
  3453. if (!sc) return; //How can an option change if there's no sc?
  3454. WBUFW(buf,0) = 0x28a;
  3455. WBUFL(buf,2) = bl->id;
  3456. WBUFL(buf,6) = sc->option;
  3457. WBUFL(buf,10) = clif_setlevel(bl);
  3458. WBUFL(buf,14) = sc->opt3;
  3459. if(disguised(bl)) {
  3460. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3461. WBUFL(buf,2) = -bl->id;
  3462. clif_send(buf,packet_len(0x28a),bl,SELF);
  3463. WBUFL(buf,2) = bl->id;
  3464. WBUFL(buf,6) = OPTION_INVISIBLE;
  3465. clif_send(buf,packet_len(0x28a),bl,SELF);
  3466. } else
  3467. clif_send(buf,packet_len(0x28a),bl,AREA);
  3468. }
  3469. /// Notifies the client about the result of an item use request.
  3470. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3471. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3472. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3473. {
  3474. nullpo_retv(sd);
  3475. if(!ok) {
  3476. int fd=sd->fd;
  3477. WFIFOHEAD(fd,packet_len(0xa8));
  3478. WFIFOW(fd,0)=0xa8;
  3479. WFIFOW(fd,2)=index+2;
  3480. WFIFOW(fd,4)=amount;
  3481. WFIFOB(fd,6)=ok;
  3482. WFIFOSET(fd,packet_len(0xa8));
  3483. }
  3484. else {
  3485. #if PACKETVER < 3
  3486. int fd=sd->fd;
  3487. WFIFOHEAD(fd,packet_len(0xa8));
  3488. WFIFOW(fd,0)=0xa8;
  3489. WFIFOW(fd,2)=index+2;
  3490. WFIFOW(fd,4)=amount;
  3491. WFIFOB(fd,6)=ok;
  3492. WFIFOSET(fd,packet_len(0xa8));
  3493. #else
  3494. unsigned char buf[32];
  3495. WBUFW(buf,0)=0x1c8;
  3496. WBUFW(buf,2)=index+2;
  3497. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3498. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3499. else
  3500. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3501. WBUFL(buf,6)=sd->bl.id;
  3502. WBUFW(buf,10)=amount;
  3503. WBUFB(buf,12)=ok;
  3504. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3505. #endif
  3506. }
  3507. }
  3508. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3509. /// 00d6 <flag>.B
  3510. /// flag:
  3511. /// 0 = Room has been successfully created (opens chat room)
  3512. /// 1 = Room limit exceeded
  3513. /// 2 = Same room already exists
  3514. void clif_createchat(struct map_session_data* sd, int flag)
  3515. {
  3516. int fd;
  3517. nullpo_retv(sd);
  3518. fd = sd->fd;
  3519. WFIFOHEAD(fd,packet_len(0xd6));
  3520. WFIFOW(fd,0) = 0xd6;
  3521. WFIFOB(fd,2) = flag;
  3522. WFIFOSET(fd,packet_len(0xd6));
  3523. }
  3524. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3525. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3526. /// type:
  3527. /// 0 = private (password protected)
  3528. /// 1 = public
  3529. /// 2 = arena (npc waiting room)
  3530. /// 3 = PK zone (non-clickable)
  3531. void clif_dispchat(struct chat_data* cd, int fd)
  3532. {
  3533. unsigned char buf[128];
  3534. uint8 type;
  3535. if( cd == NULL || cd->owner == NULL )
  3536. return;
  3537. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3538. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3539. : 1;
  3540. WBUFW(buf, 0) = 0xd7;
  3541. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3542. WBUFL(buf, 4) = cd->owner->id;
  3543. WBUFL(buf, 8) = cd->bl.id;
  3544. WBUFW(buf,12) = cd->limit;
  3545. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3546. WBUFB(buf,16) = type;
  3547. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3548. if( fd ) {
  3549. WFIFOHEAD(fd,WBUFW(buf,2));
  3550. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3551. WFIFOSET(fd,WBUFW(buf,2));
  3552. } else {
  3553. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3554. }
  3555. }
  3556. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3557. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3558. /// type:
  3559. /// 0 = private (password protected)
  3560. /// 1 = public
  3561. /// 2 = arena (npc waiting room)
  3562. /// 3 = PK zone (non-clickable)
  3563. void clif_changechatstatus(struct chat_data* cd)
  3564. {
  3565. unsigned char buf[128];
  3566. uint8 type;
  3567. if( cd == NULL || cd->usersd[0] == NULL )
  3568. return;
  3569. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3570. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3571. : 1;
  3572. WBUFW(buf, 0) = 0xdf;
  3573. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3574. WBUFL(buf, 4) = cd->owner->id;
  3575. WBUFL(buf, 8) = cd->bl.id;
  3576. WBUFW(buf,12) = cd->limit;
  3577. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3578. WBUFB(buf,16) = type;
  3579. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3580. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3581. }
  3582. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3583. /// 00d8 <chat id>.L
  3584. void clif_clearchat(struct chat_data *cd,int fd)
  3585. {
  3586. unsigned char buf[32];
  3587. nullpo_retv(cd);
  3588. WBUFW(buf,0) = 0xd8;
  3589. WBUFL(buf,2) = cd->bl.id;
  3590. if( fd ) {
  3591. WFIFOHEAD(fd,packet_len(0xd8));
  3592. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3593. WFIFOSET(fd,packet_len(0xd8));
  3594. } else {
  3595. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3596. }
  3597. }
  3598. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3599. /// 00da <result>.B
  3600. /// result:
  3601. /// 0 = room full
  3602. /// 1 = wrong password
  3603. /// 2 = kicked
  3604. /// 3 = success (no message)
  3605. /// 4 = no enough zeny
  3606. /// 5 = too low level
  3607. /// 6 = too high level
  3608. /// 7 = unsuitable job class
  3609. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3610. {
  3611. int fd;
  3612. nullpo_retv(sd);
  3613. fd = sd->fd;
  3614. WFIFOHEAD(fd,packet_len(0xda));
  3615. WFIFOW(fd,0) = 0xda;
  3616. WFIFOB(fd,2) = flag;
  3617. WFIFOSET(fd,packet_len(0xda));
  3618. }
  3619. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3620. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3621. /// role:
  3622. /// 0 = owner (menu)
  3623. /// 1 = normal
  3624. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3625. {
  3626. int fd;
  3627. int i,t;
  3628. nullpo_retv(sd);
  3629. nullpo_retv(cd);
  3630. fd = sd->fd;
  3631. if (!session_isActive(fd))
  3632. return;
  3633. t = (int)(cd->owner->type == BL_NPC);
  3634. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3635. WFIFOW(fd, 0) = 0xdb;
  3636. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3637. WFIFOL(fd, 4) = cd->bl.id;
  3638. if(cd->owner->type == BL_NPC){
  3639. WFIFOL(fd, 30) = 1;
  3640. WFIFOL(fd, 8) = 0;
  3641. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3642. for (i = 0; i < cd->users; i++) {
  3643. WFIFOL(fd, 8+(i+1)*28) = 1;
  3644. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3645. }
  3646. } else
  3647. for (i = 0; i < cd->users; i++) {
  3648. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3649. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3650. }
  3651. WFIFOSET(fd, WFIFOW(fd, 2));
  3652. }
  3653. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3654. /// 00dc <users>.W <name>.24B
  3655. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3656. {
  3657. unsigned char buf[29];
  3658. nullpo_retv(sd);
  3659. nullpo_retv(cd);
  3660. WBUFW(buf, 0) = 0xdc;
  3661. WBUFW(buf, 2) = cd->users;
  3662. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3663. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3664. }
  3665. /// Announce the new owner (ZC_ROLE_CHANGE).
  3666. /// 00e1 <role>.L <nick>.24B
  3667. /// role:
  3668. /// 0 = owner (menu)
  3669. /// 1 = normal
  3670. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3671. {
  3672. unsigned char buf[64];
  3673. nullpo_retv(sd);
  3674. nullpo_retv(cd);
  3675. WBUFW(buf, 0) = 0xe1;
  3676. WBUFL(buf, 2) = 1;
  3677. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3678. WBUFW(buf,30) = 0xe1;
  3679. WBUFL(buf,32) = 0;
  3680. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3681. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3682. }
  3683. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3684. /// 00dd <users>.W <nick>.24B <flag>.B
  3685. /// flag:
  3686. /// 0 = left
  3687. /// 1 = kicked
  3688. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3689. {
  3690. unsigned char buf[32];
  3691. nullpo_retv(sd);
  3692. nullpo_retv(cd);
  3693. WBUFW(buf, 0) = 0xdd;
  3694. WBUFW(buf, 2) = cd->users-1;
  3695. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3696. WBUFB(buf,28) = flag;
  3697. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3698. }
  3699. /// Opens a trade request window from char 'name'.
  3700. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3701. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3702. void clif_traderequest(struct map_session_data* sd, const char* name)
  3703. {
  3704. int fd = sd->fd;
  3705. #if PACKETVER < 6
  3706. WFIFOHEAD(fd,packet_len(0xe5));
  3707. WFIFOW(fd,0) = 0xe5;
  3708. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3709. WFIFOSET(fd,packet_len(0xe5));
  3710. #else
  3711. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3712. if( !tsd ) return;
  3713. WFIFOHEAD(fd,packet_len(0x1f4));
  3714. WFIFOW(fd,0) = 0x1f4;
  3715. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3716. WFIFOL(fd,26) = tsd->status.char_id;
  3717. WFIFOW(fd,30) = tsd->status.base_level;
  3718. WFIFOSET(fd,packet_len(0x1f4));
  3719. #endif
  3720. }
  3721. /// Reply to a trade-request.
  3722. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3723. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3724. /// result:
  3725. /// 0 = Char is too far
  3726. /// 1 = Character does not exist
  3727. /// 2 = Trade failed
  3728. /// 3 = Accept
  3729. /// 4 = Cancel
  3730. /// 5 = Busy
  3731. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3732. {
  3733. int fd = sd->fd;
  3734. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3735. if( PACKETVER < 6 || !tsd ) {
  3736. WFIFOHEAD(fd,packet_len(0xe7));
  3737. WFIFOW(fd,0) = 0xe7;
  3738. WFIFOB(fd,2) = type;
  3739. WFIFOSET(fd,packet_len(0xe7));
  3740. } else {
  3741. WFIFOHEAD(fd,packet_len(0x1f5));
  3742. WFIFOW(fd,0) = 0x1f5;
  3743. WFIFOB(fd,2) = type;
  3744. WFIFOL(fd,3) = tsd->status.char_id;
  3745. WFIFOW(fd,7) = tsd->status.base_level;
  3746. WFIFOSET(fd,packet_len(0x1f5));
  3747. }
  3748. }
  3749. /// Notifies the client about an item from other player in current trade.
  3750. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3751. /// 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)
  3752. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM3)
  3753. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3754. {
  3755. int fd;
  3756. unsigned char *buf;
  3757. #if PACKETVER < 20100223
  3758. const int cmd = 0xe9;
  3759. #elif PACKETVER < 20150226
  3760. const int cmd = 0x80f;
  3761. #else
  3762. const int cmd = 0xa09;
  3763. #endif
  3764. nullpo_retv(sd);
  3765. nullpo_retv(tsd);
  3766. fd = tsd->fd;
  3767. buf = WFIFOP(fd,0);
  3768. WFIFOHEAD(fd,packet_len(cmd));
  3769. WBUFW(buf,0) = cmd;
  3770. if( index == 0 )
  3771. {
  3772. #if PACKETVER < 20100223
  3773. WBUFL(buf,2) = amount; //amount
  3774. WBUFW(buf,6) = 0; // type id
  3775. #else
  3776. WBUFW(buf,2) = 0; // type id
  3777. WBUFB(buf,4) = 0; // item type
  3778. WBUFL(buf,5) = amount; // amount
  3779. buf = WBUFP(buf,1); //Advance 1B
  3780. #endif
  3781. WBUFB(buf,8) = 0; //identify flag
  3782. WBUFB(buf,9) = 0; // attribute
  3783. WBUFB(buf,10)= 0; //refine
  3784. WBUFW(buf,11)= 0; //card (4w)
  3785. WBUFW(buf,13)= 0; //card (4w)
  3786. WBUFW(buf,15)= 0; //card (4w)
  3787. WBUFW(buf,17)= 0; //card (4w)
  3788. #if PACKETVER >= 20150226
  3789. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3790. #endif
  3791. }
  3792. else
  3793. {
  3794. index -= 2; //index fix
  3795. #if PACKETVER < 20100223
  3796. WBUFL(buf,2) = amount; //amount
  3797. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3798. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3799. else
  3800. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3801. #else
  3802. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3803. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3804. else
  3805. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3806. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3807. WBUFL(buf,5) = amount; // amount
  3808. buf = WBUFP(buf,1); //Advance 1B
  3809. #endif
  3810. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3811. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3812. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3813. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3814. #if PACKETVER >= 20150226
  3815. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3816. #endif
  3817. }
  3818. WFIFOSET(fd,packet_len(cmd));
  3819. }
  3820. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3821. /// 00ea <index>.W <result>.B
  3822. /// result:
  3823. /// 0 = success
  3824. /// 1 = overweight
  3825. /// 2 = trade canceled
  3826. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3827. {
  3828. int fd;
  3829. nullpo_retv(sd);
  3830. fd = sd->fd;
  3831. WFIFOHEAD(fd,packet_len(0xea));
  3832. WFIFOW(fd,0) = 0xea;
  3833. WFIFOW(fd,2) = index;
  3834. WFIFOB(fd,4) = fail;
  3835. WFIFOSET(fd,packet_len(0xea));
  3836. }
  3837. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3838. /// 00ec <who>.B
  3839. /// who:
  3840. /// 0 = self
  3841. /// 1 = other player
  3842. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3843. {
  3844. int fd;
  3845. nullpo_retv(sd);
  3846. fd = sd->fd;
  3847. WFIFOHEAD(fd,packet_len(0xec));
  3848. WFIFOW(fd,0) = 0xec;
  3849. WFIFOB(fd,2) = fail;
  3850. WFIFOSET(fd,packet_len(0xec));
  3851. }
  3852. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3853. /// 00ee
  3854. void clif_tradecancelled(struct map_session_data* sd)
  3855. {
  3856. int fd;
  3857. nullpo_retv(sd);
  3858. fd = sd->fd;
  3859. WFIFOHEAD(fd,packet_len(0xee));
  3860. WFIFOW(fd,0) = 0xee;
  3861. WFIFOSET(fd,packet_len(0xee));
  3862. }
  3863. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3864. /// 00f0 <result>.B
  3865. /// result:
  3866. /// 0 = success
  3867. /// 1 = failure
  3868. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3869. {
  3870. int fd;
  3871. nullpo_retv(sd);
  3872. fd = sd->fd;
  3873. WFIFOHEAD(fd,packet_len(0xf0));
  3874. WFIFOW(fd,0) = 0xf0;
  3875. WFIFOB(fd,2) = fail;
  3876. WFIFOSET(fd,packet_len(0xf0));
  3877. }
  3878. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3879. /// 00f1
  3880. /// NOTE: Unknown purpose. Items are not removed until the window is
  3881. /// refreshed (ex. by putting another item in there).
  3882. void clif_tradeundo(struct map_session_data* sd)
  3883. {
  3884. int fd = sd->fd;
  3885. WFIFOHEAD(fd,packet_len(0xf1));
  3886. WFIFOW(fd,0) = 0xf1;
  3887. WFIFOSET(fd,packet_len(0xf1));
  3888. }
  3889. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3890. /// 00f2 <current count>.W <max count>.W
  3891. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3892. {
  3893. int fd;
  3894. nullpo_retv(sd);
  3895. fd=sd->fd;
  3896. WFIFOHEAD(fd,packet_len(0xf2));
  3897. WFIFOW(fd,0) = 0xf2;
  3898. WFIFOW(fd,2) = amount;
  3899. WFIFOW(fd,4) = max_amount;
  3900. WFIFOSET(fd,packet_len(0xf2));
  3901. }
  3902. /// Notifies the client of an item being added to the storage.
  3903. /// 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)
  3904. /// 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)
  3905. /// 0a0a <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_STORE3)
  3906. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3907. {
  3908. #if PACKETVER < 5
  3909. const int cmd = 0xf4;
  3910. #elif PACKETVER < 20150226
  3911. const int cmd = 0x1c4;
  3912. #else
  3913. const int cmd = 0xa0a;
  3914. #endif
  3915. int view,fd;
  3916. int offset = 0;
  3917. nullpo_retv(sd);
  3918. nullpo_retv(i);
  3919. fd=sd->fd;
  3920. view = itemdb_viewid(i->nameid);
  3921. WFIFOHEAD(fd,packet_len(cmd));
  3922. WFIFOW(fd, 0) = cmd; // Storage item added
  3923. WFIFOW(fd, 2) = index+1; // index
  3924. WFIFOL(fd, 4) = amount; // amount
  3925. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3926. #if PACKETVER >= 5
  3927. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3928. offset += 1;
  3929. #endif
  3930. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3931. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3932. WFIFOB(fd,12+offset) = i->refine; //refine
  3933. clif_addcards(WFIFOP(fd,13+offset), i);
  3934. #if PACKETVER >= 20150226
  3935. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3936. #endif
  3937. WFIFOSET(fd,packet_len(cmd));
  3938. }
  3939. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3940. /// 00f6 <index>.W <amount>.L
  3941. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3942. {
  3943. int fd;
  3944. nullpo_retv(sd);
  3945. fd=sd->fd;
  3946. WFIFOHEAD(fd,packet_len(0xf6));
  3947. WFIFOW(fd,0)=0xf6; // Storage item removed
  3948. WFIFOW(fd,2)=index+1;
  3949. WFIFOL(fd,4)=amount;
  3950. WFIFOSET(fd,packet_len(0xf6));
  3951. }
  3952. /// Closes storage (ZC_CLOSE_STORE).
  3953. /// 00f8
  3954. void clif_storageclose(struct map_session_data* sd)
  3955. {
  3956. int fd;
  3957. nullpo_retv(sd);
  3958. fd=sd->fd;
  3959. WFIFOHEAD(fd,packet_len(0xf8));
  3960. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3961. WFIFOSET(fd,packet_len(0xf8));
  3962. }
  3963. /*==========================================
  3964. * Server tells 'sd' player client the abouts of 'dstsd' player
  3965. *------------------------------------------*/
  3966. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3967. {
  3968. struct block_list *d_bl;
  3969. int i;
  3970. if( dstsd->chatID ) {
  3971. struct chat_data *cd = NULL;
  3972. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3973. clif_dispchat(cd,sd->fd);
  3974. } else if( dstsd->state.vending )
  3975. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3976. else if( dstsd->state.buyingstore )
  3977. clif_buyingstore_entry_single(sd, dstsd);
  3978. if(dstsd->spiritball > 0)
  3979. clif_spiritball_single(sd->fd, dstsd);
  3980. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3981. clif_spiritcharm_single(sd->fd, dstsd);
  3982. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3983. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3984. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3985. else
  3986. 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);
  3987. }
  3988. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3989. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3990. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3991. )
  3992. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3993. // display link (sd - dstsd) to sd
  3994. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3995. if( i < MAX_DEVOTION )
  3996. clif_devotion(&sd->bl, sd);
  3997. // display links (dstsd - devotees) to sd
  3998. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3999. if( i < MAX_DEVOTION )
  4000. clif_devotion(&dstsd->bl, sd);
  4001. // display link (dstsd - crusader) to sd
  4002. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4003. clif_devotion(d_bl, sd);
  4004. }
  4005. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4006. {
  4007. uint8 buf[128];
  4008. struct unit_data *ud;
  4009. struct view_data *vd;
  4010. int len;
  4011. vd = status_get_viewdata(bl);
  4012. if (!vd || vd->class_ == INVISIBLE_CLASS)
  4013. return;
  4014. /**
  4015. * Hide NPC from maya purple card.
  4016. **/
  4017. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4018. return;
  4019. ud = unit_bl2ud(bl);
  4020. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4021. clif_send(buf,len,&sd->bl,SELF);
  4022. if (vd->cloth_color)
  4023. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4024. if (vd->body_style)
  4025. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4026. switch (bl->type)
  4027. {
  4028. case BL_PC:
  4029. {
  4030. TBL_PC* tsd = (TBL_PC*)bl;
  4031. clif_getareachar_pc(sd, tsd);
  4032. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4033. clif_specialeffect_single(bl,423,sd->fd);
  4034. else if(tsd->state.size==SZ_MEDIUM)
  4035. clif_specialeffect_single(bl,421,sd->fd);
  4036. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4037. clif_sendbgemblem_single(sd->fd,tsd);
  4038. if ( tsd->status.robe )
  4039. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4040. if (!&tsd->sc)
  4041. break;
  4042. if( tsd->sc.data[SC_CAMOUFLAGE] )
  4043. clif_status_load(bl,SI_CAMOUFLAGE,1);
  4044. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  4045. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  4046. if( tsd->sc.data[SC_MOONSTAR] )
  4047. clif_status_load(bl,SI_MOONSTAR,1);
  4048. if( tsd->sc.data[SC_SUPER_STAR] )
  4049. clif_status_load(bl,SI_SUPER_STAR,1);
  4050. if( tsd->sc.data[SC_DECORATION_OF_MUSIC] )
  4051. clif_status_load(bl,SI_DECORATION_OF_MUSIC,1);
  4052. if( tsd->sc.data[SC_STRANGELIGHTS] )
  4053. clif_status_load(bl,SI_STRANGELIGHTS,1);
  4054. if( tsd->sc.data[SC_ALL_RIDING] )
  4055. clif_status_load(bl,SI_ALL_RIDING,1);
  4056. }
  4057. break;
  4058. case BL_MER: // Devotion Effects
  4059. if( ((TBL_MER*)bl)->devotion_flag )
  4060. clif_devotion(bl, sd);
  4061. break;
  4062. case BL_NPC:
  4063. {
  4064. TBL_NPC* nd = (TBL_NPC*)bl;
  4065. if( nd->chat_id )
  4066. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4067. if( nd->size == SZ_BIG )
  4068. clif_specialeffect_single(bl,423,sd->fd);
  4069. else if( nd->size == SZ_MEDIUM )
  4070. clif_specialeffect_single(bl,421,sd->fd);
  4071. }
  4072. break;
  4073. case BL_MOB:
  4074. {
  4075. TBL_MOB* md = (TBL_MOB*)bl;
  4076. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4077. clif_specialeffect_single(bl,423,sd->fd);
  4078. else if(md->special_state.size==SZ_MEDIUM)
  4079. clif_specialeffect_single(bl,421,sd->fd);
  4080. #if PACKETVER >= 20120404
  4081. if( battle_config.monster_hp_bars_info){
  4082. int i;
  4083. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4084. if( md->dmglog[i].id == sd->status.char_id )
  4085. clif_monster_hp_bar(md, sd->fd);
  4086. }
  4087. #endif
  4088. }
  4089. break;
  4090. case BL_PET:
  4091. if (vd->head_bottom)
  4092. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4093. break;
  4094. }
  4095. }
  4096. //Modifies the type of damage according to status changes [Skotlex]
  4097. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4098. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  4099. {
  4100. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  4101. }
  4102. /*==========================================
  4103. * Estimates walk delay based on the damage criteria. [Skotlex]
  4104. *------------------------------------------*/
  4105. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4106. {
  4107. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4108. return 0;
  4109. if (bl->type == BL_PC) {
  4110. if (battle_config.pc_walk_delay_rate != 100)
  4111. delay = delay*battle_config.pc_walk_delay_rate/100;
  4112. } else
  4113. if (battle_config.walk_delay_rate != 100)
  4114. delay = delay*battle_config.walk_delay_rate/100;
  4115. if (div_ > 1) //Multi-hit skills mean higher delays.
  4116. delay += battle_config.multihit_delay*(div_-1);
  4117. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4118. }
  4119. /// Sends a 'damage' packet (src performs action on dst)
  4120. /// 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)
  4121. /// 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)
  4122. /// 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)
  4123. /// type:
  4124. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4125. /// 1 = pick up item
  4126. /// 2 = sit down
  4127. /// 3 = stand up
  4128. /// 4 = damage (endure)
  4129. /// 5 = (splash?)
  4130. /// 6 = (skill?)
  4131. /// 7 = (repeat damage?)
  4132. /// 8 = multi-hit damage
  4133. /// 9 = multi-hit damage (endure)
  4134. /// 10 = critical hit
  4135. /// 11 = lucky dodge
  4136. /// 12 = (touch skill?)
  4137. 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)
  4138. {
  4139. unsigned char buf[34];
  4140. struct status_change *sc;
  4141. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4142. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4143. #if PACKETVER < 20071113
  4144. const int cmd = 0x8a;
  4145. int offset = 0;
  4146. #elif PACKETVER < 20131223
  4147. const int cmd = 0x2e1;
  4148. int offset = 2;
  4149. #else
  4150. const int cmd = 0x8c8;
  4151. int offset = 3;
  4152. #endif
  4153. nullpo_ret(src);
  4154. nullpo_ret(dst);
  4155. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4156. sc = status_get_sc(dst);
  4157. if(sc && sc->count) {
  4158. if(sc->data[SC_HALLUCINATION]) {
  4159. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4160. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4161. }
  4162. }
  4163. WBUFW(buf,0) = cmd;
  4164. WBUFL(buf,2) = src->id;
  4165. WBUFL(buf,6) = dst->id;
  4166. WBUFL(buf,10) = tick;
  4167. WBUFL(buf,14) = sdelay;
  4168. WBUFL(buf,18) = ddelay;
  4169. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4170. WBUFW(buf,22) = damage ? div : 0;
  4171. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4172. } else {
  4173. #if PACKETVER < 20071113
  4174. WBUFW(buf,22) = min(damage, INT16_MAX);
  4175. WBUFW(buf,27+offset) = damage2;
  4176. #else
  4177. WBUFL(buf,22) = damage;
  4178. WBUFL(buf,27+offset) = damage2;
  4179. #endif
  4180. }
  4181. #if PACKETVER >= 20131223
  4182. WBUFB(buf,26) = 0; // IsSPDamage - Displays blue digits. Need a way to handle this. [Rytech]
  4183. #endif
  4184. WBUFW(buf,24+offset) = div;
  4185. WBUFB(buf,26+offset) = type;
  4186. if(disguised(dst)) {
  4187. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4188. WBUFL(buf,6) = -dst->id;
  4189. clif_send(buf, packet_len(cmd), dst, SELF);
  4190. } else
  4191. clif_send(buf, packet_len(cmd), dst, AREA);
  4192. if(disguised(src)) {
  4193. WBUFL(buf,2) = -src->id;
  4194. if (disguised(dst))
  4195. WBUFL(buf,6) = dst->id;
  4196. #if PACKETVER < 20071113
  4197. if(damage > 0) WBUFW(buf,22) = -1;
  4198. if(damage2 > 0) WBUFW(buf,27) = -1;
  4199. #else
  4200. if(damage > 0) WBUFL(buf,22) = -1;
  4201. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4202. #endif
  4203. clif_send(buf,packet_len(cmd),src,SELF);
  4204. }
  4205. if(src == dst) {
  4206. unit_setdir(src, unit_getdir(src));
  4207. }
  4208. //Return adjusted can't walk delay for further processing.
  4209. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4210. }
  4211. /*==========================================
  4212. * src picks up dst
  4213. *------------------------------------------*/
  4214. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4215. {
  4216. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  4217. unsigned char buf[32];
  4218. nullpo_retv(src);
  4219. nullpo_retv(dst);
  4220. WBUFW(buf, 0) = 0x8a;
  4221. WBUFL(buf, 2) = src->id;
  4222. WBUFL(buf, 6) = dst->id;
  4223. WBUFB(buf,26) = 1;
  4224. clif_send(buf, packet_len(0x8a), src, AREA);
  4225. }
  4226. /*==========================================
  4227. * inform clients in area that `bl` is sitting
  4228. *------------------------------------------*/
  4229. void clif_sitting(struct block_list* bl)
  4230. {
  4231. unsigned char buf[32];
  4232. nullpo_retv(bl);
  4233. WBUFW(buf, 0) = 0x8a;
  4234. WBUFL(buf, 2) = bl->id;
  4235. WBUFB(buf,26) = 2;
  4236. clif_send(buf, packet_len(0x8a), bl, AREA);
  4237. if(disguised(bl)) {
  4238. WBUFL(buf, 2) = - bl->id;
  4239. clif_send(buf, packet_len(0x8a), bl, SELF);
  4240. }
  4241. }
  4242. /*==========================================
  4243. * inform clients in area that `bl` is standing
  4244. *------------------------------------------*/
  4245. void clif_standing(struct block_list* bl)
  4246. {
  4247. unsigned char buf[32];
  4248. nullpo_retv(bl);
  4249. WBUFW(buf, 0) = 0x8a;
  4250. WBUFL(buf, 2) = bl->id;
  4251. WBUFB(buf,26) = 3;
  4252. clif_send(buf, packet_len(0x8a), bl, AREA);
  4253. if(disguised(bl)) {
  4254. WBUFL(buf, 2) = - bl->id;
  4255. clif_send(buf, packet_len(0x8a), bl, SELF);
  4256. }
  4257. }
  4258. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4259. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4260. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4261. {
  4262. unsigned char buf[32];
  4263. WBUFW(buf,0) = 0x192;
  4264. WBUFW(buf,2) = x;
  4265. WBUFW(buf,4) = y;
  4266. WBUFW(buf,6) = type;
  4267. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  4268. if( fd )
  4269. {
  4270. WFIFOHEAD(fd,packet_len(0x192));
  4271. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4272. WFIFOSET(fd,packet_len(0x192));
  4273. }
  4274. else
  4275. {
  4276. struct block_list dummy_bl;
  4277. dummy_bl.type = BL_NUL;
  4278. dummy_bl.x = x;
  4279. dummy_bl.y = y;
  4280. dummy_bl.m = m;
  4281. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4282. }
  4283. }
  4284. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4285. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4286. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4287. {
  4288. int view,fd;
  4289. fd=sd->fd;
  4290. WFIFOHEAD(fd,packet_len(0x9d));
  4291. WFIFOW(fd,0)=0x9d;
  4292. WFIFOL(fd,2)=fitem->bl.id;
  4293. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4294. WFIFOW(fd,6)=view;
  4295. else
  4296. WFIFOW(fd,6)=fitem->item.nameid;
  4297. WFIFOB(fd,8)=fitem->item.identify;
  4298. WFIFOW(fd,9)=fitem->bl.x;
  4299. WFIFOW(fd,11)=fitem->bl.y;
  4300. WFIFOW(fd,13)=fitem->item.amount;
  4301. WFIFOB(fd,15)=fitem->subx;
  4302. WFIFOB(fd,16)=fitem->suby;
  4303. WFIFOSET(fd,packet_len(0x9d));
  4304. }
  4305. /// Notifes client about Graffiti
  4306. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4307. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4308. unsigned char buf[128];
  4309. nullpo_retv(bl);
  4310. nullpo_retv(unit);
  4311. WBUFW(buf, 0) = 0x1c9;
  4312. WBUFL(buf, 2) = unit->bl.id;
  4313. WBUFL(buf, 6) = unit->group->src_id;
  4314. WBUFW(buf,10) = unit->bl.x;
  4315. WBUFW(buf,12) = unit->bl.y;
  4316. WBUFB(buf,14) = unit->group->unit_id;
  4317. WBUFB(buf,15) = 1;
  4318. WBUFB(buf,16) = 1;
  4319. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4320. clif_send(buf,packet_len(0x1c9),bl,target);
  4321. }
  4322. /// Notifies the client of a skill unit.
  4323. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4324. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4325. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4326. /// 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)
  4327. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, uint8 flag) {
  4328. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4329. unsigned char buf[128];
  4330. nullpo_retv(bl);
  4331. nullpo_retv(unit);
  4332. if (bl->type == BL_PC)
  4333. fd = ((TBL_PC*)bl)->fd;
  4334. if (unit->group->state.guildaura)
  4335. return;
  4336. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4337. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4338. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4339. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4340. else
  4341. unit_id = unit->group->unit_id;
  4342. if (flag && battle_config.traps_setting&1) {
  4343. switch(unit->group->skill_id) {
  4344. case HT_ANKLESNARE:
  4345. if (!map_flag_vs(((TBL_PC*)bl)->bl.m))
  4346. break;
  4347. case HT_SKIDTRAP:
  4348. case MA_SKIDTRAP:
  4349. case HT_SHOCKWAVE:
  4350. case HT_SANDMAN:
  4351. case MA_SANDMAN:
  4352. case HT_FLASHER:
  4353. case HT_FREEZINGTRAP:
  4354. case MA_FREEZINGTRAP:
  4355. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for Hunter's traps
  4356. break;
  4357. }
  4358. }
  4359. #if PACKETVER >= 3
  4360. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4361. clif_graffiti(bl, unit, target);
  4362. return;
  4363. }
  4364. #endif
  4365. #if PACKETVER <= 20120702
  4366. header = 0x011f;
  4367. //#if PACKETVER < 20110718
  4368. // header = 0x011f;
  4369. //#elif PACKETVER < 20121212
  4370. // header = 0x08c7;
  4371. #elif PACKETVER < 20130731
  4372. header = 0x099f;
  4373. #else
  4374. header = 0x09ca;
  4375. #endif
  4376. len = packet_len(header);
  4377. WBUFW(buf,pos) = header;
  4378. if (header != 0x011f) {
  4379. WBUFW(buf, pos+2) = len;
  4380. pos += 2;
  4381. }
  4382. WBUFL(buf,pos+2) = unit->bl.id;
  4383. WBUFL(buf,pos+6) = unit->group->src_id;
  4384. WBUFW(buf,pos+10) = unit->bl.x;
  4385. WBUFW(buf,pos+12) = unit->bl.y;
  4386. switch (header) {
  4387. case 0x011f:
  4388. WBUFB(buf,pos+14) = unit_id;
  4389. WBUFB(buf,pos+15) = 1;
  4390. break;
  4391. case 0x08c7:
  4392. WBUFB(buf,pos+14) = unit_id;
  4393. WBUFW(buf,pos+15) = unit->range;
  4394. WBUFB(buf,pos+17) = 1;
  4395. break;
  4396. case 0x099f:
  4397. WBUFL(buf,pos+14) = unit_id;
  4398. WBUFW(buf,pos+18) = unit->range;
  4399. WBUFB(buf,pos+20) = 1;
  4400. break;
  4401. case 0x09ca:
  4402. WBUFL(buf,pos+14) = unit_id;
  4403. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4404. WBUFB(buf,pos+19) = 1;
  4405. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4406. break;
  4407. }
  4408. clif_send(buf, len, bl, target);
  4409. if (unit->group->skill_id == WZ_ICEWALL)
  4410. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4411. }
  4412. /*==========================================
  4413. * Server tells client to remove unit of id 'unit->bl.id'
  4414. *------------------------------------------*/
  4415. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4416. {
  4417. nullpo_retv(unit);
  4418. WFIFOHEAD(fd,packet_len(0x120));
  4419. WFIFOW(fd, 0)=0x120;
  4420. WFIFOL(fd, 2)=unit->bl.id;
  4421. WFIFOSET(fd,packet_len(0x120));
  4422. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4423. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4424. }
  4425. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4426. /// 0120 <id>.L
  4427. void clif_skill_delunit(struct skill_unit *unit)
  4428. {
  4429. unsigned char buf[16];
  4430. nullpo_retv(unit);
  4431. WBUFW(buf, 0)=0x120;
  4432. WBUFL(buf, 2)=unit->bl.id;
  4433. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4434. }
  4435. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4436. /// 01ac <id>.L
  4437. /// Only affects units with class [139,153] client-side.
  4438. void clif_skillunit_update(struct block_list* bl)
  4439. {
  4440. unsigned char buf[6];
  4441. nullpo_retv(bl);
  4442. WBUFW(buf,0) = 0x1ac;
  4443. WBUFL(buf,2) = bl->id;
  4444. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4445. }
  4446. /*==========================================
  4447. *
  4448. *------------------------------------------*/
  4449. static int clif_getareachar(struct block_list* bl,va_list ap)
  4450. {
  4451. struct map_session_data *sd;
  4452. nullpo_ret(bl);
  4453. sd=va_arg(ap,struct map_session_data*);
  4454. if (sd == NULL || !sd->fd)
  4455. return 0;
  4456. switch(bl->type){
  4457. case BL_ITEM:
  4458. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4459. break;
  4460. case BL_SKILL:
  4461. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF, 1);
  4462. break;
  4463. default:
  4464. if(&sd->bl == bl)
  4465. break;
  4466. clif_getareachar_unit(sd,bl);
  4467. break;
  4468. }
  4469. return 0;
  4470. }
  4471. /*==========================================
  4472. * tbl has gone out of view-size of bl
  4473. *------------------------------------------*/
  4474. int clif_outsight(struct block_list *bl,va_list ap)
  4475. {
  4476. struct block_list *tbl;
  4477. struct view_data *vd;
  4478. TBL_PC *sd, *tsd;
  4479. tbl=va_arg(ap,struct block_list*);
  4480. if(bl == tbl) return 0;
  4481. sd = BL_CAST(BL_PC, bl);
  4482. tsd = BL_CAST(BL_PC, tbl);
  4483. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4484. nullpo_ret(bl);
  4485. switch(bl->type){
  4486. case BL_PC:
  4487. if(sd->vd.class_ != INVISIBLE_CLASS)
  4488. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4489. if(sd->chatID){
  4490. struct chat_data *cd;
  4491. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4492. if(cd->usersd[0]==sd)
  4493. clif_dispchat(cd,tsd->fd);
  4494. }
  4495. if(sd->state.vending)
  4496. clif_closevendingboard(bl,tsd->fd);
  4497. if(sd->state.buyingstore)
  4498. clif_buyingstore_disappear_entry_single(tsd, sd);
  4499. break;
  4500. case BL_ITEM:
  4501. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4502. break;
  4503. case BL_SKILL:
  4504. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4505. break;
  4506. case BL_NPC:
  4507. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4508. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4509. break;
  4510. default:
  4511. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4512. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4513. break;
  4514. }
  4515. }
  4516. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4517. nullpo_ret(tbl);
  4518. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4519. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4520. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4521. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4522. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4523. }
  4524. return 0;
  4525. }
  4526. /*==========================================
  4527. * tbl has come into view of bl
  4528. *------------------------------------------*/
  4529. int clif_insight(struct block_list *bl,va_list ap)
  4530. {
  4531. struct block_list *tbl;
  4532. TBL_PC *sd, *tsd;
  4533. tbl=va_arg(ap,struct block_list*);
  4534. if (bl == tbl) return 0;
  4535. sd = BL_CAST(BL_PC, bl);
  4536. tsd = BL_CAST(BL_PC, tbl);
  4537. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4538. switch(bl->type){
  4539. case BL_ITEM:
  4540. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4541. break;
  4542. case BL_SKILL:
  4543. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF, 1);
  4544. break;
  4545. default:
  4546. clif_getareachar_unit(tsd,bl);
  4547. break;
  4548. }
  4549. }
  4550. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4551. clif_getareachar_unit(sd,tbl);
  4552. }
  4553. return 0;
  4554. }
  4555. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4556. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4557. void clif_skillinfoblock(struct map_session_data *sd)
  4558. {
  4559. int fd;
  4560. int i,len,id;
  4561. nullpo_retv(sd);
  4562. fd = sd->fd;
  4563. if (!fd)
  4564. return;
  4565. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4566. WFIFOW(fd,0) = 0x10f;
  4567. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4568. {
  4569. if( (id = sd->status.skill[i].id) != 0 )
  4570. {
  4571. // workaround for bugreport:5348
  4572. if (len + 37 > 8192)
  4573. break;
  4574. WFIFOW(fd,len) = id;
  4575. WFIFOL(fd,len+2) = skill_get_inf(id);
  4576. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4577. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4578. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4579. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4580. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4581. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4582. else
  4583. WFIFOB(fd,len+36) = 0;
  4584. len += 37;
  4585. }
  4586. }
  4587. WFIFOW(fd,2)=len;
  4588. WFIFOSET(fd,len);
  4589. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4590. for ( ; i < MAX_SKILL; i++)
  4591. {
  4592. if( (id = sd->status.skill[i].id) != 0 )
  4593. {
  4594. clif_addskill(sd, id);
  4595. clif_skillinfo(sd, id, 0);
  4596. }
  4597. }
  4598. }
  4599. /**
  4600. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4601. **/
  4602. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4603. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4604. void clif_addskill(struct map_session_data *sd, int skill_id)
  4605. {
  4606. int fd;
  4607. uint16 idx = 0;
  4608. nullpo_retv(sd);
  4609. fd = sd->fd;
  4610. if (!fd || !(idx = skill_get_index(skill_id)))
  4611. return;
  4612. if( sd->status.skill[idx].id <= 0 )
  4613. return;
  4614. WFIFOHEAD(fd, packet_len(0x111));
  4615. WFIFOW(fd,0) = 0x111;
  4616. WFIFOW(fd,2) = skill_id;
  4617. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4618. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4619. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4620. WFIFOW(fd,12)= skill_get_range2(&sd->bl, skill_id,sd->status.skill[idx].lv);
  4621. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4622. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4623. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4624. else
  4625. WFIFOB(fd,38) = 0;
  4626. WFIFOSET(fd,packet_len(0x111));
  4627. }
  4628. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4629. /// 0441 <skill id>.W
  4630. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4631. {
  4632. #if PACKETVER >= 20081217
  4633. int fd;
  4634. uint16 idx = 0;
  4635. nullpo_retv(sd);
  4636. fd = sd->fd;
  4637. if (!fd || !(idx = skill_get_index(skill_id)))
  4638. return;
  4639. WFIFOHEAD(fd,packet_len(0x441));
  4640. WFIFOW(fd,0) = 0x441;
  4641. WFIFOW(fd,2) = skill_id;
  4642. WFIFOSET(fd,packet_len(0x441));
  4643. #endif
  4644. clif_skillinfoblock(sd);
  4645. }
  4646. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4647. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4648. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4649. int fd;
  4650. nullpo_retv(sd);
  4651. fd = sd->fd;
  4652. WFIFOHEAD(fd, packet_len(0x10e));
  4653. WFIFOW(fd, 0) = 0x10e;
  4654. WFIFOW(fd, 2) = skill_id;
  4655. WFIFOW(fd, 4) = lv;
  4656. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4657. WFIFOW(fd, 8) = range;
  4658. WFIFOB(fd, 10) = upgradable;
  4659. WFIFOSET(fd, packet_len(0x10e));
  4660. }
  4661. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4662. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4663. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4664. {
  4665. const int fd = sd->fd;
  4666. uint16 idx = skill_get_index(skill_id);
  4667. if (!idx)
  4668. return;
  4669. WFIFOHEAD(fd,packet_len(0x7e1));
  4670. WFIFOW(fd,0) = 0x7e1;
  4671. WFIFOW(fd,2) = skill_id;
  4672. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4673. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4674. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4675. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv);
  4676. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4677. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4678. else
  4679. WFIFOB(fd,14) = 0;
  4680. WFIFOSET(fd,packet_len(0x7e1));
  4681. }
  4682. /// Notifies clients in area, that an object is about to use a skill.
  4683. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4684. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4685. /// property:
  4686. /// 0 = Yellow cast aura
  4687. /// 1 = Water elemental cast aura
  4688. /// 2 = Earth elemental cast aura
  4689. /// 3 = Fire elemental cast aura
  4690. /// 4 = Wind elemental cast aura
  4691. /// 5 = Poison elemental cast aura
  4692. /// 6 = Holy elemental cast aura
  4693. /// ? = like 0
  4694. /// is disposable:
  4695. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4696. /// 1 = no text
  4697. 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)
  4698. {
  4699. #if PACKETVER < 20091124
  4700. const int cmd = 0x13e;
  4701. #else
  4702. const int cmd = 0x7fb;
  4703. #endif
  4704. unsigned char buf[32];
  4705. WBUFW(buf,0) = cmd;
  4706. WBUFL(buf,2) = src_id;
  4707. WBUFL(buf,6) = dst_id;
  4708. WBUFW(buf,10) = dst_x;
  4709. WBUFW(buf,12) = dst_y;
  4710. WBUFW(buf,14) = skill_id;
  4711. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4712. WBUFL(buf,20) = casttime;
  4713. #if PACKETVER >= 20091124
  4714. WBUFB(buf,24) = 0; // isDisposable
  4715. #endif
  4716. if (disguised(bl)) {
  4717. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4718. WBUFL(buf,2) = -src_id;
  4719. clif_send(buf,packet_len(cmd), bl, SELF);
  4720. } else
  4721. clif_send(buf,packet_len(cmd), bl, AREA);
  4722. }
  4723. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4724. /// 01b9 <id>.L
  4725. void clif_skillcastcancel(struct block_list* bl)
  4726. {
  4727. unsigned char buf[16];
  4728. nullpo_retv(bl);
  4729. WBUFW(buf,0) = 0x1b9;
  4730. WBUFL(buf,2) = bl->id;
  4731. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4732. }
  4733. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4734. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4735. /// num (only used when skill id = NV_BASIC and cause = 0):
  4736. /// 0 = "skill failed" MsgStringTable[159]
  4737. /// 1 = "no emotions" MsgStringTable[160]
  4738. /// 2 = "no sit" MsgStringTable[161]
  4739. /// 3 = "no chat" MsgStringTable[162]
  4740. /// 4 = "no party" MsgStringTable[163]
  4741. /// 5 = "no shout" MsgStringTable[164]
  4742. /// 6 = "no PKing" MsgStringTable[165]
  4743. /// 7 = "no alligning" MsgStringTable[383]
  4744. /// ? = ignored
  4745. /// cause:
  4746. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4747. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4748. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4749. /// "skill failed" MsgStringTable[204] (otherwise)
  4750. /// ... = @see enum useskill_fail_cause
  4751. /// ? = ignored
  4752. ///
  4753. /// if(result!=0) doesn't display any of the previous messages
  4754. /// Note: when this packet is received an unknown flag is always set to 0,
  4755. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4756. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4757. {
  4758. int fd;
  4759. if (!sd) { //Since this is the most common nullpo....
  4760. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4761. return;
  4762. }
  4763. fd=sd->fd;
  4764. if (!fd) return;
  4765. if(battle_config.display_skill_fail&1)
  4766. return; //Disable all skill failed messages
  4767. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4768. return; //Disable delay failed messages
  4769. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4770. return;
  4771. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4772. return;
  4773. WFIFOHEAD(fd,packet_len(0x110));
  4774. WFIFOW(fd,0) = 0x110;
  4775. WFIFOW(fd,2) = skill_id;
  4776. WFIFOL(fd,4) = btype;
  4777. WFIFOB(fd,8) = 0;// success
  4778. WFIFOB(fd,9) = cause;
  4779. WFIFOSET(fd,packet_len(0x110));
  4780. }
  4781. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4782. /// 043d <skill ID>.W <tick>.L
  4783. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4784. {
  4785. #if PACKETVER>=20081112
  4786. int fd;
  4787. nullpo_retv(sd);
  4788. fd=sd->fd;
  4789. WFIFOHEAD(fd,packet_len(0x43d));
  4790. WFIFOW(fd,0) = 0x43d;
  4791. WFIFOW(fd,2) = skill_id;
  4792. WFIFOL(fd,4) = tick;
  4793. WFIFOSET(fd,packet_len(0x43d));
  4794. #endif
  4795. }
  4796. /// Skill attack effect and damage.
  4797. /// 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)
  4798. /// 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)
  4799. 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)
  4800. {
  4801. unsigned char buf[64];
  4802. struct status_change *sc;
  4803. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4804. nullpo_ret(src);
  4805. nullpo_ret(dst);
  4806. type = clif_calc_delay(type,div,damage,ddelay);
  4807. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4808. if(sc->data[SC_HALLUCINATION] && damage)
  4809. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4810. }
  4811. #if PACKETVER < 3
  4812. WBUFW(buf,0)=0x114;
  4813. WBUFW(buf,2)=skill_id;
  4814. WBUFL(buf,4)=src->id;
  4815. WBUFL(buf,8)=dst->id;
  4816. WBUFL(buf,12)=tick;
  4817. WBUFL(buf,16)=sdelay;
  4818. WBUFL(buf,20)=ddelay;
  4819. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4820. WBUFW(buf,24)=damage?div:0;
  4821. } else {
  4822. WBUFW(buf,24)=damage;
  4823. }
  4824. WBUFW(buf,26)=skill_lv;
  4825. WBUFW(buf,28)=div;
  4826. WBUFB(buf,30)=type;
  4827. if (disguised(dst)) {
  4828. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4829. WBUFL(buf,8)=-dst->id;
  4830. clif_send(buf,packet_len(0x114),dst,SELF);
  4831. } else
  4832. clif_send(buf,packet_len(0x114),dst,AREA);
  4833. if(disguised(src)) {
  4834. WBUFL(buf,4)=-src->id;
  4835. if (disguised(dst))
  4836. WBUFL(buf,8)=dst->id;
  4837. if(damage > 0)
  4838. WBUFW(buf,24)=-1;
  4839. clif_send(buf,packet_len(0x114),src,SELF);
  4840. }
  4841. #else
  4842. WBUFW(buf,0)=0x1de;
  4843. WBUFW(buf,2)=skill_id;
  4844. WBUFL(buf,4)=src->id;
  4845. WBUFL(buf,8)=dst->id;
  4846. WBUFL(buf,12)=tick;
  4847. WBUFL(buf,16)=sdelay;
  4848. WBUFL(buf,20)=ddelay;
  4849. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4850. WBUFL(buf,24)=damage?div:0;
  4851. } else {
  4852. WBUFL(buf,24)=damage;
  4853. }
  4854. WBUFW(buf,28)=skill_lv;
  4855. WBUFW(buf,30)=div;
  4856. // For some reason, late 2013 and newer clients have
  4857. // a issue that causes players and monsters to endure
  4858. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4859. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4860. #if PACKETVER < 20131223
  4861. WBUFB(buf,32)=type;
  4862. #else
  4863. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4864. #endif
  4865. if (disguised(dst)) {
  4866. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4867. WBUFL(buf,8)=-dst->id;
  4868. clif_send(buf,packet_len(0x1de),dst,SELF);
  4869. } else
  4870. clif_send(buf,packet_len(0x1de),dst,AREA);
  4871. if(disguised(src)) {
  4872. WBUFL(buf,4)=-src->id;
  4873. if (disguised(dst))
  4874. WBUFL(buf,8)=dst->id;
  4875. if(damage > 0)
  4876. WBUFL(buf,24)=-1;
  4877. clif_send(buf,packet_len(0x1de),src,SELF);
  4878. }
  4879. #endif
  4880. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4881. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4882. }
  4883. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4884. /// 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
  4885. /*
  4886. 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)
  4887. {
  4888. unsigned char buf[64];
  4889. struct status_change *sc;
  4890. nullpo_ret(src);
  4891. nullpo_ret(dst);
  4892. type = (type>0)?type:skill_get_hit(skill_id);
  4893. type = clif_calc_delay(type,div,damage,ddelay);
  4894. sc = status_get_sc(dst);
  4895. if(sc && sc->count) {
  4896. if(sc->data[SC_HALLUCINATION] && damage)
  4897. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4898. }
  4899. WBUFW(buf,0)=0x115;
  4900. WBUFW(buf,2)=skill_id;
  4901. WBUFL(buf,4)=src->id;
  4902. WBUFL(buf,8)=dst->id;
  4903. WBUFL(buf,12)=tick;
  4904. WBUFL(buf,16)=sdelay;
  4905. WBUFL(buf,20)=ddelay;
  4906. WBUFW(buf,24)=dst->x;
  4907. WBUFW(buf,26)=dst->y;
  4908. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4909. WBUFW(buf,28)=damage?div:0;
  4910. } else {
  4911. WBUFW(buf,28)=damage;
  4912. }
  4913. WBUFW(buf,30)=skill_lv;
  4914. WBUFW(buf,32)=div;
  4915. WBUFB(buf,34)=type;
  4916. clif_send(buf,packet_len(0x115),src,AREA);
  4917. if(disguised(src)) {
  4918. WBUFL(buf,4)=-src->id;
  4919. if(damage > 0)
  4920. WBUFW(buf,28)=-1;
  4921. clif_send(buf,packet_len(0x115),src,SELF);
  4922. }
  4923. if (disguised(dst)) {
  4924. WBUFL(buf,8)=-dst->id;
  4925. if (disguised(src))
  4926. WBUFL(buf,4)=src->id;
  4927. else if(damage > 0)
  4928. WBUFW(buf,28)=-1;
  4929. clif_send(buf,packet_len(0x115),dst,SELF);
  4930. }
  4931. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4932. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4933. }
  4934. */
  4935. /// Non-damaging skill effect
  4936. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4937. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4938. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4939. {
  4940. unsigned char buf[17];
  4941. #if PACKETVER < 20130731
  4942. const int cmd = 0x11a;
  4943. #else
  4944. const int cmd = 0x9cb;
  4945. #endif
  4946. int offset = 0;
  4947. nullpo_ret(dst);
  4948. WBUFW(buf,0) = cmd;
  4949. WBUFW(buf,2) = skill_id;
  4950. #if PACKETVER < 20130731
  4951. WBUFW(buf,4) = min(heal, INT16_MAX);
  4952. #else
  4953. WBUFL(buf,4) = min(heal, INT32_MAX);
  4954. offset += 2;
  4955. #endif
  4956. WBUFL(buf,6+offset) = dst->id;
  4957. WBUFL(buf,10+offset) = src ? src->id : 0;
  4958. WBUFB(buf,14+offset) = fail;
  4959. if (disguised(dst)) {
  4960. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4961. WBUFL(buf,6+offset) = -dst->id;
  4962. clif_send(buf, packet_len(cmd), dst, SELF);
  4963. } else
  4964. clif_send(buf, packet_len(cmd), dst, AREA);
  4965. if(src && disguised(src)) {
  4966. WBUFL(buf,10+offset) = -src->id;
  4967. if (disguised(dst))
  4968. WBUFL(buf,6+offset) = dst->id;
  4969. clif_send(buf, packet_len(cmd), src, SELF);
  4970. }
  4971. return fail;
  4972. }
  4973. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4974. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4975. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4976. {
  4977. unsigned char buf[32];
  4978. nullpo_retv(src);
  4979. WBUFW(buf,0)=0x117;
  4980. WBUFW(buf,2)=skill_id;
  4981. WBUFL(buf,4)=src->id;
  4982. WBUFW(buf,8)=val;
  4983. WBUFW(buf,10)=x;
  4984. WBUFW(buf,12)=y;
  4985. WBUFL(buf,14)=tick;
  4986. if(disguised(src)) {
  4987. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4988. WBUFL(buf,4)=-src->id;
  4989. clif_send(buf,packet_len(0x117),src,SELF);
  4990. } else
  4991. clif_send(buf,packet_len(0x117),src,AREA);
  4992. }
  4993. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4994. /// 011c <skill id>.W { <map name>.16B }*4
  4995. 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)
  4996. {
  4997. int fd;
  4998. nullpo_retv(sd);
  4999. fd = sd->fd;
  5000. WFIFOHEAD(fd,packet_len(0x11c));
  5001. WFIFOW(fd,0) = 0x11c;
  5002. WFIFOW(fd,2) = skill_id;
  5003. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5004. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  5005. else // normal map name
  5006. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  5007. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  5008. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  5009. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  5010. WFIFOSET(fd,packet_len(0x11c));
  5011. sd->menuskill_id = skill_id;
  5012. if (skill_id == AL_WARP)
  5013. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5014. else
  5015. sd->menuskill_val = skill_lv;
  5016. }
  5017. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5018. /// 011e <type>.B
  5019. /// type:
  5020. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5021. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5022. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5023. ///
  5024. /// @param sd Who receives the message
  5025. /// @param type What message
  5026. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5027. {
  5028. int fd;
  5029. nullpo_retv(sd);
  5030. fd=sd->fd;
  5031. WFIFOHEAD(fd,packet_len(0x11e));
  5032. WFIFOW(fd,0)=0x11e;
  5033. WFIFOB(fd,2)=type;
  5034. WFIFOSET(fd,packet_len(0x11e));
  5035. }
  5036. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5037. /// 0189 <type>.W
  5038. /// type:
  5039. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5040. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5041. ///
  5042. /// @param sd Who receives the message
  5043. /// @param type What message
  5044. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5045. {
  5046. int fd;
  5047. nullpo_retv(sd);
  5048. fd=sd->fd;
  5049. WFIFOHEAD(fd,packet_len(0x189));
  5050. WFIFOW(fd,0)=0x189;
  5051. WFIFOW(fd,2)=type;
  5052. WFIFOSET(fd,packet_len(0x189));
  5053. }
  5054. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5055. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5056. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5057. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5058. {
  5059. struct status_data *status;
  5060. unsigned char buf[64];
  5061. int i;//, fix;
  5062. nullpo_retv(sd);
  5063. nullpo_retv(dst);
  5064. if( dst->type != BL_MOB )
  5065. return;
  5066. status = status_get_status_data(dst);
  5067. WBUFW(buf, 0)=0x18c;
  5068. WBUFW(buf, 2)=status_get_class(dst);
  5069. WBUFW(buf, 4)=status_get_lv(dst);
  5070. WBUFW(buf, 6)=status->size;
  5071. WBUFL(buf, 8)=status->hp;
  5072. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5073. +(battle_config.estimation_type&2?status->def2:0);
  5074. WBUFW(buf,14)=status->race;
  5075. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5076. +(battle_config.estimation_type&2?status->mdef2:0);
  5077. WBUFW(buf,18)= status->def_ele;
  5078. for(i=0;i<9;i++)
  5079. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5080. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5081. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5082. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5083. }
  5084. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5085. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5086. /// material id:
  5087. /// unused by the client
  5088. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5089. {
  5090. int i,c,view,fd;
  5091. nullpo_retv(sd);
  5092. if (sd->menuskill_id == skill_id)
  5093. return; //Avoid resending the menu twice or more times...
  5094. if (skill_id == GC_CREATENEWPOISON)
  5095. skill_id = GC_RESEARCHNEWPOISON;
  5096. fd = sd->fd;
  5097. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5098. WFIFOW(fd, 0) = 0x18d;
  5099. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5100. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5101. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5102. )
  5103. {
  5104. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5105. WFIFOW(fd,c*8+ 4) = view;
  5106. else
  5107. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5108. WFIFOW(fd,c*8+ 6) = 0;
  5109. WFIFOW(fd,c*8+ 8) = 0;
  5110. WFIFOW(fd,c*8+10) = 0;
  5111. c++;
  5112. }
  5113. }
  5114. WFIFOW(fd, 2) = c*8+8;
  5115. WFIFOSET(fd,WFIFOW(fd,2));
  5116. if (c > 0) {
  5117. sd->menuskill_id = skill_id;
  5118. sd->menuskill_val = trigger;
  5119. return;
  5120. }
  5121. }
  5122. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5123. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5124. /// mk type:
  5125. /// 1 = cooking
  5126. /// 2 = arrow
  5127. /// 3 = elemental
  5128. /// 4 = GN_MIX_COOKING
  5129. /// 5 = GN_MAKEBOMB
  5130. /// 6 = GN_S_PHARMACY
  5131. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5132. {
  5133. int fd;
  5134. int i, c;
  5135. int view;
  5136. nullpo_retv(sd);
  5137. fd = sd->fd;
  5138. if(sd->menuskill_id == skill_id)
  5139. return; //Avoid resending the menu twice or more times...
  5140. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5141. WFIFOW(fd,0) = 0x25a;
  5142. WFIFOW(fd,4) = list_type; // list type
  5143. c = 0;
  5144. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5145. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5146. continue;
  5147. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5148. WFIFOW(fd, 6 + 2 * c) = view;
  5149. else
  5150. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5151. c++;
  5152. }
  5153. if( c > 0 || skill_id == AM_PHARMACY) {
  5154. sd->menuskill_id = skill_id;
  5155. sd->menuskill_val = trigger;
  5156. sd->menuskill_val2 = qty; // amount.
  5157. WFIFOW(fd,2) = 6 + 2 * c;
  5158. WFIFOSET(fd,WFIFOW(fd,2));
  5159. } else {
  5160. clif_menuskill_clear(sd);
  5161. #if PACKETVER >= 20090922
  5162. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5163. #else
  5164. WFIFOW(fd,2) = 6 + 2 * c;
  5165. WFIFOSET(fd,WFIFOW(fd,2));
  5166. #endif
  5167. }
  5168. }
  5169. /// Notifies clients of a status change.
  5170. /// 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)]
  5171. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5172. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5173. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  5174. {
  5175. unsigned char buf[32];
  5176. struct map_session_data *sd;
  5177. if (type == SI_BLANK) //It shows nothing on the client...
  5178. return;
  5179. nullpo_retv(bl);
  5180. sd = BL_CAST(BL_PC, bl);
  5181. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5182. return;
  5183. #if PACKETVER >= 20120618
  5184. if(flag && battle_config.display_status_timers && sd)
  5185. WBUFW(buf,0)=0x983;
  5186. else
  5187. #elif PACKETVER >= 20090121
  5188. if(flag && battle_config.display_status_timers && sd)
  5189. WBUFW(buf,0)=0x43f;
  5190. else
  5191. #endif
  5192. WBUFW(buf,0)=0x196;
  5193. WBUFW(buf,2)=type;
  5194. WBUFL(buf,4)=bl->id;
  5195. WBUFB(buf,8)=flag;
  5196. #if PACKETVER >= 20120618
  5197. if(flag && battle_config.display_status_timers && sd) {
  5198. if (tick <= 0)
  5199. tick = 9999; // this is indeed what official servers do
  5200. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  5201. WBUFL(buf,13)=tick;
  5202. WBUFL(buf,17) = val1;
  5203. WBUFL(buf,21) = val2;
  5204. WBUFL(buf,25) = val3;
  5205. }
  5206. #elif PACKETVER >= 20090121
  5207. if(flag && battle_config.display_status_timers && sd) {
  5208. if (tick <= 0)
  5209. tick = 9999; // this is indeed what official servers do
  5210. WBUFL(buf,9) = tick;
  5211. WBUFL(buf,13) = val1;
  5212. WBUFL(buf,17) = val2;
  5213. WBUFL(buf,21) = val3;
  5214. }
  5215. #endif
  5216. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  5217. }
  5218. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  5219. unsigned char buf[32];
  5220. if (type == SI_BLANK) //It shows nothing on the client
  5221. return;
  5222. nullpo_retv(bl);
  5223. WBUFW(buf,0) = 0x43f;
  5224. WBUFW(buf,2) = type;
  5225. WBUFL(buf,4) = tid;
  5226. WBUFB(buf,8) = 1;
  5227. WBUFL(buf,9) = 9999;
  5228. WBUFL(buf,13) = val1;
  5229. WBUFL(buf,17) = val2;
  5230. WBUFL(buf,21) = val3;
  5231. clif_send(buf,packet_len(0x43f),bl,target);
  5232. }
  5233. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5234. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5235. //! TODO
  5236. //void clif_efst_enter();
  5237. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5238. /// 008e <packet len>.W <message>.?B
  5239. void clif_displaymessage(const int fd, const char* mes)
  5240. {
  5241. nullpo_retv(mes);
  5242. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5243. if (fd == 0)
  5244. ;
  5245. else {
  5246. char *message, *line;
  5247. message = aStrdup(mes);
  5248. line = strtok(message, "\n");
  5249. #if PACKETVER == 20141022
  5250. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5251. /** so we redirect to ZC_NPC_CHAT **/
  5252. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5253. while(line != NULL) {
  5254. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5255. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5256. if (len > 0) {
  5257. WFIFOHEAD(fd, 13 + len);
  5258. WFIFOW(fd, 0) = 0x2C1;
  5259. WFIFOW(fd, 2) = 13 + len;
  5260. WFIFOL(fd, 4) = 0;
  5261. WFIFOL(fd, 8) = color;
  5262. safestrncpy((char*)WFIFOP(fd, 12), line, len + 1);
  5263. WFIFOSET(fd, WFIFOW(fd, 2));
  5264. }
  5265. #else
  5266. while(line != NULL) {
  5267. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5268. int len = strnlen(line, CHAT_SIZE_MAX);
  5269. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5270. WFIFOHEAD(fd, 5 + len);
  5271. WFIFOW(fd,0) = 0x8e;
  5272. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5273. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5274. WFIFOSET(fd, 5 + len);
  5275. }
  5276. #endif
  5277. line = strtok(NULL, "\n");
  5278. }
  5279. aFree(message);
  5280. }
  5281. }
  5282. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5283. /// 009a <packet len>.W <message>.?B
  5284. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5285. {
  5286. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5287. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5288. WBUFW(buf,0) = 0x9a;
  5289. WBUFW(buf,2) = 4 + lp + len;
  5290. if (type&BC_BLUE)
  5291. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5292. else if (type&BC_WOE)
  5293. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5294. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5295. clif_send(buf, WBUFW(buf,2), bl, target);
  5296. if (buf)
  5297. aFree(buf);
  5298. }
  5299. /*==========================================
  5300. * Displays a message on a 'bl' to all it's nearby clients
  5301. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5302. *------------------------------------------*/
  5303. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5304. char buf[100];
  5305. int len;
  5306. nullpo_retv(bl);
  5307. if(!message)
  5308. return;
  5309. len = strlen(message)+1;
  5310. if( len > sizeof(buf)-8 ) {
  5311. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5312. len = sizeof(buf)-8;
  5313. }
  5314. WBUFW(buf,0)=0x8d;
  5315. WBUFW(buf,2)=len+8;
  5316. WBUFL(buf,4)=bl->id;
  5317. safestrncpy((char *) WBUFP(buf,8),message,len);
  5318. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5319. }
  5320. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5321. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5322. 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)
  5323. {
  5324. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5325. WBUFW(buf,0) = 0x1c3;
  5326. WBUFW(buf,2) = len + 16;
  5327. WBUFL(buf,4) = fontColor;
  5328. WBUFW(buf,8) = fontType;
  5329. WBUFW(buf,10) = fontSize;
  5330. WBUFW(buf,12) = fontAlign;
  5331. WBUFW(buf,14) = fontY;
  5332. memcpy(WBUFP(buf,16), mes, len);
  5333. clif_send(buf, WBUFW(buf,2), bl, target);
  5334. if (buf)
  5335. aFree(buf);
  5336. }
  5337. /*
  5338. * Display *msg from *sd to all *users in channel
  5339. */
  5340. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5341. DBIterator *iter;
  5342. struct map_session_data *user;
  5343. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  5344. WFIFOHEAD(sd->fd,msg_len + 12);
  5345. WFIFOW(sd->fd,0) = 0x2C1;
  5346. WFIFOW(sd->fd,2) = msg_len + 12;
  5347. WFIFOL(sd->fd,4) = 0;
  5348. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5349. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5350. iter = db_iterator(channel->users);
  5351. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5352. if( user->fd == sd->fd )
  5353. continue;
  5354. WFIFOHEAD(user->fd,msg_len + 12);
  5355. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5356. WFIFOSET(user->fd, msg_len + 12);
  5357. }
  5358. dbi_destroy(iter);
  5359. WFIFOSET(sd->fd, msg_len + 12);
  5360. }
  5361. /// Displays heal effect.
  5362. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5363. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5364. /// var id:
  5365. /// 5 = HP (SP_HP)
  5366. /// 7 = SP (SP_SP)
  5367. /// ? = ignored
  5368. void clif_heal(int fd,int type,int val) {
  5369. #if PACKETVER < 20141022
  5370. const int cmd = 0x13d;
  5371. #else
  5372. const int cmd = 0xa27;
  5373. #endif
  5374. WFIFOHEAD(fd, packet_len(cmd));
  5375. WFIFOW(fd,0) = cmd;
  5376. WFIFOW(fd,2) = type;
  5377. #if PACKETVER < 20141022
  5378. WFIFOW(fd,4) = min(val, INT16_MAX);
  5379. #else
  5380. WFIFOL(fd,4) = min(val, INT32_MAX);
  5381. #endif
  5382. WFIFOSET(fd, packet_len(cmd));
  5383. }
  5384. /// Displays resurrection effect (ZC_RESURRECTION).
  5385. /// 0148 <id>.L <type>.W
  5386. /// type:
  5387. /// ignored
  5388. void clif_resurrection(struct block_list *bl,int type)
  5389. {
  5390. unsigned char buf[16];
  5391. nullpo_retv(bl);
  5392. WBUFW(buf,0)=0x148;
  5393. WBUFL(buf,2)=bl->id;
  5394. WBUFW(buf,6)=0;
  5395. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5396. if (disguised(bl))
  5397. clif_spawn(bl);
  5398. }
  5399. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5400. /// 0199 <type>.W
  5401. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5402. {
  5403. int fd;
  5404. nullpo_retv(sd);
  5405. fd=sd->fd;
  5406. WFIFOHEAD(fd,packet_len(0x199));
  5407. WFIFOW(fd,0)=0x199;
  5408. WFIFOW(fd,2)=property;
  5409. WFIFOSET(fd,packet_len(0x199));
  5410. }
  5411. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5412. #if PACKETVER >= 20121010
  5413. unsigned char buf[8];
  5414. unsigned int NotifyProperty =
  5415. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5416. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5417. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5418. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5419. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5420. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5421. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5422. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5423. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5424. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5425. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5426. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5427. WBUFW(buf,0)=0x99b;
  5428. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5429. WBUFL(buf,4)=NotifyProperty;
  5430. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5431. clif_send(buf,packet_len(0x99b),bl,t);
  5432. #endif
  5433. }
  5434. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5435. /// 01d6 <type>.W
  5436. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5437. {
  5438. int fd;
  5439. nullpo_retv(sd);
  5440. fd=sd->fd;
  5441. WFIFOHEAD(fd,packet_len(0x1D6));
  5442. WFIFOW(fd,0)=0x1D6;
  5443. WFIFOW(fd,2)=type;
  5444. WFIFOSET(fd,packet_len(0x1D6));
  5445. }
  5446. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5447. /// 019a <id>.L <ranking>.L <total>.L
  5448. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5449. {
  5450. if(type == 2) {
  5451. int fd = sd->fd;
  5452. WFIFOHEAD(fd,packet_len(0x19a));
  5453. WFIFOW(fd,0) = 0x19a;
  5454. WFIFOL(fd,2) = sd->bl.id;
  5455. WFIFOL(fd,6) = pvprank;
  5456. WFIFOL(fd,10) = pvpnum;
  5457. WFIFOSET(fd,packet_len(0x19a));
  5458. } else {
  5459. unsigned char buf[32];
  5460. WBUFW(buf,0) = 0x19a;
  5461. WBUFL(buf,2) = sd->bl.id;
  5462. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5463. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5464. else
  5465. WBUFL(buf,6) = pvprank;
  5466. WBUFL(buf,10) = pvpnum;
  5467. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5468. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5469. else if(!type)
  5470. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5471. else
  5472. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5473. }
  5474. }
  5475. /*==========================================
  5476. *
  5477. *------------------------------------------*/
  5478. void clif_map_property_mapall(int map_idx, enum map_property property)
  5479. {
  5480. struct block_list bl;
  5481. unsigned char buf[16];
  5482. bl.id = 0;
  5483. bl.type = BL_NUL;
  5484. bl.m = map_idx;
  5485. WBUFW(buf,0)=0x199;
  5486. WBUFW(buf,2)=property;
  5487. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5488. }
  5489. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5490. /// 0188 <result>.W <index>.W <refine>.W
  5491. /// result:
  5492. /// 0 = success
  5493. /// 1 = failure
  5494. /// 2 = downgrade
  5495. void clif_refine(int fd, int fail, int index, int val)
  5496. {
  5497. WFIFOHEAD(fd,packet_len(0x188));
  5498. WFIFOW(fd,0)=0x188;
  5499. WFIFOW(fd,2)=fail;
  5500. WFIFOW(fd,4)=index+2;
  5501. WFIFOW(fd,6)=val;
  5502. WFIFOSET(fd,packet_len(0x188));
  5503. }
  5504. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5505. /// 0223 <result>.L <nameid>.W
  5506. /// result:
  5507. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5508. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5509. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5510. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5511. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5512. {
  5513. WFIFOHEAD(fd,packet_len(0x223));
  5514. WFIFOW(fd,0)=0x223;
  5515. WFIFOL(fd,2)=result;
  5516. WFIFOW(fd,6)=item_id;
  5517. WFIFOSET(fd,packet_len(0x223));
  5518. }
  5519. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5520. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5521. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5522. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5523. {
  5524. #if PACKETVER < 20091104
  5525. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5526. WFIFOW(fd,0) = 0x97;
  5527. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5528. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5529. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5530. WFIFOSET(fd,WFIFOW(fd,2));
  5531. #else
  5532. struct map_session_data *ssd = map_nick2sd(nick);
  5533. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5534. WFIFOW(fd,0) = 0x97;
  5535. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5536. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5537. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5538. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5539. WFIFOSET(fd,WFIFOW(fd,2));
  5540. #endif
  5541. }
  5542. /// Inform the player about the result of his whisper action
  5543. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5544. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5545. /// result:
  5546. /// 0 = success to send wisper
  5547. /// 1 = target character is not loged in
  5548. /// 2 = ignored by target
  5549. /// 3 = everyone ignored by target
  5550. void clif_wis_end(int fd, int result)
  5551. {
  5552. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5553. #if PACKETVER < 20131223
  5554. const int cmd = 0x98;
  5555. #else
  5556. const int cmd = 0x9df;
  5557. #endif
  5558. if (!sd)
  5559. return;
  5560. WFIFOHEAD(fd,packet_len(cmd));
  5561. WFIFOW(fd,0) = cmd;
  5562. WFIFOB(fd,2) = (char)result;
  5563. #if PACKETVER >= 20131223
  5564. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5565. #endif
  5566. WFIFOSET(fd,packet_len(cmd));
  5567. }
  5568. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5569. /// 0194 <char id>.L <name>.24B
  5570. void clif_solved_charname(int fd, int charid, const char* name)
  5571. {
  5572. WFIFOHEAD(fd,packet_len(0x194));
  5573. WFIFOW(fd,0)=0x194;
  5574. WFIFOL(fd,2)=charid;
  5575. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5576. WFIFOSET(fd,packet_len(0x194));
  5577. }
  5578. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5579. /// 017b <packet len>.W { <name id>.W }*
  5580. void clif_use_card(struct map_session_data *sd,int idx)
  5581. {
  5582. int i,c,ep;
  5583. int fd=sd->fd;
  5584. nullpo_retv(sd);
  5585. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5586. return;
  5587. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5588. return; //Avoid parsing invalid item indexes (no card/no item)
  5589. ep=sd->inventory_data[idx]->equip;
  5590. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5591. WFIFOW(fd,0)=0x17b;
  5592. for(i=c=0;i<MAX_INVENTORY;i++){
  5593. int j;
  5594. if(sd->inventory_data[i] == NULL)
  5595. continue;
  5596. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5597. continue;
  5598. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5599. continue;
  5600. if(sd->status.inventory[i].identify==0 ) //Not identified
  5601. continue;
  5602. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5603. continue;
  5604. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5605. continue;
  5606. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5607. if( j == sd->inventory_data[i]->slot ) // No room
  5608. continue;
  5609. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5610. continue;
  5611. WFIFOW(fd,4+c*2)=i+2;
  5612. c++;
  5613. }
  5614. if( !c ) return; // no item is available for card insertion
  5615. WFIFOW(fd,2)=4+c*2;
  5616. WFIFOSET(fd,WFIFOW(fd,2));
  5617. }
  5618. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5619. /// 017d <equip index>.W <card index>.W <result>.B
  5620. /// result:
  5621. /// 0 = success
  5622. /// 1 = failure
  5623. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5624. {
  5625. int fd;
  5626. nullpo_retv(sd);
  5627. fd=sd->fd;
  5628. WFIFOHEAD(fd,packet_len(0x17d));
  5629. WFIFOW(fd,0)=0x17d;
  5630. WFIFOW(fd,2)=idx_equip+2;
  5631. WFIFOW(fd,4)=idx_card+2;
  5632. WFIFOB(fd,6)=flag;
  5633. WFIFOSET(fd,packet_len(0x17d));
  5634. }
  5635. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5636. /// 0177 <packet len>.W { <name id>.W }*
  5637. void clif_item_identify_list(struct map_session_data *sd)
  5638. {
  5639. int i,c;
  5640. int fd;
  5641. nullpo_retv(sd);
  5642. fd=sd->fd;
  5643. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5644. WFIFOW(fd,0)=0x177;
  5645. for(i=c=0;i<MAX_INVENTORY;i++){
  5646. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5647. WFIFOW(fd,c*2+4)=i+2;
  5648. c++;
  5649. }
  5650. }
  5651. if(c > 0) {
  5652. WFIFOW(fd,2)=c*2+4;
  5653. WFIFOSET(fd,WFIFOW(fd,2));
  5654. sd->menuskill_id = MC_IDENTIFY;
  5655. sd->menuskill_val = c;
  5656. }
  5657. }
  5658. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5659. /// 0179 <index>.W <result>.B
  5660. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5661. {
  5662. int fd;
  5663. nullpo_retv(sd);
  5664. fd=sd->fd;
  5665. WFIFOHEAD(fd,packet_len(0x179));
  5666. WFIFOW(fd, 0)=0x179;
  5667. WFIFOW(fd, 2)=idx+2;
  5668. WFIFOB(fd, 4)=flag;
  5669. WFIFOSET(fd,packet_len(0x179));
  5670. }
  5671. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5672. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5673. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5674. {
  5675. int i,c;
  5676. int fd;
  5677. nullpo_retv(sd);
  5678. nullpo_retv(dstsd);
  5679. fd=sd->fd;
  5680. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5681. WFIFOW(fd,0)=0x1fc;
  5682. for(i=c=0;i<MAX_INVENTORY;i++){
  5683. unsigned short nameid;
  5684. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5685. WFIFOW(fd,c*13+4) = i;
  5686. WFIFOW(fd,c*13+6) = nameid;
  5687. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5688. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5689. c++;
  5690. }
  5691. }
  5692. if(c > 0) {
  5693. WFIFOW(fd,2)=c*13+4;
  5694. WFIFOSET(fd,WFIFOW(fd,2));
  5695. sd->menuskill_id = BS_REPAIRWEAPON;
  5696. sd->menuskill_val = dstsd->bl.id;
  5697. sd->menuskill_val2 = lv;
  5698. }else
  5699. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5700. }
  5701. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5702. /// 01fe <index>.W <result>.B
  5703. /// index:
  5704. /// ignored (inventory index)
  5705. /// result:
  5706. /// 0 = Item repair success.
  5707. /// 1 = Item repair failure.
  5708. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5709. {
  5710. int fd;
  5711. nullpo_retv(sd);
  5712. fd = sd->fd;
  5713. WFIFOHEAD(fd,packet_len(0x1fe));
  5714. WFIFOW(fd, 0)=0x1fe;
  5715. WFIFOW(fd, 2)=idx+2;
  5716. WFIFOB(fd, 4)=flag;
  5717. WFIFOSET(fd,packet_len(0x1fe));
  5718. }
  5719. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5720. /// 02bb <equip location>.W <account id>.L
  5721. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5722. {
  5723. int fd = sd->fd;
  5724. WFIFOHEAD(fd,packet_len(0x2bb));
  5725. WFIFOW(fd,0) = 0x2bb;
  5726. WFIFOW(fd,2) = position;
  5727. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5728. WFIFOSET(fd,packet_len(0x2bb));
  5729. }
  5730. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5731. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5732. void clif_item_refine_list(struct map_session_data *sd)
  5733. {
  5734. int i,c;
  5735. int fd;
  5736. uint16 skill_lv;
  5737. int refine_item[5];
  5738. nullpo_retv(sd);
  5739. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5740. fd=sd->fd;
  5741. refine_item[0] = -1;
  5742. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5743. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5744. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5745. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5746. WFIFOW(fd,0)=0x221;
  5747. for(i=c=0;i<MAX_INVENTORY;i++){
  5748. unsigned char wlv;
  5749. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5750. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5751. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5752. WFIFOW(fd,c*13+ 4)=i+2;
  5753. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5754. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5755. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5756. c++;
  5757. }
  5758. }
  5759. WFIFOW(fd,2)=c*13+4;
  5760. WFIFOSET(fd,WFIFOW(fd,2));
  5761. if (c > 0) {
  5762. sd->menuskill_id = WS_WEAPONREFINE;
  5763. sd->menuskill_val = skill_lv;
  5764. }
  5765. }
  5766. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5767. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5768. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5769. {
  5770. int fd;
  5771. nullpo_retv(sd);
  5772. fd=sd->fd;
  5773. WFIFOHEAD(fd,packet_len(0x147));
  5774. WFIFOW(fd, 0)=0x147;
  5775. WFIFOW(fd, 2)=skill_id;
  5776. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5777. WFIFOW(fd, 6)=0;
  5778. WFIFOW(fd, 8)=skill_lv;
  5779. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5780. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5781. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5782. WFIFOB(fd,38)=0;
  5783. WFIFOSET(fd,packet_len(0x147));
  5784. }
  5785. /// Adds an item to character's cart.
  5786. /// 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)
  5787. /// 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)
  5788. /// 0a0b <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_CART3)
  5789. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5790. {
  5791. #if PACKETVER < 5
  5792. const int cmd = 0x124;
  5793. #elif PACKETVER < 20150226
  5794. const int cmd = 0x1c5;
  5795. #else
  5796. const int cmd = 0xa0b;
  5797. #endif
  5798. int view,fd;
  5799. unsigned char *buf;
  5800. int offset = 0;
  5801. nullpo_retv(sd);
  5802. fd=sd->fd;
  5803. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5804. return;
  5805. WFIFOHEAD(fd,packet_len(cmd));
  5806. buf=WFIFOP(fd,0);
  5807. WBUFW(buf,0)=cmd;
  5808. WBUFW(buf,2)=n+2;
  5809. WBUFL(buf,4)=amount;
  5810. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5811. WBUFW(buf,8)=view;
  5812. else
  5813. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5814. #if PACKETVER >= 5
  5815. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5816. offset += 1;
  5817. #endif
  5818. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5819. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5820. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5821. clif_addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5822. #if PACKETVER >= 20150226
  5823. clif_add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5824. #endif
  5825. WFIFOSET(fd,packet_len(cmd));
  5826. }
  5827. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5828. /* Acknowledge an item have been added to cart
  5829. * 012c <result>B
  5830. * result :
  5831. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5832. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5833. */
  5834. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5835. {
  5836. int fd;
  5837. unsigned char *buf;
  5838. nullpo_retv(sd);
  5839. fd = sd->fd;
  5840. buf = WFIFOP(fd,0);
  5841. WBUFW(buf,0) = 0x12c;
  5842. WBUFB(buf,2) = flag;
  5843. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5844. }
  5845. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5846. void clif_bank_open(struct map_session_data *sd){
  5847. int fd;
  5848. nullpo_retv(sd);
  5849. fd = sd->fd;
  5850. WFIFOHEAD(fd,4);
  5851. WFIFOW(fd,0) = 0x09b7;
  5852. WFIFOW(fd,2) = 0;
  5853. WFIFOSET(fd,4);
  5854. }
  5855. /*
  5856. * Request to Open the banking system
  5857. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5858. */
  5859. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5860. //TODO check if preventing trade or stuff like that
  5861. //also mark something in case char ain't available for saving, should we check now ?
  5862. nullpo_retv(sd);
  5863. if( !battle_config.feature_banking ) {
  5864. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5865. return;
  5866. }
  5867. else {
  5868. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5869. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5870. if(sd->status.account_id == aid){
  5871. sd->state.banking = 1;
  5872. //request save ?
  5873. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5874. //on succes open bank ?
  5875. clif_bank_open(sd);
  5876. }
  5877. }
  5878. }
  5879. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5880. void clif_bank_close(struct map_session_data *sd){
  5881. int fd;
  5882. nullpo_retv(sd);
  5883. fd = sd->fd;
  5884. WFIFOHEAD(fd,4);
  5885. WFIFOW(fd,0) = 0x09B9;
  5886. WFIFOW(fd,2) = 0;
  5887. WFIFOSET(fd,4);
  5888. }
  5889. /*
  5890. * Request to close the banking system
  5891. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5892. */
  5893. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5894. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5895. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5896. nullpo_retv(sd);
  5897. if( !battle_config.feature_banking ) {
  5898. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5899. //still allow to go trough to not stuck player if we have disable it while they was in
  5900. }
  5901. if(sd->status.account_id == aid){
  5902. sd->state.banking = 0;
  5903. clif_bank_close(sd);
  5904. }
  5905. }
  5906. /*
  5907. * Display how much we got in bank (I suppose)
  5908. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5909. */
  5910. void clif_Bank_Check(struct map_session_data* sd) {
  5911. unsigned char buf[13];
  5912. struct s_packet_db* info;
  5913. int16 len;
  5914. int cmd = 0;
  5915. nullpo_retv(sd);
  5916. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5917. if(!cmd) cmd = 0x09A6; //default
  5918. info = &packet_db[sd->packet_ver][cmd];
  5919. len = info->len;
  5920. if(!len) return; //version as packet disable
  5921. // sd->state.banking = 1; //mark opening and closing
  5922. WBUFW(buf,0) = cmd;
  5923. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5924. WBUFW(buf,info->pos[1]) = 0; //reason
  5925. clif_send(buf,len,&sd->bl,SELF);
  5926. }
  5927. /*
  5928. * Requesting the data in bank
  5929. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5930. */
  5931. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5932. nullpo_retv(sd);
  5933. if( !battle_config.feature_banking ) {
  5934. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5935. return;
  5936. }
  5937. else {
  5938. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5939. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5940. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5941. clif_Bank_Check(sd);
  5942. }
  5943. }
  5944. /*
  5945. * Acknowledge of deposit some money in bank
  5946. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5947. */
  5948. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5949. unsigned char buf[17];
  5950. struct s_packet_db* info;
  5951. int16 len;
  5952. int cmd =0;
  5953. nullpo_retv(sd);
  5954. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5955. if(!cmd) cmd = 0x09A8;
  5956. info = &packet_db[sd->packet_ver][cmd];
  5957. len = info->len;
  5958. if(!len) return; //version as packet disable
  5959. WBUFW(buf,0) = cmd;
  5960. WBUFW(buf,info->pos[0]) = (short)reason;
  5961. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5962. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5963. clif_send(buf,len,&sd->bl,SELF);
  5964. }
  5965. /*
  5966. * Request saving some money in bank
  5967. * @author : original [Yommy/Hercules]
  5968. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5969. */
  5970. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5971. nullpo_retv(sd);
  5972. if( !battle_config.feature_banking ) {
  5973. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5974. return;
  5975. }
  5976. else {
  5977. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5978. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5979. int money = RFIFOL(fd,info->pos[1]);
  5980. if(sd->status.account_id == aid){
  5981. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5982. clif_bank_deposit(sd,reason);
  5983. }
  5984. }
  5985. }
  5986. /*
  5987. * Acknowledge of withdrawing some money from bank
  5988. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5989. */
  5990. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5991. unsigned char buf[17];
  5992. struct s_packet_db* info;
  5993. int16 len;
  5994. int cmd;
  5995. nullpo_retv(sd);
  5996. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5997. if(!cmd) cmd = 0x09AA;
  5998. info = &packet_db[sd->packet_ver][cmd];
  5999. len = info->len;
  6000. if(!len) return; //version as packet disable
  6001. WBUFW(buf,0) = cmd;
  6002. WBUFW(buf,info->pos[0]) = (short)reason;
  6003. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6004. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6005. clif_send(buf,len,&sd->bl,SELF);
  6006. }
  6007. /*
  6008. * Request Withdrawing some money from bank
  6009. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6010. */
  6011. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6012. nullpo_retv(sd);
  6013. if( !battle_config.feature_banking ) {
  6014. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  6015. return;
  6016. }
  6017. else {
  6018. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  6019. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6020. int money = RFIFOL(fd,info->pos[1]);
  6021. if(sd->status.account_id == aid){
  6022. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6023. clif_bank_withdraw(sd,reason);
  6024. }
  6025. }
  6026. }
  6027. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6028. /// 0125 <index>.W <amount>.L
  6029. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6030. {
  6031. int fd;
  6032. nullpo_retv(sd);
  6033. fd=sd->fd;
  6034. WFIFOHEAD(fd,packet_len(0x125));
  6035. WFIFOW(fd,0)=0x125;
  6036. WFIFOW(fd,2)=n+2;
  6037. WFIFOL(fd,4)=amount;
  6038. WFIFOSET(fd,packet_len(0x125));
  6039. }
  6040. /// Opens the shop creation menu (ZC_OPENSTORE).
  6041. /// 012d <num>.W
  6042. /// num:
  6043. /// number of allowed item slots
  6044. void clif_openvendingreq(struct map_session_data* sd, int num)
  6045. {
  6046. int fd;
  6047. nullpo_retv(sd);
  6048. fd = sd->fd;
  6049. WFIFOHEAD(fd,packet_len(0x12d));
  6050. WFIFOW(fd,0) = 0x12d;
  6051. WFIFOW(fd,2) = num;
  6052. WFIFOSET(fd,packet_len(0x12d));
  6053. }
  6054. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6055. /// 0131 <owner id>.L <message>.80B
  6056. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6057. {
  6058. unsigned char buf[128];
  6059. nullpo_retv(bl);
  6060. WBUFW(buf,0) = 0x131;
  6061. WBUFL(buf,2) = bl->id;
  6062. safestrncpy((char*)WBUFP(buf,6), message, 80);
  6063. if( fd ) {
  6064. WFIFOHEAD(fd,packet_len(0x131));
  6065. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6066. WFIFOSET(fd,packet_len(0x131));
  6067. } else {
  6068. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6069. }
  6070. }
  6071. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6072. /// 0132 <owner id>.L
  6073. void clif_closevendingboard(struct block_list* bl, int fd)
  6074. {
  6075. unsigned char buf[16];
  6076. nullpo_retv(bl);
  6077. WBUFW(buf,0) = 0x132;
  6078. WBUFL(buf,2) = bl->id;
  6079. if( fd ) {
  6080. WFIFOHEAD(fd,packet_len(0x132));
  6081. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6082. WFIFOSET(fd,packet_len(0x132));
  6083. } else {
  6084. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6085. }
  6086. }
  6087. /// Sends a list of items in a shop.
  6088. /// 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)
  6089. /// 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)
  6090. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6091. {
  6092. int i,fd;
  6093. int count;
  6094. struct map_session_data* vsd;
  6095. #if PACKETVER < 20100105
  6096. const int cmd = 0x133;
  6097. const int offset = 8;
  6098. #else
  6099. const int cmd = 0x800;
  6100. const int offset = 12;
  6101. #endif
  6102. #if PACKETVER < 20150226
  6103. const int item_length = 22;
  6104. #else
  6105. const int item_length = 47;
  6106. #endif
  6107. nullpo_retv(sd);
  6108. nullpo_retv(vending);
  6109. nullpo_retv(vsd=map_id2sd(id));
  6110. fd = sd->fd;
  6111. count = vsd->vend_num;
  6112. WFIFOHEAD(fd, offset+count*item_length);
  6113. WFIFOW(fd,0) = cmd;
  6114. WFIFOW(fd,2) = offset+count*item_length;
  6115. WFIFOL(fd,4) = id;
  6116. #if PACKETVER >= 20100105
  6117. WFIFOL(fd,8) = vsd->vender_id;
  6118. #endif
  6119. for( i = 0; i < count; i++ )
  6120. {
  6121. int index = vending[i].index;
  6122. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  6123. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6124. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6125. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6126. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6127. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  6128. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  6129. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  6130. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  6131. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  6132. #if PACKETVER >= 20150226
  6133. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  6134. #endif
  6135. }
  6136. WFIFOSET(fd,WFIFOW(fd,2));
  6137. }
  6138. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6139. /// 0135 <index>.W <amount>.W <result>.B
  6140. /// result:
  6141. /// 0 = success
  6142. /// 1 = not enough zeny
  6143. /// 2 = overweight
  6144. /// 4 = out of stock
  6145. /// 5 = "cannot use an npc shop while in a trade"
  6146. /// 6 = Because the store information was incorrect the item was not purchased.
  6147. /// 7 = No sales information.
  6148. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6149. {
  6150. int fd;
  6151. nullpo_retv(sd);
  6152. fd = sd->fd;
  6153. WFIFOHEAD(fd,packet_len(0x135));
  6154. WFIFOW(fd,0) = 0x135;
  6155. WFIFOW(fd,2) = index+2;
  6156. WFIFOW(fd,4) = amount;
  6157. WFIFOB(fd,6) = fail;
  6158. WFIFOSET(fd,packet_len(0x135));
  6159. }
  6160. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6161. /// 0a28 <Result>.B
  6162. /// result:
  6163. /// 0 = Successed
  6164. /// 1 = Failed
  6165. void clif_openvending_ack(struct map_session_data* sd, int result)
  6166. {
  6167. int fd;
  6168. nullpo_retv(sd);
  6169. fd = sd->fd;
  6170. WFIFOHEAD(fd, 3);
  6171. WFIFOW(fd,0) = 0xa28;
  6172. WFIFOB(fd,2) = result;
  6173. WFIFOSET(fd, 3);
  6174. }
  6175. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6176. /// 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 }*
  6177. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6178. {
  6179. int i,fd;
  6180. int count;
  6181. #if PACKETVER < 20150226
  6182. const int item_length = 22;
  6183. #else
  6184. const int item_length = 47;
  6185. #endif
  6186. nullpo_retv(sd);
  6187. fd = sd->fd;
  6188. count = sd->vend_num;
  6189. WFIFOHEAD(fd, 8+count*item_length);
  6190. WFIFOW(fd,0) = 0x136;
  6191. WFIFOW(fd,2) = 8+count*item_length;
  6192. WFIFOL(fd,4) = id;
  6193. for( i = 0; i < count; i++ ) {
  6194. int index = vending[i].index;
  6195. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  6196. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6197. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6198. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6199. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6200. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  6201. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  6202. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  6203. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  6204. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  6205. #if PACKETVER >= 20150226
  6206. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->status.cart[index]);
  6207. #endif
  6208. }
  6209. WFIFOSET(fd,WFIFOW(fd,2));
  6210. #if PACKETVER >= 20141022
  6211. /// 0 = Successed
  6212. /// 1 = Failed
  6213. clif_openvending_ack(sd, 0);
  6214. #endif
  6215. }
  6216. /// Inform merchant that someone has bought an item.
  6217. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6218. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6219. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6220. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6221. const int cmd = 0x137;
  6222. #else
  6223. const int cmd = 0x9e5;
  6224. #endif
  6225. int fd = sd->fd;
  6226. nullpo_retv(sd);
  6227. WFIFOHEAD(fd,packet_len(cmd));
  6228. WFIFOW(fd,0) = cmd;
  6229. WFIFOW(fd,2) = index+2;
  6230. WFIFOW(fd,4) = amount;
  6231. #if PACKETVER >= 20141016
  6232. WFIFOL(fd,6) = char_id; // GID
  6233. WFIFOL(fd,10) = (int)time(NULL); // Date
  6234. WFIFOL(fd,14) = zeny; // zeny
  6235. #endif
  6236. WFIFOSET(fd,packet_len(cmd));
  6237. }
  6238. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6239. /// 00fa <result>.B
  6240. /// result:
  6241. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6242. /// 1 = MsgStringTable[78]="party name already exists"
  6243. /// 2 = MsgStringTable[79]="already in a party"
  6244. /// 3 = cannot organize parties on this map
  6245. /// ? = nothing
  6246. void clif_party_created(struct map_session_data *sd,int result)
  6247. {
  6248. int fd;
  6249. nullpo_retv(sd);
  6250. fd=sd->fd;
  6251. WFIFOHEAD(fd,packet_len(0xfa));
  6252. WFIFOW(fd,0)=0xfa;
  6253. WFIFOB(fd,2)=result;
  6254. WFIFOSET(fd,packet_len(0xfa));
  6255. }
  6256. /// Adds new member to a party.
  6257. /// 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)
  6258. /// 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)
  6259. /// role:
  6260. /// 0 = leader
  6261. /// 1 = normal
  6262. /// state:
  6263. /// 0 = connected
  6264. /// 1 = disconnected
  6265. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6266. {
  6267. unsigned char buf[81];
  6268. int i;
  6269. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6270. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6271. } else {
  6272. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6273. }
  6274. if (i >= MAX_PARTY) return; //Should never happen...
  6275. sd = p->data[i].sd;
  6276. WBUFW(buf, 0) = 0x1e9;
  6277. WBUFL(buf, 2) = sd->status.account_id;
  6278. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6279. WBUFW(buf,10) = sd->bl.x;
  6280. WBUFW(buf,12) = sd->bl.y;
  6281. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6282. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6283. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6284. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6285. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6286. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6287. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6288. }
  6289. /// Sends party information (ZC_GROUP_LIST).
  6290. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6291. /// role:
  6292. /// 0 = leader
  6293. /// 1 = normal
  6294. /// state:
  6295. /// 0 = connected
  6296. /// 1 = disconnected
  6297. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6298. {
  6299. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6300. struct map_session_data* party_sd = NULL;
  6301. int i, c;
  6302. nullpo_retv(p);
  6303. WBUFW(buf,0) = 0xfb;
  6304. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6305. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6306. {
  6307. struct party_member* m = &p->party.member[i];
  6308. if(!m->account_id) continue;
  6309. if(party_sd == NULL) party_sd = p->data[i].sd;
  6310. WBUFL(buf,28+c*46) = m->account_id;
  6311. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6312. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6313. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6314. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6315. c++;
  6316. }
  6317. WBUFW(buf,2) = 28+c*46;
  6318. if(sd) { // send only to self
  6319. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6320. } else if (party_sd) { // send to whole party
  6321. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6322. }
  6323. }
  6324. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6325. /// 02c9 <flag>.B
  6326. /// flag:
  6327. /// 0 = allow party invites
  6328. /// 1 = auto-deny party invites
  6329. void clif_partyinvitationstate(struct map_session_data* sd)
  6330. {
  6331. int fd;
  6332. nullpo_retv(sd);
  6333. fd = sd->fd;
  6334. WFIFOHEAD(fd, packet_len(0x2c9));
  6335. WFIFOW(fd, 0) = 0x2c9;
  6336. WFIFOB(fd, 2) = 0; // not implemented
  6337. WFIFOSET(fd, packet_len(0x2c9));
  6338. }
  6339. /// Party invitation request.
  6340. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6341. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6342. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6343. {
  6344. #if PACKETVER < 20070821
  6345. const int cmd = 0xfe;
  6346. #else
  6347. const int cmd = 0x2c6;
  6348. #endif
  6349. int fd;
  6350. struct party_data *p;
  6351. nullpo_retv(sd);
  6352. nullpo_retv(tsd);
  6353. fd=tsd->fd;
  6354. if( (p=party_search(sd->status.party_id))==NULL )
  6355. return;
  6356. WFIFOHEAD(fd,packet_len(cmd));
  6357. WFIFOW(fd,0)=cmd;
  6358. WFIFOL(fd,2)=sd->status.party_id;
  6359. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6360. WFIFOSET(fd,packet_len(cmd));
  6361. }
  6362. /// Party invite result.
  6363. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6364. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6365. /// result=0 : char is already in a party -> MsgStringTable[80]
  6366. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6367. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6368. /// result=3 : party is full -> MsgStringTable[83]
  6369. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6370. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6371. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6372. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  6373. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  6374. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  6375. {
  6376. int fd;
  6377. nullpo_retv(sd);
  6378. fd=sd->fd;
  6379. #if PACKETVER < 20070904
  6380. if( result == 7 ) {
  6381. clif_displaymessage(fd, msg_txt(sd,3));
  6382. return;
  6383. }
  6384. #endif
  6385. #if PACKETVER < 20070821
  6386. WFIFOHEAD(fd,packet_len(0xfd));
  6387. WFIFOW(fd,0) = 0xfd;
  6388. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6389. WFIFOB(fd,26) = result;
  6390. WFIFOSET(fd,packet_len(0xfd));
  6391. #else
  6392. WFIFOHEAD(fd,packet_len(0x2c5));
  6393. WFIFOW(fd,0) = 0x2c5;
  6394. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6395. WFIFOL(fd,26) = result;
  6396. WFIFOSET(fd,packet_len(0x2c5));
  6397. #endif
  6398. }
  6399. /// Updates party settings.
  6400. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6401. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6402. /// exp option:
  6403. /// 0 = exp sharing disabled
  6404. /// 1 = exp sharing enabled
  6405. /// 2 = cannot change exp sharing
  6406. ///
  6407. /// flag:
  6408. /// 0 = send to party
  6409. /// 1 = send to sd
  6410. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6411. {
  6412. unsigned char buf[16];
  6413. #if PACKETVER < 20090603
  6414. const int cmd = 0x101;
  6415. #else
  6416. const int cmd = 0x7d8;
  6417. #endif
  6418. nullpo_retv(p);
  6419. if(!sd && flag==0){
  6420. int i;
  6421. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6422. if (i < MAX_PARTY)
  6423. sd = p->data[i].sd;
  6424. }
  6425. if(!sd) return;
  6426. WBUFW(buf,0)=cmd;
  6427. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6428. #if PACKETVER >= 20090603
  6429. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6430. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6431. #endif
  6432. if(flag==0)
  6433. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6434. else
  6435. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6436. }
  6437. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6438. /// result:
  6439. /// 0 = leave
  6440. /// 1 = expel
  6441. /// 2 = cannot leave party on this map
  6442. /// 3 = cannot expel from party on this map
  6443. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6444. {
  6445. unsigned char buf[64];
  6446. nullpo_retv(p);
  6447. if(!sd && (flag&0xf0)==0)
  6448. {
  6449. int i;
  6450. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6451. if (i < MAX_PARTY)
  6452. sd = p->data[i].sd;
  6453. }
  6454. if(!sd) return;
  6455. WBUFW(buf,0)=0x105;
  6456. WBUFL(buf,2)=account_id;
  6457. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6458. WBUFB(buf,30)=flag&0x0f;
  6459. if((flag&0xf0)==0)
  6460. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6461. else
  6462. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6463. }
  6464. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6465. /// 0109 <packet len>.W <account id>.L <message>.?B
  6466. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6467. {
  6468. struct map_session_data *sd;
  6469. int i;
  6470. nullpo_retv(p);
  6471. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6472. if(i < MAX_PARTY){
  6473. unsigned char buf[1024];
  6474. if( len > sizeof(buf)-8 )
  6475. {
  6476. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6477. len = sizeof(buf)-8;
  6478. }
  6479. sd = p->data[i].sd;
  6480. WBUFW(buf,0)=0x109;
  6481. WBUFW(buf,2)=len+8;
  6482. WBUFL(buf,4)=account_id;
  6483. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6484. clif_send(buf,len+8,&sd->bl,PARTY);
  6485. }
  6486. }
  6487. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6488. /// 0107 <account id>.L <x>.W <y>.W
  6489. void clif_party_xy(struct map_session_data *sd)
  6490. {
  6491. unsigned char buf[16];
  6492. nullpo_retv(sd);
  6493. WBUFW(buf,0)=0x107;
  6494. WBUFL(buf,2)=sd->status.account_id;
  6495. WBUFW(buf,6)=sd->bl.x;
  6496. WBUFW(buf,8)=sd->bl.y;
  6497. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6498. }
  6499. /*==========================================
  6500. * Sends x/y dot to a single fd. [Skotlex]
  6501. *------------------------------------------*/
  6502. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6503. {
  6504. WFIFOHEAD(fd,packet_len(0x107));
  6505. WFIFOW(fd,0)=0x107;
  6506. WFIFOL(fd,2)=sd->status.account_id;
  6507. WFIFOW(fd,6)=sd->bl.x;
  6508. WFIFOW(fd,8)=sd->bl.y;
  6509. WFIFOSET(fd,packet_len(0x107));
  6510. }
  6511. /// Updates HP bar of a party member.
  6512. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6513. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6514. void clif_party_hp(struct map_session_data *sd)
  6515. {
  6516. unsigned char buf[16];
  6517. #if PACKETVER < 20100126
  6518. const int cmd = 0x106;
  6519. #else
  6520. const int cmd = 0x80e;
  6521. #endif
  6522. nullpo_retv(sd);
  6523. WBUFW(buf,0)=cmd;
  6524. WBUFL(buf,2)=sd->status.account_id;
  6525. #if PACKETVER < 20100126
  6526. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6527. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6528. WBUFW(buf,8) = 100;
  6529. } else {
  6530. WBUFW(buf,6) = sd->battle_status.hp;
  6531. WBUFW(buf,8) = sd->battle_status.max_hp;
  6532. }
  6533. #else
  6534. WBUFL(buf,6) = sd->battle_status.hp;
  6535. WBUFL(buf,10) = sd->battle_status.max_hp;
  6536. #endif
  6537. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6538. }
  6539. /*==========================================
  6540. * Sends HP bar to a single fd. [Skotlex]
  6541. *------------------------------------------*/
  6542. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6543. {
  6544. #if PACKETVER < 20100126
  6545. const int cmd = 0x106;
  6546. #else
  6547. const int cmd = 0x80e;
  6548. #endif
  6549. WFIFOHEAD(fd,packet_len(cmd));
  6550. WFIFOW(fd,0) = cmd;
  6551. WFIFOL(fd,2) = id;
  6552. #if PACKETVER < 20100126
  6553. if( maxhp > INT16_MAX )
  6554. {// To correctly display the %hp bar. [Skotlex]
  6555. WFIFOW(fd,6) = hp/(maxhp/100);
  6556. WFIFOW(fd,8) = 100;
  6557. } else {
  6558. WFIFOW(fd,6) = hp;
  6559. WFIFOW(fd,8) = maxhp;
  6560. }
  6561. #else
  6562. WFIFOL(fd,6) = hp;
  6563. WFIFOL(fd,10) = maxhp;
  6564. #endif
  6565. WFIFOSET(fd, packet_len(cmd));
  6566. }
  6567. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6568. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6569. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6570. {
  6571. int fd;
  6572. nullpo_retv(sd);
  6573. nullpo_retv(bl);
  6574. fd=sd->fd;
  6575. WFIFOHEAD(fd,packet_len(0x139));
  6576. WFIFOW(fd, 0)=0x139;
  6577. WFIFOL(fd, 2)=bl->id;
  6578. WFIFOW(fd, 6)=bl->x;
  6579. WFIFOW(fd, 8)=bl->y;
  6580. WFIFOW(fd,10)=sd->bl.x;
  6581. WFIFOW(fd,12)=sd->bl.y;
  6582. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6583. WFIFOSET(fd,packet_len(0x139));
  6584. }
  6585. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6586. /// 018f <result>.W <name id>.W
  6587. /// result:
  6588. /// 0 = success
  6589. /// 1 = failure
  6590. /// 2 = success (alchemist)
  6591. /// 3 = failure (alchemist)
  6592. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6593. {
  6594. int view,fd;
  6595. nullpo_retv(sd);
  6596. fd = sd->fd;
  6597. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6598. WFIFOHEAD(fd,packet_len(0x18f));
  6599. WFIFOW(fd, 0)=0x18f;
  6600. WFIFOW(fd, 2)=flag;
  6601. if((view = itemdb_viewid(nameid)) > 0)
  6602. WFIFOW(fd, 4)=view;
  6603. else
  6604. WFIFOW(fd, 4)=nameid;
  6605. WFIFOSET(fd,packet_len(0x18f));
  6606. }
  6607. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6608. /// 019e
  6609. void clif_catch_process(struct map_session_data *sd)
  6610. {
  6611. int fd;
  6612. nullpo_retv(sd);
  6613. fd=sd->fd;
  6614. WFIFOHEAD(fd,packet_len(0x19e));
  6615. WFIFOW(fd,0)=0x19e;
  6616. WFIFOSET(fd,packet_len(0x19e));
  6617. }
  6618. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6619. /// 01a0 <result>.B
  6620. /// 0 = failure
  6621. /// 1 = success
  6622. void clif_pet_roulette(struct map_session_data *sd,int data)
  6623. {
  6624. int fd;
  6625. nullpo_retv(sd);
  6626. fd=sd->fd;
  6627. WFIFOHEAD(fd,packet_len(0x1a0));
  6628. WFIFOW(fd,0)=0x1a0;
  6629. WFIFOB(fd,2)=data;
  6630. WFIFOSET(fd,packet_len(0x1a0));
  6631. }
  6632. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6633. /// 01a6 <packet len>.W { <index>.W }*
  6634. void clif_sendegg(struct map_session_data *sd)
  6635. {
  6636. int i,n=0,fd;
  6637. nullpo_retv(sd);
  6638. fd=sd->fd;
  6639. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6640. clif_displaymessage(fd, msg_txt(sd,666));
  6641. return;
  6642. }
  6643. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6644. WFIFOW(fd,0)=0x1a6;
  6645. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6646. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6647. sd->inventory_data[i]->type!=IT_PETEGG ||
  6648. sd->status.inventory[i].amount<=0)
  6649. continue;
  6650. WFIFOW(fd,n*2+4)=i+2;
  6651. n++;
  6652. }
  6653. WFIFOW(fd,2)=4+n*2;
  6654. WFIFOSET(fd,WFIFOW(fd,2));
  6655. sd->menuskill_id = SA_TAMINGMONSTER;
  6656. sd->menuskill_val = -1;
  6657. }
  6658. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6659. /// 01a4 <type>.B <id>.L <data>.L
  6660. /// type:
  6661. /// 0 = pre-init (data = 0)
  6662. /// 1 = intimacy (data = 0~4)
  6663. /// 2 = hunger (data = 0~4)
  6664. /// 3 = accessory
  6665. /// 4 = performance (data = 1~3: normal, 4: special)
  6666. /// 5 = hairstyle
  6667. ///
  6668. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6669. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6670. {
  6671. uint8 buf[16];
  6672. nullpo_retv(pd);
  6673. WBUFW(buf,0) = 0x1a4;
  6674. WBUFB(buf,2) = type;
  6675. WBUFL(buf,3) = pd->bl.id;
  6676. WBUFL(buf,7) = param;
  6677. if (sd)
  6678. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6679. else
  6680. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6681. }
  6682. /// Pet's base data (ZC_PROPERTY_PET).
  6683. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6684. void clif_send_petstatus(struct map_session_data *sd)
  6685. {
  6686. int fd;
  6687. struct s_pet *pet;
  6688. nullpo_retv(sd);
  6689. nullpo_retv(sd->pd);
  6690. fd=sd->fd;
  6691. pet = &sd->pd->pet;
  6692. WFIFOHEAD(fd,packet_len(0x1a2));
  6693. WFIFOW(fd,0)=0x1a2;
  6694. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6695. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6696. WFIFOW(fd,27)=pet->level;
  6697. WFIFOW(fd,29)=pet->hungry;
  6698. WFIFOW(fd,31)=pet->intimate;
  6699. WFIFOW(fd,33)=pet->equip;
  6700. #if PACKETVER >= 20081126
  6701. WFIFOW(fd,35)=pet->class_;
  6702. #endif
  6703. WFIFOSET(fd,packet_len(0x1a2));
  6704. }
  6705. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6706. /// 01aa <id>.L <data>.L
  6707. /// data:
  6708. /// @see CZ_PET_ACT.
  6709. void clif_pet_emotion(struct pet_data *pd,int param)
  6710. {
  6711. unsigned char buf[16];
  6712. nullpo_retv(pd);
  6713. memset(buf,0,packet_len(0x1aa));
  6714. WBUFW(buf,0)=0x1aa;
  6715. WBUFL(buf,2)=pd->bl.id;
  6716. if(param >= 100 && pd->petDB->talk_convert_class) {
  6717. if(pd->petDB->talk_convert_class < 0)
  6718. return;
  6719. else if(pd->petDB->talk_convert_class > 0) {
  6720. // replace mob_id component of talk/act data
  6721. param -= (pd->pet.class_ - 100)*100;
  6722. param += (pd->petDB->talk_convert_class - 100)*100;
  6723. }
  6724. }
  6725. WBUFL(buf,6)=param;
  6726. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6727. }
  6728. /// Result of request to feed a pet (ZC_FEED_PET).
  6729. /// 01a3 <result>.B <name id>.W
  6730. /// result:
  6731. /// 0 = failure
  6732. /// 1 = success
  6733. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6734. {
  6735. int fd;
  6736. nullpo_retv(sd);
  6737. fd=sd->fd;
  6738. WFIFOHEAD(fd,packet_len(0x1a3));
  6739. WFIFOW(fd,0)=0x1a3;
  6740. WFIFOB(fd,2)=fail;
  6741. WFIFOW(fd,3)=foodid;
  6742. WFIFOSET(fd,packet_len(0x1a3));
  6743. }
  6744. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6745. /// 01cd { <skill id>.L }*7
  6746. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6747. {
  6748. int fd;
  6749. nullpo_retv(sd);
  6750. fd=sd->fd;
  6751. WFIFOHEAD(fd,packet_len(0x1cd));
  6752. WFIFOW(fd, 0)=0x1cd;
  6753. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6754. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6755. else
  6756. WFIFOL(fd,2)= 0x00000000;
  6757. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6758. WFIFOL(fd,6)= MG_COLDBOLT;
  6759. else
  6760. WFIFOL(fd,6)= 0x00000000;
  6761. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6762. WFIFOL(fd,10)= MG_FIREBOLT;
  6763. else
  6764. WFIFOL(fd,10)= 0x00000000;
  6765. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6766. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6767. else
  6768. WFIFOL(fd,14)= 0x00000000;
  6769. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6770. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6771. else
  6772. WFIFOL(fd,18)= 0x00000000;
  6773. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6774. WFIFOL(fd,22)= MG_FIREBALL;
  6775. else
  6776. WFIFOL(fd,22)= 0x00000000;
  6777. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6778. WFIFOL(fd,26)= MG_FROSTDIVER;
  6779. else
  6780. WFIFOL(fd,26)= 0x00000000;
  6781. WFIFOSET(fd,packet_len(0x1cd));
  6782. sd->menuskill_id = SA_AUTOSPELL;
  6783. sd->menuskill_val = skill_lv;
  6784. }
  6785. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6786. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6787. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6788. {
  6789. unsigned char buf[56];
  6790. nullpo_retv(src);
  6791. memset(buf,0,packet_len(0x1cf));
  6792. WBUFW(buf,0) = 0x1cf;
  6793. WBUFL(buf,2) = src->id;
  6794. if( src->type == BL_MER )
  6795. {
  6796. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6797. if( md && md->master && md->devotion_flag )
  6798. WBUFL(buf,6) = md->master->bl.id;
  6799. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6800. }
  6801. else
  6802. {
  6803. int i;
  6804. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6805. if( sd == NULL )
  6806. return;
  6807. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6808. WBUFL(buf,6+4*i) = sd->devotion[i];
  6809. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6810. }
  6811. if( tsd )
  6812. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6813. else
  6814. clif_send(buf, packet_len(0x1cf), src, AREA);
  6815. }
  6816. /*==========================================
  6817. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6818. * Notifies clients in an area of an object's spirits.
  6819. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6820. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6821. *------------------------------------------*/
  6822. void clif_spiritball(struct block_list *bl) {
  6823. unsigned char buf[16];
  6824. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6825. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6826. nullpo_retv(bl);
  6827. WBUFW(buf, 0) = 0x1d0;
  6828. WBUFL(buf, 2) = bl->id;
  6829. WBUFW(buf, 6) = 0; //init to 0
  6830. switch(bl->type){
  6831. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6832. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6833. }
  6834. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6835. }
  6836. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6837. /// 01d2 <account id>.L <delay>.L
  6838. void clif_combo_delay(struct block_list *bl,int wait)
  6839. {
  6840. unsigned char buf[32];
  6841. nullpo_retv(bl);
  6842. WBUFW(buf,0)=0x1d2;
  6843. WBUFL(buf,2)=bl->id;
  6844. WBUFL(buf,6)=wait;
  6845. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6846. }
  6847. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6848. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6849. /// flag:
  6850. /// 0 = inactive
  6851. /// 1 = active
  6852. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6853. {
  6854. unsigned char buf[32];
  6855. nullpo_retv(src);
  6856. WBUFW(buf,0)=0x1d1;
  6857. WBUFL(buf,2)=src->id;
  6858. WBUFL(buf,6)=dst_id;
  6859. WBUFL(buf,10)=active;
  6860. clif_send(buf,packet_len(0x1d1),src,AREA);
  6861. }
  6862. /// MVP effect (ZC_MVP).
  6863. /// 010c <account id>.L
  6864. void clif_mvp_effect(struct map_session_data *sd)
  6865. {
  6866. unsigned char buf[16];
  6867. nullpo_retv(sd);
  6868. WBUFW(buf,0)=0x10c;
  6869. WBUFL(buf,2)=sd->bl.id;
  6870. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6871. }
  6872. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6873. /// 010a <name id>.W
  6874. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6875. {
  6876. int view,fd;
  6877. nullpo_retv(sd);
  6878. fd=sd->fd;
  6879. WFIFOHEAD(fd,packet_len(0x10a));
  6880. WFIFOW(fd,0)=0x10a;
  6881. if((view = itemdb_viewid(nameid)) > 0)
  6882. WFIFOW(fd,2)=view;
  6883. else
  6884. WFIFOW(fd,2)=nameid;
  6885. WFIFOSET(fd,packet_len(0x10a));
  6886. }
  6887. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6888. /// 010b <exp>.L
  6889. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6890. {
  6891. int fd;
  6892. nullpo_retv(sd);
  6893. fd=sd->fd;
  6894. WFIFOHEAD(fd,packet_len(0x10b));
  6895. WFIFOW(fd,0)=0x10b;
  6896. WFIFOL(fd,2)=min(exp,(unsigned int)INT32_MAX);
  6897. WFIFOSET(fd,packet_len(0x10b));
  6898. }
  6899. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6900. /// 010d
  6901. ///
  6902. /// "You are the MVP, but cannot obtain the reward because
  6903. /// you are overweight."
  6904. void clif_mvp_noitem(struct map_session_data* sd)
  6905. {
  6906. int fd = sd->fd;
  6907. WFIFOHEAD(fd,packet_len(0x10d));
  6908. WFIFOW(fd,0) = 0x10d;
  6909. WFIFOSET(fd,packet_len(0x10d));
  6910. }
  6911. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6912. /// 0167 <result>.B
  6913. /// result:
  6914. /// 0 = "Guild has been created."
  6915. /// 1 = "You are already in a Guild."
  6916. /// 2 = "That Guild Name already exists."
  6917. /// 3 = "You need the neccessary item to create a Guild."
  6918. void clif_guild_created(struct map_session_data *sd,int flag)
  6919. {
  6920. int fd;
  6921. nullpo_retv(sd);
  6922. fd=sd->fd;
  6923. WFIFOHEAD(fd,packet_len(0x167));
  6924. WFIFOW(fd,0)=0x167;
  6925. WFIFOB(fd,2)=flag;
  6926. WFIFOSET(fd,packet_len(0x167));
  6927. }
  6928. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6929. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6930. /// mode:
  6931. /// &0x01 = allow invite
  6932. /// &0x10 = allow expel
  6933. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6934. {
  6935. int ps,fd;
  6936. nullpo_retv(sd);
  6937. nullpo_retv(g);
  6938. fd=sd->fd;
  6939. ps=guild_getposition(g,sd);
  6940. WFIFOHEAD(fd,packet_len(0x16c));
  6941. WFIFOW(fd,0)=0x16c;
  6942. WFIFOL(fd,2)=g->guild_id;
  6943. WFIFOL(fd,6)=g->emblem_id;
  6944. WFIFOL(fd,10)=g->position[ps].mode;
  6945. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6946. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6947. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6948. WFIFOSET(fd,packet_len(0x16c));
  6949. }
  6950. /// Guild member login notice.
  6951. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6952. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6953. /// status:
  6954. /// 0 = offline
  6955. /// 1 = online
  6956. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6957. {
  6958. unsigned char buf[64];
  6959. struct map_session_data* sd;
  6960. nullpo_retv(g);
  6961. WBUFW(buf, 0)=0x1f2;
  6962. WBUFL(buf, 2)=g->member[idx].account_id;
  6963. WBUFL(buf, 6)=g->member[idx].char_id;
  6964. WBUFL(buf,10)=flag;
  6965. if( ( sd = g->member[idx].sd ) != NULL )
  6966. {
  6967. WBUFW(buf,14) = sd->status.sex;
  6968. WBUFW(buf,16) = sd->status.hair;
  6969. WBUFW(buf,18) = sd->status.hair_color;
  6970. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6971. }
  6972. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6973. {
  6974. WBUFW(buf,14) = 0;
  6975. WBUFW(buf,16) = 0;
  6976. WBUFW(buf,18) = 0;
  6977. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6978. }
  6979. }
  6980. // Function `clif_guild_memberlogin_notice` sends info about
  6981. // logins and logouts of a guild member to the rest members.
  6982. // But at the 1st time (after a player login or map changing)
  6983. // the client won't show the message.
  6984. // So I suggest use this function for sending "first-time-info"
  6985. // to some player on entering the game or changing location.
  6986. // At next time the client would always show the message.
  6987. // The function sends all the statuses in the single packet
  6988. // to economize traffic. [LuzZza]
  6989. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6990. {
  6991. struct guild *g;
  6992. unsigned char buf[14*128];
  6993. int i, count=0, p_len;
  6994. nullpo_retv(sd);
  6995. p_len = packet_len(0x16d);
  6996. if(!(g = sd->guild))
  6997. return;
  6998. for(i=0; i<g->max_member; i++) {
  6999. if(g->member[i].account_id > 0 &&
  7000. g->member[i].account_id != sd->status.account_id) {
  7001. WBUFW(buf,count*p_len) = 0x16d;
  7002. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7003. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7004. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7005. count++;
  7006. }
  7007. }
  7008. clif_send(buf, p_len*count, &sd->bl, SELF);
  7009. }
  7010. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7011. /// 014e <menu flag>.L
  7012. /// menu flag:
  7013. /// 0x00 = Basic Info (always on)
  7014. /// &0x01 = Member manager
  7015. /// &0x02 = Positions
  7016. /// &0x04 = Skills
  7017. /// &0x10 = Expulsion list
  7018. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7019. /// &0x80 = Notice
  7020. void clif_guild_masterormember(struct map_session_data *sd)
  7021. {
  7022. int fd;
  7023. nullpo_retv(sd);
  7024. fd=sd->fd;
  7025. WFIFOHEAD(fd,packet_len(0x14e));
  7026. WFIFOW(fd,0) = 0x14e;
  7027. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7028. WFIFOSET(fd,packet_len(0x14e));
  7029. }
  7030. /// Guild basic information (Territories [Valaris])
  7031. /// 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)
  7032. /// 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)
  7033. void clif_guild_basicinfo(struct map_session_data *sd) {
  7034. int fd;
  7035. struct guild *g;
  7036. nullpo_retv(sd);
  7037. fd = sd->fd;
  7038. if( (g = sd->guild) == NULL )
  7039. return;
  7040. WFIFOHEAD(fd,packet_len(0x1b6));
  7041. WFIFOW(fd, 0)=0x1b6;//0x150;
  7042. WFIFOL(fd, 2)=g->guild_id;
  7043. WFIFOL(fd, 6)=g->guild_lv;
  7044. WFIFOL(fd,10)=g->connect_member;
  7045. WFIFOL(fd,14)=g->max_member;
  7046. WFIFOL(fd,18)=g->average_lv;
  7047. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7048. WFIFOL(fd,26)=g->next_exp;
  7049. WFIFOL(fd,30)=0; // Tax Points
  7050. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7051. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7052. WFIFOL(fd,42)=g->emblem_id;
  7053. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  7054. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  7055. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7056. WFIFOL(fd,110) = 0; // zeny
  7057. WFIFOSET(fd,packet_len(0x1b6));
  7058. }
  7059. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7060. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7061. void clif_guild_allianceinfo(struct map_session_data *sd)
  7062. {
  7063. int fd,i,c;
  7064. struct guild *g;
  7065. nullpo_retv(sd);
  7066. if( (g = sd->guild) == NULL )
  7067. return;
  7068. fd = sd->fd;
  7069. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7070. WFIFOW(fd, 0)=0x14c;
  7071. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7072. struct guild_alliance *a=&g->alliance[i];
  7073. if(a->guild_id>0){
  7074. WFIFOL(fd,c*32+4)=a->opposition;
  7075. WFIFOL(fd,c*32+8)=a->guild_id;
  7076. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  7077. c++;
  7078. }
  7079. }
  7080. WFIFOW(fd, 2)=c*32+4;
  7081. WFIFOSET(fd,WFIFOW(fd,2));
  7082. }
  7083. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  7084. /// 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 }*
  7085. /// state:
  7086. /// 0 = offline
  7087. /// 1 = online
  7088. /// memo:
  7089. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7090. void clif_guild_memberlist(struct map_session_data *sd)
  7091. {
  7092. int fd;
  7093. int i,c;
  7094. struct guild *g;
  7095. nullpo_retv(sd);
  7096. if( (fd = sd->fd) == 0 )
  7097. return;
  7098. if( (g = sd->guild) == NULL )
  7099. return;
  7100. WFIFOHEAD(fd, g->max_member * 104 + 4);
  7101. WFIFOW(fd, 0)=0x154;
  7102. for(i=0,c=0;i<g->max_member;i++){
  7103. struct guild_member *m=&g->member[i];
  7104. if(m->account_id==0)
  7105. continue;
  7106. WFIFOL(fd,c*104+ 4)=m->account_id;
  7107. WFIFOL(fd,c*104+ 8)=m->char_id;
  7108. WFIFOW(fd,c*104+12)=m->hair;
  7109. WFIFOW(fd,c*104+14)=m->hair_color;
  7110. WFIFOW(fd,c*104+16)=m->gender;
  7111. WFIFOW(fd,c*104+18)=m->class_;
  7112. WFIFOW(fd,c*104+20)=m->lv;
  7113. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7114. WFIFOL(fd,c*104+26)=m->online;
  7115. WFIFOL(fd,c*104+30)=m->position;
  7116. 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.
  7117. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  7118. c++;
  7119. }
  7120. WFIFOW(fd, 2)=c*104+4;
  7121. WFIFOSET(fd,WFIFOW(fd,2));
  7122. }
  7123. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7124. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7125. void clif_guild_positionnamelist(struct map_session_data *sd)
  7126. {
  7127. int i,fd;
  7128. struct guild *g;
  7129. nullpo_retv(sd);
  7130. if( (g = sd->guild) == NULL )
  7131. return;
  7132. fd = sd->fd;
  7133. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7134. WFIFOW(fd, 0)=0x166;
  7135. for(i=0;i<MAX_GUILDPOSITION;i++){
  7136. WFIFOL(fd,i*28+4)=i;
  7137. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7138. }
  7139. WFIFOW(fd,2)=i*28+4;
  7140. WFIFOSET(fd,WFIFOW(fd,2));
  7141. }
  7142. /// Guild position information (ZC_POSITION_INFO).
  7143. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7144. /// mode:
  7145. /// &0x01 = allow invite
  7146. /// &0x10 = allow expel
  7147. /// ranking:
  7148. /// TODO
  7149. void clif_guild_positioninfolist(struct map_session_data *sd)
  7150. {
  7151. int i,fd;
  7152. struct guild *g;
  7153. nullpo_retv(sd);
  7154. if( (g = sd->guild) == NULL )
  7155. return;
  7156. fd = sd->fd;
  7157. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7158. WFIFOW(fd, 0)=0x160;
  7159. for(i=0;i<MAX_GUILDPOSITION;i++){
  7160. struct guild_position *p=&g->position[i];
  7161. WFIFOL(fd,i*16+ 4)=i;
  7162. WFIFOL(fd,i*16+ 8)=p->mode;
  7163. WFIFOL(fd,i*16+12)=i;
  7164. WFIFOL(fd,i*16+16)=p->exp_mode;
  7165. }
  7166. WFIFOW(fd, 2)=i*16+4;
  7167. WFIFOSET(fd,WFIFOW(fd,2));
  7168. }
  7169. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7170. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7171. /// mode:
  7172. /// &0x01 = allow invite
  7173. /// &0x10 = allow expel
  7174. /// ranking:
  7175. /// TODO
  7176. void clif_guild_positionchanged(struct guild *g,int idx)
  7177. {
  7178. // FIXME: This packet is intended to update the clients after a
  7179. // commit of position info changes, not sending one packet per
  7180. // position.
  7181. struct map_session_data *sd;
  7182. unsigned char buf[128];
  7183. nullpo_retv(g);
  7184. WBUFW(buf, 0)=0x174;
  7185. WBUFW(buf, 2)=44; // packet len
  7186. // GUILD_REG_POSITION_INFO{
  7187. WBUFL(buf, 4)=idx;
  7188. WBUFL(buf, 8)=g->position[idx].mode;
  7189. WBUFL(buf,12)=idx;
  7190. WBUFL(buf,16)=g->position[idx].exp_mode;
  7191. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  7192. // }*
  7193. if( (sd=guild_getavailablesd(g))!=NULL )
  7194. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7195. }
  7196. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7197. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7198. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7199. {
  7200. // FIXME: This packet is intended to update the clients after a
  7201. // commit of member position assignment changes, not sending one
  7202. // packet per position.
  7203. struct map_session_data *sd;
  7204. unsigned char buf[64];
  7205. nullpo_retv(g);
  7206. WBUFW(buf, 0)=0x156;
  7207. WBUFW(buf, 2)=16; // packet len
  7208. // MEMBER_POSITION_INFO{
  7209. WBUFL(buf, 4)=g->member[idx].account_id;
  7210. WBUFL(buf, 8)=g->member[idx].char_id;
  7211. WBUFL(buf,12)=g->member[idx].position;
  7212. // }*
  7213. if( (sd=guild_getavailablesd(g))!=NULL )
  7214. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7215. }
  7216. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7217. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7218. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7219. {
  7220. int fd;
  7221. nullpo_retv(sd);
  7222. nullpo_retv(g);
  7223. fd = sd->fd;
  7224. if( g->emblem_len <= 0 )
  7225. return;
  7226. WFIFOHEAD(fd,g->emblem_len+12);
  7227. WFIFOW(fd,0)=0x152;
  7228. WFIFOW(fd,2)=g->emblem_len+12;
  7229. WFIFOL(fd,4)=g->guild_id;
  7230. WFIFOL(fd,8)=g->emblem_id;
  7231. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7232. WFIFOSET(fd,WFIFOW(fd,2));
  7233. }
  7234. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7235. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7236. void clif_guild_emblem_area(struct block_list* bl)
  7237. {
  7238. uint8 buf[12];
  7239. nullpo_retv(bl);
  7240. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7241. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7242. WBUFW(buf,0) = 0x1b4;
  7243. WBUFL(buf,2) = bl->id;
  7244. WBUFL(buf,6) = status_get_guild_id(bl);
  7245. WBUFW(buf,10) = status_get_emblem_id(bl);
  7246. clif_send(buf, 12, bl, AREA_WOS);
  7247. }
  7248. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7249. /// 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 }*
  7250. void clif_guild_skillinfo(struct map_session_data* sd)
  7251. {
  7252. int fd;
  7253. struct guild* g;
  7254. int i,c;
  7255. nullpo_retv(sd);
  7256. if( (g = sd->guild) == NULL )
  7257. return;
  7258. fd = sd->fd;
  7259. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7260. WFIFOW(fd,0) = 0x0162;
  7261. WFIFOW(fd,4) = g->skill_point;
  7262. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7263. {
  7264. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7265. {
  7266. int id = g->skill[i].id;
  7267. int p = 6 + c*37;
  7268. WFIFOW(fd,p+0) = id;
  7269. WFIFOL(fd,p+2) = skill_get_inf(id);
  7270. WFIFOW(fd,p+6) = g->skill[i].lv;
  7271. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7272. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7273. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7274. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7275. c++;
  7276. }
  7277. }
  7278. WFIFOW(fd,2) = 6 + c*37;
  7279. WFIFOSET(fd,WFIFOW(fd,2));
  7280. }
  7281. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7282. /// 016f <subject>.60B <notice>.120B
  7283. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  7284. {
  7285. int fd;
  7286. nullpo_retv(sd);
  7287. nullpo_retv(g);
  7288. fd = sd->fd;
  7289. if ( !session_isActive(fd) )
  7290. return;
  7291. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7292. return;
  7293. WFIFOHEAD(fd,packet_len(0x16f));
  7294. WFIFOW(fd,0) = 0x16f;
  7295. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7296. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7297. WFIFOSET(fd,packet_len(0x16f));
  7298. }
  7299. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7300. /// 016a <guild id>.L <guild name>.24B
  7301. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7302. {
  7303. int fd;
  7304. nullpo_retv(sd);
  7305. nullpo_retv(g);
  7306. fd=sd->fd;
  7307. WFIFOHEAD(fd,packet_len(0x16a));
  7308. WFIFOW(fd,0)=0x16a;
  7309. WFIFOL(fd,2)=g->guild_id;
  7310. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  7311. WFIFOSET(fd,packet_len(0x16a));
  7312. }
  7313. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7314. /// 0169 <answer>.B
  7315. /// answer:
  7316. /// 0 = Already in guild.
  7317. /// 1 = Offer rejected.
  7318. /// 2 = Offer accepted.
  7319. /// 3 = Guild full.
  7320. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7321. {
  7322. int fd;
  7323. nullpo_retv(sd);
  7324. fd=sd->fd;
  7325. WFIFOHEAD(fd,packet_len(0x169));
  7326. WFIFOW(fd,0)=0x169;
  7327. WFIFOB(fd,2)=flag;
  7328. WFIFOSET(fd,packet_len(0x169));
  7329. }
  7330. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7331. /// 015a <char name>.24B <reason>.40B
  7332. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7333. {
  7334. unsigned char buf[128];
  7335. nullpo_retv(sd);
  7336. WBUFW(buf, 0)=0x15a;
  7337. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  7338. memcpy(WBUFP(buf,26),mes,40);
  7339. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7340. }
  7341. /// Notifies clients of a guild of an expelled member.
  7342. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7343. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7344. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7345. {
  7346. unsigned char buf[128];
  7347. #if PACKETVER < 20100803
  7348. const unsigned short cmd = 0x15c;
  7349. #else
  7350. const unsigned short cmd = 0x839;
  7351. #endif
  7352. nullpo_retv(sd);
  7353. WBUFW(buf,0) = cmd;
  7354. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7355. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7356. #if PACKETVER < 20100803
  7357. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7358. #endif
  7359. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7360. }
  7361. /// Guild expulsion list (ZC_BAN_LIST).
  7362. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7363. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7364. void clif_guild_expulsionlist(struct map_session_data* sd)
  7365. {
  7366. #if PACKETVER < 20100803
  7367. const int offset = NAME_LENGTH*2+40;
  7368. #else
  7369. const int offset = NAME_LENGTH+40;
  7370. #endif
  7371. int fd, i, c = 0;
  7372. struct guild* g;
  7373. nullpo_retv(sd);
  7374. if( (g = sd->guild) == NULL )
  7375. return;
  7376. fd = sd->fd;
  7377. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7378. WFIFOW(fd,0) = 0x163;
  7379. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7380. {
  7381. struct guild_expulsion* e = &g->expulsion[i];
  7382. if( e->account_id > 0 )
  7383. {
  7384. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7385. #if PACKETVER < 20100803
  7386. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7387. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7388. #else
  7389. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7390. #endif
  7391. c++;
  7392. }
  7393. }
  7394. WFIFOW(fd,2) = 4 + c*offset;
  7395. WFIFOSET(fd,WFIFOW(fd,2));
  7396. }
  7397. /// Guild chat message (ZC_GUILD_CHAT).
  7398. /// 017f <packet len>.W <message>.?B
  7399. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7400. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7401. struct map_session_data *sd;
  7402. uint8 buf[256];
  7403. if( len == 0 )
  7404. {
  7405. return;
  7406. }
  7407. else if( len > sizeof(buf)-5 )
  7408. {
  7409. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7410. len = sizeof(buf)-5;
  7411. }
  7412. WBUFW(buf, 0) = 0x17f;
  7413. WBUFW(buf, 2) = len + 5;
  7414. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7415. if ((sd = guild_getavailablesd(g)) != NULL)
  7416. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7417. }
  7418. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7419. /// 0171 <inviter account id>.L <guild name>.24B
  7420. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7421. {
  7422. int fd;
  7423. nullpo_retv(sd);
  7424. fd=sd->fd;
  7425. WFIFOHEAD(fd,packet_len(0x171));
  7426. WFIFOW(fd,0)=0x171;
  7427. WFIFOL(fd,2)=account_id;
  7428. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7429. WFIFOSET(fd,packet_len(0x171));
  7430. }
  7431. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7432. /// 0173 <answer>.B
  7433. /// answer:
  7434. /// 0 = Already allied.
  7435. /// 1 = You rejected the offer.
  7436. /// 2 = You accepted the offer.
  7437. /// 3 = They have too any alliances.
  7438. /// 4 = You have too many alliances.
  7439. /// 5 = Alliances are disabled.
  7440. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7441. {
  7442. int fd;
  7443. nullpo_retv(sd);
  7444. fd=sd->fd;
  7445. WFIFOHEAD(fd,packet_len(0x173));
  7446. WFIFOW(fd,0)=0x173;
  7447. WFIFOL(fd,2)=flag;
  7448. WFIFOSET(fd,packet_len(0x173));
  7449. }
  7450. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7451. /// 0184 <other guild id>.L <relation>.L
  7452. /// relation:
  7453. /// 0 = Ally
  7454. /// 1 = Enemy
  7455. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7456. {
  7457. int fd;
  7458. nullpo_retv(sd);
  7459. fd = sd->fd;
  7460. if (fd <= 0)
  7461. return;
  7462. WFIFOHEAD(fd,packet_len(0x184));
  7463. WFIFOW(fd,0)=0x184;
  7464. WFIFOL(fd,2)=guild_id;
  7465. WFIFOL(fd,6)=flag;
  7466. WFIFOSET(fd,packet_len(0x184));
  7467. }
  7468. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7469. /// 0181 <result>.B
  7470. /// result:
  7471. /// 0 = Antagonist has been set.
  7472. /// 1 = Guild has too many Antagonists.
  7473. /// 2 = Already set as an Antagonist.
  7474. /// 3 = Antagonists are disabled.
  7475. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7476. {
  7477. int fd;
  7478. nullpo_retv(sd);
  7479. fd=sd->fd;
  7480. WFIFOHEAD(fd,packet_len(0x181));
  7481. WFIFOW(fd,0)=0x181;
  7482. WFIFOB(fd,2)=flag;
  7483. WFIFOSET(fd,packet_len(0x181));
  7484. }
  7485. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7486. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7487. /*
  7488. void clif_guild_allianceadded(struct guild *g,int idx)
  7489. {
  7490. unsigned char buf[64];
  7491. WBUFW(buf,0)=0x185;
  7492. WBUFL(buf,2)=g->alliance[idx].opposition;
  7493. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7494. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7495. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7496. }
  7497. */
  7498. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7499. /// 015e <reason>.L
  7500. /// 0 = success
  7501. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7502. /// 2 = there are still members in the guild
  7503. void clif_guild_broken(struct map_session_data *sd,int flag)
  7504. {
  7505. int fd;
  7506. nullpo_retv(sd);
  7507. fd=sd->fd;
  7508. WFIFOHEAD(fd,packet_len(0x15e));
  7509. WFIFOW(fd,0)=0x15e;
  7510. WFIFOL(fd,2)=flag;
  7511. WFIFOSET(fd,packet_len(0x15e));
  7512. }
  7513. /// Displays emotion on an object (ZC_EMOTION).
  7514. /// 00c0 <id>.L <type>.B
  7515. /// type:
  7516. /// enum emotion_type
  7517. void clif_emotion(struct block_list *bl,int type)
  7518. {
  7519. unsigned char buf[8];
  7520. nullpo_retv(bl);
  7521. WBUFW(buf,0)=0xc0;
  7522. WBUFL(buf,2)=bl->id;
  7523. WBUFB(buf,6)=type;
  7524. clif_send(buf,packet_len(0xc0),bl,AREA);
  7525. }
  7526. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7527. /// 0191 <id>.L <contents>.80B
  7528. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7529. {
  7530. unsigned char buf[MESSAGE_SIZE+6];
  7531. nullpo_retv(bl);
  7532. WBUFW(buf,0) = 0x191;
  7533. WBUFL(buf,2) = bl->id;
  7534. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7535. clif_send(buf,packet_len(0x191),bl,AREA);
  7536. }
  7537. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7538. /// 01ea <id>.L
  7539. void clif_wedding_effect(struct block_list *bl)
  7540. {
  7541. unsigned char buf[6];
  7542. nullpo_retv(bl);
  7543. WBUFW(buf,0) = 0x1ea;
  7544. WBUFL(buf,2) = bl->id;
  7545. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7546. }
  7547. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7548. /// 01e6 <partner name>.24B
  7549. void clif_callpartner(struct map_session_data *sd)
  7550. {
  7551. unsigned char buf[26];
  7552. nullpo_retv(sd);
  7553. WBUFW(buf,0) = 0x1e6;
  7554. if( sd->status.partner_id ) {
  7555. const char *p = map_charid2nick(sd->status.partner_id);
  7556. struct map_session_data *p_sd = pc_get_partner(sd);
  7557. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7558. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7559. else
  7560. WBUFB(buf,2) = 0;
  7561. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7562. WBUFB(buf,2) = 0;
  7563. }
  7564. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7565. }
  7566. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7567. /// 01e4
  7568. /// This packet while still implemented by the client is no longer being officially used.
  7569. /*
  7570. void clif_marriage_process(struct map_session_data *sd)
  7571. {
  7572. int fd;
  7573. nullpo_retv(sd);
  7574. fd=sd->fd;
  7575. WFIFOHEAD(fd,packet_len(0x1e4));
  7576. WFIFOW(fd,0)=0x1e4;
  7577. WFIFOSET(fd,packet_len(0x1e4));
  7578. }
  7579. */
  7580. /// Notice of divorce (ZC_DIVORCE).
  7581. /// 0205 <partner name>.24B
  7582. void clif_divorced(struct map_session_data* sd, const char* name)
  7583. {
  7584. int fd;
  7585. nullpo_retv(sd);
  7586. fd=sd->fd;
  7587. WFIFOHEAD(fd,packet_len(0x205));
  7588. WFIFOW(fd,0)=0x205;
  7589. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7590. WFIFOSET(fd, packet_len(0x205));
  7591. }
  7592. /// Marriage proposal (ZC_REQ_COUPLE).
  7593. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7594. /// This packet while still implemented by the client is no longer being officially used.
  7595. /*
  7596. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7597. {
  7598. nullpo_retv(sd);
  7599. WFIFOHEAD(fd,packet_len(0x1e2));
  7600. WFIFOW(fd,0) = 0x1e2;
  7601. WFIFOL(fd,2) = ssd->status.account_id;
  7602. WFIFOL(fd,6) = ssd->status.char_id;
  7603. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7604. WFIFOSET(fd, packet_len(0x1e2));
  7605. }
  7606. */
  7607. /*==========================================
  7608. *
  7609. *------------------------------------------*/
  7610. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7611. {
  7612. clif_disp_message(&sd->bl, mes, len, SELF);
  7613. }
  7614. /*==========================================
  7615. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7616. *------------------------------------------*/
  7617. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7618. {
  7619. unsigned char buf[256];
  7620. if( len == 0 ) {
  7621. return;
  7622. } else if( len > sizeof(buf)-5 ) {
  7623. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7624. len = sizeof(buf)-5;
  7625. }
  7626. WBUFW(buf, 0) = 0x17f;
  7627. WBUFW(buf, 2) = len + 5;
  7628. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7629. clif_send(buf, WBUFW(buf,2), src, target);
  7630. }
  7631. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7632. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7633. /// 00cd <result>.B
  7634. /// result:
  7635. /// 0 = failure
  7636. /// 1 = success
  7637. void clif_GM_kickack(struct map_session_data *sd, int id)
  7638. {
  7639. int fd;
  7640. nullpo_retv(sd);
  7641. fd = sd->fd;
  7642. WFIFOHEAD(fd,packet_len(0xcd));
  7643. WFIFOW(fd,0) = 0xcd;
  7644. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7645. WFIFOSET(fd, packet_len(0xcd));
  7646. }
  7647. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7648. {
  7649. int fd = tsd->fd;
  7650. if( fd > 0 )
  7651. clif_authfail_fd(fd, 15);
  7652. else {
  7653. // Close vending/buyingstore
  7654. if (sd) {
  7655. if (tsd->state.vending)
  7656. vending_closevending(tsd);
  7657. else if (tsd->state.buyingstore)
  7658. buyingstore_close(tsd);
  7659. }
  7660. map_quit(tsd);
  7661. }
  7662. if( sd )
  7663. clif_GM_kickack(sd,tsd->status.account_id);
  7664. }
  7665. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7666. /// 014a <result>.L
  7667. /// result:
  7668. /// 0 = "A manner point has been successfully aligned."
  7669. /// 1 = MP_FAILURE_EXHAUST
  7670. /// 2 = MP_FAILURE_ALREADY_GIVING
  7671. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7672. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7673. /// 5 = "You got a good point from %s."
  7674. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7675. {
  7676. int fd;
  7677. nullpo_retv(sd);
  7678. fd = sd->fd;
  7679. WFIFOHEAD(fd,packet_len(0x14a));
  7680. WFIFOW(fd,0) = 0x14a;
  7681. WFIFOL(fd,2) = type;
  7682. WFIFOSET(fd, packet_len(0x14a));
  7683. }
  7684. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7685. /// 014b <type>.B <GM name>.24B
  7686. /// type:
  7687. /// 0 = positive (unmute)
  7688. /// 1 = negative (mute)
  7689. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7690. {
  7691. int fd;
  7692. nullpo_retv(sd);
  7693. nullpo_retv(tsd);
  7694. fd = tsd->fd;
  7695. WFIFOHEAD(fd,packet_len(0x14b));
  7696. WFIFOW(fd,0) = 0x14b;
  7697. WFIFOB(fd,2) = type;
  7698. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7699. WFIFOSET(fd, packet_len(0x14b));
  7700. }
  7701. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7702. /// 00d1 <type>.B <result>.B
  7703. /// type:
  7704. /// 0 = /ex (deny)
  7705. /// 1 = /in (allow)
  7706. /// result:
  7707. /// 0 = success
  7708. /// 1 = failure
  7709. /// 2 = too many blocks
  7710. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7711. {
  7712. int fd;
  7713. nullpo_retv(sd);
  7714. fd=sd->fd;
  7715. WFIFOHEAD(fd,packet_len(0xd1));
  7716. WFIFOW(fd,0)=0xd1;
  7717. WFIFOB(fd,2)=type;
  7718. WFIFOB(fd,3)=flag;
  7719. WFIFOSET(fd,packet_len(0xd1));
  7720. }
  7721. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7722. /// 00d2 <type>.B <result>.B
  7723. /// type:
  7724. /// 0 = /exall (deny)
  7725. /// 1 = /inall (allow)
  7726. /// result:
  7727. /// 0 = success
  7728. /// 1 = failure
  7729. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7730. {
  7731. int fd;
  7732. nullpo_retv(sd);
  7733. fd=sd->fd;
  7734. WFIFOHEAD(fd,packet_len(0xd2));
  7735. WFIFOW(fd,0)=0xd2;
  7736. WFIFOB(fd,2)=type;
  7737. WFIFOB(fd,3)=flag;
  7738. WFIFOSET(fd,packet_len(0xd2));
  7739. }
  7740. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7741. /// 07fe <bgm>.24B
  7742. void clif_playBGM(struct map_session_data* sd, const char* name)
  7743. {
  7744. int fd;
  7745. nullpo_retv(sd);
  7746. fd = sd->fd;
  7747. WFIFOHEAD(fd,packet_len(0x7fe));
  7748. WFIFOW(fd,0) = 0x7fe;
  7749. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7750. WFIFOSET(fd,packet_len(0x7fe));
  7751. }
  7752. /// Plays/stops a wave sound (ZC_SOUND).
  7753. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7754. /// file name:
  7755. /// relative to data\wav
  7756. /// act:
  7757. /// 0 = play (once)
  7758. /// 1 = play (repeat, does not work)
  7759. /// 2 = stops all sound instances of file name (does not work)
  7760. /// term:
  7761. /// unknown purpose, only relevant to act = 1
  7762. /// npc id:
  7763. /// The accustic direction of the sound is determined by the
  7764. /// relative position of the NPC to the player (3D sound).
  7765. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7766. {
  7767. int fd;
  7768. nullpo_retv(sd);
  7769. nullpo_retv(bl);
  7770. fd = sd->fd;
  7771. WFIFOHEAD(fd,packet_len(0x1d3));
  7772. WFIFOW(fd,0) = 0x1d3;
  7773. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7774. WFIFOB(fd,26) = type;
  7775. WFIFOL(fd,27) = 0;
  7776. WFIFOL(fd,31) = bl->id;
  7777. WFIFOSET(fd,packet_len(0x1d3));
  7778. }
  7779. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7780. {
  7781. unsigned char buf[40];
  7782. nullpo_retv(bl);
  7783. WBUFW(buf,0) = 0x1d3;
  7784. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7785. WBUFB(buf,26) = type;
  7786. WBUFL(buf,27) = 0;
  7787. WBUFL(buf,31) = bl->id;
  7788. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7789. }
  7790. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7791. /// 01f3 <id>.L <effect id>.L
  7792. /// effect id:
  7793. /// @see doc/effect_list.txt
  7794. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7795. {
  7796. unsigned char buf[24];
  7797. nullpo_retv(bl);
  7798. memset(buf, 0, packet_len(0x1f3));
  7799. WBUFW(buf,0) = 0x1f3;
  7800. WBUFL(buf,2) = bl->id;
  7801. WBUFL(buf,6) = type;
  7802. clif_send(buf, packet_len(0x1f3), bl, target);
  7803. if (disguised(bl)) {
  7804. WBUFL(buf,2) = -bl->id;
  7805. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7806. }
  7807. }
  7808. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7809. {
  7810. WFIFOHEAD(fd,10);
  7811. WFIFOW(fd,0) = 0x1f3;
  7812. WFIFOL(fd,2) = bl->id;
  7813. WFIFOL(fd,6) = type;
  7814. WFIFOSET(fd,10);
  7815. }
  7816. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7817. /// 0284 <id>.L <effect id>.L <num data>.L
  7818. /// effect id:
  7819. /// @see doc/effect_list.txt
  7820. /// num data:
  7821. /// effect-dependent value
  7822. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7823. {
  7824. uint8 buf[14];
  7825. WBUFW(buf,0) = 0x284;
  7826. WBUFL(buf,2) = bl->id;
  7827. WBUFL(buf,6) = effect_id;
  7828. WBUFL(buf,10) = num;
  7829. clif_send(buf, packet_len(0x284), bl, target);
  7830. if( disguised(bl) )
  7831. {
  7832. WBUFL(buf,2) = -bl->id;
  7833. clif_send(buf, packet_len(0x284), bl, SELF);
  7834. }
  7835. }
  7836. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7837. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7838. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7839. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7840. WFIFOHEAD(fd,msg_len + 12);
  7841. WFIFOW(fd,0) = 0x2C1;
  7842. WFIFOW(fd,2) = msg_len + 12;
  7843. WFIFOL(fd,4) = 0;
  7844. WFIFOL(fd,8) = color; //either color_table or channel_table
  7845. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7846. WFIFOSET(fd, msg_len + 12);
  7847. return 0;
  7848. }
  7849. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7850. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7851. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7852. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7853. uint8 buf[256];
  7854. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7855. nullpo_retv(bl);
  7856. if( msg_len > sizeof(buf)-12 ) {
  7857. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7858. msg_len = sizeof(buf)-12;
  7859. }
  7860. WBUFW(buf,0) = 0x2C1;
  7861. WBUFW(buf,2) = msg_len + 12;
  7862. WBUFL(buf,4) = bl->id;
  7863. WBUFL(buf,8) = color;
  7864. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7865. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7866. }
  7867. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7868. {
  7869. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7870. nullpo_retv(sd);
  7871. if(msg_len > 0) {
  7872. int fd;
  7873. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7874. fd = sd->fd;
  7875. WFIFOHEAD(fd, msg_len+12);
  7876. WFIFOW(fd,0) = 0x2C1;
  7877. WFIFOW(fd,2) = msg_len+12;
  7878. WFIFOL(fd,4) = 0;
  7879. WFIFOL(fd,8) = color;
  7880. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7881. WFIFOSET(fd, WFIFOW(fd,2));
  7882. }
  7883. }
  7884. /**
  7885. * Notifies the client that the storage window is still open
  7886. *
  7887. * Should only be used in cases where the client closed the
  7888. * storage window without server's consent
  7889. */
  7890. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7891. // Notify the client that the storage is open
  7892. if( sd->state.storage_flag == 1 ) {
  7893. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7894. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7895. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7896. }
  7897. // Notify the client that the gstorage is open otherwise it will
  7898. // remain locked forever and nobody will be able to access it
  7899. if( sd->state.storage_flag == 2 ) {
  7900. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7901. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7902. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7903. else {
  7904. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7905. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7906. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7907. }
  7908. }
  7909. }
  7910. // refresh the client's screen, getting rid of any effects
  7911. void clif_refresh(struct map_session_data *sd)
  7912. {
  7913. nullpo_retv(sd);
  7914. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7915. clif_inventorylist(sd);
  7916. if(pc_iscarton(sd)) {
  7917. clif_cartlist(sd);
  7918. clif_updatestatus(sd,SP_CARTINFO);
  7919. }
  7920. clif_updatestatus(sd,SP_WEIGHT);
  7921. clif_updatestatus(sd,SP_MAXWEIGHT);
  7922. clif_updatestatus(sd,SP_STR);
  7923. clif_updatestatus(sd,SP_AGI);
  7924. clif_updatestatus(sd,SP_VIT);
  7925. clif_updatestatus(sd,SP_INT);
  7926. clif_updatestatus(sd,SP_DEX);
  7927. clif_updatestatus(sd,SP_LUK);
  7928. if (sd->spiritball)
  7929. clif_spiritball_single(sd->fd, sd);
  7930. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7931. clif_spiritcharm_single(sd->fd, sd);
  7932. if (sd->vd.cloth_color)
  7933. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7934. if (sd->vd.body_style)
  7935. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7936. if(hom_is_active(sd->hd))
  7937. clif_send_homdata(sd,SP_ACK,0);
  7938. if( sd->md ) {
  7939. clif_mercenary_info(sd);
  7940. clif_mercenary_skillblock(sd);
  7941. }
  7942. if( sd->ed )
  7943. clif_elemental_info(sd);
  7944. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7945. clif_weather_check(sd);
  7946. if( sd->chatID )
  7947. chat_leavechat(sd,0);
  7948. if( sd->state.vending )
  7949. clif_openvending(sd, sd->bl.id, sd->vending);
  7950. if( pc_issit(sd) )
  7951. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7952. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7953. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7954. else
  7955. clif_changed_dir(&sd->bl, SELF);
  7956. // unlike vending, resuming buyingstore crashes the client.
  7957. buyingstore_close(sd);
  7958. mail_clear(sd);
  7959. if( disguised(&sd->bl) ) {/* refresh-da */
  7960. short disguise = sd->disguise;
  7961. pc_disguise(sd, 0);
  7962. pc_disguise(sd, disguise);
  7963. }
  7964. clif_refresh_storagewindow(sd);
  7965. }
  7966. /// Updates the object's (bl) name on client.
  7967. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7968. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7969. void clif_charnameack (int fd, struct block_list *bl)
  7970. {
  7971. unsigned char buf[103];
  7972. int cmd = 0x95;
  7973. nullpo_retv(bl);
  7974. WBUFW(buf,0) = cmd;
  7975. WBUFL(buf,2) = bl->id;
  7976. switch( bl->type )
  7977. {
  7978. case BL_PC:
  7979. {
  7980. struct map_session_data *ssd = (struct map_session_data *)bl;
  7981. struct party_data *p = NULL;
  7982. struct guild *g = NULL;
  7983. int ps = -1;
  7984. //Requesting your own "shadow" name. [Skotlex]
  7985. if (ssd->fd == fd && ssd->disguise)
  7986. WBUFL(buf,2) = -bl->id;
  7987. if( ssd->fakename[0] ) {
  7988. WBUFW(buf, 0) = cmd = 0x195;
  7989. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7990. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7991. break;
  7992. }
  7993. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7994. if( ssd->status.party_id ) {
  7995. p = party_search(ssd->status.party_id);
  7996. }
  7997. if( ssd->status.guild_id ) {
  7998. if( ( g = ssd->guild ) != NULL ) {
  7999. int i;
  8000. 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);
  8001. if( i < g->max_member ) ps = g->member[i].position;
  8002. }
  8003. }
  8004. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  8005. p = NULL;
  8006. }
  8007. if (p == NULL && g == NULL)
  8008. break;
  8009. WBUFW(buf, 0) = cmd = 0x195;
  8010. if (p)
  8011. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8012. else
  8013. WBUFB(buf,30) = 0;
  8014. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  8015. {
  8016. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  8017. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8018. } else { //Assume no guild.
  8019. WBUFB(buf,54) = 0;
  8020. WBUFB(buf,78) = 0;
  8021. }
  8022. }
  8023. break;
  8024. //[blackhole89]
  8025. case BL_HOM:
  8026. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8027. break;
  8028. case BL_MER:
  8029. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8030. break;
  8031. case BL_PET:
  8032. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8033. break;
  8034. case BL_NPC:
  8035. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8036. break;
  8037. case BL_MOB:
  8038. {
  8039. struct mob_data *md = (struct mob_data *)bl;
  8040. nullpo_retv(md);
  8041. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  8042. if( md->guardian_data && md->guardian_data->guild_id )
  8043. {
  8044. WBUFW(buf, 0) = cmd = 0x195;
  8045. WBUFB(buf,30) = 0;
  8046. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8047. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8048. }
  8049. else if( battle_config.show_mob_info )
  8050. {
  8051. char mobhp[50], *str_p = mobhp;
  8052. WBUFW(buf, 0) = cmd = 0x195;
  8053. if( battle_config.show_mob_info&4 )
  8054. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8055. if( battle_config.show_mob_info&1 )
  8056. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8057. if( battle_config.show_mob_info&2 )
  8058. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8059. //Even thought mobhp ain't a name, we send it as one so the client
  8060. //can parse it. [Skotlex]
  8061. if( str_p != mobhp )
  8062. {
  8063. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8064. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  8065. WBUFB(buf,54) = 0;
  8066. WBUFB(buf,78) = 0;
  8067. }
  8068. }
  8069. }
  8070. break;
  8071. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8072. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8073. // break;
  8074. return;
  8075. case BL_ELEM:
  8076. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8077. break;
  8078. default:
  8079. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  8080. return;
  8081. }
  8082. // if no receipient specified just update nearby clients
  8083. if (fd == 0)
  8084. clif_send(buf, packet_len(cmd), bl, AREA);
  8085. else {
  8086. WFIFOHEAD(fd, packet_len(cmd));
  8087. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  8088. WFIFOSET(fd, packet_len(cmd));
  8089. }
  8090. }
  8091. //Used to update when a char leaves a party/guild. [Skotlex]
  8092. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8093. void clif_charnameupdate (struct map_session_data *ssd)
  8094. {
  8095. unsigned char buf[103];
  8096. int cmd = 0x195, ps = -1;
  8097. struct party_data *p = NULL;
  8098. struct guild *g = NULL;
  8099. nullpo_retv(ssd);
  8100. if( ssd->fakename[0] )
  8101. return; //No need to update as the party/guild was not displayed anyway.
  8102. WBUFW(buf,0) = cmd;
  8103. WBUFL(buf,2) = ssd->bl.id;
  8104. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  8105. if (!battle_config.display_party_name) {
  8106. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  8107. p = party_search(ssd->status.party_id);
  8108. }else{
  8109. if (ssd->status.party_id > 0)
  8110. p = party_search(ssd->status.party_id);
  8111. }
  8112. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  8113. {
  8114. int i;
  8115. 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);
  8116. if( i < g->max_member ) ps = g->member[i].position;
  8117. }
  8118. if( p )
  8119. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8120. else
  8121. WBUFB(buf,30) = 0;
  8122. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  8123. {
  8124. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  8125. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8126. }
  8127. else
  8128. {
  8129. WBUFB(buf,54) = 0;
  8130. WBUFB(buf,78) = 0;
  8131. }
  8132. // Update nearby clients
  8133. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  8134. }
  8135. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8136. /// 01ff <id>.L <x>.W <y>.W
  8137. ///
  8138. /// Visually moves(instant) a character to x,y. The char moves even
  8139. /// when the target cell isn't walkable. If the char is sitting it
  8140. /// stays that way.
  8141. void clif_slide(struct block_list *bl, int x, int y)
  8142. {
  8143. unsigned char buf[10];
  8144. nullpo_retv(bl);
  8145. WBUFW(buf, 0) = 0x01ff;
  8146. WBUFL(buf, 2) = bl->id;
  8147. WBUFW(buf, 6) = x;
  8148. WBUFW(buf, 8) = y;
  8149. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8150. if( disguised(bl) )
  8151. {
  8152. WBUFL(buf,2) = -bl->id;
  8153. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8154. }
  8155. }
  8156. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8157. /// 008d <packet len>.W <id>.L <message>.?B
  8158. void clif_disp_overhead(struct block_list *bl, const char* mes)
  8159. {
  8160. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8161. int len_mes = strlen(mes)+1; //Account for \0
  8162. if (len_mes > sizeof(buf)-8) {
  8163. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8164. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8165. }
  8166. // send message to others
  8167. WBUFW(buf,0) = 0x8d;
  8168. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8169. WBUFL(buf,4) = bl->id;
  8170. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  8171. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8172. // send back message to the speaker
  8173. if( bl->type == BL_PC ) {
  8174. WBUFW(buf,0) = 0x8e;
  8175. WBUFW(buf, 2) = len_mes + 4;
  8176. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  8177. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8178. }
  8179. }
  8180. /*==========================
  8181. * Minimap fix [Kevin]
  8182. * Remove dot from minimap
  8183. *--------------------------*/
  8184. void clif_party_xy_remove(struct map_session_data *sd)
  8185. {
  8186. unsigned char buf[16];
  8187. nullpo_retv(sd);
  8188. WBUFW(buf,0)=0x107;
  8189. WBUFL(buf,2)=sd->status.account_id;
  8190. WBUFW(buf,6)=-1;
  8191. WBUFW(buf,8)=-1;
  8192. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8193. }
  8194. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8195. /// 0215 <msg id>.L
  8196. /// msg id:
  8197. /// 0x15 = End all negative status (PA_GOSPEL)
  8198. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8199. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8200. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8201. /// 0x19 = All stats +20 (PA_GOSPEL)
  8202. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8203. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8204. /// 0x1e = DEF +25% (PA_GOSPEL)
  8205. /// 0x1f = ATK +100% (PA_GOSPEL)
  8206. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8207. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8208. /// ? = nothing
  8209. void clif_gospel_info(struct map_session_data *sd, int type)
  8210. {
  8211. int fd=sd->fd;
  8212. WFIFOHEAD(fd,packet_len(0x215));
  8213. WFIFOW(fd,0)=0x215;
  8214. WFIFOL(fd,2)=type;
  8215. WFIFOSET(fd, packet_len(0x215));
  8216. }
  8217. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8218. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8219. /// result:
  8220. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8221. /// star:
  8222. /// 0 = Place of the Sun
  8223. /// 1 = Place of the Moon
  8224. /// 2 = Place of the Stars
  8225. /// 1 = Star Gladiator %s's %s: <mapname>
  8226. /// star:
  8227. /// 0 = Place of the Sun
  8228. /// 1 = Place of the Moon
  8229. /// 2 = Place of the Stars
  8230. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8231. /// star:
  8232. /// 0 = Target of the Sun
  8233. /// 1 = Target of the Moon
  8234. /// 2 = Target of the Stars
  8235. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8236. /// star:
  8237. /// 0 = Monster of the Sun
  8238. /// 1 = Monster of the Moon
  8239. /// 2 = Monster of the Stars
  8240. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8241. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8242. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8243. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8244. /// 40 = Target HP : <monster_id used as HP>
  8245. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8246. {
  8247. int fd = sd->fd;
  8248. WFIFOHEAD(fd,packet_len(0x20e));
  8249. WFIFOW(fd,0) = 0x20e;
  8250. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8251. WFIFOL(fd,26) = monster_id;
  8252. WFIFOB(fd,30) = star;
  8253. WFIFOB(fd,31) = result;
  8254. WFIFOSET(fd,packet_len(0x20e));
  8255. }
  8256. /*==========================================
  8257. * Info about Star Glaldiator save map [Komurka]
  8258. * type: 1: Information, 0: Map registered
  8259. *------------------------------------------*/
  8260. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8261. {
  8262. char mapname[MAP_NAME_LENGTH_EXT];
  8263. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8264. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8265. }
  8266. /*==========================================
  8267. * Info about Star Glaldiator hate mob [Komurka]
  8268. * type: 1: Register mob, 0: Information.
  8269. *------------------------------------------*/
  8270. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8271. {
  8272. if( pcdb_checkid(class_) ) {
  8273. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8274. } else if( mobdb_checkid(class_) ) {
  8275. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8276. } else {
  8277. 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);
  8278. }
  8279. }
  8280. /*==========================================
  8281. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8282. *------------------------------------------*/
  8283. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8284. {
  8285. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8286. }
  8287. /*==========================================
  8288. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8289. *------------------------------------------*/
  8290. void clif_feel_hate_reset(struct map_session_data *sd)
  8291. {
  8292. clif_starskill(sd, "", 0, 0, 30);
  8293. }
  8294. /// Equip window (un)tick ack (ZC_CONFIG).
  8295. /// 02d9 <type>.L <value>.L
  8296. /// type:
  8297. /// 0 = open equip window
  8298. /// value:
  8299. /// 0 = disabled
  8300. /// 1 = enabled
  8301. void clif_equiptickack(struct map_session_data* sd, int flag)
  8302. {
  8303. int fd;
  8304. nullpo_retv(sd);
  8305. fd = sd->fd;
  8306. WFIFOHEAD(fd, packet_len(0x2d9));
  8307. WFIFOW(fd, 0) = 0x2d9;
  8308. WFIFOL(fd, 2) = 0;
  8309. WFIFOL(fd, 6) = flag;
  8310. WFIFOSET(fd, packet_len(0x2d9));
  8311. }
  8312. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8313. /// 02da <open equip window>.B
  8314. /// open equip window:
  8315. /// 0 = disabled
  8316. /// 1 = enabled
  8317. void clif_equipcheckbox(struct map_session_data* sd)
  8318. {
  8319. int fd;
  8320. nullpo_retv(sd);
  8321. fd = sd->fd;
  8322. WFIFOHEAD(fd, packet_len(0x2da));
  8323. WFIFOW(fd, 0) = 0x2da;
  8324. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8325. WFIFOSET(fd, packet_len(0x2da));
  8326. }
  8327. /// Sends info about a player's equipped items.
  8328. /// 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)
  8329. /// 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)
  8330. /// 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)
  8331. /// 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)
  8332. /// 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)
  8333. /// 0a2d <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}.57B* (ZC_EQUIPWIN_MICROSCOPE_V6, PACKETVER >= 20150226)
  8334. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8335. {
  8336. uint8* buf;
  8337. int i, n, fd, offset = 0;
  8338. #if PACKETVER < 20100629
  8339. const int s = 26;
  8340. #elif PACKETVER < 20120925
  8341. const int s = 28;
  8342. #elif PACKETVER < 20150226
  8343. const int s = 31;
  8344. #else
  8345. const int s = 57;
  8346. #endif
  8347. nullpo_retv(sd);
  8348. nullpo_retv(tsd);
  8349. fd = sd->fd;
  8350. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8351. buf = WFIFOP(fd,0);
  8352. #if PACKETVER < 20101124
  8353. WBUFW(buf, 0) = 0x2d7;
  8354. #elif PACKETVER < 20120925
  8355. WBUFW(buf, 0) = 0x859;
  8356. #elif PACKETVER < 20150226
  8357. WBUFW(buf, 0) = 0x997;
  8358. #else
  8359. WBUFW(buf, 0) = 0xa2d;
  8360. #endif
  8361. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8362. WBUFW(buf,28) = tsd->status.class_;
  8363. WBUFW(buf,30) = tsd->vd.hair_style;
  8364. WBUFW(buf,32) = tsd->vd.head_bottom;
  8365. WBUFW(buf,34) = tsd->vd.head_mid;
  8366. WBUFW(buf,36) = tsd->vd.head_top;
  8367. #if PACKETVER >= 20110111
  8368. WBUFW(buf,38) = tsd->vd.robe;
  8369. offset+= 2;
  8370. buf = WBUFP(buf,2);
  8371. #endif
  8372. WBUFW(buf,38) = tsd->vd.hair_color;
  8373. WBUFW(buf,40) = tsd->vd.cloth_color;
  8374. WBUFB(buf,42) = tsd->vd.sex;
  8375. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8376. {
  8377. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8378. continue;
  8379. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8380. continue;
  8381. // Add item info : refine, identify flag, element, etc.
  8382. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8383. n++;
  8384. }
  8385. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8386. WFIFOSET(fd, WFIFOW(fd, 2));
  8387. }
  8388. /// Display msgstringtable.txt string (ZC_MSG).
  8389. /// 0291 <message>.W
  8390. void clif_msg(struct map_session_data* sd, unsigned short id)
  8391. {
  8392. int fd;
  8393. nullpo_retv(sd);
  8394. fd = sd->fd;
  8395. WFIFOHEAD(fd, packet_len(0x291));
  8396. WFIFOW(fd, 0) = 0x291;
  8397. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8398. WFIFOSET(fd, packet_len(0x291));
  8399. }
  8400. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8401. /// 0x7e2 <message>.W <value>.L
  8402. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8403. {
  8404. int fd = sd->fd;
  8405. WFIFOHEAD(fd, packet_len(0x7e2));
  8406. WFIFOW(fd,0) = 0x7e2;
  8407. WFIFOW(fd,2) = id;
  8408. WFIFOL(fd,4) = value;
  8409. WFIFOSET(fd, packet_len(0x7e2));
  8410. }
  8411. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8412. /// 07e6 <skill id>.W <msg id>.L
  8413. ///
  8414. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8415. /// "[SkillName] Message"
  8416. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8417. {
  8418. int fd = sd->fd;
  8419. WFIFOHEAD(fd, packet_len(0x7e6));
  8420. WFIFOW(fd,0) = 0x7e6;
  8421. WFIFOW(fd,2) = skill_id;
  8422. WFIFOL(fd,4) = msg_id;
  8423. WFIFOSET(fd, packet_len(0x7e6));
  8424. }
  8425. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8426. /// Returns true if the packet was parsed successfully.
  8427. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8428. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8429. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_) {
  8430. char *text, *name, *message;
  8431. unsigned int packetlen, textlen, namelen, messagelen;
  8432. int fd = sd->fd;
  8433. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8434. *name_ = NULL;
  8435. *namelen_ = 0;
  8436. *message_ = NULL;
  8437. *messagelen_ = 0;
  8438. packetlen = RFIFOW(fd,info->pos[0]);
  8439. // basic structure checks
  8440. if( packetlen < 4 + 1 ) { // 4-byte header and at least an empty string is expected
  8441. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8442. return false;
  8443. }
  8444. text = (char*)RFIFOP(fd,info->pos[1]);
  8445. textlen = packetlen - 4;
  8446. // process <name> part of the packet
  8447. if( format == 0 ) { // name and message are separated by ' : '
  8448. // validate name
  8449. name = text;
  8450. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8451. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8452. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8453. {
  8454. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8455. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8456. set_eof(fd); // Just kick them out to correct it.
  8457. return false;
  8458. }
  8459. message = name + namelen + 3;
  8460. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8461. } else {
  8462. // name has fixed width
  8463. if( textlen < NAME_LENGTH + 1 ) {
  8464. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8465. return false;
  8466. }
  8467. // validate name
  8468. name = text;
  8469. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8470. // only restriction is that the name must be zero-terminated
  8471. if( name[namelen] != '\0' ) {
  8472. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8473. return false;
  8474. }
  8475. message = name + NAME_LENGTH;
  8476. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8477. }
  8478. #if PACKETVER >= 20151001
  8479. message[messagelen++] = '\0';
  8480. #endif
  8481. // the declared length must match real length
  8482. if( messagelen != strnlen(message, messagelen)+1 ) {
  8483. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8484. return false;
  8485. }
  8486. // verify <message> part of the packet
  8487. if( message[messagelen-1] != '\0' ) { // message must be zero-terminated
  8488. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8489. return false;
  8490. }
  8491. // messages mustn't be too long
  8492. if( messagelen > CHAT_SIZE_MAX-1 ) {
  8493. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8494. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8495. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8496. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8497. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8498. return false;
  8499. }
  8500. *name_ = name;
  8501. *namelen_ = namelen;
  8502. *message_ = message;
  8503. *messagelen_ = messagelen;
  8504. return true;
  8505. }
  8506. // ---------------------
  8507. // clif_guess_PacketVer
  8508. // ---------------------
  8509. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8510. // error codes:
  8511. // 0 - Success
  8512. // 1 - Unknown packet_ver
  8513. // 2 - Invalid account_id
  8514. // 3 - Invalid char_id
  8515. // 4 - Invalid login_id1 (reserved)
  8516. // 5 - Invalid client_tick (reserved)
  8517. // 6 - Invalid sex
  8518. // Only the first 'invalid' error that appears is used.
  8519. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8520. {
  8521. static int err = 1;
  8522. static int packet_ver = -1;
  8523. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8524. unsigned short cmd;
  8525. if (get_previous)
  8526. {//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]
  8527. if( error )
  8528. *error = err;
  8529. return packet_ver;
  8530. }
  8531. //By default, start searching on the default one.
  8532. err = 1;
  8533. packet_ver = clif_config.packet_db_ver;
  8534. cmd = clif_parse_cmd(fd, NULL);
  8535. packet_len = RFIFOREST(fd);
  8536. #define SET_ERROR(n) \
  8537. if( err == 1 )\
  8538. err = n;\
  8539. //define SET_ERROR
  8540. // FIXME: If the packet is not received at once, this will FAIL.
  8541. // Figure out, when it happens, that only part of the packet is
  8542. // received, or fix the function to be able to deal with that
  8543. // case.
  8544. #define CHECK_PACKET_VER() \
  8545. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8546. ;/* not wanttoconnection or wrong length */\
  8547. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8548. { SET_ERROR(2); }/* invalid account_id */\
  8549. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8550. { SET_ERROR(3); }/* invalid char_id */\
  8551. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8552. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8553. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8554. { SET_ERROR(6); }/* invalid sex */\
  8555. else\
  8556. {\
  8557. err = 0;\
  8558. if( error )\
  8559. *error = 0;\
  8560. return packet_ver;\
  8561. }\
  8562. //define CHECK_PACKET_VER
  8563. CHECK_PACKET_VER();//Default packet version found.
  8564. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8565. CHECK_PACKET_VER();
  8566. }
  8567. if( error )
  8568. *error = err;
  8569. packet_ver = -1;
  8570. return -1;
  8571. #undef SET_ERROR
  8572. #undef CHECK_PACKET_VER
  8573. }
  8574. // ------------
  8575. // clif_parse_*
  8576. // ------------
  8577. // Parses incoming (player) connection
  8578. /// Request to connect to map-server.
  8579. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8580. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8581. /// There are various variants of this packet, some of them have padding between fields.
  8582. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8583. {
  8584. struct block_list* bl;
  8585. struct auth_node* node;
  8586. int cmd, account_id, char_id, login_id1, sex;
  8587. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8588. 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])
  8589. if (sd) {
  8590. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8591. return;
  8592. }
  8593. // Only valid packet version get here
  8594. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8595. cmd = RFIFOW(fd,0);
  8596. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8597. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8598. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8599. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8600. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8601. if( packet_ver < 5 || // reject really old client versions
  8602. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8603. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8604. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8605. {// packet version rejected
  8606. 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));
  8607. WFIFOHEAD(fd,packet_len(0x6a));
  8608. WFIFOW(fd,0) = 0x6a;
  8609. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8610. WFIFOSET(fd,packet_len(0x6a));
  8611. set_eof(fd);
  8612. return;
  8613. }
  8614. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8615. clif_authfail_fd(fd,1);// server closed
  8616. return;
  8617. }
  8618. //Check for double login.
  8619. bl = map_id2bl(account_id);
  8620. if(bl && bl->type != BL_PC) {
  8621. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8622. WFIFOHEAD(fd,packet_len(0x6a));
  8623. WFIFOW(fd,0) = 0x6a;
  8624. WFIFOB(fd,2) = 3; // Rejected by server
  8625. WFIFOSET(fd,packet_len(0x6a));
  8626. set_eof(fd);
  8627. return;
  8628. }
  8629. if (bl ||
  8630. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8631. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8632. {
  8633. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8634. return;
  8635. }
  8636. CREATE(sd, TBL_PC, 1);
  8637. sd->fd = fd;
  8638. sd->packet_ver = packet_ver;
  8639. #ifdef PACKET_OBFUSCATION
  8640. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8641. #endif
  8642. session[fd]->session_data = sd;
  8643. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8644. #if PACKETVER < 20070521
  8645. WFIFOHEAD(fd,4);
  8646. WFIFOL(fd,0) = sd->bl.id;
  8647. WFIFOSET(fd,4);
  8648. #else
  8649. WFIFOHEAD(fd,packet_len(0x283));
  8650. WFIFOW(fd,0) = 0x283;
  8651. WFIFOL(fd,2) = sd->bl.id;
  8652. WFIFOSET(fd,packet_len(0x283));
  8653. #endif
  8654. chrif_authreq(sd,false);
  8655. }
  8656. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8657. /// 007d
  8658. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8659. {
  8660. bool guild_notice = false;
  8661. if(sd->bl.prev != NULL)
  8662. return;
  8663. if (!sd->state.active) { //Character loading is not complete yet!
  8664. //Let pc_reg_received reinvoke this when ready.
  8665. sd->state.connect_new = 0;
  8666. return;
  8667. }
  8668. if (sd->state.rewarp) { //Rewarp player.
  8669. sd->state.rewarp = 0;
  8670. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8671. return;
  8672. }
  8673. sd->state.warping = 0;
  8674. // look
  8675. #if PACKETVER < 4
  8676. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8677. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8678. #else
  8679. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8680. #endif
  8681. if(sd->vd.cloth_color)
  8682. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8683. if(sd->vd.body_style)
  8684. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8685. // item
  8686. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8687. pc_checkitem(sd);
  8688. // cart
  8689. if(pc_iscarton(sd)) {
  8690. clif_cartlist(sd);
  8691. clif_updatestatus(sd,SP_CARTINFO);
  8692. }
  8693. // weight
  8694. clif_updatestatus(sd,SP_WEIGHT);
  8695. clif_updatestatus(sd,SP_MAXWEIGHT);
  8696. // guild
  8697. // (needs to go before clif_spawn() to show guild emblems correctly)
  8698. if(sd->status.guild_id)
  8699. guild_send_memberinfoshort(sd,1);
  8700. if(battle_config.pc_invincible_time > 0) {
  8701. if(map_flag_gvg(sd->bl.m))
  8702. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8703. else
  8704. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8705. }
  8706. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8707. map_spawnmobs(sd->bl.m);
  8708. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8709. map[sd->bl.m].users_pvp++;
  8710. }
  8711. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8712. // reset the callshop flag if the player changes map
  8713. sd->state.callshop = 0;
  8714. if(map_addblock(&sd->bl))
  8715. return;
  8716. clif_spawn(&sd->bl);
  8717. // Party
  8718. // (needs to go after clif_spawn() to show hp bars correctly)
  8719. if(sd->status.party_id) {
  8720. party_send_movemap(sd);
  8721. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8722. }
  8723. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8724. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8725. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8726. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8727. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8728. sd->pvp_rank = 0;
  8729. sd->pvp_lastusers = 0;
  8730. sd->pvp_point = 5;
  8731. sd->pvp_won = 0;
  8732. sd->pvp_lost = 0;
  8733. }
  8734. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8735. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8736. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8737. if (map[sd->bl.m].flag.gvg_dungeon)
  8738. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8739. if( map_flag_gvg(sd->bl.m) )
  8740. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8741. // info about nearby objects
  8742. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8743. 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);
  8744. // pet
  8745. if( sd->pd ) {
  8746. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8747. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8748. pet_menu(sd, 3); //Option 3 is return to egg.
  8749. } else {
  8750. if(map_addblock(&sd->pd->bl))
  8751. return;
  8752. clif_spawn(&sd->pd->bl);
  8753. clif_send_petdata(sd,sd->pd,0,0);
  8754. clif_send_petstatus(sd);
  8755. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8756. }
  8757. }
  8758. //homunculus [blackhole89]
  8759. if( hom_is_active(sd->hd) ) {
  8760. if(map_addblock(&sd->hd->bl))
  8761. return;
  8762. clif_spawn(&sd->hd->bl);
  8763. clif_send_homdata(sd,SP_ACK,0);
  8764. clif_hominfo(sd,sd->hd,1);
  8765. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8766. clif_homskillinfoblock(sd);
  8767. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8768. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8769. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8770. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8771. }
  8772. if( sd->md ) {
  8773. if(map_addblock(&sd->md->bl))
  8774. return;
  8775. clif_spawn(&sd->md->bl);
  8776. clif_mercenary_info(sd);
  8777. clif_mercenary_skillblock(sd);
  8778. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8779. }
  8780. if( sd->ed ) {
  8781. if (map_addblock(&sd->ed->bl))
  8782. return;
  8783. clif_spawn(&sd->ed->bl);
  8784. clif_elemental_info(sd);
  8785. clif_elemental_updatestatus(sd,SP_HP);
  8786. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8787. clif_elemental_updatestatus(sd,SP_SP);
  8788. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8789. }
  8790. if(sd->state.connect_new) {
  8791. int lv;
  8792. guild_notice = true;
  8793. sd->state.connect_new = 0;
  8794. clif_skillinfoblock(sd);
  8795. clif_hotkeys_send(sd);
  8796. clif_updatestatus(sd,SP_BASEEXP);
  8797. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8798. clif_updatestatus(sd,SP_JOBEXP);
  8799. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8800. clif_updatestatus(sd,SP_SKILLPOINT);
  8801. clif_initialstatus(sd);
  8802. if (sd->sc.option&OPTION_FALCON)
  8803. clif_status_load(&sd->bl, SI_FALCON, 1);
  8804. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8805. clif_status_load(&sd->bl, SI_RIDING, 1);
  8806. else if (sd->sc.option&OPTION_WUGRIDER)
  8807. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8808. else if (sd->sc.data[SC_ALL_RIDING])
  8809. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8810. if(sd->status.manner < 0)
  8811. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8812. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8813. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8814. if(sd->bl.m == sd->feel_map[0].m
  8815. || sd->bl.m == sd->feel_map[1].m
  8816. || sd->bl.m == sd->feel_map[2].m)
  8817. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8818. }
  8819. if(sd->pd && sd->pd->pet.intimate > 900)
  8820. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8821. if(hom_is_active(sd->hd))
  8822. hom_init_timers(sd->hd);
  8823. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8824. sd->state.night = 1;
  8825. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8826. }
  8827. // Notify everyone that this char logged in [Skotlex].
  8828. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8829. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8830. //Login Event
  8831. npc_script_event(sd, NPCE_LOGIN);
  8832. }
  8833. } else {
  8834. //For some reason the client "loses" these on warp/map-change.
  8835. clif_updatestatus(sd,SP_STR);
  8836. clif_updatestatus(sd,SP_AGI);
  8837. clif_updatestatus(sd,SP_VIT);
  8838. clif_updatestatus(sd,SP_INT);
  8839. clif_updatestatus(sd,SP_DEX);
  8840. clif_updatestatus(sd,SP_LUK);
  8841. // abort currently running script
  8842. sd->state.using_fake_npc = 0;
  8843. sd->state.menu_or_input = 0;
  8844. sd->npc_menu = 0;
  8845. if(sd->npc_id)
  8846. npc_event_dequeue(sd);
  8847. }
  8848. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8849. #if PACKETVER >= 20070918
  8850. clif_partyinvitationstate(sd);
  8851. clif_equipcheckbox(sd);
  8852. #endif
  8853. #ifdef VIP_ENABLE
  8854. if (!sd->disableshowrate) {
  8855. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8856. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8857. }
  8858. #endif
  8859. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8860. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8861. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8862. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8863. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8864. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8865. { //Display night.
  8866. if( !sd->state.night )
  8867. {
  8868. sd->state.night = 1;
  8869. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8870. }
  8871. }
  8872. else if( sd->state.night )
  8873. { //Clear night display.
  8874. sd->state.night = 0;
  8875. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8876. }
  8877. if( map[sd->bl.m].flag.battleground )
  8878. {
  8879. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8880. if( map[sd->bl.m].flag.battleground == 2 )
  8881. clif_bg_updatescore_single(sd);
  8882. }
  8883. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8884. {
  8885. char output[128];
  8886. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8887. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8888. }
  8889. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8890. map[sd->bl.m].hpmeter_visible++;
  8891. sd->state.hpmeter_visible = 1;
  8892. }
  8893. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8894. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8895. sd->state.changemap = false;
  8896. // Instances do not need their own channels
  8897. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8898. channel_mjoin(sd); //join new map
  8899. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8900. clif_guild_notice(sd, sd->guild); // Displays at end
  8901. mail_clear(sd);
  8902. clif_maptypeproperty2(&sd->bl,SELF);
  8903. /* Guild Aura Init */
  8904. if( sd->state.gmaster_flag ) {
  8905. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8906. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8907. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8908. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8909. }
  8910. if( sd->state.vending ) { /* show we have a vending */
  8911. clif_openvending(sd,sd->bl.id,sd->vending);
  8912. clif_showvendingboard(&sd->bl,sd->message,0);
  8913. }
  8914. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8915. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8916. npc_script_event(sd, NPCE_LOADMAP);
  8917. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8918. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8919. if (sd->sc.opt2) //Client loses these on warp.
  8920. clif_changeoption(&sd->bl);
  8921. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8922. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8923. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8924. }
  8925. clif_weather_check(sd);
  8926. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8927. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8928. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8929. else
  8930. sd->areanpc_id = 0;
  8931. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8932. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8933. pc_setdead(sd);
  8934. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8935. if(pc_isdead(sd))
  8936. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8937. else {
  8938. skill_usave_trigger(sd);
  8939. if (battle_config.spawn_direction)
  8940. clif_changed_dir(&sd->bl, SELF);
  8941. }
  8942. // Trigger skill effects if you appear standing on them
  8943. if(!battle_config.pc_invincible_time)
  8944. skill_unit_move(&sd->bl,gettick(),1);
  8945. pc_show_questinfo_reinit(sd);
  8946. pc_show_questinfo(sd);
  8947. }
  8948. /// Server's tick (ZC_NOTIFY_TIME).
  8949. /// 007f <time>.L
  8950. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8951. {
  8952. int fd = sd->fd;
  8953. WFIFOHEAD(fd,packet_len(0x7f));
  8954. WFIFOW(fd,0) = 0x7f;
  8955. WFIFOL(fd,2) = time;
  8956. WFIFOSET(fd,packet_len(0x7f));
  8957. }
  8958. /// Request for server's tick.
  8959. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8960. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8961. /// There are various variants of this packet, some of them have padding between fields.
  8962. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8963. {
  8964. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8965. clif_notify_time(sd, gettick());
  8966. }
  8967. /// Sends hotkey bar.
  8968. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8969. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8970. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8971. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8972. void clif_hotkeys_send(struct map_session_data *sd) {
  8973. #ifdef HOTKEY_SAVING
  8974. const int fd = sd->fd;
  8975. int i;
  8976. int offset = 2;
  8977. #if PACKETVER < 20090603
  8978. const int cmd = 0x2b9;
  8979. #elif PACKETVER < 20141022
  8980. const int cmd = 0x7d9;
  8981. #else
  8982. char Rotate = sd->status.hotkey_rowshift;
  8983. const int cmd = 0xa00;
  8984. offset = 3;
  8985. #endif
  8986. if (!fd) return;
  8987. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8988. WFIFOW(fd, 0) = cmd;
  8989. #if PACKETVER >= 20141022
  8990. WFIFOB(fd, 2) = Rotate;
  8991. #endif
  8992. for(i = 0; i < MAX_HOTKEYS; i++) {
  8993. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8994. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8995. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8996. }
  8997. WFIFOSET(fd, packet_len(cmd));
  8998. #endif
  8999. }
  9000. /// Request to update a position on the hotkey row bar
  9001. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9002. int cmd = RFIFOW(fd, 0);
  9003. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  9004. }
  9005. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9006. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9007. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9008. #ifdef HOTKEY_SAVING
  9009. unsigned short idx;
  9010. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9011. idx = RFIFOW(fd, info->pos[0]);
  9012. if (idx >= MAX_HOTKEYS) return;
  9013. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9014. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9015. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9016. #endif
  9017. }
  9018. /// Displays cast-like progress bar (ZC_PROGRESS).
  9019. /// 02f0 <color>.L <time>.L
  9020. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9021. {
  9022. int fd = sd->fd;
  9023. WFIFOHEAD(fd,packet_len(0x2f0));
  9024. WFIFOW(fd,0) = 0x2f0;
  9025. WFIFOL(fd,2) = color;
  9026. WFIFOL(fd,6) = second;
  9027. WFIFOSET(fd,packet_len(0x2f0));
  9028. }
  9029. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9030. /// 02f2
  9031. void clif_progressbar_abort(struct map_session_data * sd)
  9032. {
  9033. int fd = sd->fd;
  9034. WFIFOHEAD(fd,packet_len(0x2f2));
  9035. WFIFOW(fd,0) = 0x2f2;
  9036. WFIFOSET(fd,packet_len(0x2f2));
  9037. }
  9038. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9039. /// 02f1
  9040. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9041. {
  9042. int npc_id = sd->progressbar.npc_id;
  9043. if( gettick() < sd->progressbar.timeout && sd->st )
  9044. sd->st->state = END;
  9045. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9046. npc_scriptcont(sd, npc_id, false);
  9047. }
  9048. /// Request to walk to a certain position on the current map.
  9049. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9050. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9051. /// There are various variants of this packet, some of them have padding between fields.
  9052. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9053. {
  9054. short x, y;
  9055. if (pc_isdead(sd)) {
  9056. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9057. return;
  9058. }
  9059. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9060. ; //You CAN walk on this OPT1 value.
  9061. else if( sd->progressbar.npc_id )
  9062. clif_progressbar_abort(sd);
  9063. else if (pc_cant_act(sd))
  9064. return;
  9065. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9066. return;
  9067. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9068. //A move command one cell west is only valid if the target cell is free
  9069. if(battle_config.official_cell_stack_limit > 0
  9070. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9071. return;
  9072. // Cloaking wall check is actually updated when you click to process next movement
  9073. // not when you move each cell. This is official behaviour.
  9074. if (sd->sc.data[SC_CLOAKING])
  9075. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9076. pc_delinvincibletimer(sd);
  9077. //Set last idle time... [Skotlex]
  9078. if (battle_config.idletime_option&IDLE_WALK)
  9079. sd->idletime = last_tick;
  9080. unit_walktoxy(&sd->bl, x, y, 4);
  9081. }
  9082. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9083. /// 018b <result>.W
  9084. /// result:
  9085. /// 0 = disconnect (quit)
  9086. /// 1 = cannot disconnect (wait 10 seconds)
  9087. /// ? = ignored
  9088. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9089. {
  9090. int fd = sd->fd;
  9091. WFIFOHEAD(fd,packet_len(0x18b));
  9092. WFIFOW(fd,0) = 0x18b;
  9093. WFIFOW(fd,2) = result;
  9094. WFIFOSET(fd,packet_len(0x18b));
  9095. }
  9096. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9097. /// 018a <type>.W
  9098. /// type:
  9099. /// 0 = quit
  9100. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9101. {
  9102. /* Rovert's prevent logout option fixed [Valaris] */
  9103. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9104. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9105. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9106. {
  9107. set_eof(fd);
  9108. pc_damage_log_clear(sd,0);
  9109. clif_disconnect_ack(sd, 0);
  9110. } else {
  9111. clif_disconnect_ack(sd, 1);
  9112. }
  9113. }
  9114. /// Requesting unit's name.
  9115. /// 0094 <id>.L (CZ_REQNAME)
  9116. /// 0368 <id>.L (CZ_REQNAME2)
  9117. /// There are various variants of this packet, some of them have padding between fields.
  9118. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9119. {
  9120. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9121. struct block_list* bl;
  9122. //struct status_change *sc;
  9123. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9124. id = sd->bl.id;
  9125. bl = map_id2bl(id);
  9126. if( bl == NULL )
  9127. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9128. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9129. return; // Block namerequests past view range
  9130. // 'see people in GM hide' cheat detection
  9131. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9132. sc = status_get_sc(bl);
  9133. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9134. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9135. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9136. ) {
  9137. char gm_msg[256];
  9138. 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);
  9139. ShowWarning(gm_msg);
  9140. // information is sent to all online GMs
  9141. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9142. return;
  9143. }
  9144. */
  9145. clif_charnameack(fd, bl);
  9146. }
  9147. /// Validates and processes global messages
  9148. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9149. /// There are various variants of this packet.
  9150. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9151. {
  9152. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9153. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  9154. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  9155. char *name, *message, *fakename = NULL;
  9156. int namelen, messagelen;
  9157. bool is_fake;
  9158. // validate packet and retrieve name and message
  9159. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9160. return;
  9161. if( is_atcommand(fd, sd, message, 1) )
  9162. return;
  9163. if (sd->sc.cant.chat)
  9164. return; //no "chatting" while muted.
  9165. if( battle_config.min_chat_delay ) { //[Skotlex]
  9166. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9167. return;
  9168. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9169. }
  9170. if (battle_config.idletime_option&IDLE_CHAT)
  9171. sd->idletime = last_tick;
  9172. if( sd->gcbind ) {
  9173. channel_send(sd->gcbind,sd,message);
  9174. return;
  9175. }
  9176. /**
  9177. * Fake Name Design by FatalEror (bug report #9)
  9178. **/
  9179. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  9180. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  9181. strcpy(fakename, sd->fakename);
  9182. strcat(fakename, " : ");
  9183. strcat(fakename, message);
  9184. textlen = strlen(fakename) + 1;
  9185. }
  9186. // send message to others (using the send buffer for temp. storage)
  9187. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9188. // send back message to the speaker
  9189. if( is_fake ) {
  9190. WFIFOW(fd,0) = 0x8e;
  9191. WFIFOW(fd,2) = textlen + 4;
  9192. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  9193. aFree(fakename);
  9194. } else {
  9195. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  9196. WFIFOW(fd,0) = 0x8e;
  9197. }
  9198. WFIFOSET(fd, WFIFOW(fd,2));
  9199. #ifdef PCRE_SUPPORT
  9200. // trigger listening npcs
  9201. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  9202. #endif
  9203. // Chat logging type 'O' / Global Chat
  9204. 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);
  9205. }
  9206. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9207. /// Request to warp to a map on given coordinates.
  9208. /// 0140 <map name>.16B <x>.W <y>.W
  9209. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9210. {
  9211. char command[MAP_NAME_LENGTH_EXT+25];
  9212. char* map_name;
  9213. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9214. map_name = (char*)RFIFOP(fd,info->pos[0]);
  9215. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9216. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9217. RFIFOW(fd,info->pos[1]), //x
  9218. RFIFOW(fd,info->pos[2])); //y
  9219. is_atcommand(fd, sd, command, 1);
  9220. }
  9221. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9222. /// 009c <id>.L <head dir>.W <dir>.B
  9223. /// head dir:
  9224. /// 0 = straight
  9225. /// 1 = turned CW
  9226. /// 2 = turned CCW
  9227. /// dir:
  9228. /// 0 = north
  9229. /// 1 = northwest
  9230. /// 2 = west
  9231. /// 3 = southwest
  9232. /// 4 = south
  9233. /// 5 = southeast
  9234. /// 6 = east
  9235. /// 7 = northeast
  9236. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9237. {
  9238. unsigned char buf[64];
  9239. WBUFW(buf,0) = 0x9c;
  9240. WBUFL(buf,2) = bl->id;
  9241. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9242. WBUFB(buf,8) = unit_getdir(bl);
  9243. clif_send(buf, packet_len(0x9c), bl, target);
  9244. if (disguised(bl)) {
  9245. WBUFL(buf,2) = -bl->id;
  9246. WBUFW(buf,6) = 0;
  9247. clif_send(buf, packet_len(0x9c), bl, SELF);
  9248. }
  9249. }
  9250. /// Request to change own body and head direction.
  9251. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9252. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9253. /// There are various variants of this packet, some of them have padding between fields.
  9254. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9255. {
  9256. unsigned char headdir, dir;
  9257. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9258. headdir = RFIFOB(fd,info->pos[0]);
  9259. dir = RFIFOB(fd,info->pos[1]);
  9260. pc_setdir(sd, dir, headdir);
  9261. clif_changed_dir(&sd->bl, AREA_WOS);
  9262. }
  9263. /// Request to show an emotion (CZ_REQ_EMOTION).
  9264. /// 00bf <type>.B
  9265. /// type:
  9266. /// @see enum emotion_type
  9267. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9268. {
  9269. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9270. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  9271. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9272. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9273. return;
  9274. }
  9275. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9276. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9277. sd->emotionlasttime = time(NULL);
  9278. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9279. return;
  9280. }
  9281. sd->emotionlasttime = time(NULL);
  9282. if (battle_config.idletime_option&IDLE_EMOTION)
  9283. sd->idletime = last_tick;
  9284. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9285. emoticon = rnd()%6+E_DICE1;
  9286. }
  9287. clif_emotion(&sd->bl, emoticon);
  9288. } else
  9289. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9290. }
  9291. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9292. /// 00c2 <count>.L
  9293. void clif_user_count(struct map_session_data* sd, int count)
  9294. {
  9295. int fd = sd->fd;
  9296. WFIFOHEAD(fd,packet_len(0xc2));
  9297. WFIFOW(fd,0) = 0xc2;
  9298. WFIFOL(fd,2) = count;
  9299. WFIFOSET(fd,packet_len(0xc2));
  9300. }
  9301. /// /w /who (CZ_REQ_USER_COUNT).
  9302. /// Request to display amount of currently connected players.
  9303. /// 00c1
  9304. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9305. {
  9306. clif_user_count(sd, map_getusers());
  9307. }
  9308. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9309. {
  9310. if (pc_isdead(sd)) {
  9311. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9312. return;
  9313. }
  9314. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9315. // (not all are included in pc_can_attack)
  9316. if (sd->sc.count &&
  9317. (sd->sc.data[SC_TRICKDEAD] ||
  9318. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9319. sd->sc.data[SC_BLADESTOP] ||
  9320. sd->sc.data[SC__MANHOLE] ))
  9321. return;
  9322. if(action_type != 0x00 && action_type != 0x07)
  9323. pc_stop_walking(sd, 1);
  9324. pc_stop_attack(sd);
  9325. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9326. target_id = sd->bl.id;
  9327. switch(action_type)
  9328. {
  9329. case 0x00: // once attack
  9330. case 0x07: // continuous attack
  9331. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9332. return;
  9333. if( sd->sc.option&OPTION_COSTUME )
  9334. return;
  9335. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9336. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9337. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9338. return;
  9339. }
  9340. }
  9341. pc_delinvincibletimer(sd);
  9342. if (battle_config.idletime_option&IDLE_ATTACK)
  9343. sd->idletime = last_tick;
  9344. unit_attack(&sd->bl, target_id, action_type != 0);
  9345. break;
  9346. case 0x02: // sitdown
  9347. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  9348. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9349. break;
  9350. }
  9351. if(pc_issit(sd)) {
  9352. //Bugged client? Just refresh them.
  9353. clif_sitting(&sd->bl);
  9354. return;
  9355. }
  9356. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  9357. break;
  9358. if (sd->sc.count && (
  9359. sd->sc.data[SC_DANCING] ||
  9360. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9361. )) //No sitting during these states either.
  9362. break;
  9363. if (battle_config.idletime_option&IDLE_SIT)
  9364. sd->idletime = last_tick;
  9365. pc_setsit(sd);
  9366. skill_sit(sd, 1);
  9367. clif_sitting(&sd->bl);
  9368. break;
  9369. case 0x03: // standup
  9370. if (!pc_issit(sd)) {
  9371. //Bugged client? Just refresh them.
  9372. clif_standing(&sd->bl);
  9373. return;
  9374. }
  9375. if (pc_setstand(sd, false)) {
  9376. if (battle_config.idletime_option&IDLE_SIT)
  9377. sd->idletime = last_tick;
  9378. skill_sit(sd, 0);
  9379. clif_standing(&sd->bl);
  9380. }
  9381. break;
  9382. }
  9383. }
  9384. /// Request for an action.
  9385. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9386. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9387. /// action:
  9388. /// 0 = attack
  9389. /// 1 = pick up item
  9390. /// 2 = sit down
  9391. /// 3 = stand up
  9392. /// 7 = continous attack
  9393. /// 12 = (touch skill?)
  9394. /// There are various variants of this packet, some of them have padding between fields.
  9395. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9396. {
  9397. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9398. clif_parse_ActionRequest_sub(sd,
  9399. RFIFOB(fd,info->pos[1]),
  9400. RFIFOL(fd,info->pos[0]),
  9401. gettick()
  9402. );
  9403. }
  9404. /// Response to the death/system menu (CZ_RESTART).
  9405. /// 00b2 <type>.B
  9406. /// type:
  9407. /// 0 = restart (respawn)
  9408. /// 1 = char-select (disconnect)
  9409. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9410. {
  9411. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9412. case 0x00:
  9413. pc_respawn(sd,CLR_OUTSIGHT);
  9414. break;
  9415. case 0x01:
  9416. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9417. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9418. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9419. { //Send to char-server for character selection.
  9420. pc_damage_log_clear(sd,0);
  9421. chrif_charselectreq(sd, session[fd]->client_addr);
  9422. } else {
  9423. clif_disconnect_ack(sd, 1);
  9424. }
  9425. break;
  9426. }
  9427. }
  9428. /// Validates and processes whispered messages (CZ_WHISPER).
  9429. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9430. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9431. {
  9432. struct map_session_data* dstsd;
  9433. int i;
  9434. char *target, *message;
  9435. int namelen, messagelen;
  9436. // validate packet and retrieve name and message
  9437. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9438. return;
  9439. if ( is_atcommand(fd, sd, message, 1) )
  9440. return;
  9441. if (sd->sc.cant.chat)
  9442. return; //no "chatting" while muted.
  9443. if (battle_config.min_chat_delay) { //[Skotlex]
  9444. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9445. return;
  9446. }
  9447. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9448. }
  9449. if (battle_config.idletime_option&IDLE_CHAT)
  9450. sd->idletime = last_tick;
  9451. // Chat logging type 'W' / Whisper
  9452. 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);
  9453. //-------------------------------------------------------//
  9454. // Lordalfa - Paperboy - To whisper NPC commands //
  9455. //-------------------------------------------------------//
  9456. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9457. {
  9458. char* str = target+4; //Skip the NPC: string part.
  9459. struct npc_data* npc;
  9460. if ((npc = npc_name2id(str))) {
  9461. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9462. char *split;
  9463. char output[256];
  9464. str = message;
  9465. // skip codepage indicator, if detected
  9466. if( str[0] == '|' && strlen(str) >= 4 )
  9467. str += 3;
  9468. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9469. split = strchr(str,'#');
  9470. if( split == NULL ) { // use the remaining string
  9471. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9472. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9473. split_data[i][0] = '\0';
  9474. break;
  9475. }
  9476. *split = '\0';
  9477. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9478. str = split+1;
  9479. }
  9480. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9481. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9482. set_var(sd,output,(char *) split_data[i]);
  9483. }
  9484. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9485. npc_event(sd,output,0); // Calls the NPC label
  9486. return;
  9487. }
  9488. } else if( target[0] == '#' ) {
  9489. struct Channel *channel = NULL;
  9490. char* chname = target;
  9491. channel = channel_name2channel(chname,sd,3);
  9492. if(channel){
  9493. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9494. channel_send(channel,sd,message);
  9495. }
  9496. else if( channel->pass[0] == '\0') { //no pass needed
  9497. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9498. }
  9499. else {
  9500. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9501. }
  9502. return;
  9503. }
  9504. }
  9505. // searching destination character
  9506. dstsd = map_nick2sd(target);
  9507. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9508. // player is not on this map-server
  9509. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9510. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9511. // and if we ask for 'Test', we must not contact 'test' player
  9512. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9513. intif_wis_message(sd, target, message, messagelen);
  9514. return;
  9515. }
  9516. // if player ignores everyone
  9517. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9518. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9519. clif_wis_end(fd, 1); // 1: target character is not logged in
  9520. else
  9521. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9522. return;
  9523. }
  9524. // if player is autotrading
  9525. if (dstsd->state.autotrade == 1) {
  9526. char output[256];
  9527. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9528. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9529. return;
  9530. }
  9531. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9532. // if player ignores the source character
  9533. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9534. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9535. clif_wis_end(fd, 2); // 2: ignored by target
  9536. return;
  9537. }
  9538. }
  9539. // notify sender of success
  9540. clif_wis_end(fd, 0); // 0: success to send wisper
  9541. // Normal message
  9542. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9543. }
  9544. /// /b /nb (CZ_BROADCAST).
  9545. /// Request to broadcast a message on whole server.
  9546. /// 0099 <packet len>.W <text>.?B 00
  9547. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9548. char command[CHAT_SIZE_MAX+11];
  9549. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9550. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9551. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9552. // as the length varies depending on the command used, just block unreasonably long strings
  9553. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9554. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9555. is_atcommand(fd, sd, command, 1);
  9556. }
  9557. /// Request to pick up an item.
  9558. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9559. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9560. /// There are various variants of this packet, some of them have padding between fields.
  9561. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9562. {
  9563. struct flooritem_data *fitem;
  9564. int map_object_id;
  9565. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9566. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9567. do {
  9568. if (pc_isdead(sd)) {
  9569. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9570. break;
  9571. }
  9572. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9573. break;
  9574. if (pc_cant_act(sd))
  9575. break;
  9576. if (!pc_takeitem(sd, fitem))
  9577. break;
  9578. return;
  9579. } while (0);
  9580. // Client REQUIRES a fail packet or you can no longer pick items.
  9581. clif_additem(sd,0,0,6);
  9582. }
  9583. /// Request to drop an item.
  9584. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9585. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9586. /// There are various variants of this packet, some of them have padding between fields.
  9587. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9588. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9589. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9590. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9591. for(;;) {
  9592. if (pc_isdead(sd))
  9593. break;
  9594. if (pc_cant_act2(sd) || sd->npc_id)
  9595. break;
  9596. if (sd->sc.count && (
  9597. sd->sc.data[SC_AUTOCOUNTER] ||
  9598. sd->sc.data[SC_BLADESTOP] ||
  9599. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9600. ))
  9601. break;
  9602. if (!pc_dropitem(sd, item_index, item_amount))
  9603. break;
  9604. if (battle_config.idletime_option&IDLE_DROPITEM)
  9605. sd->idletime = last_tick;
  9606. return;
  9607. }
  9608. //Because the client does not like being ignored.
  9609. clif_dropitem(sd, item_index,0);
  9610. }
  9611. /// Request to use an item.
  9612. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9613. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9614. /// There are various variants of this packet, some of them have padding between fields.
  9615. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9616. {
  9617. int n;
  9618. if (pc_isdead(sd)) {
  9619. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9620. return;
  9621. }
  9622. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9623. return;
  9624. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9625. if (battle_config.idletime_option&IDLE_USEITEM)
  9626. sd->idletime = last_tick;
  9627. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9628. if(n <0 || n >= MAX_INVENTORY)
  9629. return;
  9630. if (!pc_useitem(sd,n))
  9631. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9632. }
  9633. /// Request to equip an item
  9634. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9635. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9636. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9637. {
  9638. int index;
  9639. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9640. if(pc_isdead(sd)) {
  9641. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9642. return;
  9643. }
  9644. index = RFIFOW(fd,info->pos[0])-2;
  9645. if (index < 0 || index >= MAX_INVENTORY)
  9646. return; //Out of bounds check.
  9647. if(sd->npc_id && !sd->npc_item_flag) {
  9648. return;
  9649. } else if (sd->state.storage_flag || sd->sc.opt1)
  9650. ; //You can equip/unequip stuff while storage is open/under status changes
  9651. else if (pc_cant_act2(sd))
  9652. return;
  9653. if(!sd->status.inventory[index].identify) {
  9654. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9655. return;
  9656. }
  9657. if(!sd->inventory_data[index])
  9658. return;
  9659. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9660. pet_equipitem(sd,index);
  9661. return;
  9662. }
  9663. if (battle_config.idletime_option&IDLE_USEITEM)
  9664. sd->idletime = last_tick;
  9665. //Client doesn't send the position for ammo.
  9666. if(sd->inventory_data[index]->type == IT_AMMO)
  9667. pc_equipitem(sd,index,EQP_AMMO);
  9668. else {
  9669. int req_pos;
  9670. #if PACKETVER >= 20120925
  9671. req_pos = RFIFOL(fd,info->pos[1]);
  9672. #else
  9673. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9674. #endif
  9675. pc_equipitem(sd,index,req_pos);
  9676. }
  9677. }
  9678. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9679. /// 00ab <index>.W
  9680. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9681. {
  9682. int index;
  9683. if(pc_isdead(sd)) {
  9684. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9685. return;
  9686. }
  9687. if (sd->npc_id && !sd->npc_item_flag) {
  9688. return;
  9689. } else if (sd->state.storage_flag || sd->sc.opt1)
  9690. ; //You can equip/unequip stuff while storage is open/under status changes
  9691. else if (pc_cant_act2(sd))
  9692. return;
  9693. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9694. if (battle_config.idletime_option&IDLE_USEITEM)
  9695. sd->idletime = last_tick;
  9696. pc_unequipitem(sd,index,1);
  9697. }
  9698. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9699. /// 0090 <id>.L <type>.B
  9700. /// type:
  9701. /// 1 = click
  9702. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9703. {
  9704. struct block_list *bl;
  9705. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9706. if(pc_isdead(sd)) {
  9707. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9708. return;
  9709. }
  9710. if (pc_cant_act2(sd) || sd->npc_id)
  9711. return;
  9712. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9713. //type = RFIFOB(fd,info->pos[1]);
  9714. if (!bl) return;
  9715. switch (bl->type) {
  9716. case BL_MOB:
  9717. case BL_PC:
  9718. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9719. break;
  9720. case BL_NPC:
  9721. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9722. npc_click(sd,(TBL_NPC*)bl);
  9723. break;
  9724. }
  9725. }
  9726. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9727. /// 00c5 <id>.L <type>.B
  9728. /// type:
  9729. /// 0 = buy
  9730. /// 1 = sell
  9731. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9732. {
  9733. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9734. if (sd->state.trading)
  9735. return;
  9736. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9737. }
  9738. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9739. /// 00ca <result>.B
  9740. /// result:
  9741. /// 0 = "The deal has successfully completed."
  9742. /// 1 = "You do not have enough zeny."
  9743. /// 2 = "You are over your Weight Limit."
  9744. /// 3 = "Out of the maximum capacity, you have too many items."
  9745. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9746. {
  9747. int fd = sd->fd;
  9748. WFIFOHEAD(fd,packet_len(0xca));
  9749. WFIFOW(fd,0) = 0xca;
  9750. WFIFOB(fd,2) = result;
  9751. WFIFOSET(fd,packet_len(0xca));
  9752. }
  9753. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9754. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9755. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9756. {
  9757. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9758. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9759. int result;
  9760. if( sd->state.trading || !sd->npc_shopid )
  9761. result = 1;
  9762. else
  9763. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9764. sd->npc_shopid = 0; //Clear shop data.
  9765. clif_npc_buy_result(sd, result);
  9766. }
  9767. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9768. /// 00cb <result>.B
  9769. /// result:
  9770. /// 0 = "The deal has successfully completed."
  9771. /// 1 = "The deal has failed."
  9772. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9773. {
  9774. int fd = sd->fd;
  9775. WFIFOHEAD(fd,packet_len(0xcb));
  9776. WFIFOW(fd,0) = 0xcb;
  9777. WFIFOB(fd,2) = result;
  9778. WFIFOSET(fd,packet_len(0xcb));
  9779. }
  9780. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9781. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9782. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9783. {
  9784. int fail=0,n;
  9785. unsigned short *item_list;
  9786. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9787. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9788. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9789. if (sd->state.trading || !sd->npc_shopid)
  9790. fail = 1;
  9791. else
  9792. fail = npc_selllist(sd,n,item_list);
  9793. sd->npc_shopid = 0; //Clear shop data.
  9794. clif_npc_sell_result(sd, fail);
  9795. }
  9796. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9797. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9798. /// type:
  9799. /// 0 = private
  9800. /// 1 = public
  9801. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9802. {
  9803. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9804. int len = RFIFOW(fd,info->pos[0])-15;
  9805. int limit = RFIFOW(fd,info->pos[1]);
  9806. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9807. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9808. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9809. char s_password[CHATROOM_PASS_SIZE];
  9810. char s_title[CHATROOM_TITLE_SIZE];
  9811. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9812. return;
  9813. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9814. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9815. return;
  9816. }
  9817. if( npc_isnear(&sd->bl) ) {
  9818. // uncomment to send msg_txt.
  9819. //char output[150];
  9820. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9821. //clif_displaymessage(sd->fd, output);
  9822. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9823. return;
  9824. }
  9825. if( len <= 0 )
  9826. return; // invalid input
  9827. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9828. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9829. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9830. }
  9831. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9832. /// 00d9 <chat ID>.L <passwd>.8B
  9833. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9834. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9835. int chatid = RFIFOL(fd,info->pos[0]);
  9836. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9837. chat_joinchat(sd,chatid,password);
  9838. }
  9839. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9840. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9841. /// type:
  9842. /// 0 = private
  9843. /// 1 = public
  9844. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9845. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9846. int len = RFIFOW(fd,info->pos[0])-15;
  9847. int limit = RFIFOW(fd,info->pos[1]);
  9848. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9849. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9850. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9851. char s_password[CHATROOM_PASS_SIZE];
  9852. char s_title[CHATROOM_TITLE_SIZE];
  9853. if( len <= 0 )
  9854. return; // invalid input
  9855. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9856. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9857. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9858. }
  9859. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9860. /// 00e0 <role>.L <nick>.24B
  9861. /// role:
  9862. /// 0 = owner
  9863. /// 1 = normal
  9864. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9865. {
  9866. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9867. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9868. }
  9869. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9870. /// 00e2 <name>.24B
  9871. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9872. {
  9873. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9874. }
  9875. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9876. /// 00e3
  9877. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9878. {
  9879. chat_leavechat(sd,0);
  9880. }
  9881. //Handles notifying asker and rejecter of what has just ocurred.
  9882. //Type is used to determine the correct msg_txt to use:
  9883. //0:
  9884. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9885. {
  9886. const char* msg;
  9887. char output[256];
  9888. // Your request has been rejected by autoreject option.
  9889. msg = msg_txt(sd,392);
  9890. clif_disp_onlyself(sd, msg, strlen(msg));
  9891. //Notice that a request was rejected.
  9892. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9893. clif_disp_onlyself(tsd, output, strlen(output));
  9894. }
  9895. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9896. /// 00e4 <account id>.L
  9897. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9898. {
  9899. struct map_session_data *t_sd;
  9900. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9901. if(!sd->chatID && pc_cant_act(sd))
  9902. return; //You can trade while in a chatroom.
  9903. // @noask [LuzZza]
  9904. if(t_sd && t_sd->state.noask) {
  9905. clif_noask_sub(sd, t_sd, 0);
  9906. return;
  9907. }
  9908. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9909. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9910. return;
  9911. }
  9912. trade_traderequest(sd,t_sd);
  9913. }
  9914. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9915. /// 00e6 <result>.B
  9916. /// result:
  9917. /// 3 = accepted
  9918. /// 4 = rejected
  9919. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9920. {
  9921. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9922. }
  9923. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9924. /// 00e8 <index>.W <amount>.L
  9925. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9926. {
  9927. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9928. short index = RFIFOW(fd,info->pos[0]);
  9929. int amount = RFIFOL(fd,info->pos[1]);
  9930. if( index == 0 )
  9931. trade_tradeaddzeny(sd, amount);
  9932. else
  9933. trade_tradeadditem(sd, index, (short)amount);
  9934. }
  9935. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9936. /// 00eb
  9937. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9938. {
  9939. trade_tradeok(sd);
  9940. }
  9941. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9942. /// 00ed
  9943. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9944. {
  9945. trade_tradecancel(sd);
  9946. }
  9947. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9948. /// 00ef
  9949. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9950. {
  9951. trade_tradecommit(sd);
  9952. }
  9953. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9954. /// 0118
  9955. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9956. {
  9957. pc_stop_attack(sd);
  9958. }
  9959. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9960. /// 0126 <index>.W <amount>.L
  9961. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9962. {
  9963. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9964. if (pc_istrading(sd))
  9965. return;
  9966. if (!pc_iscarton(sd))
  9967. return;
  9968. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9969. }
  9970. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9971. /// 0127 <index>.W <amount>.L
  9972. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9973. {
  9974. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9975. if (!pc_iscarton(sd))
  9976. return;
  9977. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9978. }
  9979. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9980. /// 012a
  9981. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9982. {
  9983. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9984. #ifdef NEW_CARTS
  9985. && sd->sc.data[SC_PUSH_CART] )
  9986. pc_setcart(sd,0);
  9987. #else
  9988. )
  9989. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9990. #endif
  9991. else // priority to remove this option before we can clear cart
  9992. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9993. }
  9994. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  9995. /// 097f <Length>.W <identity>.L <type>.B
  9996. void clif_SelectCart(struct map_session_data *sd) {
  9997. #if PACKETVER >= 20150826
  9998. int i = 0, carts = 3;
  9999. int fd = sd->fd;
  10000. WFIFOHEAD(fd,8 + carts);
  10001. WFIFOW(fd,0) = 0x97f;
  10002. WFIFOW(fd,2) = 8 + carts;
  10003. WFIFOL(fd,4) = sd->status.account_id;
  10004. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10005. for( i = 0; i < carts; i++ ) {
  10006. WFIFOB(fd,8 + i) = 10 + i;
  10007. }
  10008. WFIFOSET(fd,8 + carts);
  10009. #endif
  10010. }
  10011. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10012. /// 0980 <identity>.L <type>.B
  10013. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10014. #if PACKETVER >= 20150826
  10015. int type;
  10016. // Check identity
  10017. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10018. return;
  10019. type = (int)RFIFOB(fd,6);
  10020. // Check type
  10021. if( type < 10 || type > MAX_CARTS )
  10022. return;
  10023. pc_setcart(sd, type);
  10024. #endif
  10025. }
  10026. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10027. /// 01af <num>.W
  10028. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10029. {// TODO: State tracking?
  10030. int type;
  10031. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10032. return;
  10033. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10034. #ifdef NEW_CARTS
  10035. if( (type == 9 && sd->status.base_level > 131) ||
  10036. (type == 8 && sd->status.base_level > 121) ||
  10037. (type == 7 && sd->status.base_level > 111) ||
  10038. (type == 6 && sd->status.base_level > 101) ||
  10039. (type == 5 && sd->status.base_level > 90) ||
  10040. (type == 4 && sd->status.base_level > 80) ||
  10041. (type == 3 && sd->status.base_level > 65) ||
  10042. (type == 2 && sd->status.base_level > 40) ||
  10043. (type == 1))
  10044. #else
  10045. if( (type == 5 && sd->status.base_level > 90) ||
  10046. (type == 4 && sd->status.base_level > 80) ||
  10047. (type == 3 && sd->status.base_level > 65) ||
  10048. (type == 2 && sd->status.base_level > 40) ||
  10049. (type == 1))
  10050. #endif
  10051. pc_setcart(sd, type);
  10052. }
  10053. /// Request to increase status (CZ_STATUS_CHANGE).
  10054. /// 00bb <status id>.W <amount>.B
  10055. /// status id:
  10056. /// SP_STR ~ SP_LUK
  10057. /// amount:
  10058. /// Old clients always send 1 for this, even when using /str+ and the like.
  10059. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10060. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10061. {
  10062. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10063. if( increase_amount < 0 ) {
  10064. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10065. fd, increase_amount);
  10066. }
  10067. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  10068. }
  10069. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10070. /// 0112 <skill id>.W
  10071. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10072. {
  10073. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10074. }
  10075. 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)
  10076. {
  10077. int lv;
  10078. if( !hd )
  10079. return;
  10080. if( skill_isNotOk_hom(skill_id, hd) ) {
  10081. clif_emotion(&hd->bl, E_DOTS);
  10082. return;
  10083. }
  10084. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10085. target_id = hd->bl.id;
  10086. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10087. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10088. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10089. clif_emotion(&hd->bl, E_DOTS);
  10090. if (hd->master)
  10091. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10092. return;
  10093. }
  10094. lv = hom_checkskill(hd, skill_id);
  10095. if( skill_lv > lv )
  10096. skill_lv = lv;
  10097. if( skill_lv )
  10098. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10099. }
  10100. 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)
  10101. {
  10102. int lv;
  10103. if( !hd )
  10104. return;
  10105. if( skill_isNotOk_hom(skill_id, hd) ) {
  10106. clif_emotion(&hd->bl, E_DOTS);
  10107. return;
  10108. }
  10109. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10110. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10111. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10112. clif_emotion(&hd->bl, E_DOTS);
  10113. if (hd->master)
  10114. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10115. return;
  10116. }
  10117. if( hd->sc.data[SC_BASILICA] )
  10118. return;
  10119. lv = hom_checkskill(hd, skill_id);
  10120. if( skill_lv > lv )
  10121. skill_lv = lv;
  10122. if( skill_lv )
  10123. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10124. }
  10125. 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)
  10126. {
  10127. int lv;
  10128. if( !md )
  10129. return;
  10130. if( skill_isNotOk_mercenary(skill_id, md) )
  10131. return;
  10132. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10133. target_id = md->bl.id;
  10134. if( md->ud.skilltimer != INVALID_TIMER )
  10135. {
  10136. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10137. }
  10138. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10139. return;
  10140. lv = mercenary_checkskill(md, skill_id);
  10141. if( skill_lv > lv )
  10142. skill_lv = lv;
  10143. if( skill_lv )
  10144. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10145. }
  10146. 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)
  10147. {
  10148. int lv;
  10149. if( !md )
  10150. return;
  10151. if( skill_isNotOk_mercenary(skill_id, md) )
  10152. return;
  10153. if( md->ud.skilltimer != INVALID_TIMER )
  10154. return;
  10155. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10156. {
  10157. if (md->master)
  10158. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10159. return;
  10160. }
  10161. if( md->sc.data[SC_BASILICA] )
  10162. return;
  10163. lv = mercenary_checkskill(md, skill_id);
  10164. if( skill_lv > lv )
  10165. skill_lv = lv;
  10166. if( skill_lv )
  10167. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10168. }
  10169. /// Request to use a targeted skill.
  10170. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10171. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10172. /// There are various variants of this packet, some of them have padding between fields.
  10173. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10174. {
  10175. uint16 skill_id, skill_lv;
  10176. int inf,target_id;
  10177. unsigned int tick = gettick();
  10178. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10179. skill_lv = RFIFOW(fd,info->pos[0]);
  10180. skill_id = RFIFOW(fd,info->pos[1]);
  10181. target_id = RFIFOL(fd,info->pos[2]);
  10182. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10183. inf = skill_get_inf(skill_id);
  10184. if (inf&INF_GROUND_SKILL || !inf)
  10185. return; //Using a ground/passive skill on a target? WRONG.
  10186. if( SKILL_CHK_HOMUN(skill_id) ) {
  10187. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10188. return;
  10189. }
  10190. if( SKILL_CHK_MERC(skill_id) ) {
  10191. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10192. return;
  10193. }
  10194. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10195. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10196. sd->idletime = last_tick;
  10197. if( sd->npc_id ){
  10198. #ifdef RENEWAL
  10199. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  10200. return;
  10201. #else
  10202. if( !sd->npc_item_flag || !(inf&INF_SELF_SKILL) )
  10203. return;
  10204. #endif
  10205. }
  10206. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10207. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10208. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10209. return;
  10210. if( pc_issit(sd) )
  10211. return;
  10212. if( skill_isNotOk(skill_id, sd) )
  10213. return;
  10214. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10215. target_id = sd->bl.id; // never trust the client
  10216. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10217. target_id = sd->bl.id;
  10218. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10219. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10220. return;
  10221. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10222. if( sd->skillitem != skill_id ) {
  10223. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10224. return;
  10225. }
  10226. }
  10227. if( sd->sc.option&OPTION_COSTUME )
  10228. return;
  10229. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10230. return; // On basilica only caster can use Basilica again to stop it.
  10231. if( sd->menuskill_id ) {
  10232. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10233. clif_menuskill_clear(sd); //Cancel pet capture.
  10234. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10235. return; //Can't use skills while a menu is open.
  10236. }
  10237. if( sd->skillitem == skill_id ) {
  10238. if( skill_lv != sd->skillitemlv )
  10239. skill_lv = sd->skillitemlv;
  10240. if( !(inf&INF_SELF_SKILL) )
  10241. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10242. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10243. return;
  10244. }
  10245. sd->skillitem = sd->skillitemlv = 0;
  10246. if( SKILL_CHK_GUILD(skill_id) ) {
  10247. if( sd->state.gmaster_flag )
  10248. skill_lv = guild_checkskill(sd->guild, skill_id);
  10249. else
  10250. skill_lv = 0;
  10251. } else {
  10252. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10253. }
  10254. pc_delinvincibletimer(sd);
  10255. if( skill_lv )
  10256. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10257. }
  10258. /*==========================================
  10259. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10260. *------------------------------------------*/
  10261. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10262. {
  10263. unsigned int tick = gettick();
  10264. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10265. return; //Using a target skill on the ground? WRONG.
  10266. if( SKILL_CHK_HOMUN(skill_id) ) {
  10267. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10268. return;
  10269. }
  10270. if( SKILL_CHK_MERC(skill_id) ) {
  10271. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10272. return;
  10273. }
  10274. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10275. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10276. sd->idletime = last_tick;
  10277. if( skill_isNotOk(skill_id, sd) )
  10278. return;
  10279. if( skillmoreinfo != -1 ) {
  10280. if( pc_issit(sd) ) {
  10281. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10282. return;
  10283. }
  10284. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10285. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10286. }
  10287. if( sd->ud.skilltimer != INVALID_TIMER )
  10288. return;
  10289. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10290. if( sd->skillitem != skill_id ) {
  10291. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10292. return;
  10293. }
  10294. }
  10295. if( sd->sc.option&OPTION_COSTUME )
  10296. return;
  10297. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10298. return; // On basilica only caster can use Basilica again to stop it.
  10299. if( sd->menuskill_id ) {
  10300. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10301. clif_menuskill_clear(sd); //Cancel pet capture.
  10302. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10303. return; //Can't use skills while a menu is open.
  10304. }
  10305. pc_delinvincibletimer(sd);
  10306. if( sd->skillitem == skill_id ) {
  10307. if( skill_lv != sd->skillitemlv )
  10308. skill_lv = sd->skillitemlv;
  10309. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10310. } else {
  10311. int lv;
  10312. sd->skillitem = sd->skillitemlv = 0;
  10313. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10314. if( skill_lv > lv )
  10315. skill_lv = lv;
  10316. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10317. }
  10318. }
  10319. }
  10320. /// Request to use a ground skill.
  10321. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10322. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10323. /// There are various variants of this packet, some of them have padding between fields.
  10324. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10325. {
  10326. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10327. if (pc_cant_act(sd))
  10328. return;
  10329. if (pc_issit(sd))
  10330. return;
  10331. clif_parse_UseSkillToPosSub(fd, sd,
  10332. RFIFOW(fd,info->pos[0]), //skill lv
  10333. RFIFOW(fd,info->pos[1]), //skill num
  10334. RFIFOW(fd,info->pos[2]), //pos x
  10335. RFIFOW(fd,info->pos[3]), //pos y
  10336. -1 //Skill more info.
  10337. );
  10338. }
  10339. /// Request to use a ground skill with text.
  10340. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10341. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10342. /// There are various variants of this packet, some of them have padding between fields.
  10343. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10344. {
  10345. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10346. if (pc_cant_act(sd))
  10347. return;
  10348. if (pc_issit(sd))
  10349. return;
  10350. clif_parse_UseSkillToPosSub(fd, sd,
  10351. RFIFOW(fd,info->pos[0]), //Skill lv
  10352. RFIFOW(fd,info->pos[1]), //Skill num
  10353. RFIFOW(fd,info->pos[2]), //pos x
  10354. RFIFOW(fd,info->pos[3]), //pos y
  10355. info->pos[4] //skill more info
  10356. );
  10357. }
  10358. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10359. /// 011b <skill id>.W <map name>.16B
  10360. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10361. {
  10362. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10363. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10364. char map_name[MAP_NAME_LENGTH];
  10365. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10366. if(skill_id != sd->menuskill_id)
  10367. return;
  10368. //It is possible to use teleport with the storage window open bugreport:8027
  10369. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10370. clif_menuskill_clear(sd);
  10371. return;
  10372. }
  10373. pc_delinvincibletimer(sd);
  10374. skill_castend_map(sd,skill_id,map_name);
  10375. }
  10376. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10377. /// 011d
  10378. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10379. {
  10380. if (!pc_isdead(sd))
  10381. pc_memo(sd,-1);
  10382. }
  10383. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10384. /// 018e <name id>.W { <material id>.W }*3
  10385. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10386. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10387. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10388. int slot1 = RFIFOW(fd,info->pos[1]);
  10389. int slot2 = RFIFOW(fd,info->pos[2]);
  10390. int slot3 = RFIFOW(fd,info->pos[3]);
  10391. short produce_idx = -1;
  10392. switch( sd->menuskill_id ) {
  10393. case -1:
  10394. case AM_PHARMACY:
  10395. case RK_RUNEMASTERY:
  10396. case GC_RESEARCHNEWPOISON:
  10397. break;
  10398. default:
  10399. return;
  10400. }
  10401. if (pc_istrading(sd)) {
  10402. //Make it fail to avoid shop exploits where you sell something different than you see.
  10403. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10404. clif_menuskill_clear(sd);
  10405. return;
  10406. }
  10407. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10408. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10409. clif_menuskill_clear(sd);
  10410. }
  10411. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10412. /// 025b <mk type>.W <name id>.W
  10413. /// mk type:
  10414. /// 1 = cooking
  10415. /// 2 = arrow
  10416. /// 3 = elemental
  10417. /// 4 = GN_MIX_COOKING
  10418. /// 5 = GN_MAKEBOMB
  10419. /// 6 = GN_S_PHARMACY
  10420. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10421. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10422. int type = RFIFOW(fd,info->pos[0]);
  10423. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10424. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10425. short food_idx = -1;
  10426. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10427. return;
  10428. if (pc_istrading(sd)) {
  10429. //Make it fail to avoid shop exploits where you sell something different than you see.
  10430. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10431. clif_menuskill_clear(sd);
  10432. return;
  10433. }
  10434. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10435. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10436. clif_menuskill_clear(sd);
  10437. }
  10438. /// Answer to repair weapon item selection dialog
  10439. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10440. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10441. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10442. {
  10443. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10444. return;
  10445. if (pc_istrading(sd)) {
  10446. //Make it fail to avoid shop exploits where you sell something different than you see.
  10447. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10448. clif_menuskill_clear(sd);
  10449. return;
  10450. }
  10451. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10452. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10453. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10454. //for(i = 0; i<MAX_SLOTS; i++)
  10455. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10456. clif_menuskill_clear(sd);
  10457. }
  10458. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10459. /// 0222 <index>.L
  10460. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10461. {
  10462. int idx;
  10463. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10464. return;
  10465. if (pc_istrading(sd)) {
  10466. //Make it fail to avoid shop exploits where you sell something different than you see.
  10467. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10468. clif_menuskill_clear(sd);
  10469. return;
  10470. }
  10471. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10472. skill_weaponrefine(sd, idx-2);
  10473. clif_menuskill_clear(sd);
  10474. }
  10475. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10476. /// 00b8 <npc id>.L <choice>.B
  10477. /// choice:
  10478. /// 1~254 = menu item
  10479. /// 255 = cancel
  10480. /// NOTE: If there were more than 254 items in the list, choice
  10481. /// overflows to choice%256.
  10482. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10483. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10484. int npc_id = RFIFOL(fd,info->pos[0]);
  10485. uint8 select = RFIFOB(fd,info->pos[1]);
  10486. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10487. #ifdef SECURE_NPCTIMEOUT
  10488. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10489. #endif
  10490. TBL_NPC* nd = map_id2nd(npc_id);
  10491. 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);
  10492. clif_GM_kick(NULL,sd);
  10493. #ifdef SECURE_NPCTIMEOUT
  10494. }
  10495. #endif
  10496. return;
  10497. }
  10498. sd->npc_menu = select;
  10499. npc_scriptcont(sd,npc_id, false);
  10500. }
  10501. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10502. /// 00b9 <npc id>.L
  10503. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10504. {
  10505. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10506. }
  10507. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10508. /// 0143 <npc id>.L <value>.L
  10509. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10510. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10511. int npcid = RFIFOL(fd,info->pos[0]);
  10512. int amount = (int)RFIFOL(fd,info->pos[1]);
  10513. sd->npc_amount = amount;
  10514. npc_scriptcont(sd, npcid, false);
  10515. }
  10516. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10517. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10518. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10519. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10520. int message_len = RFIFOW(fd,info->pos[0])-8;
  10521. int npcid = RFIFOL(fd,info->pos[1]);
  10522. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10523. if( message_len <= 0 )
  10524. return; // invalid input
  10525. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10526. npc_scriptcont(sd, npcid, false);
  10527. }
  10528. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10529. /// 0146 <npc id>.L
  10530. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10531. {
  10532. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10533. return;
  10534. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10535. }
  10536. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10537. /// 0178 <index>.W
  10538. /// index:
  10539. /// -1 = cancel
  10540. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10541. {
  10542. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10543. if (sd->menuskill_id != MC_IDENTIFY)
  10544. return;
  10545. if( idx == -1 ) {// cancel pressed
  10546. clif_menuskill_clear(sd);
  10547. return;
  10548. }
  10549. skill_identify(sd,idx-2);
  10550. clif_menuskill_clear(sd);
  10551. }
  10552. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10553. /// 01ae <name id>.W
  10554. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10555. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10556. if (pc_istrading(sd)) {
  10557. //Make it fail to avoid shop exploits where you sell something different than you see.
  10558. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10559. clif_menuskill_clear(sd);
  10560. return;
  10561. }
  10562. switch (sd->menuskill_id) {
  10563. case AC_MAKINGARROW:
  10564. skill_arrow_create(sd,nameid);
  10565. break;
  10566. case SA_CREATECON:
  10567. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10568. break;
  10569. case WL_READING_SB:
  10570. skill_spellbook(sd,nameid);
  10571. break;
  10572. case GC_POISONINGWEAPON:
  10573. skill_poisoningweapon(sd,nameid);
  10574. break;
  10575. case NC_MAGICDECOY:
  10576. skill_magicdecoy(sd,nameid);
  10577. break;
  10578. }
  10579. clif_menuskill_clear(sd);
  10580. }
  10581. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10582. /// 01ce <skill id>.L
  10583. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10584. {
  10585. if (sd->menuskill_id != SA_AUTOSPELL)
  10586. return;
  10587. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10588. clif_menuskill_clear(sd);
  10589. }
  10590. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10591. /// 017a <card index>.W
  10592. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10593. {
  10594. if (sd->state.trading != 0)
  10595. return;
  10596. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10597. }
  10598. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10599. /// 017c <card index>.W <equip index>.W
  10600. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10601. {
  10602. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10603. if (sd->state.trading != 0)
  10604. return;
  10605. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10606. }
  10607. /// Request of character's name by char ID.
  10608. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10609. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10610. /// There are various variants of this packet, some of them have padding between fields.
  10611. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10612. {
  10613. int charid;
  10614. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10615. map_reqnickdb(sd, charid);
  10616. }
  10617. /// /resetskill /resetstate (CZ_RESET).
  10618. /// Request to reset stats or skills.
  10619. /// 0197 <type>.W
  10620. /// type:
  10621. /// 0 = state
  10622. /// 1 = skill
  10623. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10624. char cmd[15];
  10625. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10626. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10627. else
  10628. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10629. is_atcommand(fd, sd, cmd, 1);
  10630. }
  10631. /// /lb /nlb (CZ_LOCALBROADCAST).
  10632. /// Request to broadcast a message on current map.
  10633. /// 019c <packet len>.W <text>.?B
  10634. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10635. {
  10636. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10637. char command[CHAT_SIZE_MAX+16];
  10638. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10639. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10640. // as the length varies depending on the command used, just block unreasonably long strings
  10641. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10642. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10643. is_atcommand(fd, sd, command, 1);
  10644. }
  10645. /// Request to move an item from inventory to storage.
  10646. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10647. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10648. /// There are various variants of this packet, some of them have padding between fields.
  10649. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10650. {
  10651. int item_index, item_amount;
  10652. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10653. if (pc_istrading(sd))
  10654. return;
  10655. item_index = RFIFOW(fd,info->pos[0])-2;
  10656. item_amount = RFIFOL(fd,info->pos[1]);
  10657. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10658. return;
  10659. if (sd->state.storage_flag == 1)
  10660. storage_storageadd(sd, item_index, item_amount);
  10661. else
  10662. if (sd->state.storage_flag == 2)
  10663. gstorage_storageadd(sd, item_index, item_amount);
  10664. }
  10665. /// Request to move an item from storage to inventory.
  10666. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10667. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10668. /// There are various variants of this packet, some of them have padding between fields.
  10669. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10670. {
  10671. int item_index, item_amount;
  10672. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10673. item_index = RFIFOW(fd,info->pos[0])-1;
  10674. item_amount = RFIFOL(fd,info->pos[1]);
  10675. if (sd->state.storage_flag == 1)
  10676. storage_storageget(sd, item_index, item_amount);
  10677. else if(sd->state.storage_flag == 2)
  10678. gstorage_storageget(sd, item_index, item_amount);
  10679. }
  10680. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10681. /// 0129 <index>.W <amount>.L
  10682. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10683. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10684. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10685. int amount = RFIFOL(fd,info->pos[1]);
  10686. if( sd->state.vending )
  10687. return;
  10688. if (!pc_iscarton(sd))
  10689. return;
  10690. if (sd->state.storage_flag == 1)
  10691. storage_storageaddfromcart(sd, idx, amount);
  10692. else if (sd->state.storage_flag == 2)
  10693. gstorage_storageaddfromcart(sd, idx, amount);
  10694. }
  10695. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10696. /// 0128 <index>.W <amount>.L
  10697. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10698. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10699. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10700. int amount = RFIFOL(fd,info->pos[1]);
  10701. if( sd->state.vending )
  10702. return;
  10703. if (!pc_iscarton(sd))
  10704. return;
  10705. if (sd->state.storage_flag == 1)
  10706. storage_storagegettocart(sd, idx, amount);
  10707. else
  10708. if (sd->state.storage_flag == 2)
  10709. gstorage_storagegettocart(sd, idx, amount);
  10710. }
  10711. /// Request to close storage (CZ_CLOSE_STORE).
  10712. /// 00f7
  10713. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10714. {
  10715. if( sd->state.storage_flag == 1 )
  10716. storage_storageclose(sd);
  10717. else
  10718. if( sd->state.storage_flag == 2 )
  10719. gstorage_storageclose(sd);
  10720. }
  10721. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10722. /// 023a <info>.W
  10723. /// info:
  10724. /// 0 = password has not been set yet
  10725. /// 1 = storage is password-protected
  10726. /// 8 = too many wrong passwords
  10727. /// ? = ignored
  10728. /// NOTE: This packet is only available on certain non-kRO clients.
  10729. void clif_storagepassword(struct map_session_data* sd, short info)
  10730. {
  10731. int fd = sd->fd;
  10732. WFIFOHEAD(fd,packet_len(0x23a));
  10733. WFIFOW(fd,0) = 0x23a;
  10734. WFIFOW(fd,2) = info;
  10735. WFIFOSET(fd,packet_len(0x23a));
  10736. }
  10737. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10738. /// 023b <type>.W <password>.16B <new password>.16B
  10739. /// type:
  10740. /// 2 = change password
  10741. /// 3 = check password
  10742. /// NOTE: This packet is only available on certain non-kRO clients.
  10743. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10744. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10745. // int type = RFIFOW(fd,info->pos[0]);
  10746. // char* password = RFIFOP(fd,info->pos[1]);
  10747. // char* new_password = RFIFOP(fd,info->pos[2]);
  10748. // storage_changepass(sd,password,new_password);
  10749. }
  10750. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10751. /// 023c <result>.W <error count>.W
  10752. /// result:
  10753. /// 4 = password change success
  10754. /// 5 = password change failure
  10755. /// 6 = password check success
  10756. /// 7 = password check failure
  10757. /// 8 = too many wrong passwords
  10758. /// ? = ignored
  10759. /// NOTE: This packet is only available on certain non-kRO clients.
  10760. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10761. {
  10762. int fd = sd->fd;
  10763. WFIFOHEAD(fd,packet_len(0x23c));
  10764. WFIFOW(fd,0) = 0x23c;
  10765. WFIFOW(fd,2) = result;
  10766. WFIFOW(fd,4) = error_count;
  10767. WFIFOSET(fd,packet_len(0x23c));
  10768. }
  10769. /// Party creation request
  10770. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10771. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10772. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10773. name[NAME_LENGTH-1] = '\0';
  10774. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10775. clif_displaymessage(fd, msg_txt(sd,227));
  10776. return;
  10777. }
  10778. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10779. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10780. return;
  10781. }
  10782. party_create(sd,name,0,0);
  10783. }
  10784. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10785. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10786. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10787. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10788. int item1 = RFIFOB(fd,info->pos[1]);
  10789. int item2 = RFIFOB(fd,info->pos[2]);
  10790. name[NAME_LENGTH-1] = '\0';
  10791. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10792. clif_displaymessage(fd, msg_txt(sd,227));
  10793. return;
  10794. }
  10795. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10796. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10797. return;
  10798. }
  10799. party_create(sd,name,item1,item2);
  10800. }
  10801. /// Party invitation request
  10802. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10803. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10804. {
  10805. struct map_session_data *t_sd;
  10806. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10807. clif_displaymessage(fd, msg_txt(sd,227));
  10808. return;
  10809. }
  10810. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10811. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10812. clif_noask_sub(sd, t_sd, 1);
  10813. return;
  10814. }
  10815. party_invite(sd, t_sd);
  10816. }
  10817. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10818. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10819. struct map_session_data *t_sd;
  10820. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10821. name[NAME_LENGTH-1] = '\0';
  10822. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10823. clif_displaymessage(fd, msg_txt(sd,227));
  10824. return;
  10825. }
  10826. t_sd = map_nick2sd(name);
  10827. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10828. clif_noask_sub(sd, t_sd, 1);
  10829. return;
  10830. }
  10831. party_invite(sd, t_sd);
  10832. }
  10833. /// Party invitation reply
  10834. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10835. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10836. /// flag:
  10837. /// 0 = reject
  10838. /// 1 = accept
  10839. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10840. {
  10841. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10842. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10843. RFIFOL(fd,info->pos[1]));
  10844. }
  10845. //(CZ_PARTY_JOIN_REQ_ACK)
  10846. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10847. {
  10848. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10849. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10850. RFIFOB(fd,info->pos[1]));
  10851. }
  10852. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10853. /// 0100
  10854. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10855. {
  10856. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10857. clif_displaymessage(fd, msg_txt(sd,227));
  10858. return;
  10859. }
  10860. party_leave(sd);
  10861. }
  10862. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10863. /// 0103 <account id>.L <char name>.24B
  10864. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10865. {
  10866. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10867. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10868. clif_displaymessage(fd, msg_txt(sd,227));
  10869. return;
  10870. }
  10871. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10872. (char*)RFIFOP(fd,info->pos[1]));
  10873. }
  10874. /// Request to change party options.
  10875. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10876. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10877. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10878. {
  10879. struct party_data *p;
  10880. int i,expflag;
  10881. int cmd = RFIFOW(fd,0);
  10882. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10883. if( !sd->status.party_id )
  10884. return;
  10885. p = party_search(sd->status.party_id);
  10886. if( p == NULL )
  10887. return;
  10888. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10889. if( i == MAX_PARTY )
  10890. return; //Shouldn't happen
  10891. if( !p->party.member[i].leader )
  10892. return;
  10893. expflag = RFIFOL(fd,info->pos[0]);
  10894. if(cmd == 0x0102){ //Client can't change the item-field
  10895. party_changeoption(sd, expflag, p->party.item);
  10896. }
  10897. else {
  10898. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10899. party_changeoption(sd, expflag, itemflag);
  10900. }
  10901. }
  10902. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10903. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10904. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10905. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10906. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10907. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10908. char *name, *message;
  10909. int namelen, messagelen;
  10910. // validate packet and retrieve name and message
  10911. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10912. return;
  10913. if( is_atcommand(fd, sd, message, 1) )
  10914. return;
  10915. if (sd->sc.cant.chat)
  10916. return; //no "chatting" while muted.
  10917. if( battle_config.min_chat_delay )
  10918. { //[Skotlex]
  10919. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10920. return;
  10921. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10922. }
  10923. if (battle_config.idletime_option&IDLE_CHAT)
  10924. sd->idletime = last_tick;
  10925. party_send_message(sd, text, textlen);
  10926. }
  10927. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10928. /// 07da <account id>.L
  10929. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10930. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10931. }
  10932. /// Party Booking in KRO [Spiria]
  10933. ///
  10934. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10935. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10936. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10937. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10938. short level = RFIFOW(fd,info->pos[0]);
  10939. short mapid = RFIFOW(fd,info->pos[1]);
  10940. int idxpbj = info->pos[2];
  10941. short job[PARTY_BOOKING_JOBS];
  10942. int i;
  10943. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10944. job[i] = RFIFOB(fd,idxpbj+i*2);
  10945. party_booking_register(sd, level, mapid, job);
  10946. }
  10947. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10948. /// 0803 <result>.W
  10949. /// result:
  10950. /// 0 = success
  10951. /// 1 = failure
  10952. /// 2 = already registered
  10953. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10954. {
  10955. int fd = sd->fd;
  10956. WFIFOHEAD(fd,packet_len(0x803));
  10957. WFIFOW(fd,0) = 0x803;
  10958. WFIFOW(fd,2) = flag;
  10959. WFIFOSET(fd,packet_len(0x803));
  10960. }
  10961. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10962. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10963. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10964. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10965. short level = RFIFOW(fd,info->pos[0]);
  10966. short mapid = RFIFOW(fd,info->pos[1]);
  10967. short job = RFIFOW(fd,info->pos[2]);
  10968. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10969. short resultcount = RFIFOW(fd,info->pos[4]);
  10970. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10971. }
  10972. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10973. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10974. /// more results:
  10975. /// 0 = no
  10976. /// 1 = yes
  10977. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10978. {
  10979. int i, j;
  10980. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10981. struct party_booking_ad_info *pb_ad;
  10982. WFIFOHEAD(fd,size*count + 5);
  10983. WFIFOW(fd,0) = 0x805;
  10984. WFIFOW(fd,2) = size*count + 5;
  10985. WFIFOB(fd,4) = more_result;
  10986. for(i=0; i<count; i++)
  10987. {
  10988. pb_ad = results[i];
  10989. WFIFOL(fd,i*size+5) = pb_ad->index;
  10990. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10991. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10992. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10993. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10994. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10995. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10996. }
  10997. WFIFOSET(fd,WFIFOW(fd,2));
  10998. }
  10999. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11000. /// 0806
  11001. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11002. {
  11003. if(party_booking_delete(sd))
  11004. clif_PartyBookingDeleteAck(sd, 0);
  11005. }
  11006. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11007. /// 0807 <result>.W
  11008. /// result:
  11009. /// 0 = success
  11010. /// 1 = success (auto-removed expired ad)
  11011. /// 2 = failure
  11012. /// 3 = nothing registered
  11013. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11014. {
  11015. int fd = sd->fd;
  11016. WFIFOHEAD(fd,packet_len(0x807));
  11017. WFIFOW(fd,0) = 0x807;
  11018. WFIFOW(fd,2) = flag;
  11019. WFIFOSET(fd,packet_len(0x807));
  11020. }
  11021. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11022. /// 0808 { <job>.W }*6
  11023. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11024. {
  11025. short job[PARTY_BOOKING_JOBS];
  11026. int i;
  11027. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  11028. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  11029. job[i] = RFIFOW(fd,idxpbu+i*2);
  11030. party_booking_update(sd, job);
  11031. }
  11032. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11033. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11034. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11035. {
  11036. int i;
  11037. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  11038. if(pb_ad == NULL) return;
  11039. WBUFW(buf,0) = 0x809;
  11040. WBUFL(buf,2) = pb_ad->index;
  11041. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  11042. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11043. WBUFW(buf,34) = pb_ad->p_detail.level;
  11044. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11045. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  11046. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11047. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11048. }
  11049. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11050. /// 080a <index>.L { <job>.W }*6
  11051. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11052. {
  11053. int i;
  11054. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  11055. if(pb_ad == NULL) return;
  11056. WBUFW(buf,0) = 0x80a;
  11057. WBUFL(buf,2) = pb_ad->index;
  11058. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  11059. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11060. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11061. }
  11062. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11063. /// 080b <index>.L
  11064. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11065. {
  11066. uint8 buf[6];
  11067. WBUFW(buf,0) = 0x80b;
  11068. WBUFL(buf,2) = index;
  11069. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11070. }
  11071. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11072. /// 012e
  11073. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11074. {
  11075. vending_closevending(sd);
  11076. }
  11077. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11078. /// 0130 <account id>.L
  11079. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11080. {
  11081. if( sd->npc_id ) {// using an NPC
  11082. return;
  11083. }
  11084. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11085. }
  11086. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11087. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11088. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11089. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11090. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11091. int id = (int)RFIFOL(fd,info->pos[1]);
  11092. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11093. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11094. // whether it fails or not, the buy window is closed
  11095. sd->vended_id = 0;
  11096. }
  11097. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11098. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11099. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11100. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11101. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11102. int aid = (int)RFIFOL(fd,info->pos[1]);
  11103. int uid = (int)RFIFOL(fd,info->pos[2]);
  11104. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11105. vending_purchasereq(sd, aid, uid, data, len/4);
  11106. // whether it fails or not, the buy window is closed
  11107. sd->vended_id = 0;
  11108. }
  11109. /// Confirm or cancel the shop preparation window.
  11110. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11111. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11112. /// result:
  11113. /// 0 = canceled
  11114. /// 1 = open
  11115. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11116. int cmd = RFIFOW(fd,0);
  11117. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  11118. short len = (short)RFIFOW(fd,info->pos[0]);
  11119. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  11120. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11121. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11122. len -= 84;
  11123. }
  11124. else { //(CZ_REQ_OPENSTORE2)
  11125. bool flag;
  11126. len -= 85;
  11127. flag = (bool)RFIFOB(fd,info->pos[2]);
  11128. if( !flag )
  11129. sd->state.prevend = 0;
  11130. }
  11131. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11132. return;
  11133. if( map[sd->bl.m].flag.novending ) {
  11134. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11135. return;
  11136. }
  11137. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11138. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11139. return;
  11140. }
  11141. if( message[0] == '\0' ) // invalid input
  11142. return;
  11143. vending_openvending(sd, message, data, len/8, NULL);
  11144. }
  11145. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11146. /// 0165 <char id>.L <guild name>.24B
  11147. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11148. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11149. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11150. name[NAME_LENGTH-1] = '\0';
  11151. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11152. clif_displaymessage(fd, msg_txt(sd,228));
  11153. return;
  11154. }
  11155. guild_create(sd, name);
  11156. }
  11157. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11158. /// 014d
  11159. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11160. {
  11161. clif_guild_masterormember(sd);
  11162. }
  11163. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11164. /// 014f <type>.L
  11165. /// type:
  11166. /// 0 = basic info
  11167. /// 1 = member manager
  11168. /// 2 = positions
  11169. /// 3 = skills
  11170. /// 4 = expulsion list
  11171. /// 5 = unknown (GM_ALLGUILDLIST)
  11172. /// 6 = notice
  11173. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11174. {
  11175. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11176. if( !sd->status.guild_id && !sd->bg_id )
  11177. return;
  11178. switch( type )
  11179. {
  11180. case 0: // Basic Information Guild, hostile alliance information
  11181. clif_guild_basicinfo(sd);
  11182. clif_guild_allianceinfo(sd);
  11183. break;
  11184. case 1: // Members list, list job title
  11185. clif_guild_positionnamelist(sd);
  11186. clif_guild_memberlist(sd);
  11187. break;
  11188. case 2: // List job title, title information list
  11189. clif_guild_positionnamelist(sd);
  11190. clif_guild_positioninfolist(sd);
  11191. break;
  11192. case 3: // Skill list
  11193. clif_guild_skillinfo(sd);
  11194. break;
  11195. case 4: // Expulsion list
  11196. clif_guild_expulsionlist(sd);
  11197. break;
  11198. default:
  11199. ShowError("clif: guild request info: unknown type %d\n", type);
  11200. break;
  11201. }
  11202. }
  11203. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11204. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11205. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11206. {
  11207. int i;
  11208. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11209. int len = RFIFOW(fd,info->pos[0]);
  11210. int idxgpos = info->pos[1];
  11211. if(!sd->state.gmaster_flag)
  11212. return;
  11213. for(i = idxgpos; i < len; i += 40 ){
  11214. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  11215. }
  11216. }
  11217. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11218. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11219. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11220. {
  11221. int i;
  11222. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11223. int len = RFIFOW(fd,info->pos[0]);
  11224. int idxgpos = info->pos[1];
  11225. if(!sd->state.gmaster_flag)
  11226. return;
  11227. for(i=idxgpos;i<len;i+=12){
  11228. guild_change_memberposition(sd->status.guild_id,
  11229. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11230. }
  11231. }
  11232. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11233. /// 0151 <guild id>.L
  11234. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11235. {
  11236. struct guild* g;
  11237. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11238. if( (g = guild_search(guild_id)) != NULL )
  11239. clif_guild_emblem(sd,g);
  11240. }
  11241. /// Validates data of a guild emblem (compressed bitmap)
  11242. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11243. {
  11244. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11245. unsigned long buf_len = sizeof(buf);
  11246. int offset = 0;
  11247. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11248. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11249. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11250. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11251. ))
  11252. return -1;
  11253. if(battle_config.emblem_transparency_limit != 100) {
  11254. int i, transcount = 1, tmp[3];
  11255. for(i = offset; i < buf_len-1; i++) {
  11256. int j = i%3;
  11257. tmp[j] = RBUFL(buf,i);
  11258. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11259. transcount++;
  11260. }
  11261. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11262. return -2;
  11263. }
  11264. return 0;
  11265. }
  11266. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11267. /// 0153 <packet len>.W <emblem data>.?B
  11268. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11269. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11270. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11271. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11272. int emb_val=0;
  11273. if( !emblem_len || !sd->state.gmaster_flag )
  11274. return;
  11275. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  11276. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  11277. return;
  11278. }
  11279. emb_val = clif_validate_emblem(emblem, emblem_len);
  11280. if(emb_val ==-1 ){
  11281. 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);
  11282. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11283. return;
  11284. } else if(emb_val == -2){
  11285. char output[128];
  11286. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11287. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11288. return;
  11289. }
  11290. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11291. }
  11292. /// Guild notice update request (CZ_GUILD_NOTICE).
  11293. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11294. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11295. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11296. int guild_id = RFIFOL(fd,info->pos[0]);
  11297. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11298. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11299. if(!sd->state.gmaster_flag)
  11300. return;
  11301. // compensate for some client defects when using multilanguage mode
  11302. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11303. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11304. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11305. guild_change_notice(sd, guild_id, msg1, msg2);
  11306. }
  11307. // Helper function for guild invite functions
  11308. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11309. {
  11310. if (t_sd == NULL) // not online or does not exist
  11311. return 1;
  11312. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11313. clif_displaymessage(fd, msg_txt(sd,228));
  11314. return 1;
  11315. }
  11316. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11317. clif_noask_sub(sd, t_sd, 2);
  11318. return 1;
  11319. }
  11320. guild_invite(sd, t_sd);
  11321. return 0;
  11322. }
  11323. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11324. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11325. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11326. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11327. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11328. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11329. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11330. if (clif_sub_guild_invite(fd, sd, t_sd))
  11331. return;
  11332. }
  11333. /// Guild invite request (/guildinvite)
  11334. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11335. void
  11336. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11337. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11338. if (clif_sub_guild_invite(fd, sd, t_sd))
  11339. return;
  11340. }
  11341. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11342. /// 016b <guild id>.L <answer>.L
  11343. /// answer:
  11344. /// 0 = refuse
  11345. /// 1 = accept
  11346. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11347. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11348. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11349. RFIFOL(fd,info->pos[1]));
  11350. }
  11351. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11352. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11353. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11354. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11355. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11356. clif_displaymessage(fd, msg_txt(sd,228));
  11357. return;
  11358. }
  11359. if( sd->bg_id ) {
  11360. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11361. return;
  11362. }
  11363. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11364. RFIFOL(fd,info->pos[1]),
  11365. RFIFOL(fd,info->pos[2]),
  11366. (char*)RFIFOP(fd,info->pos[3]));
  11367. }
  11368. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11369. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11370. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11371. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11372. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11373. { // Guild locked.
  11374. clif_displaymessage(fd, msg_txt(sd,228));
  11375. return;
  11376. }
  11377. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11378. RFIFOL(fd,info->pos[1]),
  11379. RFIFOL(fd,info->pos[2]),
  11380. (char*)RFIFOP(fd,info->pos[3]));
  11381. }
  11382. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11383. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11384. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11385. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11386. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  11387. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  11388. char *name, *message;
  11389. int namelen, messagelen;
  11390. // validate packet and retrieve name and message
  11391. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11392. return;
  11393. if( is_atcommand(fd, sd, message, 1) )
  11394. return;
  11395. if (sd->sc.cant.chat)
  11396. return; //no "chatting" while muted.
  11397. if( battle_config.min_chat_delay )
  11398. { //[Skotlex]
  11399. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  11400. return;
  11401. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11402. }
  11403. if (battle_config.idletime_option&IDLE_CHAT)
  11404. sd->idletime = last_tick;
  11405. if( sd->bg_id )
  11406. bg_send_message(sd, text, textlen);
  11407. else
  11408. guild_send_message(sd, text, textlen);
  11409. }
  11410. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11411. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11412. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11413. {
  11414. struct map_session_data *t_sd;
  11415. if(!sd->state.gmaster_flag)
  11416. return;
  11417. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11418. clif_displaymessage(fd, msg_txt(sd,228));
  11419. return;
  11420. }
  11421. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11422. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11423. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11424. // @noask [LuzZza]
  11425. if(t_sd && t_sd->state.noask) {
  11426. clif_noask_sub(sd, t_sd, 3);
  11427. return;
  11428. }
  11429. guild_reqalliance(sd,t_sd);
  11430. }
  11431. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11432. /// 0172 <inviter account id>.L <answer>.L
  11433. /// answer:
  11434. /// 0 = refuse
  11435. /// 1 = accept
  11436. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11437. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11438. guild_reply_reqalliance(sd,
  11439. RFIFOL(fd,info->pos[0]),
  11440. RFIFOL(fd,info->pos[1]));
  11441. }
  11442. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11443. /// 0183 <opponent guild id>.L <relation>.L
  11444. /// relation:
  11445. /// 0 = Ally
  11446. /// 1 = Enemy
  11447. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11448. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11449. if(!sd->state.gmaster_flag)
  11450. return;
  11451. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11452. clif_displaymessage(fd, msg_txt(sd,228));
  11453. return;
  11454. }
  11455. guild_delalliance(sd,
  11456. RFIFOL(fd,info->pos[0]),
  11457. RFIFOL(fd,info->pos[1]));
  11458. }
  11459. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11460. /// 0180 <account id>.L
  11461. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11462. {
  11463. struct map_session_data *t_sd;
  11464. if(!sd->state.gmaster_flag)
  11465. return;
  11466. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11467. clif_displaymessage(fd, msg_txt(sd,228));
  11468. return;
  11469. }
  11470. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11471. // @noask [LuzZza]
  11472. if(t_sd && t_sd->state.noask) {
  11473. clif_noask_sub(sd, t_sd, 4);
  11474. return;
  11475. }
  11476. guild_opposition(sd,t_sd);
  11477. }
  11478. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11479. /// 015d <key>.40B
  11480. /// key:
  11481. /// now guild name; might have been (intended) email, since the
  11482. /// field name and size is same as the one in CH_DELETE_CHAR.
  11483. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11484. {
  11485. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11486. clif_displaymessage(fd, msg_txt(sd,228));
  11487. return;
  11488. }
  11489. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11490. }
  11491. /// Pet
  11492. ///
  11493. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11494. /// 01a1 <type>.B
  11495. /// type:
  11496. /// 0 = pet information
  11497. /// 1 = feed
  11498. /// 2 = performance
  11499. /// 3 = return to egg
  11500. /// 4 = unequip accessory
  11501. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11502. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11503. }
  11504. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11505. /// 019f <id>.L
  11506. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11507. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11508. }
  11509. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11510. /// 01a7 <index>.W
  11511. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11512. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11513. return;
  11514. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11515. clif_menuskill_clear(sd);
  11516. }
  11517. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11518. /// 01a9 <data>.L
  11519. /// data:
  11520. /// is either emotion (@see enum emotion_type) or a compound value
  11521. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11522. /// entry (given in parentheses) in data\pettalktable.xml
  11523. /// act id:
  11524. /// 0 = feeding
  11525. /// 1 = hunting
  11526. /// 2 = danger
  11527. /// 3 = dead
  11528. /// 4 = normal (stand)
  11529. /// 5 = special performance (perfor_s)
  11530. /// 6 = level up (levelup)
  11531. /// 7 = performance 1 (perfor_1)
  11532. /// 8 = performance 2 (perfor_2)
  11533. /// 9 = performance 3 (perfor_3)
  11534. /// 10 = log-in greeting (connect)
  11535. /// hungry value:
  11536. /// 0 = very hungry (hungry)
  11537. /// 1 = hungry (bit_hungry)
  11538. /// 2 = satisfied (noting)
  11539. /// 3 = stuffed (full)
  11540. /// 4 = full (so_full)
  11541. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11542. {
  11543. if(sd->pd)
  11544. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11545. }
  11546. /// Request to change pet's name (CZ_RENAME_PET).
  11547. /// 01a5 <name>.24B
  11548. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11549. {
  11550. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11551. }
  11552. /// /kill (CZ_DISCONNECT_CHARACTER).
  11553. /// Request to disconnect a character.
  11554. /// 00cc <account id>.L
  11555. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11556. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11557. {
  11558. struct block_list *target;
  11559. int tid;
  11560. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11561. target = map_id2bl(tid);
  11562. if (!target) {
  11563. clif_GM_kickack(sd, 0);
  11564. return;
  11565. }
  11566. switch (target->type) {
  11567. case BL_PC:
  11568. {
  11569. char command[NAME_LENGTH+6];
  11570. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11571. is_atcommand(fd, sd, command, 1);
  11572. }
  11573. break;
  11574. /**
  11575. * This one does not invoke any atcommand, so we need to check for permissions.
  11576. */
  11577. case BL_MOB:
  11578. {
  11579. char command[100];
  11580. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11581. clif_GM_kickack(sd, 0);
  11582. return;
  11583. }
  11584. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11585. log_atcommand(sd, command);
  11586. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11587. }
  11588. break;
  11589. case BL_NPC:
  11590. {
  11591. struct npc_data* nd = (struct npc_data *)target;
  11592. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11593. npc_unload_duplicates(nd);
  11594. npc_unload(nd,true);
  11595. npc_read_event_script();
  11596. }
  11597. }
  11598. break;
  11599. default:
  11600. clif_GM_kickack(sd, 0);
  11601. }
  11602. }
  11603. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11604. /// Request to disconnect all characters.
  11605. /// 00ce
  11606. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11607. char cmd[15];
  11608. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11609. is_atcommand(fd, sd, cmd, 1);
  11610. }
  11611. /// /remove (CZ_REMOVE_AID).
  11612. /// Request to warp to a character with given login ID.
  11613. /// 01ba <account name>.24B
  11614. /// /shift (CZ_SHIFT).
  11615. /// Request to warp to a character with given name.
  11616. /// 01bb <char name>.24B
  11617. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11618. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11619. char *player_name;
  11620. char command[NAME_LENGTH+8];
  11621. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11622. player_name[NAME_LENGTH-1] = '\0';
  11623. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11624. is_atcommand(fd, sd, command, 1);
  11625. }
  11626. /// /remove (CZ_REMOVE_AID_SSO).
  11627. /// Request to warp to a character with given account ID.
  11628. /// 0843 <account id>.L
  11629. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11630. {
  11631. uint32 account_id;
  11632. struct map_session_data* pl_sd;
  11633. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11634. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11635. char command[NAME_LENGTH+8];
  11636. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11637. is_atcommand(fd, sd, command, 1);
  11638. }
  11639. }
  11640. /// /recall (CZ_RECALL).
  11641. /// Request to summon a player with given login ID to own position.
  11642. /// 01bc <account name>.24B
  11643. /// /summon (CZ_RECALL_GID).
  11644. /// Request to summon a player with given name to own position.
  11645. /// 01bd <char name>.24B
  11646. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11647. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11648. char *player_name;
  11649. char command [NAME_LENGTH+8];
  11650. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11651. player_name[NAME_LENGTH-1] = '\0';
  11652. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11653. is_atcommand(fd, sd, command, 1);
  11654. }
  11655. /// /recall (CZ_RECALL_SSO).
  11656. /// Request to summon a player with given account ID to own position.
  11657. /// 0842 <account id>.L
  11658. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11659. {
  11660. uint32 account_id;
  11661. struct map_session_data* pl_sd;
  11662. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11663. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11664. char command[NAME_LENGTH+8];
  11665. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11666. is_atcommand(fd, sd, command, 1);
  11667. }
  11668. }
  11669. /// /item /monster (CZ_ITEM_CREATE).
  11670. /// Request to execute GM commands.
  11671. /// Usage:
  11672. /// /item n - summon n monster or acquire n item/s
  11673. /// /item money - grants 2147483647 zenies
  11674. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11675. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11676. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11677. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11678. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11679. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11680. /// 013f <item/mob name>.24B
  11681. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11682. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11683. {
  11684. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11685. int mob_id = 0;
  11686. struct item_data *id = NULL;
  11687. struct mob_db *mob = NULL;
  11688. StringBuf command;
  11689. char *str;
  11690. //#if PACKETVER >= 20131218
  11691. // char str[100];
  11692. //#else
  11693. // char str[24];
  11694. //#endif
  11695. str = (char*)RFIFOP(fd,info->pos[0]);
  11696. if (!str || str[0] == '\0')
  11697. return;
  11698. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11699. return;
  11700. trim(str);
  11701. // Zeny
  11702. if( strcmpi(str, "money") == 0 ) {
  11703. StringBuf_Init(&command);
  11704. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11705. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11706. StringBuf_Destroy(&command);
  11707. return;
  11708. }
  11709. // Item
  11710. if( (id = itemdb_searchname(str)) ) {
  11711. StringBuf_Init(&command);
  11712. if( !itemdb_isstackable2(id) ) //Nonstackable
  11713. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11714. else {
  11715. if (id->flag.guid)
  11716. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11717. else
  11718. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11719. }
  11720. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11721. StringBuf_Destroy(&command);
  11722. return;
  11723. }
  11724. // Monster
  11725. if ((mob_id = mobdb_searchname(str)) == 0)
  11726. mob_id = mobdb_checkid(atoi(str));
  11727. if( (mob = mob_db(mob_id)) ) {
  11728. StringBuf_Init(&command);
  11729. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11730. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11731. StringBuf_Destroy(&command);
  11732. return;
  11733. }
  11734. }
  11735. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11736. /// 019d <effect state>.L
  11737. /// effect state:
  11738. /// TODO: Any OPTION_* ?
  11739. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11740. char cmd[6];
  11741. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11742. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11743. is_atcommand(fd, sd, cmd, 1);
  11744. }
  11745. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11746. /// 0149 <account id>.L <type>.B <value>.W
  11747. /// type:
  11748. /// 0 = positive points
  11749. /// 1 = negative points
  11750. /// 2 = self mute (+10 minutes)
  11751. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11752. {
  11753. int id, type, value;
  11754. struct map_session_data *dstsd;
  11755. char command[NAME_LENGTH+15];
  11756. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11757. id = RFIFOL(fd,info->pos[0]);
  11758. type = RFIFOB(fd,info->pos[1]);
  11759. value = RFIFOW(fd,info->pos[2]);
  11760. if( type == 0 )
  11761. value = -value;
  11762. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11763. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11764. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11765. return;
  11766. dstsd = map_id2sd(id);
  11767. if( dstsd == NULL )
  11768. return;
  11769. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11770. is_atcommand(fd, sd, command, 1);
  11771. }
  11772. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11773. /// GM adjustment of a player's manner value by -60.
  11774. /// 0212 <char name>.24B
  11775. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11776. {
  11777. char command[NAME_LENGTH+15];
  11778. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11779. name[NAME_LENGTH-1] = '\0';
  11780. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11781. is_atcommand(fd, sd, command, 1);
  11782. }
  11783. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11784. /// 01e0 <account id>.L <account name>.24B
  11785. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11786. {
  11787. WFIFOHEAD(fd,packet_len(0x1e0));
  11788. WFIFOW(fd,0) = 0x1e0;
  11789. WFIFOL(fd,2) = account_id;
  11790. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11791. WFIFOSET(fd,packet_len(0x1e0));
  11792. }
  11793. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11794. /// 01df <account id>.L
  11795. //! TODO: Figure out how does this actually work
  11796. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11797. {
  11798. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11799. /*
  11800. char query[30];
  11801. safesnprintf(query,sizeof(query),"%d", account_id);
  11802. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11803. */
  11804. clif_account_name(fd, account_id, "");
  11805. }
  11806. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11807. /// GM single cell type change request.
  11808. /// 0198 <x>.W <y>.W <type>.W
  11809. /// type:
  11810. /// 0 = not walkable
  11811. /// 1 = walkable
  11812. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11813. {
  11814. int x,y,type;
  11815. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11816. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11817. return;
  11818. x = RFIFOW(fd,info->pos[0]);
  11819. y = RFIFOW(fd,info->pos[1]);
  11820. type = RFIFOW(fd,info->pos[2]);
  11821. map_setgatcell(sd->bl.m,x,y,type);
  11822. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11823. //FIXME: once players leave the map, the client 'forgets' this information.
  11824. }
  11825. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11826. /// Request to allow/deny whispers from a nick.
  11827. /// 00cf <nick>.24B <type>.B
  11828. /// type:
  11829. /// 0 = (/ex nick) deny speech from nick
  11830. /// 1 = (/in nick) allow speech from nick
  11831. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11832. {
  11833. char* nick;
  11834. uint8 type;
  11835. int i;
  11836. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11837. nick = (char*)RFIFOP(fd,info->pos[0]);
  11838. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11839. type = RFIFOB(fd,info->pos[1]);
  11840. if( type == 0 ) { // Add name to ignore list (block)
  11841. if (strcmp(wisp_server_name, nick) == 0) {
  11842. clif_wisexin(sd, type, 1); // fail
  11843. return;
  11844. }
  11845. // try to find a free spot, while checking for duplicates at the same time
  11846. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11847. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11848. clif_wisexin(sd, type, 2); // too many blocks
  11849. return;
  11850. }
  11851. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11852. clif_wisexin(sd, type, 0); // Aegis reports success.
  11853. return;
  11854. }
  11855. //Insert in position i
  11856. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11857. } else { // Remove name from ignore list (unblock)
  11858. // find entry
  11859. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11860. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11861. clif_wisexin(sd, type, 1); // fail
  11862. return;
  11863. }
  11864. // move everything one place down to overwrite removed entry
  11865. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11866. // wipe last entry
  11867. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11868. }
  11869. clif_wisexin(sd, type, 0); // success
  11870. }
  11871. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11872. /// Request to allow/deny all whispers.
  11873. /// 00d0 <type>.B
  11874. /// type:
  11875. /// 0 = (/exall) deny all speech
  11876. /// 1 = (/inall) allow all speech
  11877. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11878. {
  11879. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11880. if( type == 0 ) {// Deny all
  11881. if( sd->state.ignoreAll ) {
  11882. flag = 1; // fail
  11883. } else {
  11884. sd->state.ignoreAll = 1;
  11885. flag = 0; // success
  11886. }
  11887. } else {//Unblock everyone
  11888. if( sd->state.ignoreAll ) {
  11889. sd->state.ignoreAll = 0;
  11890. flag = 0; // success
  11891. } else {
  11892. if (sd->ignore[0].name[0] != '\0')
  11893. { //Wipe the ignore list.
  11894. memset(sd->ignore, 0, sizeof(sd->ignore));
  11895. flag = 0; // success
  11896. } else {
  11897. flag = 1; // fail
  11898. }
  11899. }
  11900. }
  11901. clif_wisall(sd, type, flag);
  11902. }
  11903. /// Whisper ignore list (ZC_WHISPER_LIST).
  11904. /// 00d4 <packet len>.W { <char name>.24B }*
  11905. void clif_PMIgnoreList(struct map_session_data* sd)
  11906. {
  11907. int i, fd = sd->fd;
  11908. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11909. WFIFOW(fd,0) = 0xd4;
  11910. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11911. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11912. }
  11913. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11914. WFIFOSET(fd,WFIFOW(fd,2));
  11915. }
  11916. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11917. /// 00d3
  11918. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11919. {
  11920. clif_PMIgnoreList(sd);
  11921. }
  11922. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11923. /// 01e7
  11924. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11925. {
  11926. if (sd->state.doridori) return;
  11927. switch (sd->class_&MAPID_UPPERMASK) {
  11928. case MAPID_SOUL_LINKER:
  11929. case MAPID_STAR_GLADIATOR:
  11930. case MAPID_TAEKWON:
  11931. if (!sd->state.rest)
  11932. break;
  11933. case MAPID_SUPER_NOVICE:
  11934. case MAPID_SUPER_BABY:
  11935. case MAPID_SUPER_NOVICE_E:
  11936. case MAPID_SUPER_BABY_E:
  11937. sd->state.doridori=1;
  11938. break;
  11939. }
  11940. }
  11941. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11942. /// 01ed
  11943. /// Note: This packet is caused by 7 lines of any text, followed by
  11944. /// the prayer and an another line of any text. The prayer is
  11945. /// defined by lines 790~793 in data\msgstringtable.txt
  11946. /// "Dear angel, can you hear my voice?"
  11947. /// "I am" (space separated player name) "Super Novice~"
  11948. /// "Help me out~ Please~ T_T"
  11949. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11950. {
  11951. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11952. unsigned int next = pc_nextbaseexp(sd);
  11953. if( next == 0 ) next = pc_thisbaseexp(sd);
  11954. if( next ) {
  11955. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11956. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11957. 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]
  11958. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11959. }
  11960. }
  11961. }
  11962. }
  11963. /// Friends List
  11964. ///
  11965. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11966. /// 0206 <account id>.L <char id>.L <state>.B
  11967. /// state:
  11968. /// 0 = online
  11969. /// 1 = offline
  11970. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11971. {
  11972. int i, fd = sd->fd;
  11973. //Seek friend.
  11974. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11975. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11976. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11977. return; //Not found
  11978. WFIFOHEAD(fd,packet_len(0x206));
  11979. WFIFOW(fd, 0) = 0x206;
  11980. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11981. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11982. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11983. WFIFOSET(fd, packet_len(0x206));
  11984. }
  11985. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11986. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11987. {
  11988. uint32 account_id, char_id, online;
  11989. account_id = va_arg(ap, int);
  11990. char_id = va_arg(ap, int);
  11991. online = va_arg(ap, int);
  11992. clif_friendslist_toggle(sd, account_id, char_id, online);
  11993. return 0;
  11994. }
  11995. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11996. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11997. void clif_friendslist_send(struct map_session_data *sd)
  11998. {
  11999. int i = 0, n, fd = sd->fd;
  12000. // Send friends list
  12001. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  12002. WFIFOW(fd, 0) = 0x201;
  12003. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12004. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  12005. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  12006. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  12007. }
  12008. if (i) {
  12009. WFIFOW(fd,2) = 4 + 32 * i;
  12010. WFIFOSET(fd, WFIFOW(fd,2));
  12011. }
  12012. for (n = 0; n < i; n++) { //Sending the online players
  12013. if (map_charid2sd(sd->status.friends[n].char_id))
  12014. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12015. }
  12016. }
  12017. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12018. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12019. /// result:
  12020. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12021. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12022. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12023. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12024. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12025. {
  12026. int fd;
  12027. nullpo_retv(sd);
  12028. fd = sd->fd;
  12029. WFIFOHEAD(fd,packet_len(0x209));
  12030. WFIFOW(fd,0) = 0x209;
  12031. WFIFOW(fd,2) = type;
  12032. if (f_sd) {
  12033. WFIFOL(fd,4) = f_sd->status.account_id;
  12034. WFIFOL(fd,8) = f_sd->status.char_id;
  12035. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12036. }
  12037. WFIFOSET(fd, packet_len(0x209));
  12038. }
  12039. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12040. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12041. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12042. {
  12043. int fd = sd->fd;
  12044. WFIFOHEAD(fd,packet_len(0x207));
  12045. WFIFOW(fd,0) = 0x207;
  12046. WFIFOL(fd,2) = account_id;
  12047. WFIFOL(fd,6) = char_id;
  12048. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  12049. WFIFOSET(fd,packet_len(0x207));
  12050. }
  12051. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12052. /// 0202 <name>.24B
  12053. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12054. {
  12055. struct map_session_data *f_sd;
  12056. int i;
  12057. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12058. // ensure that the request player's friend list is not full
  12059. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12060. if( i == MAX_FRIENDS ) {
  12061. clif_friendslist_reqack(sd, f_sd, 2);
  12062. return;
  12063. }
  12064. // Friend doesn't exist (no player with this name)
  12065. if (f_sd == NULL) {
  12066. clif_displaymessage(fd, msg_txt(sd,3));
  12067. return;
  12068. }
  12069. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12070. return;
  12071. }
  12072. // @noask [LuzZza]
  12073. if(f_sd->state.noask) {
  12074. clif_noask_sub(sd, f_sd, 5);
  12075. return;
  12076. }
  12077. // Friend already exists
  12078. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12079. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12080. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12081. return;
  12082. }
  12083. }
  12084. f_sd->friend_req = sd->status.char_id;
  12085. sd->friend_req = f_sd->status.char_id;
  12086. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12087. }
  12088. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12089. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12090. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12091. /// reply:
  12092. /// 0 = rejected
  12093. /// 1 = accepted
  12094. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12095. {
  12096. struct map_session_data *f_sd;
  12097. uint32 account_id;
  12098. char reply;
  12099. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12100. account_id = RFIFOL(fd,info->pos[0]);
  12101. //char_id = RFIFOL(fd,info->pos[1]);
  12102. if(sd->packet_ver < 6)
  12103. reply = RFIFOB(fd,info->pos[2]);
  12104. else
  12105. reply = RFIFOL(fd,info->pos[2]);
  12106. if( sd->bl.id == account_id ) {// adding oneself as friend
  12107. return;
  12108. }
  12109. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12110. if (f_sd == NULL)
  12111. return;
  12112. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12113. clif_friendslist_reqack(f_sd, sd, 1);
  12114. else {
  12115. int i;
  12116. // Find an empty slot
  12117. for (i = 0; i < MAX_FRIENDS; i++)
  12118. if (f_sd->status.friends[i].char_id == 0)
  12119. break;
  12120. if (i == MAX_FRIENDS) {
  12121. clif_friendslist_reqack(f_sd, sd, 2);
  12122. return;
  12123. }
  12124. f_sd->status.friends[i].account_id = sd->status.account_id;
  12125. f_sd->status.friends[i].char_id = sd->status.char_id;
  12126. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12127. clif_friendslist_reqack(f_sd, sd, 0);
  12128. if (battle_config.friend_auto_add) {
  12129. // Also add f_sd to sd's friendlist.
  12130. for (i = 0; i < MAX_FRIENDS; i++) {
  12131. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12132. return; //No need to add anything.
  12133. if (sd->status.friends[i].char_id == 0)
  12134. break;
  12135. }
  12136. if (i == MAX_FRIENDS) {
  12137. clif_friendslist_reqack(sd, f_sd, 2);
  12138. return;
  12139. }
  12140. sd->status.friends[i].account_id = f_sd->status.account_id;
  12141. sd->status.friends[i].char_id = f_sd->status.char_id;
  12142. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12143. clif_friendslist_reqack(sd, f_sd, 0);
  12144. }
  12145. }
  12146. }
  12147. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12148. /// 0203 <account id>.L <char id>.L
  12149. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12150. {
  12151. struct map_session_data *f_sd = NULL;
  12152. uint32 account_id, char_id;
  12153. int i, j;
  12154. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12155. account_id = RFIFOL(fd,info->pos[0]);
  12156. char_id = RFIFOL(fd,info->pos[1]);
  12157. // Search friend
  12158. for (i = 0; i < MAX_FRIENDS &&
  12159. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12160. if (i == MAX_FRIENDS) {
  12161. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12162. return;
  12163. }
  12164. //remove from friend's list first
  12165. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12166. for (i = 0; i < MAX_FRIENDS &&
  12167. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12168. if (i != MAX_FRIENDS) {
  12169. // move all chars up
  12170. for(j = i + 1; j < MAX_FRIENDS; j++)
  12171. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12172. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12173. //should the guy be notified of some message? we should add it here if so
  12174. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12175. WFIFOW(f_sd->fd,0) = 0x20a;
  12176. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12177. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12178. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12179. }
  12180. } else { //friend not online -- ask char server to delete from his friendlist
  12181. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12182. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12183. return;
  12184. }
  12185. }
  12186. // We can now delete from original requester
  12187. for (i = 0; i < MAX_FRIENDS &&
  12188. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12189. // move all chars up
  12190. for(j = i + 1; j < MAX_FRIENDS; j++)
  12191. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12192. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12193. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12194. WFIFOHEAD(fd,packet_len(0x20a));
  12195. WFIFOW(fd,0) = 0x20a;
  12196. WFIFOL(fd,2) = account_id;
  12197. WFIFOL(fd,6) = char_id;
  12198. WFIFOSET(fd, packet_len(0x20a));
  12199. }
  12200. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12201. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12202. void clif_PVPInfo(struct map_session_data* sd)
  12203. {
  12204. int fd = sd->fd;
  12205. WFIFOHEAD(fd,packet_len(0x210));
  12206. WFIFOW(fd,0) = 0x210;
  12207. WFIFOL(fd,2) = sd->status.char_id;
  12208. WFIFOL(fd,6) = sd->status.account_id;
  12209. WFIFOL(fd,10) = sd->pvp_won; // times won
  12210. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12211. WFIFOL(fd,18) = sd->pvp_point;
  12212. WFIFOSET(fd, packet_len(0x210));
  12213. }
  12214. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12215. /// 020f <char id>.L <account id>.L
  12216. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12217. {
  12218. // TODO: Is there a way to use this on an another player (char/acc id)?
  12219. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12220. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12221. clif_PVPInfo(sd);
  12222. }
  12223. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  12224. /// 0219 { <name>.24B }*10 { <point>.L }*10
  12225. void clif_blacksmith(struct map_session_data* sd)
  12226. {
  12227. int i, fd = sd->fd;
  12228. const char* name;
  12229. WFIFOHEAD(fd,packet_len(0x219));
  12230. WFIFOW(fd,0) = 0x219;
  12231. //Packet size limits this list to 10 elements. [Skotlex]
  12232. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  12233. if (smith_fame_list[i].id > 0) {
  12234. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  12235. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  12236. {
  12237. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  12238. } else
  12239. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  12240. } else
  12241. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  12242. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  12243. }
  12244. for(;i < 10; i++) { //In case the MAX is less than 10.
  12245. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  12246. WFIFOL(fd, 242 + i * 4) = 0;
  12247. }
  12248. WFIFOSET(fd, packet_len(0x219));
  12249. }
  12250. /// /blacksmith (CZ_BLACKSMITH_RANK).
  12251. /// 0217
  12252. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  12253. {
  12254. clif_blacksmith(sd);
  12255. }
  12256. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  12257. /// 021b <points>.L <total points>.L
  12258. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  12259. {
  12260. int fd = sd->fd;
  12261. WFIFOHEAD(fd,packet_len(0x21b));
  12262. WFIFOW(fd,0) = 0x21b;
  12263. WFIFOL(fd,2) = points;
  12264. WFIFOL(fd,6) = sd->status.fame;
  12265. WFIFOSET(fd, packet_len(0x21b));
  12266. }
  12267. /// /alchemist list (ZC_ALCHEMIST_RANK).
  12268. /// 021a { <name>.24B }*10 { <point>.L }*10
  12269. void clif_alchemist(struct map_session_data* sd)
  12270. {
  12271. int i, fd = sd->fd;
  12272. const char* name;
  12273. WFIFOHEAD(fd,packet_len(0x21a));
  12274. WFIFOW(fd,0) = 0x21a;
  12275. //Packet size limits this list to 10 elements. [Skotlex]
  12276. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12277. if (chemist_fame_list[i].id > 0) {
  12278. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  12279. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12280. {
  12281. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12282. } else
  12283. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12284. } else
  12285. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12286. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12287. }
  12288. for(;i < 10; i++) { //In case the MAX is less than 10.
  12289. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12290. WFIFOL(fd, 242 + i * 4) = 0;
  12291. }
  12292. WFIFOSET(fd, packet_len(0x21a));
  12293. }
  12294. /// /alchemist (CZ_ALCHEMIST_RANK).
  12295. /// 0218
  12296. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12297. {
  12298. clif_alchemist(sd);
  12299. }
  12300. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12301. /// 021c <points>.L <total points>.L
  12302. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12303. {
  12304. int fd = sd->fd;
  12305. WFIFOHEAD(fd,packet_len(0x21c));
  12306. WFIFOW(fd,0) = 0x21c;
  12307. WFIFOL(fd,2) = points;
  12308. WFIFOL(fd,6) = sd->status.fame;
  12309. WFIFOSET(fd, packet_len(0x21c));
  12310. }
  12311. /// /taekwon list (ZC_TAEKWON_RANK).
  12312. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12313. void clif_taekwon(struct map_session_data* sd)
  12314. {
  12315. int i, fd = sd->fd;
  12316. const char* name;
  12317. WFIFOHEAD(fd,packet_len(0x226));
  12318. WFIFOW(fd,0) = 0x226;
  12319. //Packet size limits this list to 10 elements. [Skotlex]
  12320. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12321. if (taekwon_fame_list[i].id > 0) {
  12322. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12323. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12324. {
  12325. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12326. } else
  12327. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12328. } else
  12329. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12330. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12331. }
  12332. for(;i < 10; i++) { //In case the MAX is less than 10.
  12333. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12334. WFIFOL(fd, 242 + i * 4) = 0;
  12335. }
  12336. WFIFOSET(fd, packet_len(0x226));
  12337. }
  12338. /// /taekwon (CZ_TAEKWON_RANK).
  12339. /// 0225
  12340. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12341. {
  12342. clif_taekwon(sd);
  12343. }
  12344. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12345. /// 0224 <points>.L <total points>.L
  12346. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12347. {
  12348. int fd = sd->fd;
  12349. WFIFOHEAD(fd,packet_len(0x224));
  12350. WFIFOW(fd,0) = 0x224;
  12351. WFIFOL(fd,2) = points;
  12352. WFIFOL(fd,6) = sd->status.fame;
  12353. WFIFOSET(fd, packet_len(0x224));
  12354. }
  12355. /// /pk list (ZC_KILLER_RANK).
  12356. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12357. void clif_ranking_pk(struct map_session_data* sd)
  12358. {
  12359. int i, fd = sd->fd;
  12360. WFIFOHEAD(fd,packet_len(0x238));
  12361. WFIFOW(fd,0) = 0x238;
  12362. for(i=0;i<10;i++){
  12363. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12364. WFIFOL(fd,i*4+242) = 0;
  12365. }
  12366. WFIFOSET(fd, packet_len(0x238));
  12367. }
  12368. /// /pk (CZ_KILLER_RANK).
  12369. /// 0237
  12370. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12371. {
  12372. clif_ranking_pk(sd);
  12373. }
  12374. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12375. /// 0254 <which>.B
  12376. /// which: (unused atm for security purpose)
  12377. /// 0 = sun
  12378. /// 1 = moon
  12379. /// 2 = star
  12380. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12381. {
  12382. int i;
  12383. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12384. if (sd->menuskill_id != SG_FEEL)
  12385. return;
  12386. i = sd->menuskill_val-1;
  12387. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12388. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12389. sd->feel_map[i].m = sd->bl.m;
  12390. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12391. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12392. // clif_misceffect2(&sd->bl, 0x1b0);
  12393. // clif_misceffect2(&sd->bl, 0x21f);
  12394. clif_feel_info(sd, i, 0);
  12395. clif_menuskill_clear(sd);
  12396. }
  12397. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12398. /// 0253 <which>.B
  12399. /// which:
  12400. /// 0 = sun
  12401. /// 1 = moon
  12402. /// 2 = star
  12403. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12404. {
  12405. WFIFOHEAD(fd,packet_len(0x253));
  12406. WFIFOW(fd,0)=0x253;
  12407. WFIFOB(fd,2)=TOB(skill_lv-1);
  12408. WFIFOSET(fd, packet_len(0x253));
  12409. sd->menuskill_id = SG_FEEL;
  12410. sd->menuskill_val = skill_lv;
  12411. }
  12412. /// Request to change homunculus' name (CZ_RENAME_MER).
  12413. /// 0231 <name>.24B
  12414. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12415. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12416. }
  12417. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12418. /// 0234 <id>.L
  12419. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12420. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12421. struct block_list *bl = NULL;
  12422. struct unit_data *ud = NULL;
  12423. if( sd->md && sd->md->bl.id == id )
  12424. bl = &sd->md->bl;
  12425. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12426. bl = &sd->hd->bl; // Moving Homunculus
  12427. else
  12428. return;
  12429. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12430. ud = unit_bl2ud(bl);
  12431. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12432. }
  12433. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12434. /// 0232 <id>.L <position data>.3B
  12435. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12436. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12437. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12438. struct block_list *bl = NULL;
  12439. short x, y;
  12440. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12441. if( sd->md && sd->md->bl.id == id )
  12442. bl = &sd->md->bl; // Moving Mercenary
  12443. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12444. bl = &sd->hd->bl; // Moving Homunculus
  12445. else
  12446. return;
  12447. unit_walktoxy(bl, x, y, 4);
  12448. }
  12449. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12450. /// 0233 <id>.L <target id>.L <action>.B
  12451. /// action:
  12452. /// always 0
  12453. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12454. {
  12455. struct block_list *bl = NULL;
  12456. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12457. int id = RFIFOL(fd,info->pos[0]);
  12458. int target_id = RFIFOL(fd,info->pos[1]);
  12459. int action_type = RFIFOB(fd,info->pos[2]);
  12460. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12461. bl = &sd->hd->bl;
  12462. else if( sd->md && sd->md->bl.id == id )
  12463. bl = &sd->md->bl;
  12464. else return;
  12465. unit_stop_attack(bl);
  12466. unit_attack(bl, target_id, action_type != 0);
  12467. }
  12468. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12469. /// 022d <type>.W <command>.B
  12470. /// type:
  12471. /// always 0
  12472. /// command:
  12473. /// 0 = homunculus information
  12474. /// 1 = feed
  12475. /// 2 = delete
  12476. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12477. { //[orn]
  12478. int cmd = RFIFOW(fd,0);
  12479. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12480. if(!hom_is_active(sd->hd))
  12481. return;
  12482. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12483. }
  12484. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12485. /// 0292
  12486. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12487. {
  12488. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12489. uint8 hp = 100, sp = 100;
  12490. if (item_position < 0) {
  12491. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12492. // HP restored
  12493. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12494. sp = 0;
  12495. }
  12496. else
  12497. return;
  12498. }
  12499. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12500. return;
  12501. if (!status_revive(&sd->bl, hp, sp))
  12502. return;
  12503. if (item_position < 0)
  12504. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12505. else
  12506. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12507. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12508. }
  12509. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12510. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12511. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12512. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12513. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12514. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12515. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12516. void clif_check(int fd, struct map_session_data* pl_sd)
  12517. {
  12518. WFIFOHEAD(fd,packet_len(0x214));
  12519. WFIFOW(fd, 0) = 0x214;
  12520. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12521. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12522. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12523. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12524. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12525. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12526. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12527. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12528. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12529. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12530. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12531. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12532. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12533. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12534. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12535. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12536. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12537. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12538. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12539. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12540. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12541. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12542. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12543. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12544. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12545. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12546. WFIFOSET(fd,packet_len(0x214));
  12547. }
  12548. /// /check (CZ_REQ_STATUS_GM).
  12549. /// Request character's status values.
  12550. /// 0213 <char name>.24B
  12551. void clif_parse_Check(int fd, struct map_session_data *sd)
  12552. {
  12553. char charname[NAME_LENGTH];
  12554. struct map_session_data* pl_sd;
  12555. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12556. return;
  12557. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12558. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12559. {
  12560. return;
  12561. }
  12562. clif_check(fd, pl_sd);
  12563. }
  12564. /// MAIL SYSTEM
  12565. /// By Zephyrus
  12566. ///
  12567. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12568. /// 0255 <index>.W <result>.B
  12569. /// result:
  12570. /// 0 = success
  12571. /// 1 = failure
  12572. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12573. {
  12574. WFIFOHEAD(fd,packet_len(0x255));
  12575. WFIFOW(fd,0) = 0x255;
  12576. WFIFOW(fd,2) = index;
  12577. WFIFOB(fd,4) = flag;
  12578. WFIFOSET(fd,packet_len(0x255));
  12579. }
  12580. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12581. /// 0245 <result>.B
  12582. /// result:
  12583. /// 0 = success
  12584. /// 1 = failure
  12585. /// 2 = too many items
  12586. void clif_Mail_getattachment(int fd, uint8 result)
  12587. {
  12588. WFIFOHEAD(fd,packet_len(0x245));
  12589. WFIFOW(fd,0) = 0x245;
  12590. WFIFOB(fd,2) = result;
  12591. WFIFOSET(fd,packet_len(0x245));
  12592. }
  12593. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12594. /// 0249 <result>.B
  12595. /// result:
  12596. /// 0 = success
  12597. /// 1 = recipinent does not exist
  12598. void clif_Mail_send(int fd, bool fail)
  12599. {
  12600. WFIFOHEAD(fd,packet_len(0x249));
  12601. WFIFOW(fd,0) = 0x249;
  12602. WFIFOB(fd,2) = fail;
  12603. WFIFOSET(fd,packet_len(0x249));
  12604. }
  12605. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12606. /// 0257 <mail id>.L <result>.W
  12607. /// result:
  12608. /// 0 = success
  12609. /// 1 = failure
  12610. void clif_Mail_delete(int fd, int mail_id, short fail)
  12611. {
  12612. WFIFOHEAD(fd, packet_len(0x257));
  12613. WFIFOW(fd,0) = 0x257;
  12614. WFIFOL(fd,2) = mail_id;
  12615. WFIFOW(fd,6) = fail;
  12616. WFIFOSET(fd, packet_len(0x257));
  12617. }
  12618. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12619. /// 0274 <mail id>.L <result>.W
  12620. /// result:
  12621. /// 0 = success
  12622. /// 1 = failure
  12623. void clif_Mail_return(int fd, int mail_id, short fail)
  12624. {
  12625. WFIFOHEAD(fd,packet_len(0x274));
  12626. WFIFOW(fd,0) = 0x274;
  12627. WFIFOL(fd,2) = mail_id;
  12628. WFIFOW(fd,6) = fail;
  12629. WFIFOSET(fd,packet_len(0x274));
  12630. }
  12631. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12632. /// 024a <mail id>.L <title>.40B <sender>.24B
  12633. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12634. {
  12635. WFIFOHEAD(fd,packet_len(0x24a));
  12636. WFIFOW(fd,0) = 0x24a;
  12637. WFIFOL(fd,2) = mail_id;
  12638. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12639. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12640. WFIFOSET(fd,packet_len(0x24a));
  12641. }
  12642. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12643. /// 0260 <type>.L
  12644. /// type:
  12645. /// 0 = open
  12646. /// 1 = close
  12647. void clif_Mail_window(int fd, int flag)
  12648. {
  12649. WFIFOHEAD(fd,packet_len(0x260));
  12650. WFIFOW(fd,0) = 0x260;
  12651. WFIFOL(fd,2) = flag;
  12652. WFIFOSET(fd,packet_len(0x260));
  12653. }
  12654. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12655. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12656. /// read:
  12657. /// 0 = unread
  12658. /// 1 = read
  12659. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12660. {
  12661. int fd = sd->fd;
  12662. struct mail_data *md = &sd->mail.inbox;
  12663. struct mail_message *msg;
  12664. int len, i, j;
  12665. len = 8 + (73 * md->amount);
  12666. WFIFOHEAD(fd,len);
  12667. WFIFOW(fd,0) = 0x240;
  12668. WFIFOW(fd,2) = len;
  12669. WFIFOL(fd,4) = md->amount;
  12670. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12671. {
  12672. msg = &md->msg[i];
  12673. if (msg->id < 1)
  12674. continue;
  12675. WFIFOL(fd,8+73*j) = msg->id;
  12676. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12677. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12678. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12679. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12680. j++;
  12681. }
  12682. WFIFOSET(fd,len);
  12683. if( md->full ) {// TODO: is this official?
  12684. char output[100];
  12685. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12686. clif_disp_onlyself(sd, output, strlen(output));
  12687. }
  12688. }
  12689. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12690. /// 023f
  12691. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12692. {
  12693. struct mail_data* md = &sd->mail.inbox;
  12694. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12695. intif_Mail_requestinbox(sd->status.char_id, 1);
  12696. else
  12697. clif_Mail_refreshinbox(sd);
  12698. mail_removeitem(sd, 0);
  12699. mail_removezeny(sd, 0);
  12700. }
  12701. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12702. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12703. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12704. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12705. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12706. {
  12707. int i, fd = sd->fd;
  12708. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12709. if( i == MAIL_MAX_INBOX ) {
  12710. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12711. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12712. return;
  12713. } else {
  12714. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12715. struct item *item = &msg->item;
  12716. struct item_data *data;
  12717. int msg_len = strlen(msg->body), len;
  12718. if( msg_len == 0 ) {
  12719. strcpy(msg->body, "(no message)");
  12720. msg_len = strlen(msg->body);
  12721. }
  12722. len = 101 + msg_len;
  12723. WFIFOHEAD(fd,len);
  12724. WFIFOW(fd,0) = 0x242;
  12725. WFIFOW(fd,2) = len;
  12726. WFIFOL(fd,4) = msg->id;
  12727. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12728. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12729. WFIFOL(fd,72) = 0;
  12730. WFIFOL(fd,76) = msg->zeny;
  12731. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12732. WFIFOL(fd,80) = item->amount;
  12733. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12734. WFIFOW(fd,86) = data->type;
  12735. WFIFOB(fd,88) = item->identify;
  12736. WFIFOB(fd,89) = item->attribute;
  12737. WFIFOB(fd,90) = item->refine;
  12738. WFIFOW(fd,91) = item->card[0];
  12739. WFIFOW(fd,93) = item->card[1];
  12740. WFIFOW(fd,95) = item->card[2];
  12741. WFIFOW(fd,97) = item->card[3];
  12742. } else // no item, set all to zero
  12743. memset(WFIFOP(fd,80), 0x00, 19);
  12744. WFIFOB(fd,99) = (unsigned char)msg_len;
  12745. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12746. WFIFOSET(fd,len);
  12747. if (msg->status == MAIL_UNREAD) {
  12748. msg->status = MAIL_READ;
  12749. intif_Mail_read(mail_id);
  12750. clif_parse_Mail_refreshinbox(fd, sd);
  12751. }
  12752. }
  12753. }
  12754. /// Request to open a mail (CZ_MAIL_OPEN).
  12755. /// 0241 <mail id>.L
  12756. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12757. {
  12758. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12759. if( mail_id <= 0 )
  12760. return;
  12761. if( mail_invalid_operation(sd) )
  12762. return;
  12763. clif_Mail_read(sd, mail_id);
  12764. }
  12765. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12766. /// 0244 <mail id>.L
  12767. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12768. {
  12769. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12770. int i;
  12771. bool fail = false;
  12772. if( !chrif_isconnected() )
  12773. return;
  12774. if( mail_id <= 0 )
  12775. return;
  12776. if( mail_invalid_operation(sd) )
  12777. return;
  12778. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12779. if( i == MAIL_MAX_INBOX )
  12780. return;
  12781. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12782. return;
  12783. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12784. clif_Mail_getattachment(fd, 1); //too many zeny
  12785. return;
  12786. }
  12787. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12788. struct item_data *data;
  12789. unsigned int weight;
  12790. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12791. return;
  12792. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12793. case CHKADDITEM_NEW:
  12794. fail = ( pc_inventoryblank(sd) == 0 );
  12795. break;
  12796. case CHKADDITEM_OVERAMOUNT:
  12797. fail = true;
  12798. }
  12799. if( fail ) {
  12800. clif_Mail_getattachment(fd, 1);
  12801. return;
  12802. }
  12803. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12804. if( sd->weight + weight > sd->max_weight ) {
  12805. clif_Mail_getattachment(fd, 2);
  12806. return;
  12807. }
  12808. }
  12809. sd->mail.inbox.msg[i].zeny = 0;
  12810. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12811. clif_Mail_read(sd, mail_id);
  12812. intif_Mail_getattach(sd->status.char_id, mail_id);
  12813. }
  12814. /// Request to delete a mail (CZ_MAIL_DELETE).
  12815. /// 0243 <mail id>.L
  12816. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12817. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12818. int i;
  12819. if( !chrif_isconnected() )
  12820. return;
  12821. if( mail_id <= 0 )
  12822. return;
  12823. if( mail_invalid_operation(sd) )
  12824. return;
  12825. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12826. if (i < MAIL_MAX_INBOX) {
  12827. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12828. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12829. clif_Mail_delete(sd->fd, mail_id, 1);
  12830. return;
  12831. }
  12832. intif_Mail_delete(sd->status.char_id, mail_id);
  12833. }
  12834. }
  12835. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12836. /// 0273 <mail id>.L <receive name>.24B
  12837. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12838. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12839. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12840. int i;
  12841. if( mail_id <= 0 )
  12842. return;
  12843. if( mail_invalid_operation(sd) )
  12844. return;
  12845. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12846. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12847. intif_Mail_return(sd->status.char_id, mail_id);
  12848. else
  12849. clif_Mail_return(sd->fd, mail_id, 1);
  12850. }
  12851. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12852. /// 0247 <index>.W <amount>.L
  12853. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12854. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12855. int idx = RFIFOW(fd,info->pos[0]);
  12856. int amount = RFIFOL(fd,info->pos[1]);
  12857. unsigned char flag;
  12858. if( !chrif_isconnected() )
  12859. return;
  12860. if (idx < 0 || amount < 0)
  12861. return;
  12862. flag = mail_setitem(sd, idx, amount);
  12863. clif_Mail_setattachment(fd,idx,!flag);
  12864. }
  12865. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12866. /// 0246 <type>.W
  12867. /// type:
  12868. /// 0 = reset all
  12869. /// 1 = remove item
  12870. /// 2 = remove zeny
  12871. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12872. {
  12873. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12874. if (type == 0 || type == 1)
  12875. mail_removeitem(sd, 0);
  12876. if (type == 0 || type == 2)
  12877. mail_removezeny(sd, 0);
  12878. }
  12879. /// Request to send mail (CZ_MAIL_SEND).
  12880. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12881. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12882. {
  12883. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12884. if( !chrif_isconnected() )
  12885. return;
  12886. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12887. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12888. return;
  12889. }
  12890. 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]));
  12891. }
  12892. /// AUCTION SYSTEM
  12893. /// By Zephyrus
  12894. ///
  12895. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12896. /// 025f <type>.L
  12897. /// type:
  12898. /// 0 = open
  12899. /// 1 = close
  12900. void clif_Auction_openwindow(struct map_session_data *sd)
  12901. {
  12902. int fd = sd->fd;
  12903. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12904. return;
  12905. if( !battle_config.feature_auction )
  12906. return;
  12907. WFIFOHEAD(fd,packet_len(0x25f));
  12908. WFIFOW(fd,0) = 0x25f;
  12909. WFIFOL(fd,2) = 0;
  12910. WFIFOSET(fd,packet_len(0x25f));
  12911. }
  12912. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12913. /// 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 }*
  12914. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12915. {
  12916. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12917. struct auction_data auction;
  12918. struct item_data *item;
  12919. WFIFOHEAD(fd,12 + (count * 83));
  12920. WFIFOW(fd,0) = 0x252;
  12921. WFIFOW(fd,2) = 12 + (count * 83);
  12922. WFIFOL(fd,4) = pages;
  12923. WFIFOL(fd,8) = count;
  12924. for( i = 0; i < count; i++ ) {
  12925. int k = 12 + (i * 83);
  12926. memcpy(&auction, RBUFP(buf,i * len), len);
  12927. WFIFOL(fd,k) = auction.auction_id;
  12928. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12929. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12930. WFIFOW(fd,28+k) = item->view_id;
  12931. else
  12932. WFIFOW(fd,28+k) = auction.item.nameid;
  12933. WFIFOL(fd,30+k) = auction.type;
  12934. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12935. WFIFOB(fd,36+k) = auction.item.identify;
  12936. WFIFOB(fd,37+k) = auction.item.attribute;
  12937. WFIFOB(fd,38+k) = auction.item.refine;
  12938. WFIFOW(fd,39+k) = auction.item.card[0];
  12939. WFIFOW(fd,41+k) = auction.item.card[1];
  12940. WFIFOW(fd,43+k) = auction.item.card[2];
  12941. WFIFOW(fd,45+k) = auction.item.card[3];
  12942. WFIFOL(fd,47+k) = auction.price;
  12943. WFIFOL(fd,51+k) = auction.buynow;
  12944. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12945. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12946. }
  12947. WFIFOSET(fd,WFIFOW(fd,2));
  12948. }
  12949. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12950. /// 0256 <index>.W <result>.B
  12951. /// result:
  12952. /// 0 = success
  12953. /// 1 = failure
  12954. static void clif_Auction_setitem(int fd, int index, bool fail)
  12955. {
  12956. WFIFOHEAD(fd,packet_len(0x256));
  12957. WFIFOW(fd,0) = 0x256;
  12958. WFIFOW(fd,2) = index;
  12959. WFIFOB(fd,4) = fail;
  12960. WFIFOSET(fd,packet_len(0x256));
  12961. }
  12962. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12963. /// 024b <type>.W
  12964. /// type:
  12965. /// 0 = create (any other action in auction window)
  12966. /// 1 = cancel (cancel pressed on register tab)
  12967. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12968. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12969. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12970. if( sd->auction.amount > 0 )
  12971. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12972. sd->auction.amount = 0;
  12973. }
  12974. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12975. /// 024c <index>.W <count>.L
  12976. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12977. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12978. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12979. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12980. struct item_data *item;
  12981. if( !battle_config.feature_auction )
  12982. return;
  12983. if( sd->auction.amount > 0 )
  12984. sd->auction.amount = 0;
  12985. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12986. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12987. return;
  12988. }
  12989. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12990. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12991. return;
  12992. }
  12993. 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) )
  12994. { // Consumable or pets are not allowed
  12995. clif_Auction_setitem(sd->fd, idx, true);
  12996. return;
  12997. }
  12998. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12999. !sd->status.inventory[idx].identify ||
  13000. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13001. !itemdb_available(sd->status.inventory[idx].nameid) ||
  13002. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  13003. ) {
  13004. clif_Auction_setitem(sd->fd, idx, true);
  13005. return;
  13006. }
  13007. sd->auction.index = idx;
  13008. sd->auction.amount = amount;
  13009. clif_Auction_setitem(fd, idx + 2, false);
  13010. }
  13011. /// Result from an auction action (ZC_AUCTION_RESULT).
  13012. /// 0250 <result>.B
  13013. /// result:
  13014. /// 0 = You have failed to bid into the auction
  13015. /// 1 = You have successfully bid in the auction
  13016. /// 2 = The auction has been canceled
  13017. /// 3 = An auction with at least one bidder cannot be canceled
  13018. /// 4 = You cannot register more than 5 items in an auction at a time
  13019. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13020. /// 6 = You have won the auction
  13021. /// 7 = You have failed to win the auction
  13022. /// 8 = You do not have enough Zeny
  13023. /// 9 = You cannot place more than 5 bids at a time
  13024. void clif_Auction_message(int fd, unsigned char flag)
  13025. {
  13026. WFIFOHEAD(fd,packet_len(0x250));
  13027. WFIFOW(fd,0) = 0x250;
  13028. WFIFOB(fd,2) = flag;
  13029. WFIFOSET(fd,packet_len(0x250));
  13030. }
  13031. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13032. /// 025e <result>.W
  13033. /// result:
  13034. /// 0 = You have ended the auction
  13035. /// 1 = You cannot end the auction
  13036. /// 2 = Auction ID is incorrect
  13037. void clif_Auction_close(int fd, unsigned char flag)
  13038. {
  13039. WFIFOHEAD(fd,packet_len(0x25e));
  13040. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13041. WFIFOW(fd,2) = flag;
  13042. WFIFOSET(fd,packet_len(0x25e));
  13043. }
  13044. /// Request to add an auction (CZ_AUCTION_ADD).
  13045. /// 024d <now money>.L <max money>.L <delete hour>.W
  13046. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13047. {
  13048. struct auction_data auction;
  13049. struct item_data *item;
  13050. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13051. if( !battle_config.feature_auction )
  13052. return;
  13053. auction.price = RFIFOL(fd,info->pos[0]);
  13054. auction.buynow = RFIFOL(fd,info->pos[1]);
  13055. auction.hours = RFIFOW(fd,info->pos[2]);
  13056. // Invalid Situations...
  13057. if( sd->auction.amount < 1 ) {
  13058. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13059. return;
  13060. }
  13061. if( auction.price >= auction.buynow ) {
  13062. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13063. return;
  13064. }
  13065. if( auction.hours < 1 || auction.hours > 48 ) {
  13066. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13067. return;
  13068. }
  13069. // Auction checks...
  13070. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13071. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13072. clif_Auction_message(fd, 2); // The auction has been canceled
  13073. return;
  13074. }
  13075. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13076. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13077. return;
  13078. }
  13079. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13080. auction.buynow = battle_config.auction_maximumprice;
  13081. if( auction.price >= auction.buynow )
  13082. auction.price = auction.buynow - 1;
  13083. }
  13084. auction.auction_id = 0;
  13085. auction.seller_id = sd->status.char_id;
  13086. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13087. auction.buyer_id = 0;
  13088. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13089. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  13090. {
  13091. clif_Auction_message(fd, 2); // The auction has been canceled
  13092. return;
  13093. }
  13094. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  13095. { // Just in case
  13096. clif_Auction_message(fd, 2); // The auction has been canceled
  13097. return;
  13098. }
  13099. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13100. auction.type = item->type;
  13101. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  13102. auction.item.amount = 1;
  13103. auction.timestamp = 0;
  13104. if( !intif_Auction_register(&auction) )
  13105. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13106. else
  13107. {
  13108. int zeny = auction.hours*battle_config.auction_feeperhour;
  13109. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13110. sd->auction.amount = 0;
  13111. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13112. }
  13113. }
  13114. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13115. /// 024e <auction id>.L
  13116. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13117. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13118. intif_Auction_cancel(sd->status.char_id, auction_id);
  13119. }
  13120. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13121. /// 025d <auction id>.L
  13122. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13123. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13124. intif_Auction_close(sd->status.char_id, auction_id);
  13125. }
  13126. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13127. /// 024f <auction id>.L <money>.L
  13128. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13129. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13130. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13131. int bid = RFIFOL(fd,info->pos[1]);
  13132. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13133. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13134. return;
  13135. }
  13136. if( bid <= 0 )
  13137. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13138. else if( bid > sd->status.zeny )
  13139. clif_Auction_message(fd, 8); // You do not have enough zeny
  13140. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13141. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13142. else {
  13143. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13144. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13145. }
  13146. }
  13147. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13148. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13149. /// search type:
  13150. /// 0 = armor
  13151. /// 1 = weapon
  13152. /// 2 = card
  13153. /// 3 = misc
  13154. /// 4 = name search
  13155. /// 5 = auction id search
  13156. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13157. char search_text[NAME_LENGTH];
  13158. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13159. short type = RFIFOW(fd,info->pos[0]);
  13160. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13161. int page = RFIFOW(fd,info->pos[3]);
  13162. if( !battle_config.feature_auction )
  13163. return;
  13164. clif_parse_Auction_cancelreg(fd, sd);
  13165. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  13166. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13167. }
  13168. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13169. /// 025c <type>.W
  13170. /// type:
  13171. /// 0 = sell (own auctions)
  13172. /// 1 = buy (own bids)
  13173. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13174. {
  13175. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  13176. if( !battle_config.feature_auction )
  13177. return;
  13178. clif_parse_Auction_cancelreg(fd, sd);
  13179. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13180. }
  13181. /// CASH/POINT SHOP
  13182. ///
  13183. void clif_cashshop_open( struct map_session_data* sd ){
  13184. WFIFOHEAD( sd->fd, 10 );
  13185. WFIFOW( sd->fd, 0 ) = 0x845;
  13186. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13187. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13188. WFIFOSET( sd->fd, 10 );
  13189. }
  13190. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13191. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13192. clif_cashshop_open( sd );
  13193. }
  13194. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13195. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13196. // No need to do anything here
  13197. }
  13198. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13199. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13200. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13201. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13202. int j;
  13203. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  13204. return;
  13205. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13206. WFIFOW(fd, 0) = 0x8c0;
  13207. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13208. WFIFOL(fd, 4) = tab;
  13209. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13210. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13211. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13212. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13213. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13214. }
  13215. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13216. }
  13217. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13218. void clif_cashshop_list( int fd ){
  13219. int tab;
  13220. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13221. int length = 8 + cash_shop_items[tab].count * 6;
  13222. int i, offset;
  13223. WFIFOHEAD( fd, length );
  13224. WFIFOW( fd, 0 ) = 0x8ca;
  13225. WFIFOW( fd, 2 ) = length;
  13226. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13227. WFIFOW( fd, 6 ) = tab;
  13228. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13229. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13230. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13231. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13232. }
  13233. WFIFOSET( fd, length );
  13234. }
  13235. }
  13236. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13237. if( !sd->status.cashshop_sent ) {
  13238. clif_cashshop_list( fd );
  13239. sd->status.cashshop_sent = true;
  13240. }
  13241. }
  13242. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13243. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13244. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13245. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13246. {
  13247. int fd,i;
  13248. #if PACKETVER < 20070711
  13249. const int offset = 8;
  13250. #else
  13251. const int offset = 12;
  13252. #endif
  13253. nullpo_retv(sd);
  13254. nullpo_retv(nd);
  13255. fd = sd->fd;
  13256. sd->npc_shopid = nd->bl.id;
  13257. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13258. WFIFOW(fd,0) = 0x287;
  13259. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13260. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  13261. #if PACKETVER >= 20070711
  13262. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  13263. #endif
  13264. for( i = 0; i < nd->u.shop.count; i++ ) {
  13265. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13266. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13267. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13268. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13269. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13270. }
  13271. WFIFOSET(fd,WFIFOW(fd,2));
  13272. }
  13273. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13274. /// 0289 <cash point>.L <error>.W
  13275. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13276. /// error:
  13277. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13278. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13279. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13280. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13281. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13282. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13283. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13284. /// 7 = You can purchase up to 10 items.
  13285. /// 8 = Some items could not be purchased.
  13286. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13287. {
  13288. int fd = sd->fd;
  13289. WFIFOHEAD(fd, packet_len(0x289));
  13290. WFIFOW(fd,0) = 0x289;
  13291. WFIFOL(fd,2) = sd->cashPoints;
  13292. #if PACKETVER < 20070711
  13293. WFIFOW(fd,6) = TOW(error);
  13294. #else
  13295. WFIFOL(fd,6) = sd->kafraPoints;
  13296. WFIFOW(fd,10) = TOW(error);
  13297. #endif
  13298. WFIFOSET(fd, packet_len(0x289));
  13299. }
  13300. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13301. WFIFOHEAD( sd->fd, 16 );
  13302. WFIFOW( sd->fd, 0 ) = 0x849;
  13303. WFIFOL( sd->fd, 2 ) = item_id;
  13304. WFIFOW( sd->fd, 6 ) = result;
  13305. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13306. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13307. WFIFOSET( sd->fd, 16 );
  13308. }
  13309. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13310. /// 0288 <name id>.W <amount>.W
  13311. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13312. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13313. /// 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)
  13314. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  13315. struct s_packet_db* info;
  13316. int cmd = RFIFOW(fd,0);
  13317. nullpo_retv(sd);
  13318. info = &packet_db[sd->packet_ver][cmd];
  13319. if( sd->state.trading || !sd->npc_shopid || !cash_shop_defined) {
  13320. clif_cashshop_ack(sd,1);
  13321. return;
  13322. } else {
  13323. #if PACKETVER < 20101116
  13324. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  13325. short amount = RFIFOW(fd,info->pos[1]);
  13326. int points = RFIFOL(fd,info->pos[2]);
  13327. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13328. #else
  13329. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13330. int len = RFIFOW(fd,info->pos[0]);
  13331. int points = RFIFOL(fd,info->pos[1]);
  13332. int count = RFIFOW(fd,info->pos[2]);
  13333. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13334. if( len < 10 || len != 10 + count * s_itl) {
  13335. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13336. return;
  13337. }
  13338. if(cmd == 0x848) {
  13339. if (cashshop_buylist( sd, points, count, item_list))
  13340. clif_cashshop_ack(sd,0);
  13341. return;
  13342. } else {
  13343. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13344. return;
  13345. }
  13346. #endif
  13347. }
  13348. }
  13349. /// Adoption System
  13350. ///
  13351. /// Adoption message (ZC_BABYMSG).
  13352. /// 0216 <msg>.L
  13353. /// msg:
  13354. /// 0 = "You cannot adopt more than 1 child."
  13355. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13356. /// 2 = "You cannot adopt a married person."
  13357. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13358. {
  13359. int fd = sd->fd;
  13360. WFIFOHEAD(fd,6);
  13361. WFIFOW(fd,0) = 0x216;
  13362. WFIFOL(fd,2) = type;
  13363. WFIFOSET(fd,6);
  13364. }
  13365. /// Adoption confirmation (ZC_REQ_BABY).
  13366. /// 01f6 <account id>.L <char id>.L <name>.B
  13367. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13368. {
  13369. int fd = sd->fd;
  13370. WFIFOHEAD(fd,34);
  13371. WFIFOW(fd,0) = 0x1f6;
  13372. WFIFOL(fd,2) = src->status.account_id;
  13373. WFIFOL(fd,6) = p_id;
  13374. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13375. WFIFOSET(fd,34);
  13376. }
  13377. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13378. /// 01f9 <account id>.L
  13379. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13380. {
  13381. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13382. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13383. if( pc_can_Adopt(sd, p_sd, tsd) )
  13384. {
  13385. tsd->adopt_invite = sd->status.account_id;
  13386. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13387. }
  13388. }
  13389. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13390. /// 01f7 <account id>.L <char id>.L <answer>.L
  13391. /// answer:
  13392. /// 0 = rejected
  13393. /// 1 = accepted
  13394. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13395. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13396. int p1_id = RFIFOL(fd,info->pos[0]);
  13397. int p2_id = RFIFOL(fd,info->pos[1]);
  13398. int result = RFIFOL(fd,info->pos[2]);
  13399. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13400. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13401. int pid = sd->adopt_invite;
  13402. sd->adopt_invite = 0;
  13403. if( p1_sd == NULL || p2_sd == NULL )
  13404. return; // Both players need to be online
  13405. if( pid != p1_sd->status.account_id )
  13406. return; // Incorrect values
  13407. if( result == 0 )
  13408. return; // Rejected
  13409. pc_adoption(p1_sd, p2_sd, sd);
  13410. }
  13411. /// Convex Mirror (ZC_BOSS_INFO).
  13412. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13413. /// infoType:
  13414. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13415. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13416. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13417. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13418. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13419. {
  13420. WFIFOHEAD(fd,70);
  13421. memset(WFIFOP(fd,0),0,70);
  13422. WFIFOW(fd,0) = 0x293;
  13423. if( md != NULL ) {
  13424. if( md->bl.prev != NULL ) { // Boss on This Map
  13425. if( flag ) {
  13426. WFIFOB(fd,2) = 1;
  13427. WFIFOL(fd,3) = md->bl.x;
  13428. WFIFOL(fd,7) = md->bl.y;
  13429. } else
  13430. WFIFOB(fd,2) = 2; // First Time
  13431. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13432. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13433. unsigned int seconds;
  13434. int hours, minutes;
  13435. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13436. hours = seconds / (60 * 60);
  13437. seconds = seconds - (60 * 60 * hours);
  13438. minutes = seconds / 60;
  13439. WFIFOB(fd,2) = 3;
  13440. WFIFOW(fd,11) = hours; // Hours
  13441. WFIFOW(fd,13) = minutes; // Minutes
  13442. }
  13443. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13444. }
  13445. WFIFOSET(fd,70);
  13446. }
  13447. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13448. /// 02d6 <account id>.L
  13449. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13450. {
  13451. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13452. struct map_session_data* tsd = map_id2sd(aid);
  13453. if (!tsd)
  13454. return;
  13455. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13456. clif_viewequip_ack(sd, tsd);
  13457. else
  13458. clif_msg(sd, VIEW_EQUIP_FAIL);
  13459. }
  13460. /// Request to change equip window tick (CZ_CONFIG).
  13461. /// 02d8 <type>.L <flag>.L
  13462. /// type:
  13463. /// 0 = open equip window
  13464. /// flag:
  13465. /// 0 = disabled
  13466. /// 1 = enabled
  13467. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13468. {
  13469. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13470. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13471. sd->status.show_equip = flag;
  13472. clif_equiptickack(sd, flag);
  13473. }
  13474. /// Request to change party invitation tick.
  13475. /// value:
  13476. /// 0 = disabled
  13477. /// 1 = enabled
  13478. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13479. {
  13480. bool flag = RFIFOB(fd,6) ? true : false;
  13481. sd->status.allow_party = flag;
  13482. clif_partytickack(sd, flag);
  13483. }
  13484. /// Questlog System [Kevin] [Inkfish]
  13485. ///
  13486. /**
  13487. * Safe check to init packet len & quest num for player.
  13488. * @param def_len
  13489. * @param info_len Length of each quest info.
  13490. * @param avail_quests Avail quests that player has.
  13491. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13492. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13493. **/
  13494. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13495. (*limit_out) = (0xFFFF - def_len) / info_len;
  13496. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13497. (*len_out) = ((*limit_out) * info_len) + def_len;
  13498. }
  13499. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13500. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13501. /// 097a <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST2)
  13502. /// 09f8 <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST3) // TODO!
  13503. void clif_quest_send_list(struct map_session_data *sd)
  13504. {
  13505. int fd = sd->fd;
  13506. int i;
  13507. int offset = 8;
  13508. int limit = 0;
  13509. #if PACKETVER >= 20141022
  13510. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13511. WFIFOHEAD(fd,i);
  13512. WFIFOW(fd, 0) = 0x97a;
  13513. WFIFOL(fd, 4) = limit;
  13514. for (i = 0; i < limit; i++) {
  13515. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13516. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13517. offset += 4;
  13518. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13519. offset++;
  13520. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13521. offset += 4;
  13522. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13523. offset += 4;
  13524. WFIFOW(fd, offset) = qi->objectives_count;
  13525. offset += 2;
  13526. if( qi->objectives_count > 0 ){
  13527. int j;
  13528. struct mob_db *mob;
  13529. for( j = 0; j < qi->objectives_count; j++ ){
  13530. mob = mob_db(qi->objectives[j].mob);
  13531. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13532. offset += 4;
  13533. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13534. offset += 2;
  13535. WFIFOW(fd, offset) = qi->objectives[j].count;
  13536. offset += 2;
  13537. memcpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13538. offset += NAME_LENGTH;
  13539. }
  13540. }
  13541. }
  13542. WFIFOW(fd, 2) = offset;
  13543. WFIFOSET(fd, offset);
  13544. #else
  13545. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13546. WFIFOHEAD(fd,i);
  13547. WFIFOW(fd, 0) = 0x2b1;
  13548. WFIFOL(fd, 4) = limit;
  13549. for (i = 0; i < limit; i++) {
  13550. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13551. offset += 4;
  13552. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13553. offset += 1;
  13554. }
  13555. WFIFOW(fd, 2) = offset;
  13556. WFIFOSET(fd, offset);
  13557. #endif
  13558. }
  13559. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13560. /// 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
  13561. void clif_quest_send_mission(struct map_session_data *sd)
  13562. {
  13563. int fd = sd->fd;
  13564. int i, j, limit = 0;
  13565. int len = sd->avail_quests*104+8;
  13566. struct mob_db *mob;
  13567. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13568. WFIFOHEAD(fd, len);
  13569. WFIFOW(fd, 0) = 0x2b2;
  13570. WFIFOW(fd, 2) = len;
  13571. WFIFOL(fd, 4) = limit;
  13572. for (i = 0; i < limit; i++) {
  13573. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13574. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13575. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13576. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13577. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13578. for (j = 0 ; j < qi->objectives_count; j++) {
  13579. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13580. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13581. mob = mob_db(qi->objectives[j].mob);
  13582. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13583. }
  13584. }
  13585. WFIFOSET(fd, len);
  13586. }
  13587. /// Notification about a new quest (ZC_ADD_QUEST).
  13588. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13589. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13590. {
  13591. int fd = sd->fd;
  13592. int i;
  13593. struct quest_db *qi = quest_search(qd->quest_id);
  13594. WFIFOHEAD(fd, packet_len(0x2b3));
  13595. WFIFOW(fd, 0) = 0x2b3;
  13596. WFIFOL(fd, 2) = qd->quest_id;
  13597. WFIFOB(fd, 6) = qd->state;
  13598. WFIFOB(fd, 7) = qd->time - qi->time;
  13599. WFIFOL(fd, 11) = qd->time;
  13600. WFIFOW(fd, 15) = qi->objectives_count;
  13601. for (i = 0; i < qi->objectives_count; i++) {
  13602. struct mob_db *mob;
  13603. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13604. WFIFOW(fd, i*30+21) = qd->count[i];
  13605. mob = mob_db(qi->objectives[i].mob);
  13606. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13607. }
  13608. WFIFOSET(fd, packet_len(0x2b3));
  13609. }
  13610. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13611. /// 02b4 <quest id>.L
  13612. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13613. {
  13614. int fd = sd->fd;
  13615. WFIFOHEAD(fd, packet_len(0x2b4));
  13616. WFIFOW(fd, 0) = 0x2b4;
  13617. WFIFOL(fd, 2) = quest_id;
  13618. WFIFOSET(fd, packet_len(0x2b4));
  13619. }
  13620. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13621. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13622. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  13623. {
  13624. int fd = sd->fd;
  13625. int i;
  13626. struct quest_db *qi = quest_search(qd->quest_id);
  13627. int len = qi->objectives_count * 12 + 6;
  13628. WFIFOHEAD(fd, len);
  13629. WFIFOW(fd, 0) = 0x2b5;
  13630. WFIFOW(fd, 2) = len;
  13631. WFIFOW(fd, 4) = qi->objectives_count;
  13632. for (i = 0; i < qi->objectives_count; i++) {
  13633. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  13634. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  13635. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  13636. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  13637. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  13638. }
  13639. }
  13640. WFIFOSET(fd, len);
  13641. }
  13642. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13643. /// 02b6 <quest id>.L <active>.B
  13644. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13645. {
  13646. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13647. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13648. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13649. }
  13650. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13651. /// 02b7 <quest id>.L <active>.B
  13652. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13653. {
  13654. int fd = sd->fd;
  13655. WFIFOHEAD(fd, packet_len(0x2b7));
  13656. WFIFOW(fd, 0) = 0x2b7;
  13657. WFIFOL(fd, 2) = quest_id;
  13658. WFIFOB(fd, 6) = active;
  13659. WFIFOSET(fd, packet_len(0x2b7));
  13660. }
  13661. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13662. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  13663. /// effect:
  13664. /// 0 = none
  13665. /// 1 = exclamation mark icon
  13666. /// 2 = question mark icon
  13667. /// color:
  13668. /// 0 = yellow
  13669. /// 1 = orange
  13670. /// 2 = green
  13671. /// 3 = purple
  13672. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  13673. {
  13674. #if PACKETVER >= 20090218
  13675. int fd = sd->fd;
  13676. WFIFOHEAD(fd, packet_len(0x446));
  13677. WFIFOW(fd, 0) = 0x446;
  13678. WFIFOL(fd, 2) = bl->id;
  13679. WFIFOW(fd, 6) = bl->x;
  13680. WFIFOW(fd, 8) = bl->y;
  13681. WFIFOW(fd, 10) = effect;
  13682. WFIFOW(fd, 12) = color;
  13683. WFIFOSET(fd, packet_len(0x446));
  13684. #endif
  13685. }
  13686. /// Mercenary System
  13687. ///
  13688. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13689. /// 02a2 <var id>.W <value>.L
  13690. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13691. {
  13692. struct mercenary_data *md;
  13693. struct status_data *status;
  13694. int fd;
  13695. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13696. return;
  13697. fd = sd->fd;
  13698. status = &md->battle_status;
  13699. WFIFOHEAD(fd,packet_len(0x2a2));
  13700. WFIFOW(fd,0) = 0x2a2;
  13701. WFIFOW(fd,2) = type;
  13702. switch( type ) {
  13703. case SP_ATK1:
  13704. {
  13705. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13706. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13707. }
  13708. break;
  13709. case SP_MATK1:
  13710. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13711. break;
  13712. case SP_HIT:
  13713. WFIFOL(fd,4) = status->hit;
  13714. break;
  13715. case SP_CRITICAL:
  13716. WFIFOL(fd,4) = status->cri/10;
  13717. break;
  13718. case SP_DEF1:
  13719. WFIFOL(fd,4) = status->def;
  13720. break;
  13721. case SP_MDEF1:
  13722. WFIFOL(fd,4) = status->mdef;
  13723. break;
  13724. case SP_MERCFLEE:
  13725. WFIFOL(fd,4) = status->flee;
  13726. break;
  13727. case SP_ASPD:
  13728. WFIFOL(fd,4) = status->amotion;
  13729. break;
  13730. case SP_HP:
  13731. WFIFOL(fd,4) = status->hp;
  13732. break;
  13733. case SP_MAXHP:
  13734. WFIFOL(fd,4) = status->max_hp;
  13735. break;
  13736. case SP_SP:
  13737. WFIFOL(fd,4) = status->sp;
  13738. break;
  13739. case SP_MAXSP:
  13740. WFIFOL(fd,4) = status->max_sp;
  13741. break;
  13742. case SP_MERCKILLS:
  13743. WFIFOL(fd,4) = md->mercenary.kill_count;
  13744. break;
  13745. case SP_MERCFAITH:
  13746. WFIFOL(fd,4) = mercenary_get_faith(md);
  13747. break;
  13748. }
  13749. WFIFOSET(fd,packet_len(0x2a2));
  13750. }
  13751. /// Mercenary base status data (ZC_MER_INIT).
  13752. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13753. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13754. /// <calls>.L <kills>.L <atk range>.W
  13755. void clif_mercenary_info(struct map_session_data *sd)
  13756. {
  13757. int fd;
  13758. struct mercenary_data *md;
  13759. struct status_data *status;
  13760. int atk;
  13761. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13762. return;
  13763. fd = sd->fd;
  13764. status = &md->battle_status;
  13765. WFIFOHEAD(fd,packet_len(0x29b));
  13766. WFIFOW(fd,0) = 0x29b;
  13767. WFIFOL(fd,2) = md->bl.id;
  13768. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13769. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13770. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13771. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13772. WFIFOW(fd,10) = status->hit;
  13773. WFIFOW(fd,12) = status->cri/10;
  13774. WFIFOW(fd,14) = status->def;
  13775. WFIFOW(fd,16) = status->mdef;
  13776. WFIFOW(fd,18) = status->flee;
  13777. WFIFOW(fd,20) = status->amotion;
  13778. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13779. WFIFOW(fd,46) = md->db->lv;
  13780. WFIFOL(fd,48) = status->hp;
  13781. WFIFOL(fd,52) = status->max_hp;
  13782. WFIFOL(fd,56) = status->sp;
  13783. WFIFOL(fd,60) = status->max_sp;
  13784. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13785. WFIFOW(fd,68) = mercenary_get_faith(md);
  13786. WFIFOL(fd,70) = mercenary_get_calls(md);
  13787. WFIFOL(fd,74) = md->mercenary.kill_count;
  13788. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13789. WFIFOSET(fd,packet_len(0x29b));
  13790. }
  13791. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13792. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13793. void clif_mercenary_skillblock(struct map_session_data *sd)
  13794. {
  13795. struct mercenary_data *md;
  13796. int fd, i, len = 4;
  13797. if( sd == NULL || (md = sd->md) == NULL )
  13798. return;
  13799. fd = sd->fd;
  13800. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13801. WFIFOW(fd,0) = 0x29d;
  13802. for( i = 0; i < MAX_MERCSKILL; i++ )
  13803. {
  13804. uint16 id;
  13805. short idx = -1;
  13806. if( (id = md->db->skill[i].id) == 0 )
  13807. continue;
  13808. if ((idx = mercenary_skill_get_index(id)) == -1)
  13809. continue;
  13810. WFIFOW(fd,len) = id;
  13811. WFIFOL(fd,len+2) = skill_get_inf(id);
  13812. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13813. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13814. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv);
  13815. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13816. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13817. len += 37;
  13818. }
  13819. WFIFOW(fd,2) = len;
  13820. WFIFOSET(fd,len);
  13821. }
  13822. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13823. /// 029f <command>.B
  13824. /// 1 = mercenary information
  13825. /// 2 = delete
  13826. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13827. {
  13828. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13829. if( sd->md == NULL )
  13830. return;
  13831. if( option == 2 ) mercenary_delete(sd->md, 2);
  13832. }
  13833. /// Mercenary Message
  13834. /// message:
  13835. /// 0 = Mercenary soldier's duty hour is over.
  13836. /// 1 = Your mercenary soldier has been killed.
  13837. /// 2 = Your mercenary soldier has been fired.
  13838. /// 3 = Your mercenary soldier has ran away.
  13839. void clif_mercenary_message(struct map_session_data* sd, int message){
  13840. clif_msg(sd, MERC_MSG_BASE + message);
  13841. }
  13842. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13843. /// 0298 <name id>.W <seconds>.L
  13844. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13845. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13846. WFIFOHEAD(fd,packet_len(0x298));
  13847. WFIFOW(fd,0) = 0x298;
  13848. WFIFOW(fd,2) = nameid;
  13849. WFIFOL(fd,4) = seconds;
  13850. WFIFOSET(fd,packet_len(0x298));
  13851. }
  13852. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13853. /// 0299 <index>.W <name id>.W
  13854. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13855. { // '<ItemName>' item has been deleted from the Inventory
  13856. WFIFOHEAD(fd,packet_len(0x299));
  13857. WFIFOW(fd,0) = 0x299;
  13858. WFIFOW(fd,2) = index+2;
  13859. WFIFOW(fd,4) = nameid;
  13860. WFIFOSET(fd,packet_len(0x299));
  13861. }
  13862. /// Book Reading (ZC_READ_BOOK).
  13863. /// 0294 <book id>.L <page>.L
  13864. void clif_readbook(int fd, int book_id, int page)
  13865. {
  13866. WFIFOHEAD(fd,packet_len(0x294));
  13867. WFIFOW(fd,0) = 0x294;
  13868. WFIFOL(fd,2) = book_id;
  13869. WFIFOL(fd,6) = page;
  13870. WFIFOSET(fd,packet_len(0x294));
  13871. }
  13872. /// Battlegrounds
  13873. ///
  13874. /// Updates HP bar of a camp member.
  13875. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  13876. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  13877. void clif_bg_hp(struct map_session_data *sd) {
  13878. #if PACKETVER < 20140613
  13879. unsigned char buf[34];
  13880. const int cmd = 0x2e0;
  13881. #else
  13882. unsigned char buf[14];
  13883. const int cmd = 0xa0e;
  13884. #endif
  13885. nullpo_retv(sd);
  13886. WBUFW(buf,0) = cmd;
  13887. WBUFL(buf,2) = sd->status.account_id;
  13888. #if PACKETVER < 20140613
  13889. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13890. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  13891. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13892. WBUFW(buf,32) = 100;
  13893. } else {
  13894. WBUFW(buf,30) = sd->battle_status.hp;
  13895. WBUFW(buf,32) = sd->battle_status.max_hp;
  13896. }
  13897. #else
  13898. if( sd->battle_status.max_hp > INT32_MAX ) {
  13899. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13900. WBUFL(buf,10) = 100;
  13901. } else {
  13902. WBUFL(buf,6) = sd->battle_status.hp;
  13903. WBUFL(buf,10) = sd->battle_status.max_hp;
  13904. }
  13905. #endif
  13906. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13907. }
  13908. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13909. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13910. void clif_bg_xy(struct map_session_data *sd)
  13911. {
  13912. unsigned char buf[36];
  13913. nullpo_retv(sd);
  13914. WBUFW(buf,0)=0x2df;
  13915. WBUFL(buf,2)=sd->status.account_id;
  13916. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13917. WBUFW(buf,30)=sd->status.class_;
  13918. WBUFW(buf,32)=sd->bl.x;
  13919. WBUFW(buf,34)=sd->bl.y;
  13920. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13921. }
  13922. void clif_bg_xy_remove(struct map_session_data *sd)
  13923. {
  13924. unsigned char buf[36];
  13925. nullpo_retv(sd);
  13926. WBUFW(buf,0)=0x2df;
  13927. WBUFL(buf,2)=sd->status.account_id;
  13928. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13929. WBUFW(buf,30)=0;
  13930. WBUFW(buf,32)=-1;
  13931. WBUFW(buf,34)=-1;
  13932. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13933. }
  13934. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13935. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13936. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13937. {
  13938. struct map_session_data *sd;
  13939. unsigned char *buf;
  13940. if( (sd = bg_getavailablesd(bg)) == NULL )
  13941. return;
  13942. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13943. WBUFW(buf,0) = 0x2dc;
  13944. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13945. WBUFL(buf,4) = src_id;
  13946. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13947. memcpy(WBUFP(buf,32), mes, len);
  13948. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13949. if( buf )
  13950. aFree(buf);
  13951. }
  13952. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13953. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13954. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13955. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13956. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13957. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13958. char *name, *message;
  13959. int namelen, messagelen;
  13960. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13961. return;
  13962. if( is_atcommand(fd, sd, message, 1) )
  13963. return;
  13964. if (sd->sc.cant.chat)
  13965. return; //no "chatting" while muted.
  13966. if( battle_config.min_chat_delay ) {
  13967. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13968. return;
  13969. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13970. }
  13971. if (battle_config.idletime_option&IDLE_CHAT)
  13972. sd->idletime = last_tick;
  13973. bg_send_message(sd, text, textlen);
  13974. }
  13975. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13976. /// 02de <camp A points>.W <camp B points>.W
  13977. void clif_bg_updatescore(int16 m)
  13978. {
  13979. struct block_list bl;
  13980. unsigned char buf[6];
  13981. bl.id = 0;
  13982. bl.type = BL_NUL;
  13983. bl.m = m;
  13984. WBUFW(buf,0) = 0x2de;
  13985. WBUFW(buf,2) = map[m].bgscore_lion;
  13986. WBUFW(buf,4) = map[m].bgscore_eagle;
  13987. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13988. }
  13989. void clif_bg_updatescore_single(struct map_session_data *sd)
  13990. {
  13991. int fd;
  13992. nullpo_retv(sd);
  13993. fd = sd->fd;
  13994. WFIFOHEAD(fd,packet_len(0x2de));
  13995. WFIFOW(fd,0) = 0x2de;
  13996. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13997. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13998. WFIFOSET(fd,packet_len(0x2de));
  13999. }
  14000. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14001. /// 02dd <account id>.L <name>.24B <camp>.W
  14002. void clif_sendbgemblem_area(struct map_session_data *sd)
  14003. {
  14004. unsigned char buf[33];
  14005. nullpo_retv(sd);
  14006. WBUFW(buf, 0) = 0x2dd;
  14007. WBUFL(buf,2) = sd->bl.id;
  14008. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14009. WBUFW(buf,30) = sd->bg_id;
  14010. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14011. }
  14012. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14013. {
  14014. nullpo_retv(sd);
  14015. WFIFOHEAD(fd,32);
  14016. WFIFOW(fd,0) = 0x2dd;
  14017. WFIFOL(fd,2) = sd->bl.id;
  14018. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  14019. WFIFOW(fd,30) = sd->bg_id;
  14020. WFIFOSET(fd,packet_len(0x2dd));
  14021. }
  14022. /// Custom Fonts (ZC_NOTIFY_FONT).
  14023. /// 02ef <account_id>.L <font id>.W
  14024. void clif_font(struct map_session_data *sd)
  14025. {
  14026. #if PACKETVER >= 20080102
  14027. unsigned char buf[8];
  14028. nullpo_retv(sd);
  14029. WBUFW(buf,0) = 0x2ef;
  14030. WBUFL(buf,2) = sd->bl.id;
  14031. WBUFW(buf,6) = sd->status.font;
  14032. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14033. #endif
  14034. }
  14035. /*==========================================
  14036. * Notifies party members of instance change
  14037. *------------------------------------------*/
  14038. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  14039. {
  14040. #if PACKETVER >= 20071128
  14041. unsigned char buf[65];
  14042. if(!sd) return;
  14043. WBUFW(buf,0) = 0x2cb;
  14044. memcpy( WBUFP(buf,2), name, 62 );
  14045. WBUFW(buf,63) = num;
  14046. if(flag) // A timer has changed or been added
  14047. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  14048. else // No notification
  14049. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  14050. #endif
  14051. return;
  14052. }
  14053. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  14054. {
  14055. #if PACKETVER >= 20071128
  14056. unsigned char buf[4];
  14057. if(!sd) return;
  14058. WBUFW(buf,0) = 0x2cc;
  14059. WBUFW(buf,2) = num;
  14060. if(flag) // A timer has changed or been added
  14061. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  14062. else // No notification
  14063. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  14064. #endif
  14065. return;
  14066. }
  14067. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  14068. {
  14069. #if PACKETVER >= 20071128
  14070. unsigned char buf[71];
  14071. if(!sd) return; //party_getavailablesd can return NULL
  14072. WBUFW(buf,0) = 0x2cd;
  14073. memcpy( WBUFP(buf,2), name, 62 );
  14074. WBUFL(buf,63) = limit1;
  14075. WBUFL(buf,67) = limit2;
  14076. if(flag) // A timer has changed or been added
  14077. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  14078. else // No notification
  14079. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  14080. #endif
  14081. return;
  14082. }
  14083. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  14084. {
  14085. #if PACKETVER >= 20071128
  14086. unsigned char buf[10];
  14087. if(!sd) return;
  14088. WBUFW(buf,0) = 0x2ce;
  14089. WBUFL(buf,2) = type;
  14090. WBUFL(buf,6) = limit;
  14091. if(flag) // A timer has changed or been added
  14092. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  14093. else // No notification
  14094. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  14095. #endif
  14096. return;
  14097. }
  14098. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14099. /// 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
  14100. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14101. {
  14102. #if PACKETVER >= 20071002
  14103. unsigned char buf[22];
  14104. struct item_data* id = itemdb_search(item_data->nameid);
  14105. WBUFW(buf,0) = 0x2b8;
  14106. WBUFL(buf,2) = sd->status.account_id;
  14107. WBUFW(buf,6) = item_data->nameid;
  14108. WBUFB(buf,8) = item_data->identify;
  14109. WBUFB(buf,9) = item_data->attribute;
  14110. WBUFB(buf,10) = item_data->refine;
  14111. clif_addcards(WBUFP(buf,11), item_data);
  14112. WBUFW(buf,19) = id->equip; // equip location
  14113. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14114. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14115. #endif
  14116. }
  14117. /// Display gained exp (ZC_NOTIFY_EXP).
  14118. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14119. /// var id:
  14120. /// SP_BASEEXP, SP_JOBEXP
  14121. /// exp type:
  14122. /// 0 = normal exp gain/loss
  14123. /// 1 = quest exp gain/loss
  14124. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  14125. {
  14126. int fd;
  14127. nullpo_retv(sd);
  14128. fd = sd->fd;
  14129. WFIFOHEAD(fd, packet_len(0x7f6));
  14130. WFIFOW(fd,0) = 0x7f6;
  14131. WFIFOL(fd,2) = sd->bl.id;
  14132. WFIFOL(fd,6) = exp;
  14133. WFIFOW(fd,10) = type;
  14134. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  14135. WFIFOSET(fd,packet_len(0x7f6));
  14136. }
  14137. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14138. /// type:
  14139. /// 0 = Displays 'value' for 5 seconds.
  14140. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14141. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14142. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14143. /// value:
  14144. /// 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).
  14145. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14146. {
  14147. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14148. WFIFOW(sd->fd,0) = 0x1b1;
  14149. WFIFOB(sd->fd,2) = type;
  14150. WFIFOL(sd->fd,3) = value;
  14151. WFIFOSET(sd->fd, packet_len(0x1b1));
  14152. }
  14153. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14154. /// 021d <state>.L
  14155. /// state:
  14156. /// 0 = Full effects
  14157. /// 1 = Reduced effects
  14158. ///
  14159. /// NOTE: The state is used on Aegis for sending skill unit packet
  14160. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14161. /// whenever possible. Due to the way the decision check is
  14162. /// constructed, this state tracking was rendered useless,
  14163. /// as the only skill unit, that is sent with 0x1c9 is
  14164. /// Graffiti.
  14165. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14166. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14167. sd->state.lesseffect = ( isLess != 0 );
  14168. }
  14169. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14170. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  14171. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  14172. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14173. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14174. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14175. int type = RFIFOL(fd,info->pos[1]);
  14176. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14177. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14178. if( sd->state.trading || sd->npc_shopid )
  14179. return;
  14180. if( flag == 0 || n == 0) {
  14181. clif_menuskill_clear(sd);
  14182. return; // Canceled by player.
  14183. }
  14184. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14185. clif_menuskill_clear(sd);
  14186. return; // Prevent hacking.
  14187. }
  14188. switch( type ) {
  14189. case 0: // Change Material
  14190. skill_changematerial(sd,n,item_list);
  14191. break;
  14192. case 1: // Level 1: Pure to Rough
  14193. case 2: // Level 2: Rough to Pure
  14194. skill_elementalanalysis(sd,n,type,item_list);
  14195. break;
  14196. }
  14197. clif_menuskill_clear(sd);
  14198. return;
  14199. }
  14200. /*==========================================
  14201. * Elemental System
  14202. *==========================================*/
  14203. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14204. struct elemental_data *ed;
  14205. struct status_data *status;
  14206. int fd;
  14207. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14208. return;
  14209. fd = sd->fd;
  14210. status = &ed->battle_status;
  14211. WFIFOHEAD(fd,8);
  14212. WFIFOW(fd,0) = 0x81e;
  14213. WFIFOW(fd,2) = type;
  14214. switch( type ) {
  14215. case SP_HP:
  14216. WFIFOL(fd,4) = status->hp;
  14217. break;
  14218. case SP_MAXHP:
  14219. WFIFOL(fd,4) = status->max_hp;
  14220. break;
  14221. case SP_SP:
  14222. WFIFOL(fd,4) = status->sp;
  14223. break;
  14224. case SP_MAXSP:
  14225. WFIFOL(fd,4) = status->max_sp;
  14226. break;
  14227. }
  14228. WFIFOSET(fd,8);
  14229. }
  14230. void clif_elemental_info(struct map_session_data *sd) {
  14231. int fd;
  14232. struct elemental_data *ed;
  14233. struct status_data *status;
  14234. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14235. return;
  14236. fd = sd->fd;
  14237. status = &ed->battle_status;
  14238. WFIFOHEAD(fd,22);
  14239. WFIFOW(fd, 0) = 0x81d;
  14240. WFIFOL(fd, 2) = ed->bl.id;
  14241. WFIFOL(fd, 6) = status->hp;
  14242. WFIFOL(fd,10) = status->max_hp;
  14243. WFIFOL(fd,14) = status->sp;
  14244. WFIFOL(fd,18) = status->max_sp;
  14245. WFIFOSET(fd,22);
  14246. }
  14247. /// Buying Store System
  14248. ///
  14249. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14250. /// 0810 <slots>.B
  14251. void clif_buyingstore_open(struct map_session_data* sd)
  14252. {
  14253. int fd = sd->fd;
  14254. WFIFOHEAD(fd,packet_len(0x810));
  14255. WFIFOW(fd,0) = 0x810;
  14256. WFIFOB(fd,2) = sd->buyingstore.slots;
  14257. WFIFOSET(fd,packet_len(0x810));
  14258. }
  14259. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14260. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14261. /// result:
  14262. /// 0 = cancel
  14263. /// 1 = open
  14264. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14265. {
  14266. const unsigned int blocksize = 8;
  14267. uint8* itemlist;
  14268. char storename[MESSAGE_SIZE];
  14269. unsigned char result;
  14270. int zenylimit;
  14271. unsigned int count, packet_len;
  14272. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14273. packet_len = RFIFOW(fd,info->pos[0]);
  14274. // TODO: Make this check global for all variable length packets.
  14275. if( packet_len < 89 )
  14276. {// minimum packet length
  14277. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14278. return;
  14279. }
  14280. zenylimit = RFIFOL(fd,info->pos[1]);
  14281. result = RFIFOL(fd,info->pos[2]);
  14282. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  14283. itemlist = RFIFOP(fd,info->pos[4]);
  14284. // so that buyingstore_create knows, how many elements it has access to
  14285. packet_len-= info->pos[4];
  14286. if( packet_len%blocksize )
  14287. {
  14288. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14289. return;
  14290. }
  14291. count = packet_len/blocksize;
  14292. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14293. }
  14294. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14295. /// 0812 <result>.W <total weight>.L
  14296. /// result:
  14297. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14298. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14299. /// 8 = "No sale (purchase) information available." (0x705)
  14300. /// ? = nothing
  14301. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14302. {
  14303. int fd = sd->fd;
  14304. WFIFOHEAD(fd,packet_len(0x812));
  14305. WFIFOW(fd,0) = 0x812;
  14306. WFIFOW(fd,2) = result;
  14307. WFIFOL(fd,4) = weight;
  14308. WFIFOSET(fd,packet_len(0x812));
  14309. }
  14310. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14311. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14312. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14313. {
  14314. int fd = sd->fd;
  14315. unsigned int i;
  14316. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14317. WFIFOW(fd,0) = 0x813;
  14318. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14319. WFIFOL(fd,4) = sd->bl.id;
  14320. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14321. for( i = 0; i < sd->buyingstore.slots; i++ )
  14322. {
  14323. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14324. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14325. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14326. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14327. }
  14328. WFIFOSET(fd,WFIFOW(fd,2));
  14329. }
  14330. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14331. /// 0814 <account id>.L <store name>.80B
  14332. void clif_buyingstore_entry(struct map_session_data* sd)
  14333. {
  14334. uint8 buf[86];
  14335. WBUFW(buf,0) = 0x814;
  14336. WBUFL(buf,2) = sd->bl.id;
  14337. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14338. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14339. }
  14340. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14341. {
  14342. int fd = sd->fd;
  14343. WFIFOHEAD(fd,packet_len(0x814));
  14344. WFIFOW(fd,0) = 0x814;
  14345. WFIFOL(fd,2) = pl_sd->bl.id;
  14346. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14347. WFIFOSET(fd,packet_len(0x814));
  14348. }
  14349. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14350. /// 0815
  14351. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14352. {
  14353. buyingstore_close(sd);
  14354. }
  14355. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14356. /// 0816 <account id>.L
  14357. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14358. {
  14359. uint8 buf[6];
  14360. WBUFW(buf,0) = 0x816;
  14361. WBUFL(buf,2) = sd->bl.id;
  14362. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14363. }
  14364. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14365. {
  14366. int fd = sd->fd;
  14367. WFIFOHEAD(fd,packet_len(0x816));
  14368. WFIFOW(fd,0) = 0x816;
  14369. WFIFOL(fd,2) = pl_sd->bl.id;
  14370. WFIFOSET(fd,packet_len(0x816));
  14371. }
  14372. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14373. /// 0817 <account id>.L
  14374. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14375. {
  14376. uint32 account_id;
  14377. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14378. buyingstore_open(sd, account_id);
  14379. }
  14380. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14381. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14382. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14383. {
  14384. int fd = sd->fd;
  14385. unsigned int i;
  14386. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14387. WFIFOW(fd,0) = 0x818;
  14388. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14389. WFIFOL(fd,4) = pl_sd->bl.id;
  14390. WFIFOL(fd,8) = pl_sd->buyer_id;
  14391. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14392. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14393. {
  14394. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14395. 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.
  14396. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14397. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14398. }
  14399. WFIFOSET(fd,WFIFOW(fd,2));
  14400. }
  14401. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14402. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14403. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14404. {
  14405. const unsigned int blocksize = 6;
  14406. uint8* itemlist;
  14407. uint32 account_id;
  14408. unsigned int count, packet_len, buyer_id;
  14409. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14410. packet_len = RFIFOW(fd,info->pos[0]);
  14411. if( packet_len < 12 )
  14412. {// minimum packet length
  14413. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14414. return;
  14415. }
  14416. account_id = RFIFOL(fd,info->pos[1]);
  14417. buyer_id = RFIFOL(fd,info->pos[2]);
  14418. itemlist = RFIFOP(fd,info->pos[3]);
  14419. // so that buyingstore_trade knows, how many elements it has access to
  14420. packet_len-= info->pos[3];
  14421. if( packet_len%blocksize )
  14422. {
  14423. 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);
  14424. return;
  14425. }
  14426. count = packet_len/blocksize;
  14427. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14428. }
  14429. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14430. /// 081a <result>.W
  14431. /// result:
  14432. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14433. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14434. /// ? = nothing
  14435. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14436. {
  14437. int fd = sd->fd;
  14438. WFIFOHEAD(fd,packet_len(0x81a));
  14439. WFIFOW(fd,0) = 0x81a;
  14440. WFIFOW(fd,2) = result;
  14441. WFIFOSET(fd,packet_len(0x81a));
  14442. }
  14443. /// Updates the zeny limit and an item in the buying store item list.
  14444. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  14445. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  14446. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  14447. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  14448. const int cmd = 0x81b;
  14449. #else
  14450. const int cmd = 0x9e6;
  14451. #endif
  14452. int offset = 0;
  14453. int fd = sd->fd;
  14454. WFIFOHEAD(fd,packet_len(cmd));
  14455. WFIFOW(fd,0) = cmd;
  14456. WFIFOW(fd,2) = nameid;
  14457. WFIFOW(fd,4) = amount; // amount of nameid received
  14458. #if PACKETVER >= 20141016
  14459. WFIFOL(fd,6) = zeny; // zeny
  14460. offset += 4;
  14461. #endif
  14462. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  14463. #if PACKETVER >= 20141016
  14464. WFIFOL(fd,10+offset) = char_id; // GID
  14465. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  14466. #endif
  14467. WFIFOSET(fd,packet_len(cmd));
  14468. }
  14469. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14470. /// 081c <index>.W <amount>.W <price>.L
  14471. /// message:
  14472. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14473. ///
  14474. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14475. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14476. {
  14477. int fd = sd->fd;
  14478. WFIFOHEAD(fd,packet_len(0x81c));
  14479. WFIFOW(fd,0) = 0x81c;
  14480. WFIFOW(fd,2) = index+2;
  14481. WFIFOW(fd,4) = amount;
  14482. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14483. WFIFOSET(fd,packet_len(0x81c));
  14484. }
  14485. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14486. /// 0824 <result>.W <name id>.W
  14487. /// result:
  14488. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14489. /// 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)
  14490. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14491. /// ? = nothing
  14492. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14493. {
  14494. int fd = sd->fd;
  14495. WFIFOHEAD(fd,packet_len(0x824));
  14496. WFIFOW(fd,0) = 0x824;
  14497. WFIFOW(fd,2) = result;
  14498. WFIFOW(fd,4) = nameid;
  14499. WFIFOSET(fd,packet_len(0x824));
  14500. }
  14501. /// Search Store Info System
  14502. ///
  14503. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14504. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14505. /// type:
  14506. /// 0 = Vending
  14507. /// 1 = Buying Store
  14508. ///
  14509. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14510. /// amount of card slots. If the client does not know about the item it
  14511. /// cannot be searched.
  14512. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14513. {
  14514. const unsigned int blocksize = 2;
  14515. const uint8* itemlist;
  14516. const uint8* cardlist;
  14517. unsigned char type;
  14518. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14519. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14520. packet_len = RFIFOW(fd,info->pos[0]);
  14521. if( packet_len < 15 )
  14522. {// minimum packet length
  14523. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14524. return;
  14525. }
  14526. type = RFIFOB(fd,info->pos[1]);
  14527. max_price = RFIFOL(fd,info->pos[2]);
  14528. min_price = RFIFOL(fd,info->pos[3]);
  14529. item_count = RFIFOB(fd,info->pos[4]);
  14530. card_count = RFIFOB(fd,info->pos[5]);
  14531. itemlist = RFIFOP(fd,info->pos[6]);
  14532. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14533. // check, if there is enough data for the claimed count of items
  14534. packet_len-= info->pos[6];
  14535. if( packet_len%blocksize )
  14536. {
  14537. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14538. return;
  14539. }
  14540. count = packet_len/blocksize;
  14541. if( count < item_count+card_count )
  14542. {
  14543. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14544. return;
  14545. }
  14546. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14547. }
  14548. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14549. /// 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 }*
  14550. /// is first page:
  14551. /// 0 = appends to existing results
  14552. /// 1 = clears previous results before displaying this result set
  14553. /// is next page:
  14554. /// 0 = no "next" label
  14555. /// 1 = "next" label to retrieve more results
  14556. void clif_search_store_info_ack(struct map_session_data* sd)
  14557. {
  14558. const unsigned int blocksize = MESSAGE_SIZE+26;
  14559. int fd = sd->fd;
  14560. unsigned int i, start, end;
  14561. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14562. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14563. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14564. WFIFOW(fd,0) = 0x836;
  14565. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14566. WFIFOB(fd,4) = !sd->searchstore.pages;
  14567. WFIFOB(fd,5) = searchstore_querynext(sd);
  14568. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14569. for( i = start; i < end; i++ ) {
  14570. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14571. struct item it;
  14572. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14573. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14574. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14575. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14576. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14577. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14578. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14579. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14580. // make-up an item for clif_addcards
  14581. memset(&it, 0, sizeof(it));
  14582. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14583. it.nameid = ssitem->nameid;
  14584. it.amount = ssitem->amount;
  14585. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14586. }
  14587. WFIFOSET(fd,WFIFOW(fd,2));
  14588. }
  14589. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14590. /// 0837 <reason>.B
  14591. /// reason:
  14592. /// 0 = "No matching stores were found." (0x70b)
  14593. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14594. /// 2 = "You cannot search anymore." (0x706)
  14595. /// 3 = "You cannot search yet." (0x708)
  14596. /// 4 = "No sale (purchase) information available." (0x705)
  14597. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14598. {
  14599. int fd = sd->fd;
  14600. WFIFOHEAD(fd,packet_len(0x837));
  14601. WFIFOW(fd,0) = 0x837;
  14602. WFIFOB(fd,2) = reason;
  14603. WFIFOSET(fd,packet_len(0x837));
  14604. }
  14605. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14606. /// 0838
  14607. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14608. {
  14609. searchstore_next(sd);
  14610. }
  14611. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14612. /// 083a <type>.W <remaining uses>.B
  14613. /// type:
  14614. /// 0 = Search Stores
  14615. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14616. void clif_open_search_store_info(struct map_session_data* sd)
  14617. {
  14618. int fd = sd->fd;
  14619. WFIFOHEAD(fd,packet_len(0x83a));
  14620. WFIFOW(fd,0) = 0x83a;
  14621. WFIFOW(fd,2) = sd->searchstore.effect;
  14622. #if PACKETVER > 20100701
  14623. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14624. #endif
  14625. WFIFOSET(fd,packet_len(0x83a));
  14626. }
  14627. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14628. /// 083b
  14629. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14630. {
  14631. searchstore_close(sd);
  14632. }
  14633. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14634. /// 083c <account id>.L <store id>.L <nameid>.W
  14635. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14636. {
  14637. unsigned short nameid;
  14638. uint32 account_id, store_id;
  14639. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14640. account_id = RFIFOL(fd,info->pos[0]);
  14641. store_id = RFIFOL(fd,info->pos[1]);
  14642. nameid = RFIFOW(fd,info->pos[2]);
  14643. searchstore_click(sd, account_id, store_id, nameid);
  14644. }
  14645. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14646. /// 083d <xPos>.W <yPos>.W
  14647. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14648. {
  14649. int fd = sd->fd;
  14650. WFIFOHEAD(fd,packet_len(0x83d));
  14651. WFIFOW(fd,0) = 0x83d;
  14652. WFIFOW(fd,2) = x;
  14653. WFIFOW(fd,4) = y;
  14654. WFIFOSET(fd,packet_len(0x83d));
  14655. }
  14656. /// Parse function for packet debugging.
  14657. void clif_parse_debug(int fd,struct map_session_data *sd)
  14658. {
  14659. int cmd, packet_len;
  14660. // clif_parse ensures, that there is at least 2 bytes of data
  14661. cmd = RFIFOW(fd,0);
  14662. if( sd ) {
  14663. packet_len = packet_db[sd->packet_ver][cmd].len;
  14664. if( packet_len == 0 )
  14665. {// unknown
  14666. packet_len = RFIFOREST(fd);
  14667. }
  14668. else if( packet_len == -1 )
  14669. {// variable length
  14670. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14671. }
  14672. 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);
  14673. }
  14674. else
  14675. {
  14676. packet_len = RFIFOREST(fd);
  14677. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14678. }
  14679. ShowDump(RFIFOP(fd,0), packet_len);
  14680. }
  14681. /*==========================================
  14682. * Server tells client to display a window similar to Magnifier (item) one
  14683. * Server populates the window with avilable elemental converter options according to player's inventory
  14684. *------------------------------------------*/
  14685. int clif_elementalconverter_list(struct map_session_data *sd) {
  14686. int i,c,view,fd;
  14687. nullpo_ret(sd);
  14688. /// Main client packet processing function
  14689. fd=sd->fd;
  14690. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14691. WFIFOW(fd, 0)=0x1ad;
  14692. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14693. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14694. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14695. WFIFOW(fd,c*2+ 4)= view;
  14696. else
  14697. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14698. c++;
  14699. }
  14700. }
  14701. WFIFOW(fd,2) = c*2+4;
  14702. WFIFOSET(fd, WFIFOW(fd,2));
  14703. if (c > 0) {
  14704. sd->menuskill_id = SA_CREATECON;
  14705. sd->menuskill_val = c;
  14706. }
  14707. return 0;
  14708. }
  14709. /**
  14710. * Rune Knight
  14711. **/
  14712. void clif_millenniumshield(struct block_list *bl, short shields) {
  14713. #if PACKETVER >= 20081217
  14714. unsigned char buf[10];
  14715. WBUFW(buf,0) = 0x440;
  14716. WBUFL(buf,2) = bl->id;
  14717. WBUFW(buf,6) = shields;
  14718. WBUFW(buf,8) = 0;
  14719. clif_send(buf,packet_len(0x440),bl,AREA);
  14720. #endif
  14721. }
  14722. /**
  14723. * Warlock
  14724. **/
  14725. /*==========================================
  14726. * Spellbook list [LimitLine/3CeAM]
  14727. *------------------------------------------*/
  14728. int clif_spellbook_list(struct map_session_data *sd)
  14729. {
  14730. int i, c;
  14731. int fd;
  14732. nullpo_ret(sd);
  14733. fd = sd->fd;
  14734. WFIFOHEAD(fd, 8 * 8 + 8);
  14735. WFIFOW(fd,0) = 0x1ad;
  14736. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14737. {
  14738. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14739. {
  14740. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14741. c++;
  14742. }
  14743. }
  14744. if( c > 0 )
  14745. {
  14746. WFIFOW(fd,2) = c * 2 + 4;
  14747. WFIFOSET(fd, WFIFOW(fd, 2));
  14748. sd->menuskill_id = WL_READING_SB;
  14749. sd->menuskill_val = c;
  14750. }
  14751. else{
  14752. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14753. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14754. }
  14755. return 1;
  14756. }
  14757. /**
  14758. * Mechanic
  14759. **/
  14760. /*==========================================
  14761. * Magic Decoy Material List
  14762. *------------------------------------------*/
  14763. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14764. int i, c;
  14765. int fd;
  14766. nullpo_ret(sd);
  14767. fd = sd->fd;
  14768. WFIFOHEAD(fd, 8 * 8 + 8);
  14769. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14770. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14771. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14772. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14773. c ++;
  14774. }
  14775. }
  14776. if( c > 0 ) {
  14777. sd->menuskill_id = NC_MAGICDECOY;
  14778. sd->menuskill_val = skill_lv;
  14779. sd->sc.comet_x = x;
  14780. sd->sc.comet_y = y;
  14781. WFIFOW(fd,2) = c * 2 + 4;
  14782. WFIFOSET(fd, WFIFOW(fd, 2));
  14783. } else {
  14784. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14785. return 0;
  14786. }
  14787. return 1;
  14788. }
  14789. /*==========================================
  14790. * Guillotine Cross Poisons List
  14791. *------------------------------------------*/
  14792. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14793. int i, c;
  14794. int fd;
  14795. nullpo_ret(sd);
  14796. fd = sd->fd;
  14797. WFIFOHEAD(fd, 8 * 8 + 8);
  14798. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14799. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14800. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14801. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14802. c ++;
  14803. }
  14804. }
  14805. if( c > 0 ) {
  14806. sd->menuskill_id = GC_POISONINGWEAPON;
  14807. sd->menuskill_val = skill_lv;
  14808. WFIFOW(fd,2) = c * 2 + 4;
  14809. WFIFOSET(fd, WFIFOW(fd, 2));
  14810. } else {
  14811. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14812. return 0;
  14813. }
  14814. return 1;
  14815. }
  14816. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14817. int fd, i, c;
  14818. nullpo_ret(sd);
  14819. fd = sd->fd;
  14820. if( !fd ) return 0;
  14821. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14822. return 0;
  14823. WFIFOHEAD(fd, 2 * 6 + 4);
  14824. WFIFOW(fd,0) = 0x442;
  14825. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14826. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14827. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14828. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14829. {
  14830. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14831. c++;
  14832. }
  14833. if( c > 0 ) {
  14834. WFIFOW(fd,2) = 8 + c * 2;
  14835. WFIFOL(fd,4) = c;
  14836. WFIFOSET(fd,WFIFOW(fd,2));
  14837. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14838. sd->menuskill_val = c;
  14839. } else {
  14840. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14841. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14842. }
  14843. return 1;
  14844. }
  14845. /*===========================================
  14846. * Skill list for Four Elemental Analysis
  14847. * and Change Material skills.
  14848. *------------------------------------------*/
  14849. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14850. {
  14851. #if PACKETVER >= 20090922
  14852. int fd;
  14853. nullpo_ret(sd);
  14854. sd->menuskill_id = skill_id; // To prevent hacking.
  14855. sd->menuskill_val = skill_lv;
  14856. if( skill_id == GN_CHANGEMATERIAL )
  14857. skill_lv = 0; // Changematerial
  14858. fd = sd->fd;
  14859. WFIFOHEAD(fd,packet_len(0x7e3));
  14860. WFIFOW(fd,0) = 0x7e3;
  14861. WFIFOL(fd,2) = skill_lv;
  14862. WFIFOL(fd,4) = 0;
  14863. WFIFOSET(fd,packet_len(0x7e3));
  14864. #endif
  14865. return 1;
  14866. }
  14867. /*==========================================
  14868. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14869. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14870. * RFIFOL(fd,2) - type (currently not used)
  14871. *------------------------------------------*/
  14872. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14873. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14874. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14875. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14876. return;
  14877. if( pc_istrading(sd) ) {
  14878. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14879. clif_menuskill_clear(sd);
  14880. return;
  14881. }
  14882. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14883. clif_menuskill_clear(sd);
  14884. }
  14885. /*==========================================
  14886. * Kagerou/Oboro amulet spirit
  14887. *------------------------------------------*/
  14888. void clif_spiritcharm(struct map_session_data *sd)
  14889. {
  14890. unsigned char buf[10];
  14891. nullpo_retv(sd);
  14892. WBUFW(buf,0)=0x08cf;
  14893. WBUFL(buf,2)=sd->bl.id;
  14894. WBUFW(buf,6)=sd->spiritcharm_type;
  14895. WBUFW(buf,8)=sd->spiritcharm;
  14896. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14897. }
  14898. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14899. /// 0907 <index>.W
  14900. ///
  14901. /// R 0908 <index>.w <type>.b
  14902. /// type:
  14903. /// 0 = move item to personal tab
  14904. /// 1 = move item to normal tab
  14905. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14906. #if PACKETVER >= 20111122
  14907. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14908. int index = RFIFOW(fd,info->pos[0])-2;
  14909. int type = RFIFOB(fd, info->pos[1]);
  14910. /* can't move while dead. */
  14911. if(pc_isdead(sd)) {
  14912. return;
  14913. }
  14914. if (index < 0 || index >= MAX_INVENTORY)
  14915. return;
  14916. if ( sd->status.inventory[index].favorite && type == 1 )
  14917. sd->status.inventory[index].favorite = 0;
  14918. else if( type == 0 )
  14919. sd->status.inventory[index].favorite = 1;
  14920. else
  14921. return;/* nothing to do. */
  14922. clif_favorite_item(sd, index);
  14923. #endif
  14924. }
  14925. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14926. /// 0900 <index>.W <favorite>.B
  14927. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14928. int fd = sd->fd;
  14929. WFIFOHEAD(fd,packet_len(0x908));
  14930. WFIFOW(fd,0) = 0x908;
  14931. WFIFOW(fd,2) = index+2;
  14932. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14933. WFIFOSET(fd,packet_len(0x908));
  14934. }
  14935. void clif_snap( struct block_list *bl, short x, short y ) {
  14936. unsigned char buf[10];
  14937. WBUFW(buf,0) = 0x8d2;
  14938. WBUFL(buf,2) = bl->id;
  14939. WBUFW(buf,6) = x;
  14940. WBUFW(buf,8) = y;
  14941. if( disguised(bl) )
  14942. {
  14943. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14944. WBUFL(buf,2) = -bl->id;
  14945. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14946. } else
  14947. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14948. }
  14949. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14950. #if PACKETVER >= 20120404
  14951. WFIFOHEAD(fd,packet_len(0x977));
  14952. WFIFOW(fd,0) = 0x977;
  14953. WFIFOL(fd,2) = md->bl.id;
  14954. WFIFOL(fd,6) = md->status.hp;
  14955. WFIFOL(fd,10) = md->status.max_hp;
  14956. WFIFOSET(fd,packet_len(0x977));
  14957. #endif
  14958. }
  14959. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14960. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14961. return;
  14962. }
  14963. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14964. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14965. WFIFOW(sd->fd,0) = 0x2c9;
  14966. WFIFOB(sd->fd,2) = flag;
  14967. WFIFOSET(sd->fd, packet_len(0x2c9));
  14968. }
  14969. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14970. /// 0979 <world name>.24B <char name>.24B
  14971. void clif_ackworldinfo(struct map_session_data* sd) {
  14972. int fd;
  14973. nullpo_retv(sd);
  14974. fd = sd->fd;
  14975. WFIFOHEAD(fd,packet_len(0x979));
  14976. WFIFOW(fd,0)=0x979;
  14977. //AID -> world name ?
  14978. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14979. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14980. WFIFOSET(fd,packet_len(0x979));
  14981. }
  14982. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14983. /// 0978 <AID>.L
  14984. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14985. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14986. if(sd) clif_ackworldinfo(sd);
  14987. }
  14988. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14989. /// 0447
  14990. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14991. //if(sd)
  14992. ;
  14993. }
  14994. /// req world info (CZ_CLIENT_VERSION)
  14995. /// 044A <version>.L
  14996. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14997. //if(sd)
  14998. ;
  14999. }
  15000. /// Ranking list
  15001. /// ranking pointlist { <name>.24B <point>.L }*10
  15002. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  15003. struct fame_list* list;
  15004. int skip = 0;
  15005. switch(rankingtype+1) { //to keep the same case as char.c
  15006. case 1: list = smith_fame_list; break;
  15007. case 2: list = chemist_fame_list; break;
  15008. case 3: list = taekwon_fame_list; break;
  15009. default: skip=1; break;
  15010. }
  15011. if(!skip) {
  15012. int i;
  15013. //Packet size limits this list to 10 elements. [Skotlex]
  15014. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  15015. if (list[i].id > 0) {
  15016. const char* name;
  15017. if (strcmp(list[i].name, "-") == 0 &&
  15018. (name = map_charid2nick(list[i].id)) != NULL)
  15019. {
  15020. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  15021. } else {
  15022. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  15023. }
  15024. } else {
  15025. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  15026. }
  15027. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  15028. }
  15029. for(;i < 10; i++) { //In case the MAX is less than 10.
  15030. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  15031. WBUFL(buf, idx+24*10 + i * 4) = 0;
  15032. }
  15033. }
  15034. }
  15035. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15036. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15037. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  15038. int mypoint = 0;
  15039. WBUFW(buf,0) = 0x97d;
  15040. WBUFW(buf,2) = rankingType;
  15041. clif_sub_ranklist(buf,4,sd,rankingType);
  15042. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15043. case MAPID_BLACKSMITH:
  15044. case MAPID_ALCHEMIST:
  15045. case MAPID_TAEKWON:
  15046. mypoint = sd->status.fame;
  15047. }
  15048. WBUFL(buf,284) = mypoint; //mypoint
  15049. clif_send(buf, 288, &sd->bl, SELF);
  15050. }
  15051. /*
  15052. * 097c <type> (CZ_REQ_RANKING)
  15053. * type
  15054. * 0: /blacksmith
  15055. * 1: /alchemist
  15056. * 2: /taekwon
  15057. * 3: /pk
  15058. * */
  15059. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15060. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  15061. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15062. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  15063. }
  15064. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15065. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15066. #if PACKETVER < 20130710
  15067. switch(rankingtype){
  15068. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  15069. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  15070. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  15071. }
  15072. #else
  15073. int fd=sd->fd;
  15074. WFIFOHEAD(fd,14);
  15075. WFIFOW(fd,0) = 0x97e;
  15076. WFIFOW(fd,2) = rankingtype;
  15077. WFIFOL(fd,4) = point;
  15078. WFIFOL(fd,8) = sd->status.fame;
  15079. WFIFOSET(fd,12);
  15080. #endif
  15081. }
  15082. /**
  15083. * Transmit personal information to player. (rates)
  15084. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15085. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15086. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15087. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15088. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15089. * FIXME!
  15090. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15091. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15092. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15093. */
  15094. #ifdef VIP_ENABLE
  15095. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15096. if (sd) {
  15097. struct s_packet_db* info;
  15098. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15099. int cmd = 0, fd, i = 0;
  15100. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15101. int details_bexp[PINFO_MAX];
  15102. int details_drop[PINFO_MAX];
  15103. int details_penalty[PINFO_MAX];
  15104. int penalty_const;
  15105. /**
  15106. * Set for EXP
  15107. */
  15108. //0:PCRoom
  15109. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15110. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  15111. details_bexp[0] = 0;
  15112. else {
  15113. if (details_bexp[0] < 100) {
  15114. details_bexp[0] = 100 - details_bexp[0];
  15115. details_bexp[0] = 0 - details_bexp[0];
  15116. }
  15117. else
  15118. details_bexp[0] = details_bexp[0] - 100;
  15119. }
  15120. //1:Premium
  15121. if (pc_isvip(sd)) {
  15122. details_bexp[1] = battle_config.vip_base_exp_increase;
  15123. if (details_bexp[1] < 0)
  15124. details_bexp[1] = 0 - details_bexp[1];
  15125. }
  15126. else
  15127. details_bexp[1] = 0;
  15128. //2:Server
  15129. details_bexp[2] = battle_config.base_exp_rate;
  15130. if (details_bexp[2] == 100)
  15131. details_bexp[2] = 0;
  15132. else {
  15133. if (details_bexp[2] < 100) {
  15134. details_bexp[2] = 100 - details_bexp[2];
  15135. details_bexp[2] = 0 - details_bexp[2];
  15136. }
  15137. else
  15138. details_bexp[2] = details_bexp[2] - 100;
  15139. }
  15140. //3:TPLUS
  15141. details_bexp[3] = 0;
  15142. /* End - EXP set*/
  15143. /**
  15144. * Set for Drop rate
  15145. */
  15146. //0:PCRoom
  15147. details_drop[0] = 0;
  15148. //1:Premium
  15149. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15150. if (pc_isvip(sd)) {
  15151. if (details_drop[1] < 0)
  15152. details_drop[1] = 0 - details_drop[1];
  15153. }
  15154. else
  15155. details_drop[1] = 0;
  15156. //2:Server
  15157. details_drop[2] = battle_config.item_rate_common;
  15158. if (details_drop[2] == 100)
  15159. details_drop[2] = 0;
  15160. else {
  15161. if (details_drop[2] < 100) {
  15162. details_drop[2] = 100 - details_drop[2];
  15163. details_drop[2] = 0 - details_drop[2];
  15164. }
  15165. else
  15166. details_drop[2] = details_drop[2] - 100;
  15167. }
  15168. //3:TPLUS
  15169. details_drop[3] = 0;
  15170. /* End - Drop set*/
  15171. /**
  15172. * Set for Penalty rate
  15173. */
  15174. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  15175. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  15176. //0:PCRoom
  15177. details_penalty[0] = 0;
  15178. //1:Premium
  15179. if (pc_isvip(sd)) {
  15180. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  15181. if (details_penalty[1] == 100)
  15182. details_penalty[1] = 0;
  15183. else {
  15184. if (details_penalty[1] < 100) {
  15185. details_penalty[1] = 100 - details_penalty[1];
  15186. details_penalty[1] = 0 - details_penalty[1];
  15187. }
  15188. else
  15189. details_penalty[1] = details_penalty[1] - 100;
  15190. }
  15191. }
  15192. else
  15193. details_penalty[1] = 0;
  15194. //2:Server
  15195. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  15196. if (details_penalty[2] == 100)
  15197. details_penalty[2] = 0;
  15198. else {
  15199. if (details_penalty[2] < 100) {
  15200. details_penalty[2] = 100 - details_penalty[2];
  15201. details_penalty[2] = 0 - details_penalty[2];
  15202. }
  15203. else
  15204. details_penalty[2] = details_penalty[2] - 100;
  15205. }
  15206. //3:TPLUS
  15207. details_penalty[3] = 0;
  15208. /* End - Penalty set*/
  15209. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  15210. info = &packet_db[sd->packet_ver][cmd];
  15211. len = info->len; //this is the base len without details
  15212. if(!len) return; //version as packet disable
  15213. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15214. szdetails = 7;
  15215. factor = 1;
  15216. }
  15217. else if (cmd == 0x097b) {
  15218. tot_baseexp *= factor;
  15219. tot_drop *= factor;
  15220. tot_penalty *= factor;
  15221. }
  15222. fd = sd->fd;
  15223. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15224. WFIFOW(fd,0) = cmd;
  15225. for (i = 0; i < maxinfotype; i++) {
  15226. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15227. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15228. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15229. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15230. tot_baseexp += details_bexp[i]*factor;
  15231. tot_drop += details_penalty[i]*factor;
  15232. tot_penalty += details_drop[i]*factor;
  15233. len += szdetails;
  15234. }
  15235. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15236. if (cmd == 0x08cb) { //0x08cb version
  15237. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15238. WFIFOW(fd,info->pos[2]) = tot_drop;
  15239. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15240. }
  15241. else { //2013-08-07aRagexe uses 0x097b
  15242. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15243. WFIFOL(fd,info->pos[2]) = tot_drop;
  15244. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15245. }
  15246. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15247. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15248. WFIFOSET(fd,len);
  15249. }
  15250. }
  15251. #endif
  15252. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15253. char cmd[30];
  15254. int t_aid = RFIFOL(fd,2);
  15255. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15256. is_atcommand(fd, sd, cmd, 1);
  15257. }
  15258. /**
  15259. * Marks Crimson Marker target on mini-map to the caster
  15260. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15261. * @param fd
  15262. * @param bl Crimson Marker target
  15263. **/
  15264. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15265. struct s_packet_db* info;
  15266. int cmd = 0;
  15267. int16 len;
  15268. unsigned char buf[11];
  15269. nullpo_retv(sd);
  15270. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  15271. if (!cmd)
  15272. cmd = 0x09C1; //default
  15273. info = &packet_db[sd->packet_ver][cmd];
  15274. if (!(len = info->len))
  15275. return;
  15276. WBUFW(buf, 0) = cmd;
  15277. WBUFL(buf, info->pos[0]) = bl->id;
  15278. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15279. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15280. clif_send(buf, len, &sd->bl, SELF);
  15281. }
  15282. /**
  15283. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15284. **/
  15285. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15286. struct s_packet_db *info = NULL;
  15287. int cmd = 0;
  15288. nullpo_retv(sd);
  15289. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  15290. info = &packet_db[sd->packet_ver][cmd];
  15291. if (!cmd || !info->len)
  15292. return;
  15293. WFIFOHEAD(sd->fd, info->len);
  15294. WFIFOW(sd->fd, 0) = cmd;
  15295. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15296. WFIFOSET(sd->fd, info->len);
  15297. }
  15298. /// [Ind/Hercules]
  15299. void clif_showscript(struct block_list* bl, const char* message) {
  15300. char buf[256];
  15301. size_t len;
  15302. nullpo_retv(bl);
  15303. if(!message)
  15304. return;
  15305. len = strlen(message)+1;
  15306. if( len > sizeof(buf)-8 ) {
  15307. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15308. len = sizeof(buf)-8;
  15309. }
  15310. WBUFW(buf,0) = 0x8b3;
  15311. WBUFW(buf,2) = (uint16)(len+8);
  15312. WBUFL(buf,4) = bl->id;
  15313. safestrncpy((char *) WBUFP(buf,8), message, len);
  15314. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  15315. }
  15316. /// [Ind/Hercules]
  15317. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15318. unsigned char buf[10];
  15319. nullpo_retv(sd);
  15320. WBUFW(buf,0) = 0x7fc;
  15321. WBUFL(buf,2) = prev_leader_aid;
  15322. WBUFL(buf,6) = new_leader_aid;
  15323. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  15324. }
  15325. /**
  15326. * Decrypt packet identifier for player
  15327. * @param fd
  15328. * @param sd
  15329. * @param packet_ver
  15330. * Orig author [Ind/Hercules]
  15331. **/
  15332. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15333. #ifndef PACKET_OBFUSCATION
  15334. return RFIFOW(fd, 0);
  15335. #else
  15336. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15337. if (sd)
  15338. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15339. else
  15340. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF)); // A player tries to connect - use the initial keys for the decryption of the packet ID.
  15341. return cmd; // Return the decrypted packet ID.
  15342. #endif
  15343. }
  15344. #ifdef DUMP_UNKNOWN_PACKET
  15345. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15346. {
  15347. const char* packet_txt = "save/packet.txt";
  15348. FILE* fp;
  15349. time_t time_server;
  15350. struct tm *datetime;
  15351. char datestr[512];
  15352. time(&time_server); // get time in seconds since 1/1/1970
  15353. datetime = localtime(&time_server); // convert seconds in structure
  15354. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15355. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15356. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15357. if( sd ) {
  15358. 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);
  15359. } else {
  15360. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15361. }
  15362. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15363. fprintf(fp, "\n");
  15364. fclose(fp);
  15365. } else {
  15366. ShowError("Failed to write '%s'.\n", packet_txt);
  15367. // Dump on console instead
  15368. if( sd ) {
  15369. 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);
  15370. } else {
  15371. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15372. }
  15373. ShowDump(RFIFOP(fd,0), packet_len);
  15374. }
  15375. }
  15376. #endif
  15377. /// Roulette System
  15378. /// Author: Yommy
  15379. /**
  15380. * Opens Roulette window
  15381. * @param fd
  15382. * @param sd
  15383. */
  15384. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15385. {
  15386. nullpo_retv(sd);
  15387. if (!battle_config.feature_roulette) {
  15388. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15389. return;
  15390. }
  15391. WFIFOHEAD(fd,packet_len(0xa1a));
  15392. WFIFOW(fd,0) = 0xa1a;
  15393. WFIFOB(fd,2) = 0; // result
  15394. WFIFOL(fd,3) = 0; // serial
  15395. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15396. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15397. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15398. WFIFOL(fd,11) = sd->roulette_point.gold;
  15399. WFIFOL(fd,15) = sd->roulette_point.silver;
  15400. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15401. WFIFOSET(fd,packet_len(0xa1a));
  15402. }
  15403. /**
  15404. * Generates information to be displayed
  15405. * @param fd
  15406. * @param sd
  15407. */
  15408. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15409. {
  15410. unsigned short i, j, count = 0;
  15411. int len = 8 + (42 * 8);
  15412. nullpo_retv(sd);
  15413. if (!battle_config.feature_roulette) {
  15414. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15415. return;
  15416. }
  15417. WFIFOHEAD(fd,len);
  15418. WFIFOW(fd,0) = 0xa1c;
  15419. WFIFOW(fd,2) = len;
  15420. WFIFOL(fd,4) = 1; // serial
  15421. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15422. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15423. WFIFOW(fd,8 * count + 8) = i;
  15424. WFIFOW(fd,8 * count + 10) = j;
  15425. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15426. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15427. count++;
  15428. }
  15429. }
  15430. WFIFOSET(fd,len);
  15431. return;
  15432. }
  15433. /**
  15434. * Closes Roulette window
  15435. * @param fd
  15436. * @param sd
  15437. */
  15438. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15439. {
  15440. nullpo_retv(sd);
  15441. if (!battle_config.feature_roulette) {
  15442. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15443. return;
  15444. }
  15445. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15446. return;
  15447. }
  15448. /**
  15449. *
  15450. **/
  15451. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15452. #if PACKETVER >= 20141016
  15453. uint16 cmd = 0xa22;
  15454. unsigned char buf[5];
  15455. nullpo_retv(sd);
  15456. if (packet_db[sd->packet_ver][cmd].len == 0)
  15457. return;
  15458. WBUFW(buf,0) = cmd;
  15459. WBUFB(buf,2) = type;
  15460. WBUFW(buf,3) = 0; //! TODO: Additional item
  15461. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15462. #endif
  15463. }
  15464. /**
  15465. * Claim roulette reward
  15466. * @param sd Player
  15467. * @return 0:Success
  15468. **/
  15469. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15470. struct item it;
  15471. uint8 res = 1;
  15472. nullpo_retr(1, sd);
  15473. if (sd->roulette.prizeIdx < 0)
  15474. return RECV_ITEM_FAILED;
  15475. memset(&it, 0, sizeof(it));
  15476. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15477. it.identify = 1;
  15478. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15479. ; // onSuccess
  15480. }
  15481. sd->roulette.claimPrize = false;
  15482. sd->roulette.prizeStage = 0;
  15483. sd->roulette.prizeIdx = -1;
  15484. sd->roulette.stage = 0;
  15485. return res;
  15486. }
  15487. /**
  15488. * Process the stage and attempt to give a prize
  15489. * @param fd
  15490. * @param sd
  15491. */
  15492. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15493. {
  15494. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15495. short stage = sd->roulette.stage;
  15496. nullpo_retv(sd);
  15497. if (!battle_config.feature_roulette) {
  15498. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15499. return;
  15500. }
  15501. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15502. stage = sd->roulette.stage = 0;
  15503. if (!stage) {
  15504. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15505. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15506. }
  15507. if (result == GENERATE_ROULETTE_SUCCESS) {
  15508. if (!stage) {
  15509. if (sd->roulette_point.bronze > 0) {
  15510. sd->roulette_point.bronze -= 1;
  15511. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15512. } else if (sd->roulette_point.silver > 9) {
  15513. sd->roulette_point.silver -= 10;
  15514. stage = sd->roulette.stage = 2;
  15515. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15516. } else if (sd->roulette_point.gold > 9) {
  15517. sd->roulette_point.gold -= 10;
  15518. stage = sd->roulette.stage = 4;
  15519. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15520. }
  15521. }
  15522. sd->roulette.prizeStage = stage;
  15523. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15524. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15525. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15526. clif_roulette_getitem(sd);
  15527. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15528. return;
  15529. }
  15530. else {
  15531. sd->roulette.claimPrize = true;
  15532. sd->roulette.stage++;
  15533. }
  15534. }
  15535. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15536. }
  15537. /**
  15538. * Request to cash in prize
  15539. * @param fd
  15540. * @param sd
  15541. */
  15542. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15543. {
  15544. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15545. nullpo_retv(sd);
  15546. if (!battle_config.feature_roulette) {
  15547. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15548. return;
  15549. }
  15550. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15551. switch (clif_roulette_getitem(sd)) {
  15552. case 0:
  15553. type = RECV_ITEM_SUCCESS;
  15554. break;
  15555. case 1:
  15556. case 4:
  15557. case 5:
  15558. type = RECV_ITEM_OVERCOUNT;
  15559. break;
  15560. case 2:
  15561. type = RECV_ITEM_OVERWEIGHT;
  15562. break;
  15563. case 7:
  15564. default:
  15565. type = RECV_ITEM_FAILED;
  15566. break;
  15567. }
  15568. }
  15569. clif_roulette_recvitem_ack(sd,type);
  15570. return;
  15571. }
  15572. /**
  15573. * Update Roulette window with current stats
  15574. * @param sd
  15575. * @param result
  15576. * @param stage
  15577. * @param prizeIdx
  15578. * @param bonusItemID
  15579. */
  15580. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15581. {
  15582. int fd = sd->fd;
  15583. nullpo_retv(sd);
  15584. WFIFOHEAD(fd,packet_len(0xa20));
  15585. WFIFOW(fd,0) = 0xa20;
  15586. WFIFOB(fd,2) = result;
  15587. WFIFOW(fd,3) = stage;
  15588. WFIFOW(fd,5) = prizeIdx;
  15589. WFIFOW(fd,7) = bonusItemID;
  15590. WFIFOL(fd,9) = sd->roulette_point.gold;
  15591. WFIFOL(fd,13) = sd->roulette_point.silver;
  15592. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15593. WFIFOSET(fd,packet_len(0xa20));
  15594. }
  15595. /// MERGE ITEM
  15596. /**
  15597. * Acknowledge the client about item merger result
  15598. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15599. * @param fd
  15600. * @param sd
  15601. **/
  15602. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15603. unsigned char buf[9];
  15604. struct s_packet_db *info = NULL;
  15605. short cmd = 0;
  15606. nullpo_retv(sd);
  15607. if (!clif_session_isValid(sd))
  15608. return;
  15609. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15610. return;
  15611. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15612. return;
  15613. WBUFW(buf, 0) = cmd;
  15614. WBUFW(buf, info->pos[0]) = index;
  15615. WBUFW(buf, info->pos[1]) = count;
  15616. WBUFB(buf, info->pos[2]) = type;
  15617. clif_send(buf, info->len, &sd->bl, SELF);
  15618. }
  15619. /**
  15620. * Check if item has the pair to be merged
  15621. * @param sd
  15622. * @param it Item
  15623. * @return True if has pair, False if not
  15624. **/
  15625. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15626. struct item *it_;
  15627. unsigned short i;
  15628. nullpo_retr(false, sd);
  15629. ARR_FIND(0, MAX_INVENTORY, i, (it_ = &sd->status.inventory[i]) && it->nameid == it_->nameid && it->bound == it_->bound && memcmp(it_, it, sizeof(struct item)) != 0);
  15630. if (i < MAX_INVENTORY)
  15631. return true;
  15632. return false;
  15633. }
  15634. /**
  15635. * Check if item can be merged
  15636. * @param id Item Data
  15637. * @param it Item
  15638. * @return True if can be merged, False if not
  15639. **/
  15640. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15641. if (!id || !it)
  15642. return false;
  15643. if (id->type == IT_CASH)
  15644. return false;
  15645. if (!itemdb_isstackable2(id))
  15646. return false;
  15647. if (itemdb_isspecial(it->card[0]))
  15648. return false;
  15649. if (!it->unique_id)
  15650. return false;
  15651. return true;
  15652. }
  15653. /**
  15654. * Open available item to be merged.
  15655. * Only show 1 item in 1 process.
  15656. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15657. * @param sd
  15658. **/
  15659. void clif_merge_item_open(struct map_session_data *sd) {
  15660. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15661. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15662. int len = 0;
  15663. struct s_packet_db *info = NULL;
  15664. struct item *it;
  15665. nullpo_retv(sd);
  15666. if (!clif_session_isValid(sd))
  15667. return;
  15668. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15669. return;
  15670. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15671. return;
  15672. // Get entries
  15673. for (i = 0; i < MAX_INVENTORY; i++) {
  15674. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15675. continue;
  15676. if (clif_merge_item_has_pair(sd, it))
  15677. indexes[n++] = i;
  15678. }
  15679. if (n < 2) { // No item need to be merged
  15680. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15681. return;
  15682. }
  15683. WBUFW(buf, 0) = cmd;
  15684. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15685. for (i = 0; i < n; i++) {
  15686. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15687. }
  15688. clif_send(buf, len, &sd->bl, SELF);
  15689. }
  15690. /**
  15691. * Process item merger
  15692. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15693. * @param fd
  15694. * @param sd
  15695. **/
  15696. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15697. struct s_packet_db *info = NULL;
  15698. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15699. unsigned int count = 0;
  15700. struct item_data *id = NULL;
  15701. nullpo_retv(sd);
  15702. if (!clif_session_isValid(sd))
  15703. return;
  15704. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15705. return;
  15706. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15707. if (n < 2) { // No item need to be merged
  15708. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15709. return;
  15710. }
  15711. for (i = 0, j = 0; i < n; i++) {
  15712. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15713. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15714. continue;
  15715. indexes[j] = idx;
  15716. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15717. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15718. return;
  15719. }
  15720. count += sd->status.inventory[idx].amount;
  15721. j++;
  15722. }
  15723. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15724. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15725. return;
  15726. }
  15727. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15728. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15729. return;
  15730. }
  15731. // Merrrrge!!!!
  15732. for (i = 1; i < n; i++) {
  15733. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15734. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15735. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15736. sd->inventory_data[idx] = NULL;
  15737. clif_delitem(sd, idx, amt, 0);
  15738. }
  15739. sd->status.inventory[indexes[0]].amount = count;
  15740. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15741. }
  15742. /**
  15743. * Cancel item merge
  15744. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15745. * @param fd
  15746. * @param sd
  15747. **/
  15748. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15749. return; // Nothing todo yet
  15750. }
  15751. /**
  15752. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15753. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15754. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15755. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15756. **/
  15757. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type, const char *srcname) {
  15758. unsigned char buf[9 + NAME_LENGTH * 2];
  15759. unsigned short cmd = 0;
  15760. struct s_packet_db *info = NULL;
  15761. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15762. return;
  15763. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15764. return;
  15765. WBUFW(buf, 0) = 0x7fd;
  15766. WBUFB(buf, 4) = type;
  15767. WBUFW(buf, 5) = nameid;
  15768. WBUFB(buf, 7) = NAME_LENGTH;
  15769. safestrncpy((char *)WBUFP(buf, 8), char_name, NAME_LENGTH);
  15770. switch (type) {
  15771. case ITEMOBTAIN_TYPE_BOXITEM:
  15772. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15773. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15774. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15775. break;
  15776. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15777. {
  15778. struct mob_db *db = mob_db(container);
  15779. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15780. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15781. safestrncpy((char *)WBUFP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15782. }
  15783. break;
  15784. case ITEMOBTAIN_TYPE_NPC:
  15785. default:
  15786. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15787. break;
  15788. }
  15789. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15790. }
  15791. /// Show body view windows (ZC_DRESSROOM_OPEN).
  15792. /// 0A02 <view>.W
  15793. /// Value <flag> has the following effects:
  15794. /// 0: Close an open Dress Room window.
  15795. /// 1: Open a Dress Room window.
  15796. void clif_dressing_room(struct map_session_data *sd, int flag) {
  15797. #if PACKETVER >= 20150513
  15798. int fd = sd->fd;
  15799. nullpo_retv(sd);
  15800. WFIFOHEAD(fd, packet_len(0xa02));
  15801. WFIFOW(fd,0) = 0xa02;
  15802. WFIFOW(fd,2) = flag;
  15803. WFIFOSET(fd, packet_len(0xa02));
  15804. #endif
  15805. }
  15806. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  15807. /// 0A35 <result>.W
  15808. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  15809. #if PACKETVER >= 20150513
  15810. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2;
  15811. int i;
  15812. // Invalid index - ignore the request
  15813. if ( idx < 0 )
  15814. return;
  15815. // Item already identified - ignore the request
  15816. if ( sd->status.inventory[idx].identify )
  15817. return;
  15818. if ( ( i = pc_search_inventory(sd,ITEMID_MAGNIFIER) ) == -1 )
  15819. return;
  15820. if ( pc_delitem(sd, i, 1, 0, 0, LOG_TYPE_OTHER) != 0 ) {
  15821. // TODO: deleting magnifier failed, for whatever reason...
  15822. return;
  15823. }
  15824. skill_identify(sd, idx);
  15825. #endif
  15826. }
  15827. /*==========================================
  15828. * Main client packet processing function
  15829. *------------------------------------------*/
  15830. static int clif_parse(int fd)
  15831. {
  15832. int cmd, packet_ver, packet_len, err;
  15833. TBL_PC* sd;
  15834. int pnum;
  15835. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15836. // Note: "click masters" can do 80+ clicks in 10 seconds
  15837. 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]
  15838. { // begin main client packet processing loop
  15839. sd = (TBL_PC *)session[fd]->session_data;
  15840. if (session[fd]->flag.eof) {
  15841. if (sd) {
  15842. if (sd->state.autotrade) {
  15843. //Disassociate character from the socket connection.
  15844. session[fd]->session_data = NULL;
  15845. sd->fd = 0;
  15846. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15847. } else
  15848. if (sd->state.active) {
  15849. // Player logout display [Valaris]
  15850. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15851. clif_quitsave(fd, sd);
  15852. } else {
  15853. //Unusual logout (during log on/off/map-changer procedure)
  15854. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15855. map_quit(sd);
  15856. }
  15857. } else {
  15858. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15859. }
  15860. do_close(fd);
  15861. return 0;
  15862. }
  15863. if (RFIFOREST(fd) < 2)
  15864. return 0;
  15865. cmd = clif_parse_cmd(fd, sd);
  15866. // identify client's packet version
  15867. if (sd) {
  15868. packet_ver = sd->packet_ver;
  15869. } else {
  15870. // check authentification packet to know packet version
  15871. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15872. if( err ) {// failed to identify packet version
  15873. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15874. err == 1 ? "" :
  15875. err == 2 ? ", possibly for having an invalid account_id" :
  15876. err == 3 ? ", possibly for having an invalid char_id." :
  15877. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15878. err == 4 ? ", possibly for having an invalid login_id1." :
  15879. err == 5 ? ", possibly for having an invalid client_tick." :
  15880. */
  15881. err == 6 ? ", possibly for having an invalid sex." :
  15882. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15883. WFIFOHEAD(fd,packet_len(0x6a));
  15884. WFIFOW(fd,0) = 0x6a;
  15885. WFIFOB(fd,2) = 3; // Rejected from Server
  15886. WFIFOSET(fd,packet_len(0x6a));
  15887. #ifdef DUMP_INVALID_PACKET
  15888. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15889. #endif
  15890. RFIFOSKIP(fd, RFIFOREST(fd));
  15891. set_eof(fd);
  15892. return 0;
  15893. }
  15894. }
  15895. // filter out invalid / unsupported packets
  15896. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15897. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15898. #ifdef DUMP_INVALID_PACKET
  15899. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15900. #endif
  15901. set_eof(fd);
  15902. return 0;
  15903. }
  15904. // determine real packet length
  15905. packet_len = packet_db[packet_ver][cmd].len;
  15906. if (packet_len == -1) { // variable-length packet
  15907. if (RFIFOREST(fd) < 4)
  15908. return 0;
  15909. packet_len = RFIFOW(fd,2);
  15910. if (packet_len < 4 || packet_len > 32768) {
  15911. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15912. #ifdef DUMP_INVALID_PACKET
  15913. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15914. #endif
  15915. set_eof(fd);
  15916. return 0;
  15917. }
  15918. }
  15919. if ((int)RFIFOREST(fd) < packet_len)
  15920. return 0; // not enough data received to form the packet
  15921. #ifdef PACKET_OBFUSCATION
  15922. RFIFOW(fd, 0) = cmd;
  15923. if (sd)
  15924. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15925. #endif
  15926. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15927. packet_db[packet_ver][cmd].func(fd, sd);
  15928. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15929. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15930. ; //Only valid packet when there is no session
  15931. else
  15932. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15933. ; //Only valid packet when player is not on a map
  15934. else
  15935. packet_db[packet_ver][cmd].func(fd, sd);
  15936. }
  15937. #ifdef DUMP_UNKNOWN_PACKET
  15938. else DumpUnknown(fd,sd,cmd,packet_len);
  15939. #endif
  15940. RFIFOSKIP(fd, packet_len);
  15941. }; // main loop end
  15942. return 0;
  15943. }
  15944. /*==========================================
  15945. * Reads packet_db.txt and setups its array reference
  15946. *------------------------------------------*/
  15947. void packetdb_readdb(bool reload)
  15948. {
  15949. char line[1024];
  15950. int cmd,i,j;
  15951. int max_cmd=-1;
  15952. bool skip_ver = false;
  15953. int warned = 0;
  15954. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15955. #ifdef PACKET_OBFUSCATION
  15956. bool key_defined = false;
  15957. int last_key_defined = -1;
  15958. #endif
  15959. int packet_len_table[MAX_PACKET_DB] = {
  15960. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15964. //#0x0040
  15965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15967. #if PACKETVER <= 20081217
  15968. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  15969. #else
  15970. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  15971. #endif
  15972. #if PACKETVER < 2
  15973. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  15974. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  15975. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  15976. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  15977. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  15978. #else
  15979. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  15980. #endif
  15981. //#0x0080
  15982. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  15983. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  15984. #if PACKETVER <= 20100622
  15985. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  15986. #else
  15987. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  15988. #endif
  15989. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  15990. //#0x00C0
  15991. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  15992. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  15993. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  15994. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  15995. //#0x0100
  15996. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  15997. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  15998. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  15999. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  16000. //#0x0140
  16001. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  16002. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  16003. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  16004. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  16005. //#0x0180
  16006. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  16007. #if PACKETVER < 1
  16008. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16009. #else // 196 comodo icon status display for later
  16010. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16011. #endif
  16012. #if PACKETVER < 20081126
  16013. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16014. #else // 0x1a2 changed (35->37)
  16015. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16016. #endif
  16017. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  16018. //#0x01C0, Set 0x1d5=-1
  16019. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  16020. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  16021. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  16022. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  16023. //#0x0200
  16024. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  16025. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  16026. #if PACKETVER < 20071106
  16027. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  16028. #else // 0x22c changed
  16029. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  16030. #endif
  16031. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  16032. //#0x0240
  16033. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  16034. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  16035. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16036. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16037. //#0x0280
  16038. #if PACKETVER < 20070711
  16039. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  16040. #else
  16041. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  16042. #endif
  16043. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  16044. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16045. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  16046. //#0x02C0
  16047. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  16048. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  16049. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  16050. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16051. //#0x0300
  16052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16056. //#0x0340
  16057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16061. //#0x0380
  16062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16066. //#0x03C0
  16067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16071. //#0x0400
  16072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  16076. //#0x0440
  16077. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  16078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16081. //#0x0480
  16082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16086. //#0x04C0
  16087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16091. //#0x0500
  16092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16096. //#0x0540
  16097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16101. //#0x0580
  16102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16106. //#0x05C0
  16107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16111. //#0x0600
  16112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16116. //#0x0640
  16117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16121. //#0x0680
  16122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16126. //#0x06C0
  16127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16131. //#0x0700
  16132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16136. //#0x0740
  16137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16141. //#0x0780
  16142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16146. //#0x07C0
  16147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16148. #if PACKETVER < 20090617
  16149. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  16150. #else // 0x7d9 changed
  16151. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  16152. #endif
  16153. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  16154. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  16155. //#0x0800
  16156. #if PACKETVER < 20091229
  16157. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  16158. #else // for Party booking ( PACKETVER >= 20091229 )
  16159. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  16160. #endif
  16161. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  16162. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16163. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  16164. //#0x0840
  16165. #if PACKETVER < 20130000
  16166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16167. #else
  16168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  16169. #endif
  16170. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  16171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16173. //#0x0880
  16174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16177. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16178. //#0x08C0
  16179. 0, 0, 0, 0, 0, 0, 0, 20, 34, 0, 0, 0, 0, 0, 0, 10,
  16180. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16183. //#0x0900
  16184. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1,
  16185. 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16188. //#0x0940
  16189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  16192. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, -1, 0, 0, 0, 0, -1,
  16193. //#0x0980
  16194. 7, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16195. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  16196. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  16197. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  16198. //#0x09C0
  16199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 17, 0, 0,102, 0,
  16200. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, -1, -1, -1, 0, 7,
  16201. 0, 0, 0, 0, 0, 18, 22, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  16202. 0, 11, 12, 11, 0, 0, 0, 75, -1,143, 0, 0, 0, -1, -1, -1,
  16203. //#0x0A00
  16204. #if PACKETVER >= 20141022
  16205. 269, 3, 4, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 14, -1,
  16206. #else
  16207. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 14, 0,
  16208. #endif
  16209. -1, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  16210. 21, 3, 5, 0, 66, 0, 0, 8, 3, 0, 0, 0, 0, -1, 0, 0,
  16211. 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16212. };
  16213. struct {
  16214. void (*func)(int, struct map_session_data *);
  16215. char *name;
  16216. } clif_parse_func[]={
  16217. {clif_parse_WantToConnection,"wanttoconnection"},
  16218. {clif_parse_LoadEndAck,"loadendack"},
  16219. {clif_parse_TickSend,"ticksend"},
  16220. {clif_parse_WalkToXY,"walktoxy"},
  16221. {clif_parse_QuitGame,"quitgame"},
  16222. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  16223. {clif_parse_GlobalMessage,"globalmessage"},
  16224. {clif_parse_MapMove,"mapmove"},
  16225. {clif_parse_ChangeDir,"changedir"},
  16226. {clif_parse_Emotion,"emotion"},
  16227. {clif_parse_HowManyConnections,"howmanyconnections"},
  16228. {clif_parse_ActionRequest,"actionrequest"},
  16229. {clif_parse_Restart,"restart"},
  16230. {clif_parse_WisMessage,"wis"},
  16231. {clif_parse_Broadcast,"broadcast"},
  16232. {clif_parse_TakeItem,"takeitem"},
  16233. {clif_parse_DropItem,"dropitem"},
  16234. {clif_parse_UseItem,"useitem"},
  16235. {clif_parse_EquipItem,"equipitem"},
  16236. {clif_parse_UnequipItem,"unequipitem"},
  16237. {clif_parse_NpcClicked,"npcclicked"},
  16238. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  16239. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  16240. {clif_parse_NpcSellListSend,"npcselllistsend"},
  16241. {clif_parse_CreateChatRoom,"createchatroom"},
  16242. {clif_parse_ChatAddMember,"chataddmember"},
  16243. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  16244. {clif_parse_ChangeChatOwner,"changechatowner"},
  16245. {clif_parse_KickFromChat,"kickfromchat"},
  16246. {clif_parse_ChatLeave,"chatleave"},
  16247. {clif_parse_TradeRequest,"traderequest"},
  16248. {clif_parse_TradeAck,"tradeack"},
  16249. {clif_parse_TradeAddItem,"tradeadditem"},
  16250. {clif_parse_TradeOk,"tradeok"},
  16251. {clif_parse_TradeCancel,"tradecancel"},
  16252. {clif_parse_TradeCommit,"tradecommit"},
  16253. {clif_parse_StopAttack,"stopattack"},
  16254. {clif_parse_PutItemToCart,"putitemtocart"},
  16255. {clif_parse_GetItemFromCart,"getitemfromcart"},
  16256. {clif_parse_RemoveOption,"removeoption"},
  16257. {clif_parse_ChangeCart,"changecart"},
  16258. {clif_parse_StatusUp,"statusup"},
  16259. {clif_parse_SkillUp,"skillup"},
  16260. {clif_parse_UseSkillToId,"useskilltoid"},
  16261. {clif_parse_UseSkillToPos,"useskilltopos"},
  16262. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  16263. {clif_parse_UseSkillMap,"useskillmap"},
  16264. {clif_parse_RequestMemo,"requestmemo"},
  16265. {clif_parse_ProduceMix,"producemix"},
  16266. {clif_parse_Cooking,"cooking"},
  16267. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  16268. {clif_parse_NpcNextClicked,"npcnextclicked"},
  16269. {clif_parse_NpcAmountInput,"npcamountinput"},
  16270. {clif_parse_NpcStringInput,"npcstringinput"},
  16271. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  16272. {clif_parse_ItemIdentify,"itemidentify"},
  16273. {clif_parse_SelectArrow,"selectarrow"},
  16274. {clif_parse_AutoSpell,"autospell"},
  16275. {clif_parse_UseCard,"usecard"},
  16276. {clif_parse_InsertCard,"insertcard"},
  16277. {clif_parse_RepairItem,"repairitem"},
  16278. {clif_parse_WeaponRefine,"weaponrefine"},
  16279. {clif_parse_SolveCharName,"solvecharname"},
  16280. {clif_parse_ResetChar,"resetchar"},
  16281. {clif_parse_LocalBroadcast,"localbroadcast"},
  16282. {clif_parse_MoveToKafra,"movetokafra"},
  16283. {clif_parse_MoveFromKafra,"movefromkafra"},
  16284. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  16285. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  16286. {clif_parse_CloseKafra,"closekafra"},
  16287. {clif_parse_CreateParty,"createparty"},
  16288. {clif_parse_CreateParty2,"createparty2"},
  16289. {clif_parse_PartyInvite,"partyinvite"},
  16290. {clif_parse_PartyInvite2,"partyinvite2"},
  16291. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  16292. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  16293. {clif_parse_LeaveParty,"leaveparty"},
  16294. {clif_parse_RemovePartyMember,"removepartymember"},
  16295. {clif_parse_PartyChangeOption,"partychangeoption"},
  16296. {clif_parse_PartyMessage,"partymessage"},
  16297. {clif_parse_PartyChangeLeader,"partychangeleader"},
  16298. {clif_parse_CloseVending,"closevending"},
  16299. {clif_parse_VendingListReq,"vendinglistreq"},
  16300. {clif_parse_PurchaseReq,"purchasereq"},
  16301. {clif_parse_PurchaseReq2,"purchasereq2"},
  16302. {clif_parse_OpenVending,"openvending"},
  16303. {clif_parse_CreateGuild,"createguild"},
  16304. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  16305. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  16306. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  16307. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  16308. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  16309. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  16310. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  16311. {clif_parse_GuildInvite,"guildinvite"},
  16312. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  16313. {clif_parse_GuildLeave,"guildleave"},
  16314. {clif_parse_GuildExpulsion,"guildexpulsion"},
  16315. {clif_parse_GuildMessage,"guildmessage"},
  16316. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  16317. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  16318. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  16319. {clif_parse_GuildOpposition,"guildopposition"},
  16320. {clif_parse_GuildBreak,"guildbreak"},
  16321. {clif_parse_PetMenu,"petmenu"},
  16322. {clif_parse_CatchPet,"catchpet"},
  16323. {clif_parse_SelectEgg,"selectegg"},
  16324. {clif_parse_SendEmotion,"sendemotion"},
  16325. {clif_parse_ChangePetName,"changepetname"},
  16326. {clif_parse_GMKick,"gmkick"},
  16327. {clif_parse_GMHide,"gmhide"},
  16328. {clif_parse_GMReqNoChat,"gmreqnochat"},
  16329. {clif_parse_GMReqAccountName,"gmreqaccname"},
  16330. {clif_parse_GMKickAll,"killall"},
  16331. {clif_parse_GMRecall,"recall"},
  16332. {clif_parse_GMRecall,"summon"},
  16333. {clif_parse_GM_Item_Monster,"itemmonster"},
  16334. {clif_parse_GMShift,"remove"},
  16335. {clif_parse_GMShift,"shift"},
  16336. {clif_parse_GMChangeMapType,"changemaptype"},
  16337. {clif_parse_GMRc,"rc"},
  16338. {clif_parse_GMRecall2,"recall2"},
  16339. {clif_parse_GMRemove2,"remove2"},
  16340. {clif_parse_GMFullStrip,"gmfullstrip"},
  16341. {clif_parse_NoviceDoriDori,"sndoridori"},
  16342. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  16343. {clif_parse_PMIgnore,"wisexin"},
  16344. {clif_parse_PMIgnoreList,"wisexlist"},
  16345. {clif_parse_PMIgnoreAll,"wisall"},
  16346. {clif_parse_FriendsListAdd,"friendslistadd"},
  16347. {clif_parse_FriendsListRemove,"friendslistremove"},
  16348. {clif_parse_FriendsListReply,"friendslistreply"},
  16349. {clif_parse_Blacksmith,"blacksmith"},
  16350. {clif_parse_Alchemist,"alchemist"},
  16351. {clif_parse_Taekwon,"taekwon"},
  16352. {clif_parse_RankingPk,"rankingpk"},
  16353. {clif_parse_FeelSaveOk,"feelsaveok"},
  16354. {clif_parse_debug,"debug"},
  16355. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16356. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16357. {clif_parse_HomMoveTo,"hommoveto"},
  16358. {clif_parse_HomAttack,"homattack"},
  16359. {clif_parse_HomMenu,"hommenu"},
  16360. {clif_parse_StoragePassword,"storagepassword"},
  16361. {clif_parse_Hotkey,"hotkey"},
  16362. {clif_parse_AutoRevive,"autorevive"},
  16363. {clif_parse_Check,"check"},
  16364. {clif_parse_Adopt_request,"adoptrequest"},
  16365. {clif_parse_Adopt_reply,"adoptreply"},
  16366. // MAIL SYSTEM
  16367. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16368. {clif_parse_Mail_read,"mailread"},
  16369. {clif_parse_Mail_getattach,"mailgetattach"},
  16370. {clif_parse_Mail_delete,"maildelete"},
  16371. {clif_parse_Mail_return,"mailreturn"},
  16372. {clif_parse_Mail_setattach,"mailsetattach"},
  16373. {clif_parse_Mail_winopen,"mailwinopen"},
  16374. {clif_parse_Mail_send,"mailsend"},
  16375. // AUCTION SYSTEM
  16376. {clif_parse_Auction_search,"auctionsearch"},
  16377. {clif_parse_Auction_buysell,"auctionbuysell"},
  16378. {clif_parse_Auction_setitem,"auctionsetitem"},
  16379. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16380. {clif_parse_Auction_register,"auctionregister"},
  16381. {clif_parse_Auction_cancel,"auctioncancel"},
  16382. {clif_parse_Auction_close,"auctionclose"},
  16383. {clif_parse_Auction_bid,"auctionbid"},
  16384. // Quest Log System
  16385. {clif_parse_questStateAck,"queststate"},
  16386. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16387. {clif_parse_EquipTick,"equiptickbox"},
  16388. {clif_parse_BattleChat,"battlechat"},
  16389. {clif_parse_mercenary_action,"mermenu"},
  16390. {clif_parse_progressbar,"progressbar"},
  16391. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16392. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16393. #if PACKETVER >= 20091229
  16394. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16395. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16396. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16397. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16398. #endif
  16399. {clif_parse_BankCheck,"bankcheck"},
  16400. {clif_parse_BankDeposit,"bankdeposit"},
  16401. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16402. {clif_parse_BankOpen,"bankopen"},
  16403. {clif_parse_BankClose,"bankclose"},
  16404. {clif_parse_PVPInfo,"pvpinfo"},
  16405. {clif_parse_LessEffect,"lesseffect"},
  16406. // Buying Store
  16407. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16408. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16409. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16410. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16411. // Store Search
  16412. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16413. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16414. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16415. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16416. // Cashshop
  16417. { clif_parse_cashshop_open_request, "cashshopopen" },
  16418. { clif_parse_cashshop_close, "cashshopclose" },
  16419. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16420. { clif_parse_cashshop_buy, "cashshopbuy" },
  16421. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16422. /* */
  16423. { clif_parse_MoveItem , "moveitem" },
  16424. { clif_parse_PartyTick, "partytick" },
  16425. { clif_parse_dull, "dull" },
  16426. { clif_parse_GuildInvite2 , "guildinvite2" },
  16427. { clif_parse_reqworldinfo, "reqworldinfo"},
  16428. { clif_parse_client_version, "clientversion"},
  16429. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16430. { clif_parse_ranklist, "ranklist"},
  16431. // Market NPC
  16432. { clif_parse_NPCShopClosed, "npcshopclosed" },
  16433. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16434. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16435. // Roulette
  16436. { clif_parse_RouletteOpen, "rouletteopen" },
  16437. { clif_parse_RouletteInfo, "rouletteinfo" },
  16438. { clif_parse_RouletteClose, "rouletteclose" },
  16439. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16440. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16441. // Merge Item
  16442. { clif_parse_merge_item_req, "mergeitem_req"},
  16443. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16444. // HotkeyRowShift
  16445. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16446. // OneClick Item Identify
  16447. { clif_parse_Oneclick_Itemidentify, "oneclick_itemidentify" },
  16448. // NewChange Cart2
  16449. { clif_parse_SelectCart, "selectcart" },
  16450. {NULL,NULL}
  16451. };
  16452. struct {
  16453. char *name; //function name
  16454. int funcidx; //
  16455. } clif_ack_func[]={ //hash
  16456. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16457. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16458. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16459. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16460. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16461. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16462. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16463. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16464. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16465. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16466. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16467. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16468. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16469. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16470. };
  16471. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16472. int f;
  16473. memset(packet_db,0,sizeof(packet_db));
  16474. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16475. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16476. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16477. packet_len(i) = packet_len_table[i];
  16478. clif_config.packet_db_ver = MAX_PACKET_VER;
  16479. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16480. FILE *fp;
  16481. int ln = 0;
  16482. int entries = 0;
  16483. char *str[64], *p, *str2[64], *p2;
  16484. sprintf(line, "%s/%s", db_path, filename[f]);
  16485. if( (fp = fopen(line,"r")) == NULL ) {
  16486. if (f == 0) {
  16487. ShowFatalError("Can't read %s\n", line);
  16488. exit(EXIT_FAILURE);
  16489. }
  16490. return;
  16491. }
  16492. while( fgets(line, sizeof(line), fp) ) {
  16493. char w1[256],w2[256];
  16494. ln++;
  16495. if(line[0]=='/' && line[1]=='/')
  16496. continue;
  16497. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16498. if (strcmpi(w1,"packet_ver") == 0) {
  16499. int prev_ver = packet_ver;
  16500. skip_ver = false;
  16501. packet_ver = atoi(w2);
  16502. if ( packet_ver > MAX_PACKET_VER )
  16503. { //Check to avoid overflowing. [Skotlex]
  16504. if( (warned&1) == 0 )
  16505. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16506. warned &= 1;
  16507. skip_ver = true;
  16508. }
  16509. else if( packet_ver < 0 )
  16510. {
  16511. if( (warned&2) == 0 )
  16512. ShowWarning("Negative packet versions are not supported.\n");
  16513. warned &= 2;
  16514. skip_ver = true;
  16515. }
  16516. else if( packet_ver == SERVER )
  16517. {
  16518. if( (warned&4) == 0 )
  16519. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16520. warned &= 4;
  16521. skip_ver = true;
  16522. }
  16523. if( skip_ver )
  16524. {
  16525. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16526. packet_ver = prev_ver;
  16527. continue;
  16528. }
  16529. // copy from previous version into new version and continue
  16530. // - indicating all following packets should be read into the newer version
  16531. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16532. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16533. continue;
  16534. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16535. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16536. clif_config.packet_db_ver = MAX_PACKET_VER;
  16537. else // to manually set the packet DB version
  16538. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16539. continue;
  16540. }
  16541. #ifdef PACKET_OBFUSCATION
  16542. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16543. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16544. trim(w2);
  16545. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16546. if (!packet_keys[packet_ver])
  16547. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16548. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16549. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16550. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16551. last_key_defined = packet_ver;
  16552. if (battle_config.etc_log)
  16553. ShowInfo("Packet Ver:%d -> Keys: 0x%08X, 0x%08X, 0x%08X\n", packet_ver, packet_keys[packet_ver]->keys[0], packet_keys[packet_ver]->keys[1], packet_keys[packet_ver]->keys[2]);
  16554. }
  16555. continue;
  16556. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16557. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16558. trim(w2);
  16559. if (strcmpi(w2,"default") == 0)
  16560. continue;
  16561. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16562. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16563. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16564. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16565. key_defined = true;
  16566. if (battle_config.etc_log)
  16567. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16568. }
  16569. continue;
  16570. }
  16571. #endif
  16572. }
  16573. if( skip_ver )
  16574. continue; // Skipping current packet version
  16575. memset(str,0,sizeof(str));
  16576. for (j = 0, p = line; j < 4 && p; ++j) {
  16577. str[j] = p;
  16578. p = strchr(p,',');
  16579. if (p)
  16580. *p++=0;
  16581. }
  16582. if (str[0] == NULL)
  16583. continue;
  16584. cmd = strtol(str[0],(char **)NULL,0);
  16585. if(max_cmd < cmd)
  16586. max_cmd = cmd;
  16587. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16588. continue;
  16589. if(str[1]==NULL){
  16590. ShowError("packet_db: packet len error\n");
  16591. continue;
  16592. }
  16593. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16594. if(str[2]==NULL){
  16595. packet_db[packet_ver][cmd].func = NULL;
  16596. ln++;
  16597. continue;
  16598. }
  16599. // look up processing function by name
  16600. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16601. if( j < ARRAYLENGTH(clif_parse_func) )
  16602. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16603. else { //search if it's a mapped ack func
  16604. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16605. if( j < ARRAYLENGTH(clif_ack_func)) {
  16606. int fidx = clif_ack_func[j].funcidx;
  16607. packet_db_ack[packet_ver][fidx] = cmd;
  16608. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16609. }
  16610. }
  16611. // set the identifying cmd for the packet_db version
  16612. if (strcmp(str[2],"wanttoconnection")==0)
  16613. clif_config.connect_cmd[packet_ver] = cmd;
  16614. if(str[3]==NULL){
  16615. ShowError("packet_db: packet error\n");
  16616. exit(EXIT_FAILURE);
  16617. }
  16618. for(j = 0, p2 = str[3]; p2; j++){
  16619. short k;
  16620. str2[j] = p2;
  16621. p2 = strchr(p2,':');
  16622. if(p2)
  16623. *p2++=0;
  16624. k = atoi(str2[j]);
  16625. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16626. if( j >= MAX_PACKET_POS )
  16627. {
  16628. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16629. break;
  16630. }
  16631. packet_db[packet_ver][cmd].pos[j] = k;
  16632. }
  16633. entries++;
  16634. }
  16635. fclose(fp);
  16636. if(max_cmd > MAX_PACKET_DB) {
  16637. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16638. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16639. }
  16640. //Locate the nearest version that we still support. [Skotlex]
  16641. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16642. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16643. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16644. }
  16645. sprintf(line, "%s/%s", db_path,filename[f]);
  16646. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16647. }
  16648. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16649. #ifdef PACKET_OBFUSCATION
  16650. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16651. int use_key = last_key_defined;
  16652. if (last_key_defined == -1)
  16653. ShowError("Can't find packet obfuscation keys!\n");
  16654. else {
  16655. if (packet_keys[clif_config.packet_db_ver])
  16656. use_key = clif_config.packet_db_ver;
  16657. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16658. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16659. }
  16660. }
  16661. ShowStatus("Packet Obfuscation: "CL_GREEN"Enabled"CL_RESET". Keys: "CL_WHITE"0x%08X, 0x%08X, 0x%08X"CL_RESET"\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16662. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16663. if (packet_keys[i]) {
  16664. aFree(packet_keys[i]);
  16665. packet_keys[i] = NULL;
  16666. }
  16667. }
  16668. #endif
  16669. }
  16670. /*==========================================
  16671. *
  16672. *------------------------------------------*/
  16673. void do_init_clif(void) {
  16674. const char* colors[COLOR_MAX] = {
  16675. "0x00FF00",
  16676. "0xFF0000",
  16677. "0xFFFFFF",
  16678. "0xFFFF00",
  16679. };
  16680. int i;
  16681. /**
  16682. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16683. **/
  16684. for(i = 0; i < COLOR_MAX; i++) {
  16685. color_table[i] = strtoul(colors[i],NULL,0);
  16686. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16687. }
  16688. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16689. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16690. #ifdef PACKET_OBFUSCATION
  16691. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16692. #endif
  16693. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16694. packetdb_readdb(false);
  16695. set_defaultparse(clif_parse);
  16696. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16697. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16698. exit(EXIT_FAILURE);
  16699. }
  16700. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16701. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16702. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16703. }
  16704. void do_final_clif(void) {
  16705. ers_destroy(delay_clearunit_ers);
  16706. }