clif.c 565 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675
  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) = (uint16)((spawn ? 77 : 78)+strlen(name));
  858. #else
  859. WBUFW(buf,2) = (uint16)((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) = (uint16)(84+strlen(name));
  1047. #else
  1048. WBUFW(buf, 2) = (uint16)(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. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2974. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2975. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  2976. unsigned char buf[32];
  2977. #if PACKETVER < 4
  2978. const int cmd = 0xc3;
  2979. #else
  2980. const int cmd = 0x1d7;
  2981. #endif
  2982. WBUFW(buf,0) = cmd;
  2983. WBUFL(buf,2) = id;
  2984. WBUFB(buf,6) = type;
  2985. WBUFW(buf,7) = val;
  2986. #if PACKETVER >= 4
  2987. WBUFW(buf,9) = val2;
  2988. #endif
  2989. clif_send(buf,packet_len(cmd), bl, target);
  2990. }
  2991. /// Updates sprite/style properties of an object.
  2992. void clif_changelook(struct block_list *bl, int type, int val) {
  2993. struct map_session_data* sd;
  2994. struct status_change* sc;
  2995. struct view_data* vd;
  2996. enum send_target target = AREA;
  2997. int val2 = 0;
  2998. nullpo_retv(bl);
  2999. sd = BL_CAST(BL_PC, bl);
  3000. sc = status_get_sc(bl);
  3001. vd = status_get_viewdata(bl);
  3002. if( vd ) //temp hack to let Warp Portal change appearance
  3003. switch(type) {
  3004. case LOOK_WEAPON:
  3005. if (sd) {
  3006. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3007. val = vd->weapon;
  3008. }
  3009. else
  3010. vd->weapon = val;
  3011. break;
  3012. case LOOK_SHIELD:
  3013. if (sd) {
  3014. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3015. val = vd->shield;
  3016. }
  3017. else
  3018. vd->shield = val;
  3019. break;
  3020. case LOOK_BASE:
  3021. if (!sd)
  3022. break;
  3023. if ( val == INVISIBLE_CLASS )
  3024. return;
  3025. if (sd->sc.option&OPTION_COSTUME)
  3026. vd->weapon = vd->shield = 0;
  3027. if (!vd->cloth_color)
  3028. break;
  3029. if (sd) {
  3030. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3031. vd->cloth_color = 0;
  3032. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3033. vd->cloth_color = 0;
  3034. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3035. vd->cloth_color = 0;
  3036. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3037. vd->cloth_color = 0;
  3038. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3039. vd->cloth_color = 0;
  3040. if (vd->body_style && (
  3041. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3042. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3043. sd->sc.option&OPTION_OKTOBERFEST))
  3044. vd->body_style = 0;
  3045. }
  3046. break;
  3047. case LOOK_HAIR:
  3048. vd->hair_style = val;
  3049. break;
  3050. case LOOK_HEAD_BOTTOM:
  3051. vd->head_bottom = val;
  3052. break;
  3053. case LOOK_HEAD_TOP:
  3054. vd->head_top = val;
  3055. break;
  3056. case LOOK_HEAD_MID:
  3057. vd->head_mid = val;
  3058. break;
  3059. case LOOK_HAIR_COLOR:
  3060. vd->hair_color = val;
  3061. break;
  3062. case LOOK_CLOTHES_COLOR:
  3063. if (val && sd) {
  3064. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3065. val = 0;
  3066. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3067. val = 0;
  3068. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3069. val = 0;
  3070. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3071. val = 0;
  3072. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3073. val = 0;
  3074. }
  3075. vd->cloth_color = val;
  3076. break;
  3077. case LOOK_SHOES:
  3078. #if PACKETVER > 3
  3079. if (sd) {
  3080. int n;
  3081. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3082. if(sd->inventory_data[n]->view_id > 0)
  3083. val = sd->inventory_data[n]->view_id;
  3084. else
  3085. val = sd->status.inventory[n].nameid;
  3086. } else
  3087. val = 0;
  3088. }
  3089. #endif
  3090. //Shoes? No packet uses this....
  3091. break;
  3092. case LOOK_BODY:
  3093. // unknown purpose
  3094. break;
  3095. case LOOK_ROBE:
  3096. #if PACKETVER < 20110111
  3097. return;
  3098. #else
  3099. vd->robe = val;
  3100. #endif
  3101. break;
  3102. case LOOK_BODY2:
  3103. #if PACKETVER < 20150513
  3104. return;
  3105. #else
  3106. if (val && (
  3107. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3108. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3109. sd->sc.option&OPTION_OKTOBERFEST))
  3110. val = 0;
  3111. vd->body_style = val;
  3112. #endif
  3113. break;
  3114. }
  3115. // prevent leaking the presence of GM-hidden objects
  3116. if( sc && sc->option&OPTION_INVISIBLE )
  3117. target = SELF;
  3118. #if PACKETVER < 4
  3119. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3120. #else
  3121. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3122. nullpo_retv(vd);
  3123. type = LOOK_WEAPON;
  3124. val = vd->weapon;
  3125. val2 = vd->shield;
  3126. }
  3127. if( disguised(bl) ) {
  3128. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3129. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3130. } else
  3131. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3132. #endif
  3133. }
  3134. //Sends a change-base-look packet required for traps as they are triggered.
  3135. void clif_changetraplook(struct block_list *bl,int val) {
  3136. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3137. }
  3138. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3139. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3140. clif_sprite_change(bl, id, type, val, 0, target);
  3141. }
  3142. /// Character status (ZC_STATUS).
  3143. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3144. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3145. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3146. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3147. void clif_initialstatus(struct map_session_data *sd) {
  3148. int fd, mdef2;
  3149. unsigned char *buf;
  3150. nullpo_retv(sd);
  3151. fd=sd->fd;
  3152. WFIFOHEAD(fd, packet_len(0xbd));
  3153. buf = WFIFOP(fd,0);
  3154. WBUFW(buf,0) = 0xbd;
  3155. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3156. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3157. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3158. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3159. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3160. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3161. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3162. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3163. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3164. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3165. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3166. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3167. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3168. WBUFW(buf,16) = pc_leftside_atk(sd);
  3169. WBUFW(buf,18) = pc_rightside_atk(sd);
  3170. WBUFW(buf,20) = pc_rightside_matk(sd);
  3171. WBUFW(buf,22) = pc_leftside_matk(sd);
  3172. WBUFW(buf,24) = pc_leftside_def(sd);
  3173. WBUFW(buf,26) = pc_rightside_def(sd);
  3174. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3175. mdef2 = pc_rightside_mdef(sd);
  3176. WBUFW(buf,30) =
  3177. #ifndef RENEWAL
  3178. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3179. #endif
  3180. mdef2;
  3181. WBUFW(buf,32) = sd->battle_status.hit;
  3182. WBUFW(buf,34) = sd->battle_status.flee;
  3183. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3184. WBUFW(buf,38) = sd->battle_status.cri/10;
  3185. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3186. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3187. WFIFOSET(fd, packet_len(0xbd));
  3188. clif_updatestatus(sd, SP_STR);
  3189. clif_updatestatus(sd, SP_AGI);
  3190. clif_updatestatus(sd, SP_VIT);
  3191. clif_updatestatus(sd, SP_INT);
  3192. clif_updatestatus(sd, SP_DEX);
  3193. clif_updatestatus(sd, SP_LUK);
  3194. clif_updatestatus(sd, SP_ATTACKRANGE);
  3195. clif_updatestatus(sd, SP_ASPD);
  3196. }
  3197. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3198. /// 013c <index>.W
  3199. void clif_arrowequip(struct map_session_data *sd,int val) {
  3200. int fd;
  3201. nullpo_retv(sd);
  3202. #if PACKETVER >= 20121128
  3203. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3204. #endif
  3205. fd=sd->fd;
  3206. WFIFOHEAD(fd, packet_len(0x013c));
  3207. WFIFOW(fd,0) = 0x013c;
  3208. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3209. WFIFOSET(fd, packet_len(0x013c));
  3210. }
  3211. /// Ammunition action message (ZC_ACTION_FAILURE).
  3212. /// 013b <type>.W
  3213. /// type:
  3214. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3215. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3216. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3217. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3218. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3219. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3220. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3221. int fd;
  3222. nullpo_retv(sd);
  3223. fd=sd->fd;
  3224. WFIFOHEAD(fd, packet_len(0x013b));
  3225. WFIFOW(fd,0) = 0x013b;
  3226. WFIFOW(fd,2) = type;
  3227. WFIFOSET(fd, packet_len(0x013b));
  3228. }
  3229. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3230. /// 01ad <packet len>.W { <name id>.W }*
  3231. void clif_arrow_create_list(struct map_session_data *sd)
  3232. {
  3233. int i, c;
  3234. int fd;
  3235. nullpo_retv(sd);
  3236. fd = sd->fd;
  3237. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3238. WFIFOW(fd,0) = 0x1ad;
  3239. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3240. short j, nameid = skill_arrow_db[i].nameid;
  3241. if (nameid > 0 && itemdb_exists(nameid) &&
  3242. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3243. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3244. {
  3245. if ((j = itemdb_viewid(nameid)) > 0)
  3246. WFIFOW(fd,c*2+4) = j;
  3247. else
  3248. WFIFOW(fd,c*2+4) = nameid;
  3249. c++;
  3250. }
  3251. }
  3252. WFIFOW(fd,2) = c*2+4;
  3253. WFIFOSET(fd, WFIFOW(fd,2));
  3254. if (c > 0) {
  3255. sd->menuskill_id = AC_MAKINGARROW;
  3256. sd->menuskill_val = c;
  3257. }
  3258. }
  3259. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3260. /// 00bc <status id>.W <result>.B <value>.B
  3261. /// status id:
  3262. /// SP_STR ~ SP_LUK
  3263. /// result:
  3264. /// 0 = failure
  3265. /// 1 = success
  3266. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3267. int fd;
  3268. nullpo_retv(sd);
  3269. fd=sd->fd;
  3270. WFIFOHEAD(fd, packet_len(0xbc));
  3271. WFIFOW(fd,0) = 0xbc;
  3272. WFIFOW(fd,2) = type;
  3273. WFIFOB(fd,4) = ok;
  3274. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3275. WFIFOSET(fd, packet_len(0xbc));
  3276. }
  3277. /// Notifies the client about the result of a request to equip an item.
  3278. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3279. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3280. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3281. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3282. /// @ok: //inversed forv2 v5
  3283. /// 0 = failure
  3284. /// 1 = success
  3285. /// 2 = failure due to low level
  3286. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3287. {
  3288. int fd = 0, cmd = 0, look = 0;
  3289. struct s_packet_db *info = NULL;
  3290. nullpo_retv(sd);
  3291. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3292. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3293. return;
  3294. fd = sd->fd;
  3295. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3296. look = sd->inventory_data[n]->look;
  3297. WFIFOHEAD(fd, info->len);
  3298. WFIFOW(fd, 0) = cmd;
  3299. WFIFOW(fd, info->pos[0]) = n+2;
  3300. switch (cmd) {
  3301. case 0xaa:
  3302. WFIFOW(fd, info->pos[1]) = pos;
  3303. if (sd->packet_ver < date2version(20100629))
  3304. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3305. else {
  3306. WFIFOL(fd, info->pos[2]) = look;
  3307. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3308. }
  3309. break;
  3310. case 0x8d0:
  3311. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3312. flag = 1;
  3313. case 0x999:
  3314. if (cmd == 0x999)
  3315. WFIFOL(fd, info->pos[1]) = pos;
  3316. else
  3317. WFIFOW(fd, info->pos[1]) = pos;
  3318. WFIFOL(fd, info->pos[2]) = look;
  3319. WFIFOW(fd, info->pos[3]) = flag;
  3320. break;
  3321. }
  3322. WFIFOSET(fd, info->len);
  3323. }
  3324. /// Notifies the client about the result of a request to take off an item.
  3325. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3326. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3327. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3328. /// @ok : //inversed for v2 v5
  3329. /// 0 = failure
  3330. /// 1 = success
  3331. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3332. {
  3333. int fd, header, offs = 0;
  3334. #if PACKETVER >= 20130000
  3335. header = 0x99a;
  3336. ok = ok ? 0 : 1;
  3337. #elif PACKETVER >= 20110824
  3338. header = 0x8d1;
  3339. ok = ok ? 0 : 1;
  3340. #else
  3341. header = 0xac;
  3342. #endif
  3343. nullpo_retv(sd);
  3344. fd=sd->fd;
  3345. WFIFOHEAD(fd, packet_len(header));
  3346. WFIFOW(fd,offs+0) = header;
  3347. WFIFOW(fd,offs+2) = n+2;
  3348. #if PACKETVER >= 20130000
  3349. WFIFOL(fd,offs+4) = pos;
  3350. offs += 2;
  3351. #else
  3352. WFIFOW(fd,offs+4) = pos;
  3353. #endif
  3354. WFIFOB(fd,offs+6) = ok;
  3355. WFIFOSET(fd, packet_len(header));
  3356. }
  3357. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3358. /// 019b <id>.L <effect id>.L
  3359. /// effect id:
  3360. /// 0 = base level up
  3361. /// 1 = job level up
  3362. /// 2 = refine failure
  3363. /// 3 = refine success
  3364. /// 4 = game over
  3365. /// 5 = pharmacy success
  3366. /// 6 = pharmacy failure
  3367. /// 7 = base level up (super novice)
  3368. /// 8 = job level up (super novice)
  3369. /// 9 = base level up (taekwon)
  3370. void clif_misceffect(struct block_list* bl,int type)
  3371. {
  3372. unsigned char buf[32];
  3373. nullpo_retv(bl);
  3374. WBUFW(buf,0) = 0x19b;
  3375. WBUFL(buf,2) = bl->id;
  3376. WBUFL(buf,6) = type;
  3377. clif_send(buf,packet_len(0x19b),bl,AREA);
  3378. }
  3379. /// Notifies clients in the area of a state change.
  3380. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3381. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3382. void clif_changeoption(struct block_list* bl)
  3383. {
  3384. unsigned char buf[32];
  3385. struct status_change *sc;
  3386. struct map_session_data* sd;
  3387. nullpo_retv(bl);
  3388. sc = status_get_sc(bl);
  3389. if (!sc) return; //How can an option change if there's no sc?
  3390. sd = BL_CAST(BL_PC, bl);
  3391. #if PACKETVER >= 7
  3392. WBUFW(buf,0) = 0x229;
  3393. WBUFL(buf,2) = bl->id;
  3394. WBUFW(buf,6) = sc->opt1;
  3395. WBUFW(buf,8) = sc->opt2;
  3396. WBUFL(buf,10) = sc->option;
  3397. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3398. if(disguised(bl)) {
  3399. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3400. WBUFL(buf,2) = -bl->id;
  3401. clif_send(buf,packet_len(0x229),bl,SELF);
  3402. WBUFL(buf,2) = bl->id;
  3403. WBUFL(buf,10) = OPTION_INVISIBLE;
  3404. clif_send(buf,packet_len(0x229),bl,SELF);
  3405. } else
  3406. clif_send(buf,packet_len(0x229),bl,AREA);
  3407. #else
  3408. WBUFW(buf,0) = 0x119;
  3409. WBUFL(buf,2) = bl->id;
  3410. WBUFW(buf,6) = sc->opt1;
  3411. WBUFW(buf,8) = sc->opt2;
  3412. WBUFW(buf,10) = sc->option;
  3413. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3414. if(disguised(bl)) {
  3415. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3416. WBUFL(buf,2) = -bl->id;
  3417. clif_send(buf,packet_len(0x119),bl,SELF);
  3418. WBUFL(buf,2) = bl->id;
  3419. WBUFW(buf,10) = OPTION_INVISIBLE;
  3420. clif_send(buf,packet_len(0x119),bl,SELF);
  3421. } else
  3422. clif_send(buf,packet_len(0x119),bl,AREA);
  3423. #endif
  3424. }
  3425. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3426. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3427. void clif_changeoption2(struct block_list* bl)
  3428. {
  3429. unsigned char buf[20];
  3430. struct status_change *sc;
  3431. sc = status_get_sc(bl);
  3432. if (!sc) return; //How can an option change if there's no sc?
  3433. WBUFW(buf,0) = 0x28a;
  3434. WBUFL(buf,2) = bl->id;
  3435. WBUFL(buf,6) = sc->option;
  3436. WBUFL(buf,10) = clif_setlevel(bl);
  3437. WBUFL(buf,14) = sc->opt3;
  3438. if(disguised(bl)) {
  3439. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3440. WBUFL(buf,2) = -bl->id;
  3441. clif_send(buf,packet_len(0x28a),bl,SELF);
  3442. WBUFL(buf,2) = bl->id;
  3443. WBUFL(buf,6) = OPTION_INVISIBLE;
  3444. clif_send(buf,packet_len(0x28a),bl,SELF);
  3445. } else
  3446. clif_send(buf,packet_len(0x28a),bl,AREA);
  3447. }
  3448. /// Notifies the client about the result of an item use request.
  3449. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3450. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3451. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3452. {
  3453. nullpo_retv(sd);
  3454. if(!ok) {
  3455. int fd=sd->fd;
  3456. WFIFOHEAD(fd,packet_len(0xa8));
  3457. WFIFOW(fd,0)=0xa8;
  3458. WFIFOW(fd,2)=index+2;
  3459. WFIFOW(fd,4)=amount;
  3460. WFIFOB(fd,6)=ok;
  3461. WFIFOSET(fd,packet_len(0xa8));
  3462. }
  3463. else {
  3464. #if PACKETVER < 3
  3465. int fd=sd->fd;
  3466. WFIFOHEAD(fd,packet_len(0xa8));
  3467. WFIFOW(fd,0)=0xa8;
  3468. WFIFOW(fd,2)=index+2;
  3469. WFIFOW(fd,4)=amount;
  3470. WFIFOB(fd,6)=ok;
  3471. WFIFOSET(fd,packet_len(0xa8));
  3472. #else
  3473. unsigned char buf[32];
  3474. WBUFW(buf,0)=0x1c8;
  3475. WBUFW(buf,2)=index+2;
  3476. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3477. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3478. else
  3479. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3480. WBUFL(buf,6)=sd->bl.id;
  3481. WBUFW(buf,10)=amount;
  3482. WBUFB(buf,12)=ok;
  3483. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3484. #endif
  3485. }
  3486. }
  3487. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3488. /// 00d6 <flag>.B
  3489. /// flag:
  3490. /// 0 = Room has been successfully created (opens chat room)
  3491. /// 1 = Room limit exceeded
  3492. /// 2 = Same room already exists
  3493. void clif_createchat(struct map_session_data* sd, int flag)
  3494. {
  3495. int fd;
  3496. nullpo_retv(sd);
  3497. fd = sd->fd;
  3498. WFIFOHEAD(fd,packet_len(0xd6));
  3499. WFIFOW(fd,0) = 0xd6;
  3500. WFIFOB(fd,2) = flag;
  3501. WFIFOSET(fd,packet_len(0xd6));
  3502. }
  3503. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3504. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3505. /// type:
  3506. /// 0 = private (password protected)
  3507. /// 1 = public
  3508. /// 2 = arena (npc waiting room)
  3509. /// 3 = PK zone (non-clickable)
  3510. void clif_dispchat(struct chat_data* cd, int fd)
  3511. {
  3512. unsigned char buf[128];
  3513. uint8 type;
  3514. if( cd == NULL || cd->owner == NULL )
  3515. return;
  3516. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3517. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3518. : 1;
  3519. WBUFW(buf, 0) = 0xd7;
  3520. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3521. WBUFL(buf, 4) = cd->owner->id;
  3522. WBUFL(buf, 8) = cd->bl.id;
  3523. WBUFW(buf,12) = cd->limit;
  3524. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3525. WBUFB(buf,16) = type;
  3526. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3527. if( fd ) {
  3528. WFIFOHEAD(fd,WBUFW(buf,2));
  3529. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3530. WFIFOSET(fd,WBUFW(buf,2));
  3531. } else {
  3532. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3533. }
  3534. }
  3535. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3536. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3537. /// type:
  3538. /// 0 = private (password protected)
  3539. /// 1 = public
  3540. /// 2 = arena (npc waiting room)
  3541. /// 3 = PK zone (non-clickable)
  3542. void clif_changechatstatus(struct chat_data* cd)
  3543. {
  3544. unsigned char buf[128];
  3545. uint8 type;
  3546. if( cd == NULL || cd->usersd[0] == NULL )
  3547. return;
  3548. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3549. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3550. : 1;
  3551. WBUFW(buf, 0) = 0xdf;
  3552. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3553. WBUFL(buf, 4) = cd->owner->id;
  3554. WBUFL(buf, 8) = cd->bl.id;
  3555. WBUFW(buf,12) = cd->limit;
  3556. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3557. WBUFB(buf,16) = type;
  3558. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3559. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3560. }
  3561. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3562. /// 00d8 <chat id>.L
  3563. void clif_clearchat(struct chat_data *cd,int fd)
  3564. {
  3565. unsigned char buf[32];
  3566. nullpo_retv(cd);
  3567. WBUFW(buf,0) = 0xd8;
  3568. WBUFL(buf,2) = cd->bl.id;
  3569. if( fd ) {
  3570. WFIFOHEAD(fd,packet_len(0xd8));
  3571. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3572. WFIFOSET(fd,packet_len(0xd8));
  3573. } else {
  3574. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3575. }
  3576. }
  3577. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3578. /// 00da <result>.B
  3579. /// result:
  3580. /// 0 = room full
  3581. /// 1 = wrong password
  3582. /// 2 = kicked
  3583. /// 3 = success (no message)
  3584. /// 4 = no enough zeny
  3585. /// 5 = too low level
  3586. /// 6 = too high level
  3587. /// 7 = unsuitable job class
  3588. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3589. {
  3590. int fd;
  3591. nullpo_retv(sd);
  3592. fd = sd->fd;
  3593. WFIFOHEAD(fd,packet_len(0xda));
  3594. WFIFOW(fd,0) = 0xda;
  3595. WFIFOB(fd,2) = flag;
  3596. WFIFOSET(fd,packet_len(0xda));
  3597. }
  3598. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3599. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3600. /// role:
  3601. /// 0 = owner (menu)
  3602. /// 1 = normal
  3603. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3604. {
  3605. int fd;
  3606. int i,t;
  3607. nullpo_retv(sd);
  3608. nullpo_retv(cd);
  3609. fd = sd->fd;
  3610. if (!session_isActive(fd))
  3611. return;
  3612. t = (int)(cd->owner->type == BL_NPC);
  3613. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3614. WFIFOW(fd, 0) = 0xdb;
  3615. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3616. WFIFOL(fd, 4) = cd->bl.id;
  3617. if(cd->owner->type == BL_NPC){
  3618. WFIFOL(fd, 30) = 1;
  3619. WFIFOL(fd, 8) = 0;
  3620. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3621. for (i = 0; i < cd->users; i++) {
  3622. WFIFOL(fd, 8+(i+1)*28) = 1;
  3623. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3624. }
  3625. } else
  3626. for (i = 0; i < cd->users; i++) {
  3627. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3628. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3629. }
  3630. WFIFOSET(fd, WFIFOW(fd, 2));
  3631. }
  3632. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3633. /// 00dc <users>.W <name>.24B
  3634. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3635. {
  3636. unsigned char buf[29];
  3637. nullpo_retv(sd);
  3638. nullpo_retv(cd);
  3639. WBUFW(buf, 0) = 0xdc;
  3640. WBUFW(buf, 2) = cd->users;
  3641. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3642. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3643. }
  3644. /// Announce the new owner (ZC_ROLE_CHANGE).
  3645. /// 00e1 <role>.L <nick>.24B
  3646. /// role:
  3647. /// 0 = owner (menu)
  3648. /// 1 = normal
  3649. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3650. {
  3651. unsigned char buf[64];
  3652. nullpo_retv(sd);
  3653. nullpo_retv(cd);
  3654. WBUFW(buf, 0) = 0xe1;
  3655. WBUFL(buf, 2) = 1;
  3656. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3657. WBUFW(buf,30) = 0xe1;
  3658. WBUFL(buf,32) = 0;
  3659. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3660. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3661. }
  3662. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3663. /// 00dd <users>.W <nick>.24B <flag>.B
  3664. /// flag:
  3665. /// 0 = left
  3666. /// 1 = kicked
  3667. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3668. {
  3669. unsigned char buf[32];
  3670. nullpo_retv(sd);
  3671. nullpo_retv(cd);
  3672. WBUFW(buf, 0) = 0xdd;
  3673. WBUFW(buf, 2) = cd->users-1;
  3674. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3675. WBUFB(buf,28) = flag;
  3676. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3677. }
  3678. /// Opens a trade request window from char 'name'.
  3679. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3680. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3681. void clif_traderequest(struct map_session_data* sd, const char* name)
  3682. {
  3683. int fd = sd->fd;
  3684. #if PACKETVER < 6
  3685. WFIFOHEAD(fd,packet_len(0xe5));
  3686. WFIFOW(fd,0) = 0xe5;
  3687. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3688. WFIFOSET(fd,packet_len(0xe5));
  3689. #else
  3690. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3691. if( !tsd ) return;
  3692. WFIFOHEAD(fd,packet_len(0x1f4));
  3693. WFIFOW(fd,0) = 0x1f4;
  3694. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3695. WFIFOL(fd,26) = tsd->status.char_id;
  3696. WFIFOW(fd,30) = tsd->status.base_level;
  3697. WFIFOSET(fd,packet_len(0x1f4));
  3698. #endif
  3699. }
  3700. /// Reply to a trade-request.
  3701. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3702. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3703. /// result:
  3704. /// 0 = Char is too far
  3705. /// 1 = Character does not exist
  3706. /// 2 = Trade failed
  3707. /// 3 = Accept
  3708. /// 4 = Cancel
  3709. /// 5 = Busy
  3710. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3711. {
  3712. int fd = sd->fd;
  3713. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3714. if( PACKETVER < 6 || !tsd ) {
  3715. WFIFOHEAD(fd,packet_len(0xe7));
  3716. WFIFOW(fd,0) = 0xe7;
  3717. WFIFOB(fd,2) = type;
  3718. WFIFOSET(fd,packet_len(0xe7));
  3719. } else {
  3720. WFIFOHEAD(fd,packet_len(0x1f5));
  3721. WFIFOW(fd,0) = 0x1f5;
  3722. WFIFOB(fd,2) = type;
  3723. WFIFOL(fd,3) = tsd->status.char_id;
  3724. WFIFOW(fd,7) = tsd->status.base_level;
  3725. WFIFOSET(fd,packet_len(0x1f5));
  3726. }
  3727. }
  3728. /// Notifies the client about an item from other player in current trade.
  3729. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3730. /// 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)
  3731. /// 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)
  3732. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3733. {
  3734. int fd;
  3735. unsigned char *buf;
  3736. #if PACKETVER < 20100223
  3737. const int cmd = 0xe9;
  3738. #elif PACKETVER < 20150226
  3739. const int cmd = 0x80f;
  3740. #else
  3741. const int cmd = 0xa09;
  3742. #endif
  3743. nullpo_retv(sd);
  3744. nullpo_retv(tsd);
  3745. fd = tsd->fd;
  3746. buf = WFIFOP(fd,0);
  3747. WFIFOHEAD(fd,packet_len(cmd));
  3748. WBUFW(buf,0) = cmd;
  3749. if( index == 0 )
  3750. {
  3751. #if PACKETVER < 20100223
  3752. WBUFL(buf,2) = amount; //amount
  3753. WBUFW(buf,6) = 0; // type id
  3754. #else
  3755. WBUFW(buf,2) = 0; // type id
  3756. WBUFB(buf,4) = 0; // item type
  3757. WBUFL(buf,5) = amount; // amount
  3758. buf = WBUFP(buf,1); //Advance 1B
  3759. #endif
  3760. WBUFB(buf,8) = 0; //identify flag
  3761. WBUFB(buf,9) = 0; // attribute
  3762. WBUFB(buf,10)= 0; //refine
  3763. WBUFW(buf,11)= 0; //card (4w)
  3764. WBUFW(buf,13)= 0; //card (4w)
  3765. WBUFW(buf,15)= 0; //card (4w)
  3766. WBUFW(buf,17)= 0; //card (4w)
  3767. #if PACKETVER >= 20150226
  3768. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3769. #endif
  3770. }
  3771. else
  3772. {
  3773. index -= 2; //index fix
  3774. #if PACKETVER < 20100223
  3775. WBUFL(buf,2) = amount; //amount
  3776. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3777. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3778. else
  3779. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3780. #else
  3781. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3782. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3783. else
  3784. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3785. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3786. WBUFL(buf,5) = amount; // amount
  3787. buf = WBUFP(buf,1); //Advance 1B
  3788. #endif
  3789. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3790. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3791. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3792. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3793. #if PACKETVER >= 20150226
  3794. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3795. #endif
  3796. }
  3797. WFIFOSET(fd,packet_len(cmd));
  3798. }
  3799. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3800. /// 00ea <index>.W <result>.B
  3801. /// result:
  3802. /// 0 = success
  3803. /// 1 = overweight
  3804. /// 2 = trade canceled
  3805. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3806. {
  3807. int fd;
  3808. nullpo_retv(sd);
  3809. fd = sd->fd;
  3810. WFIFOHEAD(fd,packet_len(0xea));
  3811. WFIFOW(fd,0) = 0xea;
  3812. WFIFOW(fd,2) = index;
  3813. WFIFOB(fd,4) = fail;
  3814. WFIFOSET(fd,packet_len(0xea));
  3815. }
  3816. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3817. /// 00ec <who>.B
  3818. /// who:
  3819. /// 0 = self
  3820. /// 1 = other player
  3821. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3822. {
  3823. int fd;
  3824. nullpo_retv(sd);
  3825. fd = sd->fd;
  3826. WFIFOHEAD(fd,packet_len(0xec));
  3827. WFIFOW(fd,0) = 0xec;
  3828. WFIFOB(fd,2) = fail;
  3829. WFIFOSET(fd,packet_len(0xec));
  3830. }
  3831. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3832. /// 00ee
  3833. void clif_tradecancelled(struct map_session_data* sd)
  3834. {
  3835. int fd;
  3836. nullpo_retv(sd);
  3837. fd = sd->fd;
  3838. WFIFOHEAD(fd,packet_len(0xee));
  3839. WFIFOW(fd,0) = 0xee;
  3840. WFIFOSET(fd,packet_len(0xee));
  3841. }
  3842. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3843. /// 00f0 <result>.B
  3844. /// result:
  3845. /// 0 = success
  3846. /// 1 = failure
  3847. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3848. {
  3849. int fd;
  3850. nullpo_retv(sd);
  3851. fd = sd->fd;
  3852. WFIFOHEAD(fd,packet_len(0xf0));
  3853. WFIFOW(fd,0) = 0xf0;
  3854. WFIFOB(fd,2) = fail;
  3855. WFIFOSET(fd,packet_len(0xf0));
  3856. }
  3857. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3858. /// 00f1
  3859. /// NOTE: Unknown purpose. Items are not removed until the window is
  3860. /// refreshed (ex. by putting another item in there).
  3861. void clif_tradeundo(struct map_session_data* sd)
  3862. {
  3863. int fd = sd->fd;
  3864. WFIFOHEAD(fd,packet_len(0xf1));
  3865. WFIFOW(fd,0) = 0xf1;
  3866. WFIFOSET(fd,packet_len(0xf1));
  3867. }
  3868. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3869. /// 00f2 <current count>.W <max count>.W
  3870. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3871. {
  3872. int fd;
  3873. nullpo_retv(sd);
  3874. fd=sd->fd;
  3875. WFIFOHEAD(fd,packet_len(0xf2));
  3876. WFIFOW(fd,0) = 0xf2;
  3877. WFIFOW(fd,2) = amount;
  3878. WFIFOW(fd,4) = max_amount;
  3879. WFIFOSET(fd,packet_len(0xf2));
  3880. }
  3881. /// Notifies the client of an item being added to the storage.
  3882. /// 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)
  3883. /// 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)
  3884. /// 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)
  3885. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3886. {
  3887. #if PACKETVER < 5
  3888. const int cmd = 0xf4;
  3889. #elif PACKETVER < 20150226
  3890. const int cmd = 0x1c4;
  3891. #else
  3892. const int cmd = 0xa0a;
  3893. #endif
  3894. int view,fd;
  3895. int offset = 0;
  3896. nullpo_retv(sd);
  3897. nullpo_retv(i);
  3898. fd=sd->fd;
  3899. view = itemdb_viewid(i->nameid);
  3900. WFIFOHEAD(fd,packet_len(cmd));
  3901. WFIFOW(fd, 0) = cmd; // Storage item added
  3902. WFIFOW(fd, 2) = index+1; // index
  3903. WFIFOL(fd, 4) = amount; // amount
  3904. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3905. #if PACKETVER >= 5
  3906. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3907. offset += 1;
  3908. #endif
  3909. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3910. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3911. WFIFOB(fd,12+offset) = i->refine; //refine
  3912. clif_addcards(WFIFOP(fd,13+offset), i);
  3913. #if PACKETVER >= 20150226
  3914. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3915. #endif
  3916. WFIFOSET(fd,packet_len(cmd));
  3917. }
  3918. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3919. /// 00f6 <index>.W <amount>.L
  3920. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3921. {
  3922. int fd;
  3923. nullpo_retv(sd);
  3924. fd=sd->fd;
  3925. WFIFOHEAD(fd,packet_len(0xf6));
  3926. WFIFOW(fd,0)=0xf6; // Storage item removed
  3927. WFIFOW(fd,2)=index+1;
  3928. WFIFOL(fd,4)=amount;
  3929. WFIFOSET(fd,packet_len(0xf6));
  3930. }
  3931. /// Closes storage (ZC_CLOSE_STORE).
  3932. /// 00f8
  3933. void clif_storageclose(struct map_session_data* sd)
  3934. {
  3935. int fd;
  3936. nullpo_retv(sd);
  3937. fd=sd->fd;
  3938. WFIFOHEAD(fd,packet_len(0xf8));
  3939. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3940. WFIFOSET(fd,packet_len(0xf8));
  3941. }
  3942. /*==========================================
  3943. * Server tells 'sd' player client the abouts of 'dstsd' player
  3944. *------------------------------------------*/
  3945. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3946. {
  3947. struct block_list *d_bl;
  3948. int i;
  3949. if( dstsd->chatID ) {
  3950. struct chat_data *cd = NULL;
  3951. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3952. clif_dispchat(cd,sd->fd);
  3953. } else if( dstsd->state.vending )
  3954. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3955. else if( dstsd->state.buyingstore )
  3956. clif_buyingstore_entry_single(sd, dstsd);
  3957. if(dstsd->spiritball > 0)
  3958. clif_spiritball_single(sd->fd, dstsd);
  3959. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3960. clif_spiritcharm_single(sd->fd, dstsd);
  3961. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3962. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3963. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3964. else
  3965. 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);
  3966. }
  3967. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3968. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3969. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3970. )
  3971. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3972. // display link (sd - dstsd) to sd
  3973. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3974. if( i < MAX_DEVOTION )
  3975. clif_devotion(&sd->bl, sd);
  3976. // display links (dstsd - devotees) to sd
  3977. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3978. if( i < MAX_DEVOTION )
  3979. clif_devotion(&dstsd->bl, sd);
  3980. // display link (dstsd - crusader) to sd
  3981. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3982. clif_devotion(d_bl, sd);
  3983. }
  3984. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3985. {
  3986. uint8 buf[128];
  3987. struct unit_data *ud;
  3988. struct view_data *vd;
  3989. int len;
  3990. vd = status_get_viewdata(bl);
  3991. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3992. return;
  3993. /**
  3994. * Hide NPC from maya purple card.
  3995. **/
  3996. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3997. return;
  3998. ud = unit_bl2ud(bl);
  3999. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4000. clif_send(buf,len,&sd->bl,SELF);
  4001. if (vd->cloth_color)
  4002. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4003. if (vd->body_style)
  4004. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4005. switch (bl->type)
  4006. {
  4007. case BL_PC:
  4008. {
  4009. TBL_PC* tsd = (TBL_PC*)bl;
  4010. clif_getareachar_pc(sd, tsd);
  4011. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4012. clif_specialeffect_single(bl,423,sd->fd);
  4013. else if(tsd->state.size==SZ_MEDIUM)
  4014. clif_specialeffect_single(bl,421,sd->fd);
  4015. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4016. clif_sendbgemblem_single(sd->fd,tsd);
  4017. if ( tsd->status.robe )
  4018. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4019. if (!&tsd->sc)
  4020. break;
  4021. if( tsd->sc.data[SC_CAMOUFLAGE] )
  4022. clif_status_load(bl,SI_CAMOUFLAGE,1);
  4023. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  4024. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  4025. if( tsd->sc.data[SC_MOONSTAR] )
  4026. clif_status_load(bl,SI_MOONSTAR,1);
  4027. if( tsd->sc.data[SC_SUPER_STAR] )
  4028. clif_status_load(bl,SI_SUPER_STAR,1);
  4029. if( tsd->sc.data[SC_DECORATION_OF_MUSIC] )
  4030. clif_status_load(bl,SI_DECORATION_OF_MUSIC,1);
  4031. if( tsd->sc.data[SC_STRANGELIGHTS] )
  4032. clif_status_load(bl,SI_STRANGELIGHTS,1);
  4033. if( tsd->sc.data[SC_ALL_RIDING] )
  4034. clif_status_load(bl,SI_ALL_RIDING,1);
  4035. }
  4036. break;
  4037. case BL_MER: // Devotion Effects
  4038. if( ((TBL_MER*)bl)->devotion_flag )
  4039. clif_devotion(bl, sd);
  4040. break;
  4041. case BL_NPC:
  4042. {
  4043. TBL_NPC* nd = (TBL_NPC*)bl;
  4044. if( nd->chat_id )
  4045. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4046. if( nd->size == SZ_BIG )
  4047. clif_specialeffect_single(bl,423,sd->fd);
  4048. else if( nd->size == SZ_MEDIUM )
  4049. clif_specialeffect_single(bl,421,sd->fd);
  4050. }
  4051. break;
  4052. case BL_MOB:
  4053. {
  4054. TBL_MOB* md = (TBL_MOB*)bl;
  4055. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4056. clif_specialeffect_single(bl,423,sd->fd);
  4057. else if(md->special_state.size==SZ_MEDIUM)
  4058. clif_specialeffect_single(bl,421,sd->fd);
  4059. #if PACKETVER >= 20120404
  4060. if( battle_config.monster_hp_bars_info){
  4061. int i;
  4062. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4063. if( md->dmglog[i].id == sd->status.char_id )
  4064. clif_monster_hp_bar(md, sd->fd);
  4065. }
  4066. #endif
  4067. }
  4068. break;
  4069. case BL_PET:
  4070. if (vd->head_bottom)
  4071. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4072. break;
  4073. }
  4074. }
  4075. //Modifies the type of damage according to status changes [Skotlex]
  4076. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4077. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  4078. {
  4079. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  4080. }
  4081. /*==========================================
  4082. * Estimates walk delay based on the damage criteria. [Skotlex]
  4083. *------------------------------------------*/
  4084. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4085. {
  4086. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4087. return 0;
  4088. if (bl->type == BL_PC) {
  4089. if (battle_config.pc_walk_delay_rate != 100)
  4090. delay = delay*battle_config.pc_walk_delay_rate/100;
  4091. } else
  4092. if (battle_config.walk_delay_rate != 100)
  4093. delay = delay*battle_config.walk_delay_rate/100;
  4094. if (div_ > 1) //Multi-hit skills mean higher delays.
  4095. delay += battle_config.multihit_delay*(div_-1);
  4096. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4097. }
  4098. /// Sends a 'damage' packet (src performs action on dst)
  4099. /// 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)
  4100. /// 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)
  4101. /// 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)
  4102. /// type:
  4103. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4104. /// 1 = pick up item
  4105. /// 2 = sit down
  4106. /// 3 = stand up
  4107. /// 4 = damage (endure)
  4108. /// 5 = (splash?)
  4109. /// 6 = (skill?)
  4110. /// 7 = (repeat damage?)
  4111. /// 8 = multi-hit damage
  4112. /// 9 = multi-hit damage (endure)
  4113. /// 10 = critical hit
  4114. /// 11 = lucky dodge
  4115. /// 12 = (touch skill?)
  4116. 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)
  4117. {
  4118. unsigned char buf[34];
  4119. struct status_change *sc;
  4120. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4121. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4122. #if PACKETVER < 20071113
  4123. const int cmd = 0x8a;
  4124. int offset = 0;
  4125. #elif PACKETVER < 20131223
  4126. const int cmd = 0x2e1;
  4127. int offset = 2;
  4128. #else
  4129. const int cmd = 0x8c8;
  4130. int offset = 3;
  4131. #endif
  4132. nullpo_ret(src);
  4133. nullpo_ret(dst);
  4134. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4135. sc = status_get_sc(dst);
  4136. if(sc && sc->count) {
  4137. if(sc->data[SC_HALLUCINATION]) {
  4138. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4139. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4140. }
  4141. }
  4142. WBUFW(buf,0) = cmd;
  4143. WBUFL(buf,2) = src->id;
  4144. WBUFL(buf,6) = dst->id;
  4145. WBUFL(buf,10) = tick;
  4146. WBUFL(buf,14) = sdelay;
  4147. WBUFL(buf,18) = ddelay;
  4148. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4149. WBUFW(buf,22) = damage ? div : 0;
  4150. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4151. } else {
  4152. #if PACKETVER < 20071113
  4153. WBUFW(buf,22) = min(damage, INT16_MAX);
  4154. WBUFW(buf,27+offset) = damage2;
  4155. #else
  4156. WBUFL(buf,22) = damage;
  4157. WBUFL(buf,27+offset) = damage2;
  4158. #endif
  4159. }
  4160. #if PACKETVER >= 20131223
  4161. WBUFB(buf,26) = 0; // IsSPDamage - Displays blue digits. Need a way to handle this. [Rytech]
  4162. #endif
  4163. WBUFW(buf,24+offset) = div;
  4164. WBUFB(buf,26+offset) = type;
  4165. if(disguised(dst)) {
  4166. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4167. WBUFL(buf,6) = -dst->id;
  4168. clif_send(buf, packet_len(cmd), dst, SELF);
  4169. } else
  4170. clif_send(buf, packet_len(cmd), dst, AREA);
  4171. if(disguised(src)) {
  4172. WBUFL(buf,2) = -src->id;
  4173. if (disguised(dst))
  4174. WBUFL(buf,6) = dst->id;
  4175. #if PACKETVER < 20071113
  4176. if(damage > 0) WBUFW(buf,22) = -1;
  4177. if(damage2 > 0) WBUFW(buf,27) = -1;
  4178. #else
  4179. if(damage > 0) WBUFL(buf,22) = -1;
  4180. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4181. #endif
  4182. clif_send(buf,packet_len(cmd),src,SELF);
  4183. }
  4184. if(src == dst) {
  4185. unit_setdir(src, unit_getdir(src));
  4186. }
  4187. //Return adjusted can't walk delay for further processing.
  4188. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4189. }
  4190. /*==========================================
  4191. * src picks up dst
  4192. *------------------------------------------*/
  4193. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4194. {
  4195. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  4196. unsigned char buf[32];
  4197. nullpo_retv(src);
  4198. nullpo_retv(dst);
  4199. WBUFW(buf, 0) = 0x8a;
  4200. WBUFL(buf, 2) = src->id;
  4201. WBUFL(buf, 6) = dst->id;
  4202. WBUFB(buf,26) = 1;
  4203. clif_send(buf, packet_len(0x8a), src, AREA);
  4204. }
  4205. /*==========================================
  4206. * inform clients in area that `bl` is sitting
  4207. *------------------------------------------*/
  4208. void clif_sitting(struct block_list* bl)
  4209. {
  4210. unsigned char buf[32];
  4211. nullpo_retv(bl);
  4212. WBUFW(buf, 0) = 0x8a;
  4213. WBUFL(buf, 2) = bl->id;
  4214. WBUFB(buf,26) = 2;
  4215. clif_send(buf, packet_len(0x8a), bl, AREA);
  4216. if(disguised(bl)) {
  4217. WBUFL(buf, 2) = - bl->id;
  4218. clif_send(buf, packet_len(0x8a), bl, SELF);
  4219. }
  4220. }
  4221. /*==========================================
  4222. * inform clients in area that `bl` is standing
  4223. *------------------------------------------*/
  4224. void clif_standing(struct block_list* bl)
  4225. {
  4226. unsigned char buf[32];
  4227. nullpo_retv(bl);
  4228. WBUFW(buf, 0) = 0x8a;
  4229. WBUFL(buf, 2) = bl->id;
  4230. WBUFB(buf,26) = 3;
  4231. clif_send(buf, packet_len(0x8a), bl, AREA);
  4232. if(disguised(bl)) {
  4233. WBUFL(buf, 2) = - bl->id;
  4234. clif_send(buf, packet_len(0x8a), bl, SELF);
  4235. }
  4236. }
  4237. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4238. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4239. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4240. {
  4241. unsigned char buf[32];
  4242. WBUFW(buf,0) = 0x192;
  4243. WBUFW(buf,2) = x;
  4244. WBUFW(buf,4) = y;
  4245. WBUFW(buf,6) = type;
  4246. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  4247. if( fd )
  4248. {
  4249. WFIFOHEAD(fd,packet_len(0x192));
  4250. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4251. WFIFOSET(fd,packet_len(0x192));
  4252. }
  4253. else
  4254. {
  4255. struct block_list dummy_bl;
  4256. dummy_bl.type = BL_NUL;
  4257. dummy_bl.x = x;
  4258. dummy_bl.y = y;
  4259. dummy_bl.m = m;
  4260. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4261. }
  4262. }
  4263. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4264. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4265. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4266. {
  4267. int view,fd;
  4268. fd=sd->fd;
  4269. WFIFOHEAD(fd,packet_len(0x9d));
  4270. WFIFOW(fd,0)=0x9d;
  4271. WFIFOL(fd,2)=fitem->bl.id;
  4272. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4273. WFIFOW(fd,6)=view;
  4274. else
  4275. WFIFOW(fd,6)=fitem->item.nameid;
  4276. WFIFOB(fd,8)=fitem->item.identify;
  4277. WFIFOW(fd,9)=fitem->bl.x;
  4278. WFIFOW(fd,11)=fitem->bl.y;
  4279. WFIFOW(fd,13)=fitem->item.amount;
  4280. WFIFOB(fd,15)=fitem->subx;
  4281. WFIFOB(fd,16)=fitem->suby;
  4282. WFIFOSET(fd,packet_len(0x9d));
  4283. }
  4284. /// Notifes client about Graffiti
  4285. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4286. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4287. unsigned char buf[128];
  4288. nullpo_retv(bl);
  4289. nullpo_retv(unit);
  4290. WBUFW(buf, 0) = 0x1c9;
  4291. WBUFL(buf, 2) = unit->bl.id;
  4292. WBUFL(buf, 6) = unit->group->src_id;
  4293. WBUFW(buf,10) = unit->bl.x;
  4294. WBUFW(buf,12) = unit->bl.y;
  4295. WBUFB(buf,14) = unit->group->unit_id;
  4296. WBUFB(buf,15) = 1;
  4297. WBUFB(buf,16) = 1;
  4298. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4299. clif_send(buf,packet_len(0x1c9),bl,target);
  4300. }
  4301. /// Notifies the client of a skill unit.
  4302. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4303. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4304. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4305. /// 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)
  4306. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, uint8 flag) {
  4307. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4308. unsigned char buf[128];
  4309. nullpo_retv(bl);
  4310. nullpo_retv(unit);
  4311. if (bl->type == BL_PC)
  4312. fd = ((TBL_PC*)bl)->fd;
  4313. if (unit->group->state.guildaura)
  4314. return;
  4315. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4316. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4317. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4318. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4319. else
  4320. unit_id = unit->group->unit_id;
  4321. if (flag && battle_config.traps_setting&1) {
  4322. switch(unit->group->skill_id) {
  4323. case HT_ANKLESNARE:
  4324. if (!map_flag_vs(((TBL_PC*)bl)->bl.m))
  4325. break;
  4326. case HT_SKIDTRAP:
  4327. case MA_SKIDTRAP:
  4328. case HT_SHOCKWAVE:
  4329. case HT_SANDMAN:
  4330. case MA_SANDMAN:
  4331. case HT_FLASHER:
  4332. case HT_FREEZINGTRAP:
  4333. case MA_FREEZINGTRAP:
  4334. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for Hunter's traps
  4335. break;
  4336. }
  4337. }
  4338. #if PACKETVER >= 3
  4339. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4340. clif_graffiti(bl, unit, target);
  4341. return;
  4342. }
  4343. #endif
  4344. #if PACKETVER <= 20120702
  4345. header = 0x011f;
  4346. //#if PACKETVER < 20110718
  4347. // header = 0x011f;
  4348. //#elif PACKETVER < 20121212
  4349. // header = 0x08c7;
  4350. #elif PACKETVER < 20130731
  4351. header = 0x099f;
  4352. #else
  4353. header = 0x09ca;
  4354. #endif
  4355. len = packet_len(header);
  4356. WBUFW(buf,pos) = header;
  4357. if (header != 0x011f) {
  4358. WBUFW(buf, pos+2) = len;
  4359. pos += 2;
  4360. }
  4361. WBUFL(buf,pos+2) = unit->bl.id;
  4362. WBUFL(buf,pos+6) = unit->group->src_id;
  4363. WBUFW(buf,pos+10) = unit->bl.x;
  4364. WBUFW(buf,pos+12) = unit->bl.y;
  4365. switch (header) {
  4366. case 0x011f:
  4367. WBUFB(buf,pos+14) = unit_id;
  4368. WBUFB(buf,pos+15) = 1;
  4369. break;
  4370. case 0x08c7:
  4371. WBUFB(buf,pos+14) = unit_id;
  4372. WBUFW(buf,pos+15) = unit->range;
  4373. WBUFB(buf,pos+17) = 1;
  4374. break;
  4375. case 0x099f:
  4376. WBUFL(buf,pos+14) = unit_id;
  4377. WBUFW(buf,pos+18) = unit->range;
  4378. WBUFB(buf,pos+20) = 1;
  4379. break;
  4380. case 0x09ca:
  4381. WBUFL(buf,pos+14) = unit_id;
  4382. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4383. WBUFB(buf,pos+19) = 1;
  4384. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4385. break;
  4386. }
  4387. clif_send(buf, len, bl, target);
  4388. if (unit->group->skill_id == WZ_ICEWALL)
  4389. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4390. }
  4391. /*==========================================
  4392. * Server tells client to remove unit of id 'unit->bl.id'
  4393. *------------------------------------------*/
  4394. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4395. {
  4396. nullpo_retv(unit);
  4397. WFIFOHEAD(fd,packet_len(0x120));
  4398. WFIFOW(fd, 0)=0x120;
  4399. WFIFOL(fd, 2)=unit->bl.id;
  4400. WFIFOSET(fd,packet_len(0x120));
  4401. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4402. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4403. }
  4404. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4405. /// 0120 <id>.L
  4406. void clif_skill_delunit(struct skill_unit *unit)
  4407. {
  4408. unsigned char buf[16];
  4409. nullpo_retv(unit);
  4410. WBUFW(buf, 0)=0x120;
  4411. WBUFL(buf, 2)=unit->bl.id;
  4412. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4413. }
  4414. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4415. /// 01ac <id>.L
  4416. /// Only affects units with class [139,153] client-side.
  4417. void clif_skillunit_update(struct block_list* bl)
  4418. {
  4419. unsigned char buf[6];
  4420. nullpo_retv(bl);
  4421. WBUFW(buf,0) = 0x1ac;
  4422. WBUFL(buf,2) = bl->id;
  4423. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4424. }
  4425. /*==========================================
  4426. *
  4427. *------------------------------------------*/
  4428. static int clif_getareachar(struct block_list* bl,va_list ap)
  4429. {
  4430. struct map_session_data *sd;
  4431. nullpo_ret(bl);
  4432. sd=va_arg(ap,struct map_session_data*);
  4433. if (sd == NULL || !sd->fd)
  4434. return 0;
  4435. switch(bl->type){
  4436. case BL_ITEM:
  4437. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4438. break;
  4439. case BL_SKILL:
  4440. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF, 1);
  4441. break;
  4442. default:
  4443. if(&sd->bl == bl)
  4444. break;
  4445. clif_getareachar_unit(sd,bl);
  4446. break;
  4447. }
  4448. return 0;
  4449. }
  4450. /*==========================================
  4451. * tbl has gone out of view-size of bl
  4452. *------------------------------------------*/
  4453. int clif_outsight(struct block_list *bl,va_list ap)
  4454. {
  4455. struct block_list *tbl;
  4456. struct view_data *vd;
  4457. TBL_PC *sd, *tsd;
  4458. tbl=va_arg(ap,struct block_list*);
  4459. if(bl == tbl) return 0;
  4460. sd = BL_CAST(BL_PC, bl);
  4461. tsd = BL_CAST(BL_PC, tbl);
  4462. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4463. nullpo_ret(bl);
  4464. switch(bl->type){
  4465. case BL_PC:
  4466. if(sd->vd.class_ != INVISIBLE_CLASS)
  4467. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4468. if(sd->chatID){
  4469. struct chat_data *cd;
  4470. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4471. if(cd->usersd[0]==sd)
  4472. clif_dispchat(cd,tsd->fd);
  4473. }
  4474. if(sd->state.vending)
  4475. clif_closevendingboard(bl,tsd->fd);
  4476. if(sd->state.buyingstore)
  4477. clif_buyingstore_disappear_entry_single(tsd, sd);
  4478. break;
  4479. case BL_ITEM:
  4480. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4481. break;
  4482. case BL_SKILL:
  4483. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4484. break;
  4485. case BL_NPC:
  4486. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4487. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4488. break;
  4489. default:
  4490. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4491. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4492. break;
  4493. }
  4494. }
  4495. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4496. nullpo_ret(tbl);
  4497. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4498. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4499. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4500. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4501. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4502. }
  4503. return 0;
  4504. }
  4505. /*==========================================
  4506. * tbl has come into view of bl
  4507. *------------------------------------------*/
  4508. int clif_insight(struct block_list *bl,va_list ap)
  4509. {
  4510. struct block_list *tbl;
  4511. TBL_PC *sd, *tsd;
  4512. tbl=va_arg(ap,struct block_list*);
  4513. if (bl == tbl) return 0;
  4514. sd = BL_CAST(BL_PC, bl);
  4515. tsd = BL_CAST(BL_PC, tbl);
  4516. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4517. switch(bl->type){
  4518. case BL_ITEM:
  4519. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4520. break;
  4521. case BL_SKILL:
  4522. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF, 1);
  4523. break;
  4524. default:
  4525. clif_getareachar_unit(tsd,bl);
  4526. break;
  4527. }
  4528. }
  4529. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4530. clif_getareachar_unit(sd,tbl);
  4531. }
  4532. return 0;
  4533. }
  4534. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4535. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4536. void clif_skillinfoblock(struct map_session_data *sd)
  4537. {
  4538. int fd;
  4539. int i,len,id;
  4540. nullpo_retv(sd);
  4541. fd = sd->fd;
  4542. if (!fd)
  4543. return;
  4544. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4545. WFIFOW(fd,0) = 0x10f;
  4546. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4547. {
  4548. if( (id = sd->status.skill[i].id) != 0 )
  4549. {
  4550. // workaround for bugreport:5348
  4551. if (len + 37 > 8192)
  4552. break;
  4553. WFIFOW(fd,len) = id;
  4554. WFIFOL(fd,len+2) = skill_get_inf(id);
  4555. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4556. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4557. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4558. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4559. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4560. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4561. else
  4562. WFIFOB(fd,len+36) = 0;
  4563. len += 37;
  4564. }
  4565. }
  4566. WFIFOW(fd,2)=len;
  4567. WFIFOSET(fd,len);
  4568. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4569. for ( ; i < MAX_SKILL; i++)
  4570. {
  4571. if( (id = sd->status.skill[i].id) != 0 )
  4572. {
  4573. clif_addskill(sd, id);
  4574. clif_skillinfo(sd, id, 0);
  4575. }
  4576. }
  4577. }
  4578. /**
  4579. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4580. **/
  4581. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4582. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4583. void clif_addskill(struct map_session_data *sd, int skill_id)
  4584. {
  4585. int fd;
  4586. uint16 idx = 0;
  4587. nullpo_retv(sd);
  4588. fd = sd->fd;
  4589. if (!fd || !(idx = skill_get_index(skill_id)))
  4590. return;
  4591. if( sd->status.skill[idx].id <= 0 )
  4592. return;
  4593. WFIFOHEAD(fd, packet_len(0x111));
  4594. WFIFOW(fd,0) = 0x111;
  4595. WFIFOW(fd,2) = skill_id;
  4596. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4597. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4598. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4599. WFIFOW(fd,12)= skill_get_range2(&sd->bl, skill_id,sd->status.skill[idx].lv);
  4600. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4601. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4602. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4603. else
  4604. WFIFOB(fd,38) = 0;
  4605. WFIFOSET(fd,packet_len(0x111));
  4606. }
  4607. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4608. /// 0441 <skill id>.W
  4609. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4610. {
  4611. #if PACKETVER >= 20081217
  4612. int fd;
  4613. uint16 idx = 0;
  4614. nullpo_retv(sd);
  4615. fd = sd->fd;
  4616. if (!fd || !(idx = skill_get_index(skill_id)))
  4617. return;
  4618. WFIFOHEAD(fd,packet_len(0x441));
  4619. WFIFOW(fd,0) = 0x441;
  4620. WFIFOW(fd,2) = skill_id;
  4621. WFIFOSET(fd,packet_len(0x441));
  4622. #endif
  4623. clif_skillinfoblock(sd);
  4624. }
  4625. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4626. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4627. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4628. int fd;
  4629. nullpo_retv(sd);
  4630. fd = sd->fd;
  4631. WFIFOHEAD(fd, packet_len(0x10e));
  4632. WFIFOW(fd, 0) = 0x10e;
  4633. WFIFOW(fd, 2) = skill_id;
  4634. WFIFOW(fd, 4) = lv;
  4635. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4636. WFIFOW(fd, 8) = range;
  4637. WFIFOB(fd, 10) = upgradable;
  4638. WFIFOSET(fd, packet_len(0x10e));
  4639. }
  4640. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4641. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4642. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4643. {
  4644. const int fd = sd->fd;
  4645. uint16 idx = skill_get_index(skill_id);
  4646. if (!idx)
  4647. return;
  4648. WFIFOHEAD(fd,packet_len(0x7e1));
  4649. WFIFOW(fd,0) = 0x7e1;
  4650. WFIFOW(fd,2) = skill_id;
  4651. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4652. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4653. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4654. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv);
  4655. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4656. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4657. else
  4658. WFIFOB(fd,14) = 0;
  4659. WFIFOSET(fd,packet_len(0x7e1));
  4660. }
  4661. /// Notifies clients in area, that an object is about to use a skill.
  4662. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4663. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4664. /// property:
  4665. /// 0 = Yellow cast aura
  4666. /// 1 = Water elemental cast aura
  4667. /// 2 = Earth elemental cast aura
  4668. /// 3 = Fire elemental cast aura
  4669. /// 4 = Wind elemental cast aura
  4670. /// 5 = Poison elemental cast aura
  4671. /// 6 = Holy elemental cast aura
  4672. /// ? = like 0
  4673. /// is disposable:
  4674. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4675. /// 1 = no text
  4676. 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)
  4677. {
  4678. #if PACKETVER < 20091124
  4679. const int cmd = 0x13e;
  4680. #else
  4681. const int cmd = 0x7fb;
  4682. #endif
  4683. unsigned char buf[32];
  4684. WBUFW(buf,0) = cmd;
  4685. WBUFL(buf,2) = src_id;
  4686. WBUFL(buf,6) = dst_id;
  4687. WBUFW(buf,10) = dst_x;
  4688. WBUFW(buf,12) = dst_y;
  4689. WBUFW(buf,14) = skill_id;
  4690. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4691. WBUFL(buf,20) = casttime;
  4692. #if PACKETVER >= 20091124
  4693. WBUFB(buf,24) = 0; // isDisposable
  4694. #endif
  4695. if (disguised(bl)) {
  4696. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4697. WBUFL(buf,2) = -src_id;
  4698. clif_send(buf,packet_len(cmd), bl, SELF);
  4699. } else
  4700. clif_send(buf,packet_len(cmd), bl, AREA);
  4701. }
  4702. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4703. /// 01b9 <id>.L
  4704. void clif_skillcastcancel(struct block_list* bl)
  4705. {
  4706. unsigned char buf[16];
  4707. nullpo_retv(bl);
  4708. WBUFW(buf,0) = 0x1b9;
  4709. WBUFL(buf,2) = bl->id;
  4710. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4711. }
  4712. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4713. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4714. /// num (only used when skill id = NV_BASIC and cause = 0):
  4715. /// 0 = "skill failed" MsgStringTable[159]
  4716. /// 1 = "no emotions" MsgStringTable[160]
  4717. /// 2 = "no sit" MsgStringTable[161]
  4718. /// 3 = "no chat" MsgStringTable[162]
  4719. /// 4 = "no party" MsgStringTable[163]
  4720. /// 5 = "no shout" MsgStringTable[164]
  4721. /// 6 = "no PKing" MsgStringTable[165]
  4722. /// 7 = "no alligning" MsgStringTable[383]
  4723. /// ? = ignored
  4724. /// cause:
  4725. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4726. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4727. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4728. /// "skill failed" MsgStringTable[204] (otherwise)
  4729. /// ... = @see enum useskill_fail_cause
  4730. /// ? = ignored
  4731. ///
  4732. /// if(result!=0) doesn't display any of the previous messages
  4733. /// Note: when this packet is received an unknown flag is always set to 0,
  4734. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4735. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4736. {
  4737. int fd;
  4738. if (!sd) { //Since this is the most common nullpo....
  4739. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4740. return;
  4741. }
  4742. fd=sd->fd;
  4743. if (!fd) return;
  4744. if(battle_config.display_skill_fail&1)
  4745. return; //Disable all skill failed messages
  4746. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4747. return; //Disable delay failed messages
  4748. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4749. return;
  4750. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4751. return;
  4752. WFIFOHEAD(fd,packet_len(0x110));
  4753. WFIFOW(fd,0) = 0x110;
  4754. WFIFOW(fd,2) = skill_id;
  4755. WFIFOL(fd,4) = btype;
  4756. WFIFOB(fd,8) = 0;// success
  4757. WFIFOB(fd,9) = cause;
  4758. WFIFOSET(fd,packet_len(0x110));
  4759. }
  4760. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4761. /// 043d <skill ID>.W <tick>.L
  4762. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4763. {
  4764. #if PACKETVER>=20081112
  4765. int fd;
  4766. nullpo_retv(sd);
  4767. fd=sd->fd;
  4768. WFIFOHEAD(fd,packet_len(0x43d));
  4769. WFIFOW(fd,0) = 0x43d;
  4770. WFIFOW(fd,2) = skill_id;
  4771. WFIFOL(fd,4) = tick;
  4772. WFIFOSET(fd,packet_len(0x43d));
  4773. #endif
  4774. }
  4775. /// Skill attack effect and damage.
  4776. /// 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)
  4777. /// 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)
  4778. 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)
  4779. {
  4780. unsigned char buf[64];
  4781. struct status_change *sc;
  4782. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4783. nullpo_ret(src);
  4784. nullpo_ret(dst);
  4785. type = clif_calc_delay(type,div,damage,ddelay);
  4786. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4787. if(sc->data[SC_HALLUCINATION] && damage)
  4788. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4789. }
  4790. #if PACKETVER < 3
  4791. WBUFW(buf,0)=0x114;
  4792. WBUFW(buf,2)=skill_id;
  4793. WBUFL(buf,4)=src->id;
  4794. WBUFL(buf,8)=dst->id;
  4795. WBUFL(buf,12)=tick;
  4796. WBUFL(buf,16)=sdelay;
  4797. WBUFL(buf,20)=ddelay;
  4798. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4799. WBUFW(buf,24)=damage?div:0;
  4800. } else {
  4801. WBUFW(buf,24)=damage;
  4802. }
  4803. WBUFW(buf,26)=skill_lv;
  4804. WBUFW(buf,28)=div;
  4805. WBUFB(buf,30)=type;
  4806. if (disguised(dst)) {
  4807. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4808. WBUFL(buf,8)=-dst->id;
  4809. clif_send(buf,packet_len(0x114),dst,SELF);
  4810. } else
  4811. clif_send(buf,packet_len(0x114),dst,AREA);
  4812. if(disguised(src)) {
  4813. WBUFL(buf,4)=-src->id;
  4814. if (disguised(dst))
  4815. WBUFL(buf,8)=dst->id;
  4816. if(damage > 0)
  4817. WBUFW(buf,24)=-1;
  4818. clif_send(buf,packet_len(0x114),src,SELF);
  4819. }
  4820. #else
  4821. WBUFW(buf,0)=0x1de;
  4822. WBUFW(buf,2)=skill_id;
  4823. WBUFL(buf,4)=src->id;
  4824. WBUFL(buf,8)=dst->id;
  4825. WBUFL(buf,12)=tick;
  4826. WBUFL(buf,16)=sdelay;
  4827. WBUFL(buf,20)=ddelay;
  4828. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4829. WBUFL(buf,24)=damage?div:0;
  4830. } else {
  4831. WBUFL(buf,24)=damage;
  4832. }
  4833. WBUFW(buf,28)=skill_lv;
  4834. WBUFW(buf,30)=div;
  4835. // For some reason, late 2013 and newer clients have
  4836. // a issue that causes players and monsters to endure
  4837. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4838. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4839. #if PACKETVER < 20131223
  4840. WBUFB(buf,32)=type;
  4841. #else
  4842. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4843. #endif
  4844. if (disguised(dst)) {
  4845. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4846. WBUFL(buf,8)=-dst->id;
  4847. clif_send(buf,packet_len(0x1de),dst,SELF);
  4848. } else
  4849. clif_send(buf,packet_len(0x1de),dst,AREA);
  4850. if(disguised(src)) {
  4851. WBUFL(buf,4)=-src->id;
  4852. if (disguised(dst))
  4853. WBUFL(buf,8)=dst->id;
  4854. if(damage > 0)
  4855. WBUFL(buf,24)=-1;
  4856. clif_send(buf,packet_len(0x1de),src,SELF);
  4857. }
  4858. #endif
  4859. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4860. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4861. }
  4862. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4863. /// 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
  4864. /*
  4865. 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)
  4866. {
  4867. unsigned char buf[64];
  4868. struct status_change *sc;
  4869. nullpo_ret(src);
  4870. nullpo_ret(dst);
  4871. type = (type>0)?type:skill_get_hit(skill_id);
  4872. type = clif_calc_delay(type,div,damage,ddelay);
  4873. sc = status_get_sc(dst);
  4874. if(sc && sc->count) {
  4875. if(sc->data[SC_HALLUCINATION] && damage)
  4876. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4877. }
  4878. WBUFW(buf,0)=0x115;
  4879. WBUFW(buf,2)=skill_id;
  4880. WBUFL(buf,4)=src->id;
  4881. WBUFL(buf,8)=dst->id;
  4882. WBUFL(buf,12)=tick;
  4883. WBUFL(buf,16)=sdelay;
  4884. WBUFL(buf,20)=ddelay;
  4885. WBUFW(buf,24)=dst->x;
  4886. WBUFW(buf,26)=dst->y;
  4887. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4888. WBUFW(buf,28)=damage?div:0;
  4889. } else {
  4890. WBUFW(buf,28)=damage;
  4891. }
  4892. WBUFW(buf,30)=skill_lv;
  4893. WBUFW(buf,32)=div;
  4894. WBUFB(buf,34)=type;
  4895. clif_send(buf,packet_len(0x115),src,AREA);
  4896. if(disguised(src)) {
  4897. WBUFL(buf,4)=-src->id;
  4898. if(damage > 0)
  4899. WBUFW(buf,28)=-1;
  4900. clif_send(buf,packet_len(0x115),src,SELF);
  4901. }
  4902. if (disguised(dst)) {
  4903. WBUFL(buf,8)=-dst->id;
  4904. if (disguised(src))
  4905. WBUFL(buf,4)=src->id;
  4906. else if(damage > 0)
  4907. WBUFW(buf,28)=-1;
  4908. clif_send(buf,packet_len(0x115),dst,SELF);
  4909. }
  4910. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4911. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4912. }
  4913. */
  4914. /// Non-damaging skill effect
  4915. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4916. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4917. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4918. {
  4919. unsigned char buf[17];
  4920. #if PACKETVER < 20130731
  4921. const int cmd = 0x11a;
  4922. #else
  4923. const int cmd = 0x9cb;
  4924. #endif
  4925. int offset = 0;
  4926. nullpo_ret(dst);
  4927. WBUFW(buf,0) = cmd;
  4928. WBUFW(buf,2) = skill_id;
  4929. #if PACKETVER < 20130731
  4930. WBUFW(buf,4) = min(heal, INT16_MAX);
  4931. #else
  4932. WBUFL(buf,4) = min(heal, INT32_MAX);
  4933. offset += 2;
  4934. #endif
  4935. WBUFL(buf,6+offset) = dst->id;
  4936. WBUFL(buf,10+offset) = src ? src->id : 0;
  4937. WBUFB(buf,14+offset) = fail;
  4938. if (disguised(dst)) {
  4939. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4940. WBUFL(buf,6+offset) = -dst->id;
  4941. clif_send(buf, packet_len(cmd), dst, SELF);
  4942. } else
  4943. clif_send(buf, packet_len(cmd), dst, AREA);
  4944. if(src && disguised(src)) {
  4945. WBUFL(buf,10+offset) = -src->id;
  4946. if (disguised(dst))
  4947. WBUFL(buf,6+offset) = dst->id;
  4948. clif_send(buf, packet_len(cmd), src, SELF);
  4949. }
  4950. return fail;
  4951. }
  4952. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4953. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4954. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4955. {
  4956. unsigned char buf[32];
  4957. nullpo_retv(src);
  4958. WBUFW(buf,0)=0x117;
  4959. WBUFW(buf,2)=skill_id;
  4960. WBUFL(buf,4)=src->id;
  4961. WBUFW(buf,8)=val;
  4962. WBUFW(buf,10)=x;
  4963. WBUFW(buf,12)=y;
  4964. WBUFL(buf,14)=tick;
  4965. if(disguised(src)) {
  4966. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4967. WBUFL(buf,4)=-src->id;
  4968. clif_send(buf,packet_len(0x117),src,SELF);
  4969. } else
  4970. clif_send(buf,packet_len(0x117),src,AREA);
  4971. }
  4972. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4973. /// 011c <skill id>.W { <map name>.16B }*4
  4974. 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)
  4975. {
  4976. int fd;
  4977. nullpo_retv(sd);
  4978. fd = sd->fd;
  4979. WFIFOHEAD(fd,packet_len(0x11c));
  4980. WFIFOW(fd,0) = 0x11c;
  4981. WFIFOW(fd,2) = skill_id;
  4982. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4983. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4984. else // normal map name
  4985. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4986. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4987. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4988. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4989. WFIFOSET(fd,packet_len(0x11c));
  4990. sd->menuskill_id = skill_id;
  4991. if (skill_id == AL_WARP)
  4992. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4993. else
  4994. sd->menuskill_val = skill_lv;
  4995. }
  4996. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4997. /// 011e <type>.B
  4998. /// type:
  4999. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5000. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5001. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5002. ///
  5003. /// @param sd Who receives the message
  5004. /// @param type What message
  5005. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5006. {
  5007. int fd;
  5008. nullpo_retv(sd);
  5009. fd=sd->fd;
  5010. WFIFOHEAD(fd,packet_len(0x11e));
  5011. WFIFOW(fd,0)=0x11e;
  5012. WFIFOB(fd,2)=type;
  5013. WFIFOSET(fd,packet_len(0x11e));
  5014. }
  5015. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5016. /// 0189 <type>.W
  5017. /// type:
  5018. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5019. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5020. ///
  5021. /// @param sd Who receives the message
  5022. /// @param type What message
  5023. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5024. {
  5025. int fd;
  5026. nullpo_retv(sd);
  5027. fd=sd->fd;
  5028. WFIFOHEAD(fd,packet_len(0x189));
  5029. WFIFOW(fd,0)=0x189;
  5030. WFIFOW(fd,2)=type;
  5031. WFIFOSET(fd,packet_len(0x189));
  5032. }
  5033. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5034. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5035. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5036. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5037. {
  5038. struct status_data *status;
  5039. unsigned char buf[64];
  5040. int i;//, fix;
  5041. nullpo_retv(sd);
  5042. nullpo_retv(dst);
  5043. if( dst->type != BL_MOB )
  5044. return;
  5045. status = status_get_status_data(dst);
  5046. WBUFW(buf, 0)=0x18c;
  5047. WBUFW(buf, 2)=status_get_class(dst);
  5048. WBUFW(buf, 4)=status_get_lv(dst);
  5049. WBUFW(buf, 6)=status->size;
  5050. WBUFL(buf, 8)=status->hp;
  5051. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5052. +(battle_config.estimation_type&2?status->def2:0);
  5053. WBUFW(buf,14)=status->race;
  5054. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5055. +(battle_config.estimation_type&2?status->mdef2:0);
  5056. WBUFW(buf,18)= status->def_ele;
  5057. for(i=0;i<9;i++)
  5058. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5059. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5060. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5061. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5062. }
  5063. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5064. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5065. /// material id:
  5066. /// unused by the client
  5067. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5068. {
  5069. int i,c,view,fd;
  5070. nullpo_retv(sd);
  5071. if (sd->menuskill_id == skill_id)
  5072. return; //Avoid resending the menu twice or more times...
  5073. if (skill_id == GC_CREATENEWPOISON)
  5074. skill_id = GC_RESEARCHNEWPOISON;
  5075. fd = sd->fd;
  5076. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5077. WFIFOW(fd, 0) = 0x18d;
  5078. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5079. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5080. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5081. )
  5082. {
  5083. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5084. WFIFOW(fd,c*8+ 4) = view;
  5085. else
  5086. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5087. WFIFOW(fd,c*8+ 6) = 0;
  5088. WFIFOW(fd,c*8+ 8) = 0;
  5089. WFIFOW(fd,c*8+10) = 0;
  5090. c++;
  5091. }
  5092. }
  5093. WFIFOW(fd, 2) = c*8+8;
  5094. WFIFOSET(fd,WFIFOW(fd,2));
  5095. if (c > 0) {
  5096. sd->menuskill_id = skill_id;
  5097. sd->menuskill_val = trigger;
  5098. return;
  5099. }
  5100. }
  5101. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5102. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5103. /// mk type:
  5104. /// 1 = cooking
  5105. /// 2 = arrow
  5106. /// 3 = elemental
  5107. /// 4 = GN_MIX_COOKING
  5108. /// 5 = GN_MAKEBOMB
  5109. /// 6 = GN_S_PHARMACY
  5110. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5111. {
  5112. int fd;
  5113. int i, c;
  5114. int view;
  5115. nullpo_retv(sd);
  5116. fd = sd->fd;
  5117. if(sd->menuskill_id == skill_id)
  5118. return; //Avoid resending the menu twice or more times...
  5119. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5120. WFIFOW(fd,0) = 0x25a;
  5121. WFIFOW(fd,4) = list_type; // list type
  5122. c = 0;
  5123. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5124. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5125. continue;
  5126. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5127. WFIFOW(fd, 6 + 2 * c) = view;
  5128. else
  5129. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5130. c++;
  5131. }
  5132. if( c > 0 || skill_id == AM_PHARMACY) {
  5133. sd->menuskill_id = skill_id;
  5134. sd->menuskill_val = trigger;
  5135. sd->menuskill_val2 = qty; // amount.
  5136. WFIFOW(fd,2) = 6 + 2 * c;
  5137. WFIFOSET(fd,WFIFOW(fd,2));
  5138. } else {
  5139. clif_menuskill_clear(sd);
  5140. #if PACKETVER >= 20090922
  5141. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5142. #else
  5143. WFIFOW(fd,2) = 6 + 2 * c;
  5144. WFIFOSET(fd,WFIFOW(fd,2));
  5145. #endif
  5146. }
  5147. }
  5148. /// Notifies clients of a status change.
  5149. /// 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)]
  5150. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5151. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5152. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  5153. {
  5154. unsigned char buf[32];
  5155. struct map_session_data *sd;
  5156. if (type == SI_BLANK) //It shows nothing on the client...
  5157. return;
  5158. if (type == SI_ACTIONDELAY && tick == 0)
  5159. return;
  5160. nullpo_retv(bl);
  5161. sd = BL_CAST(BL_PC, bl);
  5162. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5163. return;
  5164. #if PACKETVER >= 20120618
  5165. if(flag && battle_config.display_status_timers && sd)
  5166. WBUFW(buf,0)=0x983;
  5167. else
  5168. #elif PACKETVER >= 20090121
  5169. if(flag && battle_config.display_status_timers && sd)
  5170. WBUFW(buf,0)=0x43f;
  5171. else
  5172. #endif
  5173. WBUFW(buf,0)=0x196;
  5174. WBUFW(buf,2)=type;
  5175. WBUFL(buf,4)=bl->id;
  5176. WBUFB(buf,8)=flag;
  5177. #if PACKETVER >= 20120618
  5178. if(flag && battle_config.display_status_timers && sd) {
  5179. if (tick <= 0)
  5180. tick = 9999; // this is indeed what official servers do
  5181. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  5182. WBUFL(buf,13)=tick;
  5183. WBUFL(buf,17) = val1;
  5184. WBUFL(buf,21) = val2;
  5185. WBUFL(buf,25) = val3;
  5186. }
  5187. #elif PACKETVER >= 20090121
  5188. if(flag && battle_config.display_status_timers && sd) {
  5189. if (tick <= 0)
  5190. tick = 9999; // this is indeed what official servers do
  5191. WBUFL(buf,9) = tick;
  5192. WBUFL(buf,13) = val1;
  5193. WBUFL(buf,17) = val2;
  5194. WBUFL(buf,21) = val3;
  5195. }
  5196. #endif
  5197. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  5198. }
  5199. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  5200. unsigned char buf[32];
  5201. if (type == SI_BLANK) //It shows nothing on the client
  5202. return;
  5203. nullpo_retv(bl);
  5204. WBUFW(buf,0) = 0x43f;
  5205. WBUFW(buf,2) = type;
  5206. WBUFL(buf,4) = tid;
  5207. WBUFB(buf,8) = 1;
  5208. WBUFL(buf,9) = 9999;
  5209. WBUFL(buf,13) = val1;
  5210. WBUFL(buf,17) = val2;
  5211. WBUFL(buf,21) = val3;
  5212. clif_send(buf,packet_len(0x43f),bl,target);
  5213. }
  5214. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5215. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5216. //! TODO
  5217. //void clif_efst_enter();
  5218. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5219. /// 008e <packet len>.W <message>.?B
  5220. void clif_displaymessage(const int fd, const char* mes)
  5221. {
  5222. nullpo_retv(mes);
  5223. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5224. if (fd == 0)
  5225. ;
  5226. else {
  5227. char *message, *line;
  5228. message = aStrdup(mes);
  5229. line = strtok(message, "\n");
  5230. #if PACKETVER == 20141022
  5231. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5232. /** so we redirect to ZC_NPC_CHAT **/
  5233. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5234. while(line != NULL) {
  5235. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5236. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5237. if (len > 0) {
  5238. WFIFOHEAD(fd, 13 + len);
  5239. WFIFOW(fd, 0) = 0x2C1;
  5240. WFIFOW(fd, 2) = 13 + len;
  5241. WFIFOL(fd, 4) = 0;
  5242. WFIFOL(fd, 8) = color;
  5243. safestrncpy((char*)WFIFOP(fd, 12), line, len + 1);
  5244. WFIFOSET(fd, WFIFOW(fd, 2));
  5245. }
  5246. #else
  5247. while(line != NULL) {
  5248. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5249. int len = strnlen(line, CHAT_SIZE_MAX);
  5250. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5251. WFIFOHEAD(fd, 5 + len);
  5252. WFIFOW(fd,0) = 0x8e;
  5253. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5254. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5255. WFIFOSET(fd, 5 + len);
  5256. }
  5257. #endif
  5258. line = strtok(NULL, "\n");
  5259. }
  5260. aFree(message);
  5261. }
  5262. }
  5263. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5264. /// 009a <packet len>.W <message>.?B
  5265. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5266. {
  5267. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5268. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5269. WBUFW(buf,0) = 0x9a;
  5270. WBUFW(buf,2) = 4 + lp + len;
  5271. if (type&BC_BLUE)
  5272. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5273. else if (type&BC_WOE)
  5274. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5275. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5276. clif_send(buf, WBUFW(buf,2), bl, target);
  5277. if (buf)
  5278. aFree(buf);
  5279. }
  5280. /*==========================================
  5281. * Displays a message on a 'bl' to all it's nearby clients
  5282. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5283. *------------------------------------------*/
  5284. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5285. char buf[100];
  5286. int len;
  5287. nullpo_retv(bl);
  5288. if(!message)
  5289. return;
  5290. len = strlen(message)+1;
  5291. if( len > sizeof(buf)-8 ) {
  5292. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5293. len = sizeof(buf)-8;
  5294. }
  5295. WBUFW(buf,0)=0x8d;
  5296. WBUFW(buf,2)=len+8;
  5297. WBUFL(buf,4)=bl->id;
  5298. safestrncpy((char *) WBUFP(buf,8),message,len);
  5299. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5300. }
  5301. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5302. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5303. 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)
  5304. {
  5305. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5306. WBUFW(buf,0) = 0x1c3;
  5307. WBUFW(buf,2) = len + 16;
  5308. WBUFL(buf,4) = fontColor;
  5309. WBUFW(buf,8) = fontType;
  5310. WBUFW(buf,10) = fontSize;
  5311. WBUFW(buf,12) = fontAlign;
  5312. WBUFW(buf,14) = fontY;
  5313. memcpy(WBUFP(buf,16), mes, len);
  5314. clif_send(buf, WBUFW(buf,2), bl, target);
  5315. if (buf)
  5316. aFree(buf);
  5317. }
  5318. /*
  5319. * Display *msg from *sd to all *users in channel
  5320. */
  5321. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5322. DBIterator *iter;
  5323. struct map_session_data *user;
  5324. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  5325. WFIFOHEAD(sd->fd,msg_len + 12);
  5326. WFIFOW(sd->fd,0) = 0x2C1;
  5327. WFIFOW(sd->fd,2) = msg_len + 12;
  5328. WFIFOL(sd->fd,4) = 0;
  5329. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5330. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5331. iter = db_iterator(channel->users);
  5332. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5333. if( user->fd == sd->fd )
  5334. continue;
  5335. WFIFOHEAD(user->fd,msg_len + 12);
  5336. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5337. WFIFOSET(user->fd, msg_len + 12);
  5338. }
  5339. dbi_destroy(iter);
  5340. WFIFOSET(sd->fd, msg_len + 12);
  5341. }
  5342. /// Displays heal effect.
  5343. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5344. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5345. /// var id:
  5346. /// 5 = HP (SP_HP)
  5347. /// 7 = SP (SP_SP)
  5348. /// ? = ignored
  5349. void clif_heal(int fd,int type,int val) {
  5350. #if PACKETVER < 20141022
  5351. const int cmd = 0x13d;
  5352. #else
  5353. const int cmd = 0xa27;
  5354. #endif
  5355. WFIFOHEAD(fd, packet_len(cmd));
  5356. WFIFOW(fd,0) = cmd;
  5357. WFIFOW(fd,2) = type;
  5358. #if PACKETVER < 20141022
  5359. WFIFOW(fd,4) = min(val, INT16_MAX);
  5360. #else
  5361. WFIFOL(fd,4) = min(val, INT32_MAX);
  5362. #endif
  5363. WFIFOSET(fd, packet_len(cmd));
  5364. }
  5365. /// Displays resurrection effect (ZC_RESURRECTION).
  5366. /// 0148 <id>.L <type>.W
  5367. /// type:
  5368. /// ignored
  5369. void clif_resurrection(struct block_list *bl,int type)
  5370. {
  5371. unsigned char buf[16];
  5372. nullpo_retv(bl);
  5373. WBUFW(buf,0)=0x148;
  5374. WBUFL(buf,2)=bl->id;
  5375. WBUFW(buf,6)=0;
  5376. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5377. if (disguised(bl))
  5378. clif_spawn(bl);
  5379. }
  5380. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5381. /// 0199 <type>.W
  5382. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5383. {
  5384. int fd;
  5385. nullpo_retv(sd);
  5386. fd=sd->fd;
  5387. WFIFOHEAD(fd,packet_len(0x199));
  5388. WFIFOW(fd,0)=0x199;
  5389. WFIFOW(fd,2)=property;
  5390. WFIFOSET(fd,packet_len(0x199));
  5391. }
  5392. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5393. #if PACKETVER >= 20121010
  5394. unsigned char buf[8];
  5395. unsigned int NotifyProperty =
  5396. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5397. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5398. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5399. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5400. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5401. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5402. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5403. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5404. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5405. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5406. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5407. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5408. WBUFW(buf,0)=0x99b;
  5409. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5410. WBUFL(buf,4)=NotifyProperty;
  5411. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5412. clif_send(buf,packet_len(0x99b),bl,t);
  5413. #endif
  5414. }
  5415. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5416. /// 01d6 <type>.W
  5417. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5418. {
  5419. int fd;
  5420. nullpo_retv(sd);
  5421. fd=sd->fd;
  5422. WFIFOHEAD(fd,packet_len(0x1D6));
  5423. WFIFOW(fd,0)=0x1D6;
  5424. WFIFOW(fd,2)=type;
  5425. WFIFOSET(fd,packet_len(0x1D6));
  5426. }
  5427. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5428. /// 019a <id>.L <ranking>.L <total>.L
  5429. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5430. {
  5431. if(type == 2) {
  5432. int fd = sd->fd;
  5433. WFIFOHEAD(fd,packet_len(0x19a));
  5434. WFIFOW(fd,0) = 0x19a;
  5435. WFIFOL(fd,2) = sd->bl.id;
  5436. WFIFOL(fd,6) = pvprank;
  5437. WFIFOL(fd,10) = pvpnum;
  5438. WFIFOSET(fd,packet_len(0x19a));
  5439. } else {
  5440. unsigned char buf[32];
  5441. WBUFW(buf,0) = 0x19a;
  5442. WBUFL(buf,2) = sd->bl.id;
  5443. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5444. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5445. else
  5446. WBUFL(buf,6) = pvprank;
  5447. WBUFL(buf,10) = pvpnum;
  5448. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5449. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5450. else if(!type)
  5451. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5452. else
  5453. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5454. }
  5455. }
  5456. /*==========================================
  5457. *
  5458. *------------------------------------------*/
  5459. void clif_map_property_mapall(int map_idx, enum map_property property)
  5460. {
  5461. struct block_list bl;
  5462. unsigned char buf[16];
  5463. bl.id = 0;
  5464. bl.type = BL_NUL;
  5465. bl.m = map_idx;
  5466. WBUFW(buf,0)=0x199;
  5467. WBUFW(buf,2)=property;
  5468. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5469. }
  5470. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5471. /// 0188 <result>.W <index>.W <refine>.W
  5472. /// result:
  5473. /// 0 = success
  5474. /// 1 = failure
  5475. /// 2 = downgrade
  5476. void clif_refine(int fd, int fail, int index, int val)
  5477. {
  5478. WFIFOHEAD(fd,packet_len(0x188));
  5479. WFIFOW(fd,0)=0x188;
  5480. WFIFOW(fd,2)=fail;
  5481. WFIFOW(fd,4)=index+2;
  5482. WFIFOW(fd,6)=val;
  5483. WFIFOSET(fd,packet_len(0x188));
  5484. }
  5485. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5486. /// 0223 <result>.L <nameid>.W
  5487. /// result:
  5488. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5489. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5490. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5491. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5492. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5493. {
  5494. WFIFOHEAD(fd,packet_len(0x223));
  5495. WFIFOW(fd,0)=0x223;
  5496. WFIFOL(fd,2)=result;
  5497. WFIFOW(fd,6)=item_id;
  5498. WFIFOSET(fd,packet_len(0x223));
  5499. }
  5500. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5501. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5502. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5503. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5504. {
  5505. #if PACKETVER < 20091104
  5506. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5507. WFIFOW(fd,0) = 0x97;
  5508. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5509. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5510. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5511. WFIFOSET(fd,WFIFOW(fd,2));
  5512. #else
  5513. struct map_session_data *ssd = map_nick2sd(nick);
  5514. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5515. WFIFOW(fd,0) = 0x97;
  5516. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5517. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5518. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5519. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5520. WFIFOSET(fd,WFIFOW(fd,2));
  5521. #endif
  5522. }
  5523. /// Inform the player about the result of his whisper action
  5524. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5525. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5526. /// result:
  5527. /// 0 = success to send wisper
  5528. /// 1 = target character is not loged in
  5529. /// 2 = ignored by target
  5530. /// 3 = everyone ignored by target
  5531. void clif_wis_end(int fd, int result)
  5532. {
  5533. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5534. #if PACKETVER < 20131223
  5535. const int cmd = 0x98;
  5536. #else
  5537. const int cmd = 0x9df;
  5538. #endif
  5539. if (!sd)
  5540. return;
  5541. WFIFOHEAD(fd,packet_len(cmd));
  5542. WFIFOW(fd,0) = cmd;
  5543. WFIFOB(fd,2) = (char)result;
  5544. #if PACKETVER >= 20131223
  5545. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5546. #endif
  5547. WFIFOSET(fd,packet_len(cmd));
  5548. }
  5549. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5550. /// 0194 <char id>.L <name>.24B
  5551. void clif_solved_charname(int fd, int charid, const char* name)
  5552. {
  5553. WFIFOHEAD(fd,packet_len(0x194));
  5554. WFIFOW(fd,0)=0x194;
  5555. WFIFOL(fd,2)=charid;
  5556. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5557. WFIFOSET(fd,packet_len(0x194));
  5558. }
  5559. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5560. /// 017b <packet len>.W { <name id>.W }*
  5561. void clif_use_card(struct map_session_data *sd,int idx)
  5562. {
  5563. int i,c,ep;
  5564. int fd=sd->fd;
  5565. nullpo_retv(sd);
  5566. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5567. return;
  5568. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5569. return; //Avoid parsing invalid item indexes (no card/no item)
  5570. ep=sd->inventory_data[idx]->equip;
  5571. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5572. WFIFOW(fd,0)=0x17b;
  5573. for(i=c=0;i<MAX_INVENTORY;i++){
  5574. int j;
  5575. if(sd->inventory_data[i] == NULL)
  5576. continue;
  5577. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5578. continue;
  5579. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5580. continue;
  5581. if(sd->status.inventory[i].identify==0 ) //Not identified
  5582. continue;
  5583. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5584. continue;
  5585. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5586. continue;
  5587. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5588. if( j == sd->inventory_data[i]->slot ) // No room
  5589. continue;
  5590. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5591. continue;
  5592. WFIFOW(fd,4+c*2)=i+2;
  5593. c++;
  5594. }
  5595. if( !c ) return; // no item is available for card insertion
  5596. WFIFOW(fd,2)=4+c*2;
  5597. WFIFOSET(fd,WFIFOW(fd,2));
  5598. }
  5599. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5600. /// 017d <equip index>.W <card index>.W <result>.B
  5601. /// result:
  5602. /// 0 = success
  5603. /// 1 = failure
  5604. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5605. {
  5606. int fd;
  5607. nullpo_retv(sd);
  5608. fd=sd->fd;
  5609. WFIFOHEAD(fd,packet_len(0x17d));
  5610. WFIFOW(fd,0)=0x17d;
  5611. WFIFOW(fd,2)=idx_equip+2;
  5612. WFIFOW(fd,4)=idx_card+2;
  5613. WFIFOB(fd,6)=flag;
  5614. WFIFOSET(fd,packet_len(0x17d));
  5615. }
  5616. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5617. /// 0177 <packet len>.W { <name id>.W }*
  5618. void clif_item_identify_list(struct map_session_data *sd)
  5619. {
  5620. int i,c;
  5621. int fd;
  5622. nullpo_retv(sd);
  5623. fd=sd->fd;
  5624. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5625. WFIFOW(fd,0)=0x177;
  5626. for(i=c=0;i<MAX_INVENTORY;i++){
  5627. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5628. WFIFOW(fd,c*2+4)=i+2;
  5629. c++;
  5630. }
  5631. }
  5632. if(c > 0) {
  5633. WFIFOW(fd,2)=c*2+4;
  5634. WFIFOSET(fd,WFIFOW(fd,2));
  5635. sd->menuskill_id = MC_IDENTIFY;
  5636. sd->menuskill_val = c;
  5637. }
  5638. }
  5639. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5640. /// 0179 <index>.W <result>.B
  5641. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5642. {
  5643. int fd;
  5644. nullpo_retv(sd);
  5645. fd=sd->fd;
  5646. WFIFOHEAD(fd,packet_len(0x179));
  5647. WFIFOW(fd, 0)=0x179;
  5648. WFIFOW(fd, 2)=idx+2;
  5649. WFIFOB(fd, 4)=flag;
  5650. WFIFOSET(fd,packet_len(0x179));
  5651. }
  5652. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5653. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5654. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5655. {
  5656. int i,c;
  5657. int fd;
  5658. nullpo_retv(sd);
  5659. nullpo_retv(dstsd);
  5660. fd=sd->fd;
  5661. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5662. WFIFOW(fd,0)=0x1fc;
  5663. for(i=c=0;i<MAX_INVENTORY;i++){
  5664. unsigned short nameid;
  5665. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5666. WFIFOW(fd,c*13+4) = i;
  5667. WFIFOW(fd,c*13+6) = nameid;
  5668. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5669. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5670. c++;
  5671. }
  5672. }
  5673. if(c > 0) {
  5674. WFIFOW(fd,2)=c*13+4;
  5675. WFIFOSET(fd,WFIFOW(fd,2));
  5676. sd->menuskill_id = BS_REPAIRWEAPON;
  5677. sd->menuskill_val = dstsd->bl.id;
  5678. sd->menuskill_val2 = lv;
  5679. }else
  5680. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5681. }
  5682. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5683. /// 01fe <index>.W <result>.B
  5684. /// index:
  5685. /// ignored (inventory index)
  5686. /// result:
  5687. /// 0 = Item repair success.
  5688. /// 1 = Item repair failure.
  5689. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5690. {
  5691. int fd;
  5692. nullpo_retv(sd);
  5693. fd = sd->fd;
  5694. WFIFOHEAD(fd,packet_len(0x1fe));
  5695. WFIFOW(fd, 0)=0x1fe;
  5696. WFIFOW(fd, 2)=idx+2;
  5697. WFIFOB(fd, 4)=flag;
  5698. WFIFOSET(fd,packet_len(0x1fe));
  5699. }
  5700. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5701. /// 02bb <equip location>.W <account id>.L
  5702. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5703. {
  5704. int fd = sd->fd;
  5705. WFIFOHEAD(fd,packet_len(0x2bb));
  5706. WFIFOW(fd,0) = 0x2bb;
  5707. WFIFOW(fd,2) = position;
  5708. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5709. WFIFOSET(fd,packet_len(0x2bb));
  5710. }
  5711. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5712. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5713. void clif_item_refine_list(struct map_session_data *sd)
  5714. {
  5715. int i,c;
  5716. int fd;
  5717. uint16 skill_lv;
  5718. int refine_item[5];
  5719. nullpo_retv(sd);
  5720. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5721. fd=sd->fd;
  5722. refine_item[0] = -1;
  5723. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5724. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5725. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5726. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5727. WFIFOW(fd,0)=0x221;
  5728. for(i=c=0;i<MAX_INVENTORY;i++){
  5729. unsigned char wlv;
  5730. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5731. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5732. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5733. WFIFOW(fd,c*13+ 4)=i+2;
  5734. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5735. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5736. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5737. c++;
  5738. }
  5739. }
  5740. WFIFOW(fd,2)=c*13+4;
  5741. WFIFOSET(fd,WFIFOW(fd,2));
  5742. if (c > 0) {
  5743. sd->menuskill_id = WS_WEAPONREFINE;
  5744. sd->menuskill_val = skill_lv;
  5745. }
  5746. }
  5747. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5748. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5749. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5750. {
  5751. int fd;
  5752. nullpo_retv(sd);
  5753. fd=sd->fd;
  5754. WFIFOHEAD(fd,packet_len(0x147));
  5755. WFIFOW(fd, 0)=0x147;
  5756. WFIFOW(fd, 2)=skill_id;
  5757. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5758. WFIFOW(fd, 6)=0;
  5759. WFIFOW(fd, 8)=skill_lv;
  5760. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5761. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5762. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5763. WFIFOB(fd,38)=0;
  5764. WFIFOSET(fd,packet_len(0x147));
  5765. }
  5766. /// Adds an item to character's cart.
  5767. /// 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)
  5768. /// 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)
  5769. /// 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)
  5770. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5771. {
  5772. #if PACKETVER < 5
  5773. const int cmd = 0x124;
  5774. #elif PACKETVER < 20150226
  5775. const int cmd = 0x1c5;
  5776. #else
  5777. const int cmd = 0xa0b;
  5778. #endif
  5779. int view,fd;
  5780. unsigned char *buf;
  5781. int offset = 0;
  5782. nullpo_retv(sd);
  5783. fd=sd->fd;
  5784. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5785. return;
  5786. WFIFOHEAD(fd,packet_len(cmd));
  5787. buf=WFIFOP(fd,0);
  5788. WBUFW(buf,0)=cmd;
  5789. WBUFW(buf,2)=n+2;
  5790. WBUFL(buf,4)=amount;
  5791. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5792. WBUFW(buf,8)=view;
  5793. else
  5794. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5795. #if PACKETVER >= 5
  5796. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5797. offset += 1;
  5798. #endif
  5799. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5800. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5801. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5802. clif_addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5803. #if PACKETVER >= 20150226
  5804. clif_add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5805. #endif
  5806. WFIFOSET(fd,packet_len(cmd));
  5807. }
  5808. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5809. /* Acknowledge an item have been added to cart
  5810. * 012c <result>B
  5811. * result :
  5812. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5813. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5814. */
  5815. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5816. {
  5817. int fd;
  5818. unsigned char *buf;
  5819. nullpo_retv(sd);
  5820. fd = sd->fd;
  5821. buf = WFIFOP(fd,0);
  5822. WBUFW(buf,0) = 0x12c;
  5823. WBUFB(buf,2) = flag;
  5824. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5825. }
  5826. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5827. void clif_bank_open(struct map_session_data *sd){
  5828. int fd;
  5829. nullpo_retv(sd);
  5830. fd = sd->fd;
  5831. WFIFOHEAD(fd,4);
  5832. WFIFOW(fd,0) = 0x09b7;
  5833. WFIFOW(fd,2) = 0;
  5834. WFIFOSET(fd,4);
  5835. }
  5836. /*
  5837. * Request to Open the banking system
  5838. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5839. */
  5840. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5841. //TODO check if preventing trade or stuff like that
  5842. //also mark something in case char ain't available for saving, should we check now ?
  5843. nullpo_retv(sd);
  5844. if( !battle_config.feature_banking ) {
  5845. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5846. return;
  5847. }
  5848. else {
  5849. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5850. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5851. if(sd->status.account_id == aid){
  5852. sd->state.banking = 1;
  5853. //request save ?
  5854. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5855. //on succes open bank ?
  5856. clif_bank_open(sd);
  5857. }
  5858. }
  5859. }
  5860. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5861. void clif_bank_close(struct map_session_data *sd){
  5862. int fd;
  5863. nullpo_retv(sd);
  5864. fd = sd->fd;
  5865. WFIFOHEAD(fd,4);
  5866. WFIFOW(fd,0) = 0x09B9;
  5867. WFIFOW(fd,2) = 0;
  5868. WFIFOSET(fd,4);
  5869. }
  5870. /*
  5871. * Request to close the banking system
  5872. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5873. */
  5874. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5875. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5876. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5877. nullpo_retv(sd);
  5878. if( !battle_config.feature_banking ) {
  5879. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5880. //still allow to go trough to not stuck player if we have disable it while they was in
  5881. }
  5882. if(sd->status.account_id == aid){
  5883. sd->state.banking = 0;
  5884. clif_bank_close(sd);
  5885. }
  5886. }
  5887. /*
  5888. * Display how much we got in bank (I suppose)
  5889. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5890. */
  5891. void clif_Bank_Check(struct map_session_data* sd) {
  5892. unsigned char buf[13];
  5893. struct s_packet_db* info;
  5894. int16 len;
  5895. int cmd = 0;
  5896. nullpo_retv(sd);
  5897. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5898. if(!cmd) cmd = 0x09A6; //default
  5899. info = &packet_db[sd->packet_ver][cmd];
  5900. len = info->len;
  5901. if(!len) return; //version as packet disable
  5902. // sd->state.banking = 1; //mark opening and closing
  5903. WBUFW(buf,0) = cmd;
  5904. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5905. WBUFW(buf,info->pos[1]) = 0; //reason
  5906. clif_send(buf,len,&sd->bl,SELF);
  5907. }
  5908. /*
  5909. * Requesting the data in bank
  5910. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5911. */
  5912. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5913. nullpo_retv(sd);
  5914. if( !battle_config.feature_banking ) {
  5915. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5916. return;
  5917. }
  5918. else {
  5919. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5920. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5921. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5922. clif_Bank_Check(sd);
  5923. }
  5924. }
  5925. /*
  5926. * Acknowledge of deposit some money in bank
  5927. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5928. */
  5929. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5930. unsigned char buf[17];
  5931. struct s_packet_db* info;
  5932. int16 len;
  5933. int cmd =0;
  5934. nullpo_retv(sd);
  5935. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5936. if(!cmd) cmd = 0x09A8;
  5937. info = &packet_db[sd->packet_ver][cmd];
  5938. len = info->len;
  5939. if(!len) return; //version as packet disable
  5940. WBUFW(buf,0) = cmd;
  5941. WBUFW(buf,info->pos[0]) = (short)reason;
  5942. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5943. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5944. clif_send(buf,len,&sd->bl,SELF);
  5945. }
  5946. /*
  5947. * Request saving some money in bank
  5948. * @author : original [Yommy/Hercules]
  5949. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5950. */
  5951. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5952. nullpo_retv(sd);
  5953. if( !battle_config.feature_banking ) {
  5954. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5955. return;
  5956. }
  5957. else {
  5958. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5959. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5960. int money = RFIFOL(fd,info->pos[1]);
  5961. if(sd->status.account_id == aid){
  5962. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5963. clif_bank_deposit(sd,reason);
  5964. }
  5965. }
  5966. }
  5967. /*
  5968. * Acknowledge of withdrawing some money from bank
  5969. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5970. */
  5971. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5972. unsigned char buf[17];
  5973. struct s_packet_db* info;
  5974. int16 len;
  5975. int cmd;
  5976. nullpo_retv(sd);
  5977. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5978. if(!cmd) cmd = 0x09AA;
  5979. info = &packet_db[sd->packet_ver][cmd];
  5980. len = info->len;
  5981. if(!len) return; //version as packet disable
  5982. WBUFW(buf,0) = cmd;
  5983. WBUFW(buf,info->pos[0]) = (short)reason;
  5984. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5985. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5986. clif_send(buf,len,&sd->bl,SELF);
  5987. }
  5988. /*
  5989. * Request Withdrawing some money from bank
  5990. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5991. */
  5992. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5993. nullpo_retv(sd);
  5994. if( !battle_config.feature_banking ) {
  5995. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5996. return;
  5997. }
  5998. else {
  5999. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  6000. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6001. int money = RFIFOL(fd,info->pos[1]);
  6002. if(sd->status.account_id == aid){
  6003. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6004. clif_bank_withdraw(sd,reason);
  6005. }
  6006. }
  6007. }
  6008. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6009. /// 0125 <index>.W <amount>.L
  6010. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6011. {
  6012. int fd;
  6013. nullpo_retv(sd);
  6014. fd=sd->fd;
  6015. WFIFOHEAD(fd,packet_len(0x125));
  6016. WFIFOW(fd,0)=0x125;
  6017. WFIFOW(fd,2)=n+2;
  6018. WFIFOL(fd,4)=amount;
  6019. WFIFOSET(fd,packet_len(0x125));
  6020. }
  6021. /// Opens the shop creation menu (ZC_OPENSTORE).
  6022. /// 012d <num>.W
  6023. /// num:
  6024. /// number of allowed item slots
  6025. void clif_openvendingreq(struct map_session_data* sd, int num)
  6026. {
  6027. int fd;
  6028. nullpo_retv(sd);
  6029. fd = sd->fd;
  6030. WFIFOHEAD(fd,packet_len(0x12d));
  6031. WFIFOW(fd,0) = 0x12d;
  6032. WFIFOW(fd,2) = num;
  6033. WFIFOSET(fd,packet_len(0x12d));
  6034. }
  6035. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6036. /// 0131 <owner id>.L <message>.80B
  6037. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6038. {
  6039. unsigned char buf[128];
  6040. nullpo_retv(bl);
  6041. WBUFW(buf,0) = 0x131;
  6042. WBUFL(buf,2) = bl->id;
  6043. safestrncpy((char*)WBUFP(buf,6), message, 80);
  6044. if( fd ) {
  6045. WFIFOHEAD(fd,packet_len(0x131));
  6046. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6047. WFIFOSET(fd,packet_len(0x131));
  6048. } else {
  6049. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6050. }
  6051. }
  6052. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6053. /// 0132 <owner id>.L
  6054. void clif_closevendingboard(struct block_list* bl, int fd)
  6055. {
  6056. unsigned char buf[16];
  6057. nullpo_retv(bl);
  6058. WBUFW(buf,0) = 0x132;
  6059. WBUFL(buf,2) = bl->id;
  6060. if( fd ) {
  6061. WFIFOHEAD(fd,packet_len(0x132));
  6062. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6063. WFIFOSET(fd,packet_len(0x132));
  6064. } else {
  6065. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6066. }
  6067. }
  6068. /// Sends a list of items in a shop.
  6069. /// 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)
  6070. /// 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)
  6071. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6072. {
  6073. int i,fd;
  6074. int count;
  6075. struct map_session_data* vsd;
  6076. #if PACKETVER < 20100105
  6077. const int cmd = 0x133;
  6078. const int offset = 8;
  6079. #else
  6080. const int cmd = 0x800;
  6081. const int offset = 12;
  6082. #endif
  6083. #if PACKETVER < 20150226
  6084. const int item_length = 22;
  6085. #else
  6086. const int item_length = 47;
  6087. #endif
  6088. nullpo_retv(sd);
  6089. nullpo_retv(vending);
  6090. nullpo_retv(vsd=map_id2sd(id));
  6091. fd = sd->fd;
  6092. count = vsd->vend_num;
  6093. WFIFOHEAD(fd, offset+count*item_length);
  6094. WFIFOW(fd,0) = cmd;
  6095. WFIFOW(fd,2) = offset+count*item_length;
  6096. WFIFOL(fd,4) = id;
  6097. #if PACKETVER >= 20100105
  6098. WFIFOL(fd,8) = vsd->vender_id;
  6099. #endif
  6100. for( i = 0; i < count; i++ )
  6101. {
  6102. int index = vending[i].index;
  6103. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  6104. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6105. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6106. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6107. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6108. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  6109. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  6110. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  6111. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  6112. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  6113. #if PACKETVER >= 20150226
  6114. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  6115. #endif
  6116. }
  6117. WFIFOSET(fd,WFIFOW(fd,2));
  6118. }
  6119. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6120. /// 0135 <index>.W <amount>.W <result>.B
  6121. /// result:
  6122. /// 0 = success
  6123. /// 1 = not enough zeny
  6124. /// 2 = overweight
  6125. /// 4 = out of stock
  6126. /// 5 = "cannot use an npc shop while in a trade"
  6127. /// 6 = Because the store information was incorrect the item was not purchased.
  6128. /// 7 = No sales information.
  6129. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6130. {
  6131. int fd;
  6132. nullpo_retv(sd);
  6133. fd = sd->fd;
  6134. WFIFOHEAD(fd,packet_len(0x135));
  6135. WFIFOW(fd,0) = 0x135;
  6136. WFIFOW(fd,2) = index+2;
  6137. WFIFOW(fd,4) = amount;
  6138. WFIFOB(fd,6) = fail;
  6139. WFIFOSET(fd,packet_len(0x135));
  6140. }
  6141. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6142. /// 0a28 <Result>.B
  6143. /// result:
  6144. /// 0 = Successed
  6145. /// 1 = Failed
  6146. void clif_openvending_ack(struct map_session_data* sd, int result)
  6147. {
  6148. int fd;
  6149. nullpo_retv(sd);
  6150. fd = sd->fd;
  6151. WFIFOHEAD(fd, 3);
  6152. WFIFOW(fd,0) = 0xa28;
  6153. WFIFOB(fd,2) = result;
  6154. WFIFOSET(fd, 3);
  6155. }
  6156. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6157. /// 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 }*
  6158. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6159. {
  6160. int i,fd;
  6161. int count;
  6162. #if PACKETVER < 20150226
  6163. const int item_length = 22;
  6164. #else
  6165. const int item_length = 47;
  6166. #endif
  6167. nullpo_retv(sd);
  6168. fd = sd->fd;
  6169. count = sd->vend_num;
  6170. WFIFOHEAD(fd, 8+count*item_length);
  6171. WFIFOW(fd,0) = 0x136;
  6172. WFIFOW(fd,2) = 8+count*item_length;
  6173. WFIFOL(fd,4) = id;
  6174. for( i = 0; i < count; i++ ) {
  6175. int index = vending[i].index;
  6176. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  6177. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6178. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6179. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6180. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6181. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  6182. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  6183. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  6184. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  6185. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  6186. #if PACKETVER >= 20150226
  6187. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->status.cart[index]);
  6188. #endif
  6189. }
  6190. WFIFOSET(fd,WFIFOW(fd,2));
  6191. #if PACKETVER >= 20141022
  6192. /// 0 = Successed
  6193. /// 1 = Failed
  6194. clif_openvending_ack(sd, 0);
  6195. #endif
  6196. }
  6197. /// Inform merchant that someone has bought an item.
  6198. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6199. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6200. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6201. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6202. const int cmd = 0x137;
  6203. #else
  6204. const int cmd = 0x9e5;
  6205. #endif
  6206. int fd = sd->fd;
  6207. nullpo_retv(sd);
  6208. WFIFOHEAD(fd,packet_len(cmd));
  6209. WFIFOW(fd,0) = cmd;
  6210. WFIFOW(fd,2) = index+2;
  6211. WFIFOW(fd,4) = amount;
  6212. #if PACKETVER >= 20141016
  6213. WFIFOL(fd,6) = char_id; // GID
  6214. WFIFOL(fd,10) = (int)time(NULL); // Date
  6215. WFIFOL(fd,14) = zeny; // zeny
  6216. #endif
  6217. WFIFOSET(fd,packet_len(cmd));
  6218. }
  6219. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6220. /// 00fa <result>.B
  6221. /// result:
  6222. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6223. /// 1 = MsgStringTable[78]="party name already exists"
  6224. /// 2 = MsgStringTable[79]="already in a party"
  6225. /// 3 = cannot organize parties on this map
  6226. /// ? = nothing
  6227. void clif_party_created(struct map_session_data *sd,int result)
  6228. {
  6229. int fd;
  6230. nullpo_retv(sd);
  6231. fd=sd->fd;
  6232. WFIFOHEAD(fd,packet_len(0xfa));
  6233. WFIFOW(fd,0)=0xfa;
  6234. WFIFOB(fd,2)=result;
  6235. WFIFOSET(fd,packet_len(0xfa));
  6236. }
  6237. /// Adds new member to a party.
  6238. /// 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)
  6239. /// 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)
  6240. /// role:
  6241. /// 0 = leader
  6242. /// 1 = normal
  6243. /// state:
  6244. /// 0 = connected
  6245. /// 1 = disconnected
  6246. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6247. {
  6248. unsigned char buf[81];
  6249. int i;
  6250. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6251. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6252. } else {
  6253. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6254. }
  6255. if (i >= MAX_PARTY) return; //Should never happen...
  6256. sd = p->data[i].sd;
  6257. WBUFW(buf, 0) = 0x1e9;
  6258. WBUFL(buf, 2) = sd->status.account_id;
  6259. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6260. WBUFW(buf,10) = sd->bl.x;
  6261. WBUFW(buf,12) = sd->bl.y;
  6262. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6263. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6264. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6265. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6266. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6267. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6268. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6269. }
  6270. /// Sends party information (ZC_GROUP_LIST).
  6271. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6272. /// role:
  6273. /// 0 = leader
  6274. /// 1 = normal
  6275. /// state:
  6276. /// 0 = connected
  6277. /// 1 = disconnected
  6278. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6279. {
  6280. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6281. struct map_session_data* party_sd = NULL;
  6282. int i, c;
  6283. nullpo_retv(p);
  6284. WBUFW(buf,0) = 0xfb;
  6285. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6286. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6287. {
  6288. struct party_member* m = &p->party.member[i];
  6289. if(!m->account_id) continue;
  6290. if(party_sd == NULL) party_sd = p->data[i].sd;
  6291. WBUFL(buf,28+c*46) = m->account_id;
  6292. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6293. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6294. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6295. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6296. c++;
  6297. }
  6298. WBUFW(buf,2) = 28+c*46;
  6299. if(sd) { // send only to self
  6300. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6301. } else if (party_sd) { // send to whole party
  6302. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6303. }
  6304. }
  6305. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6306. /// 02c9 <flag>.B
  6307. /// flag:
  6308. /// 0 = allow party invites
  6309. /// 1 = auto-deny party invites
  6310. void clif_partyinvitationstate(struct map_session_data* sd)
  6311. {
  6312. int fd;
  6313. nullpo_retv(sd);
  6314. fd = sd->fd;
  6315. WFIFOHEAD(fd, packet_len(0x2c9));
  6316. WFIFOW(fd, 0) = 0x2c9;
  6317. WFIFOB(fd, 2) = 0; // not implemented
  6318. WFIFOSET(fd, packet_len(0x2c9));
  6319. }
  6320. /// Party invitation request.
  6321. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6322. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6323. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6324. {
  6325. #if PACKETVER < 20070821
  6326. const int cmd = 0xfe;
  6327. #else
  6328. const int cmd = 0x2c6;
  6329. #endif
  6330. int fd;
  6331. struct party_data *p;
  6332. nullpo_retv(sd);
  6333. nullpo_retv(tsd);
  6334. fd=tsd->fd;
  6335. if( (p=party_search(sd->status.party_id))==NULL )
  6336. return;
  6337. WFIFOHEAD(fd,packet_len(cmd));
  6338. WFIFOW(fd,0)=cmd;
  6339. WFIFOL(fd,2)=sd->status.party_id;
  6340. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6341. WFIFOSET(fd,packet_len(cmd));
  6342. }
  6343. /// Party invite result.
  6344. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6345. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6346. /// result=0 : char is already in a party -> MsgStringTable[80]
  6347. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6348. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6349. /// result=3 : party is full -> MsgStringTable[83]
  6350. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6351. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6352. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6353. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  6354. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  6355. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  6356. {
  6357. int fd;
  6358. nullpo_retv(sd);
  6359. fd=sd->fd;
  6360. #if PACKETVER < 20070904
  6361. if( result == 7 ) {
  6362. clif_displaymessage(fd, msg_txt(sd,3));
  6363. return;
  6364. }
  6365. #endif
  6366. #if PACKETVER < 20070821
  6367. WFIFOHEAD(fd,packet_len(0xfd));
  6368. WFIFOW(fd,0) = 0xfd;
  6369. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6370. WFIFOB(fd,26) = result;
  6371. WFIFOSET(fd,packet_len(0xfd));
  6372. #else
  6373. WFIFOHEAD(fd,packet_len(0x2c5));
  6374. WFIFOW(fd,0) = 0x2c5;
  6375. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6376. WFIFOL(fd,26) = result;
  6377. WFIFOSET(fd,packet_len(0x2c5));
  6378. #endif
  6379. }
  6380. /// Updates party settings.
  6381. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6382. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6383. /// exp option:
  6384. /// 0 = exp sharing disabled
  6385. /// 1 = exp sharing enabled
  6386. /// 2 = cannot change exp sharing
  6387. ///
  6388. /// flag:
  6389. /// 0 = send to party
  6390. /// 1 = send to sd
  6391. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6392. {
  6393. unsigned char buf[16];
  6394. #if PACKETVER < 20090603
  6395. const int cmd = 0x101;
  6396. #else
  6397. const int cmd = 0x7d8;
  6398. #endif
  6399. nullpo_retv(p);
  6400. if(!sd && flag==0){
  6401. int i;
  6402. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6403. if (i < MAX_PARTY)
  6404. sd = p->data[i].sd;
  6405. }
  6406. if(!sd) return;
  6407. WBUFW(buf,0)=cmd;
  6408. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6409. #if PACKETVER >= 20090603
  6410. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6411. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6412. #endif
  6413. if(flag==0)
  6414. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6415. else
  6416. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6417. }
  6418. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6419. /// result:
  6420. /// 0 = leave
  6421. /// 1 = expel
  6422. /// 2 = cannot leave party on this map
  6423. /// 3 = cannot expel from party on this map
  6424. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6425. {
  6426. unsigned char buf[64];
  6427. nullpo_retv(p);
  6428. if(!sd && (flag&0xf0)==0)
  6429. {
  6430. int i;
  6431. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6432. if (i < MAX_PARTY)
  6433. sd = p->data[i].sd;
  6434. }
  6435. if(!sd) return;
  6436. WBUFW(buf,0)=0x105;
  6437. WBUFL(buf,2)=account_id;
  6438. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6439. WBUFB(buf,30)=flag&0x0f;
  6440. if((flag&0xf0)==0)
  6441. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6442. else
  6443. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6444. }
  6445. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6446. /// 0109 <packet len>.W <account id>.L <message>.?B
  6447. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6448. {
  6449. struct map_session_data *sd;
  6450. int i;
  6451. nullpo_retv(p);
  6452. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6453. if(i < MAX_PARTY){
  6454. unsigned char buf[1024];
  6455. if( len > sizeof(buf)-8 )
  6456. {
  6457. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6458. len = sizeof(buf)-8;
  6459. }
  6460. sd = p->data[i].sd;
  6461. WBUFW(buf,0)=0x109;
  6462. WBUFW(buf,2)=len+8;
  6463. WBUFL(buf,4)=account_id;
  6464. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6465. clif_send(buf,len+8,&sd->bl,PARTY);
  6466. }
  6467. }
  6468. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6469. /// 0107 <account id>.L <x>.W <y>.W
  6470. void clif_party_xy(struct map_session_data *sd)
  6471. {
  6472. unsigned char buf[16];
  6473. nullpo_retv(sd);
  6474. WBUFW(buf,0)=0x107;
  6475. WBUFL(buf,2)=sd->status.account_id;
  6476. WBUFW(buf,6)=sd->bl.x;
  6477. WBUFW(buf,8)=sd->bl.y;
  6478. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6479. }
  6480. /*==========================================
  6481. * Sends x/y dot to a single fd. [Skotlex]
  6482. *------------------------------------------*/
  6483. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6484. {
  6485. WFIFOHEAD(fd,packet_len(0x107));
  6486. WFIFOW(fd,0)=0x107;
  6487. WFIFOL(fd,2)=sd->status.account_id;
  6488. WFIFOW(fd,6)=sd->bl.x;
  6489. WFIFOW(fd,8)=sd->bl.y;
  6490. WFIFOSET(fd,packet_len(0x107));
  6491. }
  6492. /// Updates HP bar of a party member.
  6493. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6494. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6495. void clif_party_hp(struct map_session_data *sd)
  6496. {
  6497. unsigned char buf[16];
  6498. #if PACKETVER < 20100126
  6499. const int cmd = 0x106;
  6500. #else
  6501. const int cmd = 0x80e;
  6502. #endif
  6503. nullpo_retv(sd);
  6504. WBUFW(buf,0)=cmd;
  6505. WBUFL(buf,2)=sd->status.account_id;
  6506. #if PACKETVER < 20100126
  6507. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6508. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6509. WBUFW(buf,8) = 100;
  6510. } else {
  6511. WBUFW(buf,6) = sd->battle_status.hp;
  6512. WBUFW(buf,8) = sd->battle_status.max_hp;
  6513. }
  6514. #else
  6515. WBUFL(buf,6) = sd->battle_status.hp;
  6516. WBUFL(buf,10) = sd->battle_status.max_hp;
  6517. #endif
  6518. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6519. }
  6520. /*==========================================
  6521. * Sends HP bar to a single fd. [Skotlex]
  6522. *------------------------------------------*/
  6523. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6524. {
  6525. #if PACKETVER < 20100126
  6526. const int cmd = 0x106;
  6527. #else
  6528. const int cmd = 0x80e;
  6529. #endif
  6530. WFIFOHEAD(fd,packet_len(cmd));
  6531. WFIFOW(fd,0) = cmd;
  6532. WFIFOL(fd,2) = id;
  6533. #if PACKETVER < 20100126
  6534. if( maxhp > INT16_MAX )
  6535. {// To correctly display the %hp bar. [Skotlex]
  6536. WFIFOW(fd,6) = hp/(maxhp/100);
  6537. WFIFOW(fd,8) = 100;
  6538. } else {
  6539. WFIFOW(fd,6) = hp;
  6540. WFIFOW(fd,8) = maxhp;
  6541. }
  6542. #else
  6543. WFIFOL(fd,6) = hp;
  6544. WFIFOL(fd,10) = maxhp;
  6545. #endif
  6546. WFIFOSET(fd, packet_len(cmd));
  6547. }
  6548. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6549. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6550. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6551. {
  6552. int fd;
  6553. nullpo_retv(sd);
  6554. nullpo_retv(bl);
  6555. fd=sd->fd;
  6556. WFIFOHEAD(fd,packet_len(0x139));
  6557. WFIFOW(fd, 0)=0x139;
  6558. WFIFOL(fd, 2)=bl->id;
  6559. WFIFOW(fd, 6)=bl->x;
  6560. WFIFOW(fd, 8)=bl->y;
  6561. WFIFOW(fd,10)=sd->bl.x;
  6562. WFIFOW(fd,12)=sd->bl.y;
  6563. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6564. WFIFOSET(fd,packet_len(0x139));
  6565. }
  6566. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6567. /// 018f <result>.W <name id>.W
  6568. /// result:
  6569. /// 0 = success
  6570. /// 1 = failure
  6571. /// 2 = success (alchemist)
  6572. /// 3 = failure (alchemist)
  6573. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6574. {
  6575. int view,fd;
  6576. nullpo_retv(sd);
  6577. fd = sd->fd;
  6578. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6579. WFIFOHEAD(fd,packet_len(0x18f));
  6580. WFIFOW(fd, 0)=0x18f;
  6581. WFIFOW(fd, 2)=flag;
  6582. if((view = itemdb_viewid(nameid)) > 0)
  6583. WFIFOW(fd, 4)=view;
  6584. else
  6585. WFIFOW(fd, 4)=nameid;
  6586. WFIFOSET(fd,packet_len(0x18f));
  6587. }
  6588. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6589. /// 019e
  6590. void clif_catch_process(struct map_session_data *sd)
  6591. {
  6592. int fd;
  6593. nullpo_retv(sd);
  6594. fd=sd->fd;
  6595. WFIFOHEAD(fd,packet_len(0x19e));
  6596. WFIFOW(fd,0)=0x19e;
  6597. WFIFOSET(fd,packet_len(0x19e));
  6598. }
  6599. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6600. /// 01a0 <result>.B
  6601. /// 0 = failure
  6602. /// 1 = success
  6603. void clif_pet_roulette(struct map_session_data *sd,int data)
  6604. {
  6605. int fd;
  6606. nullpo_retv(sd);
  6607. fd=sd->fd;
  6608. WFIFOHEAD(fd,packet_len(0x1a0));
  6609. WFIFOW(fd,0)=0x1a0;
  6610. WFIFOB(fd,2)=data;
  6611. WFIFOSET(fd,packet_len(0x1a0));
  6612. }
  6613. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6614. /// 01a6 <packet len>.W { <index>.W }*
  6615. void clif_sendegg(struct map_session_data *sd)
  6616. {
  6617. int i,n=0,fd;
  6618. nullpo_retv(sd);
  6619. fd=sd->fd;
  6620. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6621. clif_displaymessage(fd, msg_txt(sd,666));
  6622. return;
  6623. }
  6624. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6625. WFIFOW(fd,0)=0x1a6;
  6626. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6627. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6628. sd->inventory_data[i]->type!=IT_PETEGG ||
  6629. sd->status.inventory[i].amount<=0)
  6630. continue;
  6631. WFIFOW(fd,n*2+4)=i+2;
  6632. n++;
  6633. }
  6634. WFIFOW(fd,2)=4+n*2;
  6635. WFIFOSET(fd,WFIFOW(fd,2));
  6636. sd->menuskill_id = SA_TAMINGMONSTER;
  6637. sd->menuskill_val = -1;
  6638. }
  6639. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6640. /// 01a4 <type>.B <id>.L <data>.L
  6641. /// type:
  6642. /// 0 = pre-init (data = 0)
  6643. /// 1 = intimacy (data = 0~4)
  6644. /// 2 = hunger (data = 0~4)
  6645. /// 3 = accessory
  6646. /// 4 = performance (data = 1~3: normal, 4: special)
  6647. /// 5 = hairstyle
  6648. ///
  6649. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6650. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6651. {
  6652. uint8 buf[16];
  6653. nullpo_retv(pd);
  6654. WBUFW(buf,0) = 0x1a4;
  6655. WBUFB(buf,2) = type;
  6656. WBUFL(buf,3) = pd->bl.id;
  6657. WBUFL(buf,7) = param;
  6658. if (sd)
  6659. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6660. else
  6661. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6662. }
  6663. /// Pet's base data (ZC_PROPERTY_PET).
  6664. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6665. void clif_send_petstatus(struct map_session_data *sd)
  6666. {
  6667. int fd;
  6668. struct s_pet *pet;
  6669. nullpo_retv(sd);
  6670. nullpo_retv(sd->pd);
  6671. fd=sd->fd;
  6672. pet = &sd->pd->pet;
  6673. WFIFOHEAD(fd,packet_len(0x1a2));
  6674. WFIFOW(fd,0)=0x1a2;
  6675. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6676. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6677. WFIFOW(fd,27)=pet->level;
  6678. WFIFOW(fd,29)=pet->hungry;
  6679. WFIFOW(fd,31)=pet->intimate;
  6680. WFIFOW(fd,33)=pet->equip;
  6681. #if PACKETVER >= 20081126
  6682. WFIFOW(fd,35)=pet->class_;
  6683. #endif
  6684. WFIFOSET(fd,packet_len(0x1a2));
  6685. }
  6686. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6687. /// 01aa <id>.L <data>.L
  6688. /// data:
  6689. /// @see CZ_PET_ACT.
  6690. void clif_pet_emotion(struct pet_data *pd,int param)
  6691. {
  6692. unsigned char buf[16];
  6693. nullpo_retv(pd);
  6694. memset(buf,0,packet_len(0x1aa));
  6695. WBUFW(buf,0)=0x1aa;
  6696. WBUFL(buf,2)=pd->bl.id;
  6697. if(param >= 100 && pd->petDB->talk_convert_class) {
  6698. if(pd->petDB->talk_convert_class < 0)
  6699. return;
  6700. else if(pd->petDB->talk_convert_class > 0) {
  6701. // replace mob_id component of talk/act data
  6702. param -= (pd->pet.class_ - 100)*100;
  6703. param += (pd->petDB->talk_convert_class - 100)*100;
  6704. }
  6705. }
  6706. WBUFL(buf,6)=param;
  6707. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6708. }
  6709. /// Result of request to feed a pet (ZC_FEED_PET).
  6710. /// 01a3 <result>.B <name id>.W
  6711. /// result:
  6712. /// 0 = failure
  6713. /// 1 = success
  6714. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6715. {
  6716. int fd;
  6717. nullpo_retv(sd);
  6718. fd=sd->fd;
  6719. WFIFOHEAD(fd,packet_len(0x1a3));
  6720. WFIFOW(fd,0)=0x1a3;
  6721. WFIFOB(fd,2)=fail;
  6722. WFIFOW(fd,3)=foodid;
  6723. WFIFOSET(fd,packet_len(0x1a3));
  6724. }
  6725. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6726. /// 01cd { <skill id>.L }*7
  6727. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6728. {
  6729. int fd;
  6730. nullpo_retv(sd);
  6731. fd=sd->fd;
  6732. WFIFOHEAD(fd,packet_len(0x1cd));
  6733. WFIFOW(fd, 0)=0x1cd;
  6734. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6735. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6736. else
  6737. WFIFOL(fd,2)= 0x00000000;
  6738. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6739. WFIFOL(fd,6)= MG_COLDBOLT;
  6740. else
  6741. WFIFOL(fd,6)= 0x00000000;
  6742. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6743. WFIFOL(fd,10)= MG_FIREBOLT;
  6744. else
  6745. WFIFOL(fd,10)= 0x00000000;
  6746. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6747. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6748. else
  6749. WFIFOL(fd,14)= 0x00000000;
  6750. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6751. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6752. else
  6753. WFIFOL(fd,18)= 0x00000000;
  6754. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6755. WFIFOL(fd,22)= MG_FIREBALL;
  6756. else
  6757. WFIFOL(fd,22)= 0x00000000;
  6758. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6759. WFIFOL(fd,26)= MG_FROSTDIVER;
  6760. else
  6761. WFIFOL(fd,26)= 0x00000000;
  6762. WFIFOSET(fd,packet_len(0x1cd));
  6763. sd->menuskill_id = SA_AUTOSPELL;
  6764. sd->menuskill_val = skill_lv;
  6765. }
  6766. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6767. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6768. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6769. {
  6770. unsigned char buf[56];
  6771. nullpo_retv(src);
  6772. memset(buf,0,packet_len(0x1cf));
  6773. WBUFW(buf,0) = 0x1cf;
  6774. WBUFL(buf,2) = src->id;
  6775. if( src->type == BL_MER )
  6776. {
  6777. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6778. if( md && md->master && md->devotion_flag )
  6779. WBUFL(buf,6) = md->master->bl.id;
  6780. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6781. }
  6782. else
  6783. {
  6784. int i;
  6785. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6786. if( sd == NULL )
  6787. return;
  6788. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6789. WBUFL(buf,6+4*i) = sd->devotion[i];
  6790. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6791. }
  6792. if( tsd )
  6793. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6794. else
  6795. clif_send(buf, packet_len(0x1cf), src, AREA);
  6796. }
  6797. /*==========================================
  6798. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6799. * Notifies clients in an area of an object's spirits.
  6800. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6801. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6802. *------------------------------------------*/
  6803. void clif_spiritball(struct block_list *bl) {
  6804. unsigned char buf[16];
  6805. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6806. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6807. nullpo_retv(bl);
  6808. WBUFW(buf, 0) = 0x1d0;
  6809. WBUFL(buf, 2) = bl->id;
  6810. WBUFW(buf, 6) = 0; //init to 0
  6811. switch(bl->type){
  6812. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6813. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6814. }
  6815. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6816. }
  6817. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6818. /// 01d2 <account id>.L <delay>.L
  6819. void clif_combo_delay(struct block_list *bl,int wait)
  6820. {
  6821. unsigned char buf[32];
  6822. nullpo_retv(bl);
  6823. WBUFW(buf,0)=0x1d2;
  6824. WBUFL(buf,2)=bl->id;
  6825. WBUFL(buf,6)=wait;
  6826. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6827. }
  6828. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6829. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6830. /// flag:
  6831. /// 0 = inactive
  6832. /// 1 = active
  6833. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6834. {
  6835. unsigned char buf[32];
  6836. nullpo_retv(src);
  6837. WBUFW(buf,0)=0x1d1;
  6838. WBUFL(buf,2)=src->id;
  6839. WBUFL(buf,6)=dst_id;
  6840. WBUFL(buf,10)=active;
  6841. clif_send(buf,packet_len(0x1d1),src,AREA);
  6842. }
  6843. /// MVP effect (ZC_MVP).
  6844. /// 010c <account id>.L
  6845. void clif_mvp_effect(struct map_session_data *sd)
  6846. {
  6847. unsigned char buf[16];
  6848. nullpo_retv(sd);
  6849. WBUFW(buf,0)=0x10c;
  6850. WBUFL(buf,2)=sd->bl.id;
  6851. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6852. }
  6853. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6854. /// 010a <name id>.W
  6855. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6856. {
  6857. int view,fd;
  6858. nullpo_retv(sd);
  6859. fd=sd->fd;
  6860. WFIFOHEAD(fd,packet_len(0x10a));
  6861. WFIFOW(fd,0)=0x10a;
  6862. if((view = itemdb_viewid(nameid)) > 0)
  6863. WFIFOW(fd,2)=view;
  6864. else
  6865. WFIFOW(fd,2)=nameid;
  6866. WFIFOSET(fd,packet_len(0x10a));
  6867. }
  6868. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6869. /// 010b <exp>.L
  6870. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6871. {
  6872. int fd;
  6873. nullpo_retv(sd);
  6874. fd=sd->fd;
  6875. WFIFOHEAD(fd,packet_len(0x10b));
  6876. WFIFOW(fd,0)=0x10b;
  6877. WFIFOL(fd,2)=min(exp,(unsigned int)INT32_MAX);
  6878. WFIFOSET(fd,packet_len(0x10b));
  6879. }
  6880. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6881. /// 010d
  6882. ///
  6883. /// "You are the MVP, but cannot obtain the reward because
  6884. /// you are overweight."
  6885. void clif_mvp_noitem(struct map_session_data* sd)
  6886. {
  6887. int fd = sd->fd;
  6888. WFIFOHEAD(fd,packet_len(0x10d));
  6889. WFIFOW(fd,0) = 0x10d;
  6890. WFIFOSET(fd,packet_len(0x10d));
  6891. }
  6892. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6893. /// 0167 <result>.B
  6894. /// result:
  6895. /// 0 = "Guild has been created."
  6896. /// 1 = "You are already in a Guild."
  6897. /// 2 = "That Guild Name already exists."
  6898. /// 3 = "You need the neccessary item to create a Guild."
  6899. void clif_guild_created(struct map_session_data *sd,int flag)
  6900. {
  6901. int fd;
  6902. nullpo_retv(sd);
  6903. fd=sd->fd;
  6904. WFIFOHEAD(fd,packet_len(0x167));
  6905. WFIFOW(fd,0)=0x167;
  6906. WFIFOB(fd,2)=flag;
  6907. WFIFOSET(fd,packet_len(0x167));
  6908. }
  6909. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6910. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6911. /// mode:
  6912. /// &0x01 = allow invite
  6913. /// &0x10 = allow expel
  6914. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6915. {
  6916. int ps,fd;
  6917. nullpo_retv(sd);
  6918. nullpo_retv(g);
  6919. fd=sd->fd;
  6920. ps=guild_getposition(g,sd);
  6921. WFIFOHEAD(fd,packet_len(0x16c));
  6922. WFIFOW(fd,0)=0x16c;
  6923. WFIFOL(fd,2)=g->guild_id;
  6924. WFIFOL(fd,6)=g->emblem_id;
  6925. WFIFOL(fd,10)=g->position[ps].mode;
  6926. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6927. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6928. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6929. WFIFOSET(fd,packet_len(0x16c));
  6930. }
  6931. /// Guild member login notice.
  6932. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6933. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6934. /// status:
  6935. /// 0 = offline
  6936. /// 1 = online
  6937. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6938. {
  6939. unsigned char buf[64];
  6940. struct map_session_data* sd;
  6941. nullpo_retv(g);
  6942. WBUFW(buf, 0)=0x1f2;
  6943. WBUFL(buf, 2)=g->member[idx].account_id;
  6944. WBUFL(buf, 6)=g->member[idx].char_id;
  6945. WBUFL(buf,10)=flag;
  6946. if( ( sd = g->member[idx].sd ) != NULL )
  6947. {
  6948. WBUFW(buf,14) = sd->status.sex;
  6949. WBUFW(buf,16) = sd->status.hair;
  6950. WBUFW(buf,18) = sd->status.hair_color;
  6951. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6952. }
  6953. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6954. {
  6955. WBUFW(buf,14) = 0;
  6956. WBUFW(buf,16) = 0;
  6957. WBUFW(buf,18) = 0;
  6958. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6959. }
  6960. }
  6961. // Function `clif_guild_memberlogin_notice` sends info about
  6962. // logins and logouts of a guild member to the rest members.
  6963. // But at the 1st time (after a player login or map changing)
  6964. // the client won't show the message.
  6965. // So I suggest use this function for sending "first-time-info"
  6966. // to some player on entering the game or changing location.
  6967. // At next time the client would always show the message.
  6968. // The function sends all the statuses in the single packet
  6969. // to economize traffic. [LuzZza]
  6970. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6971. {
  6972. struct guild *g;
  6973. unsigned char buf[14*128];
  6974. int i, count=0, p_len;
  6975. nullpo_retv(sd);
  6976. p_len = packet_len(0x16d);
  6977. if(!(g = sd->guild))
  6978. return;
  6979. for(i=0; i<g->max_member; i++) {
  6980. if(g->member[i].account_id > 0 &&
  6981. g->member[i].account_id != sd->status.account_id) {
  6982. WBUFW(buf,count*p_len) = 0x16d;
  6983. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6984. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6985. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6986. count++;
  6987. }
  6988. }
  6989. clif_send(buf, p_len*count, &sd->bl, SELF);
  6990. }
  6991. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6992. /// 014e <menu flag>.L
  6993. /// menu flag:
  6994. /// 0x00 = Basic Info (always on)
  6995. /// &0x01 = Member manager
  6996. /// &0x02 = Positions
  6997. /// &0x04 = Skills
  6998. /// &0x10 = Expulsion list
  6999. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7000. /// &0x80 = Notice
  7001. void clif_guild_masterormember(struct map_session_data *sd)
  7002. {
  7003. int fd;
  7004. nullpo_retv(sd);
  7005. fd=sd->fd;
  7006. WFIFOHEAD(fd,packet_len(0x14e));
  7007. WFIFOW(fd,0) = 0x14e;
  7008. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7009. WFIFOSET(fd,packet_len(0x14e));
  7010. }
  7011. /// Guild basic information (Territories [Valaris])
  7012. /// 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)
  7013. /// 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)
  7014. void clif_guild_basicinfo(struct map_session_data *sd) {
  7015. int fd;
  7016. struct guild *g;
  7017. nullpo_retv(sd);
  7018. fd = sd->fd;
  7019. if( (g = sd->guild) == NULL )
  7020. return;
  7021. WFIFOHEAD(fd,packet_len(0x1b6));
  7022. WFIFOW(fd, 0)=0x1b6;//0x150;
  7023. WFIFOL(fd, 2)=g->guild_id;
  7024. WFIFOL(fd, 6)=g->guild_lv;
  7025. WFIFOL(fd,10)=g->connect_member;
  7026. WFIFOL(fd,14)=g->max_member;
  7027. WFIFOL(fd,18)=g->average_lv;
  7028. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7029. WFIFOL(fd,26)=g->next_exp;
  7030. WFIFOL(fd,30)=0; // Tax Points
  7031. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7032. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7033. WFIFOL(fd,42)=g->emblem_id;
  7034. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  7035. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  7036. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7037. WFIFOL(fd,110) = 0; // zeny
  7038. WFIFOSET(fd,packet_len(0x1b6));
  7039. }
  7040. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7041. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7042. void clif_guild_allianceinfo(struct map_session_data *sd)
  7043. {
  7044. int fd,i,c;
  7045. struct guild *g;
  7046. nullpo_retv(sd);
  7047. if( (g = sd->guild) == NULL )
  7048. return;
  7049. fd = sd->fd;
  7050. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7051. WFIFOW(fd, 0)=0x14c;
  7052. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7053. struct guild_alliance *a=&g->alliance[i];
  7054. if(a->guild_id>0){
  7055. WFIFOL(fd,c*32+4)=a->opposition;
  7056. WFIFOL(fd,c*32+8)=a->guild_id;
  7057. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  7058. c++;
  7059. }
  7060. }
  7061. WFIFOW(fd, 2)=c*32+4;
  7062. WFIFOSET(fd,WFIFOW(fd,2));
  7063. }
  7064. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  7065. /// 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 }*
  7066. /// state:
  7067. /// 0 = offline
  7068. /// 1 = online
  7069. /// memo:
  7070. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7071. void clif_guild_memberlist(struct map_session_data *sd)
  7072. {
  7073. int fd;
  7074. int i,c;
  7075. struct guild *g;
  7076. nullpo_retv(sd);
  7077. if( (fd = sd->fd) == 0 )
  7078. return;
  7079. if( (g = sd->guild) == NULL )
  7080. return;
  7081. WFIFOHEAD(fd, g->max_member * 104 + 4);
  7082. WFIFOW(fd, 0)=0x154;
  7083. for(i=0,c=0;i<g->max_member;i++){
  7084. struct guild_member *m=&g->member[i];
  7085. if(m->account_id==0)
  7086. continue;
  7087. WFIFOL(fd,c*104+ 4)=m->account_id;
  7088. WFIFOL(fd,c*104+ 8)=m->char_id;
  7089. WFIFOW(fd,c*104+12)=m->hair;
  7090. WFIFOW(fd,c*104+14)=m->hair_color;
  7091. WFIFOW(fd,c*104+16)=m->gender;
  7092. WFIFOW(fd,c*104+18)=m->class_;
  7093. WFIFOW(fd,c*104+20)=m->lv;
  7094. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7095. WFIFOL(fd,c*104+26)=m->online;
  7096. WFIFOL(fd,c*104+30)=m->position;
  7097. 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.
  7098. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  7099. c++;
  7100. }
  7101. WFIFOW(fd, 2)=c*104+4;
  7102. WFIFOSET(fd,WFIFOW(fd,2));
  7103. }
  7104. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7105. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7106. void clif_guild_positionnamelist(struct map_session_data *sd)
  7107. {
  7108. int i,fd;
  7109. struct guild *g;
  7110. nullpo_retv(sd);
  7111. if( (g = sd->guild) == NULL )
  7112. return;
  7113. fd = sd->fd;
  7114. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7115. WFIFOW(fd, 0)=0x166;
  7116. for(i=0;i<MAX_GUILDPOSITION;i++){
  7117. WFIFOL(fd,i*28+4)=i;
  7118. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7119. }
  7120. WFIFOW(fd,2)=i*28+4;
  7121. WFIFOSET(fd,WFIFOW(fd,2));
  7122. }
  7123. /// Guild position information (ZC_POSITION_INFO).
  7124. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7125. /// mode:
  7126. /// &0x01 = allow invite
  7127. /// &0x10 = allow expel
  7128. /// ranking:
  7129. /// TODO
  7130. void clif_guild_positioninfolist(struct map_session_data *sd)
  7131. {
  7132. int i,fd;
  7133. struct guild *g;
  7134. nullpo_retv(sd);
  7135. if( (g = sd->guild) == NULL )
  7136. return;
  7137. fd = sd->fd;
  7138. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7139. WFIFOW(fd, 0)=0x160;
  7140. for(i=0;i<MAX_GUILDPOSITION;i++){
  7141. struct guild_position *p=&g->position[i];
  7142. WFIFOL(fd,i*16+ 4)=i;
  7143. WFIFOL(fd,i*16+ 8)=p->mode;
  7144. WFIFOL(fd,i*16+12)=i;
  7145. WFIFOL(fd,i*16+16)=p->exp_mode;
  7146. }
  7147. WFIFOW(fd, 2)=i*16+4;
  7148. WFIFOSET(fd,WFIFOW(fd,2));
  7149. }
  7150. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7151. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7152. /// mode:
  7153. /// &0x01 = allow invite
  7154. /// &0x10 = allow expel
  7155. /// ranking:
  7156. /// TODO
  7157. void clif_guild_positionchanged(struct guild *g,int idx)
  7158. {
  7159. // FIXME: This packet is intended to update the clients after a
  7160. // commit of position info changes, not sending one packet per
  7161. // position.
  7162. struct map_session_data *sd;
  7163. unsigned char buf[128];
  7164. nullpo_retv(g);
  7165. WBUFW(buf, 0)=0x174;
  7166. WBUFW(buf, 2)=44; // packet len
  7167. // GUILD_REG_POSITION_INFO{
  7168. WBUFL(buf, 4)=idx;
  7169. WBUFL(buf, 8)=g->position[idx].mode;
  7170. WBUFL(buf,12)=idx;
  7171. WBUFL(buf,16)=g->position[idx].exp_mode;
  7172. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  7173. // }*
  7174. if( (sd=guild_getavailablesd(g))!=NULL )
  7175. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7176. }
  7177. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7178. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7179. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7180. {
  7181. // FIXME: This packet is intended to update the clients after a
  7182. // commit of member position assignment changes, not sending one
  7183. // packet per position.
  7184. struct map_session_data *sd;
  7185. unsigned char buf[64];
  7186. nullpo_retv(g);
  7187. WBUFW(buf, 0)=0x156;
  7188. WBUFW(buf, 2)=16; // packet len
  7189. // MEMBER_POSITION_INFO{
  7190. WBUFL(buf, 4)=g->member[idx].account_id;
  7191. WBUFL(buf, 8)=g->member[idx].char_id;
  7192. WBUFL(buf,12)=g->member[idx].position;
  7193. // }*
  7194. if( (sd=guild_getavailablesd(g))!=NULL )
  7195. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7196. }
  7197. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7198. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7199. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7200. {
  7201. int fd;
  7202. nullpo_retv(sd);
  7203. nullpo_retv(g);
  7204. fd = sd->fd;
  7205. if( g->emblem_len <= 0 )
  7206. return;
  7207. WFIFOHEAD(fd,g->emblem_len+12);
  7208. WFIFOW(fd,0)=0x152;
  7209. WFIFOW(fd,2)=g->emblem_len+12;
  7210. WFIFOL(fd,4)=g->guild_id;
  7211. WFIFOL(fd,8)=g->emblem_id;
  7212. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7213. WFIFOSET(fd,WFIFOW(fd,2));
  7214. }
  7215. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7216. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7217. void clif_guild_emblem_area(struct block_list* bl)
  7218. {
  7219. uint8 buf[12];
  7220. nullpo_retv(bl);
  7221. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7222. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7223. WBUFW(buf,0) = 0x1b4;
  7224. WBUFL(buf,2) = bl->id;
  7225. WBUFL(buf,6) = status_get_guild_id(bl);
  7226. WBUFW(buf,10) = status_get_emblem_id(bl);
  7227. clif_send(buf, 12, bl, AREA_WOS);
  7228. }
  7229. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7230. /// 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 }*
  7231. void clif_guild_skillinfo(struct map_session_data* sd)
  7232. {
  7233. int fd;
  7234. struct guild* g;
  7235. int i,c;
  7236. nullpo_retv(sd);
  7237. if( (g = sd->guild) == NULL )
  7238. return;
  7239. fd = sd->fd;
  7240. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7241. WFIFOW(fd,0) = 0x0162;
  7242. WFIFOW(fd,4) = g->skill_point;
  7243. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7244. {
  7245. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7246. {
  7247. int id = g->skill[i].id;
  7248. int p = 6 + c*37;
  7249. WFIFOW(fd,p+0) = id;
  7250. WFIFOL(fd,p+2) = skill_get_inf(id);
  7251. WFIFOW(fd,p+6) = g->skill[i].lv;
  7252. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7253. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7254. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7255. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7256. c++;
  7257. }
  7258. }
  7259. WFIFOW(fd,2) = 6 + c*37;
  7260. WFIFOSET(fd,WFIFOW(fd,2));
  7261. }
  7262. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7263. /// 016f <subject>.60B <notice>.120B
  7264. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  7265. {
  7266. int fd;
  7267. nullpo_retv(sd);
  7268. nullpo_retv(g);
  7269. fd = sd->fd;
  7270. if ( !session_isActive(fd) )
  7271. return;
  7272. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7273. return;
  7274. WFIFOHEAD(fd,packet_len(0x16f));
  7275. WFIFOW(fd,0) = 0x16f;
  7276. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7277. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7278. WFIFOSET(fd,packet_len(0x16f));
  7279. }
  7280. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7281. /// 016a <guild id>.L <guild name>.24B
  7282. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7283. {
  7284. int fd;
  7285. nullpo_retv(sd);
  7286. nullpo_retv(g);
  7287. fd=sd->fd;
  7288. WFIFOHEAD(fd,packet_len(0x16a));
  7289. WFIFOW(fd,0)=0x16a;
  7290. WFIFOL(fd,2)=g->guild_id;
  7291. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  7292. WFIFOSET(fd,packet_len(0x16a));
  7293. }
  7294. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7295. /// 0169 <answer>.B
  7296. /// answer:
  7297. /// 0 = Already in guild.
  7298. /// 1 = Offer rejected.
  7299. /// 2 = Offer accepted.
  7300. /// 3 = Guild full.
  7301. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7302. {
  7303. int fd;
  7304. nullpo_retv(sd);
  7305. fd=sd->fd;
  7306. WFIFOHEAD(fd,packet_len(0x169));
  7307. WFIFOW(fd,0)=0x169;
  7308. WFIFOB(fd,2)=flag;
  7309. WFIFOSET(fd,packet_len(0x169));
  7310. }
  7311. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7312. /// 015a <char name>.24B <reason>.40B
  7313. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7314. {
  7315. unsigned char buf[128];
  7316. nullpo_retv(sd);
  7317. WBUFW(buf, 0)=0x15a;
  7318. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  7319. memcpy(WBUFP(buf,26),mes,40);
  7320. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7321. }
  7322. /// Notifies clients of a guild of an expelled member.
  7323. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7324. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7325. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7326. {
  7327. unsigned char buf[128];
  7328. #if PACKETVER < 20100803
  7329. const unsigned short cmd = 0x15c;
  7330. #else
  7331. const unsigned short cmd = 0x839;
  7332. #endif
  7333. nullpo_retv(sd);
  7334. WBUFW(buf,0) = cmd;
  7335. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7336. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7337. #if PACKETVER < 20100803
  7338. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7339. #endif
  7340. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7341. }
  7342. /// Guild expulsion list (ZC_BAN_LIST).
  7343. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7344. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7345. void clif_guild_expulsionlist(struct map_session_data* sd)
  7346. {
  7347. #if PACKETVER < 20100803
  7348. const int offset = NAME_LENGTH*2+40;
  7349. #else
  7350. const int offset = NAME_LENGTH+40;
  7351. #endif
  7352. int fd, i, c = 0;
  7353. struct guild* g;
  7354. nullpo_retv(sd);
  7355. if( (g = sd->guild) == NULL )
  7356. return;
  7357. fd = sd->fd;
  7358. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7359. WFIFOW(fd,0) = 0x163;
  7360. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7361. {
  7362. struct guild_expulsion* e = &g->expulsion[i];
  7363. if( e->account_id > 0 )
  7364. {
  7365. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7366. #if PACKETVER < 20100803
  7367. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7368. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7369. #else
  7370. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7371. #endif
  7372. c++;
  7373. }
  7374. }
  7375. WFIFOW(fd,2) = 4 + c*offset;
  7376. WFIFOSET(fd,WFIFOW(fd,2));
  7377. }
  7378. /// Guild chat message (ZC_GUILD_CHAT).
  7379. /// 017f <packet len>.W <message>.?B
  7380. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7381. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7382. struct map_session_data *sd;
  7383. uint8 buf[256];
  7384. if( len == 0 )
  7385. {
  7386. return;
  7387. }
  7388. else if( len > sizeof(buf)-5 )
  7389. {
  7390. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7391. len = sizeof(buf)-5;
  7392. }
  7393. WBUFW(buf, 0) = 0x17f;
  7394. WBUFW(buf, 2) = len + 5;
  7395. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7396. if ((sd = guild_getavailablesd(g)) != NULL)
  7397. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7398. }
  7399. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7400. /// 0171 <inviter account id>.L <guild name>.24B
  7401. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7402. {
  7403. int fd;
  7404. nullpo_retv(sd);
  7405. fd=sd->fd;
  7406. WFIFOHEAD(fd,packet_len(0x171));
  7407. WFIFOW(fd,0)=0x171;
  7408. WFIFOL(fd,2)=account_id;
  7409. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7410. WFIFOSET(fd,packet_len(0x171));
  7411. }
  7412. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7413. /// 0173 <answer>.B
  7414. /// answer:
  7415. /// 0 = Already allied.
  7416. /// 1 = You rejected the offer.
  7417. /// 2 = You accepted the offer.
  7418. /// 3 = They have too any alliances.
  7419. /// 4 = You have too many alliances.
  7420. /// 5 = Alliances are disabled.
  7421. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7422. {
  7423. int fd;
  7424. nullpo_retv(sd);
  7425. fd=sd->fd;
  7426. WFIFOHEAD(fd,packet_len(0x173));
  7427. WFIFOW(fd,0)=0x173;
  7428. WFIFOL(fd,2)=flag;
  7429. WFIFOSET(fd,packet_len(0x173));
  7430. }
  7431. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7432. /// 0184 <other guild id>.L <relation>.L
  7433. /// relation:
  7434. /// 0 = Ally
  7435. /// 1 = Enemy
  7436. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7437. {
  7438. int fd;
  7439. nullpo_retv(sd);
  7440. fd = sd->fd;
  7441. if (fd <= 0)
  7442. return;
  7443. WFIFOHEAD(fd,packet_len(0x184));
  7444. WFIFOW(fd,0)=0x184;
  7445. WFIFOL(fd,2)=guild_id;
  7446. WFIFOL(fd,6)=flag;
  7447. WFIFOSET(fd,packet_len(0x184));
  7448. }
  7449. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7450. /// 0181 <result>.B
  7451. /// result:
  7452. /// 0 = Antagonist has been set.
  7453. /// 1 = Guild has too many Antagonists.
  7454. /// 2 = Already set as an Antagonist.
  7455. /// 3 = Antagonists are disabled.
  7456. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7457. {
  7458. int fd;
  7459. nullpo_retv(sd);
  7460. fd=sd->fd;
  7461. WFIFOHEAD(fd,packet_len(0x181));
  7462. WFIFOW(fd,0)=0x181;
  7463. WFIFOB(fd,2)=flag;
  7464. WFIFOSET(fd,packet_len(0x181));
  7465. }
  7466. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7467. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7468. /*
  7469. void clif_guild_allianceadded(struct guild *g,int idx)
  7470. {
  7471. unsigned char buf[64];
  7472. WBUFW(buf,0)=0x185;
  7473. WBUFL(buf,2)=g->alliance[idx].opposition;
  7474. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7475. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7476. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7477. }
  7478. */
  7479. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7480. /// 015e <reason>.L
  7481. /// 0 = success
  7482. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7483. /// 2 = there are still members in the guild
  7484. void clif_guild_broken(struct map_session_data *sd,int flag)
  7485. {
  7486. int fd;
  7487. nullpo_retv(sd);
  7488. fd=sd->fd;
  7489. WFIFOHEAD(fd,packet_len(0x15e));
  7490. WFIFOW(fd,0)=0x15e;
  7491. WFIFOL(fd,2)=flag;
  7492. WFIFOSET(fd,packet_len(0x15e));
  7493. }
  7494. /// Displays emotion on an object (ZC_EMOTION).
  7495. /// 00c0 <id>.L <type>.B
  7496. /// type:
  7497. /// enum emotion_type
  7498. void clif_emotion(struct block_list *bl,int type)
  7499. {
  7500. unsigned char buf[8];
  7501. nullpo_retv(bl);
  7502. WBUFW(buf,0)=0xc0;
  7503. WBUFL(buf,2)=bl->id;
  7504. WBUFB(buf,6)=type;
  7505. clif_send(buf,packet_len(0xc0),bl,AREA);
  7506. }
  7507. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7508. /// 0191 <id>.L <contents>.80B
  7509. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7510. {
  7511. unsigned char buf[MESSAGE_SIZE+6];
  7512. nullpo_retv(bl);
  7513. WBUFW(buf,0) = 0x191;
  7514. WBUFL(buf,2) = bl->id;
  7515. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7516. clif_send(buf,packet_len(0x191),bl,AREA);
  7517. }
  7518. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7519. /// 01ea <id>.L
  7520. void clif_wedding_effect(struct block_list *bl)
  7521. {
  7522. unsigned char buf[6];
  7523. nullpo_retv(bl);
  7524. WBUFW(buf,0) = 0x1ea;
  7525. WBUFL(buf,2) = bl->id;
  7526. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7527. }
  7528. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7529. /// 01e6 <partner name>.24B
  7530. void clif_callpartner(struct map_session_data *sd)
  7531. {
  7532. unsigned char buf[26];
  7533. nullpo_retv(sd);
  7534. WBUFW(buf,0) = 0x1e6;
  7535. if( sd->status.partner_id ) {
  7536. const char *p = map_charid2nick(sd->status.partner_id);
  7537. struct map_session_data *p_sd = pc_get_partner(sd);
  7538. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7539. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7540. else
  7541. WBUFB(buf,2) = 0;
  7542. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7543. WBUFB(buf,2) = 0;
  7544. }
  7545. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7546. }
  7547. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7548. /// 01e4
  7549. /// This packet while still implemented by the client is no longer being officially used.
  7550. /*
  7551. void clif_marriage_process(struct map_session_data *sd)
  7552. {
  7553. int fd;
  7554. nullpo_retv(sd);
  7555. fd=sd->fd;
  7556. WFIFOHEAD(fd,packet_len(0x1e4));
  7557. WFIFOW(fd,0)=0x1e4;
  7558. WFIFOSET(fd,packet_len(0x1e4));
  7559. }
  7560. */
  7561. /// Notice of divorce (ZC_DIVORCE).
  7562. /// 0205 <partner name>.24B
  7563. void clif_divorced(struct map_session_data* sd, const char* name)
  7564. {
  7565. int fd;
  7566. nullpo_retv(sd);
  7567. fd=sd->fd;
  7568. WFIFOHEAD(fd,packet_len(0x205));
  7569. WFIFOW(fd,0)=0x205;
  7570. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7571. WFIFOSET(fd, packet_len(0x205));
  7572. }
  7573. /// Marriage proposal (ZC_REQ_COUPLE).
  7574. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7575. /// This packet while still implemented by the client is no longer being officially used.
  7576. /*
  7577. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7578. {
  7579. nullpo_retv(sd);
  7580. WFIFOHEAD(fd,packet_len(0x1e2));
  7581. WFIFOW(fd,0) = 0x1e2;
  7582. WFIFOL(fd,2) = ssd->status.account_id;
  7583. WFIFOL(fd,6) = ssd->status.char_id;
  7584. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7585. WFIFOSET(fd, packet_len(0x1e2));
  7586. }
  7587. */
  7588. /*==========================================
  7589. *
  7590. *------------------------------------------*/
  7591. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7592. {
  7593. clif_disp_message(&sd->bl, mes, len, SELF);
  7594. }
  7595. /*==========================================
  7596. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7597. *------------------------------------------*/
  7598. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7599. {
  7600. unsigned char buf[256];
  7601. if( len == 0 ) {
  7602. return;
  7603. } else if( len > sizeof(buf)-5 ) {
  7604. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7605. len = sizeof(buf)-5;
  7606. }
  7607. WBUFW(buf, 0) = 0x17f;
  7608. WBUFW(buf, 2) = len + 5;
  7609. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7610. clif_send(buf, WBUFW(buf,2), src, target);
  7611. }
  7612. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7613. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7614. /// 00cd <result>.B
  7615. /// result:
  7616. /// 0 = failure
  7617. /// 1 = success
  7618. void clif_GM_kickack(struct map_session_data *sd, int id)
  7619. {
  7620. int fd;
  7621. nullpo_retv(sd);
  7622. fd = sd->fd;
  7623. WFIFOHEAD(fd,packet_len(0xcd));
  7624. WFIFOW(fd,0) = 0xcd;
  7625. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7626. WFIFOSET(fd, packet_len(0xcd));
  7627. }
  7628. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7629. {
  7630. int fd = tsd->fd;
  7631. if( fd > 0 )
  7632. clif_authfail_fd(fd, 15);
  7633. else {
  7634. // Close vending/buyingstore
  7635. if (sd) {
  7636. if (tsd->state.vending)
  7637. vending_closevending(tsd);
  7638. else if (tsd->state.buyingstore)
  7639. buyingstore_close(tsd);
  7640. }
  7641. map_quit(tsd);
  7642. }
  7643. if( sd )
  7644. clif_GM_kickack(sd,tsd->status.account_id);
  7645. }
  7646. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7647. /// 014a <result>.L
  7648. /// result:
  7649. /// 0 = "A manner point has been successfully aligned."
  7650. /// 1 = MP_FAILURE_EXHAUST
  7651. /// 2 = MP_FAILURE_ALREADY_GIVING
  7652. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7653. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7654. /// 5 = "You got a good point from %s."
  7655. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7656. {
  7657. int fd;
  7658. nullpo_retv(sd);
  7659. fd = sd->fd;
  7660. WFIFOHEAD(fd,packet_len(0x14a));
  7661. WFIFOW(fd,0) = 0x14a;
  7662. WFIFOL(fd,2) = type;
  7663. WFIFOSET(fd, packet_len(0x14a));
  7664. }
  7665. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7666. /// 014b <type>.B <GM name>.24B
  7667. /// type:
  7668. /// 0 = positive (unmute)
  7669. /// 1 = negative (mute)
  7670. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7671. {
  7672. int fd;
  7673. nullpo_retv(sd);
  7674. nullpo_retv(tsd);
  7675. fd = tsd->fd;
  7676. WFIFOHEAD(fd,packet_len(0x14b));
  7677. WFIFOW(fd,0) = 0x14b;
  7678. WFIFOB(fd,2) = type;
  7679. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7680. WFIFOSET(fd, packet_len(0x14b));
  7681. }
  7682. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7683. /// 00d1 <type>.B <result>.B
  7684. /// type:
  7685. /// 0 = /ex (deny)
  7686. /// 1 = /in (allow)
  7687. /// result:
  7688. /// 0 = success
  7689. /// 1 = failure
  7690. /// 2 = too many blocks
  7691. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7692. {
  7693. int fd;
  7694. nullpo_retv(sd);
  7695. fd=sd->fd;
  7696. WFIFOHEAD(fd,packet_len(0xd1));
  7697. WFIFOW(fd,0)=0xd1;
  7698. WFIFOB(fd,2)=type;
  7699. WFIFOB(fd,3)=flag;
  7700. WFIFOSET(fd,packet_len(0xd1));
  7701. }
  7702. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7703. /// 00d2 <type>.B <result>.B
  7704. /// type:
  7705. /// 0 = /exall (deny)
  7706. /// 1 = /inall (allow)
  7707. /// result:
  7708. /// 0 = success
  7709. /// 1 = failure
  7710. void clif_wisall(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(0xd2));
  7716. WFIFOW(fd,0)=0xd2;
  7717. WFIFOB(fd,2)=type;
  7718. WFIFOB(fd,3)=flag;
  7719. WFIFOSET(fd,packet_len(0xd2));
  7720. }
  7721. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7722. /// 07fe <bgm>.24B
  7723. void clif_playBGM(struct map_session_data* sd, const char* name)
  7724. {
  7725. int fd;
  7726. nullpo_retv(sd);
  7727. fd = sd->fd;
  7728. WFIFOHEAD(fd,packet_len(0x7fe));
  7729. WFIFOW(fd,0) = 0x7fe;
  7730. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7731. WFIFOSET(fd,packet_len(0x7fe));
  7732. }
  7733. /// Plays/stops a wave sound (ZC_SOUND).
  7734. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7735. /// file name:
  7736. /// relative to data\wav
  7737. /// act:
  7738. /// 0 = play (once)
  7739. /// 1 = play (repeat, does not work)
  7740. /// 2 = stops all sound instances of file name (does not work)
  7741. /// term:
  7742. /// unknown purpose, only relevant to act = 1
  7743. /// npc id:
  7744. /// The accustic direction of the sound is determined by the
  7745. /// relative position of the NPC to the player (3D sound).
  7746. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7747. {
  7748. int fd;
  7749. nullpo_retv(sd);
  7750. nullpo_retv(bl);
  7751. fd = sd->fd;
  7752. WFIFOHEAD(fd,packet_len(0x1d3));
  7753. WFIFOW(fd,0) = 0x1d3;
  7754. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7755. WFIFOB(fd,26) = type;
  7756. WFIFOL(fd,27) = 0;
  7757. WFIFOL(fd,31) = bl->id;
  7758. WFIFOSET(fd,packet_len(0x1d3));
  7759. }
  7760. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7761. {
  7762. unsigned char buf[40];
  7763. nullpo_retv(bl);
  7764. WBUFW(buf,0) = 0x1d3;
  7765. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7766. WBUFB(buf,26) = type;
  7767. WBUFL(buf,27) = 0;
  7768. WBUFL(buf,31) = bl->id;
  7769. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7770. }
  7771. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7772. /// 01f3 <id>.L <effect id>.L
  7773. /// effect id:
  7774. /// @see doc/effect_list.txt
  7775. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7776. {
  7777. unsigned char buf[24];
  7778. nullpo_retv(bl);
  7779. memset(buf, 0, packet_len(0x1f3));
  7780. WBUFW(buf,0) = 0x1f3;
  7781. WBUFL(buf,2) = bl->id;
  7782. WBUFL(buf,6) = type;
  7783. clif_send(buf, packet_len(0x1f3), bl, target);
  7784. if (disguised(bl)) {
  7785. WBUFL(buf,2) = -bl->id;
  7786. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7787. }
  7788. }
  7789. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7790. {
  7791. WFIFOHEAD(fd,10);
  7792. WFIFOW(fd,0) = 0x1f3;
  7793. WFIFOL(fd,2) = bl->id;
  7794. WFIFOL(fd,6) = type;
  7795. WFIFOSET(fd,10);
  7796. }
  7797. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7798. /// 0284 <id>.L <effect id>.L <num data>.L
  7799. /// effect id:
  7800. /// @see doc/effect_list.txt
  7801. /// num data:
  7802. /// effect-dependent value
  7803. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7804. {
  7805. uint8 buf[14];
  7806. WBUFW(buf,0) = 0x284;
  7807. WBUFL(buf,2) = bl->id;
  7808. WBUFL(buf,6) = effect_id;
  7809. WBUFL(buf,10) = num;
  7810. clif_send(buf, packet_len(0x284), bl, target);
  7811. if( disguised(bl) )
  7812. {
  7813. WBUFL(buf,2) = -bl->id;
  7814. clif_send(buf, packet_len(0x284), bl, SELF);
  7815. }
  7816. }
  7817. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7818. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7819. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7820. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7821. WFIFOHEAD(fd,msg_len + 12);
  7822. WFIFOW(fd,0) = 0x2C1;
  7823. WFIFOW(fd,2) = msg_len + 12;
  7824. WFIFOL(fd,4) = 0;
  7825. WFIFOL(fd,8) = color; //either color_table or channel_table
  7826. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7827. WFIFOSET(fd, msg_len + 12);
  7828. return 0;
  7829. }
  7830. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7831. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7832. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7833. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7834. uint8 buf[256];
  7835. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7836. nullpo_retv(bl);
  7837. if( msg_len > sizeof(buf)-12 ) {
  7838. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7839. msg_len = sizeof(buf)-12;
  7840. }
  7841. WBUFW(buf,0) = 0x2C1;
  7842. WBUFW(buf,2) = msg_len + 12;
  7843. WBUFL(buf,4) = bl->id;
  7844. WBUFL(buf,8) = color;
  7845. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7846. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7847. }
  7848. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7849. {
  7850. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7851. nullpo_retv(sd);
  7852. if(msg_len > 0) {
  7853. int fd;
  7854. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7855. fd = sd->fd;
  7856. WFIFOHEAD(fd, msg_len+12);
  7857. WFIFOW(fd,0) = 0x2C1;
  7858. WFIFOW(fd,2) = msg_len+12;
  7859. WFIFOL(fd,4) = 0;
  7860. WFIFOL(fd,8) = color;
  7861. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7862. WFIFOSET(fd, WFIFOW(fd,2));
  7863. }
  7864. }
  7865. /**
  7866. * Notifies the client that the storage window is still open
  7867. *
  7868. * Should only be used in cases where the client closed the
  7869. * storage window without server's consent
  7870. */
  7871. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7872. // Notify the client that the storage is open
  7873. if( sd->state.storage_flag == 1 ) {
  7874. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7875. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7876. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7877. }
  7878. // Notify the client that the gstorage is open otherwise it will
  7879. // remain locked forever and nobody will be able to access it
  7880. if( sd->state.storage_flag == 2 ) {
  7881. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7882. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7883. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7884. else {
  7885. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7886. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7887. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7888. }
  7889. }
  7890. }
  7891. // refresh the client's screen, getting rid of any effects
  7892. void clif_refresh(struct map_session_data *sd)
  7893. {
  7894. nullpo_retv(sd);
  7895. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7896. clif_inventorylist(sd);
  7897. if(pc_iscarton(sd)) {
  7898. clif_cartlist(sd);
  7899. clif_updatestatus(sd,SP_CARTINFO);
  7900. }
  7901. clif_updatestatus(sd,SP_WEIGHT);
  7902. clif_updatestatus(sd,SP_MAXWEIGHT);
  7903. clif_updatestatus(sd,SP_STR);
  7904. clif_updatestatus(sd,SP_AGI);
  7905. clif_updatestatus(sd,SP_VIT);
  7906. clif_updatestatus(sd,SP_INT);
  7907. clif_updatestatus(sd,SP_DEX);
  7908. clif_updatestatus(sd,SP_LUK);
  7909. if (sd->spiritball)
  7910. clif_spiritball_single(sd->fd, sd);
  7911. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7912. clif_spiritcharm_single(sd->fd, sd);
  7913. if (sd->vd.cloth_color)
  7914. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7915. if (sd->vd.body_style)
  7916. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7917. if(hom_is_active(sd->hd))
  7918. clif_send_homdata(sd,SP_ACK,0);
  7919. if( sd->md ) {
  7920. clif_mercenary_info(sd);
  7921. clif_mercenary_skillblock(sd);
  7922. }
  7923. if( sd->ed )
  7924. clif_elemental_info(sd);
  7925. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7926. clif_weather_check(sd);
  7927. if( sd->chatID )
  7928. chat_leavechat(sd,0);
  7929. if( sd->state.vending )
  7930. clif_openvending(sd, sd->bl.id, sd->vending);
  7931. if( pc_issit(sd) )
  7932. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7933. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7934. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7935. else
  7936. clif_changed_dir(&sd->bl, SELF);
  7937. // unlike vending, resuming buyingstore crashes the client.
  7938. buyingstore_close(sd);
  7939. mail_clear(sd);
  7940. if( disguised(&sd->bl) ) {/* refresh-da */
  7941. short disguise = sd->disguise;
  7942. pc_disguise(sd, 0);
  7943. pc_disguise(sd, disguise);
  7944. }
  7945. clif_refresh_storagewindow(sd);
  7946. }
  7947. /// Updates the object's (bl) name on client.
  7948. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7949. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7950. void clif_charnameack (int fd, struct block_list *bl)
  7951. {
  7952. unsigned char buf[103];
  7953. int cmd = 0x95;
  7954. nullpo_retv(bl);
  7955. WBUFW(buf,0) = cmd;
  7956. WBUFL(buf,2) = bl->id;
  7957. switch( bl->type )
  7958. {
  7959. case BL_PC:
  7960. {
  7961. struct map_session_data *ssd = (struct map_session_data *)bl;
  7962. struct party_data *p = NULL;
  7963. struct guild *g = NULL;
  7964. int ps = -1;
  7965. //Requesting your own "shadow" name. [Skotlex]
  7966. if (ssd->fd == fd && ssd->disguise)
  7967. WBUFL(buf,2) = -bl->id;
  7968. if( ssd->fakename[0] ) {
  7969. WBUFW(buf, 0) = cmd = 0x195;
  7970. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7971. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7972. break;
  7973. }
  7974. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7975. if( ssd->status.party_id ) {
  7976. p = party_search(ssd->status.party_id);
  7977. }
  7978. if( ssd->status.guild_id ) {
  7979. if( ( g = ssd->guild ) != NULL ) {
  7980. int i;
  7981. 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);
  7982. if( i < g->max_member ) ps = g->member[i].position;
  7983. }
  7984. }
  7985. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7986. p = NULL;
  7987. }
  7988. if (p == NULL && g == NULL)
  7989. break;
  7990. WBUFW(buf, 0) = cmd = 0x195;
  7991. if (p)
  7992. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7993. else
  7994. WBUFB(buf,30) = 0;
  7995. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7996. {
  7997. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7998. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7999. } else { //Assume no guild.
  8000. WBUFB(buf,54) = 0;
  8001. WBUFB(buf,78) = 0;
  8002. }
  8003. }
  8004. break;
  8005. //[blackhole89]
  8006. case BL_HOM:
  8007. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8008. break;
  8009. case BL_MER:
  8010. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8011. break;
  8012. case BL_PET:
  8013. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8014. break;
  8015. case BL_NPC:
  8016. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8017. break;
  8018. case BL_MOB:
  8019. {
  8020. struct mob_data *md = (struct mob_data *)bl;
  8021. nullpo_retv(md);
  8022. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  8023. if( md->guardian_data && md->guardian_data->guild_id )
  8024. {
  8025. WBUFW(buf, 0) = cmd = 0x195;
  8026. WBUFB(buf,30) = 0;
  8027. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8028. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8029. }
  8030. else if( battle_config.show_mob_info )
  8031. {
  8032. char mobhp[50], *str_p = mobhp;
  8033. WBUFW(buf, 0) = cmd = 0x195;
  8034. if( battle_config.show_mob_info&4 )
  8035. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8036. if( battle_config.show_mob_info&1 )
  8037. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8038. if( battle_config.show_mob_info&2 )
  8039. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8040. //Even thought mobhp ain't a name, we send it as one so the client
  8041. //can parse it. [Skotlex]
  8042. if( str_p != mobhp )
  8043. {
  8044. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8045. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  8046. WBUFB(buf,54) = 0;
  8047. WBUFB(buf,78) = 0;
  8048. }
  8049. }
  8050. }
  8051. break;
  8052. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8053. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8054. // break;
  8055. return;
  8056. case BL_ELEM:
  8057. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8058. break;
  8059. default:
  8060. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  8061. return;
  8062. }
  8063. // if no receipient specified just update nearby clients
  8064. if (fd == 0)
  8065. clif_send(buf, packet_len(cmd), bl, AREA);
  8066. else {
  8067. WFIFOHEAD(fd, packet_len(cmd));
  8068. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  8069. WFIFOSET(fd, packet_len(cmd));
  8070. }
  8071. }
  8072. //Used to update when a char leaves a party/guild. [Skotlex]
  8073. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8074. void clif_charnameupdate (struct map_session_data *ssd)
  8075. {
  8076. unsigned char buf[103];
  8077. int cmd = 0x195, ps = -1;
  8078. struct party_data *p = NULL;
  8079. struct guild *g = NULL;
  8080. nullpo_retv(ssd);
  8081. if( ssd->fakename[0] )
  8082. return; //No need to update as the party/guild was not displayed anyway.
  8083. WBUFW(buf,0) = cmd;
  8084. WBUFL(buf,2) = ssd->bl.id;
  8085. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  8086. if (!battle_config.display_party_name) {
  8087. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  8088. p = party_search(ssd->status.party_id);
  8089. }else{
  8090. if (ssd->status.party_id > 0)
  8091. p = party_search(ssd->status.party_id);
  8092. }
  8093. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  8094. {
  8095. int i;
  8096. 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);
  8097. if( i < g->max_member ) ps = g->member[i].position;
  8098. }
  8099. if( p )
  8100. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8101. else
  8102. WBUFB(buf,30) = 0;
  8103. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  8104. {
  8105. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  8106. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8107. }
  8108. else
  8109. {
  8110. WBUFB(buf,54) = 0;
  8111. WBUFB(buf,78) = 0;
  8112. }
  8113. // Update nearby clients
  8114. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  8115. }
  8116. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8117. /// 01ff <id>.L <x>.W <y>.W
  8118. ///
  8119. /// Visually moves(instant) a character to x,y. The char moves even
  8120. /// when the target cell isn't walkable. If the char is sitting it
  8121. /// stays that way.
  8122. void clif_slide(struct block_list *bl, int x, int y)
  8123. {
  8124. unsigned char buf[10];
  8125. nullpo_retv(bl);
  8126. WBUFW(buf, 0) = 0x01ff;
  8127. WBUFL(buf, 2) = bl->id;
  8128. WBUFW(buf, 6) = x;
  8129. WBUFW(buf, 8) = y;
  8130. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8131. if( disguised(bl) )
  8132. {
  8133. WBUFL(buf,2) = -bl->id;
  8134. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8135. }
  8136. }
  8137. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8138. /// 008d <packet len>.W <id>.L <message>.?B
  8139. void clif_disp_overhead(struct block_list *bl, const char* mes)
  8140. {
  8141. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8142. int len_mes = strlen(mes)+1; //Account for \0
  8143. if (len_mes > sizeof(buf)-8) {
  8144. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8145. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8146. }
  8147. // send message to others
  8148. WBUFW(buf,0) = 0x8d;
  8149. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8150. WBUFL(buf,4) = bl->id;
  8151. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  8152. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8153. // send back message to the speaker
  8154. if( bl->type == BL_PC ) {
  8155. WBUFW(buf,0) = 0x8e;
  8156. WBUFW(buf, 2) = len_mes + 4;
  8157. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  8158. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8159. }
  8160. }
  8161. /*==========================
  8162. * Minimap fix [Kevin]
  8163. * Remove dot from minimap
  8164. *--------------------------*/
  8165. void clif_party_xy_remove(struct map_session_data *sd)
  8166. {
  8167. unsigned char buf[16];
  8168. nullpo_retv(sd);
  8169. WBUFW(buf,0)=0x107;
  8170. WBUFL(buf,2)=sd->status.account_id;
  8171. WBUFW(buf,6)=-1;
  8172. WBUFW(buf,8)=-1;
  8173. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8174. }
  8175. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8176. /// 0215 <msg id>.L
  8177. /// msg id:
  8178. /// 0x15 = End all negative status (PA_GOSPEL)
  8179. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8180. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8181. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8182. /// 0x19 = All stats +20 (PA_GOSPEL)
  8183. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8184. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8185. /// 0x1e = DEF +25% (PA_GOSPEL)
  8186. /// 0x1f = ATK +100% (PA_GOSPEL)
  8187. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8188. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8189. /// ? = nothing
  8190. void clif_gospel_info(struct map_session_data *sd, int type)
  8191. {
  8192. int fd=sd->fd;
  8193. WFIFOHEAD(fd,packet_len(0x215));
  8194. WFIFOW(fd,0)=0x215;
  8195. WFIFOL(fd,2)=type;
  8196. WFIFOSET(fd, packet_len(0x215));
  8197. }
  8198. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8199. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8200. /// result:
  8201. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8202. /// star:
  8203. /// 0 = Place of the Sun
  8204. /// 1 = Place of the Moon
  8205. /// 2 = Place of the Stars
  8206. /// 1 = Star Gladiator %s's %s: <mapname>
  8207. /// star:
  8208. /// 0 = Place of the Sun
  8209. /// 1 = Place of the Moon
  8210. /// 2 = Place of the Stars
  8211. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8212. /// star:
  8213. /// 0 = Target of the Sun
  8214. /// 1 = Target of the Moon
  8215. /// 2 = Target of the Stars
  8216. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8217. /// star:
  8218. /// 0 = Monster of the Sun
  8219. /// 1 = Monster of the Moon
  8220. /// 2 = Monster of the Stars
  8221. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8222. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8223. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8224. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8225. /// 40 = Target HP : <monster_id used as HP>
  8226. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8227. {
  8228. int fd = sd->fd;
  8229. WFIFOHEAD(fd,packet_len(0x20e));
  8230. WFIFOW(fd,0) = 0x20e;
  8231. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8232. WFIFOL(fd,26) = monster_id;
  8233. WFIFOB(fd,30) = star;
  8234. WFIFOB(fd,31) = result;
  8235. WFIFOSET(fd,packet_len(0x20e));
  8236. }
  8237. /*==========================================
  8238. * Info about Star Glaldiator save map [Komurka]
  8239. * type: 1: Information, 0: Map registered
  8240. *------------------------------------------*/
  8241. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8242. {
  8243. char mapname[MAP_NAME_LENGTH_EXT];
  8244. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8245. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8246. }
  8247. /*==========================================
  8248. * Info about Star Glaldiator hate mob [Komurka]
  8249. * type: 1: Register mob, 0: Information.
  8250. *------------------------------------------*/
  8251. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8252. {
  8253. if( pcdb_checkid(class_) ) {
  8254. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8255. } else if( mobdb_checkid(class_) ) {
  8256. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8257. } else {
  8258. 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);
  8259. }
  8260. }
  8261. /*==========================================
  8262. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8263. *------------------------------------------*/
  8264. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8265. {
  8266. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8267. }
  8268. /*==========================================
  8269. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8270. *------------------------------------------*/
  8271. void clif_feel_hate_reset(struct map_session_data *sd)
  8272. {
  8273. clif_starskill(sd, "", 0, 0, 30);
  8274. }
  8275. /// Equip window (un)tick ack (ZC_CONFIG).
  8276. /// 02d9 <type>.L <value>.L
  8277. /// type:
  8278. /// 0 = open equip window
  8279. /// value:
  8280. /// 0 = disabled
  8281. /// 1 = enabled
  8282. void clif_equiptickack(struct map_session_data* sd, int flag)
  8283. {
  8284. int fd;
  8285. nullpo_retv(sd);
  8286. fd = sd->fd;
  8287. WFIFOHEAD(fd, packet_len(0x2d9));
  8288. WFIFOW(fd, 0) = 0x2d9;
  8289. WFIFOL(fd, 2) = 0;
  8290. WFIFOL(fd, 6) = flag;
  8291. WFIFOSET(fd, packet_len(0x2d9));
  8292. }
  8293. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8294. /// 02da <open equip window>.B
  8295. /// open equip window:
  8296. /// 0 = disabled
  8297. /// 1 = enabled
  8298. void clif_equipcheckbox(struct map_session_data* sd)
  8299. {
  8300. int fd;
  8301. nullpo_retv(sd);
  8302. fd = sd->fd;
  8303. WFIFOHEAD(fd, packet_len(0x2da));
  8304. WFIFOW(fd, 0) = 0x2da;
  8305. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8306. WFIFOSET(fd, packet_len(0x2da));
  8307. }
  8308. /// Sends info about a player's equipped items.
  8309. /// 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)
  8310. /// 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)
  8311. /// 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)
  8312. /// 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)
  8313. /// 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)
  8314. /// 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)
  8315. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8316. {
  8317. uint8* buf;
  8318. int i, n, fd, offset = 0;
  8319. #if PACKETVER < 20100629
  8320. const int s = 26;
  8321. #elif PACKETVER < 20120925
  8322. const int s = 28;
  8323. #elif PACKETVER < 20150226
  8324. const int s = 31;
  8325. #else
  8326. const int s = 57;
  8327. #endif
  8328. nullpo_retv(sd);
  8329. nullpo_retv(tsd);
  8330. fd = sd->fd;
  8331. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8332. buf = WFIFOP(fd,0);
  8333. #if PACKETVER < 20101124
  8334. WBUFW(buf, 0) = 0x2d7;
  8335. #elif PACKETVER < 20120925
  8336. WBUFW(buf, 0) = 0x859;
  8337. #elif PACKETVER < 20150226
  8338. WBUFW(buf, 0) = 0x997;
  8339. #else
  8340. WBUFW(buf, 0) = 0xa2d;
  8341. #endif
  8342. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8343. WBUFW(buf,28) = tsd->status.class_;
  8344. WBUFW(buf,30) = tsd->vd.hair_style;
  8345. WBUFW(buf,32) = tsd->vd.head_bottom;
  8346. WBUFW(buf,34) = tsd->vd.head_mid;
  8347. WBUFW(buf,36) = tsd->vd.head_top;
  8348. #if PACKETVER >= 20110111
  8349. WBUFW(buf,38) = tsd->vd.robe;
  8350. offset+= 2;
  8351. buf = WBUFP(buf,2);
  8352. #endif
  8353. WBUFW(buf,38) = tsd->vd.hair_color;
  8354. WBUFW(buf,40) = tsd->vd.cloth_color;
  8355. WBUFB(buf,42) = tsd->vd.sex;
  8356. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8357. {
  8358. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8359. continue;
  8360. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8361. continue;
  8362. // Add item info : refine, identify flag, element, etc.
  8363. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8364. n++;
  8365. }
  8366. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8367. WFIFOSET(fd, WFIFOW(fd, 2));
  8368. }
  8369. /// Display msgstringtable.txt string (ZC_MSG).
  8370. /// 0291 <message>.W
  8371. void clif_msg(struct map_session_data* sd, unsigned short id)
  8372. {
  8373. int fd;
  8374. nullpo_retv(sd);
  8375. fd = sd->fd;
  8376. WFIFOHEAD(fd, packet_len(0x291));
  8377. WFIFOW(fd, 0) = 0x291;
  8378. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8379. WFIFOSET(fd, packet_len(0x291));
  8380. }
  8381. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8382. /// 0x7e2 <message>.W <value>.L
  8383. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8384. {
  8385. int fd = sd->fd;
  8386. WFIFOHEAD(fd, packet_len(0x7e2));
  8387. WFIFOW(fd,0) = 0x7e2;
  8388. WFIFOW(fd,2) = id;
  8389. WFIFOL(fd,4) = value;
  8390. WFIFOSET(fd, packet_len(0x7e2));
  8391. }
  8392. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8393. /// 07e6 <skill id>.W <msg id>.L
  8394. ///
  8395. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8396. /// "[SkillName] Message"
  8397. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8398. {
  8399. int fd = sd->fd;
  8400. WFIFOHEAD(fd, packet_len(0x7e6));
  8401. WFIFOW(fd,0) = 0x7e6;
  8402. WFIFOW(fd,2) = skill_id;
  8403. WFIFOL(fd,4) = msg_id;
  8404. WFIFOSET(fd, packet_len(0x7e6));
  8405. }
  8406. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8407. /// Returns true if the packet was parsed successfully.
  8408. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8409. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8410. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_) {
  8411. char *text, *name, *message;
  8412. unsigned int packetlen, textlen, namelen, messagelen;
  8413. int fd = sd->fd;
  8414. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8415. *name_ = NULL;
  8416. *namelen_ = 0;
  8417. *message_ = NULL;
  8418. *messagelen_ = 0;
  8419. packetlen = RFIFOW(fd,info->pos[0]);
  8420. // basic structure checks
  8421. if( packetlen < 4 + 1 ) { // 4-byte header and at least an empty string is expected
  8422. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8423. return false;
  8424. }
  8425. text = (char*)RFIFOP(fd,info->pos[1]);
  8426. textlen = packetlen - 4;
  8427. // process <name> part of the packet
  8428. if( format == 0 ) { // name and message are separated by ' : '
  8429. // validate name
  8430. name = text;
  8431. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8432. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8433. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8434. {
  8435. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8436. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8437. set_eof(fd); // Just kick them out to correct it.
  8438. return false;
  8439. }
  8440. message = name + namelen + 3;
  8441. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8442. } else {
  8443. // name has fixed width
  8444. if( textlen < NAME_LENGTH + 1 ) {
  8445. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8446. return false;
  8447. }
  8448. // validate name
  8449. name = text;
  8450. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8451. // only restriction is that the name must be zero-terminated
  8452. if( name[namelen] != '\0' ) {
  8453. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8454. return false;
  8455. }
  8456. message = name + NAME_LENGTH;
  8457. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8458. }
  8459. #if PACKETVER >= 20151001
  8460. if (message[messagelen-1] != '\0')
  8461. {
  8462. message[messagelen++] = '\0';
  8463. }
  8464. #endif
  8465. // the declared length must match real length
  8466. if( messagelen != strnlen(message, messagelen)+1 ) {
  8467. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8468. return false;
  8469. }
  8470. // verify <message> part of the packet
  8471. if( message[messagelen-1] != '\0' ) { // message must be zero-terminated
  8472. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8473. return false;
  8474. }
  8475. // messages mustn't be too long
  8476. if( messagelen > CHAT_SIZE_MAX-1 ) {
  8477. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8478. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8479. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8480. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8481. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8482. return false;
  8483. }
  8484. *name_ = name;
  8485. *namelen_ = namelen;
  8486. *message_ = message;
  8487. *messagelen_ = messagelen;
  8488. return true;
  8489. }
  8490. // ---------------------
  8491. // clif_guess_PacketVer
  8492. // ---------------------
  8493. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8494. // error codes:
  8495. // 0 - Success
  8496. // 1 - Unknown packet_ver
  8497. // 2 - Invalid account_id
  8498. // 3 - Invalid char_id
  8499. // 4 - Invalid login_id1 (reserved)
  8500. // 5 - Invalid client_tick (reserved)
  8501. // 6 - Invalid sex
  8502. // Only the first 'invalid' error that appears is used.
  8503. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8504. {
  8505. static int err = 1;
  8506. static int packet_ver = -1;
  8507. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8508. unsigned short cmd;
  8509. if (get_previous)
  8510. {//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]
  8511. if( error )
  8512. *error = err;
  8513. return packet_ver;
  8514. }
  8515. //By default, start searching on the default one.
  8516. err = 1;
  8517. packet_ver = clif_config.packet_db_ver;
  8518. cmd = clif_parse_cmd(fd, NULL);
  8519. packet_len = RFIFOREST(fd);
  8520. #define SET_ERROR(n) \
  8521. if( err == 1 )\
  8522. err = n;\
  8523. //define SET_ERROR
  8524. // FIXME: If the packet is not received at once, this will FAIL.
  8525. // Figure out, when it happens, that only part of the packet is
  8526. // received, or fix the function to be able to deal with that
  8527. // case.
  8528. #define CHECK_PACKET_VER() \
  8529. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8530. ;/* not wanttoconnection or wrong length */\
  8531. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8532. { SET_ERROR(2); }/* invalid account_id */\
  8533. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8534. { SET_ERROR(3); }/* invalid char_id */\
  8535. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8536. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8537. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8538. { SET_ERROR(6); }/* invalid sex */\
  8539. else\
  8540. {\
  8541. err = 0;\
  8542. if( error )\
  8543. *error = 0;\
  8544. return packet_ver;\
  8545. }\
  8546. //define CHECK_PACKET_VER
  8547. CHECK_PACKET_VER();//Default packet version found.
  8548. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8549. CHECK_PACKET_VER();
  8550. }
  8551. if( error )
  8552. *error = err;
  8553. packet_ver = -1;
  8554. return -1;
  8555. #undef SET_ERROR
  8556. #undef CHECK_PACKET_VER
  8557. }
  8558. // ------------
  8559. // clif_parse_*
  8560. // ------------
  8561. // Parses incoming (player) connection
  8562. /// Request to connect to map-server.
  8563. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8564. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8565. /// There are various variants of this packet, some of them have padding between fields.
  8566. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8567. {
  8568. struct block_list* bl;
  8569. struct auth_node* node;
  8570. int cmd, account_id, char_id, login_id1, sex;
  8571. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8572. 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])
  8573. if (sd) {
  8574. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8575. return;
  8576. }
  8577. // Only valid packet version get here
  8578. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8579. cmd = RFIFOW(fd,0);
  8580. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8581. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8582. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8583. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8584. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8585. if( packet_ver < 5 || // reject really old client versions
  8586. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8587. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8588. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8589. {// packet version rejected
  8590. 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));
  8591. WFIFOHEAD(fd,packet_len(0x6a));
  8592. WFIFOW(fd,0) = 0x6a;
  8593. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8594. WFIFOSET(fd,packet_len(0x6a));
  8595. set_eof(fd);
  8596. return;
  8597. }
  8598. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8599. clif_authfail_fd(fd,1);// server closed
  8600. return;
  8601. }
  8602. //Check for double login.
  8603. bl = map_id2bl(account_id);
  8604. if(bl && bl->type != BL_PC) {
  8605. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8606. WFIFOHEAD(fd,packet_len(0x6a));
  8607. WFIFOW(fd,0) = 0x6a;
  8608. WFIFOB(fd,2) = 3; // Rejected by server
  8609. WFIFOSET(fd,packet_len(0x6a));
  8610. set_eof(fd);
  8611. return;
  8612. }
  8613. if (bl ||
  8614. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8615. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8616. {
  8617. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8618. return;
  8619. }
  8620. CREATE(sd, TBL_PC, 1);
  8621. sd->fd = fd;
  8622. sd->packet_ver = packet_ver;
  8623. #ifdef PACKET_OBFUSCATION
  8624. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8625. #endif
  8626. session[fd]->session_data = sd;
  8627. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8628. #if PACKETVER < 20070521
  8629. WFIFOHEAD(fd,4);
  8630. WFIFOL(fd,0) = sd->bl.id;
  8631. WFIFOSET(fd,4);
  8632. #else
  8633. WFIFOHEAD(fd,packet_len(0x283));
  8634. WFIFOW(fd,0) = 0x283;
  8635. WFIFOL(fd,2) = sd->bl.id;
  8636. WFIFOSET(fd,packet_len(0x283));
  8637. #endif
  8638. chrif_authreq(sd,false);
  8639. }
  8640. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8641. /// 007d
  8642. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8643. {
  8644. bool guild_notice = false;
  8645. if(sd->bl.prev != NULL)
  8646. return;
  8647. if (!sd->state.active) { //Character loading is not complete yet!
  8648. //Let pc_reg_received reinvoke this when ready.
  8649. sd->state.connect_new = 0;
  8650. return;
  8651. }
  8652. if (sd->state.rewarp) { //Rewarp player.
  8653. sd->state.rewarp = 0;
  8654. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8655. return;
  8656. }
  8657. sd->state.warping = 0;
  8658. // look
  8659. #if PACKETVER < 4
  8660. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8661. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8662. #else
  8663. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8664. #endif
  8665. if(sd->vd.cloth_color)
  8666. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8667. if(sd->vd.body_style)
  8668. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8669. // item
  8670. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8671. pc_checkitem(sd);
  8672. // cart
  8673. if(pc_iscarton(sd)) {
  8674. clif_cartlist(sd);
  8675. clif_updatestatus(sd,SP_CARTINFO);
  8676. }
  8677. // weight
  8678. clif_updatestatus(sd,SP_WEIGHT);
  8679. clif_updatestatus(sd,SP_MAXWEIGHT);
  8680. // guild
  8681. // (needs to go before clif_spawn() to show guild emblems correctly)
  8682. if(sd->status.guild_id)
  8683. guild_send_memberinfoshort(sd,1);
  8684. if(battle_config.pc_invincible_time > 0) {
  8685. if(map_flag_gvg(sd->bl.m))
  8686. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8687. else
  8688. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8689. }
  8690. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8691. map_spawnmobs(sd->bl.m);
  8692. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8693. map[sd->bl.m].users_pvp++;
  8694. }
  8695. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8696. // reset the callshop flag if the player changes map
  8697. sd->state.callshop = 0;
  8698. if(map_addblock(&sd->bl))
  8699. return;
  8700. clif_spawn(&sd->bl);
  8701. // Party
  8702. // (needs to go after clif_spawn() to show hp bars correctly)
  8703. if(sd->status.party_id) {
  8704. party_send_movemap(sd);
  8705. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8706. }
  8707. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8708. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8709. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8710. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8711. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8712. sd->pvp_rank = 0;
  8713. sd->pvp_lastusers = 0;
  8714. sd->pvp_point = 5;
  8715. sd->pvp_won = 0;
  8716. sd->pvp_lost = 0;
  8717. }
  8718. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8719. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8720. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8721. if (map[sd->bl.m].flag.gvg_dungeon)
  8722. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8723. if( map_flag_gvg(sd->bl.m) )
  8724. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8725. // info about nearby objects
  8726. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8727. 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);
  8728. // pet
  8729. if( sd->pd ) {
  8730. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8731. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8732. pet_menu(sd, 3); //Option 3 is return to egg.
  8733. } else {
  8734. if(map_addblock(&sd->pd->bl))
  8735. return;
  8736. clif_spawn(&sd->pd->bl);
  8737. clif_send_petdata(sd,sd->pd,0,0);
  8738. clif_send_petstatus(sd);
  8739. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8740. }
  8741. }
  8742. //homunculus [blackhole89]
  8743. if( hom_is_active(sd->hd) ) {
  8744. if(map_addblock(&sd->hd->bl))
  8745. return;
  8746. clif_spawn(&sd->hd->bl);
  8747. clif_send_homdata(sd,SP_ACK,0);
  8748. clif_hominfo(sd,sd->hd,1);
  8749. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8750. clif_homskillinfoblock(sd);
  8751. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8752. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8753. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8754. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8755. }
  8756. if( sd->md ) {
  8757. if(map_addblock(&sd->md->bl))
  8758. return;
  8759. clif_spawn(&sd->md->bl);
  8760. clif_mercenary_info(sd);
  8761. clif_mercenary_skillblock(sd);
  8762. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8763. }
  8764. if( sd->ed ) {
  8765. if (map_addblock(&sd->ed->bl))
  8766. return;
  8767. clif_spawn(&sd->ed->bl);
  8768. clif_elemental_info(sd);
  8769. clif_elemental_updatestatus(sd,SP_HP);
  8770. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8771. clif_elemental_updatestatus(sd,SP_SP);
  8772. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8773. }
  8774. if(sd->state.connect_new) {
  8775. int lv;
  8776. guild_notice = true;
  8777. sd->state.connect_new = 0;
  8778. clif_skillinfoblock(sd);
  8779. clif_hotkeys_send(sd);
  8780. clif_updatestatus(sd,SP_BASEEXP);
  8781. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8782. clif_updatestatus(sd,SP_JOBEXP);
  8783. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8784. clif_updatestatus(sd,SP_SKILLPOINT);
  8785. clif_initialstatus(sd);
  8786. if (sd->sc.option&OPTION_FALCON)
  8787. clif_status_load(&sd->bl, SI_FALCON, 1);
  8788. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8789. clif_status_load(&sd->bl, SI_RIDING, 1);
  8790. else if (sd->sc.option&OPTION_WUGRIDER)
  8791. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8792. else if (sd->sc.data[SC_ALL_RIDING])
  8793. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8794. if(sd->status.manner < 0)
  8795. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8796. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8797. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8798. if(sd->bl.m == sd->feel_map[0].m
  8799. || sd->bl.m == sd->feel_map[1].m
  8800. || sd->bl.m == sd->feel_map[2].m)
  8801. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8802. }
  8803. if(sd->pd && sd->pd->pet.intimate > 900)
  8804. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8805. if(hom_is_active(sd->hd))
  8806. hom_init_timers(sd->hd);
  8807. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8808. sd->state.night = 1;
  8809. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8810. }
  8811. // Notify everyone that this char logged in [Skotlex].
  8812. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8813. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8814. //Login Event
  8815. npc_script_event(sd, NPCE_LOGIN);
  8816. }
  8817. } else {
  8818. //For some reason the client "loses" these on warp/map-change.
  8819. clif_updatestatus(sd,SP_STR);
  8820. clif_updatestatus(sd,SP_AGI);
  8821. clif_updatestatus(sd,SP_VIT);
  8822. clif_updatestatus(sd,SP_INT);
  8823. clif_updatestatus(sd,SP_DEX);
  8824. clif_updatestatus(sd,SP_LUK);
  8825. // abort currently running script
  8826. sd->state.using_fake_npc = 0;
  8827. sd->state.menu_or_input = 0;
  8828. sd->npc_menu = 0;
  8829. if(sd->npc_id)
  8830. npc_event_dequeue(sd);
  8831. }
  8832. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8833. #if PACKETVER >= 20070918
  8834. clif_partyinvitationstate(sd);
  8835. clif_equipcheckbox(sd);
  8836. #endif
  8837. #ifdef VIP_ENABLE
  8838. if (!sd->disableshowrate) {
  8839. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8840. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8841. }
  8842. #endif
  8843. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8844. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8845. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8846. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8847. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8848. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8849. { //Display night.
  8850. if( !sd->state.night )
  8851. {
  8852. sd->state.night = 1;
  8853. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8854. }
  8855. }
  8856. else if( sd->state.night )
  8857. { //Clear night display.
  8858. sd->state.night = 0;
  8859. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8860. }
  8861. if( map[sd->bl.m].flag.battleground )
  8862. {
  8863. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8864. if( map[sd->bl.m].flag.battleground == 2 )
  8865. clif_bg_updatescore_single(sd);
  8866. }
  8867. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8868. {
  8869. char output[128];
  8870. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8871. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8872. }
  8873. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8874. map[sd->bl.m].hpmeter_visible++;
  8875. sd->state.hpmeter_visible = 1;
  8876. }
  8877. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  8878. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8879. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8880. sd->state.changemap = false;
  8881. // Instances do not need their own channels
  8882. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8883. channel_mjoin(sd); //join new map
  8884. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8885. clif_guild_notice(sd, sd->guild); // Displays at end
  8886. mail_clear(sd);
  8887. clif_maptypeproperty2(&sd->bl,SELF);
  8888. /* Guild Aura Init */
  8889. if( sd->state.gmaster_flag ) {
  8890. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8891. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8892. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8893. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8894. }
  8895. if( sd->state.vending ) { /* show we have a vending */
  8896. clif_openvending(sd,sd->bl.id,sd->vending);
  8897. clif_showvendingboard(&sd->bl,sd->message,0);
  8898. }
  8899. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8900. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8901. npc_script_event(sd, NPCE_LOADMAP);
  8902. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  8903. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8904. if (sd->sc.opt2) //Client loses these on warp.
  8905. clif_changeoption(&sd->bl);
  8906. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8907. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8908. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8909. }
  8910. clif_weather_check(sd);
  8911. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8912. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8913. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8914. else
  8915. sd->areanpc_id = 0;
  8916. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8917. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8918. pc_setdead(sd);
  8919. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8920. if(pc_isdead(sd))
  8921. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8922. else {
  8923. skill_usave_trigger(sd);
  8924. if (battle_config.spawn_direction)
  8925. clif_changed_dir(&sd->bl, SELF);
  8926. }
  8927. // Trigger skill effects if you appear standing on them
  8928. if(!battle_config.pc_invincible_time)
  8929. skill_unit_move(&sd->bl,gettick(),1);
  8930. pc_show_questinfo_reinit(sd);
  8931. pc_show_questinfo(sd);
  8932. }
  8933. /// Server's tick (ZC_NOTIFY_TIME).
  8934. /// 007f <time>.L
  8935. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8936. {
  8937. int fd = sd->fd;
  8938. WFIFOHEAD(fd,packet_len(0x7f));
  8939. WFIFOW(fd,0) = 0x7f;
  8940. WFIFOL(fd,2) = time;
  8941. WFIFOSET(fd,packet_len(0x7f));
  8942. }
  8943. /// Request for server's tick.
  8944. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8945. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8946. /// There are various variants of this packet, some of them have padding between fields.
  8947. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8948. {
  8949. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8950. clif_notify_time(sd, gettick());
  8951. }
  8952. /// Sends hotkey bar.
  8953. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8954. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8955. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8956. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8957. void clif_hotkeys_send(struct map_session_data *sd) {
  8958. #ifdef HOTKEY_SAVING
  8959. const int fd = sd->fd;
  8960. int i;
  8961. int offset = 2;
  8962. #if PACKETVER < 20090603
  8963. const int cmd = 0x2b9;
  8964. #elif PACKETVER < 20141022
  8965. const int cmd = 0x7d9;
  8966. #else
  8967. char Rotate = sd->status.hotkey_rowshift;
  8968. const int cmd = 0xa00;
  8969. offset = 3;
  8970. #endif
  8971. if (!fd) return;
  8972. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8973. WFIFOW(fd, 0) = cmd;
  8974. #if PACKETVER >= 20141022
  8975. WFIFOB(fd, 2) = Rotate;
  8976. #endif
  8977. for(i = 0; i < MAX_HOTKEYS; i++) {
  8978. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8979. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8980. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8981. }
  8982. WFIFOSET(fd, packet_len(cmd));
  8983. #endif
  8984. }
  8985. /// Request to update a position on the hotkey row bar
  8986. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  8987. int cmd = RFIFOW(fd, 0);
  8988. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8989. }
  8990. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8991. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8992. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8993. #ifdef HOTKEY_SAVING
  8994. unsigned short idx;
  8995. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8996. idx = RFIFOW(fd, info->pos[0]);
  8997. if (idx >= MAX_HOTKEYS) return;
  8998. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8999. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9000. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9001. #endif
  9002. }
  9003. /// Displays cast-like progress bar (ZC_PROGRESS).
  9004. /// 02f0 <color>.L <time>.L
  9005. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9006. {
  9007. int fd = sd->fd;
  9008. WFIFOHEAD(fd,packet_len(0x2f0));
  9009. WFIFOW(fd,0) = 0x2f0;
  9010. WFIFOL(fd,2) = color;
  9011. WFIFOL(fd,6) = second;
  9012. WFIFOSET(fd,packet_len(0x2f0));
  9013. }
  9014. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9015. /// 02f2
  9016. void clif_progressbar_abort(struct map_session_data * sd)
  9017. {
  9018. int fd = sd->fd;
  9019. WFIFOHEAD(fd,packet_len(0x2f2));
  9020. WFIFOW(fd,0) = 0x2f2;
  9021. WFIFOSET(fd,packet_len(0x2f2));
  9022. }
  9023. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9024. /// 02f1
  9025. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9026. {
  9027. int npc_id = sd->progressbar.npc_id;
  9028. if( gettick() < sd->progressbar.timeout && sd->st )
  9029. sd->st->state = END;
  9030. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9031. npc_scriptcont(sd, npc_id, false);
  9032. }
  9033. /// Request to walk to a certain position on the current map.
  9034. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9035. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9036. /// There are various variants of this packet, some of them have padding between fields.
  9037. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9038. {
  9039. short x, y;
  9040. if (pc_isdead(sd)) {
  9041. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9042. return;
  9043. }
  9044. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9045. ; //You CAN walk on this OPT1 value.
  9046. else if( sd->progressbar.npc_id )
  9047. clif_progressbar_abort(sd);
  9048. else if (pc_cant_act(sd))
  9049. return;
  9050. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9051. return;
  9052. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9053. //A move command one cell west is only valid if the target cell is free
  9054. if(battle_config.official_cell_stack_limit > 0
  9055. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9056. return;
  9057. // Cloaking wall check is actually updated when you click to process next movement
  9058. // not when you move each cell. This is official behaviour.
  9059. if (sd->sc.data[SC_CLOAKING])
  9060. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9061. pc_delinvincibletimer(sd);
  9062. //Set last idle time... [Skotlex]
  9063. if (battle_config.idletime_option&IDLE_WALK)
  9064. sd->idletime = last_tick;
  9065. unit_walktoxy(&sd->bl, x, y, 4);
  9066. }
  9067. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9068. /// 018b <result>.W
  9069. /// result:
  9070. /// 0 = disconnect (quit)
  9071. /// 1 = cannot disconnect (wait 10 seconds)
  9072. /// ? = ignored
  9073. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9074. {
  9075. int fd = sd->fd;
  9076. WFIFOHEAD(fd,packet_len(0x18b));
  9077. WFIFOW(fd,0) = 0x18b;
  9078. WFIFOW(fd,2) = result;
  9079. WFIFOSET(fd,packet_len(0x18b));
  9080. }
  9081. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9082. /// 018a <type>.W
  9083. /// type:
  9084. /// 0 = quit
  9085. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9086. {
  9087. /* Rovert's prevent logout option fixed [Valaris] */
  9088. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9089. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9090. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9091. {
  9092. set_eof(fd);
  9093. pc_damage_log_clear(sd,0);
  9094. clif_disconnect_ack(sd, 0);
  9095. } else {
  9096. clif_disconnect_ack(sd, 1);
  9097. }
  9098. }
  9099. /// Requesting unit's name.
  9100. /// 0094 <id>.L (CZ_REQNAME)
  9101. /// 0368 <id>.L (CZ_REQNAME2)
  9102. /// There are various variants of this packet, some of them have padding between fields.
  9103. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9104. {
  9105. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9106. struct block_list* bl;
  9107. //struct status_change *sc;
  9108. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9109. id = sd->bl.id;
  9110. bl = map_id2bl(id);
  9111. if( bl == NULL )
  9112. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9113. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9114. return; // Block namerequests past view range
  9115. // 'see people in GM hide' cheat detection
  9116. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9117. sc = status_get_sc(bl);
  9118. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9119. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9120. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9121. ) {
  9122. char gm_msg[256];
  9123. 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);
  9124. ShowWarning(gm_msg);
  9125. // information is sent to all online GMs
  9126. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9127. return;
  9128. }
  9129. */
  9130. clif_charnameack(fd, bl);
  9131. }
  9132. /// Validates and processes global messages
  9133. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9134. /// There are various variants of this packet.
  9135. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9136. {
  9137. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9138. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  9139. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  9140. char *name, *message, *fakename = NULL;
  9141. int namelen, messagelen;
  9142. bool is_fake;
  9143. // validate packet and retrieve name and message
  9144. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9145. return;
  9146. if( is_atcommand(fd, sd, message, 1) )
  9147. return;
  9148. if (sd->sc.cant.chat)
  9149. return; //no "chatting" while muted.
  9150. if( battle_config.min_chat_delay ) { //[Skotlex]
  9151. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9152. return;
  9153. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9154. }
  9155. if (battle_config.idletime_option&IDLE_CHAT)
  9156. sd->idletime = last_tick;
  9157. if( sd->gcbind ) {
  9158. channel_send(sd->gcbind,sd,message);
  9159. return;
  9160. }
  9161. /**
  9162. * Fake Name Design by FatalEror (bug report #9)
  9163. **/
  9164. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  9165. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  9166. strcpy(fakename, sd->fakename);
  9167. strcat(fakename, " : ");
  9168. strcat(fakename, message);
  9169. textlen = strlen(fakename) + 1;
  9170. }
  9171. // send message to others (using the send buffer for temp. storage)
  9172. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9173. // send back message to the speaker
  9174. if( is_fake ) {
  9175. WFIFOW(fd,0) = 0x8e;
  9176. WFIFOW(fd,2) = textlen + 4;
  9177. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  9178. aFree(fakename);
  9179. } else {
  9180. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  9181. WFIFOW(fd,0) = 0x8e;
  9182. }
  9183. WFIFOSET(fd, WFIFOW(fd,2));
  9184. #ifdef PCRE_SUPPORT
  9185. // trigger listening npcs
  9186. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  9187. #endif
  9188. // Chat logging type 'O' / Global Chat
  9189. 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);
  9190. }
  9191. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9192. /// Request to warp to a map on given coordinates.
  9193. /// 0140 <map name>.16B <x>.W <y>.W
  9194. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9195. {
  9196. char command[MAP_NAME_LENGTH_EXT+25];
  9197. char* map_name;
  9198. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9199. map_name = (char*)RFIFOP(fd,info->pos[0]);
  9200. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9201. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9202. RFIFOW(fd,info->pos[1]), //x
  9203. RFIFOW(fd,info->pos[2])); //y
  9204. is_atcommand(fd, sd, command, 1);
  9205. }
  9206. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9207. /// 009c <id>.L <head dir>.W <dir>.B
  9208. /// head dir:
  9209. /// 0 = straight
  9210. /// 1 = turned CW
  9211. /// 2 = turned CCW
  9212. /// dir:
  9213. /// 0 = north
  9214. /// 1 = northwest
  9215. /// 2 = west
  9216. /// 3 = southwest
  9217. /// 4 = south
  9218. /// 5 = southeast
  9219. /// 6 = east
  9220. /// 7 = northeast
  9221. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9222. {
  9223. unsigned char buf[64];
  9224. WBUFW(buf,0) = 0x9c;
  9225. WBUFL(buf,2) = bl->id;
  9226. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9227. WBUFB(buf,8) = unit_getdir(bl);
  9228. clif_send(buf, packet_len(0x9c), bl, target);
  9229. if (disguised(bl)) {
  9230. WBUFL(buf,2) = -bl->id;
  9231. WBUFW(buf,6) = 0;
  9232. clif_send(buf, packet_len(0x9c), bl, SELF);
  9233. }
  9234. }
  9235. /// Request to change own body and head direction.
  9236. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9237. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9238. /// There are various variants of this packet, some of them have padding between fields.
  9239. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9240. {
  9241. unsigned char headdir, dir;
  9242. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9243. headdir = RFIFOB(fd,info->pos[0]);
  9244. dir = RFIFOB(fd,info->pos[1]);
  9245. pc_setdir(sd, dir, headdir);
  9246. clif_changed_dir(&sd->bl, AREA_WOS);
  9247. }
  9248. /// Request to show an emotion (CZ_REQ_EMOTION).
  9249. /// 00bf <type>.B
  9250. /// type:
  9251. /// @see enum emotion_type
  9252. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9253. {
  9254. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9255. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  9256. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9257. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9258. return;
  9259. }
  9260. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9261. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9262. sd->emotionlasttime = time(NULL);
  9263. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9264. return;
  9265. }
  9266. sd->emotionlasttime = time(NULL);
  9267. if (battle_config.idletime_option&IDLE_EMOTION)
  9268. sd->idletime = last_tick;
  9269. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9270. emoticon = rnd()%6+E_DICE1;
  9271. }
  9272. clif_emotion(&sd->bl, emoticon);
  9273. } else
  9274. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9275. }
  9276. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9277. /// 00c2 <count>.L
  9278. void clif_user_count(struct map_session_data* sd, int count)
  9279. {
  9280. int fd = sd->fd;
  9281. WFIFOHEAD(fd,packet_len(0xc2));
  9282. WFIFOW(fd,0) = 0xc2;
  9283. WFIFOL(fd,2) = count;
  9284. WFIFOSET(fd,packet_len(0xc2));
  9285. }
  9286. /// /w /who (CZ_REQ_USER_COUNT).
  9287. /// Request to display amount of currently connected players.
  9288. /// 00c1
  9289. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9290. {
  9291. clif_user_count(sd, map_getusers());
  9292. }
  9293. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9294. {
  9295. if (pc_isdead(sd)) {
  9296. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9297. return;
  9298. }
  9299. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9300. // (not all are included in pc_can_attack)
  9301. if (sd->sc.count &&
  9302. (sd->sc.data[SC_TRICKDEAD] ||
  9303. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9304. sd->sc.data[SC_BLADESTOP] ||
  9305. sd->sc.data[SC__MANHOLE] ))
  9306. return;
  9307. if(action_type != 0x00 && action_type != 0x07)
  9308. pc_stop_walking(sd, 1);
  9309. pc_stop_attack(sd);
  9310. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9311. target_id = sd->bl.id;
  9312. switch(action_type)
  9313. {
  9314. case 0x00: // once attack
  9315. case 0x07: // continuous attack
  9316. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9317. return;
  9318. if( sd->sc.option&OPTION_COSTUME )
  9319. return;
  9320. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9321. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9322. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9323. return;
  9324. }
  9325. }
  9326. pc_delinvincibletimer(sd);
  9327. if (battle_config.idletime_option&IDLE_ATTACK)
  9328. sd->idletime = last_tick;
  9329. unit_attack(&sd->bl, target_id, action_type != 0);
  9330. break;
  9331. case 0x02: // sitdown
  9332. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  9333. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9334. break;
  9335. }
  9336. if(pc_issit(sd)) {
  9337. //Bugged client? Just refresh them.
  9338. clif_sitting(&sd->bl);
  9339. return;
  9340. }
  9341. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9342. break;
  9343. if (sd->sc.count && (
  9344. sd->sc.data[SC_DANCING] ||
  9345. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9346. )) //No sitting during these states either.
  9347. break;
  9348. if (battle_config.idletime_option&IDLE_SIT)
  9349. sd->idletime = last_tick;
  9350. pc_setsit(sd);
  9351. skill_sit(sd, 1);
  9352. clif_sitting(&sd->bl);
  9353. break;
  9354. case 0x03: // standup
  9355. if (!pc_issit(sd)) {
  9356. //Bugged client? Just refresh them.
  9357. clif_standing(&sd->bl);
  9358. return;
  9359. }
  9360. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9361. break;
  9362. if (pc_setstand(sd, false)) {
  9363. if (battle_config.idletime_option&IDLE_SIT)
  9364. sd->idletime = last_tick;
  9365. skill_sit(sd, 0);
  9366. clif_standing(&sd->bl);
  9367. }
  9368. break;
  9369. }
  9370. }
  9371. /// Request for an action.
  9372. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9373. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9374. /// action:
  9375. /// 0 = attack
  9376. /// 1 = pick up item
  9377. /// 2 = sit down
  9378. /// 3 = stand up
  9379. /// 7 = continous attack
  9380. /// 12 = (touch skill?)
  9381. /// There are various variants of this packet, some of them have padding between fields.
  9382. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9383. {
  9384. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9385. clif_parse_ActionRequest_sub(sd,
  9386. RFIFOB(fd,info->pos[1]),
  9387. RFIFOL(fd,info->pos[0]),
  9388. gettick()
  9389. );
  9390. }
  9391. /// Response to the death/system menu (CZ_RESTART).
  9392. /// 00b2 <type>.B
  9393. /// type:
  9394. /// 0 = restart (respawn)
  9395. /// 1 = char-select (disconnect)
  9396. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9397. {
  9398. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9399. case 0x00:
  9400. pc_respawn(sd,CLR_OUTSIGHT);
  9401. break;
  9402. case 0x01:
  9403. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9404. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9405. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9406. { //Send to char-server for character selection.
  9407. pc_damage_log_clear(sd,0);
  9408. chrif_charselectreq(sd, session[fd]->client_addr);
  9409. } else {
  9410. clif_disconnect_ack(sd, 1);
  9411. }
  9412. break;
  9413. }
  9414. }
  9415. /// Validates and processes whispered messages (CZ_WHISPER).
  9416. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9417. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9418. {
  9419. struct map_session_data* dstsd;
  9420. int i;
  9421. char *target, *message;
  9422. int namelen, messagelen;
  9423. // validate packet and retrieve name and message
  9424. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9425. return;
  9426. if ( is_atcommand(fd, sd, message, 1) )
  9427. return;
  9428. if (sd->sc.cant.chat)
  9429. return; //no "chatting" while muted.
  9430. if (battle_config.min_chat_delay) { //[Skotlex]
  9431. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9432. return;
  9433. }
  9434. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9435. }
  9436. if (battle_config.idletime_option&IDLE_CHAT)
  9437. sd->idletime = last_tick;
  9438. // Chat logging type 'W' / Whisper
  9439. 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);
  9440. //-------------------------------------------------------//
  9441. // Lordalfa - Paperboy - To whisper NPC commands //
  9442. //-------------------------------------------------------//
  9443. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9444. {
  9445. char* str = target+4; //Skip the NPC: string part.
  9446. struct npc_data* npc;
  9447. if ((npc = npc_name2id(str))) {
  9448. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9449. char *split;
  9450. char output[256];
  9451. str = message;
  9452. // skip codepage indicator, if detected
  9453. if( str[0] == '|' && strlen(str) >= 4 )
  9454. str += 3;
  9455. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9456. split = strchr(str,'#');
  9457. if( split == NULL ) { // use the remaining string
  9458. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9459. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9460. split_data[i][0] = '\0';
  9461. break;
  9462. }
  9463. *split = '\0';
  9464. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9465. str = split+1;
  9466. }
  9467. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9468. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9469. set_var(sd,output,(char *) split_data[i]);
  9470. }
  9471. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9472. npc_event(sd,output,0); // Calls the NPC label
  9473. return;
  9474. }
  9475. } else if( target[0] == '#' ) {
  9476. struct Channel *channel = NULL;
  9477. char* chname = target;
  9478. channel = channel_name2channel(chname,sd,3);
  9479. if(channel){
  9480. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9481. channel_send(channel,sd,message);
  9482. }
  9483. else if( channel->pass[0] == '\0') { //no pass needed
  9484. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9485. }
  9486. else {
  9487. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9488. }
  9489. return;
  9490. }
  9491. }
  9492. // searching destination character
  9493. dstsd = map_nick2sd(target);
  9494. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9495. // player is not on this map-server
  9496. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9497. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9498. // and if we ask for 'Test', we must not contact 'test' player
  9499. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9500. intif_wis_message(sd, target, message, messagelen);
  9501. return;
  9502. }
  9503. // if player ignores everyone
  9504. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9505. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9506. clif_wis_end(fd, 1); // 1: target character is not logged in
  9507. else
  9508. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9509. return;
  9510. }
  9511. // if player is autotrading
  9512. if (dstsd->state.autotrade == 1) {
  9513. char output[256];
  9514. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9515. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9516. return;
  9517. }
  9518. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9519. // if player ignores the source character
  9520. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9521. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9522. clif_wis_end(fd, 2); // 2: ignored by target
  9523. return;
  9524. }
  9525. }
  9526. // notify sender of success
  9527. clif_wis_end(fd, 0); // 0: success to send wisper
  9528. // Normal message
  9529. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9530. }
  9531. /// /b /nb (CZ_BROADCAST).
  9532. /// Request to broadcast a message on whole server.
  9533. /// 0099 <packet len>.W <text>.?B 00
  9534. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9535. char command[CHAT_SIZE_MAX+11];
  9536. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9537. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9538. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9539. // as the length varies depending on the command used, just block unreasonably long strings
  9540. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9541. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9542. is_atcommand(fd, sd, command, 1);
  9543. }
  9544. /// Request to pick up an item.
  9545. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9546. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9547. /// There are various variants of this packet, some of them have padding between fields.
  9548. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9549. {
  9550. struct flooritem_data *fitem;
  9551. int map_object_id;
  9552. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9553. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9554. do {
  9555. if (pc_isdead(sd)) {
  9556. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9557. break;
  9558. }
  9559. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9560. break;
  9561. if (pc_cant_act(sd))
  9562. break;
  9563. if (!pc_takeitem(sd, fitem))
  9564. break;
  9565. return;
  9566. } while (0);
  9567. // Client REQUIRES a fail packet or you can no longer pick items.
  9568. clif_additem(sd,0,0,6);
  9569. }
  9570. /// Request to drop an item.
  9571. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9572. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9573. /// There are various variants of this packet, some of them have padding between fields.
  9574. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9575. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9576. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9577. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9578. for(;;) {
  9579. if (pc_isdead(sd))
  9580. break;
  9581. if (pc_cant_act2(sd) || sd->npc_id)
  9582. break;
  9583. if (sd->sc.count && (
  9584. sd->sc.data[SC_AUTOCOUNTER] ||
  9585. sd->sc.data[SC_BLADESTOP] ||
  9586. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9587. ))
  9588. break;
  9589. if (!pc_dropitem(sd, item_index, item_amount))
  9590. break;
  9591. if (battle_config.idletime_option&IDLE_DROPITEM)
  9592. sd->idletime = last_tick;
  9593. return;
  9594. }
  9595. //Because the client does not like being ignored.
  9596. clif_dropitem(sd, item_index,0);
  9597. }
  9598. /// Request to use an item.
  9599. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9600. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9601. /// There are various variants of this packet, some of them have padding between fields.
  9602. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9603. {
  9604. int n;
  9605. if (pc_isdead(sd)) {
  9606. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9607. return;
  9608. }
  9609. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9610. return;
  9611. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9612. if (battle_config.idletime_option&IDLE_USEITEM)
  9613. sd->idletime = last_tick;
  9614. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9615. if(n <0 || n >= MAX_INVENTORY)
  9616. return;
  9617. if (!pc_useitem(sd,n))
  9618. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9619. }
  9620. /// Request to equip an item
  9621. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9622. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9623. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9624. {
  9625. int index;
  9626. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9627. if(pc_isdead(sd)) {
  9628. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9629. return;
  9630. }
  9631. index = RFIFOW(fd,info->pos[0])-2;
  9632. if (index < 0 || index >= MAX_INVENTORY)
  9633. return; //Out of bounds check.
  9634. if(sd->npc_id && !sd->npc_item_flag) {
  9635. return;
  9636. } else if (sd->state.storage_flag || sd->sc.opt1)
  9637. ; //You can equip/unequip stuff while storage is open/under status changes
  9638. else if (pc_cant_act2(sd))
  9639. return;
  9640. if(!sd->status.inventory[index].identify) {
  9641. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9642. return;
  9643. }
  9644. if(!sd->inventory_data[index])
  9645. return;
  9646. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9647. pet_equipitem(sd,index);
  9648. return;
  9649. }
  9650. if (battle_config.idletime_option&IDLE_USEITEM)
  9651. sd->idletime = last_tick;
  9652. //Client doesn't send the position for ammo.
  9653. if(sd->inventory_data[index]->type == IT_AMMO)
  9654. pc_equipitem(sd,index,EQP_AMMO);
  9655. else {
  9656. int req_pos;
  9657. #if PACKETVER >= 20120925
  9658. req_pos = RFIFOL(fd,info->pos[1]);
  9659. #else
  9660. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9661. #endif
  9662. pc_equipitem(sd,index,req_pos);
  9663. }
  9664. }
  9665. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9666. /// 00ab <index>.W
  9667. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9668. {
  9669. int index;
  9670. if(pc_isdead(sd)) {
  9671. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9672. return;
  9673. }
  9674. if (sd->npc_id && !sd->npc_item_flag) {
  9675. return;
  9676. } else if (sd->state.storage_flag || sd->sc.opt1)
  9677. ; //You can equip/unequip stuff while storage is open/under status changes
  9678. else if (pc_cant_act2(sd))
  9679. return;
  9680. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9681. if (battle_config.idletime_option&IDLE_USEITEM)
  9682. sd->idletime = last_tick;
  9683. pc_unequipitem(sd,index,1);
  9684. }
  9685. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9686. /// 0090 <id>.L <type>.B
  9687. /// type:
  9688. /// 1 = click
  9689. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9690. {
  9691. struct block_list *bl;
  9692. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9693. if(pc_isdead(sd)) {
  9694. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9695. return;
  9696. }
  9697. if (pc_cant_act2(sd) || sd->npc_id)
  9698. return;
  9699. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9700. //type = RFIFOB(fd,info->pos[1]);
  9701. if (!bl) return;
  9702. switch (bl->type) {
  9703. case BL_MOB:
  9704. case BL_PC:
  9705. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9706. break;
  9707. case BL_NPC:
  9708. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9709. npc_click(sd,(TBL_NPC*)bl);
  9710. break;
  9711. }
  9712. }
  9713. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9714. /// 00c5 <id>.L <type>.B
  9715. /// type:
  9716. /// 0 = buy
  9717. /// 1 = sell
  9718. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9719. {
  9720. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9721. if (sd->state.trading)
  9722. return;
  9723. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9724. }
  9725. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9726. /// 00ca <result>.B
  9727. /// result:
  9728. /// 0 = "The deal has successfully completed."
  9729. /// 1 = "You do not have enough zeny."
  9730. /// 2 = "You are over your Weight Limit."
  9731. /// 3 = "Out of the maximum capacity, you have too many items."
  9732. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9733. {
  9734. int fd = sd->fd;
  9735. WFIFOHEAD(fd,packet_len(0xca));
  9736. WFIFOW(fd,0) = 0xca;
  9737. WFIFOB(fd,2) = result;
  9738. WFIFOSET(fd,packet_len(0xca));
  9739. }
  9740. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9741. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9742. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9743. {
  9744. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9745. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9746. int result;
  9747. if( sd->state.trading || !sd->npc_shopid )
  9748. result = 1;
  9749. else
  9750. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9751. sd->npc_shopid = 0; //Clear shop data.
  9752. clif_npc_buy_result(sd, result);
  9753. }
  9754. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9755. /// 00cb <result>.B
  9756. /// result:
  9757. /// 0 = "The deal has successfully completed."
  9758. /// 1 = "The deal has failed."
  9759. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9760. {
  9761. int fd = sd->fd;
  9762. WFIFOHEAD(fd,packet_len(0xcb));
  9763. WFIFOW(fd,0) = 0xcb;
  9764. WFIFOB(fd,2) = result;
  9765. WFIFOSET(fd,packet_len(0xcb));
  9766. }
  9767. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9768. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9769. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9770. {
  9771. int fail=0,n;
  9772. unsigned short *item_list;
  9773. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9774. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9775. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9776. if (sd->state.trading || !sd->npc_shopid)
  9777. fail = 1;
  9778. else
  9779. fail = npc_selllist(sd,n,item_list);
  9780. sd->npc_shopid = 0; //Clear shop data.
  9781. clif_npc_sell_result(sd, fail);
  9782. }
  9783. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9784. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9785. /// type:
  9786. /// 0 = private
  9787. /// 1 = public
  9788. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9789. {
  9790. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9791. int len = RFIFOW(fd,info->pos[0])-15;
  9792. int limit = RFIFOW(fd,info->pos[1]);
  9793. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9794. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9795. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9796. char s_password[CHATROOM_PASS_SIZE];
  9797. char s_title[CHATROOM_TITLE_SIZE];
  9798. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9799. return;
  9800. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9801. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9802. return;
  9803. }
  9804. if( npc_isnear(&sd->bl) ) {
  9805. // uncomment to send msg_txt.
  9806. //char output[150];
  9807. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9808. //clif_displaymessage(sd->fd, output);
  9809. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9810. return;
  9811. }
  9812. if( len <= 0 )
  9813. return; // invalid input
  9814. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9815. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9816. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9817. }
  9818. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9819. /// 00d9 <chat ID>.L <passwd>.8B
  9820. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9821. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9822. int chatid = RFIFOL(fd,info->pos[0]);
  9823. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9824. chat_joinchat(sd,chatid,password);
  9825. }
  9826. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9827. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9828. /// type:
  9829. /// 0 = private
  9830. /// 1 = public
  9831. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9832. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9833. int len = RFIFOW(fd,info->pos[0])-15;
  9834. int limit = RFIFOW(fd,info->pos[1]);
  9835. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9836. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9837. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9838. char s_password[CHATROOM_PASS_SIZE];
  9839. char s_title[CHATROOM_TITLE_SIZE];
  9840. if( len <= 0 )
  9841. return; // invalid input
  9842. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9843. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9844. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9845. }
  9846. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9847. /// 00e0 <role>.L <nick>.24B
  9848. /// role:
  9849. /// 0 = owner
  9850. /// 1 = normal
  9851. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9852. {
  9853. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9854. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9855. }
  9856. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9857. /// 00e2 <name>.24B
  9858. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9859. {
  9860. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9861. }
  9862. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9863. /// 00e3
  9864. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9865. {
  9866. chat_leavechat(sd,0);
  9867. }
  9868. //Handles notifying asker and rejecter of what has just ocurred.
  9869. //Type is used to determine the correct msg_txt to use:
  9870. //0:
  9871. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9872. {
  9873. const char* msg;
  9874. char output[256];
  9875. // Your request has been rejected by autoreject option.
  9876. msg = msg_txt(sd,392);
  9877. clif_disp_onlyself(sd, msg, strlen(msg));
  9878. //Notice that a request was rejected.
  9879. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9880. clif_disp_onlyself(tsd, output, strlen(output));
  9881. }
  9882. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9883. /// 00e4 <account id>.L
  9884. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9885. {
  9886. struct map_session_data *t_sd;
  9887. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9888. if(!sd->chatID && pc_cant_act(sd))
  9889. return; //You can trade while in a chatroom.
  9890. // @noask [LuzZza]
  9891. if(t_sd && t_sd->state.noask) {
  9892. clif_noask_sub(sd, t_sd, 0);
  9893. return;
  9894. }
  9895. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9896. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9897. return;
  9898. }
  9899. trade_traderequest(sd,t_sd);
  9900. }
  9901. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9902. /// 00e6 <result>.B
  9903. /// result:
  9904. /// 3 = accepted
  9905. /// 4 = rejected
  9906. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9907. {
  9908. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9909. }
  9910. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9911. /// 00e8 <index>.W <amount>.L
  9912. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9913. {
  9914. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9915. short index = RFIFOW(fd,info->pos[0]);
  9916. int amount = RFIFOL(fd,info->pos[1]);
  9917. if( index == 0 )
  9918. trade_tradeaddzeny(sd, amount);
  9919. else
  9920. trade_tradeadditem(sd, index, (short)amount);
  9921. }
  9922. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9923. /// 00eb
  9924. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9925. {
  9926. trade_tradeok(sd);
  9927. }
  9928. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9929. /// 00ed
  9930. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9931. {
  9932. trade_tradecancel(sd);
  9933. }
  9934. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9935. /// 00ef
  9936. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9937. {
  9938. trade_tradecommit(sd);
  9939. }
  9940. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9941. /// 0118
  9942. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9943. {
  9944. pc_stop_attack(sd);
  9945. }
  9946. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9947. /// 0126 <index>.W <amount>.L
  9948. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9949. {
  9950. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9951. if (pc_istrading(sd))
  9952. return;
  9953. if (!pc_iscarton(sd))
  9954. return;
  9955. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9956. }
  9957. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9958. /// 0127 <index>.W <amount>.L
  9959. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9960. {
  9961. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9962. if (!pc_iscarton(sd))
  9963. return;
  9964. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9965. }
  9966. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9967. /// 012a
  9968. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9969. {
  9970. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9971. #ifdef NEW_CARTS
  9972. && sd->sc.data[SC_PUSH_CART] )
  9973. pc_setcart(sd,0);
  9974. #else
  9975. )
  9976. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9977. #endif
  9978. else // priority to remove this option before we can clear cart
  9979. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9980. }
  9981. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  9982. /// 097f <Length>.W <identity>.L <type>.B
  9983. void clif_SelectCart(struct map_session_data *sd) {
  9984. #if PACKETVER >= 20150826
  9985. int i = 0, carts = 3;
  9986. int fd = sd->fd;
  9987. WFIFOHEAD(fd,8 + carts);
  9988. WFIFOW(fd,0) = 0x97f;
  9989. WFIFOW(fd,2) = 8 + carts;
  9990. WFIFOL(fd,4) = sd->status.account_id;
  9991. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  9992. for( i = 0; i < carts; i++ ) {
  9993. WFIFOB(fd,8 + i) = 10 + i;
  9994. }
  9995. WFIFOSET(fd,8 + carts);
  9996. #endif
  9997. }
  9998. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  9999. /// 0980 <identity>.L <type>.B
  10000. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10001. #if PACKETVER >= 20150826
  10002. int type;
  10003. // Check identity
  10004. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10005. return;
  10006. type = (int)RFIFOB(fd,6);
  10007. // Check type
  10008. if( type < 10 || type > MAX_CARTS )
  10009. return;
  10010. pc_setcart(sd, type);
  10011. #endif
  10012. }
  10013. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10014. /// 01af <num>.W
  10015. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10016. {// TODO: State tracking?
  10017. int type;
  10018. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10019. return;
  10020. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10021. #ifdef NEW_CARTS
  10022. if( (type == 9 && sd->status.base_level > 131) ||
  10023. (type == 8 && sd->status.base_level > 121) ||
  10024. (type == 7 && sd->status.base_level > 111) ||
  10025. (type == 6 && sd->status.base_level > 101) ||
  10026. (type == 5 && sd->status.base_level > 90) ||
  10027. (type == 4 && sd->status.base_level > 80) ||
  10028. (type == 3 && sd->status.base_level > 65) ||
  10029. (type == 2 && sd->status.base_level > 40) ||
  10030. (type == 1))
  10031. #else
  10032. if( (type == 5 && sd->status.base_level > 90) ||
  10033. (type == 4 && sd->status.base_level > 80) ||
  10034. (type == 3 && sd->status.base_level > 65) ||
  10035. (type == 2 && sd->status.base_level > 40) ||
  10036. (type == 1))
  10037. #endif
  10038. pc_setcart(sd, type);
  10039. }
  10040. /// Request to increase status (CZ_STATUS_CHANGE).
  10041. /// 00bb <status id>.W <amount>.B
  10042. /// status id:
  10043. /// SP_STR ~ SP_LUK
  10044. /// amount:
  10045. /// Old clients always send 1 for this, even when using /str+ and the like.
  10046. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10047. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10048. {
  10049. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10050. if( increase_amount < 0 ) {
  10051. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10052. fd, increase_amount);
  10053. }
  10054. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  10055. }
  10056. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10057. /// 0112 <skill id>.W
  10058. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10059. {
  10060. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10061. }
  10062. 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)
  10063. {
  10064. int lv;
  10065. if( !hd )
  10066. return;
  10067. if( skill_isNotOk_hom(skill_id, hd) ) {
  10068. clif_emotion(&hd->bl, E_DOTS);
  10069. return;
  10070. }
  10071. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10072. target_id = hd->bl.id;
  10073. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10074. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10075. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10076. clif_emotion(&hd->bl, E_DOTS);
  10077. if (hd->master)
  10078. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10079. return;
  10080. }
  10081. lv = hom_checkskill(hd, skill_id);
  10082. if( skill_lv > lv )
  10083. skill_lv = lv;
  10084. if( skill_lv )
  10085. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10086. }
  10087. 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)
  10088. {
  10089. int lv;
  10090. if( !hd )
  10091. return;
  10092. if( skill_isNotOk_hom(skill_id, hd) ) {
  10093. clif_emotion(&hd->bl, E_DOTS);
  10094. return;
  10095. }
  10096. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10097. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10098. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10099. clif_emotion(&hd->bl, E_DOTS);
  10100. if (hd->master)
  10101. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10102. return;
  10103. }
  10104. if( hd->sc.data[SC_BASILICA] )
  10105. return;
  10106. lv = hom_checkskill(hd, skill_id);
  10107. if( skill_lv > lv )
  10108. skill_lv = lv;
  10109. if( skill_lv )
  10110. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10111. }
  10112. 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)
  10113. {
  10114. int lv;
  10115. if( !md )
  10116. return;
  10117. if( skill_isNotOk_mercenary(skill_id, md) )
  10118. return;
  10119. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10120. target_id = md->bl.id;
  10121. if( md->ud.skilltimer != INVALID_TIMER )
  10122. {
  10123. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10124. }
  10125. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10126. return;
  10127. lv = mercenary_checkskill(md, skill_id);
  10128. if( skill_lv > lv )
  10129. skill_lv = lv;
  10130. if( skill_lv )
  10131. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10132. }
  10133. 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)
  10134. {
  10135. int lv;
  10136. if( !md )
  10137. return;
  10138. if( skill_isNotOk_mercenary(skill_id, md) )
  10139. return;
  10140. if( md->ud.skilltimer != INVALID_TIMER )
  10141. return;
  10142. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10143. {
  10144. if (md->master)
  10145. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10146. return;
  10147. }
  10148. if( md->sc.data[SC_BASILICA] )
  10149. return;
  10150. lv = mercenary_checkskill(md, skill_id);
  10151. if( skill_lv > lv )
  10152. skill_lv = lv;
  10153. if( skill_lv )
  10154. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10155. }
  10156. /// Request to use a targeted skill.
  10157. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10158. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10159. /// There are various variants of this packet, some of them have padding between fields.
  10160. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10161. {
  10162. uint16 skill_id, skill_lv;
  10163. int inf,target_id;
  10164. unsigned int tick = gettick();
  10165. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10166. skill_lv = RFIFOW(fd,info->pos[0]);
  10167. skill_id = RFIFOW(fd,info->pos[1]);
  10168. target_id = RFIFOL(fd,info->pos[2]);
  10169. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10170. inf = skill_get_inf(skill_id);
  10171. if (inf&INF_GROUND_SKILL || !inf)
  10172. return; //Using a ground/passive skill on a target? WRONG.
  10173. if( SKILL_CHK_HOMUN(skill_id) ) {
  10174. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10175. return;
  10176. }
  10177. if( SKILL_CHK_MERC(skill_id) ) {
  10178. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10179. return;
  10180. }
  10181. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10182. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10183. sd->idletime = last_tick;
  10184. if( sd->npc_id ){
  10185. #ifdef RENEWAL
  10186. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  10187. return;
  10188. #else
  10189. if( !sd->npc_item_flag || !(inf&INF_SELF_SKILL) )
  10190. return;
  10191. #endif
  10192. }
  10193. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10194. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10195. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10196. return;
  10197. if( pc_issit(sd) )
  10198. return;
  10199. if( skill_isNotOk(skill_id, sd) )
  10200. return;
  10201. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10202. target_id = sd->bl.id; // never trust the client
  10203. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10204. target_id = sd->bl.id;
  10205. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10206. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10207. return;
  10208. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10209. if( sd->skillitem != skill_id ) {
  10210. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10211. return;
  10212. }
  10213. }
  10214. if( sd->sc.option&OPTION_COSTUME )
  10215. return;
  10216. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10217. return; // On basilica only caster can use Basilica again to stop it.
  10218. if( sd->menuskill_id ) {
  10219. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10220. clif_menuskill_clear(sd); //Cancel pet capture.
  10221. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10222. return; //Can't use skills while a menu is open.
  10223. }
  10224. if( sd->skillitem == skill_id ) {
  10225. if( skill_lv != sd->skillitemlv )
  10226. skill_lv = sd->skillitemlv;
  10227. if( !(inf&INF_SELF_SKILL) )
  10228. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10229. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10230. return;
  10231. }
  10232. sd->skillitem = sd->skillitemlv = 0;
  10233. if( SKILL_CHK_GUILD(skill_id) ) {
  10234. if( sd->state.gmaster_flag )
  10235. skill_lv = guild_checkskill(sd->guild, skill_id);
  10236. else
  10237. skill_lv = 0;
  10238. } else {
  10239. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10240. }
  10241. pc_delinvincibletimer(sd);
  10242. if( skill_lv )
  10243. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10244. }
  10245. /*==========================================
  10246. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10247. *------------------------------------------*/
  10248. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10249. {
  10250. unsigned int tick = gettick();
  10251. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10252. return; //Using a target skill on the ground? WRONG.
  10253. if( SKILL_CHK_HOMUN(skill_id) ) {
  10254. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10255. return;
  10256. }
  10257. if( SKILL_CHK_MERC(skill_id) ) {
  10258. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10259. return;
  10260. }
  10261. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10262. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10263. sd->idletime = last_tick;
  10264. if( skill_isNotOk(skill_id, sd) )
  10265. return;
  10266. if( skillmoreinfo != -1 ) {
  10267. if( pc_issit(sd) ) {
  10268. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10269. return;
  10270. }
  10271. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10272. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10273. }
  10274. if( sd->ud.skilltimer != INVALID_TIMER )
  10275. return;
  10276. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10277. if( sd->skillitem != skill_id ) {
  10278. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10279. return;
  10280. }
  10281. }
  10282. if( sd->sc.option&OPTION_COSTUME )
  10283. return;
  10284. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10285. return; // On basilica only caster can use Basilica again to stop it.
  10286. if( sd->menuskill_id ) {
  10287. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10288. clif_menuskill_clear(sd); //Cancel pet capture.
  10289. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10290. return; //Can't use skills while a menu is open.
  10291. }
  10292. pc_delinvincibletimer(sd);
  10293. if( sd->skillitem == skill_id ) {
  10294. if( skill_lv != sd->skillitemlv )
  10295. skill_lv = sd->skillitemlv;
  10296. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10297. } else {
  10298. int lv;
  10299. sd->skillitem = sd->skillitemlv = 0;
  10300. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10301. if( skill_lv > lv )
  10302. skill_lv = lv;
  10303. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10304. }
  10305. }
  10306. }
  10307. /// Request to use a ground skill.
  10308. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10309. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10310. /// There are various variants of this packet, some of them have padding between fields.
  10311. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10312. {
  10313. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10314. if (pc_cant_act(sd))
  10315. return;
  10316. if (pc_issit(sd))
  10317. return;
  10318. clif_parse_UseSkillToPosSub(fd, sd,
  10319. RFIFOW(fd,info->pos[0]), //skill lv
  10320. RFIFOW(fd,info->pos[1]), //skill num
  10321. RFIFOW(fd,info->pos[2]), //pos x
  10322. RFIFOW(fd,info->pos[3]), //pos y
  10323. -1 //Skill more info.
  10324. );
  10325. }
  10326. /// Request to use a ground skill with text.
  10327. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10328. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10329. /// There are various variants of this packet, some of them have padding between fields.
  10330. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10331. {
  10332. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10333. if (pc_cant_act(sd))
  10334. return;
  10335. if (pc_issit(sd))
  10336. return;
  10337. clif_parse_UseSkillToPosSub(fd, sd,
  10338. RFIFOW(fd,info->pos[0]), //Skill lv
  10339. RFIFOW(fd,info->pos[1]), //Skill num
  10340. RFIFOW(fd,info->pos[2]), //pos x
  10341. RFIFOW(fd,info->pos[3]), //pos y
  10342. info->pos[4] //skill more info
  10343. );
  10344. }
  10345. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10346. /// 011b <skill id>.W <map name>.16B
  10347. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10348. {
  10349. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10350. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10351. char map_name[MAP_NAME_LENGTH];
  10352. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10353. if(skill_id != sd->menuskill_id)
  10354. return;
  10355. //It is possible to use teleport with the storage window open bugreport:8027
  10356. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10357. clif_menuskill_clear(sd);
  10358. return;
  10359. }
  10360. pc_delinvincibletimer(sd);
  10361. skill_castend_map(sd,skill_id,map_name);
  10362. }
  10363. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10364. /// 011d
  10365. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10366. {
  10367. if (!pc_isdead(sd))
  10368. pc_memo(sd,-1);
  10369. }
  10370. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10371. /// 018e <name id>.W { <material id>.W }*3
  10372. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10373. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10374. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10375. int slot1 = RFIFOW(fd,info->pos[1]);
  10376. int slot2 = RFIFOW(fd,info->pos[2]);
  10377. int slot3 = RFIFOW(fd,info->pos[3]);
  10378. short produce_idx = -1;
  10379. switch( sd->menuskill_id ) {
  10380. case -1:
  10381. case AM_PHARMACY:
  10382. case RK_RUNEMASTERY:
  10383. case GC_RESEARCHNEWPOISON:
  10384. break;
  10385. default:
  10386. return;
  10387. }
  10388. if (pc_istrading(sd)) {
  10389. //Make it fail to avoid shop exploits where you sell something different than you see.
  10390. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10391. clif_menuskill_clear(sd);
  10392. return;
  10393. }
  10394. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10395. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10396. clif_menuskill_clear(sd);
  10397. }
  10398. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10399. /// 025b <mk type>.W <name id>.W
  10400. /// mk type:
  10401. /// 1 = cooking
  10402. /// 2 = arrow
  10403. /// 3 = elemental
  10404. /// 4 = GN_MIX_COOKING
  10405. /// 5 = GN_MAKEBOMB
  10406. /// 6 = GN_S_PHARMACY
  10407. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10408. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10409. int type = RFIFOW(fd,info->pos[0]);
  10410. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10411. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10412. short food_idx = -1;
  10413. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10414. return;
  10415. if (pc_istrading(sd)) {
  10416. //Make it fail to avoid shop exploits where you sell something different than you see.
  10417. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10418. clif_menuskill_clear(sd);
  10419. return;
  10420. }
  10421. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10422. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10423. clif_menuskill_clear(sd);
  10424. }
  10425. /// Answer to repair weapon item selection dialog
  10426. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10427. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10428. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10429. {
  10430. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10431. return;
  10432. if (pc_istrading(sd)) {
  10433. //Make it fail to avoid shop exploits where you sell something different than you see.
  10434. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10435. clif_menuskill_clear(sd);
  10436. return;
  10437. }
  10438. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10439. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10440. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10441. //for(i = 0; i<MAX_SLOTS; i++)
  10442. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10443. clif_menuskill_clear(sd);
  10444. }
  10445. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10446. /// 0222 <index>.L
  10447. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10448. {
  10449. int idx;
  10450. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10451. return;
  10452. if (pc_istrading(sd)) {
  10453. //Make it fail to avoid shop exploits where you sell something different than you see.
  10454. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10455. clif_menuskill_clear(sd);
  10456. return;
  10457. }
  10458. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10459. skill_weaponrefine(sd, idx-2);
  10460. clif_menuskill_clear(sd);
  10461. }
  10462. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10463. /// 00b8 <npc id>.L <choice>.B
  10464. /// choice:
  10465. /// 1~254 = menu item
  10466. /// 255 = cancel
  10467. /// NOTE: If there were more than 254 items in the list, choice
  10468. /// overflows to choice%256.
  10469. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10470. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10471. int npc_id = RFIFOL(fd,info->pos[0]);
  10472. uint8 select = RFIFOB(fd,info->pos[1]);
  10473. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10474. #ifdef SECURE_NPCTIMEOUT
  10475. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10476. #endif
  10477. TBL_NPC* nd = map_id2nd(npc_id);
  10478. 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);
  10479. clif_GM_kick(NULL,sd);
  10480. #ifdef SECURE_NPCTIMEOUT
  10481. }
  10482. #endif
  10483. return;
  10484. }
  10485. sd->npc_menu = select;
  10486. npc_scriptcont(sd,npc_id, false);
  10487. }
  10488. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10489. /// 00b9 <npc id>.L
  10490. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10491. {
  10492. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10493. }
  10494. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10495. /// 0143 <npc id>.L <value>.L
  10496. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10497. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10498. int npcid = RFIFOL(fd,info->pos[0]);
  10499. int amount = (int)RFIFOL(fd,info->pos[1]);
  10500. sd->npc_amount = amount;
  10501. npc_scriptcont(sd, npcid, false);
  10502. }
  10503. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10504. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10505. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10506. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10507. int message_len = RFIFOW(fd,info->pos[0])-8;
  10508. int npcid = RFIFOL(fd,info->pos[1]);
  10509. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10510. if( message_len <= 0 )
  10511. return; // invalid input
  10512. #if PACKETVER >= 20151001
  10513. message_len++;
  10514. #endif
  10515. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10516. npc_scriptcont(sd, npcid, false);
  10517. }
  10518. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10519. /// 0146 <npc id>.L
  10520. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10521. {
  10522. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10523. return;
  10524. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10525. }
  10526. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10527. /// 0178 <index>.W
  10528. /// index:
  10529. /// -1 = cancel
  10530. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10531. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2;
  10532. if (sd->menuskill_id != MC_IDENTIFY)
  10533. return;
  10534. // Ignore the request
  10535. // - Invalid item index
  10536. // - Invalid item ID or item doesn't exist
  10537. // - Item is already identified
  10538. if (idx < 0 || idx >= MAX_INVENTORY ||
  10539. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10540. sd->status.inventory[idx].identify) {// cancel pressed
  10541. clif_menuskill_clear(sd);
  10542. return;
  10543. }
  10544. skill_identify(sd, idx);
  10545. clif_menuskill_clear(sd);
  10546. }
  10547. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10548. /// 01ae <name id>.W
  10549. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10550. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10551. if (pc_istrading(sd)) {
  10552. //Make it fail to avoid shop exploits where you sell something different than you see.
  10553. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10554. clif_menuskill_clear(sd);
  10555. return;
  10556. }
  10557. switch (sd->menuskill_id) {
  10558. case AC_MAKINGARROW:
  10559. skill_arrow_create(sd,nameid);
  10560. break;
  10561. case SA_CREATECON:
  10562. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10563. break;
  10564. case WL_READING_SB:
  10565. skill_spellbook(sd,nameid);
  10566. break;
  10567. case GC_POISONINGWEAPON:
  10568. skill_poisoningweapon(sd,nameid);
  10569. break;
  10570. case NC_MAGICDECOY:
  10571. skill_magicdecoy(sd,nameid);
  10572. break;
  10573. }
  10574. clif_menuskill_clear(sd);
  10575. }
  10576. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10577. /// 01ce <skill id>.L
  10578. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10579. {
  10580. if (sd->menuskill_id != SA_AUTOSPELL)
  10581. return;
  10582. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10583. clif_menuskill_clear(sd);
  10584. }
  10585. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10586. /// 017a <card index>.W
  10587. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10588. {
  10589. if (sd->state.trading != 0)
  10590. return;
  10591. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10592. }
  10593. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10594. /// 017c <card index>.W <equip index>.W
  10595. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10596. {
  10597. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10598. if (sd->state.trading != 0)
  10599. return;
  10600. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10601. }
  10602. /// Request of character's name by char ID.
  10603. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10604. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10605. /// There are various variants of this packet, some of them have padding between fields.
  10606. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10607. {
  10608. int charid;
  10609. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10610. map_reqnickdb(sd, charid);
  10611. }
  10612. /// /resetskill /resetstate (CZ_RESET).
  10613. /// Request to reset stats or skills.
  10614. /// 0197 <type>.W
  10615. /// type:
  10616. /// 0 = state
  10617. /// 1 = skill
  10618. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10619. char cmd[15];
  10620. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10621. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10622. else
  10623. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10624. is_atcommand(fd, sd, cmd, 1);
  10625. }
  10626. /// /lb /nlb (CZ_LOCALBROADCAST).
  10627. /// Request to broadcast a message on current map.
  10628. /// 019c <packet len>.W <text>.?B
  10629. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10630. {
  10631. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10632. char command[CHAT_SIZE_MAX+16];
  10633. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10634. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10635. // as the length varies depending on the command used, just block unreasonably long strings
  10636. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10637. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10638. is_atcommand(fd, sd, command, 1);
  10639. }
  10640. /// Request to move an item from inventory to storage.
  10641. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10642. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10643. /// There are various variants of this packet, some of them have padding between fields.
  10644. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10645. {
  10646. int item_index, item_amount;
  10647. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10648. if (pc_istrading(sd))
  10649. return;
  10650. item_index = RFIFOW(fd,info->pos[0])-2;
  10651. item_amount = RFIFOL(fd,info->pos[1]);
  10652. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10653. return;
  10654. if (sd->state.storage_flag == 1)
  10655. storage_storageadd(sd, item_index, item_amount);
  10656. else
  10657. if (sd->state.storage_flag == 2)
  10658. gstorage_storageadd(sd, item_index, item_amount);
  10659. }
  10660. /// Request to move an item from storage to inventory.
  10661. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10662. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10663. /// There are various variants of this packet, some of them have padding between fields.
  10664. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10665. {
  10666. int item_index, item_amount;
  10667. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10668. item_index = RFIFOW(fd,info->pos[0])-1;
  10669. item_amount = RFIFOL(fd,info->pos[1]);
  10670. if (sd->state.storage_flag == 1)
  10671. storage_storageget(sd, item_index, item_amount);
  10672. else if(sd->state.storage_flag == 2)
  10673. gstorage_storageget(sd, item_index, item_amount);
  10674. }
  10675. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10676. /// 0129 <index>.W <amount>.L
  10677. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10678. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10679. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10680. int amount = RFIFOL(fd,info->pos[1]);
  10681. if( sd->state.vending )
  10682. return;
  10683. if (!pc_iscarton(sd))
  10684. return;
  10685. if (sd->state.storage_flag == 1)
  10686. storage_storageaddfromcart(sd, idx, amount);
  10687. else if (sd->state.storage_flag == 2)
  10688. gstorage_storageaddfromcart(sd, idx, amount);
  10689. }
  10690. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10691. /// 0128 <index>.W <amount>.L
  10692. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10693. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10694. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10695. int amount = RFIFOL(fd,info->pos[1]);
  10696. if( sd->state.vending )
  10697. return;
  10698. if (!pc_iscarton(sd))
  10699. return;
  10700. if (sd->state.storage_flag == 1)
  10701. storage_storagegettocart(sd, idx, amount);
  10702. else
  10703. if (sd->state.storage_flag == 2)
  10704. gstorage_storagegettocart(sd, idx, amount);
  10705. }
  10706. /// Request to close storage (CZ_CLOSE_STORE).
  10707. /// 00f7
  10708. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10709. {
  10710. if( sd->state.storage_flag == 1 )
  10711. storage_storageclose(sd);
  10712. else
  10713. if( sd->state.storage_flag == 2 )
  10714. gstorage_storageclose(sd);
  10715. }
  10716. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10717. /// 023a <info>.W
  10718. /// info:
  10719. /// 0 = password has not been set yet
  10720. /// 1 = storage is password-protected
  10721. /// 8 = too many wrong passwords
  10722. /// ? = ignored
  10723. /// NOTE: This packet is only available on certain non-kRO clients.
  10724. void clif_storagepassword(struct map_session_data* sd, short info)
  10725. {
  10726. int fd = sd->fd;
  10727. WFIFOHEAD(fd,packet_len(0x23a));
  10728. WFIFOW(fd,0) = 0x23a;
  10729. WFIFOW(fd,2) = info;
  10730. WFIFOSET(fd,packet_len(0x23a));
  10731. }
  10732. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10733. /// 023b <type>.W <password>.16B <new password>.16B
  10734. /// type:
  10735. /// 2 = change password
  10736. /// 3 = check password
  10737. /// NOTE: This packet is only available on certain non-kRO clients.
  10738. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10739. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10740. // int type = RFIFOW(fd,info->pos[0]);
  10741. // char* password = RFIFOP(fd,info->pos[1]);
  10742. // char* new_password = RFIFOP(fd,info->pos[2]);
  10743. // storage_changepass(sd,password,new_password);
  10744. }
  10745. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10746. /// 023c <result>.W <error count>.W
  10747. /// result:
  10748. /// 4 = password change success
  10749. /// 5 = password change failure
  10750. /// 6 = password check success
  10751. /// 7 = password check failure
  10752. /// 8 = too many wrong passwords
  10753. /// ? = ignored
  10754. /// NOTE: This packet is only available on certain non-kRO clients.
  10755. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10756. {
  10757. int fd = sd->fd;
  10758. WFIFOHEAD(fd,packet_len(0x23c));
  10759. WFIFOW(fd,0) = 0x23c;
  10760. WFIFOW(fd,2) = result;
  10761. WFIFOW(fd,4) = error_count;
  10762. WFIFOSET(fd,packet_len(0x23c));
  10763. }
  10764. /// Party creation request
  10765. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10766. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10767. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10768. name[NAME_LENGTH-1] = '\0';
  10769. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10770. clif_displaymessage(fd, msg_txt(sd,227));
  10771. return;
  10772. }
  10773. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10774. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10775. return;
  10776. }
  10777. party_create(sd,name,0,0);
  10778. }
  10779. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10780. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10781. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10782. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10783. int item1 = RFIFOB(fd,info->pos[1]);
  10784. int item2 = RFIFOB(fd,info->pos[2]);
  10785. name[NAME_LENGTH-1] = '\0';
  10786. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10787. clif_displaymessage(fd, msg_txt(sd,227));
  10788. return;
  10789. }
  10790. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10791. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10792. return;
  10793. }
  10794. party_create(sd,name,item1,item2);
  10795. }
  10796. /// Party invitation request
  10797. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10798. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10799. {
  10800. struct map_session_data *t_sd;
  10801. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10802. clif_displaymessage(fd, msg_txt(sd,227));
  10803. return;
  10804. }
  10805. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10806. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10807. clif_noask_sub(sd, t_sd, 1);
  10808. return;
  10809. }
  10810. party_invite(sd, t_sd);
  10811. }
  10812. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10813. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10814. struct map_session_data *t_sd;
  10815. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10816. name[NAME_LENGTH-1] = '\0';
  10817. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10818. clif_displaymessage(fd, msg_txt(sd,227));
  10819. return;
  10820. }
  10821. t_sd = map_nick2sd(name);
  10822. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10823. clif_noask_sub(sd, t_sd, 1);
  10824. return;
  10825. }
  10826. party_invite(sd, t_sd);
  10827. }
  10828. /// Party invitation reply
  10829. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10830. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10831. /// flag:
  10832. /// 0 = reject
  10833. /// 1 = accept
  10834. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10835. {
  10836. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10837. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10838. RFIFOL(fd,info->pos[1]));
  10839. }
  10840. //(CZ_PARTY_JOIN_REQ_ACK)
  10841. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10842. {
  10843. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10844. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10845. RFIFOB(fd,info->pos[1]));
  10846. }
  10847. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10848. /// 0100
  10849. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10850. {
  10851. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10852. clif_displaymessage(fd, msg_txt(sd,227));
  10853. return;
  10854. }
  10855. party_leave(sd);
  10856. }
  10857. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10858. /// 0103 <account id>.L <char name>.24B
  10859. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10860. {
  10861. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10862. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10863. clif_displaymessage(fd, msg_txt(sd,227));
  10864. return;
  10865. }
  10866. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10867. (char*)RFIFOP(fd,info->pos[1]));
  10868. }
  10869. /// Request to change party options.
  10870. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10871. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10872. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10873. {
  10874. struct party_data *p;
  10875. int i,expflag;
  10876. int cmd = RFIFOW(fd,0);
  10877. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10878. if( !sd->status.party_id )
  10879. return;
  10880. p = party_search(sd->status.party_id);
  10881. if( p == NULL )
  10882. return;
  10883. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10884. if( i == MAX_PARTY )
  10885. return; //Shouldn't happen
  10886. if( !p->party.member[i].leader )
  10887. return;
  10888. expflag = RFIFOL(fd,info->pos[0]);
  10889. if(cmd == 0x0102){ //Client can't change the item-field
  10890. party_changeoption(sd, expflag, p->party.item);
  10891. }
  10892. else {
  10893. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10894. party_changeoption(sd, expflag, itemflag);
  10895. }
  10896. }
  10897. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10898. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10899. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10900. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10901. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10902. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10903. char *name, *message;
  10904. int namelen, messagelen;
  10905. #if PACKETVER >= 20151001
  10906. textlen++;
  10907. #endif
  10908. // validate packet and retrieve name and message
  10909. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10910. return;
  10911. if( is_atcommand(fd, sd, message, 1) )
  10912. return;
  10913. if (sd->sc.cant.chat)
  10914. return; //no "chatting" while muted.
  10915. if( battle_config.min_chat_delay )
  10916. { //[Skotlex]
  10917. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10918. return;
  10919. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10920. }
  10921. if (battle_config.idletime_option&IDLE_CHAT)
  10922. sd->idletime = last_tick;
  10923. party_send_message(sd, text, textlen);
  10924. }
  10925. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10926. /// 07da <account id>.L
  10927. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10928. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10929. }
  10930. /// Party Booking in KRO [Spiria]
  10931. ///
  10932. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10933. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10934. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10935. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10936. short level = RFIFOW(fd,info->pos[0]);
  10937. short mapid = RFIFOW(fd,info->pos[1]);
  10938. int idxpbj = info->pos[2];
  10939. short job[MAX_PARTY_BOOKING_JOBS];
  10940. int i;
  10941. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  10942. job[i] = RFIFOB(fd,idxpbj+i*2);
  10943. party_booking_register(sd, level, mapid, job);
  10944. }
  10945. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10946. /// 0803 <result>.W
  10947. /// result:
  10948. /// 0 = success
  10949. /// 1 = failure
  10950. /// 2 = already registered
  10951. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10952. {
  10953. int fd = sd->fd;
  10954. WFIFOHEAD(fd,packet_len(0x803));
  10955. WFIFOW(fd,0) = 0x803;
  10956. WFIFOW(fd,2) = flag;
  10957. WFIFOSET(fd,packet_len(0x803));
  10958. }
  10959. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10960. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10961. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10962. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10963. short level = RFIFOW(fd,info->pos[0]);
  10964. short mapid = RFIFOW(fd,info->pos[1]);
  10965. short job = RFIFOW(fd,info->pos[2]);
  10966. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10967. short resultcount = RFIFOW(fd,info->pos[4]);
  10968. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10969. }
  10970. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10971. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10972. /// more results:
  10973. /// 0 = no
  10974. /// 1 = yes
  10975. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10976. {
  10977. int i, j;
  10978. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10979. struct party_booking_ad_info *pb_ad;
  10980. WFIFOHEAD(fd,size*count + 5);
  10981. WFIFOW(fd,0) = 0x805;
  10982. WFIFOW(fd,2) = size*count + 5;
  10983. WFIFOB(fd,4) = more_result;
  10984. for(i=0; i<count; i++)
  10985. {
  10986. pb_ad = results[i];
  10987. WFIFOL(fd,i*size+5) = pb_ad->index;
  10988. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10989. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10990. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10991. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10992. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  10993. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10994. }
  10995. WFIFOSET(fd,WFIFOW(fd,2));
  10996. }
  10997. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10998. /// 0806
  10999. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11000. {
  11001. if(party_booking_delete(sd))
  11002. clif_PartyBookingDeleteAck(sd, 0);
  11003. }
  11004. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11005. /// 0807 <result>.W
  11006. /// result:
  11007. /// 0 = success
  11008. /// 1 = success (auto-removed expired ad)
  11009. /// 2 = failure
  11010. /// 3 = nothing registered
  11011. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11012. {
  11013. int fd = sd->fd;
  11014. WFIFOHEAD(fd,packet_len(0x807));
  11015. WFIFOW(fd,0) = 0x807;
  11016. WFIFOW(fd,2) = flag;
  11017. WFIFOSET(fd,packet_len(0x807));
  11018. }
  11019. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11020. /// 0808 { <job>.W }*6
  11021. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11022. {
  11023. short job[MAX_PARTY_BOOKING_JOBS];
  11024. int i;
  11025. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  11026. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11027. job[i] = RFIFOW(fd,idxpbu+i*2);
  11028. party_booking_update(sd, job);
  11029. }
  11030. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11031. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11032. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11033. {
  11034. int i;
  11035. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11036. if(pb_ad == NULL) return;
  11037. WBUFW(buf,0) = 0x809;
  11038. WBUFL(buf,2) = pb_ad->index;
  11039. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  11040. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11041. WBUFW(buf,34) = pb_ad->p_detail.level;
  11042. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11043. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11044. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11045. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11046. }
  11047. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11048. /// 080a <index>.L { <job>.W }*6
  11049. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11050. {
  11051. int i;
  11052. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11053. if(pb_ad == NULL) return;
  11054. WBUFW(buf,0) = 0x80a;
  11055. WBUFL(buf,2) = pb_ad->index;
  11056. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11057. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11058. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11059. }
  11060. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11061. /// 080b <index>.L
  11062. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11063. {
  11064. uint8 buf[6];
  11065. WBUFW(buf,0) = 0x80b;
  11066. WBUFL(buf,2) = index;
  11067. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11068. }
  11069. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11070. /// 012e
  11071. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11072. {
  11073. vending_closevending(sd);
  11074. }
  11075. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11076. /// 0130 <account id>.L
  11077. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11078. {
  11079. if( sd->npc_id ) {// using an NPC
  11080. return;
  11081. }
  11082. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11083. }
  11084. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11085. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11086. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11087. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11088. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11089. int id = (int)RFIFOL(fd,info->pos[1]);
  11090. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11091. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11092. // whether it fails or not, the buy window is closed
  11093. sd->vended_id = 0;
  11094. }
  11095. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11096. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11097. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11098. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11099. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11100. int aid = (int)RFIFOL(fd,info->pos[1]);
  11101. int uid = (int)RFIFOL(fd,info->pos[2]);
  11102. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11103. vending_purchasereq(sd, aid, uid, data, len/4);
  11104. // whether it fails or not, the buy window is closed
  11105. sd->vended_id = 0;
  11106. }
  11107. /// Confirm or cancel the shop preparation window.
  11108. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11109. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11110. /// result:
  11111. /// 0 = canceled
  11112. /// 1 = open
  11113. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11114. int cmd = RFIFOW(fd,0);
  11115. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  11116. short len = (short)RFIFOW(fd,info->pos[0]);
  11117. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  11118. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11119. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11120. len -= 84;
  11121. }
  11122. else { //(CZ_REQ_OPENSTORE2)
  11123. bool flag;
  11124. len -= 85;
  11125. flag = (bool)RFIFOB(fd,info->pos[2]);
  11126. if( !flag )
  11127. sd->state.prevend = 0;
  11128. }
  11129. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11130. return;
  11131. if( map[sd->bl.m].flag.novending ) {
  11132. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11133. return;
  11134. }
  11135. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11136. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11137. return;
  11138. }
  11139. if( message[0] == '\0' ) // invalid input
  11140. return;
  11141. vending_openvending(sd, message, data, len/8, NULL);
  11142. }
  11143. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11144. /// 0165 <char id>.L <guild name>.24B
  11145. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11146. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11147. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11148. name[NAME_LENGTH-1] = '\0';
  11149. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11150. clif_displaymessage(fd, msg_txt(sd,228));
  11151. return;
  11152. }
  11153. guild_create(sd, name);
  11154. }
  11155. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11156. /// 014d
  11157. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11158. {
  11159. clif_guild_masterormember(sd);
  11160. }
  11161. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11162. /// 014f <type>.L
  11163. /// type:
  11164. /// 0 = basic info
  11165. /// 1 = member manager
  11166. /// 2 = positions
  11167. /// 3 = skills
  11168. /// 4 = expulsion list
  11169. /// 5 = unknown (GM_ALLGUILDLIST)
  11170. /// 6 = notice
  11171. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11172. {
  11173. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11174. if( !sd->status.guild_id && !sd->bg_id )
  11175. return;
  11176. switch( type )
  11177. {
  11178. case 0: // Basic Information Guild, hostile alliance information
  11179. clif_guild_basicinfo(sd);
  11180. clif_guild_allianceinfo(sd);
  11181. break;
  11182. case 1: // Members list, list job title
  11183. clif_guild_positionnamelist(sd);
  11184. clif_guild_memberlist(sd);
  11185. break;
  11186. case 2: // List job title, title information list
  11187. clif_guild_positionnamelist(sd);
  11188. clif_guild_positioninfolist(sd);
  11189. break;
  11190. case 3: // Skill list
  11191. clif_guild_skillinfo(sd);
  11192. break;
  11193. case 4: // Expulsion list
  11194. clif_guild_expulsionlist(sd);
  11195. break;
  11196. default:
  11197. ShowError("clif: guild request info: unknown type %d\n", type);
  11198. break;
  11199. }
  11200. }
  11201. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11202. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11203. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11204. {
  11205. int i;
  11206. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11207. int len = RFIFOW(fd,info->pos[0]);
  11208. int idxgpos = info->pos[1];
  11209. if(!sd->state.gmaster_flag)
  11210. return;
  11211. for(i = idxgpos; i < len; i += 40 ){
  11212. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  11213. }
  11214. }
  11215. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11216. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11217. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11218. {
  11219. int i;
  11220. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11221. int len = RFIFOW(fd,info->pos[0]);
  11222. int idxgpos = info->pos[1];
  11223. if(!sd->state.gmaster_flag)
  11224. return;
  11225. for(i=idxgpos;i<len;i+=12){
  11226. guild_change_memberposition(sd->status.guild_id,
  11227. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11228. }
  11229. }
  11230. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11231. /// 0151 <guild id>.L
  11232. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11233. {
  11234. struct guild* g;
  11235. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11236. if( (g = guild_search(guild_id)) != NULL )
  11237. clif_guild_emblem(sd,g);
  11238. }
  11239. /// Validates data of a guild emblem (compressed bitmap)
  11240. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11241. {
  11242. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11243. unsigned long buf_len = sizeof(buf);
  11244. int offset = 0;
  11245. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11246. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11247. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11248. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11249. ))
  11250. return -1;
  11251. if(battle_config.emblem_transparency_limit != 100) {
  11252. int i, transcount = 1, tmp[3];
  11253. for(i = offset; i < buf_len-1; i++) {
  11254. int j = i%3;
  11255. tmp[j] = RBUFL(buf,i);
  11256. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11257. transcount++;
  11258. }
  11259. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11260. return -2;
  11261. }
  11262. return 0;
  11263. }
  11264. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11265. /// 0153 <packet len>.W <emblem data>.?B
  11266. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11267. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11268. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11269. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11270. int emb_val=0;
  11271. if( !emblem_len || !sd->state.gmaster_flag )
  11272. return;
  11273. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  11274. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  11275. return;
  11276. }
  11277. emb_val = clif_validate_emblem(emblem, emblem_len);
  11278. if(emb_val ==-1 ){
  11279. 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);
  11280. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11281. return;
  11282. } else if(emb_val == -2){
  11283. char output[128];
  11284. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11285. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11286. return;
  11287. }
  11288. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11289. }
  11290. /// Guild notice update request (CZ_GUILD_NOTICE).
  11291. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11292. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11293. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11294. int guild_id = RFIFOL(fd,info->pos[0]);
  11295. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11296. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11297. if(!sd->state.gmaster_flag)
  11298. return;
  11299. // compensate for some client defects when using multilanguage mode
  11300. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11301. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11302. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11303. guild_change_notice(sd, guild_id, msg1, msg2);
  11304. }
  11305. // Helper function for guild invite functions
  11306. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11307. {
  11308. if (t_sd == NULL) // not online or does not exist
  11309. return 1;
  11310. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11311. clif_displaymessage(fd, msg_txt(sd,228));
  11312. return 1;
  11313. }
  11314. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11315. clif_noask_sub(sd, t_sd, 2);
  11316. return 1;
  11317. }
  11318. guild_invite(sd, t_sd);
  11319. return 0;
  11320. }
  11321. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11322. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11323. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11324. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11325. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11326. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11327. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11328. if (clif_sub_guild_invite(fd, sd, t_sd))
  11329. return;
  11330. }
  11331. /// Guild invite request (/guildinvite)
  11332. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11333. void
  11334. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11335. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11336. if (clif_sub_guild_invite(fd, sd, t_sd))
  11337. return;
  11338. }
  11339. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11340. /// 016b <guild id>.L <answer>.L
  11341. /// answer:
  11342. /// 0 = refuse
  11343. /// 1 = accept
  11344. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11345. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11346. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11347. RFIFOL(fd,info->pos[1]));
  11348. }
  11349. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11350. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11351. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11352. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11353. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11354. clif_displaymessage(fd, msg_txt(sd,228));
  11355. return;
  11356. }
  11357. if( sd->bg_id ) {
  11358. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11359. return;
  11360. }
  11361. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11362. RFIFOL(fd,info->pos[1]),
  11363. RFIFOL(fd,info->pos[2]),
  11364. (char*)RFIFOP(fd,info->pos[3]));
  11365. }
  11366. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11367. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11368. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11369. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11370. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11371. { // Guild locked.
  11372. clif_displaymessage(fd, msg_txt(sd,228));
  11373. return;
  11374. }
  11375. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11376. RFIFOL(fd,info->pos[1]),
  11377. RFIFOL(fd,info->pos[2]),
  11378. (char*)RFIFOP(fd,info->pos[3]));
  11379. }
  11380. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11381. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11382. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11383. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11384. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  11385. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  11386. char *name, *message;
  11387. int namelen, messagelen;
  11388. // validate packet and retrieve name and message
  11389. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11390. return;
  11391. if( is_atcommand(fd, sd, message, 1) )
  11392. return;
  11393. if (sd->sc.cant.chat)
  11394. return; //no "chatting" while muted.
  11395. if( battle_config.min_chat_delay )
  11396. { //[Skotlex]
  11397. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  11398. return;
  11399. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11400. }
  11401. if (battle_config.idletime_option&IDLE_CHAT)
  11402. sd->idletime = last_tick;
  11403. if( sd->bg_id )
  11404. bg_send_message(sd, text, textlen);
  11405. else
  11406. guild_send_message(sd, text, textlen);
  11407. }
  11408. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11409. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11410. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11411. {
  11412. struct map_session_data *t_sd;
  11413. if(!sd->state.gmaster_flag)
  11414. return;
  11415. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11416. clif_displaymessage(fd, msg_txt(sd,228));
  11417. return;
  11418. }
  11419. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11420. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11421. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11422. // @noask [LuzZza]
  11423. if(t_sd && t_sd->state.noask) {
  11424. clif_noask_sub(sd, t_sd, 3);
  11425. return;
  11426. }
  11427. guild_reqalliance(sd,t_sd);
  11428. }
  11429. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11430. /// 0172 <inviter account id>.L <answer>.L
  11431. /// answer:
  11432. /// 0 = refuse
  11433. /// 1 = accept
  11434. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11435. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11436. guild_reply_reqalliance(sd,
  11437. RFIFOL(fd,info->pos[0]),
  11438. RFIFOL(fd,info->pos[1]));
  11439. }
  11440. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11441. /// 0183 <opponent guild id>.L <relation>.L
  11442. /// relation:
  11443. /// 0 = Ally
  11444. /// 1 = Enemy
  11445. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11446. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11447. if(!sd->state.gmaster_flag)
  11448. return;
  11449. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11450. clif_displaymessage(fd, msg_txt(sd,228));
  11451. return;
  11452. }
  11453. guild_delalliance(sd,
  11454. RFIFOL(fd,info->pos[0]),
  11455. RFIFOL(fd,info->pos[1]));
  11456. }
  11457. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11458. /// 0180 <account id>.L
  11459. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11460. {
  11461. struct map_session_data *t_sd;
  11462. if(!sd->state.gmaster_flag)
  11463. return;
  11464. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11465. clif_displaymessage(fd, msg_txt(sd,228));
  11466. return;
  11467. }
  11468. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11469. // @noask [LuzZza]
  11470. if(t_sd && t_sd->state.noask) {
  11471. clif_noask_sub(sd, t_sd, 4);
  11472. return;
  11473. }
  11474. guild_opposition(sd,t_sd);
  11475. }
  11476. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11477. /// 015d <key>.40B
  11478. /// key:
  11479. /// now guild name; might have been (intended) email, since the
  11480. /// field name and size is same as the one in CH_DELETE_CHAR.
  11481. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11482. {
  11483. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11484. clif_displaymessage(fd, msg_txt(sd,228));
  11485. return;
  11486. }
  11487. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11488. }
  11489. /// Pet
  11490. ///
  11491. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11492. /// 01a1 <type>.B
  11493. /// type:
  11494. /// 0 = pet information
  11495. /// 1 = feed
  11496. /// 2 = performance
  11497. /// 3 = return to egg
  11498. /// 4 = unequip accessory
  11499. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11500. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11501. }
  11502. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11503. /// 019f <id>.L
  11504. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11505. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11506. }
  11507. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11508. /// 01a7 <index>.W
  11509. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11510. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11511. return;
  11512. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11513. clif_menuskill_clear(sd);
  11514. }
  11515. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11516. /// 01a9 <data>.L
  11517. /// data:
  11518. /// is either emotion (@see enum emotion_type) or a compound value
  11519. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11520. /// entry (given in parentheses) in data\pettalktable.xml
  11521. /// act id:
  11522. /// 0 = feeding
  11523. /// 1 = hunting
  11524. /// 2 = danger
  11525. /// 3 = dead
  11526. /// 4 = normal (stand)
  11527. /// 5 = special performance (perfor_s)
  11528. /// 6 = level up (levelup)
  11529. /// 7 = performance 1 (perfor_1)
  11530. /// 8 = performance 2 (perfor_2)
  11531. /// 9 = performance 3 (perfor_3)
  11532. /// 10 = log-in greeting (connect)
  11533. /// hungry value:
  11534. /// 0 = very hungry (hungry)
  11535. /// 1 = hungry (bit_hungry)
  11536. /// 2 = satisfied (noting)
  11537. /// 3 = stuffed (full)
  11538. /// 4 = full (so_full)
  11539. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11540. {
  11541. if(sd->pd)
  11542. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11543. }
  11544. /// Request to change pet's name (CZ_RENAME_PET).
  11545. /// 01a5 <name>.24B
  11546. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11547. {
  11548. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11549. }
  11550. /// /kill (CZ_DISCONNECT_CHARACTER).
  11551. /// Request to disconnect a character.
  11552. /// 00cc <account id>.L
  11553. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11554. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11555. {
  11556. struct block_list *target;
  11557. int tid;
  11558. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11559. target = map_id2bl(tid);
  11560. if (!target) {
  11561. clif_GM_kickack(sd, 0);
  11562. return;
  11563. }
  11564. switch (target->type) {
  11565. case BL_PC:
  11566. {
  11567. char command[NAME_LENGTH+6];
  11568. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11569. is_atcommand(fd, sd, command, 1);
  11570. }
  11571. break;
  11572. /**
  11573. * This one does not invoke any atcommand, so we need to check for permissions.
  11574. */
  11575. case BL_MOB:
  11576. {
  11577. char command[100];
  11578. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11579. clif_GM_kickack(sd, 0);
  11580. return;
  11581. }
  11582. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11583. log_atcommand(sd, command);
  11584. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11585. }
  11586. break;
  11587. case BL_NPC:
  11588. {
  11589. struct npc_data* nd = (struct npc_data *)target;
  11590. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11591. npc_unload_duplicates(nd);
  11592. npc_unload(nd,true);
  11593. npc_read_event_script();
  11594. }
  11595. }
  11596. break;
  11597. default:
  11598. clif_GM_kickack(sd, 0);
  11599. }
  11600. }
  11601. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11602. /// Request to disconnect all characters.
  11603. /// 00ce
  11604. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11605. char cmd[15];
  11606. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11607. is_atcommand(fd, sd, cmd, 1);
  11608. }
  11609. /// /remove (CZ_REMOVE_AID).
  11610. /// Request to warp to a character with given login ID.
  11611. /// 01ba <account name>.24B
  11612. /// /shift (CZ_SHIFT).
  11613. /// Request to warp to a character with given name.
  11614. /// 01bb <char name>.24B
  11615. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11616. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11617. char *player_name;
  11618. char command[NAME_LENGTH+8];
  11619. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11620. player_name[NAME_LENGTH-1] = '\0';
  11621. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11622. is_atcommand(fd, sd, command, 1);
  11623. }
  11624. /// /remove (CZ_REMOVE_AID_SSO).
  11625. /// Request to warp to a character with given account ID.
  11626. /// 0843 <account id>.L
  11627. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11628. {
  11629. uint32 account_id;
  11630. struct map_session_data* pl_sd;
  11631. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11632. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11633. char command[NAME_LENGTH+8];
  11634. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11635. is_atcommand(fd, sd, command, 1);
  11636. }
  11637. }
  11638. /// /recall (CZ_RECALL).
  11639. /// Request to summon a player with given login ID to own position.
  11640. /// 01bc <account name>.24B
  11641. /// /summon (CZ_RECALL_GID).
  11642. /// Request to summon a player with given name to own position.
  11643. /// 01bd <char name>.24B
  11644. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11645. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11646. char *player_name;
  11647. char command [NAME_LENGTH+8];
  11648. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11649. player_name[NAME_LENGTH-1] = '\0';
  11650. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11651. is_atcommand(fd, sd, command, 1);
  11652. }
  11653. /// /recall (CZ_RECALL_SSO).
  11654. /// Request to summon a player with given account ID to own position.
  11655. /// 0842 <account id>.L
  11656. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11657. {
  11658. uint32 account_id;
  11659. struct map_session_data* pl_sd;
  11660. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11661. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11662. char command[NAME_LENGTH+8];
  11663. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11664. is_atcommand(fd, sd, command, 1);
  11665. }
  11666. }
  11667. /// /item /monster (CZ_ITEM_CREATE).
  11668. /// Request to execute GM commands.
  11669. /// Usage:
  11670. /// /item n - summon n monster or acquire n item/s
  11671. /// /item money - grants 2147483647 zenies
  11672. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11673. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11674. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11675. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11676. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11677. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11678. /// 013f <item/mob name>.24B
  11679. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11680. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11681. {
  11682. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11683. int mob_id = 0;
  11684. struct item_data *id = NULL;
  11685. struct mob_db *mob = NULL;
  11686. StringBuf command;
  11687. char *str;
  11688. //#if PACKETVER >= 20131218
  11689. // char str[100];
  11690. //#else
  11691. // char str[24];
  11692. //#endif
  11693. str = (char*)RFIFOP(fd,info->pos[0]);
  11694. if (!str || str[0] == '\0')
  11695. return;
  11696. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11697. return;
  11698. trim(str);
  11699. // Zeny
  11700. if( strcmpi(str, "money") == 0 ) {
  11701. StringBuf_Init(&command);
  11702. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11703. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11704. StringBuf_Destroy(&command);
  11705. return;
  11706. }
  11707. // Item
  11708. if( (id = itemdb_searchname(str)) ) {
  11709. StringBuf_Init(&command);
  11710. if( !itemdb_isstackable2(id) ) //Nonstackable
  11711. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11712. else {
  11713. if (id->flag.guid)
  11714. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11715. else
  11716. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11717. }
  11718. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11719. StringBuf_Destroy(&command);
  11720. return;
  11721. }
  11722. // Monster
  11723. if ((mob_id = mobdb_searchname(str)) == 0)
  11724. mob_id = mobdb_checkid(atoi(str));
  11725. if( (mob = mob_db(mob_id)) ) {
  11726. StringBuf_Init(&command);
  11727. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11728. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11729. StringBuf_Destroy(&command);
  11730. return;
  11731. }
  11732. }
  11733. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11734. /// 019d <effect state>.L
  11735. /// effect state:
  11736. /// TODO: Any OPTION_* ?
  11737. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11738. char cmd[6];
  11739. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11740. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11741. is_atcommand(fd, sd, cmd, 1);
  11742. }
  11743. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11744. /// 0149 <account id>.L <type>.B <value>.W
  11745. /// type:
  11746. /// 0 = positive points
  11747. /// 1 = negative points
  11748. /// 2 = self mute (+10 minutes)
  11749. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11750. {
  11751. int id, type, value;
  11752. struct map_session_data *dstsd;
  11753. char command[NAME_LENGTH+15];
  11754. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11755. id = RFIFOL(fd,info->pos[0]);
  11756. type = RFIFOB(fd,info->pos[1]);
  11757. value = RFIFOW(fd,info->pos[2]);
  11758. if( type == 0 )
  11759. value = -value;
  11760. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11761. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11762. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11763. return;
  11764. dstsd = map_id2sd(id);
  11765. if( dstsd == NULL )
  11766. return;
  11767. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11768. is_atcommand(fd, sd, command, 1);
  11769. }
  11770. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11771. /// GM adjustment of a player's manner value by -60.
  11772. /// 0212 <char name>.24B
  11773. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11774. {
  11775. char command[NAME_LENGTH+15];
  11776. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11777. name[NAME_LENGTH-1] = '\0';
  11778. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11779. is_atcommand(fd, sd, command, 1);
  11780. }
  11781. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11782. /// 01e0 <account id>.L <account name>.24B
  11783. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11784. {
  11785. WFIFOHEAD(fd,packet_len(0x1e0));
  11786. WFIFOW(fd,0) = 0x1e0;
  11787. WFIFOL(fd,2) = account_id;
  11788. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11789. WFIFOSET(fd,packet_len(0x1e0));
  11790. }
  11791. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11792. /// 01df <account id>.L
  11793. //! TODO: Figure out how does this actually work
  11794. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11795. {
  11796. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11797. /*
  11798. char query[30];
  11799. safesnprintf(query,sizeof(query),"%d", account_id);
  11800. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11801. */
  11802. clif_account_name(fd, account_id, "");
  11803. }
  11804. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11805. /// GM single cell type change request.
  11806. /// 0198 <x>.W <y>.W <type>.W
  11807. /// type:
  11808. /// 0 = not walkable
  11809. /// 1 = walkable
  11810. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11811. {
  11812. int x,y,type;
  11813. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11814. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11815. return;
  11816. x = RFIFOW(fd,info->pos[0]);
  11817. y = RFIFOW(fd,info->pos[1]);
  11818. type = RFIFOW(fd,info->pos[2]);
  11819. map_setgatcell(sd->bl.m,x,y,type);
  11820. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11821. //FIXME: once players leave the map, the client 'forgets' this information.
  11822. }
  11823. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11824. /// Request to allow/deny whispers from a nick.
  11825. /// 00cf <nick>.24B <type>.B
  11826. /// type:
  11827. /// 0 = (/ex nick) deny speech from nick
  11828. /// 1 = (/in nick) allow speech from nick
  11829. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11830. {
  11831. char* nick;
  11832. uint8 type;
  11833. int i;
  11834. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11835. nick = (char*)RFIFOP(fd,info->pos[0]);
  11836. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11837. type = RFIFOB(fd,info->pos[1]);
  11838. if( type == 0 ) { // Add name to ignore list (block)
  11839. if (strcmp(wisp_server_name, nick) == 0) {
  11840. clif_wisexin(sd, type, 1); // fail
  11841. return;
  11842. }
  11843. // try to find a free spot, while checking for duplicates at the same time
  11844. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11845. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11846. clif_wisexin(sd, type, 2); // too many blocks
  11847. return;
  11848. }
  11849. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11850. clif_wisexin(sd, type, 0); // Aegis reports success.
  11851. return;
  11852. }
  11853. //Insert in position i
  11854. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11855. } else { // Remove name from ignore list (unblock)
  11856. // find entry
  11857. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11858. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11859. clif_wisexin(sd, type, 1); // fail
  11860. return;
  11861. }
  11862. // move everything one place down to overwrite removed entry
  11863. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11864. // wipe last entry
  11865. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11866. }
  11867. clif_wisexin(sd, type, 0); // success
  11868. }
  11869. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11870. /// Request to allow/deny all whispers.
  11871. /// 00d0 <type>.B
  11872. /// type:
  11873. /// 0 = (/exall) deny all speech
  11874. /// 1 = (/inall) allow all speech
  11875. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11876. {
  11877. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11878. if( type == 0 ) {// Deny all
  11879. if( sd->state.ignoreAll ) {
  11880. flag = 1; // fail
  11881. } else {
  11882. sd->state.ignoreAll = 1;
  11883. flag = 0; // success
  11884. }
  11885. } else {//Unblock everyone
  11886. if( sd->state.ignoreAll ) {
  11887. sd->state.ignoreAll = 0;
  11888. flag = 0; // success
  11889. } else {
  11890. if (sd->ignore[0].name[0] != '\0')
  11891. { //Wipe the ignore list.
  11892. memset(sd->ignore, 0, sizeof(sd->ignore));
  11893. flag = 0; // success
  11894. } else {
  11895. flag = 1; // fail
  11896. }
  11897. }
  11898. }
  11899. clif_wisall(sd, type, flag);
  11900. }
  11901. /// Whisper ignore list (ZC_WHISPER_LIST).
  11902. /// 00d4 <packet len>.W { <char name>.24B }*
  11903. void clif_PMIgnoreList(struct map_session_data* sd)
  11904. {
  11905. int i, fd = sd->fd;
  11906. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11907. WFIFOW(fd,0) = 0xd4;
  11908. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11909. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11910. }
  11911. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11912. WFIFOSET(fd,WFIFOW(fd,2));
  11913. }
  11914. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11915. /// 00d3
  11916. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11917. {
  11918. clif_PMIgnoreList(sd);
  11919. }
  11920. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11921. /// 01e7
  11922. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11923. {
  11924. if (sd->state.doridori) return;
  11925. switch (sd->class_&MAPID_UPPERMASK) {
  11926. case MAPID_SOUL_LINKER:
  11927. case MAPID_STAR_GLADIATOR:
  11928. case MAPID_TAEKWON:
  11929. if (!sd->state.rest)
  11930. break;
  11931. case MAPID_SUPER_NOVICE:
  11932. case MAPID_SUPER_BABY:
  11933. case MAPID_SUPER_NOVICE_E:
  11934. case MAPID_SUPER_BABY_E:
  11935. sd->state.doridori=1;
  11936. break;
  11937. }
  11938. }
  11939. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11940. /// 01ed
  11941. /// Note: This packet is caused by 7 lines of any text, followed by
  11942. /// the prayer and an another line of any text. The prayer is
  11943. /// defined by lines 790~793 in data\msgstringtable.txt
  11944. /// "Dear angel, can you hear my voice?"
  11945. /// "I am" (space separated player name) "Super Novice~"
  11946. /// "Help me out~ Please~ T_T"
  11947. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11948. {
  11949. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11950. unsigned int next = pc_nextbaseexp(sd);
  11951. if( next ) {
  11952. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11953. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11954. 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]
  11955. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11956. }
  11957. }
  11958. }
  11959. }
  11960. /// Friends List
  11961. ///
  11962. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11963. /// 0206 <account id>.L <char id>.L <state>.B
  11964. /// state:
  11965. /// 0 = online
  11966. /// 1 = offline
  11967. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11968. {
  11969. int i, fd = sd->fd;
  11970. //Seek friend.
  11971. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11972. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11973. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11974. return; //Not found
  11975. WFIFOHEAD(fd,packet_len(0x206));
  11976. WFIFOW(fd, 0) = 0x206;
  11977. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11978. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11979. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11980. WFIFOSET(fd, packet_len(0x206));
  11981. }
  11982. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11983. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11984. {
  11985. uint32 account_id, char_id, online;
  11986. account_id = va_arg(ap, int);
  11987. char_id = va_arg(ap, int);
  11988. online = va_arg(ap, int);
  11989. clif_friendslist_toggle(sd, account_id, char_id, online);
  11990. return 0;
  11991. }
  11992. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11993. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11994. void clif_friendslist_send(struct map_session_data *sd)
  11995. {
  11996. int i = 0, n, fd = sd->fd;
  11997. // Send friends list
  11998. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11999. WFIFOW(fd, 0) = 0x201;
  12000. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12001. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  12002. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  12003. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  12004. }
  12005. if (i) {
  12006. WFIFOW(fd,2) = 4 + 32 * i;
  12007. WFIFOSET(fd, WFIFOW(fd,2));
  12008. }
  12009. for (n = 0; n < i; n++) { //Sending the online players
  12010. if (map_charid2sd(sd->status.friends[n].char_id))
  12011. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12012. }
  12013. }
  12014. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12015. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12016. /// result:
  12017. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12018. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12019. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12020. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12021. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12022. {
  12023. int fd;
  12024. nullpo_retv(sd);
  12025. fd = sd->fd;
  12026. WFIFOHEAD(fd,packet_len(0x209));
  12027. WFIFOW(fd,0) = 0x209;
  12028. WFIFOW(fd,2) = type;
  12029. if (f_sd) {
  12030. WFIFOL(fd,4) = f_sd->status.account_id;
  12031. WFIFOL(fd,8) = f_sd->status.char_id;
  12032. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12033. }
  12034. WFIFOSET(fd, packet_len(0x209));
  12035. }
  12036. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12037. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12038. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12039. {
  12040. int fd = sd->fd;
  12041. WFIFOHEAD(fd,packet_len(0x207));
  12042. WFIFOW(fd,0) = 0x207;
  12043. WFIFOL(fd,2) = account_id;
  12044. WFIFOL(fd,6) = char_id;
  12045. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  12046. WFIFOSET(fd,packet_len(0x207));
  12047. }
  12048. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12049. /// 0202 <name>.24B
  12050. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12051. {
  12052. struct map_session_data *f_sd;
  12053. int i;
  12054. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12055. // ensure that the request player's friend list is not full
  12056. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12057. if( i == MAX_FRIENDS ) {
  12058. clif_friendslist_reqack(sd, f_sd, 2);
  12059. return;
  12060. }
  12061. // Friend doesn't exist (no player with this name)
  12062. if (f_sd == NULL) {
  12063. clif_displaymessage(fd, msg_txt(sd,3));
  12064. return;
  12065. }
  12066. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12067. return;
  12068. }
  12069. // @noask [LuzZza]
  12070. if(f_sd->state.noask) {
  12071. clif_noask_sub(sd, f_sd, 5);
  12072. return;
  12073. }
  12074. // Friend already exists
  12075. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12076. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12077. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12078. return;
  12079. }
  12080. }
  12081. f_sd->friend_req = sd->status.char_id;
  12082. sd->friend_req = f_sd->status.char_id;
  12083. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12084. }
  12085. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12086. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12087. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12088. /// reply:
  12089. /// 0 = rejected
  12090. /// 1 = accepted
  12091. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12092. {
  12093. struct map_session_data *f_sd;
  12094. uint32 account_id;
  12095. char reply;
  12096. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12097. account_id = RFIFOL(fd,info->pos[0]);
  12098. //char_id = RFIFOL(fd,info->pos[1]);
  12099. if(sd->packet_ver < 6)
  12100. reply = RFIFOB(fd,info->pos[2]);
  12101. else
  12102. reply = RFIFOL(fd,info->pos[2]);
  12103. if( sd->bl.id == account_id ) {// adding oneself as friend
  12104. return;
  12105. }
  12106. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12107. if (f_sd == NULL)
  12108. return;
  12109. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12110. clif_friendslist_reqack(f_sd, sd, 1);
  12111. else {
  12112. int i;
  12113. // Find an empty slot
  12114. for (i = 0; i < MAX_FRIENDS; i++)
  12115. if (f_sd->status.friends[i].char_id == 0)
  12116. break;
  12117. if (i == MAX_FRIENDS) {
  12118. clif_friendslist_reqack(f_sd, sd, 2);
  12119. return;
  12120. }
  12121. f_sd->status.friends[i].account_id = sd->status.account_id;
  12122. f_sd->status.friends[i].char_id = sd->status.char_id;
  12123. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12124. clif_friendslist_reqack(f_sd, sd, 0);
  12125. if (battle_config.friend_auto_add) {
  12126. // Also add f_sd to sd's friendlist.
  12127. for (i = 0; i < MAX_FRIENDS; i++) {
  12128. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12129. return; //No need to add anything.
  12130. if (sd->status.friends[i].char_id == 0)
  12131. break;
  12132. }
  12133. if (i == MAX_FRIENDS) {
  12134. clif_friendslist_reqack(sd, f_sd, 2);
  12135. return;
  12136. }
  12137. sd->status.friends[i].account_id = f_sd->status.account_id;
  12138. sd->status.friends[i].char_id = f_sd->status.char_id;
  12139. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12140. clif_friendslist_reqack(sd, f_sd, 0);
  12141. }
  12142. }
  12143. }
  12144. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12145. /// 0203 <account id>.L <char id>.L
  12146. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12147. {
  12148. struct map_session_data *f_sd = NULL;
  12149. uint32 account_id, char_id;
  12150. int i, j;
  12151. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12152. account_id = RFIFOL(fd,info->pos[0]);
  12153. char_id = RFIFOL(fd,info->pos[1]);
  12154. // Search friend
  12155. for (i = 0; i < MAX_FRIENDS &&
  12156. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12157. if (i == MAX_FRIENDS) {
  12158. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12159. return;
  12160. }
  12161. //remove from friend's list first
  12162. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12163. for (i = 0; i < MAX_FRIENDS &&
  12164. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12165. if (i != MAX_FRIENDS) {
  12166. // move all chars up
  12167. for(j = i + 1; j < MAX_FRIENDS; j++)
  12168. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12169. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12170. //should the guy be notified of some message? we should add it here if so
  12171. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12172. WFIFOW(f_sd->fd,0) = 0x20a;
  12173. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12174. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12175. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12176. }
  12177. } else { //friend not online -- ask char server to delete from his friendlist
  12178. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12179. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12180. return;
  12181. }
  12182. }
  12183. // We can now delete from original requester
  12184. for (i = 0; i < MAX_FRIENDS &&
  12185. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12186. // move all chars up
  12187. for(j = i + 1; j < MAX_FRIENDS; j++)
  12188. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12189. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12190. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12191. WFIFOHEAD(fd,packet_len(0x20a));
  12192. WFIFOW(fd,0) = 0x20a;
  12193. WFIFOL(fd,2) = account_id;
  12194. WFIFOL(fd,6) = char_id;
  12195. WFIFOSET(fd, packet_len(0x20a));
  12196. }
  12197. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12198. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12199. void clif_PVPInfo(struct map_session_data* sd)
  12200. {
  12201. int fd = sd->fd;
  12202. WFIFOHEAD(fd,packet_len(0x210));
  12203. WFIFOW(fd,0) = 0x210;
  12204. WFIFOL(fd,2) = sd->status.char_id;
  12205. WFIFOL(fd,6) = sd->status.account_id;
  12206. WFIFOL(fd,10) = sd->pvp_won; // times won
  12207. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12208. WFIFOL(fd,18) = sd->pvp_point;
  12209. WFIFOSET(fd, packet_len(0x210));
  12210. }
  12211. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12212. /// 020f <char id>.L <account id>.L
  12213. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12214. {
  12215. // TODO: Is there a way to use this on an another player (char/acc id)?
  12216. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12217. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12218. clif_PVPInfo(sd);
  12219. }
  12220. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  12221. /// 0219 { <name>.24B }*10 { <point>.L }*10
  12222. void clif_blacksmith(struct map_session_data* sd)
  12223. {
  12224. int i, fd = sd->fd;
  12225. const char* name;
  12226. WFIFOHEAD(fd,packet_len(0x219));
  12227. WFIFOW(fd,0) = 0x219;
  12228. //Packet size limits this list to 10 elements. [Skotlex]
  12229. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  12230. if (smith_fame_list[i].id > 0) {
  12231. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  12232. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  12233. {
  12234. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  12235. } else
  12236. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  12237. } else
  12238. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  12239. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  12240. }
  12241. for(;i < 10; i++) { //In case the MAX is less than 10.
  12242. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  12243. WFIFOL(fd, 242 + i * 4) = 0;
  12244. }
  12245. WFIFOSET(fd, packet_len(0x219));
  12246. }
  12247. /// /blacksmith (CZ_BLACKSMITH_RANK).
  12248. /// 0217
  12249. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  12250. {
  12251. clif_blacksmith(sd);
  12252. }
  12253. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  12254. /// 021b <points>.L <total points>.L
  12255. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  12256. {
  12257. int fd = sd->fd;
  12258. WFIFOHEAD(fd,packet_len(0x21b));
  12259. WFIFOW(fd,0) = 0x21b;
  12260. WFIFOL(fd,2) = points;
  12261. WFIFOL(fd,6) = sd->status.fame;
  12262. WFIFOSET(fd, packet_len(0x21b));
  12263. }
  12264. /// /alchemist list (ZC_ALCHEMIST_RANK).
  12265. /// 021a { <name>.24B }*10 { <point>.L }*10
  12266. void clif_alchemist(struct map_session_data* sd)
  12267. {
  12268. int i, fd = sd->fd;
  12269. const char* name;
  12270. WFIFOHEAD(fd,packet_len(0x21a));
  12271. WFIFOW(fd,0) = 0x21a;
  12272. //Packet size limits this list to 10 elements. [Skotlex]
  12273. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12274. if (chemist_fame_list[i].id > 0) {
  12275. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  12276. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12277. {
  12278. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12279. } else
  12280. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12281. } else
  12282. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12283. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12284. }
  12285. for(;i < 10; i++) { //In case the MAX is less than 10.
  12286. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12287. WFIFOL(fd, 242 + i * 4) = 0;
  12288. }
  12289. WFIFOSET(fd, packet_len(0x21a));
  12290. }
  12291. /// /alchemist (CZ_ALCHEMIST_RANK).
  12292. /// 0218
  12293. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12294. {
  12295. clif_alchemist(sd);
  12296. }
  12297. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12298. /// 021c <points>.L <total points>.L
  12299. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12300. {
  12301. int fd = sd->fd;
  12302. WFIFOHEAD(fd,packet_len(0x21c));
  12303. WFIFOW(fd,0) = 0x21c;
  12304. WFIFOL(fd,2) = points;
  12305. WFIFOL(fd,6) = sd->status.fame;
  12306. WFIFOSET(fd, packet_len(0x21c));
  12307. }
  12308. /// /taekwon list (ZC_TAEKWON_RANK).
  12309. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12310. void clif_taekwon(struct map_session_data* sd)
  12311. {
  12312. int i, fd = sd->fd;
  12313. const char* name;
  12314. WFIFOHEAD(fd,packet_len(0x226));
  12315. WFIFOW(fd,0) = 0x226;
  12316. //Packet size limits this list to 10 elements. [Skotlex]
  12317. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12318. if (taekwon_fame_list[i].id > 0) {
  12319. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12320. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12321. {
  12322. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12323. } else
  12324. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12325. } else
  12326. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12327. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12328. }
  12329. for(;i < 10; i++) { //In case the MAX is less than 10.
  12330. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12331. WFIFOL(fd, 242 + i * 4) = 0;
  12332. }
  12333. WFIFOSET(fd, packet_len(0x226));
  12334. }
  12335. /// /taekwon (CZ_TAEKWON_RANK).
  12336. /// 0225
  12337. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12338. {
  12339. clif_taekwon(sd);
  12340. }
  12341. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12342. /// 0224 <points>.L <total points>.L
  12343. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12344. {
  12345. int fd = sd->fd;
  12346. WFIFOHEAD(fd,packet_len(0x224));
  12347. WFIFOW(fd,0) = 0x224;
  12348. WFIFOL(fd,2) = points;
  12349. WFIFOL(fd,6) = sd->status.fame;
  12350. WFIFOSET(fd, packet_len(0x224));
  12351. }
  12352. /// /pk list (ZC_KILLER_RANK).
  12353. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12354. void clif_ranking_pk(struct map_session_data* sd)
  12355. {
  12356. int i, fd = sd->fd;
  12357. WFIFOHEAD(fd,packet_len(0x238));
  12358. WFIFOW(fd,0) = 0x238;
  12359. for(i=0;i<10;i++){
  12360. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12361. WFIFOL(fd,i*4+242) = 0;
  12362. }
  12363. WFIFOSET(fd, packet_len(0x238));
  12364. }
  12365. /// /pk (CZ_KILLER_RANK).
  12366. /// 0237
  12367. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12368. {
  12369. clif_ranking_pk(sd);
  12370. }
  12371. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12372. /// 0254 <which>.B
  12373. /// which: (unused atm for security purpose)
  12374. /// 0 = sun
  12375. /// 1 = moon
  12376. /// 2 = star
  12377. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12378. {
  12379. int i;
  12380. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12381. if (sd->menuskill_id != SG_FEEL)
  12382. return;
  12383. i = sd->menuskill_val-1;
  12384. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12385. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12386. sd->feel_map[i].m = sd->bl.m;
  12387. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12388. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12389. // clif_misceffect2(&sd->bl, 0x1b0);
  12390. // clif_misceffect2(&sd->bl, 0x21f);
  12391. clif_feel_info(sd, i, 0);
  12392. clif_menuskill_clear(sd);
  12393. }
  12394. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12395. /// 0253 <which>.B
  12396. /// which:
  12397. /// 0 = sun
  12398. /// 1 = moon
  12399. /// 2 = star
  12400. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12401. {
  12402. WFIFOHEAD(fd,packet_len(0x253));
  12403. WFIFOW(fd,0)=0x253;
  12404. WFIFOB(fd,2)=TOB(skill_lv-1);
  12405. WFIFOSET(fd, packet_len(0x253));
  12406. sd->menuskill_id = SG_FEEL;
  12407. sd->menuskill_val = skill_lv;
  12408. }
  12409. /// Request to change homunculus' name (CZ_RENAME_MER).
  12410. /// 0231 <name>.24B
  12411. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12412. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12413. }
  12414. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12415. /// 0234 <id>.L
  12416. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12417. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12418. struct block_list *bl = NULL;
  12419. struct unit_data *ud = NULL;
  12420. if( sd->md && sd->md->bl.id == id )
  12421. bl = &sd->md->bl;
  12422. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12423. bl = &sd->hd->bl; // Moving Homunculus
  12424. else
  12425. return;
  12426. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12427. ud = unit_bl2ud(bl);
  12428. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12429. }
  12430. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12431. /// 0232 <id>.L <position data>.3B
  12432. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12433. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12434. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12435. struct block_list *bl = NULL;
  12436. short x, y;
  12437. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12438. if( sd->md && sd->md->bl.id == id )
  12439. bl = &sd->md->bl; // Moving Mercenary
  12440. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12441. bl = &sd->hd->bl; // Moving Homunculus
  12442. else
  12443. return;
  12444. unit_walktoxy(bl, x, y, 4);
  12445. }
  12446. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12447. /// 0233 <id>.L <target id>.L <action>.B
  12448. /// action:
  12449. /// always 0
  12450. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12451. {
  12452. struct block_list *bl = NULL;
  12453. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12454. int id = RFIFOL(fd,info->pos[0]);
  12455. int target_id = RFIFOL(fd,info->pos[1]);
  12456. int action_type = RFIFOB(fd,info->pos[2]);
  12457. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12458. bl = &sd->hd->bl;
  12459. else if( sd->md && sd->md->bl.id == id )
  12460. bl = &sd->md->bl;
  12461. else return;
  12462. unit_stop_attack(bl);
  12463. unit_attack(bl, target_id, action_type != 0);
  12464. }
  12465. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12466. /// 022d <type>.W <command>.B
  12467. /// type:
  12468. /// always 0
  12469. /// command:
  12470. /// 0 = homunculus information
  12471. /// 1 = feed
  12472. /// 2 = delete
  12473. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12474. { //[orn]
  12475. int cmd = RFIFOW(fd,0);
  12476. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12477. if(!hom_is_active(sd->hd))
  12478. return;
  12479. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12480. }
  12481. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12482. /// 0292
  12483. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12484. {
  12485. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12486. uint8 hp = 100, sp = 100;
  12487. if (item_position < 0) {
  12488. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12489. // HP restored
  12490. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12491. sp = 0;
  12492. }
  12493. else
  12494. return;
  12495. }
  12496. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12497. return;
  12498. if (!status_revive(&sd->bl, hp, sp))
  12499. return;
  12500. if (item_position < 0)
  12501. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12502. else
  12503. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12504. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12505. }
  12506. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12507. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12508. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12509. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12510. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12511. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12512. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12513. void clif_check(int fd, struct map_session_data* pl_sd)
  12514. {
  12515. WFIFOHEAD(fd,packet_len(0x214));
  12516. WFIFOW(fd, 0) = 0x214;
  12517. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12518. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12519. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12520. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12521. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12522. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12523. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12524. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12525. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12526. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12527. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12528. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12529. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12530. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12531. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12532. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12533. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12534. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12535. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12536. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12537. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12538. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12539. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12540. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12541. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12542. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12543. WFIFOSET(fd,packet_len(0x214));
  12544. }
  12545. /// /check (CZ_REQ_STATUS_GM).
  12546. /// Request character's status values.
  12547. /// 0213 <char name>.24B
  12548. void clif_parse_Check(int fd, struct map_session_data *sd)
  12549. {
  12550. char charname[NAME_LENGTH];
  12551. struct map_session_data* pl_sd;
  12552. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12553. return;
  12554. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12555. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12556. {
  12557. return;
  12558. }
  12559. clif_check(fd, pl_sd);
  12560. }
  12561. /// MAIL SYSTEM
  12562. /// By Zephyrus
  12563. ///
  12564. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12565. /// 0255 <index>.W <result>.B
  12566. /// result:
  12567. /// 0 = success
  12568. /// 1 = failure
  12569. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12570. {
  12571. WFIFOHEAD(fd,packet_len(0x255));
  12572. WFIFOW(fd,0) = 0x255;
  12573. WFIFOW(fd,2) = index;
  12574. WFIFOB(fd,4) = flag;
  12575. WFIFOSET(fd,packet_len(0x255));
  12576. }
  12577. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12578. /// 0245 <result>.B
  12579. /// result:
  12580. /// 0 = success
  12581. /// 1 = failure
  12582. /// 2 = too many items
  12583. void clif_Mail_getattachment(int fd, uint8 result)
  12584. {
  12585. WFIFOHEAD(fd,packet_len(0x245));
  12586. WFIFOW(fd,0) = 0x245;
  12587. WFIFOB(fd,2) = result;
  12588. WFIFOSET(fd,packet_len(0x245));
  12589. }
  12590. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12591. /// 0249 <result>.B
  12592. /// result:
  12593. /// 0 = success
  12594. /// 1 = recipinent does not exist
  12595. void clif_Mail_send(int fd, bool fail)
  12596. {
  12597. WFIFOHEAD(fd,packet_len(0x249));
  12598. WFIFOW(fd,0) = 0x249;
  12599. WFIFOB(fd,2) = fail;
  12600. WFIFOSET(fd,packet_len(0x249));
  12601. }
  12602. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12603. /// 0257 <mail id>.L <result>.W
  12604. /// result:
  12605. /// 0 = success
  12606. /// 1 = failure
  12607. void clif_Mail_delete(int fd, int mail_id, short fail)
  12608. {
  12609. WFIFOHEAD(fd, packet_len(0x257));
  12610. WFIFOW(fd,0) = 0x257;
  12611. WFIFOL(fd,2) = mail_id;
  12612. WFIFOW(fd,6) = fail;
  12613. WFIFOSET(fd, packet_len(0x257));
  12614. }
  12615. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12616. /// 0274 <mail id>.L <result>.W
  12617. /// result:
  12618. /// 0 = success
  12619. /// 1 = failure
  12620. void clif_Mail_return(int fd, int mail_id, short fail)
  12621. {
  12622. WFIFOHEAD(fd,packet_len(0x274));
  12623. WFIFOW(fd,0) = 0x274;
  12624. WFIFOL(fd,2) = mail_id;
  12625. WFIFOW(fd,6) = fail;
  12626. WFIFOSET(fd,packet_len(0x274));
  12627. }
  12628. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12629. /// 024a <mail id>.L <title>.40B <sender>.24B
  12630. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12631. {
  12632. WFIFOHEAD(fd,packet_len(0x24a));
  12633. WFIFOW(fd,0) = 0x24a;
  12634. WFIFOL(fd,2) = mail_id;
  12635. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12636. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12637. WFIFOSET(fd,packet_len(0x24a));
  12638. }
  12639. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12640. /// 0260 <type>.L
  12641. /// type:
  12642. /// 0 = open
  12643. /// 1 = close
  12644. void clif_Mail_window(int fd, int flag)
  12645. {
  12646. WFIFOHEAD(fd,packet_len(0x260));
  12647. WFIFOW(fd,0) = 0x260;
  12648. WFIFOL(fd,2) = flag;
  12649. WFIFOSET(fd,packet_len(0x260));
  12650. }
  12651. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12652. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12653. /// read:
  12654. /// 0 = unread
  12655. /// 1 = read
  12656. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12657. {
  12658. int fd = sd->fd;
  12659. struct mail_data *md = &sd->mail.inbox;
  12660. struct mail_message *msg;
  12661. int len, i, j;
  12662. len = 8 + (73 * md->amount);
  12663. WFIFOHEAD(fd,len);
  12664. WFIFOW(fd,0) = 0x240;
  12665. WFIFOW(fd,2) = len;
  12666. WFIFOL(fd,4) = md->amount;
  12667. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12668. {
  12669. msg = &md->msg[i];
  12670. if (msg->id < 1)
  12671. continue;
  12672. WFIFOL(fd,8+73*j) = msg->id;
  12673. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12674. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12675. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12676. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12677. j++;
  12678. }
  12679. WFIFOSET(fd,len);
  12680. if( md->full ) {// TODO: is this official?
  12681. char output[100];
  12682. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12683. clif_disp_onlyself(sd, output, strlen(output));
  12684. }
  12685. }
  12686. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12687. /// 023f
  12688. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12689. {
  12690. struct mail_data* md = &sd->mail.inbox;
  12691. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12692. intif_Mail_requestinbox(sd->status.char_id, 1);
  12693. else
  12694. clif_Mail_refreshinbox(sd);
  12695. mail_removeitem(sd, 0);
  12696. mail_removezeny(sd, 0);
  12697. }
  12698. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12699. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12700. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12701. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12702. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12703. {
  12704. int i, fd = sd->fd;
  12705. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12706. if( i == MAIL_MAX_INBOX ) {
  12707. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12708. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12709. return;
  12710. } else {
  12711. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12712. struct item *item = &msg->item;
  12713. struct item_data *data;
  12714. int msg_len = strlen(msg->body), len;
  12715. if( msg_len == 0 ) {
  12716. strcpy(msg->body, "(no message)");
  12717. msg_len = strlen(msg->body);
  12718. }
  12719. len = 101 + msg_len;
  12720. WFIFOHEAD(fd,len);
  12721. WFIFOW(fd,0) = 0x242;
  12722. WFIFOW(fd,2) = len;
  12723. WFIFOL(fd,4) = msg->id;
  12724. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12725. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12726. WFIFOL(fd,72) = 0;
  12727. WFIFOL(fd,76) = msg->zeny;
  12728. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12729. WFIFOL(fd,80) = item->amount;
  12730. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12731. WFIFOW(fd,86) = data->type;
  12732. WFIFOB(fd,88) = item->identify;
  12733. WFIFOB(fd,89) = item->attribute;
  12734. WFIFOB(fd,90) = item->refine;
  12735. WFIFOW(fd,91) = item->card[0];
  12736. WFIFOW(fd,93) = item->card[1];
  12737. WFIFOW(fd,95) = item->card[2];
  12738. WFIFOW(fd,97) = item->card[3];
  12739. } else // no item, set all to zero
  12740. memset(WFIFOP(fd,80), 0x00, 19);
  12741. WFIFOB(fd,99) = (unsigned char)msg_len;
  12742. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12743. WFIFOSET(fd,len);
  12744. if (msg->status == MAIL_UNREAD) {
  12745. msg->status = MAIL_READ;
  12746. intif_Mail_read(mail_id);
  12747. clif_parse_Mail_refreshinbox(fd, sd);
  12748. }
  12749. }
  12750. }
  12751. /// Request to open a mail (CZ_MAIL_OPEN).
  12752. /// 0241 <mail id>.L
  12753. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12754. {
  12755. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12756. if( mail_id <= 0 )
  12757. return;
  12758. if( mail_invalid_operation(sd) )
  12759. return;
  12760. clif_Mail_read(sd, mail_id);
  12761. }
  12762. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12763. /// 0244 <mail id>.L
  12764. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12765. {
  12766. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12767. int i;
  12768. bool fail = false;
  12769. if( !chrif_isconnected() )
  12770. return;
  12771. if( mail_id <= 0 )
  12772. return;
  12773. if( mail_invalid_operation(sd) )
  12774. return;
  12775. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12776. if( i == MAIL_MAX_INBOX )
  12777. return;
  12778. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12779. return;
  12780. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12781. clif_Mail_getattachment(fd, 1); //too many zeny
  12782. return;
  12783. }
  12784. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12785. struct item_data *data;
  12786. unsigned int weight;
  12787. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12788. return;
  12789. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12790. case CHKADDITEM_NEW:
  12791. fail = ( pc_inventoryblank(sd) == 0 );
  12792. break;
  12793. case CHKADDITEM_OVERAMOUNT:
  12794. fail = true;
  12795. }
  12796. if( fail ) {
  12797. clif_Mail_getattachment(fd, 1);
  12798. return;
  12799. }
  12800. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12801. if( sd->weight + weight > sd->max_weight ) {
  12802. clif_Mail_getattachment(fd, 2);
  12803. return;
  12804. }
  12805. }
  12806. sd->mail.inbox.msg[i].zeny = 0;
  12807. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12808. clif_Mail_read(sd, mail_id);
  12809. intif_Mail_getattach(sd->status.char_id, mail_id);
  12810. }
  12811. /// Request to delete a mail (CZ_MAIL_DELETE).
  12812. /// 0243 <mail id>.L
  12813. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12814. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12815. int i;
  12816. if( !chrif_isconnected() )
  12817. return;
  12818. if( mail_id <= 0 )
  12819. return;
  12820. if( mail_invalid_operation(sd) )
  12821. return;
  12822. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12823. if (i < MAIL_MAX_INBOX) {
  12824. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12825. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12826. clif_Mail_delete(sd->fd, mail_id, 1);
  12827. return;
  12828. }
  12829. intif_Mail_delete(sd->status.char_id, mail_id);
  12830. }
  12831. }
  12832. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12833. /// 0273 <mail id>.L <receive name>.24B
  12834. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12835. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12836. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12837. int i;
  12838. if( mail_id <= 0 )
  12839. return;
  12840. if( mail_invalid_operation(sd) )
  12841. return;
  12842. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12843. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12844. intif_Mail_return(sd->status.char_id, mail_id);
  12845. else
  12846. clif_Mail_return(sd->fd, mail_id, 1);
  12847. }
  12848. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12849. /// 0247 <index>.W <amount>.L
  12850. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12851. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12852. int idx = RFIFOW(fd,info->pos[0]);
  12853. int amount = RFIFOL(fd,info->pos[1]);
  12854. unsigned char flag;
  12855. if( !chrif_isconnected() )
  12856. return;
  12857. if (idx < 0 || amount < 0)
  12858. return;
  12859. flag = mail_setitem(sd, idx, amount);
  12860. clif_Mail_setattachment(fd,idx,!flag);
  12861. }
  12862. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12863. /// 0246 <type>.W
  12864. /// type:
  12865. /// 0 = reset all
  12866. /// 1 = remove item
  12867. /// 2 = remove zeny
  12868. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12869. {
  12870. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12871. if (type == 0 || type == 1)
  12872. mail_removeitem(sd, 0);
  12873. if (type == 0 || type == 2)
  12874. mail_removezeny(sd, 0);
  12875. }
  12876. /// Request to send mail (CZ_MAIL_SEND).
  12877. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12878. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12879. {
  12880. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12881. if( !chrif_isconnected() )
  12882. return;
  12883. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12884. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12885. return;
  12886. }
  12887. 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]));
  12888. }
  12889. /// AUCTION SYSTEM
  12890. /// By Zephyrus
  12891. ///
  12892. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12893. /// 025f <type>.L
  12894. /// type:
  12895. /// 0 = open
  12896. /// 1 = close
  12897. void clif_Auction_openwindow(struct map_session_data *sd)
  12898. {
  12899. int fd = sd->fd;
  12900. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12901. return;
  12902. if( !battle_config.feature_auction )
  12903. return;
  12904. WFIFOHEAD(fd,packet_len(0x25f));
  12905. WFIFOW(fd,0) = 0x25f;
  12906. WFIFOL(fd,2) = 0;
  12907. WFIFOSET(fd,packet_len(0x25f));
  12908. }
  12909. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12910. /// 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 }*
  12911. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12912. {
  12913. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12914. struct auction_data auction;
  12915. struct item_data *item;
  12916. WFIFOHEAD(fd,12 + (count * 83));
  12917. WFIFOW(fd,0) = 0x252;
  12918. WFIFOW(fd,2) = 12 + (count * 83);
  12919. WFIFOL(fd,4) = pages;
  12920. WFIFOL(fd,8) = count;
  12921. for( i = 0; i < count; i++ ) {
  12922. int k = 12 + (i * 83);
  12923. memcpy(&auction, RBUFP(buf,i * len), len);
  12924. WFIFOL(fd,k) = auction.auction_id;
  12925. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12926. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12927. WFIFOW(fd,28+k) = item->view_id;
  12928. else
  12929. WFIFOW(fd,28+k) = auction.item.nameid;
  12930. WFIFOL(fd,30+k) = auction.type;
  12931. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12932. WFIFOB(fd,36+k) = auction.item.identify;
  12933. WFIFOB(fd,37+k) = auction.item.attribute;
  12934. WFIFOB(fd,38+k) = auction.item.refine;
  12935. WFIFOW(fd,39+k) = auction.item.card[0];
  12936. WFIFOW(fd,41+k) = auction.item.card[1];
  12937. WFIFOW(fd,43+k) = auction.item.card[2];
  12938. WFIFOW(fd,45+k) = auction.item.card[3];
  12939. WFIFOL(fd,47+k) = auction.price;
  12940. WFIFOL(fd,51+k) = auction.buynow;
  12941. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12942. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12943. }
  12944. WFIFOSET(fd,WFIFOW(fd,2));
  12945. }
  12946. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12947. /// 0256 <index>.W <result>.B
  12948. /// result:
  12949. /// 0 = success
  12950. /// 1 = failure
  12951. static void clif_Auction_setitem(int fd, int index, bool fail)
  12952. {
  12953. WFIFOHEAD(fd,packet_len(0x256));
  12954. WFIFOW(fd,0) = 0x256;
  12955. WFIFOW(fd,2) = index;
  12956. WFIFOB(fd,4) = fail;
  12957. WFIFOSET(fd,packet_len(0x256));
  12958. }
  12959. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12960. /// 024b <type>.W
  12961. /// type:
  12962. /// 0 = create (any other action in auction window)
  12963. /// 1 = cancel (cancel pressed on register tab)
  12964. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12965. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12966. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12967. if( sd->auction.amount > 0 )
  12968. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12969. sd->auction.amount = 0;
  12970. }
  12971. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12972. /// 024c <index>.W <count>.L
  12973. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12974. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12975. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12976. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12977. struct item_data *item;
  12978. if( !battle_config.feature_auction )
  12979. return;
  12980. if( sd->auction.amount > 0 )
  12981. sd->auction.amount = 0;
  12982. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12983. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12984. return;
  12985. }
  12986. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12987. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12988. return;
  12989. }
  12990. 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) )
  12991. { // Consumable or pets are not allowed
  12992. clif_Auction_setitem(sd->fd, idx, true);
  12993. return;
  12994. }
  12995. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12996. !sd->status.inventory[idx].identify ||
  12997. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12998. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12999. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  13000. ) {
  13001. clif_Auction_setitem(sd->fd, idx, true);
  13002. return;
  13003. }
  13004. sd->auction.index = idx;
  13005. sd->auction.amount = amount;
  13006. clif_Auction_setitem(fd, idx + 2, false);
  13007. }
  13008. /// Result from an auction action (ZC_AUCTION_RESULT).
  13009. /// 0250 <result>.B
  13010. /// result:
  13011. /// 0 = You have failed to bid into the auction
  13012. /// 1 = You have successfully bid in the auction
  13013. /// 2 = The auction has been canceled
  13014. /// 3 = An auction with at least one bidder cannot be canceled
  13015. /// 4 = You cannot register more than 5 items in an auction at a time
  13016. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13017. /// 6 = You have won the auction
  13018. /// 7 = You have failed to win the auction
  13019. /// 8 = You do not have enough Zeny
  13020. /// 9 = You cannot place more than 5 bids at a time
  13021. void clif_Auction_message(int fd, unsigned char flag)
  13022. {
  13023. WFIFOHEAD(fd,packet_len(0x250));
  13024. WFIFOW(fd,0) = 0x250;
  13025. WFIFOB(fd,2) = flag;
  13026. WFIFOSET(fd,packet_len(0x250));
  13027. }
  13028. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13029. /// 025e <result>.W
  13030. /// result:
  13031. /// 0 = You have ended the auction
  13032. /// 1 = You cannot end the auction
  13033. /// 2 = Auction ID is incorrect
  13034. void clif_Auction_close(int fd, unsigned char flag)
  13035. {
  13036. WFIFOHEAD(fd,packet_len(0x25e));
  13037. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13038. WFIFOW(fd,2) = flag;
  13039. WFIFOSET(fd,packet_len(0x25e));
  13040. }
  13041. /// Request to add an auction (CZ_AUCTION_ADD).
  13042. /// 024d <now money>.L <max money>.L <delete hour>.W
  13043. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13044. {
  13045. struct auction_data auction;
  13046. struct item_data *item;
  13047. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13048. if( !battle_config.feature_auction )
  13049. return;
  13050. auction.price = RFIFOL(fd,info->pos[0]);
  13051. auction.buynow = RFIFOL(fd,info->pos[1]);
  13052. auction.hours = RFIFOW(fd,info->pos[2]);
  13053. // Invalid Situations...
  13054. if( sd->auction.amount < 1 ) {
  13055. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13056. return;
  13057. }
  13058. if( auction.price >= auction.buynow ) {
  13059. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13060. return;
  13061. }
  13062. if( auction.hours < 1 || auction.hours > 48 ) {
  13063. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13064. return;
  13065. }
  13066. // Auction checks...
  13067. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13068. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13069. clif_Auction_message(fd, 2); // The auction has been canceled
  13070. return;
  13071. }
  13072. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13073. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13074. return;
  13075. }
  13076. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13077. auction.buynow = battle_config.auction_maximumprice;
  13078. if( auction.price >= auction.buynow )
  13079. auction.price = auction.buynow - 1;
  13080. }
  13081. auction.auction_id = 0;
  13082. auction.seller_id = sd->status.char_id;
  13083. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13084. auction.buyer_id = 0;
  13085. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13086. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  13087. {
  13088. clif_Auction_message(fd, 2); // The auction has been canceled
  13089. return;
  13090. }
  13091. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  13092. { // Just in case
  13093. clif_Auction_message(fd, 2); // The auction has been canceled
  13094. return;
  13095. }
  13096. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13097. auction.type = item->type;
  13098. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  13099. auction.item.amount = 1;
  13100. auction.timestamp = 0;
  13101. if( !intif_Auction_register(&auction) )
  13102. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13103. else
  13104. {
  13105. int zeny = auction.hours*battle_config.auction_feeperhour;
  13106. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13107. sd->auction.amount = 0;
  13108. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13109. }
  13110. }
  13111. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13112. /// 024e <auction id>.L
  13113. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13114. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13115. intif_Auction_cancel(sd->status.char_id, auction_id);
  13116. }
  13117. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13118. /// 025d <auction id>.L
  13119. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13120. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13121. intif_Auction_close(sd->status.char_id, auction_id);
  13122. }
  13123. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13124. /// 024f <auction id>.L <money>.L
  13125. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13126. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13127. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13128. int bid = RFIFOL(fd,info->pos[1]);
  13129. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13130. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13131. return;
  13132. }
  13133. if( bid <= 0 )
  13134. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13135. else if( bid > sd->status.zeny )
  13136. clif_Auction_message(fd, 8); // You do not have enough zeny
  13137. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13138. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13139. else {
  13140. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13141. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13142. }
  13143. }
  13144. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13145. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13146. /// search type:
  13147. /// 0 = armor
  13148. /// 1 = weapon
  13149. /// 2 = card
  13150. /// 3 = misc
  13151. /// 4 = name search
  13152. /// 5 = auction id search
  13153. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13154. char search_text[NAME_LENGTH];
  13155. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13156. short type = RFIFOW(fd,info->pos[0]);
  13157. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13158. int page = RFIFOW(fd,info->pos[3]);
  13159. if( !battle_config.feature_auction )
  13160. return;
  13161. clif_parse_Auction_cancelreg(fd, sd);
  13162. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  13163. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13164. }
  13165. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13166. /// 025c <type>.W
  13167. /// type:
  13168. /// 0 = sell (own auctions)
  13169. /// 1 = buy (own bids)
  13170. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13171. {
  13172. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  13173. if( !battle_config.feature_auction )
  13174. return;
  13175. clif_parse_Auction_cancelreg(fd, sd);
  13176. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13177. }
  13178. /// CASH/POINT SHOP
  13179. ///
  13180. void clif_cashshop_open( struct map_session_data* sd ){
  13181. WFIFOHEAD( sd->fd, 10 );
  13182. WFIFOW( sd->fd, 0 ) = 0x845;
  13183. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13184. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13185. WFIFOSET( sd->fd, 10 );
  13186. }
  13187. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13188. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13189. clif_cashshop_open( sd );
  13190. }
  13191. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13192. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13193. // No need to do anything here
  13194. }
  13195. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13196. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13197. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13198. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13199. int j;
  13200. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  13201. return;
  13202. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13203. WFIFOW(fd, 0) = 0x8c0;
  13204. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13205. WFIFOL(fd, 4) = tab;
  13206. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13207. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13208. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13209. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13210. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13211. }
  13212. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13213. }
  13214. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13215. void clif_cashshop_list( int fd ){
  13216. int tab;
  13217. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13218. int length = 8 + cash_shop_items[tab].count * 6;
  13219. int i, offset;
  13220. WFIFOHEAD( fd, length );
  13221. WFIFOW( fd, 0 ) = 0x8ca;
  13222. WFIFOW( fd, 2 ) = length;
  13223. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13224. WFIFOW( fd, 6 ) = tab;
  13225. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13226. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13227. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13228. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13229. }
  13230. WFIFOSET( fd, length );
  13231. }
  13232. }
  13233. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13234. if( !sd->status.cashshop_sent ) {
  13235. clif_cashshop_list( fd );
  13236. sd->status.cashshop_sent = true;
  13237. }
  13238. }
  13239. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13240. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13241. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13242. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13243. {
  13244. int fd, i, cost[2] = { 0, 0 };
  13245. #if PACKETVER < 20070711
  13246. const int offset = 8;
  13247. #else
  13248. const int offset = 12;
  13249. #endif
  13250. nullpo_retv(sd);
  13251. nullpo_retv(nd);
  13252. npc_shop_currency_type(sd, nd, cost, true);
  13253. fd = sd->fd;
  13254. sd->npc_shopid = nd->bl.id;
  13255. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13256. WFIFOW(fd,0) = 0x287;
  13257. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13258. WFIFOL(fd,4) = cost[0];
  13259. #if PACKETVER >= 20070711
  13260. WFIFOL(fd,8) = cost[1];
  13261. #endif
  13262. for( i = 0; i < nd->u.shop.count; i++ ) {
  13263. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13264. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13265. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13266. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13267. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13268. }
  13269. WFIFOSET(fd,WFIFOW(fd,2));
  13270. }
  13271. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13272. /// 0289 <cash point>.L <error>.W
  13273. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13274. /// error:
  13275. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13276. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13277. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13278. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13279. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13280. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13281. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13282. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13283. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13284. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13285. {
  13286. int fd, cost[2] = { 0, 0 };
  13287. struct npc_data *nd;
  13288. nullpo_retv(sd);
  13289. fd = sd->fd;
  13290. nd = map_id2nd(sd->npc_shopid);
  13291. npc_shop_currency_type(sd, nd, cost, false);
  13292. WFIFOHEAD(fd, packet_len(0x289));
  13293. WFIFOW(fd,0) = 0x289;
  13294. WFIFOL(fd,2) = cost[0];
  13295. #if PACKETVER < 20070711
  13296. WFIFOW(fd,6) = TOW(error);
  13297. #else
  13298. WFIFOL(fd,6) = cost[1];
  13299. WFIFOW(fd,10) = TOW(error);
  13300. #endif
  13301. WFIFOSET(fd, packet_len(0x289));
  13302. }
  13303. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13304. WFIFOHEAD( sd->fd, 16 );
  13305. WFIFOW( sd->fd, 0 ) = 0x849;
  13306. WFIFOL( sd->fd, 2 ) = item_id;
  13307. WFIFOW( sd->fd, 6 ) = result;
  13308. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13309. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13310. WFIFOSET( sd->fd, 16 );
  13311. }
  13312. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13313. /// 0288 <name id>.W <amount>.W
  13314. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13315. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13316. /// 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)
  13317. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13318. struct s_packet_db* info;
  13319. int cmd = RFIFOW(fd,0);
  13320. nullpo_retv(sd);
  13321. info = &packet_db[sd->packet_ver][cmd];
  13322. if( sd->state.trading || !sd->npc_shopid ) {
  13323. clif_cashshop_ack(sd,1);
  13324. return;
  13325. }
  13326. else {
  13327. #if PACKETVER < 20101116
  13328. short nameid = RFIFOW(fd,info->pos[0]);
  13329. short amount = RFIFOW(fd,info->pos[1]);
  13330. int points = RFIFOL(fd,info->pos[2]);
  13331. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13332. #else
  13333. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13334. int len = RFIFOW(fd,info->pos[0]);
  13335. int points = RFIFOL(fd,info->pos[1]);
  13336. int count = RFIFOW(fd,info->pos[2]);
  13337. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13338. if( len < 10 || len != 10 + count * s_itl){
  13339. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13340. return;
  13341. }
  13342. if(cmd==0x848){
  13343. if (cashshop_buylist( sd, points, count, item_list))
  13344. clif_cashshop_ack(sd,0);
  13345. return;
  13346. } else {
  13347. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13348. return;
  13349. }
  13350. #endif
  13351. }
  13352. }
  13353. /// Adoption System
  13354. ///
  13355. /// Adoption message (ZC_BABYMSG).
  13356. /// 0216 <msg>.L
  13357. /// msg:
  13358. /// 0 = "You cannot adopt more than 1 child."
  13359. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13360. /// 2 = "You cannot adopt a married person."
  13361. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13362. {
  13363. int fd = sd->fd;
  13364. WFIFOHEAD(fd,6);
  13365. WFIFOW(fd,0) = 0x216;
  13366. WFIFOL(fd,2) = type;
  13367. WFIFOSET(fd,6);
  13368. }
  13369. /// Adoption confirmation (ZC_REQ_BABY).
  13370. /// 01f6 <account id>.L <char id>.L <name>.B
  13371. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13372. {
  13373. int fd = sd->fd;
  13374. WFIFOHEAD(fd,34);
  13375. WFIFOW(fd,0) = 0x1f6;
  13376. WFIFOL(fd,2) = src->status.account_id;
  13377. WFIFOL(fd,6) = p_id;
  13378. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13379. WFIFOSET(fd,34);
  13380. }
  13381. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13382. /// 01f9 <account id>.L
  13383. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13384. {
  13385. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13386. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13387. if( pc_can_Adopt(sd, p_sd, tsd) )
  13388. {
  13389. tsd->adopt_invite = sd->status.account_id;
  13390. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13391. }
  13392. }
  13393. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13394. /// 01f7 <account id>.L <char id>.L <answer>.L
  13395. /// answer:
  13396. /// 0 = rejected
  13397. /// 1 = accepted
  13398. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13399. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13400. int p1_id = RFIFOL(fd,info->pos[0]);
  13401. int p2_id = RFIFOL(fd,info->pos[1]);
  13402. int result = RFIFOL(fd,info->pos[2]);
  13403. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13404. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13405. int pid = sd->adopt_invite;
  13406. sd->adopt_invite = 0;
  13407. if( p1_sd == NULL || p2_sd == NULL )
  13408. return; // Both players need to be online
  13409. if( pid != p1_sd->status.account_id )
  13410. return; // Incorrect values
  13411. if( result == 0 )
  13412. return; // Rejected
  13413. pc_adoption(p1_sd, p2_sd, sd);
  13414. }
  13415. /// Convex Mirror (ZC_BOSS_INFO).
  13416. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13417. /// infoType:
  13418. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13419. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13420. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13421. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13422. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13423. {
  13424. WFIFOHEAD(fd,70);
  13425. memset(WFIFOP(fd,0),0,70);
  13426. WFIFOW(fd,0) = 0x293;
  13427. if( md != NULL ) {
  13428. if( md->bl.prev != NULL ) { // Boss on This Map
  13429. if( flag ) {
  13430. WFIFOB(fd,2) = 1;
  13431. WFIFOL(fd,3) = md->bl.x;
  13432. WFIFOL(fd,7) = md->bl.y;
  13433. } else
  13434. WFIFOB(fd,2) = 2; // First Time
  13435. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13436. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13437. unsigned int seconds;
  13438. int hours, minutes;
  13439. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13440. hours = seconds / (60 * 60);
  13441. seconds = seconds - (60 * 60 * hours);
  13442. minutes = seconds / 60;
  13443. WFIFOB(fd,2) = 3;
  13444. WFIFOW(fd,11) = hours; // Hours
  13445. WFIFOW(fd,13) = minutes; // Minutes
  13446. }
  13447. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13448. }
  13449. WFIFOSET(fd,70);
  13450. }
  13451. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13452. /// 02d6 <account id>.L
  13453. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13454. {
  13455. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13456. struct map_session_data* tsd = map_id2sd(aid);
  13457. if (!tsd)
  13458. return;
  13459. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13460. clif_viewequip_ack(sd, tsd);
  13461. else
  13462. clif_msg(sd, VIEW_EQUIP_FAIL);
  13463. }
  13464. /// Request to change equip window tick (CZ_CONFIG).
  13465. /// 02d8 <type>.L <flag>.L
  13466. /// type:
  13467. /// 0 = open equip window
  13468. /// flag:
  13469. /// 0 = disabled
  13470. /// 1 = enabled
  13471. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13472. {
  13473. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13474. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13475. sd->status.show_equip = flag;
  13476. clif_equiptickack(sd, flag);
  13477. }
  13478. /// Request to change party invitation tick.
  13479. /// value:
  13480. /// 0 = disabled
  13481. /// 1 = enabled
  13482. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13483. {
  13484. bool flag = RFIFOB(fd,6) ? true : false;
  13485. sd->status.allow_party = flag;
  13486. clif_partytickack(sd, flag);
  13487. }
  13488. /// Questlog System [Kevin] [Inkfish]
  13489. ///
  13490. /**
  13491. * Safe check to init packet len & quest num for player.
  13492. * @param def_len
  13493. * @param info_len Length of each quest info.
  13494. * @param avail_quests Avail quests that player has.
  13495. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13496. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13497. **/
  13498. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13499. (*limit_out) = (0xFFFF - def_len) / info_len;
  13500. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13501. (*len_out) = ((*limit_out) * info_len) + def_len;
  13502. }
  13503. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13504. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13505. /// 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)
  13506. /// 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!
  13507. void clif_quest_send_list(struct map_session_data *sd)
  13508. {
  13509. int fd = sd->fd;
  13510. int i;
  13511. int offset = 8;
  13512. int limit = 0;
  13513. #if PACKETVER >= 20141022
  13514. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13515. WFIFOHEAD(fd,i);
  13516. WFIFOW(fd, 0) = 0x97a;
  13517. WFIFOL(fd, 4) = limit;
  13518. for (i = 0; i < limit; i++) {
  13519. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13520. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13521. offset += 4;
  13522. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13523. offset++;
  13524. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13525. offset += 4;
  13526. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13527. offset += 4;
  13528. WFIFOW(fd, offset) = qi->objectives_count;
  13529. offset += 2;
  13530. if( qi->objectives_count > 0 ){
  13531. int j;
  13532. struct mob_db *mob;
  13533. for( j = 0; j < qi->objectives_count; j++ ){
  13534. mob = mob_db(qi->objectives[j].mob);
  13535. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13536. offset += 4;
  13537. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13538. offset += 2;
  13539. WFIFOW(fd, offset) = qi->objectives[j].count;
  13540. offset += 2;
  13541. memcpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13542. offset += NAME_LENGTH;
  13543. }
  13544. }
  13545. }
  13546. WFIFOW(fd, 2) = offset;
  13547. WFIFOSET(fd, offset);
  13548. #else
  13549. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13550. WFIFOHEAD(fd,i);
  13551. WFIFOW(fd, 0) = 0x2b1;
  13552. WFIFOL(fd, 4) = limit;
  13553. for (i = 0; i < limit; i++) {
  13554. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13555. offset += 4;
  13556. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13557. offset += 1;
  13558. }
  13559. WFIFOW(fd, 2) = offset;
  13560. WFIFOSET(fd, offset);
  13561. #endif
  13562. }
  13563. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13564. /// 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
  13565. void clif_quest_send_mission(struct map_session_data *sd)
  13566. {
  13567. int fd = sd->fd;
  13568. int i, j, limit = 0;
  13569. int len = sd->avail_quests*104+8;
  13570. struct mob_db *mob;
  13571. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13572. WFIFOHEAD(fd, len);
  13573. WFIFOW(fd, 0) = 0x2b2;
  13574. WFIFOW(fd, 2) = len;
  13575. WFIFOL(fd, 4) = limit;
  13576. for (i = 0; i < limit; i++) {
  13577. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13578. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13579. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13580. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13581. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13582. for (j = 0 ; j < qi->objectives_count; j++) {
  13583. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13584. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13585. mob = mob_db(qi->objectives[j].mob);
  13586. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13587. }
  13588. }
  13589. WFIFOSET(fd, len);
  13590. }
  13591. /// Notification about a new quest (ZC_ADD_QUEST).
  13592. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13593. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13594. {
  13595. int fd = sd->fd;
  13596. int i;
  13597. struct quest_db *qi = quest_search(qd->quest_id);
  13598. WFIFOHEAD(fd, packet_len(0x2b3));
  13599. WFIFOW(fd, 0) = 0x2b3;
  13600. WFIFOL(fd, 2) = qd->quest_id;
  13601. WFIFOB(fd, 6) = qd->state;
  13602. WFIFOB(fd, 7) = qd->time - qi->time;
  13603. WFIFOL(fd, 11) = qd->time;
  13604. WFIFOW(fd, 15) = qi->objectives_count;
  13605. for (i = 0; i < qi->objectives_count; i++) {
  13606. struct mob_db *mob;
  13607. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13608. WFIFOW(fd, i*30+21) = qd->count[i];
  13609. mob = mob_db(qi->objectives[i].mob);
  13610. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13611. }
  13612. WFIFOSET(fd, packet_len(0x2b3));
  13613. }
  13614. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13615. /// 02b4 <quest id>.L
  13616. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13617. {
  13618. int fd = sd->fd;
  13619. WFIFOHEAD(fd, packet_len(0x2b4));
  13620. WFIFOW(fd, 0) = 0x2b4;
  13621. WFIFOL(fd, 2) = quest_id;
  13622. WFIFOSET(fd, packet_len(0x2b4));
  13623. }
  13624. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13625. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13626. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  13627. {
  13628. int fd = sd->fd;
  13629. int i;
  13630. struct quest_db *qi = quest_search(qd->quest_id);
  13631. int len = qi->objectives_count * 12 + 6;
  13632. WFIFOHEAD(fd, len);
  13633. WFIFOW(fd, 0) = 0x2b5;
  13634. WFIFOW(fd, 2) = len;
  13635. WFIFOW(fd, 4) = qi->objectives_count;
  13636. for (i = 0; i < qi->objectives_count; i++) {
  13637. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  13638. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  13639. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  13640. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  13641. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  13642. }
  13643. }
  13644. WFIFOSET(fd, len);
  13645. }
  13646. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13647. /// 02b6 <quest id>.L <active>.B
  13648. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13649. {
  13650. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13651. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13652. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13653. }
  13654. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13655. /// 02b7 <quest id>.L <active>.B
  13656. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13657. {
  13658. int fd = sd->fd;
  13659. WFIFOHEAD(fd, packet_len(0x2b7));
  13660. WFIFOW(fd, 0) = 0x2b7;
  13661. WFIFOL(fd, 2) = quest_id;
  13662. WFIFOB(fd, 6) = active;
  13663. WFIFOSET(fd, packet_len(0x2b7));
  13664. }
  13665. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13666. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  13667. /// effect:
  13668. /// 0 = none
  13669. /// 1 = exclamation mark icon
  13670. /// 2 = question mark icon
  13671. /// color:
  13672. /// 0 = yellow
  13673. /// 1 = orange
  13674. /// 2 = green
  13675. /// 3 = purple
  13676. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  13677. {
  13678. #if PACKETVER >= 20090218
  13679. int fd = sd->fd;
  13680. WFIFOHEAD(fd, packet_len(0x446));
  13681. WFIFOW(fd, 0) = 0x446;
  13682. WFIFOL(fd, 2) = bl->id;
  13683. WFIFOW(fd, 6) = bl->x;
  13684. WFIFOW(fd, 8) = bl->y;
  13685. WFIFOW(fd, 10) = effect;
  13686. WFIFOW(fd, 12) = color;
  13687. WFIFOSET(fd, packet_len(0x446));
  13688. #endif
  13689. }
  13690. /// Mercenary System
  13691. ///
  13692. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13693. /// 02a2 <var id>.W <value>.L
  13694. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13695. {
  13696. struct mercenary_data *md;
  13697. struct status_data *status;
  13698. int fd;
  13699. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13700. return;
  13701. fd = sd->fd;
  13702. status = &md->battle_status;
  13703. WFIFOHEAD(fd,packet_len(0x2a2));
  13704. WFIFOW(fd,0) = 0x2a2;
  13705. WFIFOW(fd,2) = type;
  13706. switch( type ) {
  13707. case SP_ATK1:
  13708. {
  13709. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13710. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13711. }
  13712. break;
  13713. case SP_MATK1:
  13714. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13715. break;
  13716. case SP_HIT:
  13717. WFIFOL(fd,4) = status->hit;
  13718. break;
  13719. case SP_CRITICAL:
  13720. WFIFOL(fd,4) = status->cri/10;
  13721. break;
  13722. case SP_DEF1:
  13723. WFIFOL(fd,4) = status->def;
  13724. break;
  13725. case SP_MDEF1:
  13726. WFIFOL(fd,4) = status->mdef;
  13727. break;
  13728. case SP_MERCFLEE:
  13729. WFIFOL(fd,4) = status->flee;
  13730. break;
  13731. case SP_ASPD:
  13732. WFIFOL(fd,4) = status->amotion;
  13733. break;
  13734. case SP_HP:
  13735. WFIFOL(fd,4) = status->hp;
  13736. break;
  13737. case SP_MAXHP:
  13738. WFIFOL(fd,4) = status->max_hp;
  13739. break;
  13740. case SP_SP:
  13741. WFIFOL(fd,4) = status->sp;
  13742. break;
  13743. case SP_MAXSP:
  13744. WFIFOL(fd,4) = status->max_sp;
  13745. break;
  13746. case SP_MERCKILLS:
  13747. WFIFOL(fd,4) = md->mercenary.kill_count;
  13748. break;
  13749. case SP_MERCFAITH:
  13750. WFIFOL(fd,4) = mercenary_get_faith(md);
  13751. break;
  13752. }
  13753. WFIFOSET(fd,packet_len(0x2a2));
  13754. }
  13755. /// Mercenary base status data (ZC_MER_INIT).
  13756. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13757. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13758. /// <calls>.L <kills>.L <atk range>.W
  13759. void clif_mercenary_info(struct map_session_data *sd)
  13760. {
  13761. int fd;
  13762. struct mercenary_data *md;
  13763. struct status_data *status;
  13764. int atk;
  13765. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13766. return;
  13767. fd = sd->fd;
  13768. status = &md->battle_status;
  13769. WFIFOHEAD(fd,packet_len(0x29b));
  13770. WFIFOW(fd,0) = 0x29b;
  13771. WFIFOL(fd,2) = md->bl.id;
  13772. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13773. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13774. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13775. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13776. WFIFOW(fd,10) = status->hit;
  13777. WFIFOW(fd,12) = status->cri/10;
  13778. WFIFOW(fd,14) = status->def;
  13779. WFIFOW(fd,16) = status->mdef;
  13780. WFIFOW(fd,18) = status->flee;
  13781. WFIFOW(fd,20) = status->amotion;
  13782. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13783. WFIFOW(fd,46) = md->db->lv;
  13784. WFIFOL(fd,48) = status->hp;
  13785. WFIFOL(fd,52) = status->max_hp;
  13786. WFIFOL(fd,56) = status->sp;
  13787. WFIFOL(fd,60) = status->max_sp;
  13788. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13789. WFIFOW(fd,68) = mercenary_get_faith(md);
  13790. WFIFOL(fd,70) = mercenary_get_calls(md);
  13791. WFIFOL(fd,74) = md->mercenary.kill_count;
  13792. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13793. WFIFOSET(fd,packet_len(0x29b));
  13794. }
  13795. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13796. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13797. void clif_mercenary_skillblock(struct map_session_data *sd)
  13798. {
  13799. struct mercenary_data *md;
  13800. int fd, i, len = 4;
  13801. if( sd == NULL || (md = sd->md) == NULL )
  13802. return;
  13803. fd = sd->fd;
  13804. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13805. WFIFOW(fd,0) = 0x29d;
  13806. for( i = 0; i < MAX_MERCSKILL; i++ )
  13807. {
  13808. uint16 id;
  13809. short idx = -1;
  13810. if( (id = md->db->skill[i].id) == 0 )
  13811. continue;
  13812. if ((idx = mercenary_skill_get_index(id)) == -1)
  13813. continue;
  13814. WFIFOW(fd,len) = id;
  13815. WFIFOL(fd,len+2) = skill_get_inf(id);
  13816. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13817. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13818. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv);
  13819. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13820. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13821. len += 37;
  13822. }
  13823. WFIFOW(fd,2) = len;
  13824. WFIFOSET(fd,len);
  13825. }
  13826. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13827. /// 029f <command>.B
  13828. /// 1 = mercenary information
  13829. /// 2 = delete
  13830. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13831. {
  13832. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13833. if( sd->md == NULL )
  13834. return;
  13835. if( option == 2 ) mercenary_delete(sd->md, 2);
  13836. }
  13837. /// Mercenary Message
  13838. /// message:
  13839. /// 0 = Mercenary soldier's duty hour is over.
  13840. /// 1 = Your mercenary soldier has been killed.
  13841. /// 2 = Your mercenary soldier has been fired.
  13842. /// 3 = Your mercenary soldier has ran away.
  13843. void clif_mercenary_message(struct map_session_data* sd, int message){
  13844. clif_msg(sd, MERC_MSG_BASE + message);
  13845. }
  13846. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13847. /// 0298 <name id>.W <seconds>.L
  13848. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13849. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13850. WFIFOHEAD(fd,packet_len(0x298));
  13851. WFIFOW(fd,0) = 0x298;
  13852. WFIFOW(fd,2) = nameid;
  13853. WFIFOL(fd,4) = seconds;
  13854. WFIFOSET(fd,packet_len(0x298));
  13855. }
  13856. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13857. /// 0299 <index>.W <name id>.W
  13858. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13859. { // '<ItemName>' item has been deleted from the Inventory
  13860. WFIFOHEAD(fd,packet_len(0x299));
  13861. WFIFOW(fd,0) = 0x299;
  13862. WFIFOW(fd,2) = index+2;
  13863. WFIFOW(fd,4) = nameid;
  13864. WFIFOSET(fd,packet_len(0x299));
  13865. }
  13866. /// Book Reading (ZC_READ_BOOK).
  13867. /// 0294 <book id>.L <page>.L
  13868. void clif_readbook(int fd, int book_id, int page)
  13869. {
  13870. WFIFOHEAD(fd,packet_len(0x294));
  13871. WFIFOW(fd,0) = 0x294;
  13872. WFIFOL(fd,2) = book_id;
  13873. WFIFOL(fd,6) = page;
  13874. WFIFOSET(fd,packet_len(0x294));
  13875. }
  13876. /// Battlegrounds
  13877. ///
  13878. /// Updates HP bar of a camp member.
  13879. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  13880. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  13881. void clif_bg_hp(struct map_session_data *sd) {
  13882. #if PACKETVER < 20140613
  13883. unsigned char buf[34];
  13884. const int cmd = 0x2e0;
  13885. #else
  13886. unsigned char buf[14];
  13887. const int cmd = 0xa0e;
  13888. #endif
  13889. nullpo_retv(sd);
  13890. WBUFW(buf,0) = cmd;
  13891. WBUFL(buf,2) = sd->status.account_id;
  13892. #if PACKETVER < 20140613
  13893. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13894. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  13895. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13896. WBUFW(buf,32) = 100;
  13897. } else {
  13898. WBUFW(buf,30) = sd->battle_status.hp;
  13899. WBUFW(buf,32) = sd->battle_status.max_hp;
  13900. }
  13901. #else
  13902. if( sd->battle_status.max_hp > INT32_MAX ) {
  13903. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13904. WBUFL(buf,10) = 100;
  13905. } else {
  13906. WBUFL(buf,6) = sd->battle_status.hp;
  13907. WBUFL(buf,10) = sd->battle_status.max_hp;
  13908. }
  13909. #endif
  13910. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13911. }
  13912. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13913. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13914. void clif_bg_xy(struct map_session_data *sd)
  13915. {
  13916. unsigned char buf[36];
  13917. nullpo_retv(sd);
  13918. WBUFW(buf,0)=0x2df;
  13919. WBUFL(buf,2)=sd->status.account_id;
  13920. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13921. WBUFW(buf,30)=sd->status.class_;
  13922. WBUFW(buf,32)=sd->bl.x;
  13923. WBUFW(buf,34)=sd->bl.y;
  13924. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13925. }
  13926. void clif_bg_xy_remove(struct map_session_data *sd)
  13927. {
  13928. unsigned char buf[36];
  13929. nullpo_retv(sd);
  13930. WBUFW(buf,0)=0x2df;
  13931. WBUFL(buf,2)=sd->status.account_id;
  13932. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13933. WBUFW(buf,30)=0;
  13934. WBUFW(buf,32)=-1;
  13935. WBUFW(buf,34)=-1;
  13936. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13937. }
  13938. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13939. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13940. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13941. {
  13942. struct map_session_data *sd;
  13943. unsigned char *buf;
  13944. if( (sd = bg_getavailablesd(bg)) == NULL )
  13945. return;
  13946. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13947. WBUFW(buf,0) = 0x2dc;
  13948. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13949. WBUFL(buf,4) = src_id;
  13950. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13951. memcpy(WBUFP(buf,32), mes, len);
  13952. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13953. if( buf )
  13954. aFree(buf);
  13955. }
  13956. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13957. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13958. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13959. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13960. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13961. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13962. char *name, *message;
  13963. int namelen, messagelen;
  13964. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13965. return;
  13966. if( is_atcommand(fd, sd, message, 1) )
  13967. return;
  13968. if (sd->sc.cant.chat)
  13969. return; //no "chatting" while muted.
  13970. if( battle_config.min_chat_delay ) {
  13971. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13972. return;
  13973. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13974. }
  13975. if (battle_config.idletime_option&IDLE_CHAT)
  13976. sd->idletime = last_tick;
  13977. bg_send_message(sd, text, textlen);
  13978. }
  13979. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13980. /// 02de <camp A points>.W <camp B points>.W
  13981. void clif_bg_updatescore(int16 m)
  13982. {
  13983. struct block_list bl;
  13984. unsigned char buf[6];
  13985. bl.id = 0;
  13986. bl.type = BL_NUL;
  13987. bl.m = m;
  13988. WBUFW(buf,0) = 0x2de;
  13989. WBUFW(buf,2) = map[m].bgscore_lion;
  13990. WBUFW(buf,4) = map[m].bgscore_eagle;
  13991. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13992. }
  13993. void clif_bg_updatescore_single(struct map_session_data *sd)
  13994. {
  13995. int fd;
  13996. nullpo_retv(sd);
  13997. fd = sd->fd;
  13998. WFIFOHEAD(fd,packet_len(0x2de));
  13999. WFIFOW(fd,0) = 0x2de;
  14000. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  14001. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  14002. WFIFOSET(fd,packet_len(0x2de));
  14003. }
  14004. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14005. /// 02dd <account id>.L <name>.24B <camp>.W
  14006. void clif_sendbgemblem_area(struct map_session_data *sd)
  14007. {
  14008. unsigned char buf[33];
  14009. nullpo_retv(sd);
  14010. WBUFW(buf, 0) = 0x2dd;
  14011. WBUFL(buf,2) = sd->bl.id;
  14012. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14013. WBUFW(buf,30) = sd->bg_id;
  14014. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14015. }
  14016. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14017. {
  14018. nullpo_retv(sd);
  14019. WFIFOHEAD(fd,32);
  14020. WFIFOW(fd,0) = 0x2dd;
  14021. WFIFOL(fd,2) = sd->bl.id;
  14022. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  14023. WFIFOW(fd,30) = sd->bg_id;
  14024. WFIFOSET(fd,packet_len(0x2dd));
  14025. }
  14026. /// Custom Fonts (ZC_NOTIFY_FONT).
  14027. /// 02ef <account_id>.L <font id>.W
  14028. void clif_font(struct map_session_data *sd)
  14029. {
  14030. #if PACKETVER >= 20080102
  14031. unsigned char buf[8];
  14032. nullpo_retv(sd);
  14033. WBUFW(buf,0) = 0x2ef;
  14034. WBUFL(buf,2) = sd->bl.id;
  14035. WBUFW(buf,6) = sd->status.font;
  14036. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14037. #endif
  14038. }
  14039. /*==========================================
  14040. * Notifies party members of instance change
  14041. *------------------------------------------*/
  14042. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  14043. {
  14044. #if PACKETVER >= 20071128
  14045. unsigned char buf[65];
  14046. if(!sd) return;
  14047. WBUFW(buf,0) = 0x2cb;
  14048. memcpy( WBUFP(buf,2), name, 62 );
  14049. WBUFW(buf,63) = num;
  14050. if(flag) // A timer has changed or been added
  14051. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  14052. else // No notification
  14053. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  14054. #endif
  14055. return;
  14056. }
  14057. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  14058. {
  14059. #if PACKETVER >= 20071128
  14060. unsigned char buf[4];
  14061. if(!sd) return;
  14062. WBUFW(buf,0) = 0x2cc;
  14063. WBUFW(buf,2) = num;
  14064. if(flag) // A timer has changed or been added
  14065. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  14066. else // No notification
  14067. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  14068. #endif
  14069. return;
  14070. }
  14071. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  14072. {
  14073. #if PACKETVER >= 20071128
  14074. unsigned char buf[71];
  14075. if(!sd) return; //party_getavailablesd can return NULL
  14076. WBUFW(buf,0) = 0x2cd;
  14077. memcpy( WBUFP(buf,2), name, 62 );
  14078. WBUFL(buf,63) = limit1;
  14079. WBUFL(buf,67) = limit2;
  14080. if(flag) // A timer has changed or been added
  14081. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  14082. else // No notification
  14083. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  14084. #endif
  14085. return;
  14086. }
  14087. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  14088. {
  14089. #if PACKETVER >= 20071128
  14090. unsigned char buf[10];
  14091. if(!sd) return;
  14092. WBUFW(buf,0) = 0x2ce;
  14093. WBUFL(buf,2) = type;
  14094. WBUFL(buf,6) = limit;
  14095. if(flag) // A timer has changed or been added
  14096. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  14097. else // No notification
  14098. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  14099. #endif
  14100. return;
  14101. }
  14102. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14103. /// 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
  14104. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14105. {
  14106. #if PACKETVER >= 20071002
  14107. unsigned char buf[22];
  14108. struct item_data* id = itemdb_search(item_data->nameid);
  14109. WBUFW(buf,0) = 0x2b8;
  14110. WBUFL(buf,2) = sd->status.account_id;
  14111. WBUFW(buf,6) = item_data->nameid;
  14112. WBUFB(buf,8) = item_data->identify;
  14113. WBUFB(buf,9) = item_data->attribute;
  14114. WBUFB(buf,10) = item_data->refine;
  14115. clif_addcards(WBUFP(buf,11), item_data);
  14116. WBUFW(buf,19) = id->equip; // equip location
  14117. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14118. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14119. #endif
  14120. }
  14121. /** Display gained exp (ZC_NOTIFY_EXP).
  14122. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14123. * amount: INT32_MIN ~ INT32_MAX
  14124. * var id:
  14125. * SP_BASEEXP, SP_JOBEXP
  14126. * exp type:
  14127. * 0 = normal exp gained/lost
  14128. * 1 = quest exp gained/lost
  14129. * @param sd Player
  14130. * @param exp EXP value gained/loss
  14131. * @param type SP_BASEEXP, SP_JOBEXP
  14132. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14133. * @param lost True:if lossing EXP
  14134. */
  14135. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14136. {
  14137. int fd;
  14138. nullpo_retv(sd);
  14139. fd = sd->fd;
  14140. WFIFOHEAD(fd, packet_len(0x7f6));
  14141. WFIFOW(fd,0) = 0x7f6;
  14142. WFIFOL(fd,2) = sd->bl.id;
  14143. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14144. WFIFOW(fd,10) = type;
  14145. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  14146. WFIFOSET(fd,packet_len(0x7f6));
  14147. }
  14148. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14149. /// type:
  14150. /// 0 = Displays 'value' for 5 seconds.
  14151. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14152. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14153. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14154. /// value:
  14155. /// 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).
  14156. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14157. {
  14158. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14159. WFIFOW(sd->fd,0) = 0x1b1;
  14160. WFIFOB(sd->fd,2) = type;
  14161. WFIFOL(sd->fd,3) = value;
  14162. WFIFOSET(sd->fd, packet_len(0x1b1));
  14163. }
  14164. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14165. /// 021d <state>.L
  14166. /// state:
  14167. /// 0 = Full effects
  14168. /// 1 = Reduced effects
  14169. ///
  14170. /// NOTE: The state is used on Aegis for sending skill unit packet
  14171. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14172. /// whenever possible. Due to the way the decision check is
  14173. /// constructed, this state tracking was rendered useless,
  14174. /// as the only skill unit, that is sent with 0x1c9 is
  14175. /// Graffiti.
  14176. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14177. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14178. sd->state.lesseffect = ( isLess != 0 );
  14179. }
  14180. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14181. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  14182. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  14183. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14184. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14185. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14186. int type = RFIFOL(fd,info->pos[1]);
  14187. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14188. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14189. if( sd->state.trading || sd->npc_shopid )
  14190. return;
  14191. if( flag == 0 || n == 0) {
  14192. clif_menuskill_clear(sd);
  14193. return; // Canceled by player.
  14194. }
  14195. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14196. clif_menuskill_clear(sd);
  14197. return; // Prevent hacking.
  14198. }
  14199. switch( type ) {
  14200. case 0: // Change Material
  14201. skill_changematerial(sd,n,item_list);
  14202. break;
  14203. case 1: // Level 1: Pure to Rough
  14204. case 2: // Level 2: Rough to Pure
  14205. skill_elementalanalysis(sd,n,type,item_list);
  14206. break;
  14207. }
  14208. clif_menuskill_clear(sd);
  14209. return;
  14210. }
  14211. /*==========================================
  14212. * Elemental System
  14213. *==========================================*/
  14214. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14215. struct elemental_data *ed;
  14216. struct status_data *status;
  14217. int fd;
  14218. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14219. return;
  14220. fd = sd->fd;
  14221. status = &ed->battle_status;
  14222. WFIFOHEAD(fd,8);
  14223. WFIFOW(fd,0) = 0x81e;
  14224. WFIFOW(fd,2) = type;
  14225. switch( type ) {
  14226. case SP_HP:
  14227. WFIFOL(fd,4) = status->hp;
  14228. break;
  14229. case SP_MAXHP:
  14230. WFIFOL(fd,4) = status->max_hp;
  14231. break;
  14232. case SP_SP:
  14233. WFIFOL(fd,4) = status->sp;
  14234. break;
  14235. case SP_MAXSP:
  14236. WFIFOL(fd,4) = status->max_sp;
  14237. break;
  14238. }
  14239. WFIFOSET(fd,8);
  14240. }
  14241. void clif_elemental_info(struct map_session_data *sd) {
  14242. int fd;
  14243. struct elemental_data *ed;
  14244. struct status_data *status;
  14245. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14246. return;
  14247. fd = sd->fd;
  14248. status = &ed->battle_status;
  14249. WFIFOHEAD(fd,22);
  14250. WFIFOW(fd, 0) = 0x81d;
  14251. WFIFOL(fd, 2) = ed->bl.id;
  14252. WFIFOL(fd, 6) = status->hp;
  14253. WFIFOL(fd,10) = status->max_hp;
  14254. WFIFOL(fd,14) = status->sp;
  14255. WFIFOL(fd,18) = status->max_sp;
  14256. WFIFOSET(fd,22);
  14257. }
  14258. /// Buying Store System
  14259. ///
  14260. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14261. /// 0810 <slots>.B
  14262. void clif_buyingstore_open(struct map_session_data* sd)
  14263. {
  14264. int fd = sd->fd;
  14265. WFIFOHEAD(fd,packet_len(0x810));
  14266. WFIFOW(fd,0) = 0x810;
  14267. WFIFOB(fd,2) = sd->buyingstore.slots;
  14268. WFIFOSET(fd,packet_len(0x810));
  14269. }
  14270. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14271. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14272. /// result:
  14273. /// 0 = cancel
  14274. /// 1 = open
  14275. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14276. {
  14277. const unsigned int blocksize = 8;
  14278. uint8* itemlist;
  14279. char storename[MESSAGE_SIZE];
  14280. unsigned char result;
  14281. int zenylimit;
  14282. unsigned int count, packet_len;
  14283. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14284. packet_len = RFIFOW(fd,info->pos[0]);
  14285. // TODO: Make this check global for all variable length packets.
  14286. if( packet_len < 89 )
  14287. {// minimum packet length
  14288. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14289. return;
  14290. }
  14291. zenylimit = RFIFOL(fd,info->pos[1]);
  14292. result = RFIFOL(fd,info->pos[2]);
  14293. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  14294. itemlist = RFIFOP(fd,info->pos[4]);
  14295. // so that buyingstore_create knows, how many elements it has access to
  14296. packet_len-= info->pos[4];
  14297. if( packet_len%blocksize )
  14298. {
  14299. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14300. return;
  14301. }
  14302. count = packet_len/blocksize;
  14303. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14304. }
  14305. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14306. /// 0812 <result>.W <total weight>.L
  14307. /// result:
  14308. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14309. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14310. /// 8 = "No sale (purchase) information available." (0x705)
  14311. /// ? = nothing
  14312. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14313. {
  14314. int fd = sd->fd;
  14315. WFIFOHEAD(fd,packet_len(0x812));
  14316. WFIFOW(fd,0) = 0x812;
  14317. WFIFOW(fd,2) = result;
  14318. WFIFOL(fd,4) = weight;
  14319. WFIFOSET(fd,packet_len(0x812));
  14320. }
  14321. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14322. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14323. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14324. {
  14325. int fd = sd->fd;
  14326. unsigned int i;
  14327. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14328. WFIFOW(fd,0) = 0x813;
  14329. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14330. WFIFOL(fd,4) = sd->bl.id;
  14331. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14332. for( i = 0; i < sd->buyingstore.slots; i++ )
  14333. {
  14334. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14335. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14336. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14337. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14338. }
  14339. WFIFOSET(fd,WFIFOW(fd,2));
  14340. }
  14341. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14342. /// 0814 <account id>.L <store name>.80B
  14343. void clif_buyingstore_entry(struct map_session_data* sd)
  14344. {
  14345. uint8 buf[86];
  14346. WBUFW(buf,0) = 0x814;
  14347. WBUFL(buf,2) = sd->bl.id;
  14348. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14349. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14350. }
  14351. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14352. {
  14353. int fd = sd->fd;
  14354. WFIFOHEAD(fd,packet_len(0x814));
  14355. WFIFOW(fd,0) = 0x814;
  14356. WFIFOL(fd,2) = pl_sd->bl.id;
  14357. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14358. WFIFOSET(fd,packet_len(0x814));
  14359. }
  14360. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14361. /// 0815
  14362. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14363. {
  14364. buyingstore_close(sd);
  14365. }
  14366. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14367. /// 0816 <account id>.L
  14368. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14369. {
  14370. uint8 buf[6];
  14371. WBUFW(buf,0) = 0x816;
  14372. WBUFL(buf,2) = sd->bl.id;
  14373. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14374. }
  14375. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14376. {
  14377. int fd = sd->fd;
  14378. WFIFOHEAD(fd,packet_len(0x816));
  14379. WFIFOW(fd,0) = 0x816;
  14380. WFIFOL(fd,2) = pl_sd->bl.id;
  14381. WFIFOSET(fd,packet_len(0x816));
  14382. }
  14383. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14384. /// 0817 <account id>.L
  14385. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14386. {
  14387. uint32 account_id;
  14388. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14389. buyingstore_open(sd, account_id);
  14390. }
  14391. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14392. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14393. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14394. {
  14395. int fd = sd->fd;
  14396. unsigned int i;
  14397. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14398. WFIFOW(fd,0) = 0x818;
  14399. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14400. WFIFOL(fd,4) = pl_sd->bl.id;
  14401. WFIFOL(fd,8) = pl_sd->buyer_id;
  14402. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14403. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14404. {
  14405. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14406. 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.
  14407. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14408. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14409. }
  14410. WFIFOSET(fd,WFIFOW(fd,2));
  14411. }
  14412. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14413. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14414. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14415. {
  14416. const unsigned int blocksize = 6;
  14417. uint8* itemlist;
  14418. uint32 account_id;
  14419. unsigned int count, packet_len, buyer_id;
  14420. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14421. packet_len = RFIFOW(fd,info->pos[0]);
  14422. if( packet_len < 12 )
  14423. {// minimum packet length
  14424. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14425. return;
  14426. }
  14427. account_id = RFIFOL(fd,info->pos[1]);
  14428. buyer_id = RFIFOL(fd,info->pos[2]);
  14429. itemlist = RFIFOP(fd,info->pos[3]);
  14430. // so that buyingstore_trade knows, how many elements it has access to
  14431. packet_len-= info->pos[3];
  14432. if( packet_len%blocksize )
  14433. {
  14434. 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);
  14435. return;
  14436. }
  14437. count = packet_len/blocksize;
  14438. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14439. }
  14440. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14441. /// 081a <result>.W
  14442. /// result:
  14443. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14444. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14445. /// ? = nothing
  14446. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14447. {
  14448. int fd = sd->fd;
  14449. WFIFOHEAD(fd,packet_len(0x81a));
  14450. WFIFOW(fd,0) = 0x81a;
  14451. WFIFOW(fd,2) = result;
  14452. WFIFOSET(fd,packet_len(0x81a));
  14453. }
  14454. /// Updates the zeny limit and an item in the buying store item list.
  14455. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  14456. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  14457. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  14458. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  14459. const int cmd = 0x81b;
  14460. #else
  14461. const int cmd = 0x9e6;
  14462. #endif
  14463. int offset = 0;
  14464. int fd = sd->fd;
  14465. WFIFOHEAD(fd,packet_len(cmd));
  14466. WFIFOW(fd,0) = cmd;
  14467. WFIFOW(fd,2) = nameid;
  14468. WFIFOW(fd,4) = amount; // amount of nameid received
  14469. #if PACKETVER >= 20141016
  14470. WFIFOL(fd,6) = zeny; // zeny
  14471. offset += 4;
  14472. #endif
  14473. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  14474. #if PACKETVER >= 20141016
  14475. WFIFOL(fd,10+offset) = char_id; // GID
  14476. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  14477. #endif
  14478. WFIFOSET(fd,packet_len(cmd));
  14479. }
  14480. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14481. /// 081c <index>.W <amount>.W <price>.L
  14482. /// message:
  14483. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14484. ///
  14485. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14486. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14487. {
  14488. int fd = sd->fd;
  14489. WFIFOHEAD(fd,packet_len(0x81c));
  14490. WFIFOW(fd,0) = 0x81c;
  14491. WFIFOW(fd,2) = index+2;
  14492. WFIFOW(fd,4) = amount;
  14493. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14494. WFIFOSET(fd,packet_len(0x81c));
  14495. }
  14496. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14497. /// 0824 <result>.W <name id>.W
  14498. /// result:
  14499. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14500. /// 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)
  14501. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14502. /// ? = nothing
  14503. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14504. {
  14505. int fd = sd->fd;
  14506. WFIFOHEAD(fd,packet_len(0x824));
  14507. WFIFOW(fd,0) = 0x824;
  14508. WFIFOW(fd,2) = result;
  14509. WFIFOW(fd,4) = nameid;
  14510. WFIFOSET(fd,packet_len(0x824));
  14511. }
  14512. /// Search Store Info System
  14513. ///
  14514. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14515. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14516. /// type:
  14517. /// 0 = Vending
  14518. /// 1 = Buying Store
  14519. ///
  14520. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14521. /// amount of card slots. If the client does not know about the item it
  14522. /// cannot be searched.
  14523. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14524. {
  14525. const unsigned int blocksize = 2;
  14526. const uint8* itemlist;
  14527. const uint8* cardlist;
  14528. unsigned char type;
  14529. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14530. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14531. packet_len = RFIFOW(fd,info->pos[0]);
  14532. if( packet_len < 15 )
  14533. {// minimum packet length
  14534. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14535. return;
  14536. }
  14537. type = RFIFOB(fd,info->pos[1]);
  14538. max_price = RFIFOL(fd,info->pos[2]);
  14539. min_price = RFIFOL(fd,info->pos[3]);
  14540. item_count = RFIFOB(fd,info->pos[4]);
  14541. card_count = RFIFOB(fd,info->pos[5]);
  14542. itemlist = RFIFOP(fd,info->pos[6]);
  14543. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14544. // check, if there is enough data for the claimed count of items
  14545. packet_len-= info->pos[6];
  14546. if( packet_len%blocksize )
  14547. {
  14548. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14549. return;
  14550. }
  14551. count = packet_len/blocksize;
  14552. if( count < item_count+card_count )
  14553. {
  14554. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14555. return;
  14556. }
  14557. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14558. }
  14559. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14560. /// 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 }*
  14561. /// is first page:
  14562. /// 0 = appends to existing results
  14563. /// 1 = clears previous results before displaying this result set
  14564. /// is next page:
  14565. /// 0 = no "next" label
  14566. /// 1 = "next" label to retrieve more results
  14567. void clif_search_store_info_ack(struct map_session_data* sd)
  14568. {
  14569. const unsigned int blocksize = MESSAGE_SIZE+26;
  14570. int fd = sd->fd;
  14571. unsigned int i, start, end;
  14572. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14573. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14574. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14575. WFIFOW(fd,0) = 0x836;
  14576. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14577. WFIFOB(fd,4) = !sd->searchstore.pages;
  14578. WFIFOB(fd,5) = searchstore_querynext(sd);
  14579. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14580. for( i = start; i < end; i++ ) {
  14581. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14582. struct item it;
  14583. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14584. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14585. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14586. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14587. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14588. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14589. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14590. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14591. // make-up an item for clif_addcards
  14592. memset(&it, 0, sizeof(it));
  14593. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14594. it.nameid = ssitem->nameid;
  14595. it.amount = ssitem->amount;
  14596. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14597. }
  14598. WFIFOSET(fd,WFIFOW(fd,2));
  14599. }
  14600. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14601. /// 0837 <reason>.B
  14602. /// reason:
  14603. /// 0 = "No matching stores were found." (0x70b)
  14604. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14605. /// 2 = "You cannot search anymore." (0x706)
  14606. /// 3 = "You cannot search yet." (0x708)
  14607. /// 4 = "No sale (purchase) information available." (0x705)
  14608. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14609. {
  14610. int fd = sd->fd;
  14611. WFIFOHEAD(fd,packet_len(0x837));
  14612. WFIFOW(fd,0) = 0x837;
  14613. WFIFOB(fd,2) = reason;
  14614. WFIFOSET(fd,packet_len(0x837));
  14615. }
  14616. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14617. /// 0838
  14618. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14619. {
  14620. searchstore_next(sd);
  14621. }
  14622. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14623. /// 083a <type>.W <remaining uses>.B
  14624. /// type:
  14625. /// 0 = Search Stores
  14626. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14627. void clif_open_search_store_info(struct map_session_data* sd)
  14628. {
  14629. int fd = sd->fd;
  14630. WFIFOHEAD(fd,packet_len(0x83a));
  14631. WFIFOW(fd,0) = 0x83a;
  14632. WFIFOW(fd,2) = sd->searchstore.effect;
  14633. #if PACKETVER > 20100701
  14634. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14635. #endif
  14636. WFIFOSET(fd,packet_len(0x83a));
  14637. }
  14638. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14639. /// 083b
  14640. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14641. {
  14642. searchstore_close(sd);
  14643. }
  14644. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14645. /// 083c <account id>.L <store id>.L <nameid>.W
  14646. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14647. {
  14648. unsigned short nameid;
  14649. uint32 account_id, store_id;
  14650. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14651. account_id = RFIFOL(fd,info->pos[0]);
  14652. store_id = RFIFOL(fd,info->pos[1]);
  14653. nameid = RFIFOW(fd,info->pos[2]);
  14654. searchstore_click(sd, account_id, store_id, nameid);
  14655. }
  14656. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14657. /// 083d <xPos>.W <yPos>.W
  14658. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14659. {
  14660. int fd = sd->fd;
  14661. WFIFOHEAD(fd,packet_len(0x83d));
  14662. WFIFOW(fd,0) = 0x83d;
  14663. WFIFOW(fd,2) = x;
  14664. WFIFOW(fd,4) = y;
  14665. WFIFOSET(fd,packet_len(0x83d));
  14666. }
  14667. /// Parse function for packet debugging.
  14668. void clif_parse_debug(int fd,struct map_session_data *sd)
  14669. {
  14670. int cmd, packet_len;
  14671. // clif_parse ensures, that there is at least 2 bytes of data
  14672. cmd = RFIFOW(fd,0);
  14673. if( sd ) {
  14674. packet_len = packet_db[sd->packet_ver][cmd].len;
  14675. if( packet_len == 0 )
  14676. {// unknown
  14677. packet_len = RFIFOREST(fd);
  14678. }
  14679. else if( packet_len == -1 )
  14680. {// variable length
  14681. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14682. }
  14683. 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);
  14684. }
  14685. else
  14686. {
  14687. packet_len = RFIFOREST(fd);
  14688. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14689. }
  14690. ShowDump(RFIFOP(fd,0), packet_len);
  14691. }
  14692. /*==========================================
  14693. * Server tells client to display a window similar to Magnifier (item) one
  14694. * Server populates the window with avilable elemental converter options according to player's inventory
  14695. *------------------------------------------*/
  14696. int clif_elementalconverter_list(struct map_session_data *sd) {
  14697. int i,c,view,fd;
  14698. nullpo_ret(sd);
  14699. /// Main client packet processing function
  14700. fd=sd->fd;
  14701. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14702. WFIFOW(fd, 0)=0x1ad;
  14703. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14704. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14705. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14706. WFIFOW(fd,c*2+ 4)= view;
  14707. else
  14708. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14709. c++;
  14710. }
  14711. }
  14712. WFIFOW(fd,2) = c*2+4;
  14713. WFIFOSET(fd, WFIFOW(fd,2));
  14714. if (c > 0) {
  14715. sd->menuskill_id = SA_CREATECON;
  14716. sd->menuskill_val = c;
  14717. }
  14718. return 0;
  14719. }
  14720. /**
  14721. * Rune Knight
  14722. **/
  14723. void clif_millenniumshield(struct block_list *bl, short shields) {
  14724. #if PACKETVER >= 20081217
  14725. unsigned char buf[10];
  14726. WBUFW(buf,0) = 0x440;
  14727. WBUFL(buf,2) = bl->id;
  14728. WBUFW(buf,6) = shields;
  14729. WBUFW(buf,8) = 0;
  14730. clif_send(buf,packet_len(0x440),bl,AREA);
  14731. #endif
  14732. }
  14733. /**
  14734. * Warlock
  14735. **/
  14736. /*==========================================
  14737. * Spellbook list [LimitLine/3CeAM]
  14738. *------------------------------------------*/
  14739. int clif_spellbook_list(struct map_session_data *sd)
  14740. {
  14741. int i, c;
  14742. int fd;
  14743. nullpo_ret(sd);
  14744. fd = sd->fd;
  14745. WFIFOHEAD(fd, 8 * 8 + 8);
  14746. WFIFOW(fd,0) = 0x1ad;
  14747. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14748. {
  14749. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14750. {
  14751. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14752. c++;
  14753. }
  14754. }
  14755. if( c > 0 )
  14756. {
  14757. WFIFOW(fd,2) = c * 2 + 4;
  14758. WFIFOSET(fd, WFIFOW(fd, 2));
  14759. sd->menuskill_id = WL_READING_SB;
  14760. sd->menuskill_val = c;
  14761. }
  14762. else{
  14763. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14764. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14765. }
  14766. return 1;
  14767. }
  14768. /**
  14769. * Mechanic
  14770. **/
  14771. /*==========================================
  14772. * Magic Decoy Material List
  14773. *------------------------------------------*/
  14774. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14775. int i, c;
  14776. int fd;
  14777. nullpo_ret(sd);
  14778. fd = sd->fd;
  14779. WFIFOHEAD(fd, 8 * 8 + 8);
  14780. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14781. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14782. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14783. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14784. c ++;
  14785. }
  14786. }
  14787. if( c > 0 ) {
  14788. sd->menuskill_id = NC_MAGICDECOY;
  14789. sd->menuskill_val = skill_lv;
  14790. sd->sc.comet_x = x;
  14791. sd->sc.comet_y = y;
  14792. WFIFOW(fd,2) = c * 2 + 4;
  14793. WFIFOSET(fd, WFIFOW(fd, 2));
  14794. } else {
  14795. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14796. return 0;
  14797. }
  14798. return 1;
  14799. }
  14800. /*==========================================
  14801. * Guillotine Cross Poisons List
  14802. *------------------------------------------*/
  14803. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14804. int i, c;
  14805. int fd;
  14806. nullpo_ret(sd);
  14807. fd = sd->fd;
  14808. WFIFOHEAD(fd, 8 * 8 + 8);
  14809. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14810. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14811. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14812. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14813. c ++;
  14814. }
  14815. }
  14816. if( c > 0 ) {
  14817. sd->menuskill_id = GC_POISONINGWEAPON;
  14818. sd->menuskill_val = skill_lv;
  14819. WFIFOW(fd,2) = c * 2 + 4;
  14820. WFIFOSET(fd, WFIFOW(fd, 2));
  14821. } else {
  14822. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14823. return 0;
  14824. }
  14825. return 1;
  14826. }
  14827. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  14828. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14829. int fd, i, c;
  14830. nullpo_ret(sd);
  14831. fd = sd->fd;
  14832. if( !fd )
  14833. return 0;
  14834. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14835. return 0;
  14836. WFIFOHEAD(fd, 2 * 6 + 4);
  14837. WFIFOW(fd,0) = 0x442;
  14838. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14839. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14840. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14841. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14842. {
  14843. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14844. c++;
  14845. }
  14846. if( c > 0 ) {
  14847. WFIFOW(fd,2) = 8 + c * 2;
  14848. WFIFOL(fd,4) = c;
  14849. WFIFOSET(fd,WFIFOW(fd,2));
  14850. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14851. sd->menuskill_val = c;
  14852. } else {
  14853. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14854. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14855. }
  14856. return 1;
  14857. }
  14858. /*===========================================
  14859. * Skill list for Four Elemental Analysis
  14860. * and Change Material skills.
  14861. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  14862. *------------------------------------------*/
  14863. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  14864. #if PACKETVER >= 20090922
  14865. int fd = sd->fd;
  14866. nullpo_ret(sd);
  14867. sd->menuskill_id = skill_id; // To prevent hacking.
  14868. sd->menuskill_val = skill_lv;
  14869. if( skill_id == GN_CHANGEMATERIAL )
  14870. skill_lv = 0; // Changematerial
  14871. WFIFOHEAD(fd, packet_len(0x7e3));
  14872. WFIFOW(fd,0) = 0x7e3;
  14873. WFIFOL(fd,2) = skill_lv;
  14874. WFIFOL(fd,4) = 0;
  14875. WFIFOSET(fd, packet_len(0x7e3));
  14876. #endif
  14877. return 1;
  14878. }
  14879. /*==========================================
  14880. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14881. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14882. * RFIFOL(fd,2) - type (currently not used)
  14883. *------------------------------------------*/
  14884. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14885. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14886. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14887. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14888. return;
  14889. if( pc_istrading(sd) ) {
  14890. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14891. clif_menuskill_clear(sd);
  14892. return;
  14893. }
  14894. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14895. clif_menuskill_clear(sd);
  14896. }
  14897. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  14898. /// 08cf <id>.L <type>.W <num>.W
  14899. void clif_spiritcharm(struct map_session_data *sd) {
  14900. unsigned char buf[10];
  14901. nullpo_retv(sd);
  14902. WBUFW(buf,0) = 0x08cf;
  14903. WBUFL(buf,2) = sd->bl.id;
  14904. WBUFW(buf,6) = sd->spiritcharm_type;
  14905. WBUFW(buf,8) = sd->spiritcharm;
  14906. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  14907. }
  14908. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14909. /// 0907 <index>.W
  14910. ///
  14911. /// R 0908 <index>.w <type>.b
  14912. /// type:
  14913. /// 0 = move item to personal tab
  14914. /// 1 = move item to normal tab
  14915. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14916. #if PACKETVER >= 20111122
  14917. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14918. int index = RFIFOW(fd,info->pos[0]) - 2;
  14919. int type = RFIFOB(fd, info->pos[1]);
  14920. /* can't move while dead. */
  14921. if(pc_isdead(sd)) {
  14922. return;
  14923. }
  14924. if (index < 0 || index >= MAX_INVENTORY)
  14925. return;
  14926. if ( sd->status.inventory[index].favorite && type == 1 )
  14927. sd->status.inventory[index].favorite = 0;
  14928. else if( type == 0 )
  14929. sd->status.inventory[index].favorite = 1;
  14930. else
  14931. return;/* nothing to do. */
  14932. clif_favorite_item(sd, index);
  14933. #endif
  14934. }
  14935. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14936. /// 0900 <index>.W <favorite>.B
  14937. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14938. int fd = sd->fd;
  14939. WFIFOHEAD(fd,packet_len(0x908));
  14940. WFIFOW(fd,0) = 0x908;
  14941. WFIFOW(fd,2) = index+2;
  14942. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14943. WFIFOSET(fd,packet_len(0x908));
  14944. }
  14945. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  14946. void clif_snap( struct block_list *bl, short x, short y ) {
  14947. unsigned char buf[10];
  14948. WBUFW(buf,0) = 0x8d2;
  14949. WBUFL(buf,2) = bl->id;
  14950. WBUFW(buf,6) = x;
  14951. WBUFW(buf,8) = y;
  14952. if( disguised(bl) )
  14953. {
  14954. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14955. WBUFL(buf,2) = -bl->id;
  14956. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14957. } else
  14958. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14959. }
  14960. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  14961. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14962. #if PACKETVER >= 20120404
  14963. WFIFOHEAD(fd,packet_len(0x977));
  14964. WFIFOW(fd,0) = 0x977;
  14965. WFIFOL(fd,2) = md->bl.id;
  14966. WFIFOL(fd,6) = md->status.hp;
  14967. WFIFOL(fd,10) = md->status.max_hp;
  14968. WFIFOSET(fd,packet_len(0x977));
  14969. #endif
  14970. }
  14971. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14972. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14973. return;
  14974. }
  14975. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14976. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14977. WFIFOW(sd->fd,0) = 0x2c9;
  14978. WFIFOB(sd->fd,2) = flag;
  14979. WFIFOSET(sd->fd, packet_len(0x2c9));
  14980. }
  14981. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14982. /// 0979 <world name>.24B <char name>.24B
  14983. void clif_ackworldinfo(struct map_session_data* sd) {
  14984. int fd;
  14985. nullpo_retv(sd);
  14986. fd = sd->fd;
  14987. WFIFOHEAD(fd,packet_len(0x979));
  14988. WFIFOW(fd,0)=0x979;
  14989. //AID -> world name ?
  14990. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14991. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14992. WFIFOSET(fd,packet_len(0x979));
  14993. }
  14994. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14995. /// 0978 <AID>.L
  14996. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  14997. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14998. if(sd)
  14999. clif_ackworldinfo(sd);
  15000. }
  15001. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15002. /// 0447
  15003. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15004. //if(sd)
  15005. ;
  15006. }
  15007. /// req world info (CZ_CLIENT_VERSION)
  15008. /// 044A <version>.L
  15009. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15010. //if(sd)
  15011. ;
  15012. }
  15013. /// Ranking list
  15014. /// ranking pointlist { <name>.24B <point>.L }*10
  15015. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  15016. struct fame_list* list;
  15017. int skip = 0;
  15018. switch(rankingtype+1) { //to keep the same case as char.c
  15019. case 1: list = smith_fame_list; break;
  15020. case 2: list = chemist_fame_list; break;
  15021. case 3: list = taekwon_fame_list; break;
  15022. default: skip=1; break;
  15023. }
  15024. if(!skip) {
  15025. int i;
  15026. //Packet size limits this list to 10 elements. [Skotlex]
  15027. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  15028. if (list[i].id > 0) {
  15029. const char* name;
  15030. if (strcmp(list[i].name, "-") == 0 &&
  15031. (name = map_charid2nick(list[i].id)) != NULL)
  15032. {
  15033. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  15034. } else {
  15035. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  15036. }
  15037. } else {
  15038. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  15039. }
  15040. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  15041. }
  15042. for(;i < 10; i++) { //In case the MAX is less than 10.
  15043. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  15044. WBUFL(buf, idx+24*10 + i * 4) = 0;
  15045. }
  15046. }
  15047. }
  15048. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15049. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15050. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  15051. int mypoint = 0;
  15052. WBUFW(buf,0) = 0x97d;
  15053. WBUFW(buf,2) = rankingType;
  15054. clif_sub_ranklist(buf,4,sd,rankingType);
  15055. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15056. case MAPID_BLACKSMITH:
  15057. case MAPID_ALCHEMIST:
  15058. case MAPID_TAEKWON:
  15059. mypoint = sd->status.fame;
  15060. }
  15061. WBUFL(buf,284) = mypoint; //mypoint
  15062. clif_send(buf, 288, &sd->bl, SELF);
  15063. }
  15064. /*
  15065. * 097c <type> (CZ_REQ_RANKING)
  15066. * type
  15067. * 0: /blacksmith
  15068. * 1: /alchemist
  15069. * 2: /taekwon
  15070. * 3: /pk
  15071. * */
  15072. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15073. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  15074. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15075. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  15076. }
  15077. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15078. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15079. #if PACKETVER < 20130710
  15080. switch(rankingtype){
  15081. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  15082. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  15083. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  15084. }
  15085. #else
  15086. int fd=sd->fd;
  15087. WFIFOHEAD(fd,14);
  15088. WFIFOW(fd,0) = 0x97e;
  15089. WFIFOW(fd,2) = rankingtype;
  15090. WFIFOL(fd,4) = point;
  15091. WFIFOL(fd,8) = sd->status.fame;
  15092. WFIFOSET(fd,12);
  15093. #endif
  15094. }
  15095. /**
  15096. * Transmit personal information to player. (rates)
  15097. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15098. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15099. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15100. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15101. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15102. * FIXME!
  15103. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15104. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15105. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15106. */
  15107. #ifdef VIP_ENABLE
  15108. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15109. if (sd) {
  15110. struct s_packet_db* info;
  15111. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15112. int cmd = 0, fd, i = 0;
  15113. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15114. int details_bexp[PINFO_MAX];
  15115. int details_drop[PINFO_MAX];
  15116. int details_penalty[PINFO_MAX];
  15117. int penalty_const;
  15118. /**
  15119. * Set for EXP
  15120. */
  15121. //0:PCRoom
  15122. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15123. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  15124. details_bexp[0] = 0;
  15125. else {
  15126. if (details_bexp[0] < 100) {
  15127. details_bexp[0] = 100 - details_bexp[0];
  15128. details_bexp[0] = 0 - details_bexp[0];
  15129. }
  15130. else
  15131. details_bexp[0] = details_bexp[0] - 100;
  15132. }
  15133. //1:Premium
  15134. if (pc_isvip(sd)) {
  15135. details_bexp[1] = battle_config.vip_base_exp_increase;
  15136. if (details_bexp[1] < 0)
  15137. details_bexp[1] = 0 - details_bexp[1];
  15138. }
  15139. else
  15140. details_bexp[1] = 0;
  15141. //2:Server
  15142. details_bexp[2] = battle_config.base_exp_rate;
  15143. if (details_bexp[2] == 100)
  15144. details_bexp[2] = 0;
  15145. else {
  15146. if (details_bexp[2] < 100) {
  15147. details_bexp[2] = 100 - details_bexp[2];
  15148. details_bexp[2] = 0 - details_bexp[2];
  15149. }
  15150. else
  15151. details_bexp[2] = details_bexp[2] - 100;
  15152. }
  15153. //3:TPLUS
  15154. details_bexp[3] = 0;
  15155. /* End - EXP set*/
  15156. /**
  15157. * Set for Drop rate
  15158. */
  15159. //0:PCRoom
  15160. details_drop[0] = 0;
  15161. //1:Premium
  15162. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15163. if (pc_isvip(sd)) {
  15164. if (details_drop[1] < 0)
  15165. details_drop[1] = 0 - details_drop[1];
  15166. }
  15167. else
  15168. details_drop[1] = 0;
  15169. //2:Server
  15170. details_drop[2] = battle_config.item_rate_common;
  15171. if (details_drop[2] == 100)
  15172. details_drop[2] = 0;
  15173. else {
  15174. if (details_drop[2] < 100) {
  15175. details_drop[2] = 100 - details_drop[2];
  15176. details_drop[2] = 0 - details_drop[2];
  15177. }
  15178. else
  15179. details_drop[2] = details_drop[2] - 100;
  15180. }
  15181. //3:TPLUS
  15182. details_drop[3] = 0;
  15183. /* End - Drop set*/
  15184. /**
  15185. * Set for Penalty rate
  15186. */
  15187. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  15188. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  15189. //0:PCRoom
  15190. details_penalty[0] = 0;
  15191. //1:Premium
  15192. if (pc_isvip(sd)) {
  15193. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  15194. if (details_penalty[1] == 100)
  15195. details_penalty[1] = 0;
  15196. else {
  15197. if (details_penalty[1] < 100) {
  15198. details_penalty[1] = 100 - details_penalty[1];
  15199. details_penalty[1] = 0 - details_penalty[1];
  15200. }
  15201. else
  15202. details_penalty[1] = details_penalty[1] - 100;
  15203. }
  15204. }
  15205. else
  15206. details_penalty[1] = 0;
  15207. //2:Server
  15208. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  15209. if (details_penalty[2] == 100)
  15210. details_penalty[2] = 0;
  15211. else {
  15212. if (details_penalty[2] < 100) {
  15213. details_penalty[2] = 100 - details_penalty[2];
  15214. details_penalty[2] = 0 - details_penalty[2];
  15215. }
  15216. else
  15217. details_penalty[2] = details_penalty[2] - 100;
  15218. }
  15219. //3:TPLUS
  15220. details_penalty[3] = 0;
  15221. /* End - Penalty set*/
  15222. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  15223. info = &packet_db[sd->packet_ver][cmd];
  15224. len = info->len; //this is the base len without details
  15225. if(!len) return; //version as packet disable
  15226. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15227. szdetails = 7;
  15228. factor = 1;
  15229. }
  15230. else if (cmd == 0x097b) {
  15231. tot_baseexp *= factor;
  15232. tot_drop *= factor;
  15233. tot_penalty *= factor;
  15234. }
  15235. fd = sd->fd;
  15236. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15237. WFIFOW(fd,0) = cmd;
  15238. for (i = 0; i < maxinfotype; i++) {
  15239. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15240. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15241. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15242. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15243. tot_baseexp += details_bexp[i]*factor;
  15244. tot_drop += details_penalty[i]*factor;
  15245. tot_penalty += details_drop[i]*factor;
  15246. len += szdetails;
  15247. }
  15248. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15249. if (cmd == 0x08cb) { //0x08cb version
  15250. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15251. WFIFOW(fd,info->pos[2]) = tot_drop;
  15252. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15253. }
  15254. else { //2013-08-07aRagexe uses 0x097b
  15255. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15256. WFIFOL(fd,info->pos[2]) = tot_drop;
  15257. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15258. }
  15259. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15260. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15261. WFIFOSET(fd,len);
  15262. }
  15263. }
  15264. #endif
  15265. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15266. char cmd[30];
  15267. int t_aid = RFIFOL(fd,2);
  15268. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15269. is_atcommand(fd, sd, cmd, 1);
  15270. }
  15271. /**
  15272. * Marks Crimson Marker target on mini-map to the caster
  15273. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15274. * @param fd
  15275. * @param bl Crimson Marker target
  15276. **/
  15277. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15278. struct s_packet_db* info;
  15279. int cmd = 0;
  15280. int16 len;
  15281. unsigned char buf[11];
  15282. nullpo_retv(sd);
  15283. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  15284. if (!cmd)
  15285. cmd = 0x09C1; //default
  15286. info = &packet_db[sd->packet_ver][cmd];
  15287. if (!(len = info->len))
  15288. return;
  15289. WBUFW(buf, 0) = cmd;
  15290. WBUFL(buf, info->pos[0]) = bl->id;
  15291. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15292. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15293. clif_send(buf, len, &sd->bl, SELF);
  15294. }
  15295. /**
  15296. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15297. **/
  15298. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15299. struct s_packet_db *info = NULL;
  15300. int cmd = 0;
  15301. nullpo_retv(sd);
  15302. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  15303. info = &packet_db[sd->packet_ver][cmd];
  15304. if (!cmd || !info->len)
  15305. return;
  15306. WFIFOHEAD(sd->fd, info->len);
  15307. WFIFOW(sd->fd, 0) = cmd;
  15308. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15309. WFIFOSET(sd->fd, info->len);
  15310. }
  15311. /**
  15312. * [Ind/Hercules]
  15313. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  15314. **/
  15315. void clif_showscript(struct block_list* bl, const char* message) {
  15316. char buf[256];
  15317. size_t len;
  15318. nullpo_retv(bl);
  15319. if(!message)
  15320. return;
  15321. len = strlen(message)+1;
  15322. if( len > sizeof(buf)-8 ) {
  15323. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15324. len = sizeof(buf)-8;
  15325. }
  15326. WBUFW(buf,0) = 0x8b3;
  15327. WBUFW(buf,2) = (uint16)(len+8);
  15328. WBUFL(buf,4) = bl->id;
  15329. safestrncpy((char *) WBUFP(buf,8), message, len);
  15330. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  15331. }
  15332. /**
  15333. * [Ind/Hercules]
  15334. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  15335. **/
  15336. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15337. unsigned char buf[10];
  15338. nullpo_retv(sd);
  15339. WBUFW(buf,0) = 0x7fc;
  15340. WBUFL(buf,2) = prev_leader_aid;
  15341. WBUFL(buf,6) = new_leader_aid;
  15342. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  15343. }
  15344. /**
  15345. * Decrypt packet identifier for player
  15346. * @param fd
  15347. * @param sd
  15348. * @param packet_ver
  15349. * Orig author [Ind/Hercules]
  15350. **/
  15351. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15352. #ifndef PACKET_OBFUSCATION
  15353. return RFIFOW(fd, 0);
  15354. #else
  15355. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15356. if (sd)
  15357. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15358. else
  15359. 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.
  15360. return cmd; // Return the decrypted packet ID.
  15361. #endif
  15362. }
  15363. #ifdef DUMP_UNKNOWN_PACKET
  15364. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15365. {
  15366. const char* packet_txt = "save/packet.txt";
  15367. FILE* fp;
  15368. time_t time_server;
  15369. struct tm *datetime;
  15370. char datestr[512];
  15371. time(&time_server); // get time in seconds since 1/1/1970
  15372. datetime = localtime(&time_server); // convert seconds in structure
  15373. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15374. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15375. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15376. if( sd ) {
  15377. 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);
  15378. } else {
  15379. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15380. }
  15381. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15382. fprintf(fp, "\n");
  15383. fclose(fp);
  15384. } else {
  15385. ShowError("Failed to write '%s'.\n", packet_txt);
  15386. // Dump on console instead
  15387. if( sd ) {
  15388. 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);
  15389. } else {
  15390. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15391. }
  15392. ShowDump(RFIFOP(fd,0), packet_len);
  15393. }
  15394. }
  15395. #endif
  15396. /// Roulette System
  15397. /// Author: Yommy
  15398. /**
  15399. * Opens Roulette window
  15400. * @param fd
  15401. * @param sd
  15402. */
  15403. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15404. {
  15405. nullpo_retv(sd);
  15406. if (!battle_config.feature_roulette) {
  15407. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15408. return;
  15409. }
  15410. WFIFOHEAD(fd,packet_len(0xa1a));
  15411. WFIFOW(fd,0) = 0xa1a;
  15412. WFIFOB(fd,2) = 0; // result
  15413. WFIFOL(fd,3) = 0; // serial
  15414. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15415. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15416. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15417. WFIFOL(fd,11) = sd->roulette_point.gold;
  15418. WFIFOL(fd,15) = sd->roulette_point.silver;
  15419. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15420. WFIFOSET(fd,packet_len(0xa1a));
  15421. }
  15422. /**
  15423. * Generates information to be displayed
  15424. * @param fd
  15425. * @param sd
  15426. */
  15427. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15428. {
  15429. unsigned short i, j, count = 0;
  15430. int len = 8 + (42 * 8);
  15431. nullpo_retv(sd);
  15432. if (!battle_config.feature_roulette) {
  15433. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15434. return;
  15435. }
  15436. WFIFOHEAD(fd,len);
  15437. WFIFOW(fd,0) = 0xa1c;
  15438. WFIFOW(fd,2) = len;
  15439. WFIFOL(fd,4) = 1; // serial
  15440. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15441. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15442. WFIFOW(fd,8 * count + 8) = i;
  15443. WFIFOW(fd,8 * count + 10) = j;
  15444. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15445. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15446. count++;
  15447. }
  15448. }
  15449. WFIFOSET(fd,len);
  15450. return;
  15451. }
  15452. /**
  15453. * Closes Roulette window
  15454. * @param fd
  15455. * @param sd
  15456. */
  15457. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15458. {
  15459. nullpo_retv(sd);
  15460. if (!battle_config.feature_roulette) {
  15461. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15462. return;
  15463. }
  15464. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15465. return;
  15466. }
  15467. /**
  15468. *
  15469. **/
  15470. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15471. #if PACKETVER >= 20141016
  15472. uint16 cmd = 0xa22;
  15473. unsigned char buf[5];
  15474. nullpo_retv(sd);
  15475. if (packet_db[sd->packet_ver][cmd].len == 0)
  15476. return;
  15477. WBUFW(buf,0) = cmd;
  15478. WBUFB(buf,2) = type;
  15479. WBUFW(buf,3) = 0; //! TODO: Additional item
  15480. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15481. #endif
  15482. }
  15483. /**
  15484. * Claim roulette reward
  15485. * @param sd Player
  15486. * @return 0:Success
  15487. **/
  15488. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15489. struct item it;
  15490. uint8 res = 1;
  15491. nullpo_retr(1, sd);
  15492. if (sd->roulette.prizeIdx < 0)
  15493. return RECV_ITEM_FAILED;
  15494. memset(&it, 0, sizeof(it));
  15495. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15496. it.identify = 1;
  15497. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15498. ; // onSuccess
  15499. }
  15500. sd->roulette.claimPrize = false;
  15501. sd->roulette.prizeStage = 0;
  15502. sd->roulette.prizeIdx = -1;
  15503. sd->roulette.stage = 0;
  15504. return res;
  15505. }
  15506. /**
  15507. * Process the stage and attempt to give a prize
  15508. * @param fd
  15509. * @param sd
  15510. */
  15511. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15512. {
  15513. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15514. short stage = sd->roulette.stage;
  15515. nullpo_retv(sd);
  15516. if (!battle_config.feature_roulette) {
  15517. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15518. return;
  15519. }
  15520. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15521. stage = sd->roulette.stage = 0;
  15522. if (!stage) {
  15523. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15524. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15525. }
  15526. if (result == GENERATE_ROULETTE_SUCCESS) {
  15527. if (!stage) {
  15528. if (sd->roulette_point.bronze > 0) {
  15529. sd->roulette_point.bronze -= 1;
  15530. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15531. } else if (sd->roulette_point.silver > 9) {
  15532. sd->roulette_point.silver -= 10;
  15533. stage = sd->roulette.stage = 2;
  15534. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15535. } else if (sd->roulette_point.gold > 9) {
  15536. sd->roulette_point.gold -= 10;
  15537. stage = sd->roulette.stage = 4;
  15538. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15539. }
  15540. }
  15541. sd->roulette.prizeStage = stage;
  15542. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15543. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15544. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15545. clif_roulette_getitem(sd);
  15546. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15547. return;
  15548. }
  15549. else {
  15550. sd->roulette.claimPrize = true;
  15551. sd->roulette.stage++;
  15552. }
  15553. }
  15554. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15555. }
  15556. /**
  15557. * Request to cash in prize
  15558. * @param fd
  15559. * @param sd
  15560. */
  15561. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15562. {
  15563. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15564. nullpo_retv(sd);
  15565. if (!battle_config.feature_roulette) {
  15566. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15567. return;
  15568. }
  15569. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15570. switch (clif_roulette_getitem(sd)) {
  15571. case 0:
  15572. type = RECV_ITEM_SUCCESS;
  15573. break;
  15574. case 1:
  15575. case 4:
  15576. case 5:
  15577. type = RECV_ITEM_OVERCOUNT;
  15578. break;
  15579. case 2:
  15580. type = RECV_ITEM_OVERWEIGHT;
  15581. break;
  15582. case 7:
  15583. default:
  15584. type = RECV_ITEM_FAILED;
  15585. break;
  15586. }
  15587. }
  15588. clif_roulette_recvitem_ack(sd,type);
  15589. return;
  15590. }
  15591. /**
  15592. * Update Roulette window with current stats
  15593. * @param sd
  15594. * @param result
  15595. * @param stage
  15596. * @param prizeIdx
  15597. * @param bonusItemID
  15598. */
  15599. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15600. {
  15601. int fd = sd->fd;
  15602. nullpo_retv(sd);
  15603. WFIFOHEAD(fd,packet_len(0xa20));
  15604. WFIFOW(fd,0) = 0xa20;
  15605. WFIFOB(fd,2) = result;
  15606. WFIFOW(fd,3) = stage;
  15607. WFIFOW(fd,5) = prizeIdx;
  15608. WFIFOW(fd,7) = bonusItemID;
  15609. WFIFOL(fd,9) = sd->roulette_point.gold;
  15610. WFIFOL(fd,13) = sd->roulette_point.silver;
  15611. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15612. WFIFOSET(fd,packet_len(0xa20));
  15613. }
  15614. /// MERGE ITEM
  15615. /**
  15616. * Acknowledge the client about item merger result
  15617. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15618. * @param fd
  15619. * @param sd
  15620. **/
  15621. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15622. unsigned char buf[9];
  15623. struct s_packet_db *info = NULL;
  15624. short cmd = 0;
  15625. nullpo_retv(sd);
  15626. if (!clif_session_isValid(sd))
  15627. return;
  15628. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15629. return;
  15630. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15631. return;
  15632. WBUFW(buf, 0) = cmd;
  15633. WBUFW(buf, info->pos[0]) = index;
  15634. WBUFW(buf, info->pos[1]) = count;
  15635. WBUFB(buf, info->pos[2]) = type;
  15636. clif_send(buf, info->len, &sd->bl, SELF);
  15637. }
  15638. /**
  15639. * Check if item has the pair to be merged
  15640. * @param sd
  15641. * @param it Item
  15642. * @return True if has pair, False if not
  15643. **/
  15644. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15645. struct item *it_;
  15646. unsigned short i;
  15647. nullpo_retr(false, sd);
  15648. 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);
  15649. if (i < MAX_INVENTORY)
  15650. return true;
  15651. return false;
  15652. }
  15653. /**
  15654. * Check if item can be merged
  15655. * @param id Item Data
  15656. * @param it Item
  15657. * @return True if can be merged, False if not
  15658. **/
  15659. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15660. if (!id || !it)
  15661. return false;
  15662. if (id->type == IT_CASH)
  15663. return false;
  15664. if (!itemdb_isstackable2(id))
  15665. return false;
  15666. if (itemdb_isspecial(it->card[0]))
  15667. return false;
  15668. if (!it->unique_id)
  15669. return false;
  15670. return true;
  15671. }
  15672. /**
  15673. * Open available item to be merged.
  15674. * Only show 1 item in 1 process.
  15675. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15676. * @param sd
  15677. **/
  15678. void clif_merge_item_open(struct map_session_data *sd) {
  15679. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15680. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15681. int len = 0;
  15682. struct s_packet_db *info = NULL;
  15683. struct item *it;
  15684. nullpo_retv(sd);
  15685. if (!clif_session_isValid(sd))
  15686. return;
  15687. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15688. return;
  15689. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15690. return;
  15691. // Get entries
  15692. for (i = 0; i < MAX_INVENTORY; i++) {
  15693. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15694. continue;
  15695. if (clif_merge_item_has_pair(sd, it))
  15696. indexes[n++] = i;
  15697. }
  15698. if (n < 2) { // No item need to be merged
  15699. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15700. return;
  15701. }
  15702. WBUFW(buf, 0) = cmd;
  15703. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15704. for (i = 0; i < n; i++) {
  15705. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15706. }
  15707. clif_send(buf, len, &sd->bl, SELF);
  15708. }
  15709. /**
  15710. * Process item merger
  15711. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15712. * @param fd
  15713. * @param sd
  15714. **/
  15715. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15716. struct s_packet_db *info = NULL;
  15717. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15718. unsigned int count = 0;
  15719. struct item_data *id = NULL;
  15720. nullpo_retv(sd);
  15721. if (!clif_session_isValid(sd))
  15722. return;
  15723. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15724. return;
  15725. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15726. if (n < 2) { // No item need to be merged
  15727. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15728. return;
  15729. }
  15730. for (i = 0, j = 0; i < n; i++) {
  15731. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15732. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15733. continue;
  15734. indexes[j] = idx;
  15735. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15736. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15737. return;
  15738. }
  15739. count += sd->status.inventory[idx].amount;
  15740. j++;
  15741. }
  15742. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15743. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15744. return;
  15745. }
  15746. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15747. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15748. return;
  15749. }
  15750. // Merrrrge!!!!
  15751. for (i = 1; i < n; i++) {
  15752. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15753. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15754. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15755. sd->inventory_data[idx] = NULL;
  15756. clif_delitem(sd, idx, amt, 0);
  15757. }
  15758. sd->status.inventory[indexes[0]].amount = count;
  15759. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15760. }
  15761. /**
  15762. * Cancel item merge
  15763. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15764. * @param fd
  15765. * @param sd
  15766. **/
  15767. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15768. return; // Nothing todo yet
  15769. }
  15770. /**
  15771. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15772. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15773. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15774. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15775. **/
  15776. 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) {
  15777. unsigned char buf[9 + NAME_LENGTH * 2];
  15778. unsigned short cmd = 0;
  15779. struct s_packet_db *info = NULL;
  15780. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15781. return;
  15782. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15783. return;
  15784. WBUFW(buf, 0) = 0x7fd;
  15785. WBUFB(buf, 4) = type;
  15786. WBUFW(buf, 5) = nameid;
  15787. WBUFB(buf, 7) = NAME_LENGTH;
  15788. safestrncpy((char *)WBUFP(buf, 8), char_name, NAME_LENGTH);
  15789. switch (type) {
  15790. case ITEMOBTAIN_TYPE_BOXITEM:
  15791. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15792. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15793. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15794. break;
  15795. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15796. {
  15797. struct mob_db *db = mob_db(container);
  15798. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15799. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15800. safestrncpy((char *)WBUFP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15801. }
  15802. break;
  15803. case ITEMOBTAIN_TYPE_NPC:
  15804. default:
  15805. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15806. break;
  15807. }
  15808. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15809. }
  15810. /// Show body view windows (ZC_DRESSROOM_OPEN).
  15811. /// 0A02 <view>.W
  15812. /// Value <flag> has the following effects:
  15813. /// 1: Open a Dress Room window.
  15814. void clif_dressing_room(struct map_session_data *sd, int flag) {
  15815. #if PACKETVER >= 20150513
  15816. int fd = sd->fd;
  15817. nullpo_retv(sd);
  15818. WFIFOHEAD(fd, packet_len(0xa02));
  15819. WFIFOW(fd,0) = 0xa02;
  15820. WFIFOW(fd,2) = flag;
  15821. WFIFOSET(fd, packet_len(0xa02));
  15822. #endif
  15823. }
  15824. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  15825. /// 0A35 <result>.W
  15826. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  15827. #if PACKETVER >= 20150513
  15828. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  15829. // Ignore the request
  15830. // - Invalid item index
  15831. // - Invalid item ID or item doesn't exist
  15832. // - Item is already identified
  15833. if (idx < 0 || idx >= MAX_INVENTORY ||
  15834. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  15835. sd->status.inventory[idx].identify)
  15836. return;
  15837. // Ignore the request - No magnifiers in inventory
  15838. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1)
  15839. return;
  15840. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  15841. return;
  15842. skill_identify(sd, idx);
  15843. #endif
  15844. }
  15845. /// Starts navigation to the given target on client side
  15846. void clif_navigateTo(struct map_session_data *sd, const char* map, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  15847. #if PACKETVER >= 20111010
  15848. int fd = sd->fd;
  15849. WFIFOHEAD(fd,27);
  15850. WFIFOW(fd,0) = 0x08e2;
  15851. // How detailed will our navigation be?
  15852. if( mob_id > 0 ){
  15853. x = 0;
  15854. y = 0;
  15855. WFIFOB(fd,2) = 3; // monster with destination field
  15856. }else if( x > 0 && y > 0 ){
  15857. WFIFOB(fd,2) = 0; // with coordinates
  15858. }else{
  15859. x = 0;
  15860. y = 0;
  15861. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  15862. }
  15863. // Which services can be used for transportation?
  15864. WFIFOB(fd,3) = flag;
  15865. // If this flag is set, the navigation window will not be opened up
  15866. WFIFOB(fd,4) = hideWindow;
  15867. // Target map
  15868. safestrncpy( (char*)WFIFOP(fd,5),map,MAP_NAME_LENGTH_EXT);
  15869. // Target x
  15870. WFIFOW(fd,21) = x;
  15871. // Target y
  15872. WFIFOW(fd,23) = y;
  15873. // Target monster ID
  15874. WFIFOW(fd,25) = mob_id;
  15875. WFIFOSET(fd,27);
  15876. #endif
  15877. }
  15878. /*==========================================
  15879. * Main client packet processing function
  15880. *------------------------------------------*/
  15881. static int clif_parse(int fd)
  15882. {
  15883. int cmd, packet_ver, packet_len, err;
  15884. TBL_PC* sd;
  15885. int pnum;
  15886. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15887. // Note: "click masters" can do 80+ clicks in 10 seconds
  15888. 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]
  15889. { // begin main client packet processing loop
  15890. sd = (TBL_PC *)session[fd]->session_data;
  15891. if (session[fd]->flag.eof) {
  15892. if (sd) {
  15893. if (sd->state.autotrade) {
  15894. //Disassociate character from the socket connection.
  15895. session[fd]->session_data = NULL;
  15896. sd->fd = 0;
  15897. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15898. } else
  15899. if (sd->state.active) {
  15900. // Player logout display [Valaris]
  15901. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15902. clif_quitsave(fd, sd);
  15903. } else {
  15904. //Unusual logout (during log on/off/map-changer procedure)
  15905. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15906. map_quit(sd);
  15907. }
  15908. } else {
  15909. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15910. }
  15911. do_close(fd);
  15912. return 0;
  15913. }
  15914. if (RFIFOREST(fd) < 2)
  15915. return 0;
  15916. cmd = clif_parse_cmd(fd, sd);
  15917. // identify client's packet version
  15918. if (sd) {
  15919. packet_ver = sd->packet_ver;
  15920. } else {
  15921. // check authentification packet to know packet version
  15922. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15923. if( err ) {// failed to identify packet version
  15924. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15925. err == 1 ? "" :
  15926. err == 2 ? ", possibly for having an invalid account_id" :
  15927. err == 3 ? ", possibly for having an invalid char_id." :
  15928. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15929. err == 4 ? ", possibly for having an invalid login_id1." :
  15930. err == 5 ? ", possibly for having an invalid client_tick." :
  15931. */
  15932. err == 6 ? ", possibly for having an invalid sex." :
  15933. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15934. WFIFOHEAD(fd,packet_len(0x6a));
  15935. WFIFOW(fd,0) = 0x6a;
  15936. WFIFOB(fd,2) = 3; // Rejected from Server
  15937. WFIFOSET(fd,packet_len(0x6a));
  15938. #ifdef DUMP_INVALID_PACKET
  15939. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15940. #endif
  15941. RFIFOSKIP(fd, RFIFOREST(fd));
  15942. set_eof(fd);
  15943. return 0;
  15944. }
  15945. }
  15946. // filter out invalid / unsupported packets
  15947. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15948. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15949. #ifdef DUMP_INVALID_PACKET
  15950. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15951. #endif
  15952. set_eof(fd);
  15953. return 0;
  15954. }
  15955. // determine real packet length
  15956. packet_len = packet_db[packet_ver][cmd].len;
  15957. if (packet_len == -1) { // variable-length packet
  15958. if (RFIFOREST(fd) < 4)
  15959. return 0;
  15960. packet_len = RFIFOW(fd,2);
  15961. if (packet_len < 4 || packet_len > 32768) {
  15962. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15963. #ifdef DUMP_INVALID_PACKET
  15964. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15965. #endif
  15966. set_eof(fd);
  15967. return 0;
  15968. }
  15969. }
  15970. if ((int)RFIFOREST(fd) < packet_len)
  15971. return 0; // not enough data received to form the packet
  15972. #ifdef PACKET_OBFUSCATION
  15973. RFIFOW(fd, 0) = cmd;
  15974. if (sd)
  15975. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15976. #endif
  15977. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15978. packet_db[packet_ver][cmd].func(fd, sd);
  15979. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15980. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15981. ; //Only valid packet when there is no session
  15982. else
  15983. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15984. ; //Only valid packet when player is not on a map
  15985. else
  15986. packet_db[packet_ver][cmd].func(fd, sd);
  15987. }
  15988. #ifdef DUMP_UNKNOWN_PACKET
  15989. else DumpUnknown(fd,sd,cmd,packet_len);
  15990. #endif
  15991. RFIFOSKIP(fd, packet_len);
  15992. }; // main loop end
  15993. return 0;
  15994. }
  15995. /*==========================================
  15996. * Reads packet_db.txt and setups its array reference
  15997. *------------------------------------------*/
  15998. void packetdb_readdb(bool reload)
  15999. {
  16000. char line[1024];
  16001. int cmd,i,j;
  16002. int max_cmd=-1;
  16003. bool skip_ver = false;
  16004. int warned = 0;
  16005. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  16006. #ifdef PACKET_OBFUSCATION
  16007. bool key_defined = false;
  16008. int last_key_defined = -1;
  16009. #endif
  16010. int packet_len_table[MAX_PACKET_DB] = {
  16011. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16015. //#0x0040
  16016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16018. #if PACKETVER <= 20081217
  16019. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  16020. #else
  16021. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  16022. #endif
  16023. #if PACKETVER < 2
  16024. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  16025. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  16026. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  16027. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  16028. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  16029. #else
  16030. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  16031. #endif
  16032. //#0x0080
  16033. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  16034. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  16035. #if PACKETVER <= 20100622
  16036. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  16037. #else
  16038. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  16039. #endif
  16040. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  16041. //#0x00C0
  16042. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  16043. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  16044. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  16045. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  16046. //#0x0100
  16047. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  16048. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  16049. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  16050. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  16051. //#0x0140
  16052. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  16053. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  16054. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  16055. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  16056. //#0x0180
  16057. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  16058. #if PACKETVER < 1
  16059. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16060. #else // 196 comodo icon status display for later
  16061. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16062. #endif
  16063. #if PACKETVER < 20081126
  16064. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16065. #else // 0x1a2 changed (35->37)
  16066. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16067. #endif
  16068. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  16069. //#0x01C0, Set 0x1d5=-1
  16070. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  16071. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  16072. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  16073. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  16074. //#0x0200
  16075. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  16076. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  16077. #if PACKETVER < 20071106
  16078. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  16079. #else // 0x22c changed
  16080. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  16081. #endif
  16082. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  16083. //#0x0240
  16084. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  16085. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  16086. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16087. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16088. //#0x0280
  16089. #if PACKETVER < 20070711
  16090. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  16091. #else
  16092. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  16093. #endif
  16094. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  16095. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16096. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  16097. //#0x02C0
  16098. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  16099. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  16100. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  16101. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16102. //#0x0300
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16107. //#0x0340
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16112. //#0x0380
  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, 0,
  16116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16117. //#0x03C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16122. //#0x0400
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  16127. //#0x0440
  16128. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16132. //#0x0480
  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, 0,
  16136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16137. //#0x04C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16142. //#0x0500
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16147. //#0x0540
  16148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16152. //#0x0580
  16153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16157. //#0x05C0
  16158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16162. //#0x0600
  16163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16167. //#0x0640
  16168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16172. //#0x0680
  16173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x06C0
  16178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16180. 0, 0, 0, 0, 0, 0, 0, 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. //#0x0700
  16183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16185. 0, 0, 0, 0, 0, 0, 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, 25,
  16187. //#0x0740
  16188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 0, 0, 0,
  16192. //#0x0780
  16193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16197. //#0x07C0
  16198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16199. #if PACKETVER < 20090617
  16200. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  16201. #else // 0x7d9 changed
  16202. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  16203. #endif
  16204. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  16205. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  16206. //#0x0800
  16207. #if PACKETVER < 20091229
  16208. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  16209. #else // for Party booking ( PACKETVER >= 20091229 )
  16210. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  16211. #endif
  16212. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  16213. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16214. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  16215. //#0x0840
  16216. #if PACKETVER < 20130000
  16217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16218. #else
  16219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  16220. #endif
  16221. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  16222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16224. //#0x0880
  16225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16228. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16229. //#0x08C0
  16230. 0, 0, 0, 0, 0, 0, 0, 20, 34, 0, 0, 0, 0, 0, 0, 10,
  16231. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16234. //#0x0900
  16235. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1,
  16236. 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16239. //#0x0940
  16240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  16243. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, -1, 0, 0, 0, 0, -1,
  16244. //#0x0980
  16245. 7, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16246. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  16247. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  16248. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  16249. //#0x09C0
  16250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 17, 0, 0,102, 0,
  16251. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, -1, -1, -1, 0, 7,
  16252. 0, 0, 0, 0, 0, 18, 22, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  16253. 0, 11, 12, 11, 0, 0, 0, 75, -1,143, 0, 0, 0, -1, -1, -1,
  16254. //#0x0A00
  16255. #if PACKETVER >= 20141022
  16256. 269, 3, 4, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 14, -1,
  16257. #else
  16258. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 14, 0,
  16259. #endif
  16260. -1, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  16261. 21, 3, 5, 0, 66, 0, 0, 8, 3, 0, 0, 0, 0, -1, 0, 0,
  16262. 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16263. };
  16264. struct {
  16265. void (*func)(int, struct map_session_data *);
  16266. char *name;
  16267. } clif_parse_func[]={
  16268. {clif_parse_WantToConnection,"wanttoconnection"},
  16269. {clif_parse_LoadEndAck,"loadendack"},
  16270. {clif_parse_TickSend,"ticksend"},
  16271. {clif_parse_WalkToXY,"walktoxy"},
  16272. {clif_parse_QuitGame,"quitgame"},
  16273. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  16274. {clif_parse_GlobalMessage,"globalmessage"},
  16275. {clif_parse_MapMove,"mapmove"},
  16276. {clif_parse_ChangeDir,"changedir"},
  16277. {clif_parse_Emotion,"emotion"},
  16278. {clif_parse_HowManyConnections,"howmanyconnections"},
  16279. {clif_parse_ActionRequest,"actionrequest"},
  16280. {clif_parse_Restart,"restart"},
  16281. {clif_parse_WisMessage,"wis"},
  16282. {clif_parse_Broadcast,"broadcast"},
  16283. {clif_parse_TakeItem,"takeitem"},
  16284. {clif_parse_DropItem,"dropitem"},
  16285. {clif_parse_UseItem,"useitem"},
  16286. {clif_parse_EquipItem,"equipitem"},
  16287. {clif_parse_UnequipItem,"unequipitem"},
  16288. {clif_parse_NpcClicked,"npcclicked"},
  16289. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  16290. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  16291. {clif_parse_NpcSellListSend,"npcselllistsend"},
  16292. {clif_parse_CreateChatRoom,"createchatroom"},
  16293. {clif_parse_ChatAddMember,"chataddmember"},
  16294. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  16295. {clif_parse_ChangeChatOwner,"changechatowner"},
  16296. {clif_parse_KickFromChat,"kickfromchat"},
  16297. {clif_parse_ChatLeave,"chatleave"},
  16298. {clif_parse_TradeRequest,"traderequest"},
  16299. {clif_parse_TradeAck,"tradeack"},
  16300. {clif_parse_TradeAddItem,"tradeadditem"},
  16301. {clif_parse_TradeOk,"tradeok"},
  16302. {clif_parse_TradeCancel,"tradecancel"},
  16303. {clif_parse_TradeCommit,"tradecommit"},
  16304. {clif_parse_StopAttack,"stopattack"},
  16305. {clif_parse_PutItemToCart,"putitemtocart"},
  16306. {clif_parse_GetItemFromCart,"getitemfromcart"},
  16307. {clif_parse_RemoveOption,"removeoption"},
  16308. {clif_parse_ChangeCart,"changecart"},
  16309. {clif_parse_StatusUp,"statusup"},
  16310. {clif_parse_SkillUp,"skillup"},
  16311. {clif_parse_UseSkillToId,"useskilltoid"},
  16312. {clif_parse_UseSkillToPos,"useskilltopos"},
  16313. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  16314. {clif_parse_UseSkillMap,"useskillmap"},
  16315. {clif_parse_RequestMemo,"requestmemo"},
  16316. {clif_parse_ProduceMix,"producemix"},
  16317. {clif_parse_Cooking,"cooking"},
  16318. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  16319. {clif_parse_NpcNextClicked,"npcnextclicked"},
  16320. {clif_parse_NpcAmountInput,"npcamountinput"},
  16321. {clif_parse_NpcStringInput,"npcstringinput"},
  16322. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  16323. {clif_parse_ItemIdentify,"itemidentify"},
  16324. {clif_parse_SelectArrow,"selectarrow"},
  16325. {clif_parse_AutoSpell,"autospell"},
  16326. {clif_parse_UseCard,"usecard"},
  16327. {clif_parse_InsertCard,"insertcard"},
  16328. {clif_parse_RepairItem,"repairitem"},
  16329. {clif_parse_WeaponRefine,"weaponrefine"},
  16330. {clif_parse_SolveCharName,"solvecharname"},
  16331. {clif_parse_ResetChar,"resetchar"},
  16332. {clif_parse_LocalBroadcast,"localbroadcast"},
  16333. {clif_parse_MoveToKafra,"movetokafra"},
  16334. {clif_parse_MoveFromKafra,"movefromkafra"},
  16335. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  16336. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  16337. {clif_parse_CloseKafra,"closekafra"},
  16338. {clif_parse_CreateParty,"createparty"},
  16339. {clif_parse_CreateParty2,"createparty2"},
  16340. {clif_parse_PartyInvite,"partyinvite"},
  16341. {clif_parse_PartyInvite2,"partyinvite2"},
  16342. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  16343. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  16344. {clif_parse_LeaveParty,"leaveparty"},
  16345. {clif_parse_RemovePartyMember,"removepartymember"},
  16346. {clif_parse_PartyChangeOption,"partychangeoption"},
  16347. {clif_parse_PartyMessage,"partymessage"},
  16348. {clif_parse_PartyChangeLeader,"partychangeleader"},
  16349. {clif_parse_CloseVending,"closevending"},
  16350. {clif_parse_VendingListReq,"vendinglistreq"},
  16351. {clif_parse_PurchaseReq,"purchasereq"},
  16352. {clif_parse_PurchaseReq2,"purchasereq2"},
  16353. {clif_parse_OpenVending,"openvending"},
  16354. {clif_parse_CreateGuild,"createguild"},
  16355. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  16356. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  16357. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  16358. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  16359. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  16360. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  16361. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  16362. {clif_parse_GuildInvite,"guildinvite"},
  16363. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  16364. {clif_parse_GuildLeave,"guildleave"},
  16365. {clif_parse_GuildExpulsion,"guildexpulsion"},
  16366. {clif_parse_GuildMessage,"guildmessage"},
  16367. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  16368. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  16369. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  16370. {clif_parse_GuildOpposition,"guildopposition"},
  16371. {clif_parse_GuildBreak,"guildbreak"},
  16372. {clif_parse_PetMenu,"petmenu"},
  16373. {clif_parse_CatchPet,"catchpet"},
  16374. {clif_parse_SelectEgg,"selectegg"},
  16375. {clif_parse_SendEmotion,"sendemotion"},
  16376. {clif_parse_ChangePetName,"changepetname"},
  16377. {clif_parse_GMKick,"gmkick"},
  16378. {clif_parse_GMHide,"gmhide"},
  16379. {clif_parse_GMReqNoChat,"gmreqnochat"},
  16380. {clif_parse_GMReqAccountName,"gmreqaccname"},
  16381. {clif_parse_GMKickAll,"killall"},
  16382. {clif_parse_GMRecall,"recall"},
  16383. {clif_parse_GMRecall,"summon"},
  16384. {clif_parse_GM_Item_Monster,"itemmonster"},
  16385. {clif_parse_GMShift,"remove"},
  16386. {clif_parse_GMShift,"shift"},
  16387. {clif_parse_GMChangeMapType,"changemaptype"},
  16388. {clif_parse_GMRc,"rc"},
  16389. {clif_parse_GMRecall2,"recall2"},
  16390. {clif_parse_GMRemove2,"remove2"},
  16391. {clif_parse_GMFullStrip,"gmfullstrip"},
  16392. {clif_parse_NoviceDoriDori,"sndoridori"},
  16393. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  16394. {clif_parse_PMIgnore,"wisexin"},
  16395. {clif_parse_PMIgnoreList,"wisexlist"},
  16396. {clif_parse_PMIgnoreAll,"wisall"},
  16397. {clif_parse_FriendsListAdd,"friendslistadd"},
  16398. {clif_parse_FriendsListRemove,"friendslistremove"},
  16399. {clif_parse_FriendsListReply,"friendslistreply"},
  16400. {clif_parse_Blacksmith,"blacksmith"},
  16401. {clif_parse_Alchemist,"alchemist"},
  16402. {clif_parse_Taekwon,"taekwon"},
  16403. {clif_parse_RankingPk,"rankingpk"},
  16404. {clif_parse_FeelSaveOk,"feelsaveok"},
  16405. {clif_parse_debug,"debug"},
  16406. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16407. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16408. {clif_parse_HomMoveTo,"hommoveto"},
  16409. {clif_parse_HomAttack,"homattack"},
  16410. {clif_parse_HomMenu,"hommenu"},
  16411. {clif_parse_StoragePassword,"storagepassword"},
  16412. {clif_parse_Hotkey,"hotkey"},
  16413. {clif_parse_AutoRevive,"autorevive"},
  16414. {clif_parse_Check,"check"},
  16415. {clif_parse_Adopt_request,"adoptrequest"},
  16416. {clif_parse_Adopt_reply,"adoptreply"},
  16417. // MAIL SYSTEM
  16418. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16419. {clif_parse_Mail_read,"mailread"},
  16420. {clif_parse_Mail_getattach,"mailgetattach"},
  16421. {clif_parse_Mail_delete,"maildelete"},
  16422. {clif_parse_Mail_return,"mailreturn"},
  16423. {clif_parse_Mail_setattach,"mailsetattach"},
  16424. {clif_parse_Mail_winopen,"mailwinopen"},
  16425. {clif_parse_Mail_send,"mailsend"},
  16426. // AUCTION SYSTEM
  16427. {clif_parse_Auction_search,"auctionsearch"},
  16428. {clif_parse_Auction_buysell,"auctionbuysell"},
  16429. {clif_parse_Auction_setitem,"auctionsetitem"},
  16430. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16431. {clif_parse_Auction_register,"auctionregister"},
  16432. {clif_parse_Auction_cancel,"auctioncancel"},
  16433. {clif_parse_Auction_close,"auctionclose"},
  16434. {clif_parse_Auction_bid,"auctionbid"},
  16435. // Quest Log System
  16436. {clif_parse_questStateAck,"queststate"},
  16437. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16438. {clif_parse_EquipTick,"equiptickbox"},
  16439. {clif_parse_BattleChat,"battlechat"},
  16440. {clif_parse_mercenary_action,"mermenu"},
  16441. {clif_parse_progressbar,"progressbar"},
  16442. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16443. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16444. #if PACKETVER >= 20091229
  16445. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16446. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16447. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16448. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16449. #endif
  16450. {clif_parse_BankCheck,"bankcheck"},
  16451. {clif_parse_BankDeposit,"bankdeposit"},
  16452. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16453. {clif_parse_BankOpen,"bankopen"},
  16454. {clif_parse_BankClose,"bankclose"},
  16455. {clif_parse_PVPInfo,"pvpinfo"},
  16456. {clif_parse_LessEffect,"lesseffect"},
  16457. // Buying Store
  16458. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16459. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16460. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16461. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16462. // Store Search
  16463. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16464. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16465. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16466. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16467. // Cashshop
  16468. { clif_parse_cashshop_open_request, "cashshopopen" },
  16469. { clif_parse_cashshop_close, "cashshopclose" },
  16470. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16471. { clif_parse_cashshop_buy, "cashshopbuy" },
  16472. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16473. /* */
  16474. { clif_parse_MoveItem , "moveitem" },
  16475. { clif_parse_PartyTick, "partytick" },
  16476. { clif_parse_dull, "dull" },
  16477. { clif_parse_GuildInvite2 , "guildinvite2" },
  16478. { clif_parse_reqworldinfo, "reqworldinfo"},
  16479. { clif_parse_client_version, "clientversion"},
  16480. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16481. { clif_parse_ranklist, "ranklist"},
  16482. // Market NPC
  16483. { clif_parse_NPCShopClosed, "npcshopclosed" },
  16484. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16485. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16486. // Roulette
  16487. { clif_parse_RouletteOpen, "rouletteopen" },
  16488. { clif_parse_RouletteInfo, "rouletteinfo" },
  16489. { clif_parse_RouletteClose, "rouletteclose" },
  16490. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16491. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16492. // Merge Item
  16493. { clif_parse_merge_item_req, "mergeitem_req"},
  16494. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16495. // HotkeyRowShift
  16496. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16497. // OneClick Item Identify
  16498. { clif_parse_Oneclick_Itemidentify, "oneclick_itemidentify" },
  16499. // NewChange Cart2
  16500. { clif_parse_SelectCart, "selectcart" },
  16501. {NULL,NULL}
  16502. };
  16503. struct {
  16504. char *name; //function name
  16505. int funcidx; //
  16506. } clif_ack_func[]={ //hash
  16507. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16508. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16509. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16510. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16511. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16512. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16513. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16514. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16515. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16516. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16517. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16518. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16519. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16520. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16521. };
  16522. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16523. int f;
  16524. memset(packet_db,0,sizeof(packet_db));
  16525. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16526. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16527. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16528. packet_len(i) = packet_len_table[i];
  16529. clif_config.packet_db_ver = MAX_PACKET_VER;
  16530. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16531. FILE *fp;
  16532. int ln = 0;
  16533. int entries = 0;
  16534. char *str[64], *p, *str2[64], *p2;
  16535. sprintf(line, "%s/%s", db_path, filename[f]);
  16536. if( (fp = fopen(line,"r")) == NULL ) {
  16537. if (f == 0) {
  16538. ShowFatalError("Can't read %s\n", line);
  16539. exit(EXIT_FAILURE);
  16540. }
  16541. return;
  16542. }
  16543. while( fgets(line, sizeof(line), fp) ) {
  16544. char w1[256],w2[256];
  16545. ln++;
  16546. if(line[0]=='/' && line[1]=='/')
  16547. continue;
  16548. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16549. if (strcmpi(w1,"packet_ver") == 0) {
  16550. int prev_ver = packet_ver;
  16551. skip_ver = false;
  16552. packet_ver = atoi(w2);
  16553. if ( packet_ver > MAX_PACKET_VER )
  16554. { //Check to avoid overflowing. [Skotlex]
  16555. if( (warned&1) == 0 )
  16556. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16557. warned &= 1;
  16558. skip_ver = true;
  16559. }
  16560. else if( packet_ver < 0 )
  16561. {
  16562. if( (warned&2) == 0 )
  16563. ShowWarning("Negative packet versions are not supported.\n");
  16564. warned &= 2;
  16565. skip_ver = true;
  16566. }
  16567. else if( packet_ver == SERVER )
  16568. {
  16569. if( (warned&4) == 0 )
  16570. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16571. warned &= 4;
  16572. skip_ver = true;
  16573. }
  16574. if( skip_ver )
  16575. {
  16576. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16577. packet_ver = prev_ver;
  16578. continue;
  16579. }
  16580. // copy from previous version into new version and continue
  16581. // - indicating all following packets should be read into the newer version
  16582. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16583. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16584. continue;
  16585. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16586. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16587. clif_config.packet_db_ver = MAX_PACKET_VER;
  16588. else // to manually set the packet DB version
  16589. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16590. continue;
  16591. }
  16592. #ifdef PACKET_OBFUSCATION
  16593. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16594. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16595. trim(w2);
  16596. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16597. if (!packet_keys[packet_ver])
  16598. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16599. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16600. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16601. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16602. last_key_defined = packet_ver;
  16603. if (battle_config.etc_log)
  16604. 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]);
  16605. }
  16606. continue;
  16607. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16608. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16609. trim(w2);
  16610. if (strcmpi(w2,"default") == 0)
  16611. continue;
  16612. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16613. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16614. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16615. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16616. key_defined = true;
  16617. if (battle_config.etc_log)
  16618. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16619. }
  16620. continue;
  16621. }
  16622. #endif
  16623. }
  16624. if( skip_ver )
  16625. continue; // Skipping current packet version
  16626. memset(str,0,sizeof(str));
  16627. for (j = 0, p = line; j < 4 && p; ++j) {
  16628. str[j] = p;
  16629. p = strchr(p,',');
  16630. if (p)
  16631. *p++=0;
  16632. }
  16633. if (str[0] == NULL)
  16634. continue;
  16635. cmd = strtol(str[0],(char **)NULL,0);
  16636. if(max_cmd < cmd)
  16637. max_cmd = cmd;
  16638. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16639. continue;
  16640. if(str[1]==NULL){
  16641. ShowError("packet_db: packet len error\n");
  16642. continue;
  16643. }
  16644. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16645. if(str[2]==NULL){
  16646. packet_db[packet_ver][cmd].func = NULL;
  16647. ln++;
  16648. continue;
  16649. }
  16650. // look up processing function by name
  16651. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16652. if( j < ARRAYLENGTH(clif_parse_func) )
  16653. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16654. else { //search if it's a mapped ack func
  16655. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16656. if( j < ARRAYLENGTH(clif_ack_func)) {
  16657. int fidx = clif_ack_func[j].funcidx;
  16658. packet_db_ack[packet_ver][fidx] = cmd;
  16659. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16660. }
  16661. }
  16662. // set the identifying cmd for the packet_db version
  16663. if (strcmp(str[2],"wanttoconnection")==0)
  16664. clif_config.connect_cmd[packet_ver] = cmd;
  16665. if(str[3]==NULL){
  16666. ShowError("packet_db: packet error\n");
  16667. exit(EXIT_FAILURE);
  16668. }
  16669. for(j = 0, p2 = str[3]; p2; j++){
  16670. short k;
  16671. str2[j] = p2;
  16672. p2 = strchr(p2,':');
  16673. if(p2)
  16674. *p2++=0;
  16675. k = atoi(str2[j]);
  16676. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16677. if( j >= MAX_PACKET_POS )
  16678. {
  16679. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16680. break;
  16681. }
  16682. packet_db[packet_ver][cmd].pos[j] = k;
  16683. }
  16684. entries++;
  16685. }
  16686. fclose(fp);
  16687. if(max_cmd > MAX_PACKET_DB) {
  16688. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16689. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16690. }
  16691. //Locate the nearest version that we still support. [Skotlex]
  16692. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16693. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16694. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16695. }
  16696. sprintf(line, "%s/%s", db_path,filename[f]);
  16697. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16698. }
  16699. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16700. #ifdef PACKET_OBFUSCATION
  16701. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16702. int use_key = last_key_defined;
  16703. if (last_key_defined == -1)
  16704. ShowError("Can't find packet obfuscation keys!\n");
  16705. else {
  16706. if (packet_keys[clif_config.packet_db_ver])
  16707. use_key = clif_config.packet_db_ver;
  16708. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16709. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16710. }
  16711. }
  16712. 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]);
  16713. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16714. if (packet_keys[i]) {
  16715. aFree(packet_keys[i]);
  16716. packet_keys[i] = NULL;
  16717. }
  16718. }
  16719. #endif
  16720. }
  16721. /*==========================================
  16722. *
  16723. *------------------------------------------*/
  16724. void do_init_clif(void) {
  16725. const char* colors[COLOR_MAX] = {
  16726. "0x00FF00",
  16727. "0xFF0000",
  16728. "0xFFFFFF",
  16729. "0xFFFF00",
  16730. };
  16731. int i;
  16732. /**
  16733. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16734. **/
  16735. for(i = 0; i < COLOR_MAX; i++) {
  16736. color_table[i] = strtoul(colors[i],NULL,0);
  16737. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16738. }
  16739. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16740. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16741. #ifdef PACKET_OBFUSCATION
  16742. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16743. #endif
  16744. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16745. packetdb_readdb(false);
  16746. set_defaultparse(clif_parse);
  16747. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16748. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16749. exit(EXIT_FAILURE);
  16750. }
  16751. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16752. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16753. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16754. }
  16755. void do_final_clif(void) {
  16756. ers_destroy(delay_clearunit_ers);
  16757. }