clif.c 569 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751
  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. safestrncpy((char*)WBUFP(buf,64), name, NAME_LENGTH);
  996. #else
  997. safestrncpy((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. safestrncpy((char*)WBUFP(buf,71), name, NAME_LENGTH);
  1133. #else
  1134. safestrncpy((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. int len;
  1254. vd = status_get_viewdata(bl);
  1255. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1256. return 0;
  1257. /**
  1258. * Hide NPC from maya purple card.
  1259. **/
  1260. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1261. return 0;
  1262. len = clif_set_unit_idle(bl, buf,true);
  1263. clif_send(buf, len, bl, AREA_WOS);
  1264. if (disguised(bl))
  1265. clif_setdisguise(bl, buf, len);
  1266. if (vd->cloth_color)
  1267. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1268. if (vd->body_style)
  1269. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1270. switch (bl->type)
  1271. {
  1272. case BL_PC:
  1273. {
  1274. TBL_PC *sd = ((TBL_PC*)bl);
  1275. if (sd->spiritball > 0)
  1276. clif_spiritball(&sd->bl);
  1277. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1278. clif_specialeffect(bl,423,AREA);
  1279. else if(sd->state.size==SZ_MEDIUM)
  1280. clif_specialeffect(bl,421,AREA);
  1281. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1282. clif_sendbgemblem_area(sd);
  1283. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1284. clif_spiritcharm(sd);
  1285. if (sd->status.robe)
  1286. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1287. clif_efst_status_change_sub(sd, bl, AREA);
  1288. clif_hat_effects(sd,bl,AREA);
  1289. }
  1290. break;
  1291. case BL_MOB:
  1292. {
  1293. TBL_MOB *md = ((TBL_MOB*)bl);
  1294. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1295. clif_specialeffect(&md->bl,423,AREA);
  1296. else if(md->special_state.size==SZ_MEDIUM)
  1297. clif_specialeffect(&md->bl,421,AREA);
  1298. }
  1299. break;
  1300. case BL_NPC:
  1301. {
  1302. TBL_NPC *nd = ((TBL_NPC*)bl);
  1303. if( nd->size == SZ_BIG )
  1304. clif_specialeffect(&nd->bl,423,AREA);
  1305. else if( nd->size == SZ_MEDIUM )
  1306. clif_specialeffect(&nd->bl,421,AREA);
  1307. }
  1308. break;
  1309. case BL_PET:
  1310. if (vd->head_bottom)
  1311. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1312. break;
  1313. }
  1314. return 0;
  1315. }
  1316. /// Sends information about owned homunculus to the client . [orn]
  1317. /// 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)
  1318. /// 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)
  1319. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1320. {
  1321. struct status_data *status;
  1322. unsigned char buf[128];
  1323. #if PACKETVER < 20141016
  1324. const int cmd = 0x22e;
  1325. int offset = 0;
  1326. #else
  1327. const int cmd = 0x9f7;
  1328. int offset = 2;
  1329. #endif
  1330. int htype;
  1331. nullpo_retv(hd);
  1332. if (!clif_session_isValid(sd))
  1333. return;
  1334. status = &hd->battle_status;
  1335. htype = hom_class2type(hd->homunculus.class_);
  1336. memset(buf,0,packet_len(cmd));
  1337. WBUFW(buf,0) = cmd;
  1338. safestrncpy((char*)WBUFP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1339. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1340. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1341. WBUFW(buf,27) = hd->homunculus.level;
  1342. WBUFW(buf,29) = hd->homunculus.hunger;
  1343. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1344. WBUFW(buf,33) = 0; // equip id
  1345. #ifdef RENEWAL
  1346. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1347. #else
  1348. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1349. #endif
  1350. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1351. WBUFW(buf,39)=status->hit;
  1352. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1353. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1354. else
  1355. WBUFW(buf,41) = status->cri/10;
  1356. #ifdef RENEWAL
  1357. WBUFW(buf,43) = status->def + status->def2;
  1358. WBUFW(buf,45) = status->mdef + status->mdef2;
  1359. #else
  1360. WBUFW(buf,43) = status->def + status->vit;
  1361. WBUFW(buf,45) = status->mdef;
  1362. #endif
  1363. WBUFW(buf,47) = status->flee;
  1364. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1365. if (status->max_hp > INT16_MAX) {
  1366. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1367. WBUFW(buf,53+offset) = 100;
  1368. } else {
  1369. WBUFW(buf,51) = status->hp;
  1370. WBUFW(buf,53+offset) = status->max_hp;
  1371. }
  1372. #if PACKETVER >= 20141016
  1373. offset += 2;
  1374. #endif
  1375. if (status->max_sp > INT16_MAX) {
  1376. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1377. WBUFW(buf,57+offset) = 100;
  1378. } else {
  1379. WBUFW(buf,55+offset) = status->sp;
  1380. WBUFW(buf,57+offset) = status->max_sp;
  1381. }
  1382. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1383. WBUFL(buf,63+offset) = hd->exp_next;
  1384. switch( htype ) {
  1385. case HT_REG:
  1386. case HT_EVO:
  1387. if( hd->homunculus.level >= battle_config.hom_max_level )
  1388. WBUFL(buf,63+offset) = 0;
  1389. break;
  1390. case HT_S:
  1391. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1392. WBUFL(buf,63+offset) = 0;
  1393. break;
  1394. }
  1395. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1396. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1397. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1398. }
  1399. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1400. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1401. /// type:
  1402. /// unused
  1403. /// state:
  1404. /// 0 = pre-init
  1405. /// 1 = intimacy
  1406. /// 2 = hunger
  1407. /// 3 = accessory?
  1408. /// ? = ignored
  1409. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1410. { //[orn]
  1411. int fd = sd->fd;
  1412. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1413. hom_calc_skilltree(sd->hd, 0);
  1414. WFIFOHEAD(fd, packet_len(0x230));
  1415. WFIFOW(fd,0)=0x230;
  1416. WFIFOB(fd,2)=0;
  1417. WFIFOB(fd,3)=state;
  1418. WFIFOL(fd,4)=sd->hd->bl.id;
  1419. WFIFOL(fd,8)=param;
  1420. WFIFOSET(fd,packet_len(0x230));
  1421. }
  1422. int clif_homskillinfoblock(struct map_session_data *sd)
  1423. { //[orn]
  1424. struct homun_data *hd;
  1425. int fd = sd->fd;
  1426. int i, len=4;
  1427. nullpo_ret(sd);
  1428. hd = sd->hd;
  1429. if ( !hd )
  1430. return 0 ;
  1431. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1432. WFIFOW(fd,0)=0x235;
  1433. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1434. int id = hd->homunculus.hskill[i].id;
  1435. if( id != 0 ){
  1436. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1437. short idx = hom_skill_get_index(id);
  1438. if (idx == -1)
  1439. continue;
  1440. WFIFOW(fd,len ) = id;
  1441. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1442. WFIFOW(fd,len+4) = 0;
  1443. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1444. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1445. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1446. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1447. 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;
  1448. len+=37;
  1449. }
  1450. }
  1451. WFIFOW(fd,2)=len;
  1452. WFIFOSET(fd,len);
  1453. return 0;
  1454. }
  1455. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1456. { //[orn]
  1457. struct homun_data *hd;
  1458. int fd;
  1459. short idx = -1;
  1460. nullpo_retv(sd);
  1461. if ((idx = hom_skill_get_index(skill_id) == -1))
  1462. return;
  1463. fd = sd->fd;
  1464. hd = sd->hd;
  1465. WFIFOHEAD(fd, packet_len(0x239));
  1466. WFIFOW(fd,0) = 0x239;
  1467. WFIFOW(fd,2) = skill_id;
  1468. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1469. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1470. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1471. 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;
  1472. WFIFOSET(fd,packet_len(0x239));
  1473. }
  1474. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1475. {
  1476. int fd=sd->fd;
  1477. WFIFOHEAD(fd,packet_len(0x22f));
  1478. WFIFOW(fd,0)=0x22f;
  1479. WFIFOB(fd,2)=fail;
  1480. WFIFOW(fd,3)=foodid;
  1481. WFIFOSET(fd,packet_len(0x22f));
  1482. return 0;
  1483. }
  1484. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1485. /// 0087 <walk start time>.L <walk data>.6B
  1486. void clif_walkok(struct map_session_data *sd)
  1487. {
  1488. int fd=sd->fd;
  1489. WFIFOHEAD(fd, packet_len(0x87));
  1490. WFIFOW(fd,0)=0x87;
  1491. WFIFOL(fd,2)=gettick();
  1492. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1493. WFIFOSET(fd,packet_len(0x87));
  1494. }
  1495. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1496. {
  1497. uint8 buf[128];
  1498. int len;
  1499. struct status_change *sc = NULL;
  1500. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1501. clif_ally_only = true;
  1502. len = clif_set_unit_walking(bl,ud,buf);
  1503. clif_send(buf,len,bl,AREA_WOS);
  1504. if (disguised(bl))
  1505. clif_setdisguise(bl, buf, len);
  1506. if(vd->cloth_color)
  1507. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1508. if(vd->body_style)
  1509. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1510. switch(bl->type) {
  1511. case BL_PC:
  1512. {
  1513. TBL_PC *sd = ((TBL_PC*)bl);
  1514. // clif_movepc(sd);
  1515. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1516. clif_specialeffect(&sd->bl,423,AREA);
  1517. else if(sd->state.size==SZ_MEDIUM)
  1518. clif_specialeffect(&sd->bl,421,AREA);
  1519. if (sd->status.robe)
  1520. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1521. }
  1522. break;
  1523. case BL_MOB:
  1524. {
  1525. TBL_MOB *md = ((TBL_MOB*)bl);
  1526. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1527. clif_specialeffect(&md->bl,423,AREA);
  1528. else if(md->special_state.size==SZ_MEDIUM)
  1529. clif_specialeffect(&md->bl,421,AREA);
  1530. }
  1531. break;
  1532. case BL_PET:
  1533. if(vd->head_bottom) // needed to display pet equip properly
  1534. clif_pet_equip_area((TBL_PET*)bl);
  1535. break;
  1536. }
  1537. clif_ally_only = false;
  1538. }
  1539. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1540. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1541. /// Note: unit must not be self
  1542. void clif_move(struct unit_data *ud)
  1543. {
  1544. unsigned char buf[16];
  1545. struct view_data* vd;
  1546. struct block_list* bl = ud->bl;
  1547. struct status_change *sc = NULL;
  1548. vd = status_get_viewdata(bl);
  1549. if (!vd )
  1550. return;
  1551. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1552. else if( vd->class_ == INVISIBLE_CLASS ){
  1553. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1554. if(disguised(bl)) {
  1555. WBUFW(buf,0)=0x86;
  1556. WBUFL(buf,2)=-bl->id;
  1557. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1558. WBUFL(buf,12)=gettick();
  1559. clif_send(buf, packet_len(0x86), bl, SELF);
  1560. }
  1561. return;
  1562. }
  1563. /**
  1564. * Hide NPC from maya purple card.
  1565. **/
  1566. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1567. return;
  1568. if (ud->state.speed_changed) {
  1569. // Since we don't know how to update the speed of other objects,
  1570. // use the old walk packet to update the data.
  1571. ud->state.speed_changed = 0;
  1572. clif_move2(bl, vd, ud);
  1573. return;
  1574. }
  1575. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1576. clif_ally_only = true;
  1577. WBUFW(buf,0)=0x86;
  1578. WBUFL(buf,2)=bl->id;
  1579. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1580. WBUFL(buf,12)=gettick();
  1581. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1582. if (disguised(bl)) {
  1583. WBUFL(buf,2)=-bl->id;
  1584. clif_send(buf, packet_len(0x86), bl, SELF);
  1585. }
  1586. clif_ally_only = false;
  1587. }
  1588. /*==========================================
  1589. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1590. *------------------------------------------*/
  1591. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1592. {
  1593. struct map_session_data *sd = NULL;
  1594. //Remove player from map server
  1595. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1596. map_quit(sd);
  1597. return 0;
  1598. }
  1599. /*==========================================
  1600. *
  1601. *------------------------------------------*/
  1602. void clif_quitsave(int fd,struct map_session_data *sd) {
  1603. if (!battle_config.prevent_logout ||
  1604. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1605. map_quit(sd);
  1606. else if (sd->fd) {
  1607. //Disassociate session from player (session is deleted after this function was called)
  1608. //And set a timer to make him quit later.
  1609. session[sd->fd]->session_data = NULL;
  1610. sd->fd = 0;
  1611. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1612. }
  1613. }
  1614. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1615. /// 0091 <map name>.16B <x>.W <y>.W
  1616. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1617. {
  1618. int fd;
  1619. nullpo_retv(sd);
  1620. fd = sd->fd;
  1621. WFIFOHEAD(fd,packet_len(0x91));
  1622. WFIFOW(fd,0) = 0x91;
  1623. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1624. WFIFOW(fd,18) = x;
  1625. WFIFOW(fd,20) = y;
  1626. WFIFOSET(fd,packet_len(0x91));
  1627. }
  1628. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1629. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1630. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1631. {
  1632. int fd;
  1633. nullpo_retv(sd);
  1634. fd = sd->fd;
  1635. WFIFOHEAD(fd,packet_len(0x92));
  1636. WFIFOW(fd,0) = 0x92;
  1637. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1638. WFIFOW(fd,18) = x;
  1639. WFIFOW(fd,20) = y;
  1640. WFIFOL(fd,22) = htonl(ip);
  1641. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1642. WFIFOSET(fd,packet_len(0x92));
  1643. }
  1644. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1645. /// This function combines both calls and allows to simplify the calling code
  1646. void clif_blown(struct block_list *bl)
  1647. {
  1648. clif_slide(bl, bl->x, bl->y);
  1649. clif_fixpos(bl);
  1650. }
  1651. /// Visually moves(slides) a character to x,y. If the target cell
  1652. /// isn't walkable, the char doesn't move at all. If the char is
  1653. /// sitting it will stand up (ZC_STOPMOVE).
  1654. /// 0088 <id>.L <x>.W <y>.W
  1655. void clif_fixpos(struct block_list *bl)
  1656. {
  1657. unsigned char buf[10];
  1658. nullpo_retv(bl);
  1659. WBUFW(buf,0) = 0x88;
  1660. WBUFL(buf,2) = bl->id;
  1661. WBUFW(buf,6) = bl->x;
  1662. WBUFW(buf,8) = bl->y;
  1663. clif_send(buf, packet_len(0x88), bl, AREA);
  1664. if( disguised(bl) ) {
  1665. WBUFL(buf,2) = -bl->id;
  1666. clif_send(buf, packet_len(0x88), bl, SELF);
  1667. }
  1668. }
  1669. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1670. /// 00c4 <shop id>.L
  1671. void clif_npcbuysell(struct map_session_data* sd, int id)
  1672. {
  1673. int fd;
  1674. nullpo_retv(sd);
  1675. fd=sd->fd;
  1676. WFIFOHEAD(fd, packet_len(0xc4));
  1677. WFIFOW(fd,0)=0xc4;
  1678. WFIFOL(fd,2)=id;
  1679. WFIFOSET(fd,packet_len(0xc4));
  1680. }
  1681. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1682. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1683. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1684. {
  1685. int fd,i,c;
  1686. bool discount;
  1687. nullpo_retv(sd);
  1688. nullpo_retv(nd);
  1689. fd = sd->fd;
  1690. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1691. WFIFOW(fd,0) = 0xc6;
  1692. c = 0;
  1693. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1694. for( i = 0; i < nd->u.shop.count; i++ )
  1695. {
  1696. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1697. int val = nd->u.shop.shop_item[i].value;
  1698. if( id == NULL )
  1699. continue;
  1700. WFIFOL(fd, 4+c*11) = val;
  1701. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1702. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1703. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1704. c++;
  1705. }
  1706. WFIFOW(fd,2) = 4 + c*11;
  1707. WFIFOSET(fd,WFIFOW(fd,2));
  1708. }
  1709. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1710. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1711. void clif_selllist(struct map_session_data *sd)
  1712. {
  1713. int fd,i,c=0,val;
  1714. nullpo_retv(sd);
  1715. fd=sd->fd;
  1716. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1717. WFIFOW(fd,0)=0xc7;
  1718. for( i = 0; i < MAX_INVENTORY; i++ )
  1719. {
  1720. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1721. {
  1722. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1723. continue;
  1724. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1725. continue; // Cannot Sell Rental Items or Account Bounded Items
  1726. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1727. continue; // Don't allow sale of bound items
  1728. val=sd->inventory_data[i]->value_sell;
  1729. if( val < 0 )
  1730. continue;
  1731. WFIFOW(fd,4+c*10)=i+2;
  1732. WFIFOL(fd,6+c*10)=val;
  1733. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1734. c++;
  1735. }
  1736. }
  1737. WFIFOW(fd,2)=c*10+4;
  1738. WFIFOSET(fd,WFIFOW(fd,2));
  1739. }
  1740. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1741. /// 09d4
  1742. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1743. // TODO: State tracking?
  1744. sd->npc_shopid = 0;
  1745. }
  1746. /**
  1747. * Presents list of items, that can be sold to a Market shop.
  1748. * @author: Ind and Yommy
  1749. **/
  1750. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1751. #if PACKETVER >= 20131223
  1752. struct npc_item_list *shop = nd->u.shop.shop_item;
  1753. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1754. struct item_data *id = NULL;
  1755. struct s_packet_db *info;
  1756. int fd;
  1757. nullpo_retv(sd);
  1758. if (sd->state.trading)
  1759. return;
  1760. info = &packet_db[sd->packet_ver][cmd];
  1761. if (!info || info->len == 0)
  1762. return;
  1763. fd = sd->fd;
  1764. WFIFOHEAD(fd, 4 + shop_size * 13);
  1765. WFIFOW(fd,0) = cmd;
  1766. for (i = 0, c = 0; i < shop_size; i++) {
  1767. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1768. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1769. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1770. WFIFOL(fd, 7+c*13) = shop[i].value;
  1771. WFIFOL(fd,11+c*13) = shop[i].qty;
  1772. WFIFOW(fd,15+c*13) = (id->view_id > 0) ? id->view_id : id->nameid;
  1773. c++;
  1774. }
  1775. }
  1776. WFIFOW(fd,2) = 4 + c*13;
  1777. WFIFOSET(fd,WFIFOW(fd,2));
  1778. sd->state.trading = 1;
  1779. #endif
  1780. }
  1781. /// Closes the Market shop window.
  1782. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1783. nullpo_retv(sd);
  1784. sd->npc_shopid = 0;
  1785. sd->state.trading = 0;
  1786. }
  1787. /// Purchase item from Market shop.
  1788. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1789. #if PACKETVER >= 20131223
  1790. unsigned short cmd = 0x9d7, len = 0;
  1791. struct npc_data* nd;
  1792. uint8 result = (res == 0 ? 1 : 0);
  1793. int fd = 0;
  1794. struct s_packet_db *info;
  1795. nullpo_retv(sd);
  1796. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1797. info = &packet_db[sd->packet_ver][cmd];
  1798. if (!info || info->len == 0)
  1799. return;
  1800. fd = sd->fd;
  1801. len = 5 + 8*n;
  1802. WFIFOHEAD(fd, len);
  1803. WFIFOW(fd, 0) = cmd;
  1804. WFIFOW(fd, 2) = len;
  1805. if (result) {
  1806. uint8 i, j;
  1807. struct npc_item_list *shop = nd->u.shop.shop_item;
  1808. unsigned short count = nd->u.shop.count;
  1809. for (i = 0; i < n; i++) {
  1810. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1811. WFIFOW(fd, 7+i*8) = list[i].qty;
  1812. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1813. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1814. }
  1815. }
  1816. WFIFOB(fd, 4) = n;
  1817. WFIFOSET(fd, len);
  1818. #endif
  1819. }
  1820. /// Purchase item from Market shop.
  1821. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1822. #if PACKETVER >= 20131223
  1823. struct s_packet_db* info;
  1824. struct s_npc_buy_list *item_list;
  1825. uint16 len = 0, i = 0;
  1826. uint8 res = 0, n = 0;
  1827. nullpo_retv(sd);
  1828. if (!sd->npc_shopid)
  1829. return;
  1830. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  1831. if (!info || info->len == 0)
  1832. return;
  1833. len = RFIFOW(fd,info->pos[0]);
  1834. n = (len-4) / 6;
  1835. CREATE(item_list, struct s_npc_buy_list, n);
  1836. for (i = 0; i < n; i++) {
  1837. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1838. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1839. }
  1840. res = npc_buylist(sd, n, item_list);
  1841. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1842. aFree(item_list);
  1843. #endif
  1844. }
  1845. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1846. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1847. /// Client behavior (dialog window):
  1848. /// - disable mouse targeting
  1849. /// - open the dialog window
  1850. /// - set npcid of dialog window (0 by default)
  1851. /// - if set to clear on next mes, clear contents
  1852. /// - append this text
  1853. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1854. {
  1855. int fd = sd->fd;
  1856. int slen = strlen(mes) + 9;
  1857. WFIFOHEAD(fd, slen);
  1858. WFIFOW(fd,0)=0xb4;
  1859. WFIFOW(fd,2)=slen;
  1860. WFIFOL(fd,4)=npcid;
  1861. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1862. WFIFOSET(fd,WFIFOW(fd,2));
  1863. }
  1864. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1865. /// 00b5 <npc id>.L
  1866. /// Client behavior (dialog window):
  1867. /// - disable mouse targeting
  1868. /// - open the dialog window
  1869. /// - add 'next' button
  1870. /// When 'next' is pressed:
  1871. /// - 00B9 <npcid of dialog window>.L
  1872. /// - set to clear on next mes
  1873. /// - remove 'next' button
  1874. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1875. {
  1876. int fd;
  1877. nullpo_retv(sd);
  1878. fd=sd->fd;
  1879. WFIFOHEAD(fd, packet_len(0xb5));
  1880. WFIFOW(fd,0)=0xb5;
  1881. WFIFOL(fd,2)=npcid;
  1882. WFIFOSET(fd,packet_len(0xb5));
  1883. }
  1884. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1885. /// 00b6 <npc id>.L
  1886. /// Client behavior:
  1887. /// - if dialog window is open:
  1888. /// - remove 'next' button
  1889. /// - add 'close' button
  1890. /// - else:
  1891. /// - enable mouse targeting
  1892. /// - close the dialog window
  1893. /// - close the menu window
  1894. /// When 'close' is pressed:
  1895. /// - enable mouse targeting
  1896. /// - close the dialog window
  1897. /// - close the menu window
  1898. /// - 0146 <npcid of dialog window>.L
  1899. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1900. {
  1901. int fd;
  1902. nullpo_retv(sd);
  1903. fd=sd->fd;
  1904. WFIFOHEAD(fd, packet_len(0xb6));
  1905. WFIFOW(fd,0)=0xb6;
  1906. WFIFOL(fd,2)=npcid;
  1907. WFIFOSET(fd,packet_len(0xb6));
  1908. }
  1909. /**
  1910. * Close script when player is idle
  1911. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1912. * @author [Ind/Hercules]
  1913. * @param sd : player pointer
  1914. * @param npcid : npc gid to close
  1915. */
  1916. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1917. {
  1918. struct s_packet_db* info;
  1919. int16 len;
  1920. int cmd = 0;
  1921. int fd;
  1922. nullpo_retv(sd);
  1923. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1924. if(!cmd) cmd = 0x8d6; //default
  1925. info = &packet_db[sd->packet_ver][cmd];
  1926. len = info->len;
  1927. fd = sd->fd;
  1928. WFIFOHEAD(fd, len);
  1929. WFIFOW(fd,0)=0x8d6;
  1930. WFIFOL(fd,info->pos[0])=npcid;
  1931. WFIFOSET(fd,len);
  1932. }
  1933. /*==========================================
  1934. *
  1935. *------------------------------------------*/
  1936. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1937. unsigned char *buf;
  1938. int fd = sd->fd;
  1939. sd->state.using_fake_npc = 1;
  1940. WFIFOHEAD(fd, packet_len(0x78));
  1941. buf = WFIFOP(fd,0);
  1942. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1943. WBUFW(buf,0)=0x78;
  1944. #if PACKETVER >= 20071106
  1945. WBUFB(buf,2) = 0; // object type
  1946. buf = WFIFOP(fd,1);
  1947. #endif
  1948. WBUFL(buf,2)=npcid;
  1949. WBUFW(buf,14)=111;
  1950. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1951. WBUFB(buf,49)=5;
  1952. WBUFB(buf,50)=5;
  1953. WFIFOSET(fd, packet_len(0x78));
  1954. }
  1955. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1956. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1957. /// Client behavior:
  1958. /// - disable mouse targeting
  1959. /// - close the menu window
  1960. /// - open the menu window
  1961. /// - add options to the menu (separated in the text by ":")
  1962. /// - set npcid of menu window
  1963. /// - if dialog window is open:
  1964. /// - remove 'next' button
  1965. /// When 'ok' is pressed:
  1966. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1967. /// - close the menu window
  1968. /// When 'cancel' is pressed:
  1969. /// - 00B8 <npcid of menu window>.L <-1>.B
  1970. /// - enable mouse targeting
  1971. /// - close a bunch of windows...
  1972. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1973. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1974. /// TODO investigate behavior of other windows [FlavioJS]
  1975. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1976. {
  1977. int fd = sd->fd;
  1978. int slen = strlen(mes) + 9;
  1979. struct block_list *bl = NULL;
  1980. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1981. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1982. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1983. clif_sendfakenpc(sd, npcid);
  1984. WFIFOHEAD(fd, slen);
  1985. WFIFOW(fd,0)=0xb7;
  1986. WFIFOW(fd,2)=slen;
  1987. WFIFOL(fd,4)=npcid;
  1988. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1989. WFIFOSET(fd,WFIFOW(fd,2));
  1990. }
  1991. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1992. /// 0142 <npc id>.L
  1993. /// Client behavior (inputnum window):
  1994. /// - if npcid exists in the client:
  1995. /// - open the inputnum window
  1996. /// - set npcid of inputnum window
  1997. /// When 'ok' is pressed:
  1998. /// - if inputnum window has text:
  1999. /// - if npcid exists in the client:
  2000. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2001. /// - close inputnum window
  2002. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2003. {
  2004. int fd;
  2005. struct block_list *bl = NULL;
  2006. nullpo_retv(sd);
  2007. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2008. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2009. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2010. clif_sendfakenpc(sd, npcid);
  2011. fd=sd->fd;
  2012. WFIFOHEAD(fd, packet_len(0x142));
  2013. WFIFOW(fd,0)=0x142;
  2014. WFIFOL(fd,2)=npcid;
  2015. WFIFOSET(fd,packet_len(0x142));
  2016. }
  2017. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2018. /// 01d4 <npc id>.L
  2019. /// Client behavior (inputstr window):
  2020. /// - if npcid is 0 or npcid exists in the client:
  2021. /// - open the inputstr window
  2022. /// - set npcid of inputstr window
  2023. /// When 'ok' is pressed:
  2024. /// - if inputstr window has text and isn't an insult(manner.txt):
  2025. /// - if npcid is 0 or npcid exists in the client:
  2026. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2027. /// - close inputstr window
  2028. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2029. {
  2030. int fd;
  2031. struct block_list *bl = NULL;
  2032. nullpo_retv(sd);
  2033. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2034. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2035. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2036. clif_sendfakenpc(sd, npcid);
  2037. fd=sd->fd;
  2038. WFIFOHEAD(fd, packet_len(0x1d4));
  2039. WFIFOW(fd,0)=0x1d4;
  2040. WFIFOL(fd,2)=npcid;
  2041. WFIFOSET(fd,packet_len(0x1d4));
  2042. }
  2043. /// Marks a position on client's minimap (ZC_COMPASS).
  2044. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2045. /// npc id:
  2046. /// is ignored in the client
  2047. /// type:
  2048. /// 0 = display mark for 15 seconds
  2049. /// 1 = display mark until dead or teleported
  2050. /// 2 = remove mark
  2051. /// color:
  2052. /// 0x00RRGGBB
  2053. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2054. {
  2055. int fd;
  2056. nullpo_retv(sd);
  2057. fd=sd->fd;
  2058. WFIFOHEAD(fd, packet_len(0x144));
  2059. WFIFOW(fd,0)=0x144;
  2060. WFIFOL(fd,2)=npc_id;
  2061. WFIFOL(fd,6)=type;
  2062. WFIFOL(fd,10)=x;
  2063. WFIFOL(fd,14)=y;
  2064. WFIFOB(fd,18)=id;
  2065. WFIFOL(fd,19)=color;
  2066. WFIFOSET(fd,packet_len(0x144));
  2067. }
  2068. /// Displays an illustration image.
  2069. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2070. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2071. /// type:
  2072. /// 0 = bottom left corner
  2073. /// 1 = bottom middle
  2074. /// 2 = bottom right corner
  2075. /// 3 = middle of screen, inside a movable window
  2076. /// 4 = middle of screen, movable with a close button, chrome-less
  2077. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2078. {
  2079. int fd;
  2080. nullpo_retv(sd);
  2081. fd=sd->fd;
  2082. WFIFOHEAD(fd, packet_len(0x1b3));
  2083. WFIFOW(fd,0)=0x1b3;
  2084. strncpy((char*)WFIFOP(fd,2),image,64);
  2085. WFIFOB(fd,66)=type;
  2086. WFIFOSET(fd,packet_len(0x1b3));
  2087. }
  2088. /*==========================================
  2089. * Fills in card data from the given item and into the buffer. [Skotlex]
  2090. *------------------------------------------*/
  2091. static void clif_addcards(unsigned char* buf, struct item* item)
  2092. {
  2093. int i=0,j;
  2094. if( item == NULL ) { //Blank data
  2095. WBUFW(buf,0) = 0;
  2096. WBUFW(buf,2) = 0;
  2097. WBUFW(buf,4) = 0;
  2098. WBUFW(buf,6) = 0;
  2099. return;
  2100. }
  2101. if( item->card[0] == CARD0_PET ) { //pet eggs
  2102. WBUFW(buf,0) = 0;
  2103. WBUFW(buf,2) = 0;
  2104. WBUFW(buf,4) = 0;
  2105. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2106. return;
  2107. }
  2108. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2109. WBUFW(buf,0) = item->card[0];
  2110. WBUFW(buf,2) = item->card[1];
  2111. WBUFW(buf,4) = item->card[2];
  2112. WBUFW(buf,6) = item->card[3];
  2113. return;
  2114. }
  2115. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2116. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2117. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2118. //Normal items.
  2119. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2120. WBUFW(buf,0) = j;
  2121. else
  2122. WBUFW(buf,0) = item->card[i];
  2123. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2124. WBUFW(buf,2) = j;
  2125. else
  2126. WBUFW(buf,2) = item->card[i];
  2127. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2128. WBUFW(buf,4) = j;
  2129. else
  2130. WBUFW(buf,4) = item->card[i];
  2131. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2132. WBUFW(buf,6) = j;
  2133. else
  2134. WBUFW(buf,6) = item->card[i];
  2135. }
  2136. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2137. /// A maximum of 5 random options can be supported.
  2138. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2139. #if PACKETVER >= 20150226
  2140. int i;
  2141. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2142. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2143. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2144. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2145. }
  2146. #if MAX_ITEM_RDM_OPT < 5
  2147. for ( ; 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. #endif
  2154. }
  2155. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2156. /// 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)
  2157. /// 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)
  2158. /// 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)
  2159. /// 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)
  2160. /// 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)
  2161. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2162. {
  2163. int fd, header, offs=0;
  2164. #if PACKETVER < 20061218
  2165. header = 0xa0;
  2166. #elif PACKETVER < 20071002
  2167. header = 0x29a;
  2168. #elif PACKETVER < 20120925
  2169. header = 0x2d4;
  2170. #elif PACKETVER < 20150226
  2171. header = 0x990;
  2172. #else
  2173. header = 0xa0c;
  2174. #endif
  2175. nullpo_retv(sd);
  2176. fd = sd->fd;
  2177. if( !session_isActive(fd) ) //Sasuke-
  2178. return;
  2179. WFIFOHEAD(fd,packet_len(header));
  2180. if( fail )
  2181. {
  2182. WFIFOW(fd,offs+0) = header;
  2183. WFIFOW(fd,offs+2) = n+2;
  2184. WFIFOW(fd,offs+4) = amount;
  2185. WFIFOW(fd,offs+6) = 0;
  2186. WFIFOB(fd,offs+8) = 0;
  2187. WFIFOB(fd,offs+9) = 0;
  2188. WFIFOB(fd,offs+10) = 0;
  2189. WFIFOW(fd,offs+11) = 0;
  2190. WFIFOW(fd,offs+13) = 0;
  2191. WFIFOW(fd,offs+15) = 0;
  2192. WFIFOW(fd,offs+17) = 0;
  2193. #if PACKETVER < 20120925
  2194. WFIFOW(fd,offs+19) = 0;
  2195. #else
  2196. WFIFOL(fd,offs+19) = 0;
  2197. offs += 2;
  2198. #endif
  2199. WFIFOB(fd,offs+21) = 0;
  2200. WFIFOB(fd,offs+22) = fail;
  2201. #if PACKETVER >= 20061218
  2202. WFIFOL(fd,offs+23) = 0;
  2203. #endif
  2204. #if PACKETVER >= 20071002
  2205. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2206. #if PACKETVER >= 20150226
  2207. clif_add_random_options(WFIFOP(fd,offs+31), &sd->status.inventory[n]);
  2208. #endif
  2209. #endif
  2210. }
  2211. else
  2212. {
  2213. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2214. return;
  2215. WFIFOW(fd,offs+0) = header;
  2216. WFIFOW(fd,offs+2) = n+2;
  2217. WFIFOW(fd,offs+4) = amount;
  2218. if (sd->inventory_data[n]->view_id > 0)
  2219. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2220. else
  2221. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  2222. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  2223. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  2224. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  2225. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  2226. #if PACKETVER < 20120925
  2227. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2228. #else
  2229. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2230. offs += 2;
  2231. #endif
  2232. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2233. WFIFOB(fd,offs+22) = fail;
  2234. #if PACKETVER >= 20061218
  2235. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  2236. #endif
  2237. #if PACKETVER >= 20071002
  2238. /* Yellow color only for non-stackable item */
  2239. 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;
  2240. #endif
  2241. #if PACKETVER >= 20150226
  2242. clif_add_random_options(WFIFOP(fd,31), &sd->status.inventory[n]);
  2243. #endif
  2244. }
  2245. WFIFOSET(fd,packet_len(header));
  2246. }
  2247. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2248. /// 00af <index>.W <amount>.W
  2249. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2250. {
  2251. int fd;
  2252. nullpo_retv(sd);
  2253. fd=sd->fd;
  2254. WFIFOHEAD(fd, packet_len(0xaf));
  2255. WFIFOW(fd,0)=0xaf;
  2256. WFIFOW(fd,2)=n+2;
  2257. WFIFOW(fd,4)=amount;
  2258. WFIFOSET(fd,packet_len(0xaf));
  2259. }
  2260. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2261. /// 07fa <delete type>.W <index>.W <amount>.W
  2262. /// delete type:
  2263. /// 0 = Normal
  2264. /// 1 = Item used for a skill
  2265. /// 2 = Refine failed
  2266. /// 3 = Material changed
  2267. /// 4 = Moved to storage
  2268. /// 5 = Moved to cart
  2269. /// 6 = Item sold
  2270. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2271. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2272. {
  2273. #if PACKETVER < 20091117
  2274. clif_dropitem(sd,n,amount);
  2275. #else
  2276. int fd;
  2277. nullpo_retv(sd);
  2278. fd=sd->fd;
  2279. WFIFOHEAD(fd, packet_len(0x7fa));
  2280. WFIFOW(fd,0)=0x7fa;
  2281. WFIFOW(fd,2)=reason;
  2282. WFIFOW(fd,4)=n+2;
  2283. WFIFOW(fd,6)=amount;
  2284. WFIFOSET(fd,packet_len(0x7fa));
  2285. #endif
  2286. }
  2287. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2288. char normal = (equip < 0);
  2289. int offset = 0;
  2290. WBUFW(buf,n) = idx; //index
  2291. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2292. WBUFB(buf,n+4) = itemtype(id->nameid);
  2293. if (!normal){ //equip 31B
  2294. WBUFL(buf,n+5) = equip; //location
  2295. WBUFL(buf,n+9) = it->equip; //wear state
  2296. WBUFB(buf,n+13) = it->refine; //refine lvl
  2297. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2298. WBUFL(buf,n+22) = it->expire_time;
  2299. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2300. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2301. #if PACKETVER >= 20150226
  2302. //V6_ITEM_Option
  2303. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2304. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2305. offset += 26;
  2306. #endif
  2307. //V5_ITEM_flag
  2308. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2309. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2310. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2311. }
  2312. else { //normal 24B
  2313. WBUFW(buf,n+5) = it->amount;
  2314. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2315. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2316. WBUFL(buf,n+19) = it->expire_time;
  2317. //V5_ITEM_flag
  2318. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2319. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2320. }
  2321. }
  2322. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2323. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2324. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2325. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2326. #if PACKETVER >= 20120925
  2327. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2328. #else
  2329. WBUFW(buf,n) = idx; //index
  2330. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2331. WBUFB(buf,n+4) = itemtype(id->nameid);
  2332. WBUFB(buf,n+5) = it->identify;
  2333. if (equip >= 0) { //Equippable item 28.B
  2334. WBUFW(buf,n+6) = equip;
  2335. WBUFW(buf,n+8) = it->equip;
  2336. WBUFB(buf,n+10) = it->attribute;
  2337. WBUFB(buf,n+11) = it->refine;
  2338. clif_addcards(WBUFP(buf, n+12), it); //8B
  2339. #if PACKETVER >= 20071002
  2340. WBUFL(buf,n+20) = it->expire_time;
  2341. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2342. #endif
  2343. #if PACKETVER >= 20100629
  2344. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2345. #endif
  2346. } else { //Stackable item. 22.B
  2347. WBUFW(buf,n+6) = it->amount;
  2348. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2349. clif_addcards(WBUFP(buf, n+10), it); //8B
  2350. #if PACKETVER >= 20071002
  2351. WBUFL(buf,n+18) = it->expire_time;
  2352. #endif
  2353. }
  2354. #endif
  2355. }
  2356. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2357. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2358. void clif_inventorylist(struct map_session_data *sd) {
  2359. int i,n,ne,arrow=-1;
  2360. unsigned char *buf;
  2361. unsigned char *bufe;
  2362. #if PACKETVER < 5
  2363. const int s = 10; //Entry size
  2364. #elif PACKETVER < 20080102
  2365. const int s = 18;
  2366. #elif PACKETVER < 20120925
  2367. const int s = 22;
  2368. #else
  2369. const int s = 24;
  2370. #endif
  2371. #if PACKETVER < 20071002
  2372. const int se = 20;
  2373. #elif PACKETVER < 20100629
  2374. const int se = 26;
  2375. #elif PACKETVER < 20120925
  2376. const int se = 28;
  2377. #elif PACKETVER < 20150226
  2378. const int se = 31;
  2379. #else
  2380. const int se = 57;
  2381. #endif
  2382. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2383. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2384. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2385. {
  2386. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2387. continue;
  2388. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2389. { //Non-stackable (Equippable)
  2390. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2391. ne++;
  2392. }
  2393. else { //Stackable.
  2394. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2395. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2396. arrow=i;
  2397. n++;
  2398. }
  2399. }
  2400. if( n )
  2401. {
  2402. #if PACKETVER < 5
  2403. WBUFW(buf,0)=0xa3;
  2404. #elif PACKETVER < 20080102
  2405. WBUFW(buf,0)=0x1ee;
  2406. #elif PACKETVER < 20120925
  2407. WBUFW(buf,0)=0x2e8;
  2408. #else
  2409. WBUFW(buf,0)=0x991;
  2410. #endif
  2411. WBUFW(buf,2)=4+n*s;
  2412. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2413. }
  2414. if( arrow >= 0 )
  2415. clif_arrowequip(sd,arrow);
  2416. if( ne ) {
  2417. #if PACKETVER < 20071002
  2418. WBUFW(bufe,0)=0xa4;
  2419. #elif PACKETVER < 20120925
  2420. WBUFW(bufe,0)=0x2d0;
  2421. #elif PACKETVER < 20150226
  2422. WBUFW(bufe,0)=0x992;
  2423. #else
  2424. WBUFW(bufe,0)=0xa0d;
  2425. #endif
  2426. WBUFW(bufe,2)=4+ne*se;
  2427. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2428. }
  2429. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2430. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2431. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2432. continue;
  2433. if ( sd->status.inventory[i].favorite )
  2434. clif_favorite_item(sd, i);
  2435. }
  2436. #endif
  2437. if( buf ) aFree(buf);
  2438. if( bufe ) aFree(bufe);
  2439. }
  2440. //Required when items break/get-repaired. Only sends equippable item list.
  2441. void clif_equiplist(struct map_session_data *sd)
  2442. {
  2443. int i,n,fd = sd->fd;
  2444. unsigned char *buf;
  2445. #if PACKETVER < 20071002
  2446. const int cmd = 20;
  2447. #elif PACKETVER < 20100629
  2448. const int cmd = 26;
  2449. #elif PACKETVER < 20120925
  2450. const int cmd = 28;
  2451. #elif PACKETVER < 20150226
  2452. const int cmd = 31;
  2453. #else
  2454. const int cmd = 57;
  2455. #endif
  2456. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2457. buf = WFIFOP(fd,0);
  2458. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2459. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2460. continue;
  2461. if(itemdb_isstackable2(sd->inventory_data[i]))
  2462. continue;
  2463. //Equippable
  2464. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2465. n++;
  2466. }
  2467. if (n) {
  2468. #if PACKETVER < 20071002
  2469. WBUFW(buf,0)=0xa4;
  2470. #elif PACKETVER < 20120925
  2471. WBUFW(buf,0)=0x2d0;
  2472. #elif PACKETVER < 20150226
  2473. WBUFW(buf,0)=0x992;
  2474. #else
  2475. WBUFW(buf,0)=0xa0d;
  2476. #endif
  2477. WBUFW(buf,2)=4+n*cmd;
  2478. WFIFOSET(fd,WFIFOW(fd,2));
  2479. }
  2480. }
  2481. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2482. {
  2483. static const int client_buf = 0x5000; // Max buffer to send
  2484. struct item_data *id;
  2485. int i,n,ne,nn;
  2486. unsigned char *buf;
  2487. unsigned char *bufe;
  2488. #if PACKETVER < 5
  2489. const int s = 10; //Entry size.normal item
  2490. const int sidx=4; //start itemlist idx
  2491. const int cmd = 0xa5;
  2492. #elif PACKETVER < 20080102
  2493. const int s = 18;
  2494. const int sidx=4;
  2495. const int cmd = 0x1f0;
  2496. #elif PACKETVER < 20120925
  2497. const int s = 22;
  2498. const int sidx=4;
  2499. const int cmd = 0x2ea;
  2500. #else
  2501. const int s = 24;
  2502. const int sidx = 4+24;
  2503. const int cmd = 0x995;
  2504. #endif
  2505. #if PACKETVER < 20071002
  2506. const int se = 20; //entry size equip
  2507. const int sidxe = 4; //start itemlist idx
  2508. const int cmde = 0xa6;
  2509. #elif PACKETVER < 20100629
  2510. const int se = 26;
  2511. const int sidxe = 4;
  2512. const int cmde = 0x2d1;
  2513. #elif PACKETVER < 20120925
  2514. const int se = 28;
  2515. const int sidxe = 4;
  2516. const int cmde = 0x2d1;
  2517. #elif PACKETVER < 20150226
  2518. const int se = 31;
  2519. const int sidxe = 4+24;
  2520. const int cmde = 0x996;
  2521. #else
  2522. const int se = 57;
  2523. const int sidxe = 4+24;
  2524. const int cmde = 0xa10;
  2525. #endif
  2526. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2527. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2528. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2529. {
  2530. if( items[i].nameid <= 0 )
  2531. continue;
  2532. id = itemdb_search(items[i].nameid);
  2533. if( !itemdb_isstackable2(id) ) { //Equippable
  2534. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2535. ne++;
  2536. }
  2537. else { //Stackable
  2538. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2539. n++;
  2540. }
  2541. }
  2542. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2543. {
  2544. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2545. WFIFOHEAD(sd->fd,sidx+nn*s);
  2546. WFIFOW(sd->fd,0)=cmd;
  2547. WFIFOW(sd->fd,2)=sidx+nn*s;
  2548. #if PACKETVER >= 20120925
  2549. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2550. #endif
  2551. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2552. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2553. }
  2554. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2555. {
  2556. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2557. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2558. WFIFOW(sd->fd,0)=cmde;
  2559. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2560. #if PACKETVER >= 20120925
  2561. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2562. #endif
  2563. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2564. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2565. }
  2566. if( buf ) aFree(buf);
  2567. if( bufe ) aFree(bufe);
  2568. }
  2569. void clif_cartlist(struct map_session_data *sd)
  2570. {
  2571. struct item_data *id;
  2572. int i,n,ne;
  2573. unsigned char *buf;
  2574. unsigned char *bufe;
  2575. #if PACKETVER < 5
  2576. const int s = 10; //Entry size.
  2577. #elif PACKETVER < 20080102
  2578. const int s = 18;
  2579. #elif PACKETVER < 20120925
  2580. const int s = 22;
  2581. #else
  2582. const int s = 24;
  2583. #endif
  2584. #if PACKETVER < 20071002
  2585. const int cmd = 20;
  2586. #elif PACKETVER < 20100629
  2587. const int cmd = 26;
  2588. #elif PACKETVER < 20120925
  2589. const int cmd = 28;
  2590. #elif PACKETVER < 20150226
  2591. const int cmd = 31;
  2592. #else
  2593. const int cmd = 57;
  2594. #endif
  2595. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2596. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2597. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2598. {
  2599. if( sd->status.cart[i].nameid <= 0 )
  2600. continue;
  2601. id = itemdb_search(sd->status.cart[i].nameid);
  2602. if( !itemdb_isstackable2(id) ) { //Equippable
  2603. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2604. ne++;
  2605. }
  2606. else { //Stackable
  2607. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2608. n++;
  2609. }
  2610. }
  2611. if( n )
  2612. {
  2613. #if PACKETVER < 5
  2614. WBUFW(buf,0)=0x123;
  2615. #elif PACKETVER < 20080102
  2616. WBUFW(buf,0)=0x1ef;
  2617. #elif PACKETVER < 20120925
  2618. WBUFW(buf,0)=0x2e9;
  2619. #else
  2620. WBUFW(buf,0)=0x993;
  2621. #endif
  2622. WBUFW(buf,2)=4+n*s;
  2623. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2624. }
  2625. if( ne )
  2626. {
  2627. #if PACKETVER < 20071002
  2628. WBUFW(bufe,0)=0x122;
  2629. #elif PACKETVER < 20120925
  2630. WBUFW(bufe,0)=0x2d2;
  2631. #elif PACKETVER < 20150226
  2632. WBUFW(bufe,0)=0x994;
  2633. #else
  2634. WBUFW(bufe,0)=0xa0f;
  2635. #endif
  2636. WBUFW(bufe,2)=4+ne*cmd;
  2637. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2638. }
  2639. if( buf ) aFree(buf);
  2640. if( bufe ) aFree(bufe);
  2641. }
  2642. /// Removes cart (ZC_CARTOFF).
  2643. /// 012b
  2644. /// Client behaviour:
  2645. /// Closes the cart storage and removes all it's items from memory.
  2646. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2647. void clif_clearcart(int fd)
  2648. {
  2649. WFIFOHEAD(fd, packet_len(0x12b));
  2650. WFIFOW(fd,0) = 0x12b;
  2651. WFIFOSET(fd, packet_len(0x12b));
  2652. }
  2653. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2654. /// 01eb <account id>.L <x>.W <y>.W
  2655. void clif_guild_xy(struct map_session_data *sd)
  2656. {
  2657. unsigned char buf[10];
  2658. nullpo_retv(sd);
  2659. WBUFW(buf,0)=0x1eb;
  2660. WBUFL(buf,2)=sd->status.account_id;
  2661. WBUFW(buf,6)=sd->bl.x;
  2662. WBUFW(buf,8)=sd->bl.y;
  2663. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2664. }
  2665. /*==========================================
  2666. * Sends x/y dot to a single fd. [Skotlex]
  2667. *------------------------------------------*/
  2668. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2669. {
  2670. if( sd->bg_id )
  2671. return;
  2672. WFIFOHEAD(fd,packet_len(0x1eb));
  2673. WFIFOW(fd,0)=0x1eb;
  2674. WFIFOL(fd,2)=sd->status.account_id;
  2675. WFIFOW(fd,6)=sd->bl.x;
  2676. WFIFOW(fd,8)=sd->bl.y;
  2677. WFIFOSET(fd,packet_len(0x1eb));
  2678. }
  2679. // Guild XY locators [Valaris]
  2680. void clif_guild_xy_remove(struct map_session_data *sd)
  2681. {
  2682. unsigned char buf[10];
  2683. nullpo_retv(sd);
  2684. WBUFW(buf,0)=0x1eb;
  2685. WBUFL(buf,2)=sd->status.account_id;
  2686. WBUFW(buf,6)=-1;
  2687. WBUFW(buf,8)=-1;
  2688. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2689. }
  2690. /*==========================================
  2691. *
  2692. *------------------------------------------*/
  2693. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2694. {
  2695. struct map_session_data *sd, *tsd;
  2696. #if PACKETVER < 20100126
  2697. const int cmd = 0x106;
  2698. #else
  2699. const int cmd = 0x80e;
  2700. #endif
  2701. sd = va_arg(ap, struct map_session_data *);
  2702. tsd = (TBL_PC *)bl;
  2703. nullpo_ret(sd);
  2704. nullpo_ret(tsd);
  2705. if( !tsd->fd || tsd == sd )
  2706. return 0;
  2707. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2708. return 0;
  2709. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2710. WFIFOW(tsd->fd,0) = cmd;
  2711. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2712. #if PACKETVER < 20100126
  2713. if( sd->battle_status.max_hp > INT16_MAX )
  2714. { //To correctly display the %hp bar. [Skotlex]
  2715. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2716. WFIFOW(tsd->fd,8) = 100;
  2717. } else {
  2718. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2719. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2720. }
  2721. #else
  2722. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2723. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2724. #endif
  2725. WFIFOSET(tsd->fd,packet_len(cmd));
  2726. return 0;
  2727. }
  2728. /*==========================================
  2729. * Server tells all players that are allowed to view HP bars
  2730. * and are nearby 'sd' that 'sd' hp bar was updated.
  2731. *------------------------------------------*/
  2732. static int clif_hpmeter(struct map_session_data *sd)
  2733. {
  2734. nullpo_ret(sd);
  2735. 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);
  2736. return 0;
  2737. }
  2738. /// Notifies client of a character parameter change.
  2739. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2740. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2741. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2742. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2743. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2744. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2745. /// TODO: Extract individual packets.
  2746. /// FIXME: Packet lengths from packet_len(cmd)
  2747. void clif_updatestatus(struct map_session_data *sd,int type)
  2748. {
  2749. int fd,len=8;
  2750. nullpo_retv(sd);
  2751. fd=sd->fd;
  2752. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2753. return;
  2754. WFIFOHEAD(fd, 14);
  2755. WFIFOW(fd,0)=0xb0;
  2756. WFIFOW(fd,2)=type;
  2757. switch(type){
  2758. // 00b0
  2759. case SP_WEIGHT:
  2760. pc_updateweightstatus(sd);
  2761. WFIFOHEAD(fd,14);
  2762. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2763. WFIFOW(fd,2)=type;
  2764. WFIFOL(fd,4)=sd->weight;
  2765. break;
  2766. case SP_MAXWEIGHT:
  2767. WFIFOL(fd,4)=sd->max_weight;
  2768. break;
  2769. case SP_SPEED:
  2770. WFIFOL(fd,4)=sd->battle_status.speed;
  2771. break;
  2772. case SP_BASELEVEL:
  2773. WFIFOL(fd,4)=sd->status.base_level;
  2774. break;
  2775. case SP_JOBLEVEL:
  2776. WFIFOL(fd,4)=sd->status.job_level;
  2777. break;
  2778. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2779. WFIFOL(fd,4)=sd->status.karma;
  2780. break;
  2781. case SP_MANNER:
  2782. WFIFOL(fd,4)=sd->status.manner;
  2783. break;
  2784. case SP_STATUSPOINT:
  2785. WFIFOL(fd,4)=sd->status.status_point;
  2786. break;
  2787. case SP_SKILLPOINT:
  2788. WFIFOL(fd,4)=sd->status.skill_point;
  2789. break;
  2790. case SP_HIT:
  2791. WFIFOL(fd,4)=sd->battle_status.hit;
  2792. break;
  2793. case SP_FLEE1:
  2794. WFIFOL(fd,4)=sd->battle_status.flee;
  2795. break;
  2796. case SP_FLEE2:
  2797. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2798. break;
  2799. case SP_MAXHP:
  2800. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2801. break;
  2802. case SP_MAXSP:
  2803. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2804. break;
  2805. case SP_HP:
  2806. // On officials the HP never go below 1, even if you die [Lemongrass]
  2807. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2808. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2809. // TODO: Won't these overwrite the current packet?
  2810. if( map[sd->bl.m].hpmeter_visible )
  2811. clif_hpmeter(sd);
  2812. if( !battle_config.party_hp_mode && sd->status.party_id )
  2813. clif_party_hp(sd);
  2814. if( sd->bg_id )
  2815. clif_bg_hp(sd);
  2816. break;
  2817. case SP_SP:
  2818. WFIFOL(fd,4)=sd->battle_status.sp;
  2819. break;
  2820. case SP_ASPD:
  2821. WFIFOL(fd,4)=sd->battle_status.amotion;
  2822. break;
  2823. case SP_ATK1:
  2824. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2825. break;
  2826. case SP_DEF1:
  2827. WFIFOL(fd,4)=pc_leftside_def(sd);
  2828. break;
  2829. case SP_MDEF1:
  2830. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2831. break;
  2832. case SP_ATK2:
  2833. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2834. break;
  2835. case SP_DEF2:
  2836. WFIFOL(fd,4)=pc_rightside_def(sd);
  2837. break;
  2838. case SP_MDEF2: {
  2839. //negative check (in case you have something like Berserk active)
  2840. int mdef2 = pc_rightside_mdef(sd);
  2841. WFIFOL(fd,4)=
  2842. #ifndef RENEWAL
  2843. ( mdef2 < 0 ) ? 0 :
  2844. #endif
  2845. mdef2;
  2846. }
  2847. break;
  2848. case SP_CRITICAL:
  2849. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2850. break;
  2851. case SP_MATK1:
  2852. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2853. break;
  2854. case SP_MATK2:
  2855. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2856. break;
  2857. case SP_ZENY:
  2858. WFIFOW(fd,0)=0xb1;
  2859. WFIFOL(fd,4)=sd->status.zeny;
  2860. break;
  2861. case SP_BASEEXP:
  2862. WFIFOW(fd,0)=0xb1;
  2863. WFIFOL(fd,4)=sd->status.base_exp;
  2864. break;
  2865. case SP_JOBEXP:
  2866. WFIFOW(fd,0)=0xb1;
  2867. WFIFOL(fd,4)=sd->status.job_exp;
  2868. break;
  2869. case SP_NEXTBASEEXP:
  2870. WFIFOW(fd,0)=0xb1;
  2871. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2872. break;
  2873. case SP_NEXTJOBEXP:
  2874. WFIFOW(fd,0)=0xb1;
  2875. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2876. break;
  2877. /**
  2878. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2879. **/
  2880. case SP_USTR:
  2881. case SP_UAGI:
  2882. case SP_UVIT:
  2883. case SP_UINT:
  2884. case SP_UDEX:
  2885. case SP_ULUK:
  2886. WFIFOW(fd,0)=0xbe;
  2887. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2888. len=5;
  2889. break;
  2890. /**
  2891. * Tells the client how far it is allowed to attack (weapon range)
  2892. **/
  2893. case SP_ATTACKRANGE:
  2894. WFIFOW(fd,0)=0x13a;
  2895. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2896. len=4;
  2897. break;
  2898. case SP_STR:
  2899. WFIFOW(fd,0)=0x141;
  2900. WFIFOL(fd,2)=type;
  2901. WFIFOL(fd,6)=sd->status.str;
  2902. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2903. len=14;
  2904. break;
  2905. case SP_AGI:
  2906. WFIFOW(fd,0)=0x141;
  2907. WFIFOL(fd,2)=type;
  2908. WFIFOL(fd,6)=sd->status.agi;
  2909. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2910. len=14;
  2911. break;
  2912. case SP_VIT:
  2913. WFIFOW(fd,0)=0x141;
  2914. WFIFOL(fd,2)=type;
  2915. WFIFOL(fd,6)=sd->status.vit;
  2916. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2917. len=14;
  2918. break;
  2919. case SP_INT:
  2920. WFIFOW(fd,0)=0x141;
  2921. WFIFOL(fd,2)=type;
  2922. WFIFOL(fd,6)=sd->status.int_;
  2923. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2924. len=14;
  2925. break;
  2926. case SP_DEX:
  2927. WFIFOW(fd,0)=0x141;
  2928. WFIFOL(fd,2)=type;
  2929. WFIFOL(fd,6)=sd->status.dex;
  2930. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2931. len=14;
  2932. break;
  2933. case SP_LUK:
  2934. WFIFOW(fd,0)=0x141;
  2935. WFIFOL(fd,2)=type;
  2936. WFIFOL(fd,6)=sd->status.luk;
  2937. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2938. len=14;
  2939. break;
  2940. case SP_CARTINFO:
  2941. WFIFOW(fd,0)=0x121;
  2942. WFIFOW(fd,2)=sd->cart_num;
  2943. WFIFOW(fd,4)=MAX_CART;
  2944. WFIFOL(fd,6)=sd->cart_weight;
  2945. WFIFOL(fd,10)=sd->cart_weight_max;
  2946. len=14;
  2947. break;
  2948. default:
  2949. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2950. return;
  2951. }
  2952. WFIFOSET(fd,len);
  2953. }
  2954. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2955. /// 01ab <account id>.L <var id>.W <value>.L
  2956. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2957. {
  2958. unsigned char buf[12];
  2959. nullpo_retv(sd);
  2960. WBUFW(buf,0)=0x1ab;
  2961. WBUFL(buf,2)=sd->bl.id;
  2962. WBUFW(buf,6)=type;
  2963. switch(type)
  2964. {
  2965. case SP_MANNER:
  2966. WBUFL(buf,8)=val;
  2967. break;
  2968. default:
  2969. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2970. return;
  2971. }
  2972. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2973. }
  2974. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2975. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2976. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  2977. unsigned char buf[32];
  2978. #if PACKETVER < 4
  2979. const int cmd = 0xc3;
  2980. #else
  2981. const int cmd = 0x1d7;
  2982. #endif
  2983. WBUFW(buf,0) = cmd;
  2984. WBUFL(buf,2) = id;
  2985. WBUFB(buf,6) = type;
  2986. WBUFW(buf,7) = val;
  2987. #if PACKETVER >= 4
  2988. WBUFW(buf,9) = val2;
  2989. #endif
  2990. clif_send(buf,packet_len(cmd), bl, target);
  2991. }
  2992. /// Updates sprite/style properties of an object.
  2993. void clif_changelook(struct block_list *bl, int type, int val) {
  2994. struct map_session_data* sd;
  2995. struct status_change* sc;
  2996. struct view_data* vd;
  2997. enum send_target target = AREA;
  2998. int val2 = 0;
  2999. nullpo_retv(bl);
  3000. sd = BL_CAST(BL_PC, bl);
  3001. sc = status_get_sc(bl);
  3002. vd = status_get_viewdata(bl);
  3003. if( vd ) //temp hack to let Warp Portal change appearance
  3004. switch(type) {
  3005. case LOOK_WEAPON:
  3006. if (sd) {
  3007. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3008. val = vd->weapon;
  3009. }
  3010. else
  3011. vd->weapon = val;
  3012. break;
  3013. case LOOK_SHIELD:
  3014. if (sd) {
  3015. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3016. val = vd->shield;
  3017. }
  3018. else
  3019. vd->shield = val;
  3020. break;
  3021. case LOOK_BASE:
  3022. if (!sd)
  3023. break;
  3024. if ( val == INVISIBLE_CLASS )
  3025. return;
  3026. if (sd->sc.option&OPTION_COSTUME)
  3027. vd->weapon = vd->shield = 0;
  3028. if (!vd->cloth_color)
  3029. break;
  3030. if (sd) {
  3031. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3032. vd->cloth_color = 0;
  3033. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3034. vd->cloth_color = 0;
  3035. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3036. vd->cloth_color = 0;
  3037. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3038. vd->cloth_color = 0;
  3039. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3040. vd->cloth_color = 0;
  3041. if (vd->body_style && (
  3042. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3043. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3044. sd->sc.option&OPTION_OKTOBERFEST))
  3045. vd->body_style = 0;
  3046. }
  3047. break;
  3048. case LOOK_HAIR:
  3049. vd->hair_style = val;
  3050. break;
  3051. case LOOK_HEAD_BOTTOM:
  3052. vd->head_bottom = val;
  3053. break;
  3054. case LOOK_HEAD_TOP:
  3055. vd->head_top = val;
  3056. break;
  3057. case LOOK_HEAD_MID:
  3058. vd->head_mid = val;
  3059. break;
  3060. case LOOK_HAIR_COLOR:
  3061. vd->hair_color = val;
  3062. break;
  3063. case LOOK_CLOTHES_COLOR:
  3064. if (val && sd) {
  3065. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3066. val = 0;
  3067. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3068. val = 0;
  3069. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3070. val = 0;
  3071. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3072. val = 0;
  3073. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3074. val = 0;
  3075. }
  3076. vd->cloth_color = val;
  3077. break;
  3078. case LOOK_SHOES:
  3079. #if PACKETVER > 3
  3080. if (sd) {
  3081. int n;
  3082. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3083. if(sd->inventory_data[n]->view_id > 0)
  3084. val = sd->inventory_data[n]->view_id;
  3085. else
  3086. val = sd->status.inventory[n].nameid;
  3087. } else
  3088. val = 0;
  3089. }
  3090. #endif
  3091. //Shoes? No packet uses this....
  3092. break;
  3093. case LOOK_BODY:
  3094. // unknown purpose
  3095. break;
  3096. case LOOK_ROBE:
  3097. #if PACKETVER < 20110111
  3098. return;
  3099. #else
  3100. vd->robe = val;
  3101. #endif
  3102. break;
  3103. case LOOK_BODY2:
  3104. #if PACKETVER < 20150513
  3105. return;
  3106. #else
  3107. if (val && (
  3108. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3109. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3110. sd->sc.option&OPTION_OKTOBERFEST))
  3111. val = 0;
  3112. vd->body_style = val;
  3113. #endif
  3114. break;
  3115. }
  3116. // prevent leaking the presence of GM-hidden objects
  3117. if( sc && sc->option&OPTION_INVISIBLE )
  3118. target = SELF;
  3119. #if PACKETVER < 4
  3120. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3121. #else
  3122. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3123. nullpo_retv(vd);
  3124. type = LOOK_WEAPON;
  3125. val = vd->weapon;
  3126. val2 = vd->shield;
  3127. }
  3128. if( disguised(bl) ) {
  3129. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3130. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3131. } else
  3132. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3133. #endif
  3134. }
  3135. //Sends a change-base-look packet required for traps as they are triggered.
  3136. void clif_changetraplook(struct block_list *bl,int val) {
  3137. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3138. }
  3139. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3140. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3141. clif_sprite_change(bl, id, type, val, 0, target);
  3142. }
  3143. /// Character status (ZC_STATUS).
  3144. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3145. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3146. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3147. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3148. void clif_initialstatus(struct map_session_data *sd) {
  3149. int fd, mdef2;
  3150. unsigned char *buf;
  3151. nullpo_retv(sd);
  3152. fd=sd->fd;
  3153. WFIFOHEAD(fd, packet_len(0xbd));
  3154. buf = WFIFOP(fd,0);
  3155. WBUFW(buf,0) = 0xbd;
  3156. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3157. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3158. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3159. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3160. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3161. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3162. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3163. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3164. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3165. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3166. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3167. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3168. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3169. WBUFW(buf,16) = pc_leftside_atk(sd);
  3170. WBUFW(buf,18) = pc_rightside_atk(sd);
  3171. WBUFW(buf,20) = pc_rightside_matk(sd);
  3172. WBUFW(buf,22) = pc_leftside_matk(sd);
  3173. WBUFW(buf,24) = pc_leftside_def(sd);
  3174. WBUFW(buf,26) = pc_rightside_def(sd);
  3175. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3176. mdef2 = pc_rightside_mdef(sd);
  3177. WBUFW(buf,30) =
  3178. #ifndef RENEWAL
  3179. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3180. #endif
  3181. mdef2;
  3182. WBUFW(buf,32) = sd->battle_status.hit;
  3183. WBUFW(buf,34) = sd->battle_status.flee;
  3184. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3185. WBUFW(buf,38) = sd->battle_status.cri/10;
  3186. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3187. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3188. WFIFOSET(fd, packet_len(0xbd));
  3189. clif_updatestatus(sd, SP_STR);
  3190. clif_updatestatus(sd, SP_AGI);
  3191. clif_updatestatus(sd, SP_VIT);
  3192. clif_updatestatus(sd, SP_INT);
  3193. clif_updatestatus(sd, SP_DEX);
  3194. clif_updatestatus(sd, SP_LUK);
  3195. clif_updatestatus(sd, SP_ATTACKRANGE);
  3196. clif_updatestatus(sd, SP_ASPD);
  3197. }
  3198. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3199. /// 013c <index>.W
  3200. void clif_arrowequip(struct map_session_data *sd,int val) {
  3201. int fd;
  3202. nullpo_retv(sd);
  3203. #if PACKETVER >= 20121128
  3204. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3205. #endif
  3206. fd=sd->fd;
  3207. WFIFOHEAD(fd, packet_len(0x013c));
  3208. WFIFOW(fd,0) = 0x013c;
  3209. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3210. WFIFOSET(fd, packet_len(0x013c));
  3211. }
  3212. /// Ammunition action message (ZC_ACTION_FAILURE).
  3213. /// 013b <type>.W
  3214. /// type:
  3215. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3216. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3217. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3218. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3219. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3220. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3221. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3222. int fd;
  3223. nullpo_retv(sd);
  3224. fd=sd->fd;
  3225. WFIFOHEAD(fd, packet_len(0x013b));
  3226. WFIFOW(fd,0) = 0x013b;
  3227. WFIFOW(fd,2) = type;
  3228. WFIFOSET(fd, packet_len(0x013b));
  3229. }
  3230. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3231. /// 01ad <packet len>.W { <name id>.W }*
  3232. void clif_arrow_create_list(struct map_session_data *sd)
  3233. {
  3234. int i, c;
  3235. int fd;
  3236. nullpo_retv(sd);
  3237. fd = sd->fd;
  3238. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3239. WFIFOW(fd,0) = 0x1ad;
  3240. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3241. short j, nameid = skill_arrow_db[i].nameid;
  3242. if (nameid > 0 && itemdb_exists(nameid) &&
  3243. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3244. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3245. {
  3246. if ((j = itemdb_viewid(nameid)) > 0)
  3247. WFIFOW(fd,c*2+4) = j;
  3248. else
  3249. WFIFOW(fd,c*2+4) = nameid;
  3250. c++;
  3251. }
  3252. }
  3253. WFIFOW(fd,2) = c*2+4;
  3254. WFIFOSET(fd, WFIFOW(fd,2));
  3255. if (c > 0) {
  3256. sd->menuskill_id = AC_MAKINGARROW;
  3257. sd->menuskill_val = c;
  3258. }
  3259. }
  3260. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3261. /// 00bc <status id>.W <result>.B <value>.B
  3262. /// status id:
  3263. /// SP_STR ~ SP_LUK
  3264. /// result:
  3265. /// 0 = failure
  3266. /// 1 = success
  3267. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3268. int fd;
  3269. nullpo_retv(sd);
  3270. fd=sd->fd;
  3271. WFIFOHEAD(fd, packet_len(0xbc));
  3272. WFIFOW(fd,0) = 0xbc;
  3273. WFIFOW(fd,2) = type;
  3274. WFIFOB(fd,4) = ok;
  3275. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3276. WFIFOSET(fd, packet_len(0xbc));
  3277. }
  3278. /// Notifies the client about the result of a request to equip an item.
  3279. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3280. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3281. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3282. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3283. /// @ok: //inversed forv2 v5
  3284. /// 0 = failure
  3285. /// 1 = success
  3286. /// 2 = failure due to low level
  3287. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3288. {
  3289. int fd = 0, cmd = 0, look = 0;
  3290. struct s_packet_db *info = NULL;
  3291. nullpo_retv(sd);
  3292. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3293. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3294. return;
  3295. fd = sd->fd;
  3296. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3297. look = sd->inventory_data[n]->look;
  3298. WFIFOHEAD(fd, info->len);
  3299. WFIFOW(fd, 0) = cmd;
  3300. WFIFOW(fd, info->pos[0]) = n+2;
  3301. switch (cmd) {
  3302. case 0xaa:
  3303. WFIFOW(fd, info->pos[1]) = pos;
  3304. if (sd->packet_ver < date2version(20100629))
  3305. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3306. else {
  3307. WFIFOL(fd, info->pos[2]) = look;
  3308. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3309. }
  3310. break;
  3311. case 0x8d0:
  3312. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3313. flag = 1;
  3314. case 0x999:
  3315. if (cmd == 0x999)
  3316. WFIFOL(fd, info->pos[1]) = pos;
  3317. else
  3318. WFIFOW(fd, info->pos[1]) = pos;
  3319. WFIFOL(fd, info->pos[2]) = look;
  3320. WFIFOW(fd, info->pos[3]) = flag;
  3321. break;
  3322. }
  3323. WFIFOSET(fd, info->len);
  3324. }
  3325. /// Notifies the client about the result of a request to take off an item.
  3326. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3327. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3328. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3329. /// @ok : //inversed for v2 v5
  3330. /// 0 = failure
  3331. /// 1 = success
  3332. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3333. {
  3334. int fd, header, offs = 0;
  3335. #if PACKETVER >= 20130000
  3336. header = 0x99a;
  3337. ok = ok ? 0 : 1;
  3338. #elif PACKETVER >= 20110824
  3339. header = 0x8d1;
  3340. ok = ok ? 0 : 1;
  3341. #else
  3342. header = 0xac;
  3343. #endif
  3344. nullpo_retv(sd);
  3345. fd=sd->fd;
  3346. WFIFOHEAD(fd, packet_len(header));
  3347. WFIFOW(fd,offs+0) = header;
  3348. WFIFOW(fd,offs+2) = n+2;
  3349. #if PACKETVER >= 20130000
  3350. WFIFOL(fd,offs+4) = pos;
  3351. offs += 2;
  3352. #else
  3353. WFIFOW(fd,offs+4) = pos;
  3354. #endif
  3355. WFIFOB(fd,offs+6) = ok;
  3356. WFIFOSET(fd, packet_len(header));
  3357. }
  3358. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3359. /// 019b <id>.L <effect id>.L
  3360. /// effect id:
  3361. /// 0 = base level up
  3362. /// 1 = job level up
  3363. /// 2 = refine failure
  3364. /// 3 = refine success
  3365. /// 4 = game over
  3366. /// 5 = pharmacy success
  3367. /// 6 = pharmacy failure
  3368. /// 7 = base level up (super novice)
  3369. /// 8 = job level up (super novice)
  3370. /// 9 = base level up (taekwon)
  3371. void clif_misceffect(struct block_list* bl,int type)
  3372. {
  3373. unsigned char buf[32];
  3374. nullpo_retv(bl);
  3375. WBUFW(buf,0) = 0x19b;
  3376. WBUFL(buf,2) = bl->id;
  3377. WBUFL(buf,6) = type;
  3378. clif_send(buf,packet_len(0x19b),bl,AREA);
  3379. }
  3380. /// Notifies clients in the area of a state change.
  3381. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3382. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3383. void clif_changeoption(struct block_list* bl)
  3384. {
  3385. unsigned char buf[32];
  3386. struct status_change *sc;
  3387. struct map_session_data* sd;
  3388. nullpo_retv(bl);
  3389. sc = status_get_sc(bl);
  3390. if (!sc) return; //How can an option change if there's no sc?
  3391. sd = BL_CAST(BL_PC, bl);
  3392. #if PACKETVER >= 7
  3393. WBUFW(buf,0) = 0x229;
  3394. WBUFL(buf,2) = bl->id;
  3395. WBUFW(buf,6) = sc->opt1;
  3396. WBUFW(buf,8) = sc->opt2;
  3397. WBUFL(buf,10) = sc->option;
  3398. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3399. if(disguised(bl)) {
  3400. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3401. WBUFL(buf,2) = -bl->id;
  3402. clif_send(buf,packet_len(0x229),bl,SELF);
  3403. WBUFL(buf,2) = bl->id;
  3404. WBUFL(buf,10) = OPTION_INVISIBLE;
  3405. clif_send(buf,packet_len(0x229),bl,SELF);
  3406. } else
  3407. clif_send(buf,packet_len(0x229),bl,AREA);
  3408. #else
  3409. WBUFW(buf,0) = 0x119;
  3410. WBUFL(buf,2) = bl->id;
  3411. WBUFW(buf,6) = sc->opt1;
  3412. WBUFW(buf,8) = sc->opt2;
  3413. WBUFW(buf,10) = sc->option;
  3414. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3415. if(disguised(bl)) {
  3416. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3417. WBUFL(buf,2) = -bl->id;
  3418. clif_send(buf,packet_len(0x119),bl,SELF);
  3419. WBUFL(buf,2) = bl->id;
  3420. WBUFW(buf,10) = OPTION_INVISIBLE;
  3421. clif_send(buf,packet_len(0x119),bl,SELF);
  3422. } else
  3423. clif_send(buf,packet_len(0x119),bl,AREA);
  3424. #endif
  3425. }
  3426. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3427. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3428. void clif_changeoption2(struct block_list* bl)
  3429. {
  3430. unsigned char buf[20];
  3431. struct status_change *sc;
  3432. sc = status_get_sc(bl);
  3433. if (!sc) return; //How can an option change if there's no sc?
  3434. WBUFW(buf,0) = 0x28a;
  3435. WBUFL(buf,2) = bl->id;
  3436. WBUFL(buf,6) = sc->option;
  3437. WBUFL(buf,10) = clif_setlevel(bl);
  3438. WBUFL(buf,14) = sc->opt3;
  3439. if(disguised(bl)) {
  3440. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3441. WBUFL(buf,2) = -bl->id;
  3442. clif_send(buf,packet_len(0x28a),bl,SELF);
  3443. WBUFL(buf,2) = bl->id;
  3444. WBUFL(buf,6) = OPTION_INVISIBLE;
  3445. clif_send(buf,packet_len(0x28a),bl,SELF);
  3446. } else
  3447. clif_send(buf,packet_len(0x28a),bl,AREA);
  3448. }
  3449. /// Notifies the client about the result of an item use request.
  3450. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3451. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3452. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3453. {
  3454. nullpo_retv(sd);
  3455. if(!ok) {
  3456. int fd=sd->fd;
  3457. WFIFOHEAD(fd,packet_len(0xa8));
  3458. WFIFOW(fd,0)=0xa8;
  3459. WFIFOW(fd,2)=index+2;
  3460. WFIFOW(fd,4)=amount;
  3461. WFIFOB(fd,6)=ok;
  3462. WFIFOSET(fd,packet_len(0xa8));
  3463. }
  3464. else {
  3465. #if PACKETVER < 3
  3466. int fd=sd->fd;
  3467. WFIFOHEAD(fd,packet_len(0xa8));
  3468. WFIFOW(fd,0)=0xa8;
  3469. WFIFOW(fd,2)=index+2;
  3470. WFIFOW(fd,4)=amount;
  3471. WFIFOB(fd,6)=ok;
  3472. WFIFOSET(fd,packet_len(0xa8));
  3473. #else
  3474. unsigned char buf[32];
  3475. WBUFW(buf,0)=0x1c8;
  3476. WBUFW(buf,2)=index+2;
  3477. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3478. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3479. else
  3480. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3481. WBUFL(buf,6)=sd->bl.id;
  3482. WBUFW(buf,10)=amount;
  3483. WBUFB(buf,12)=ok;
  3484. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3485. #endif
  3486. }
  3487. }
  3488. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3489. /// 00d6 <flag>.B
  3490. /// flag:
  3491. /// 0 = Room has been successfully created (opens chat room)
  3492. /// 1 = Room limit exceeded
  3493. /// 2 = Same room already exists
  3494. void clif_createchat(struct map_session_data* sd, int flag)
  3495. {
  3496. int fd;
  3497. nullpo_retv(sd);
  3498. fd = sd->fd;
  3499. WFIFOHEAD(fd,packet_len(0xd6));
  3500. WFIFOW(fd,0) = 0xd6;
  3501. WFIFOB(fd,2) = flag;
  3502. WFIFOSET(fd,packet_len(0xd6));
  3503. }
  3504. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3505. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3506. /// type:
  3507. /// 0 = private (password protected)
  3508. /// 1 = public
  3509. /// 2 = arena (npc waiting room)
  3510. /// 3 = PK zone (non-clickable)
  3511. void clif_dispchat(struct chat_data* cd, int fd)
  3512. {
  3513. unsigned char buf[128];
  3514. uint8 type;
  3515. if( cd == NULL || cd->owner == NULL )
  3516. return;
  3517. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3518. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3519. : 1;
  3520. WBUFW(buf, 0) = 0xd7;
  3521. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3522. WBUFL(buf, 4) = cd->owner->id;
  3523. WBUFL(buf, 8) = cd->bl.id;
  3524. WBUFW(buf,12) = cd->limit;
  3525. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3526. WBUFB(buf,16) = type;
  3527. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3528. if( fd ) {
  3529. WFIFOHEAD(fd,WBUFW(buf,2));
  3530. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3531. WFIFOSET(fd,WBUFW(buf,2));
  3532. } else {
  3533. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3534. }
  3535. }
  3536. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3537. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3538. /// type:
  3539. /// 0 = private (password protected)
  3540. /// 1 = public
  3541. /// 2 = arena (npc waiting room)
  3542. /// 3 = PK zone (non-clickable)
  3543. void clif_changechatstatus(struct chat_data* cd)
  3544. {
  3545. unsigned char buf[128];
  3546. uint8 type;
  3547. if( cd == NULL || cd->usersd[0] == NULL )
  3548. return;
  3549. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3550. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3551. : 1;
  3552. WBUFW(buf, 0) = 0xdf;
  3553. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3554. WBUFL(buf, 4) = cd->owner->id;
  3555. WBUFL(buf, 8) = cd->bl.id;
  3556. WBUFW(buf,12) = cd->limit;
  3557. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3558. WBUFB(buf,16) = type;
  3559. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3560. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3561. }
  3562. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3563. /// 00d8 <chat id>.L
  3564. void clif_clearchat(struct chat_data *cd,int fd)
  3565. {
  3566. unsigned char buf[32];
  3567. nullpo_retv(cd);
  3568. WBUFW(buf,0) = 0xd8;
  3569. WBUFL(buf,2) = cd->bl.id;
  3570. if( fd ) {
  3571. WFIFOHEAD(fd,packet_len(0xd8));
  3572. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3573. WFIFOSET(fd,packet_len(0xd8));
  3574. } else {
  3575. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3576. }
  3577. }
  3578. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3579. /// 00da <result>.B
  3580. /// result:
  3581. /// 0 = room full
  3582. /// 1 = wrong password
  3583. /// 2 = kicked
  3584. /// 3 = success (no message)
  3585. /// 4 = no enough zeny
  3586. /// 5 = too low level
  3587. /// 6 = too high level
  3588. /// 7 = unsuitable job class
  3589. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3590. {
  3591. int fd;
  3592. nullpo_retv(sd);
  3593. fd = sd->fd;
  3594. WFIFOHEAD(fd,packet_len(0xda));
  3595. WFIFOW(fd,0) = 0xda;
  3596. WFIFOB(fd,2) = flag;
  3597. WFIFOSET(fd,packet_len(0xda));
  3598. }
  3599. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3600. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3601. /// role:
  3602. /// 0 = owner (menu)
  3603. /// 1 = normal
  3604. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3605. {
  3606. int fd;
  3607. int i,t;
  3608. nullpo_retv(sd);
  3609. nullpo_retv(cd);
  3610. fd = sd->fd;
  3611. if (!session_isActive(fd))
  3612. return;
  3613. t = (int)(cd->owner->type == BL_NPC);
  3614. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3615. WFIFOW(fd, 0) = 0xdb;
  3616. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3617. WFIFOL(fd, 4) = cd->bl.id;
  3618. if(cd->owner->type == BL_NPC){
  3619. WFIFOL(fd, 30) = 1;
  3620. WFIFOL(fd, 8) = 0;
  3621. safestrncpy((char*)WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3622. for (i = 0; i < cd->users; i++) {
  3623. WFIFOL(fd, 8+(i+1)*28) = 1;
  3624. safestrncpy((char*)WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3625. }
  3626. }else{
  3627. for (i = 0; i < cd->users; i++) {
  3628. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3629. safestrncpy((char*)WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3630. }
  3631. }
  3632. WFIFOSET(fd, WFIFOW(fd, 2));
  3633. }
  3634. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3635. /// 00dc <users>.W <name>.24B
  3636. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3637. {
  3638. unsigned char buf[29];
  3639. nullpo_retv(sd);
  3640. nullpo_retv(cd);
  3641. WBUFW(buf, 0) = 0xdc;
  3642. WBUFW(buf, 2) = cd->users;
  3643. safestrncpy((char*)WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3644. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3645. }
  3646. /// Announce the new owner (ZC_ROLE_CHANGE).
  3647. /// 00e1 <role>.L <nick>.24B
  3648. /// role:
  3649. /// 0 = owner (menu)
  3650. /// 1 = normal
  3651. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3652. {
  3653. unsigned char buf[64];
  3654. nullpo_retv(sd);
  3655. nullpo_retv(cd);
  3656. WBUFW(buf, 0) = 0xe1;
  3657. WBUFL(buf, 2) = 1;
  3658. safestrncpy((char*)WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3659. WBUFW(buf,30) = 0xe1;
  3660. WBUFL(buf,32) = 0;
  3661. safestrncpy((char*)WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3662. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3663. }
  3664. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3665. /// 00dd <users>.W <nick>.24B <flag>.B
  3666. /// flag:
  3667. /// 0 = left
  3668. /// 1 = kicked
  3669. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3670. {
  3671. unsigned char buf[32];
  3672. nullpo_retv(sd);
  3673. nullpo_retv(cd);
  3674. WBUFW(buf, 0) = 0xdd;
  3675. WBUFW(buf, 2) = cd->users-1;
  3676. safestrncpy((char*)WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3677. WBUFB(buf,28) = flag;
  3678. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3679. }
  3680. /// Opens a trade request window from char 'name'.
  3681. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3682. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3683. void clif_traderequest(struct map_session_data* sd, const char* name)
  3684. {
  3685. int fd = sd->fd;
  3686. #if PACKETVER < 6
  3687. WFIFOHEAD(fd,packet_len(0xe5));
  3688. WFIFOW(fd,0) = 0xe5;
  3689. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3690. WFIFOSET(fd,packet_len(0xe5));
  3691. #else
  3692. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3693. if( !tsd ) return;
  3694. WFIFOHEAD(fd,packet_len(0x1f4));
  3695. WFIFOW(fd,0) = 0x1f4;
  3696. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3697. WFIFOL(fd,26) = tsd->status.char_id;
  3698. WFIFOW(fd,30) = tsd->status.base_level;
  3699. WFIFOSET(fd,packet_len(0x1f4));
  3700. #endif
  3701. }
  3702. /// Reply to a trade-request.
  3703. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3704. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3705. /// result:
  3706. /// 0 = Char is too far
  3707. /// 1 = Character does not exist
  3708. /// 2 = Trade failed
  3709. /// 3 = Accept
  3710. /// 4 = Cancel
  3711. /// 5 = Busy
  3712. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3713. {
  3714. int fd = sd->fd;
  3715. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3716. if( PACKETVER < 6 || !tsd ) {
  3717. WFIFOHEAD(fd,packet_len(0xe7));
  3718. WFIFOW(fd,0) = 0xe7;
  3719. WFIFOB(fd,2) = type;
  3720. WFIFOSET(fd,packet_len(0xe7));
  3721. } else {
  3722. WFIFOHEAD(fd,packet_len(0x1f5));
  3723. WFIFOW(fd,0) = 0x1f5;
  3724. WFIFOB(fd,2) = type;
  3725. WFIFOL(fd,3) = tsd->status.char_id;
  3726. WFIFOW(fd,7) = tsd->status.base_level;
  3727. WFIFOSET(fd,packet_len(0x1f5));
  3728. }
  3729. }
  3730. /// Notifies the client about an item from other player in current trade.
  3731. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3732. /// 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)
  3733. /// 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)
  3734. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3735. {
  3736. int fd;
  3737. unsigned char *buf;
  3738. #if PACKETVER < 20100223
  3739. const int cmd = 0xe9;
  3740. #elif PACKETVER < 20150226
  3741. const int cmd = 0x80f;
  3742. #else
  3743. const int cmd = 0xa09;
  3744. #endif
  3745. nullpo_retv(sd);
  3746. nullpo_retv(tsd);
  3747. fd = tsd->fd;
  3748. buf = WFIFOP(fd,0);
  3749. WFIFOHEAD(fd,packet_len(cmd));
  3750. WBUFW(buf,0) = cmd;
  3751. if( index == 0 )
  3752. {
  3753. #if PACKETVER < 20100223
  3754. WBUFL(buf,2) = amount; //amount
  3755. WBUFW(buf,6) = 0; // type id
  3756. #else
  3757. WBUFW(buf,2) = 0; // type id
  3758. WBUFB(buf,4) = 0; // item type
  3759. WBUFL(buf,5) = amount; // amount
  3760. buf = WBUFP(buf,1); //Advance 1B
  3761. #endif
  3762. WBUFB(buf,8) = 0; //identify flag
  3763. WBUFB(buf,9) = 0; // attribute
  3764. WBUFB(buf,10)= 0; //refine
  3765. WBUFW(buf,11)= 0; //card (4w)
  3766. WBUFW(buf,13)= 0; //card (4w)
  3767. WBUFW(buf,15)= 0; //card (4w)
  3768. WBUFW(buf,17)= 0; //card (4w)
  3769. #if PACKETVER >= 20150226
  3770. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3771. #endif
  3772. }
  3773. else
  3774. {
  3775. index -= 2; //index fix
  3776. #if PACKETVER < 20100223
  3777. WBUFL(buf,2) = amount; //amount
  3778. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3779. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3780. else
  3781. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3782. #else
  3783. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3784. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3785. else
  3786. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3787. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3788. WBUFL(buf,5) = amount; // amount
  3789. buf = WBUFP(buf,1); //Advance 1B
  3790. #endif
  3791. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3792. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3793. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3794. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3795. #if PACKETVER >= 20150226
  3796. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3797. #endif
  3798. }
  3799. WFIFOSET(fd,packet_len(cmd));
  3800. }
  3801. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3802. /// 00ea <index>.W <result>.B
  3803. /// result:
  3804. /// 0 = success
  3805. /// 1 = overweight
  3806. /// 2 = trade canceled
  3807. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3808. {
  3809. int fd;
  3810. nullpo_retv(sd);
  3811. fd = sd->fd;
  3812. WFIFOHEAD(fd,packet_len(0xea));
  3813. WFIFOW(fd,0) = 0xea;
  3814. WFIFOW(fd,2) = index;
  3815. WFIFOB(fd,4) = fail;
  3816. WFIFOSET(fd,packet_len(0xea));
  3817. }
  3818. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3819. /// 00ec <who>.B
  3820. /// who:
  3821. /// 0 = self
  3822. /// 1 = other player
  3823. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3824. {
  3825. int fd;
  3826. nullpo_retv(sd);
  3827. fd = sd->fd;
  3828. WFIFOHEAD(fd,packet_len(0xec));
  3829. WFIFOW(fd,0) = 0xec;
  3830. WFIFOB(fd,2) = fail;
  3831. WFIFOSET(fd,packet_len(0xec));
  3832. }
  3833. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3834. /// 00ee
  3835. void clif_tradecancelled(struct map_session_data* sd)
  3836. {
  3837. int fd;
  3838. nullpo_retv(sd);
  3839. fd = sd->fd;
  3840. WFIFOHEAD(fd,packet_len(0xee));
  3841. WFIFOW(fd,0) = 0xee;
  3842. WFIFOSET(fd,packet_len(0xee));
  3843. }
  3844. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3845. /// 00f0 <result>.B
  3846. /// result:
  3847. /// 0 = success
  3848. /// 1 = failure
  3849. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3850. {
  3851. int fd;
  3852. nullpo_retv(sd);
  3853. fd = sd->fd;
  3854. WFIFOHEAD(fd,packet_len(0xf0));
  3855. WFIFOW(fd,0) = 0xf0;
  3856. WFIFOB(fd,2) = fail;
  3857. WFIFOSET(fd,packet_len(0xf0));
  3858. }
  3859. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3860. /// 00f1
  3861. /// NOTE: Unknown purpose. Items are not removed until the window is
  3862. /// refreshed (ex. by putting another item in there).
  3863. void clif_tradeundo(struct map_session_data* sd)
  3864. {
  3865. int fd = sd->fd;
  3866. WFIFOHEAD(fd,packet_len(0xf1));
  3867. WFIFOW(fd,0) = 0xf1;
  3868. WFIFOSET(fd,packet_len(0xf1));
  3869. }
  3870. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3871. /// 00f2 <current count>.W <max count>.W
  3872. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3873. {
  3874. int fd;
  3875. nullpo_retv(sd);
  3876. fd=sd->fd;
  3877. WFIFOHEAD(fd,packet_len(0xf2));
  3878. WFIFOW(fd,0) = 0xf2;
  3879. WFIFOW(fd,2) = amount;
  3880. WFIFOW(fd,4) = max_amount;
  3881. WFIFOSET(fd,packet_len(0xf2));
  3882. }
  3883. /// Notifies the client of an item being added to the storage.
  3884. /// 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)
  3885. /// 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)
  3886. /// 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)
  3887. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3888. {
  3889. #if PACKETVER < 5
  3890. const int cmd = 0xf4;
  3891. #elif PACKETVER < 20150226
  3892. const int cmd = 0x1c4;
  3893. #else
  3894. const int cmd = 0xa0a;
  3895. #endif
  3896. int view,fd;
  3897. int offset = 0;
  3898. nullpo_retv(sd);
  3899. nullpo_retv(i);
  3900. fd=sd->fd;
  3901. view = itemdb_viewid(i->nameid);
  3902. WFIFOHEAD(fd,packet_len(cmd));
  3903. WFIFOW(fd, 0) = cmd; // Storage item added
  3904. WFIFOW(fd, 2) = index+1; // index
  3905. WFIFOL(fd, 4) = amount; // amount
  3906. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3907. #if PACKETVER >= 5
  3908. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3909. offset += 1;
  3910. #endif
  3911. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3912. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3913. WFIFOB(fd,12+offset) = i->refine; //refine
  3914. clif_addcards(WFIFOP(fd,13+offset), i);
  3915. #if PACKETVER >= 20150226
  3916. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3917. #endif
  3918. WFIFOSET(fd,packet_len(cmd));
  3919. }
  3920. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3921. /// 00f6 <index>.W <amount>.L
  3922. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3923. {
  3924. int fd;
  3925. nullpo_retv(sd);
  3926. fd=sd->fd;
  3927. WFIFOHEAD(fd,packet_len(0xf6));
  3928. WFIFOW(fd,0)=0xf6; // Storage item removed
  3929. WFIFOW(fd,2)=index+1;
  3930. WFIFOL(fd,4)=amount;
  3931. WFIFOSET(fd,packet_len(0xf6));
  3932. }
  3933. /// Closes storage (ZC_CLOSE_STORE).
  3934. /// 00f8
  3935. void clif_storageclose(struct map_session_data* sd)
  3936. {
  3937. int fd;
  3938. nullpo_retv(sd);
  3939. fd=sd->fd;
  3940. WFIFOHEAD(fd,packet_len(0xf8));
  3941. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3942. WFIFOSET(fd,packet_len(0xf8));
  3943. }
  3944. /*==========================================
  3945. * Server tells 'sd' player client the abouts of 'dstsd' player
  3946. *------------------------------------------*/
  3947. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3948. {
  3949. struct block_list *d_bl;
  3950. int i;
  3951. if( dstsd->chatID ) {
  3952. struct chat_data *cd = NULL;
  3953. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3954. clif_dispchat(cd,sd->fd);
  3955. } else if( dstsd->state.vending )
  3956. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3957. else if( dstsd->state.buyingstore )
  3958. clif_buyingstore_entry_single(sd, dstsd);
  3959. if(dstsd->spiritball > 0)
  3960. clif_spiritball_single(sd->fd, dstsd);
  3961. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3962. clif_spiritcharm_single(sd->fd, dstsd);
  3963. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3964. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3965. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3966. )
  3967. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3968. // display link (sd - dstsd) to sd
  3969. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3970. if( i < MAX_DEVOTION )
  3971. clif_devotion(&sd->bl, sd);
  3972. // display links (dstsd - devotees) to sd
  3973. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3974. if( i < MAX_DEVOTION )
  3975. clif_devotion(&dstsd->bl, sd);
  3976. // display link (dstsd - crusader) to sd
  3977. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3978. clif_devotion(d_bl, sd);
  3979. }
  3980. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3981. {
  3982. uint8 buf[128];
  3983. struct unit_data *ud;
  3984. struct view_data *vd;
  3985. int len;
  3986. vd = status_get_viewdata(bl);
  3987. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3988. return;
  3989. /**
  3990. * Hide NPC from maya purple card.
  3991. **/
  3992. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3993. return;
  3994. ud = unit_bl2ud(bl);
  3995. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3996. clif_send(buf,len,&sd->bl,SELF);
  3997. if (vd->cloth_color)
  3998. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3999. if (vd->body_style)
  4000. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4001. switch (bl->type)
  4002. {
  4003. case BL_PC:
  4004. {
  4005. TBL_PC* tsd = (TBL_PC*)bl;
  4006. clif_getareachar_pc(sd, tsd);
  4007. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4008. clif_specialeffect_single(bl,423,sd->fd);
  4009. else if(tsd->state.size==SZ_MEDIUM)
  4010. clif_specialeffect_single(bl,421,sd->fd);
  4011. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4012. clif_sendbgemblem_single(sd->fd,tsd);
  4013. if ( tsd->status.robe )
  4014. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4015. clif_efst_status_change_sub(sd, bl, SELF);
  4016. clif_hat_effects(sd,bl,SELF);
  4017. }
  4018. break;
  4019. case BL_MER: // Devotion Effects
  4020. if( ((TBL_MER*)bl)->devotion_flag )
  4021. clif_devotion(bl, sd);
  4022. break;
  4023. case BL_NPC:
  4024. {
  4025. TBL_NPC* nd = (TBL_NPC*)bl;
  4026. if( nd->chat_id )
  4027. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4028. if( nd->size == SZ_BIG )
  4029. clif_specialeffect_single(bl,423,sd->fd);
  4030. else if( nd->size == SZ_MEDIUM )
  4031. clif_specialeffect_single(bl,421,sd->fd);
  4032. }
  4033. break;
  4034. case BL_MOB:
  4035. {
  4036. TBL_MOB* md = (TBL_MOB*)bl;
  4037. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4038. clif_specialeffect_single(bl,423,sd->fd);
  4039. else if(md->special_state.size==SZ_MEDIUM)
  4040. clif_specialeffect_single(bl,421,sd->fd);
  4041. #if PACKETVER >= 20120404
  4042. if( battle_config.monster_hp_bars_info){
  4043. int i;
  4044. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4045. if( md->dmglog[i].id == sd->status.char_id )
  4046. clif_monster_hp_bar(md, sd->fd);
  4047. }
  4048. #endif
  4049. }
  4050. break;
  4051. case BL_PET:
  4052. if (vd->head_bottom)
  4053. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4054. break;
  4055. }
  4056. }
  4057. //Modifies the type of damage according to status changes [Skotlex]
  4058. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4059. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4060. {
  4061. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4062. }
  4063. /*==========================================
  4064. * Estimates walk delay based on the damage criteria. [Skotlex]
  4065. *------------------------------------------*/
  4066. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4067. {
  4068. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4069. return 0;
  4070. if (bl->type == BL_PC) {
  4071. if (battle_config.pc_walk_delay_rate != 100)
  4072. delay = delay*battle_config.pc_walk_delay_rate/100;
  4073. } else
  4074. if (battle_config.walk_delay_rate != 100)
  4075. delay = delay*battle_config.walk_delay_rate/100;
  4076. if (div_ > 1) //Multi-hit skills mean higher delays.
  4077. delay += battle_config.multihit_delay*(div_-1);
  4078. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4079. }
  4080. /// Sends a 'damage' packet (src performs action on dst)
  4081. /// 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)
  4082. /// 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)
  4083. /// 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)
  4084. /// type:
  4085. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4086. /// 1 = pick up item
  4087. /// 2 = sit down
  4088. /// 3 = stand up
  4089. /// 4 = damage (endure)
  4090. /// 5 = (splash?)
  4091. /// 6 = (skill?)
  4092. /// 7 = (repeat damage?)
  4093. /// 8 = multi-hit damage
  4094. /// 9 = multi-hit damage (endure)
  4095. /// 10 = critical hit
  4096. /// 11 = lucky dodge
  4097. /// 12 = (touch skill?)
  4098. 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, bool spdamage)
  4099. {
  4100. unsigned char buf[34];
  4101. struct status_change *sc;
  4102. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4103. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4104. #if PACKETVER < 20071113
  4105. const int cmd = 0x8a;
  4106. int offset = 0;
  4107. #elif PACKETVER < 20131223
  4108. const int cmd = 0x2e1;
  4109. int offset = 2;
  4110. #else
  4111. const int cmd = 0x8c8;
  4112. int offset = 3;
  4113. #endif
  4114. nullpo_ret(src);
  4115. nullpo_ret(dst);
  4116. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4117. sc = status_get_sc(dst);
  4118. if(sc && sc->count) {
  4119. if(sc->data[SC_HALLUCINATION]) {
  4120. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4121. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4122. }
  4123. }
  4124. WBUFW(buf,0) = cmd;
  4125. WBUFL(buf,2) = src->id;
  4126. WBUFL(buf,6) = dst->id;
  4127. WBUFL(buf,10) = tick;
  4128. WBUFL(buf,14) = sdelay;
  4129. WBUFL(buf,18) = ddelay;
  4130. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4131. WBUFW(buf,22) = damage ? div : 0;
  4132. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4133. } else {
  4134. #if PACKETVER < 20071113
  4135. WBUFW(buf,22) = min(damage, INT16_MAX);
  4136. WBUFW(buf,27+offset) = damage2;
  4137. #else
  4138. WBUFL(buf,22) = damage;
  4139. WBUFL(buf,27+offset) = damage2;
  4140. #endif
  4141. }
  4142. #if PACKETVER >= 20131223
  4143. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4144. #endif
  4145. WBUFW(buf,24+offset) = div;
  4146. WBUFB(buf,26+offset) = type;
  4147. if(disguised(dst)) {
  4148. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4149. WBUFL(buf,6) = -dst->id;
  4150. clif_send(buf, packet_len(cmd), dst, SELF);
  4151. } else
  4152. clif_send(buf, packet_len(cmd), dst, AREA);
  4153. if(disguised(src)) {
  4154. WBUFL(buf,2) = -src->id;
  4155. if (disguised(dst))
  4156. WBUFL(buf,6) = dst->id;
  4157. #if PACKETVER < 20071113
  4158. if(damage > 0) WBUFW(buf,22) = -1;
  4159. if(damage2 > 0) WBUFW(buf,27) = -1;
  4160. #else
  4161. if(damage > 0) WBUFL(buf,22) = -1;
  4162. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4163. #endif
  4164. clif_send(buf,packet_len(cmd),src,SELF);
  4165. }
  4166. if(src == dst) {
  4167. unit_setdir(src, unit_getdir(src));
  4168. }
  4169. //Return adjusted can't walk delay for further processing.
  4170. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4171. }
  4172. /*==========================================
  4173. * src picks up dst
  4174. *------------------------------------------*/
  4175. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4176. {
  4177. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4178. unsigned char buf[32];
  4179. nullpo_retv(src);
  4180. nullpo_retv(dst);
  4181. WBUFW(buf, 0) = 0x8a;
  4182. WBUFL(buf, 2) = src->id;
  4183. WBUFL(buf, 6) = dst->id;
  4184. WBUFB(buf,26) = 1;
  4185. clif_send(buf, packet_len(0x8a), src, AREA);
  4186. }
  4187. /*==========================================
  4188. * inform clients in area that `bl` is sitting
  4189. *------------------------------------------*/
  4190. void clif_sitting(struct block_list* bl)
  4191. {
  4192. unsigned char buf[32];
  4193. nullpo_retv(bl);
  4194. WBUFW(buf, 0) = 0x8a;
  4195. WBUFL(buf, 2) = bl->id;
  4196. WBUFB(buf,26) = 2;
  4197. clif_send(buf, packet_len(0x8a), bl, AREA);
  4198. if(disguised(bl)) {
  4199. WBUFL(buf, 2) = - bl->id;
  4200. clif_send(buf, packet_len(0x8a), bl, SELF);
  4201. }
  4202. }
  4203. /*==========================================
  4204. * inform clients in area that `bl` is standing
  4205. *------------------------------------------*/
  4206. void clif_standing(struct block_list* bl)
  4207. {
  4208. unsigned char buf[32];
  4209. nullpo_retv(bl);
  4210. WBUFW(buf, 0) = 0x8a;
  4211. WBUFL(buf, 2) = bl->id;
  4212. WBUFB(buf,26) = 3;
  4213. clif_send(buf, packet_len(0x8a), bl, AREA);
  4214. if(disguised(bl)) {
  4215. WBUFL(buf, 2) = - bl->id;
  4216. clif_send(buf, packet_len(0x8a), bl, SELF);
  4217. }
  4218. }
  4219. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4220. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4221. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4222. {
  4223. unsigned char buf[32];
  4224. WBUFW(buf,0) = 0x192;
  4225. WBUFW(buf,2) = x;
  4226. WBUFW(buf,4) = y;
  4227. WBUFW(buf,6) = type;
  4228. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  4229. if( fd )
  4230. {
  4231. WFIFOHEAD(fd,packet_len(0x192));
  4232. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4233. WFIFOSET(fd,packet_len(0x192));
  4234. }
  4235. else
  4236. {
  4237. struct block_list dummy_bl;
  4238. dummy_bl.type = BL_NUL;
  4239. dummy_bl.x = x;
  4240. dummy_bl.y = y;
  4241. dummy_bl.m = m;
  4242. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4243. }
  4244. }
  4245. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4246. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4247. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4248. {
  4249. int view,fd;
  4250. fd=sd->fd;
  4251. WFIFOHEAD(fd,packet_len(0x9d));
  4252. WFIFOW(fd,0)=0x9d;
  4253. WFIFOL(fd,2)=fitem->bl.id;
  4254. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4255. WFIFOW(fd,6)=view;
  4256. else
  4257. WFIFOW(fd,6)=fitem->item.nameid;
  4258. WFIFOB(fd,8)=fitem->item.identify;
  4259. WFIFOW(fd,9)=fitem->bl.x;
  4260. WFIFOW(fd,11)=fitem->bl.y;
  4261. WFIFOW(fd,13)=fitem->item.amount;
  4262. WFIFOB(fd,15)=fitem->subx;
  4263. WFIFOB(fd,16)=fitem->suby;
  4264. WFIFOSET(fd,packet_len(0x9d));
  4265. }
  4266. /// Notifes client about Graffiti
  4267. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4268. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4269. unsigned char buf[128];
  4270. nullpo_retv(bl);
  4271. nullpo_retv(unit);
  4272. WBUFW(buf, 0) = 0x1c9;
  4273. WBUFL(buf, 2) = unit->bl.id;
  4274. WBUFL(buf, 6) = unit->group->src_id;
  4275. WBUFW(buf,10) = unit->bl.x;
  4276. WBUFW(buf,12) = unit->bl.y;
  4277. WBUFB(buf,14) = unit->group->unit_id;
  4278. WBUFB(buf,15) = 1;
  4279. WBUFB(buf,16) = 1;
  4280. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4281. clif_send(buf,packet_len(0x1c9),bl,target);
  4282. }
  4283. /// Notifies the client of a skill unit.
  4284. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4285. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4286. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4287. /// 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)
  4288. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4289. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4290. unsigned char buf[128];
  4291. nullpo_retv(bl);
  4292. nullpo_retv(unit);
  4293. if (bl->type == BL_PC)
  4294. fd = ((TBL_PC*)bl)->fd;
  4295. if (unit->group->state.guildaura)
  4296. return;
  4297. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4298. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4299. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4300. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4301. else
  4302. unit_id = unit->group->unit_id;
  4303. if (!visible)
  4304. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4305. #if PACKETVER >= 3
  4306. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4307. clif_graffiti(bl, unit, target);
  4308. return;
  4309. }
  4310. #endif
  4311. #if PACKETVER <= 20120702
  4312. header = 0x011f;
  4313. //#if PACKETVER < 20110718
  4314. // header = 0x011f;
  4315. //#elif PACKETVER < 20121212
  4316. // header = 0x08c7;
  4317. #elif PACKETVER < 20130731
  4318. header = 0x099f;
  4319. #else
  4320. header = 0x09ca;
  4321. #endif
  4322. len = packet_len(header);
  4323. WBUFW(buf,pos) = header;
  4324. if (header != 0x011f) {
  4325. WBUFW(buf, pos+2) = len;
  4326. pos += 2;
  4327. }
  4328. WBUFL(buf,pos+2) = unit->bl.id;
  4329. WBUFL(buf,pos+6) = unit->group->src_id;
  4330. WBUFW(buf,pos+10) = unit->bl.x;
  4331. WBUFW(buf,pos+12) = unit->bl.y;
  4332. switch (header) {
  4333. case 0x011f:
  4334. WBUFB(buf,pos+14) = unit_id;
  4335. WBUFB(buf,pos+15) = visible;
  4336. break;
  4337. case 0x08c7:
  4338. WBUFB(buf,pos+14) = unit_id;
  4339. WBUFW(buf,pos+15) = unit->range;
  4340. WBUFB(buf,pos+17) = visible;
  4341. break;
  4342. case 0x099f:
  4343. WBUFL(buf,pos+14) = unit_id;
  4344. WBUFW(buf,pos+18) = unit->range;
  4345. WBUFB(buf,pos+20) = visible;
  4346. break;
  4347. case 0x09ca:
  4348. WBUFL(buf,pos+14) = unit_id;
  4349. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4350. WBUFB(buf,pos+19) = visible;
  4351. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4352. break;
  4353. }
  4354. clif_send(buf, len, bl, target);
  4355. if (unit->group->skill_id == WZ_ICEWALL)
  4356. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4357. }
  4358. /*==========================================
  4359. * Server tells client to remove unit of id 'unit->bl.id'
  4360. *------------------------------------------*/
  4361. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4362. {
  4363. nullpo_retv(unit);
  4364. WFIFOHEAD(fd,packet_len(0x120));
  4365. WFIFOW(fd, 0)=0x120;
  4366. WFIFOL(fd, 2)=unit->bl.id;
  4367. WFIFOSET(fd,packet_len(0x120));
  4368. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4369. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4370. }
  4371. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4372. /// 0120 <id>.L
  4373. void clif_skill_delunit(struct skill_unit *unit)
  4374. {
  4375. unsigned char buf[16];
  4376. nullpo_retv(unit);
  4377. WBUFW(buf, 0)=0x120;
  4378. WBUFL(buf, 2)=unit->bl.id;
  4379. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4380. }
  4381. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4382. /// 01ac <id>.L
  4383. /// Only affects units with class [139,153] client-side.
  4384. void clif_skillunit_update(struct block_list* bl)
  4385. {
  4386. unsigned char buf[6];
  4387. nullpo_retv(bl);
  4388. WBUFW(buf,0) = 0x1ac;
  4389. WBUFL(buf,2) = bl->id;
  4390. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4391. }
  4392. /*==========================================
  4393. *
  4394. *------------------------------------------*/
  4395. static int clif_getareachar(struct block_list* bl,va_list ap)
  4396. {
  4397. struct map_session_data *sd;
  4398. nullpo_ret(bl);
  4399. sd=va_arg(ap,struct map_session_data*);
  4400. if (sd == NULL || !sd->fd)
  4401. return 0;
  4402. switch(bl->type){
  4403. case BL_ITEM:
  4404. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4405. break;
  4406. case BL_SKILL:
  4407. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4408. break;
  4409. default:
  4410. if(&sd->bl == bl)
  4411. break;
  4412. clif_getareachar_unit(sd,bl);
  4413. break;
  4414. }
  4415. return 0;
  4416. }
  4417. /*==========================================
  4418. * tbl has gone out of view-size of bl
  4419. *------------------------------------------*/
  4420. int clif_outsight(struct block_list *bl,va_list ap)
  4421. {
  4422. struct block_list *tbl;
  4423. struct view_data *vd;
  4424. TBL_PC *sd, *tsd;
  4425. tbl=va_arg(ap,struct block_list*);
  4426. if(bl == tbl) return 0;
  4427. sd = BL_CAST(BL_PC, bl);
  4428. tsd = BL_CAST(BL_PC, tbl);
  4429. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4430. nullpo_ret(bl);
  4431. switch(bl->type){
  4432. case BL_PC:
  4433. if(sd->vd.class_ != INVISIBLE_CLASS)
  4434. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4435. if(sd->chatID){
  4436. struct chat_data *cd;
  4437. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4438. if(cd->usersd[0]==sd)
  4439. clif_dispchat(cd,tsd->fd);
  4440. }
  4441. if(sd->state.vending)
  4442. clif_closevendingboard(bl,tsd->fd);
  4443. if(sd->state.buyingstore)
  4444. clif_buyingstore_disappear_entry_single(tsd, sd);
  4445. break;
  4446. case BL_ITEM:
  4447. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4448. break;
  4449. case BL_SKILL:
  4450. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4451. break;
  4452. case BL_NPC:
  4453. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4454. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4455. break;
  4456. default:
  4457. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4458. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4459. break;
  4460. }
  4461. }
  4462. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4463. nullpo_ret(tbl);
  4464. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4465. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4466. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4467. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4468. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4469. }
  4470. return 0;
  4471. }
  4472. /*==========================================
  4473. * tbl has come into view of bl
  4474. *------------------------------------------*/
  4475. int clif_insight(struct block_list *bl,va_list ap)
  4476. {
  4477. struct block_list *tbl;
  4478. TBL_PC *sd, *tsd;
  4479. tbl=va_arg(ap,struct block_list*);
  4480. if (bl == tbl) return 0;
  4481. sd = BL_CAST(BL_PC, bl);
  4482. tsd = BL_CAST(BL_PC, tbl);
  4483. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4484. switch(bl->type){
  4485. case BL_ITEM:
  4486. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4487. break;
  4488. case BL_SKILL:
  4489. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4490. break;
  4491. default:
  4492. clif_getareachar_unit(tsd,bl);
  4493. break;
  4494. }
  4495. }
  4496. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4497. clif_getareachar_unit(sd,tbl);
  4498. }
  4499. return 0;
  4500. }
  4501. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4502. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4503. void clif_skillinfoblock(struct map_session_data *sd)
  4504. {
  4505. int fd;
  4506. int i,len,id;
  4507. nullpo_retv(sd);
  4508. fd = sd->fd;
  4509. if (!fd)
  4510. return;
  4511. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4512. WFIFOW(fd,0) = 0x10f;
  4513. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4514. {
  4515. if( (id = sd->status.skill[i].id) != 0 )
  4516. {
  4517. // workaround for bugreport:5348
  4518. if (len + 37 > 8192)
  4519. break;
  4520. WFIFOW(fd,len) = id;
  4521. WFIFOL(fd,len+2) = skill_get_inf(id);
  4522. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4523. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4524. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4525. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4526. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4527. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4528. else
  4529. WFIFOB(fd,len+36) = 0;
  4530. len += 37;
  4531. }
  4532. }
  4533. WFIFOW(fd,2)=len;
  4534. WFIFOSET(fd,len);
  4535. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4536. for ( ; i < MAX_SKILL; i++)
  4537. {
  4538. if( (id = sd->status.skill[i].id) != 0 )
  4539. {
  4540. clif_addskill(sd, id);
  4541. clif_skillinfo(sd, id, 0);
  4542. }
  4543. }
  4544. }
  4545. /**
  4546. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4547. **/
  4548. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4549. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4550. void clif_addskill(struct map_session_data *sd, int skill_id)
  4551. {
  4552. int fd;
  4553. uint16 idx = 0;
  4554. nullpo_retv(sd);
  4555. fd = sd->fd;
  4556. if (!fd || !(idx = skill_get_index(skill_id)))
  4557. return;
  4558. if( sd->status.skill[idx].id <= 0 )
  4559. return;
  4560. WFIFOHEAD(fd, packet_len(0x111));
  4561. WFIFOW(fd,0) = 0x111;
  4562. WFIFOW(fd,2) = skill_id;
  4563. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4564. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4565. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4566. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4567. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4568. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4569. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4570. else
  4571. WFIFOB(fd,38) = 0;
  4572. WFIFOSET(fd,packet_len(0x111));
  4573. }
  4574. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4575. /// 0441 <skill id>.W
  4576. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4577. {
  4578. #if PACKETVER >= 20081217
  4579. int fd;
  4580. uint16 idx = 0;
  4581. nullpo_retv(sd);
  4582. fd = sd->fd;
  4583. if (!fd || !(idx = skill_get_index(skill_id)))
  4584. return;
  4585. WFIFOHEAD(fd,packet_len(0x441));
  4586. WFIFOW(fd,0) = 0x441;
  4587. WFIFOW(fd,2) = skill_id;
  4588. WFIFOSET(fd,packet_len(0x441));
  4589. #endif
  4590. clif_skillinfoblock(sd);
  4591. }
  4592. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4593. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4594. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4595. int fd;
  4596. nullpo_retv(sd);
  4597. fd = sd->fd;
  4598. WFIFOHEAD(fd, packet_len(0x10e));
  4599. WFIFOW(fd, 0) = 0x10e;
  4600. WFIFOW(fd, 2) = skill_id;
  4601. WFIFOW(fd, 4) = lv;
  4602. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4603. WFIFOW(fd, 8) = range;
  4604. WFIFOB(fd, 10) = upgradable;
  4605. WFIFOSET(fd, packet_len(0x10e));
  4606. }
  4607. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4608. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4609. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4610. {
  4611. const int fd = sd->fd;
  4612. uint16 idx = skill_get_index(skill_id);
  4613. if (!idx)
  4614. return;
  4615. WFIFOHEAD(fd,packet_len(0x7e1));
  4616. WFIFOW(fd,0) = 0x7e1;
  4617. WFIFOW(fd,2) = skill_id;
  4618. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4619. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4620. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4621. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4622. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4623. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4624. else
  4625. WFIFOB(fd,14) = 0;
  4626. WFIFOSET(fd,packet_len(0x7e1));
  4627. }
  4628. /// Notifies clients in area, that an object is about to use a skill.
  4629. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4630. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4631. /// property:
  4632. /// 0 = Yellow cast aura
  4633. /// 1 = Water elemental cast aura
  4634. /// 2 = Earth elemental cast aura
  4635. /// 3 = Fire elemental cast aura
  4636. /// 4 = Wind elemental cast aura
  4637. /// 5 = Poison elemental cast aura
  4638. /// 6 = Holy elemental cast aura
  4639. /// ? = like 0
  4640. /// is disposable:
  4641. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4642. /// 1 = no text
  4643. 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)
  4644. {
  4645. #if PACKETVER < 20091124
  4646. const int cmd = 0x13e;
  4647. #else
  4648. const int cmd = 0x7fb;
  4649. #endif
  4650. unsigned char buf[32];
  4651. WBUFW(buf,0) = cmd;
  4652. WBUFL(buf,2) = src_id;
  4653. WBUFL(buf,6) = dst_id;
  4654. WBUFW(buf,10) = dst_x;
  4655. WBUFW(buf,12) = dst_y;
  4656. WBUFW(buf,14) = skill_id;
  4657. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4658. WBUFL(buf,20) = casttime;
  4659. #if PACKETVER >= 20091124
  4660. WBUFB(buf,24) = 0; // isDisposable
  4661. #endif
  4662. if (disguised(bl)) {
  4663. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4664. WBUFL(buf,2) = -src_id;
  4665. clif_send(buf,packet_len(cmd), bl, SELF);
  4666. } else
  4667. clif_send(buf,packet_len(cmd), bl, AREA);
  4668. }
  4669. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4670. /// 01b9 <id>.L
  4671. void clif_skillcastcancel(struct block_list* bl)
  4672. {
  4673. unsigned char buf[16];
  4674. nullpo_retv(bl);
  4675. WBUFW(buf,0) = 0x1b9;
  4676. WBUFL(buf,2) = bl->id;
  4677. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4678. }
  4679. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4680. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4681. /// num (only used when skill id = NV_BASIC and cause = 0):
  4682. /// 0 = "skill failed" MsgStringTable[159]
  4683. /// 1 = "no emotions" MsgStringTable[160]
  4684. /// 2 = "no sit" MsgStringTable[161]
  4685. /// 3 = "no chat" MsgStringTable[162]
  4686. /// 4 = "no party" MsgStringTable[163]
  4687. /// 5 = "no shout" MsgStringTable[164]
  4688. /// 6 = "no PKing" MsgStringTable[165]
  4689. /// 7 = "no alligning" MsgStringTable[383]
  4690. /// ? = ignored
  4691. /// cause:
  4692. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4693. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4694. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4695. /// "skill failed" MsgStringTable[204] (otherwise)
  4696. /// ... = @see enum useskill_fail_cause
  4697. /// ? = ignored
  4698. ///
  4699. /// if(result!=0) doesn't display any of the previous messages
  4700. /// Note: when this packet is received an unknown flag is always set to 0,
  4701. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4702. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4703. {
  4704. int fd;
  4705. if (!sd) { //Since this is the most common nullpo....
  4706. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4707. return;
  4708. }
  4709. fd=sd->fd;
  4710. if (!fd) return;
  4711. if(battle_config.display_skill_fail&1)
  4712. return; //Disable all skill failed messages
  4713. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4714. return; //Disable delay failed messages
  4715. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4716. return;
  4717. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4718. return;
  4719. WFIFOHEAD(fd,packet_len(0x110));
  4720. WFIFOW(fd,0) = 0x110;
  4721. WFIFOW(fd,2) = skill_id;
  4722. WFIFOL(fd,4) = btype;
  4723. WFIFOB(fd,8) = 0;// success
  4724. WFIFOB(fd,9) = cause;
  4725. WFIFOSET(fd,packet_len(0x110));
  4726. }
  4727. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4728. /// 043d <skill ID>.W <tick>.L
  4729. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4730. {
  4731. #if PACKETVER>=20081112
  4732. int fd;
  4733. nullpo_retv(sd);
  4734. fd=sd->fd;
  4735. WFIFOHEAD(fd,packet_len(0x43d));
  4736. WFIFOW(fd,0) = 0x43d;
  4737. WFIFOW(fd,2) = skill_id;
  4738. WFIFOL(fd,4) = tick;
  4739. WFIFOSET(fd,packet_len(0x43d));
  4740. #endif
  4741. }
  4742. /// Skill attack effect and damage.
  4743. /// 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)
  4744. /// 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)
  4745. 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,enum e_damage_type type)
  4746. {
  4747. unsigned char buf[64];
  4748. struct status_change *sc;
  4749. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4750. nullpo_ret(src);
  4751. nullpo_ret(dst);
  4752. type = clif_calc_delay(type,div,damage,ddelay);
  4753. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4754. if(sc->data[SC_HALLUCINATION] && damage)
  4755. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4756. }
  4757. #if PACKETVER < 3
  4758. WBUFW(buf,0)=0x114;
  4759. WBUFW(buf,2)=skill_id;
  4760. WBUFL(buf,4)=src->id;
  4761. WBUFL(buf,8)=dst->id;
  4762. WBUFL(buf,12)=tick;
  4763. WBUFL(buf,16)=sdelay;
  4764. WBUFL(buf,20)=ddelay;
  4765. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4766. WBUFW(buf,24)=damage?div:0;
  4767. } else {
  4768. WBUFW(buf,24)=damage;
  4769. }
  4770. WBUFW(buf,26)=skill_lv;
  4771. WBUFW(buf,28)=div;
  4772. WBUFB(buf,30)=type;
  4773. if (disguised(dst)) {
  4774. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4775. WBUFL(buf,8)=-dst->id;
  4776. clif_send(buf,packet_len(0x114),dst,SELF);
  4777. } else
  4778. clif_send(buf,packet_len(0x114),dst,AREA);
  4779. if(disguised(src)) {
  4780. WBUFL(buf,4)=-src->id;
  4781. if (disguised(dst))
  4782. WBUFL(buf,8)=dst->id;
  4783. if(damage > 0)
  4784. WBUFW(buf,24)=-1;
  4785. clif_send(buf,packet_len(0x114),src,SELF);
  4786. }
  4787. #else
  4788. WBUFW(buf,0)=0x1de;
  4789. WBUFW(buf,2)=skill_id;
  4790. WBUFL(buf,4)=src->id;
  4791. WBUFL(buf,8)=dst->id;
  4792. WBUFL(buf,12)=tick;
  4793. WBUFL(buf,16)=sdelay;
  4794. WBUFL(buf,20)=ddelay;
  4795. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4796. WBUFL(buf,24)=damage?div:0;
  4797. } else {
  4798. WBUFL(buf,24)=damage;
  4799. }
  4800. WBUFW(buf,28)=skill_lv;
  4801. WBUFW(buf,30)=div;
  4802. // For some reason, late 2013 and newer clients have
  4803. // a issue that causes players and monsters to endure
  4804. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4805. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4806. #if PACKETVER < 20131223
  4807. WBUFB(buf,32)=type;
  4808. #else
  4809. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4810. #endif
  4811. if (disguised(dst)) {
  4812. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4813. WBUFL(buf,8)=-dst->id;
  4814. clif_send(buf,packet_len(0x1de),dst,SELF);
  4815. } else
  4816. clif_send(buf,packet_len(0x1de),dst,AREA);
  4817. if(disguised(src)) {
  4818. WBUFL(buf,4)=-src->id;
  4819. if (disguised(dst))
  4820. WBUFL(buf,8)=dst->id;
  4821. if(damage > 0)
  4822. WBUFL(buf,24)=-1;
  4823. clif_send(buf,packet_len(0x1de),src,SELF);
  4824. }
  4825. #endif
  4826. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4827. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4828. }
  4829. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4830. /// 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
  4831. /*
  4832. 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,enum e_damage_type type)
  4833. {
  4834. unsigned char buf[64];
  4835. struct status_change *sc;
  4836. nullpo_ret(src);
  4837. nullpo_ret(dst);
  4838. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4839. type = clif_calc_delay(type,div,damage,ddelay);
  4840. sc = status_get_sc(dst);
  4841. if(sc && sc->count) {
  4842. if(sc->data[SC_HALLUCINATION] && damage)
  4843. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4844. }
  4845. WBUFW(buf,0)=0x115;
  4846. WBUFW(buf,2)=skill_id;
  4847. WBUFL(buf,4)=src->id;
  4848. WBUFL(buf,8)=dst->id;
  4849. WBUFL(buf,12)=tick;
  4850. WBUFL(buf,16)=sdelay;
  4851. WBUFL(buf,20)=ddelay;
  4852. WBUFW(buf,24)=dst->x;
  4853. WBUFW(buf,26)=dst->y;
  4854. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4855. WBUFW(buf,28)=damage?div:0;
  4856. } else {
  4857. WBUFW(buf,28)=damage;
  4858. }
  4859. WBUFW(buf,30)=skill_lv;
  4860. WBUFW(buf,32)=div;
  4861. WBUFB(buf,34)=type;
  4862. clif_send(buf,packet_len(0x115),src,AREA);
  4863. if(disguised(src)) {
  4864. WBUFL(buf,4)=-src->id;
  4865. if(damage > 0)
  4866. WBUFW(buf,28)=-1;
  4867. clif_send(buf,packet_len(0x115),src,SELF);
  4868. }
  4869. if (disguised(dst)) {
  4870. WBUFL(buf,8)=-dst->id;
  4871. if (disguised(src))
  4872. WBUFL(buf,4)=src->id;
  4873. else if(damage > 0)
  4874. WBUFW(buf,28)=-1;
  4875. clif_send(buf,packet_len(0x115),dst,SELF);
  4876. }
  4877. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4878. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4879. }
  4880. */
  4881. /// Non-damaging skill effect
  4882. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4883. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4884. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4885. {
  4886. unsigned char buf[17];
  4887. #if PACKETVER < 20130731
  4888. const int cmd = 0x11a;
  4889. #else
  4890. const int cmd = 0x9cb;
  4891. #endif
  4892. int offset = 0;
  4893. nullpo_ret(dst);
  4894. WBUFW(buf,0) = cmd;
  4895. WBUFW(buf,2) = skill_id;
  4896. #if PACKETVER < 20130731
  4897. WBUFW(buf,4) = min(heal, INT16_MAX);
  4898. #else
  4899. WBUFL(buf,4) = min(heal, INT32_MAX);
  4900. offset += 2;
  4901. #endif
  4902. WBUFL(buf,6+offset) = dst->id;
  4903. WBUFL(buf,10+offset) = src ? src->id : 0;
  4904. WBUFB(buf,14+offset) = fail;
  4905. if (disguised(dst)) {
  4906. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4907. WBUFL(buf,6+offset) = -dst->id;
  4908. clif_send(buf, packet_len(cmd), dst, SELF);
  4909. } else
  4910. clif_send(buf, packet_len(cmd), dst, AREA);
  4911. if(src && disguised(src)) {
  4912. WBUFL(buf,10+offset) = -src->id;
  4913. if (disguised(dst))
  4914. WBUFL(buf,6+offset) = dst->id;
  4915. clif_send(buf, packet_len(cmd), src, SELF);
  4916. }
  4917. return fail;
  4918. }
  4919. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4920. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4921. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4922. {
  4923. unsigned char buf[32];
  4924. nullpo_retv(src);
  4925. WBUFW(buf,0)=0x117;
  4926. WBUFW(buf,2)=skill_id;
  4927. WBUFL(buf,4)=src->id;
  4928. WBUFW(buf,8)=val;
  4929. WBUFW(buf,10)=x;
  4930. WBUFW(buf,12)=y;
  4931. WBUFL(buf,14)=tick;
  4932. if(disguised(src)) {
  4933. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4934. WBUFL(buf,4)=-src->id;
  4935. clif_send(buf,packet_len(0x117),src,SELF);
  4936. } else
  4937. clif_send(buf,packet_len(0x117),src,AREA);
  4938. }
  4939. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4940. /// 011c <skill id>.W { <map name>.16B }*4
  4941. 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)
  4942. {
  4943. int fd;
  4944. nullpo_retv(sd);
  4945. fd = sd->fd;
  4946. WFIFOHEAD(fd,packet_len(0x11c));
  4947. WFIFOW(fd,0) = 0x11c;
  4948. WFIFOW(fd,2) = skill_id;
  4949. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4950. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4951. else // normal map name
  4952. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4953. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4954. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4955. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4956. WFIFOSET(fd,packet_len(0x11c));
  4957. sd->menuskill_id = skill_id;
  4958. if (skill_id == AL_WARP) {
  4959. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4960. sd->state.workinprogress = WIP_DISABLE_ALL;
  4961. } else
  4962. sd->menuskill_val = skill_lv;
  4963. }
  4964. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4965. /// 011e <type>.B
  4966. /// type:
  4967. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4968. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4969. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4970. ///
  4971. /// @param sd Who receives the message
  4972. /// @param type What message
  4973. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4974. {
  4975. int fd;
  4976. nullpo_retv(sd);
  4977. fd=sd->fd;
  4978. WFIFOHEAD(fd,packet_len(0x11e));
  4979. WFIFOW(fd,0)=0x11e;
  4980. WFIFOB(fd,2)=type;
  4981. WFIFOSET(fd,packet_len(0x11e));
  4982. }
  4983. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4984. /// 0189 <type>.W
  4985. /// type:
  4986. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4987. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4988. ///
  4989. /// @param sd Who receives the message
  4990. /// @param type What message
  4991. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4992. {
  4993. int fd;
  4994. nullpo_retv(sd);
  4995. fd=sd->fd;
  4996. WFIFOHEAD(fd,packet_len(0x189));
  4997. WFIFOW(fd,0)=0x189;
  4998. WFIFOW(fd,2)=type;
  4999. WFIFOSET(fd,packet_len(0x189));
  5000. }
  5001. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5002. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5003. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5004. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5005. {
  5006. struct status_data *status;
  5007. unsigned char buf[64];
  5008. int i;//, fix;
  5009. nullpo_retv(sd);
  5010. nullpo_retv(dst);
  5011. if( dst->type != BL_MOB )
  5012. return;
  5013. status = status_get_status_data(dst);
  5014. WBUFW(buf, 0)=0x18c;
  5015. WBUFW(buf, 2)=status_get_class(dst);
  5016. WBUFW(buf, 4)=status_get_lv(dst);
  5017. WBUFW(buf, 6)=status->size;
  5018. WBUFL(buf, 8)=status->hp;
  5019. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5020. +(battle_config.estimation_type&2?status->def2:0);
  5021. WBUFW(buf,14)=status->race;
  5022. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5023. +(battle_config.estimation_type&2?status->mdef2:0);
  5024. WBUFW(buf,18)= status->def_ele;
  5025. for(i=0;i<9;i++)
  5026. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5027. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5028. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5029. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5030. }
  5031. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5032. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5033. /// material id:
  5034. /// unused by the client
  5035. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5036. {
  5037. int i,c,view,fd;
  5038. nullpo_retv(sd);
  5039. if (sd->menuskill_id == skill_id)
  5040. return; //Avoid resending the menu twice or more times...
  5041. if (skill_id == GC_CREATENEWPOISON)
  5042. skill_id = GC_RESEARCHNEWPOISON;
  5043. fd = sd->fd;
  5044. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5045. WFIFOW(fd, 0) = 0x18d;
  5046. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5047. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5048. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5049. )
  5050. {
  5051. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5052. WFIFOW(fd,c*8+ 4) = view;
  5053. else
  5054. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5055. WFIFOW(fd,c*8+ 6) = 0;
  5056. WFIFOW(fd,c*8+ 8) = 0;
  5057. WFIFOW(fd,c*8+10) = 0;
  5058. c++;
  5059. }
  5060. }
  5061. WFIFOW(fd, 2) = c*8+8;
  5062. WFIFOSET(fd,WFIFOW(fd,2));
  5063. if (c > 0) {
  5064. sd->menuskill_id = skill_id;
  5065. sd->menuskill_val = trigger;
  5066. return;
  5067. }
  5068. }
  5069. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5070. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5071. /// mk type:
  5072. /// 1 = cooking
  5073. /// 2 = arrow
  5074. /// 3 = elemental
  5075. /// 4 = GN_MIX_COOKING
  5076. /// 5 = GN_MAKEBOMB
  5077. /// 6 = GN_S_PHARMACY
  5078. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5079. {
  5080. int fd;
  5081. int i, c;
  5082. int view;
  5083. nullpo_retv(sd);
  5084. fd = sd->fd;
  5085. if(sd->menuskill_id == skill_id)
  5086. return; //Avoid resending the menu twice or more times...
  5087. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5088. WFIFOW(fd,0) = 0x25a;
  5089. WFIFOW(fd,4) = list_type; // list type
  5090. c = 0;
  5091. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5092. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5093. continue;
  5094. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5095. WFIFOW(fd, 6 + 2 * c) = view;
  5096. else
  5097. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5098. c++;
  5099. }
  5100. if( c > 0 || skill_id == AM_PHARMACY) {
  5101. sd->menuskill_id = skill_id;
  5102. sd->menuskill_val = trigger;
  5103. sd->menuskill_val2 = qty; // amount.
  5104. WFIFOW(fd,2) = 6 + 2 * c;
  5105. WFIFOSET(fd,WFIFOW(fd,2));
  5106. } else {
  5107. clif_menuskill_clear(sd);
  5108. #if PACKETVER >= 20090922
  5109. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5110. #else
  5111. WFIFOW(fd,2) = 6 + 2 * c;
  5112. WFIFOSET(fd,WFIFOW(fd,2));
  5113. #endif
  5114. }
  5115. }
  5116. /// Notifies clients of a status change.
  5117. /// 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)]
  5118. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5119. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5120. /// @param bl Sends packet to clients around this object
  5121. /// @param id ID of object that has this effect
  5122. /// @param type Status icon see enum si_type
  5123. /// @param flag 1:Active, 0:Deactive
  5124. /// @param tick Duration in ms
  5125. /// @param val1
  5126. /// @param val2
  5127. /// @param val3
  5128. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, int tick, int val1, int val2, int val3, enum send_target target_type)
  5129. {
  5130. unsigned char buf[32];
  5131. if (type == SI_BLANK) //It shows nothing on the client...
  5132. return;
  5133. if (type == SI_ACTIONDELAY && tick == 0)
  5134. return;
  5135. nullpo_retv(bl);
  5136. #if PACKETVER >= 20120618
  5137. if (flag && battle_config.display_status_timers)
  5138. WBUFW(buf,0) = 0x983;
  5139. else
  5140. #elif PACKETVER >= 20090121
  5141. if (flag && battle_config.display_status_timers)
  5142. WBUFW(buf,0) = 0x43f;
  5143. else
  5144. #endif
  5145. WBUFW(buf,0) = 0x196;
  5146. WBUFW(buf,2) = type;
  5147. WBUFL(buf,4) = id;
  5148. WBUFB(buf,8) = flag;
  5149. #if PACKETVER >= 20120618
  5150. if (flag && battle_config.display_status_timers) {
  5151. if (tick <= 0)
  5152. tick = 9999; // this is indeed what official servers do
  5153. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5154. WBUFL(buf,13) = tick;
  5155. WBUFL(buf,17) = val1;
  5156. WBUFL(buf,21) = val2;
  5157. WBUFL(buf,25) = val3;
  5158. }
  5159. #elif PACKETVER >= 20090121
  5160. if (flag && battle_config.display_status_timers) {
  5161. if (tick <= 0)
  5162. tick = 9999; // this is indeed what official servers do
  5163. WBUFL(buf,9) = tick;
  5164. WBUFL(buf,13) = val1;
  5165. WBUFL(buf,17) = val2;
  5166. WBUFL(buf,21) = val3;
  5167. }
  5168. #endif
  5169. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5170. }
  5171. /* Sends status effect to clients around the bl
  5172. * @param bl Object that has the effect
  5173. * @param type Status icon see enum si_type
  5174. * @param flag 1:Active, 0:Deactive
  5175. * @param tick Duration in ms
  5176. * @param val1
  5177. * @param val2
  5178. * @param val3
  5179. */
  5180. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5181. struct map_session_data *sd = NULL;
  5182. if (type == SI_BLANK) //It shows nothing on the client...
  5183. return;
  5184. if (type == SI_ACTIONDELAY && tick == 0)
  5185. return;
  5186. nullpo_retv(bl);
  5187. sd = BL_CAST(BL_PC, bl);
  5188. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5189. return;
  5190. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (sd->status.option&OPTION_INVISIBLE ? SELF : AREA) : AREA_WOS)));
  5191. }
  5192. /**
  5193. * Send any active EFST to those around.
  5194. * @param sd: Player to send the packet to
  5195. * @param bl: Objects walking into view
  5196. * @param target: Client send type
  5197. */
  5198. void clif_efst_status_change_sub(struct map_session_data *sd, struct block_list *bl, enum send_target target) {
  5199. struct map_session_data *tsd = NULL;
  5200. unsigned char i;
  5201. nullpo_retv(sd);
  5202. nullpo_retv(bl);
  5203. if (target == SELF)
  5204. tsd = (TBL_PC *)bl;
  5205. else
  5206. tsd = sd;
  5207. for (i = 0; i < tsd->sc_display_count; i++) {
  5208. enum sc_type type = tsd->sc_display[i]->type;
  5209. struct status_change *sc = status_get_sc(bl);
  5210. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5211. int tick = 0;
  5212. if (td)
  5213. tick = DIFF_TICK(td->tick, gettick());
  5214. #if PACKETVER > 20120418
  5215. clif_efst_status_change((target == SELF) ? &sd->bl : bl, bl->id, target, StatusIconChangeTable[type], tick, tsd->sc_display[i]->val1, tsd->sc_display[i]->val2, tsd->sc_display[i]->val3);
  5216. #else
  5217. clif_status_change_sub(&sd->bl, bl->id, StatusIconChangeTable[type], 1, tick, tsd->sc_display[i]->val1, tsd->sc_display[i]->val2, tsd->sc_display[i]->val3, target);
  5218. #endif
  5219. }
  5220. }
  5221. /// Notifies the client when a player enters the screen with an active EFST.
  5222. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5223. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5224. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, int tick, int val1, int val2, int val3) {
  5225. #if PACKETVER >= 20111108
  5226. unsigned char buf[32];
  5227. #if PACKETVER >= 20120618
  5228. const int cmd = 0x984;
  5229. #elif PACKETVER >= 20111108
  5230. const int cmd = 0x8ff;
  5231. #endif
  5232. int offset = 0;
  5233. if (type == SI_BLANK)
  5234. return;
  5235. nullpo_retv(bl);
  5236. if (tick <= 0)
  5237. tick = 9999;
  5238. WBUFW(buf,offset + 0) = cmd;
  5239. WBUFL(buf,offset + 2) = tid;
  5240. WBUFW(buf,offset + 6) = type;
  5241. #if PACKETVER >= 20111108
  5242. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5243. #if PACKETVER >= 20120618
  5244. WBUFL(buf,offset + 12) = tick;
  5245. offset += 4;
  5246. #endif
  5247. WBUFL(buf,offset + 12) = val1;
  5248. WBUFL(buf,offset + 16) = val2;
  5249. WBUFL(buf,offset + 20) = val3;
  5250. #endif
  5251. clif_send(buf,packet_len(cmd),bl,target);
  5252. #endif
  5253. }
  5254. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5255. /// 008e <packet len>.W <message>.?B
  5256. void clif_displaymessage(const int fd, const char* mes)
  5257. {
  5258. nullpo_retv(mes);
  5259. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5260. if (fd == 0)
  5261. ;
  5262. else {
  5263. char *message, *line;
  5264. message = aStrdup(mes);
  5265. line = strtok(message, "\n");
  5266. #if PACKETVER == 20141022
  5267. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5268. /** so we redirect to ZC_NPC_CHAT **/
  5269. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5270. while(line != NULL) {
  5271. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5272. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5273. if (len > 0) {
  5274. WFIFOHEAD(fd, 13 + len);
  5275. WFIFOW(fd, 0) = 0x2C1;
  5276. WFIFOW(fd, 2) = 13 + len;
  5277. WFIFOL(fd, 4) = 0;
  5278. WFIFOL(fd, 8) = color;
  5279. safestrncpy((char*)WFIFOP(fd, 12), line, len + 1);
  5280. WFIFOSET(fd, WFIFOW(fd, 2));
  5281. }
  5282. #else
  5283. while(line != NULL) {
  5284. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5285. int len = strnlen(line, CHAT_SIZE_MAX);
  5286. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5287. WFIFOHEAD(fd, 5 + len);
  5288. WFIFOW(fd,0) = 0x8e;
  5289. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5290. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5291. WFIFOSET(fd, 5 + len);
  5292. }
  5293. #endif
  5294. line = strtok(NULL, "\n");
  5295. }
  5296. aFree(message);
  5297. }
  5298. }
  5299. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5300. /// 009a <packet len>.W <message>.?B
  5301. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5302. {
  5303. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5304. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5305. WBUFW(buf,0) = 0x9a;
  5306. WBUFW(buf,2) = 4 + lp + len;
  5307. if (type&BC_BLUE)
  5308. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5309. else if (type&BC_WOE)
  5310. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5311. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5312. clif_send(buf, WBUFW(buf,2), bl, target);
  5313. if (buf)
  5314. aFree(buf);
  5315. }
  5316. /*==========================================
  5317. * Displays a message on a 'bl' to all it's nearby clients
  5318. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5319. *------------------------------------------*/
  5320. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5321. char buf[100];
  5322. int len;
  5323. nullpo_retv(bl);
  5324. if(!message)
  5325. return;
  5326. len = strlen(message)+1;
  5327. if( len > sizeof(buf)-8 ) {
  5328. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5329. len = sizeof(buf)-8;
  5330. }
  5331. WBUFW(buf,0)=0x8d;
  5332. WBUFW(buf,2)=len+8;
  5333. WBUFL(buf,4)=bl->id;
  5334. safestrncpy((char *) WBUFP(buf,8),message,len);
  5335. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5336. }
  5337. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5338. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5339. 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)
  5340. {
  5341. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5342. WBUFW(buf,0) = 0x1c3;
  5343. WBUFW(buf,2) = len + 16;
  5344. WBUFL(buf,4) = fontColor;
  5345. WBUFW(buf,8) = fontType;
  5346. WBUFW(buf,10) = fontSize;
  5347. WBUFW(buf,12) = fontAlign;
  5348. WBUFW(buf,14) = fontY;
  5349. memcpy(WBUFP(buf,16), mes, len);
  5350. clif_send(buf, WBUFW(buf,2), bl, target);
  5351. if (buf)
  5352. aFree(buf);
  5353. }
  5354. /*
  5355. * Display *msg from *sd to all *users in channel
  5356. */
  5357. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5358. DBIterator *iter;
  5359. struct map_session_data *user;
  5360. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  5361. WFIFOHEAD(sd->fd,msg_len + 12);
  5362. WFIFOW(sd->fd,0) = 0x2C1;
  5363. WFIFOW(sd->fd,2) = msg_len + 12;
  5364. WFIFOL(sd->fd,4) = 0;
  5365. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5366. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5367. iter = db_iterator(channel->users);
  5368. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5369. if( user->fd == sd->fd )
  5370. continue;
  5371. WFIFOHEAD(user->fd,msg_len + 12);
  5372. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5373. WFIFOSET(user->fd, msg_len + 12);
  5374. }
  5375. dbi_destroy(iter);
  5376. WFIFOSET(sd->fd, msg_len + 12);
  5377. }
  5378. /// Displays heal effect.
  5379. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5380. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5381. /// var id:
  5382. /// 5 = HP (SP_HP)
  5383. /// 7 = SP (SP_SP)
  5384. /// ? = ignored
  5385. void clif_heal(int fd,int type,int val) {
  5386. #if PACKETVER < 20141022
  5387. const int cmd = 0x13d;
  5388. #else
  5389. const int cmd = 0xa27;
  5390. #endif
  5391. WFIFOHEAD(fd, packet_len(cmd));
  5392. WFIFOW(fd,0) = cmd;
  5393. WFIFOW(fd,2) = type;
  5394. #if PACKETVER < 20141022
  5395. WFIFOW(fd,4) = min(val, INT16_MAX);
  5396. #else
  5397. WFIFOL(fd,4) = min(val, INT32_MAX);
  5398. #endif
  5399. WFIFOSET(fd, packet_len(cmd));
  5400. }
  5401. /// Displays resurrection effect (ZC_RESURRECTION).
  5402. /// 0148 <id>.L <type>.W
  5403. /// type:
  5404. /// ignored
  5405. void clif_resurrection(struct block_list *bl,int type)
  5406. {
  5407. unsigned char buf[16];
  5408. nullpo_retv(bl);
  5409. WBUFW(buf,0)=0x148;
  5410. WBUFL(buf,2)=bl->id;
  5411. WBUFW(buf,6)=0;
  5412. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5413. if (disguised(bl))
  5414. clif_spawn(bl);
  5415. }
  5416. /// Sets the map property
  5417. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5418. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5419. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5420. {
  5421. #if PACKETVER >= 20121010
  5422. short cmd = 0x99b;
  5423. unsigned char buf[8];
  5424. #else
  5425. short cmd = 0x199;
  5426. unsigned char buf[4];
  5427. #endif
  5428. WBUFW(buf,0)=cmd;
  5429. WBUFW(buf,2)=property;
  5430. #if PACKETVER >= 20121010
  5431. WBUFL(buf,4) = ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5432. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5433. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5434. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5435. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5436. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5437. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5438. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5439. ((map[bl->m].flag.nocostume?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5440. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5441. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5442. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5443. #endif
  5444. clif_send(buf,packet_len(cmd),bl,t);
  5445. }
  5446. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5447. /// 01d6 <type>.W
  5448. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5449. {
  5450. int fd;
  5451. nullpo_retv(sd);
  5452. fd=sd->fd;
  5453. WFIFOHEAD(fd,packet_len(0x1D6));
  5454. WFIFOW(fd,0)=0x1D6;
  5455. WFIFOW(fd,2)=type;
  5456. WFIFOSET(fd,packet_len(0x1D6));
  5457. }
  5458. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5459. /// 019a <id>.L <ranking>.L <total>.L
  5460. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5461. {
  5462. if(type == 2) {
  5463. int fd = sd->fd;
  5464. WFIFOHEAD(fd,packet_len(0x19a));
  5465. WFIFOW(fd,0) = 0x19a;
  5466. WFIFOL(fd,2) = sd->bl.id;
  5467. WFIFOL(fd,6) = pvprank;
  5468. WFIFOL(fd,10) = pvpnum;
  5469. WFIFOSET(fd,packet_len(0x19a));
  5470. } else {
  5471. unsigned char buf[32];
  5472. WBUFW(buf,0) = 0x19a;
  5473. WBUFL(buf,2) = sd->bl.id;
  5474. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5475. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5476. else
  5477. WBUFL(buf,6) = pvprank;
  5478. WBUFL(buf,10) = pvpnum;
  5479. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5480. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5481. else if(!type)
  5482. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5483. else
  5484. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5485. }
  5486. }
  5487. /*==========================================
  5488. *
  5489. *------------------------------------------*/
  5490. void clif_map_property_mapall(int map_idx, enum map_property property)
  5491. {
  5492. struct block_list bl;
  5493. bl.id = 0;
  5494. bl.type = BL_NUL;
  5495. bl.m = map_idx;
  5496. clif_map_property( &bl, property, ALL_SAMEMAP );
  5497. }
  5498. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5499. /// 0188 <result>.W <index>.W <refine>.W
  5500. /// result:
  5501. /// 0 = success
  5502. /// 1 = failure
  5503. /// 2 = downgrade
  5504. void clif_refine(int fd, int fail, int index, int val)
  5505. {
  5506. WFIFOHEAD(fd,packet_len(0x188));
  5507. WFIFOW(fd,0)=0x188;
  5508. WFIFOW(fd,2)=fail;
  5509. WFIFOW(fd,4)=index+2;
  5510. WFIFOW(fd,6)=val;
  5511. WFIFOSET(fd,packet_len(0x188));
  5512. }
  5513. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5514. /// 0223 <result>.L <nameid>.W
  5515. /// result:
  5516. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5517. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5518. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5519. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5520. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5521. {
  5522. WFIFOHEAD(fd,packet_len(0x223));
  5523. WFIFOW(fd,0)=0x223;
  5524. WFIFOL(fd,2)=result;
  5525. WFIFOW(fd,6)=item_id;
  5526. WFIFOSET(fd,packet_len(0x223));
  5527. }
  5528. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5529. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5530. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5531. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5532. {
  5533. #if PACKETVER < 20091104
  5534. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5535. WFIFOW(fd,0) = 0x97;
  5536. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5537. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5538. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5539. WFIFOSET(fd,WFIFOW(fd,2));
  5540. #else
  5541. struct map_session_data *ssd = map_nick2sd(nick);
  5542. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5543. WFIFOW(fd,0) = 0x97;
  5544. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5545. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5546. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5547. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5548. WFIFOSET(fd,WFIFOW(fd,2));
  5549. #endif
  5550. }
  5551. /// Inform the player about the result of his whisper action
  5552. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5553. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5554. /// result:
  5555. /// 0 = success to send wisper
  5556. /// 1 = target character is not loged in
  5557. /// 2 = ignored by target
  5558. /// 3 = everyone ignored by target
  5559. void clif_wis_end(int fd, int result)
  5560. {
  5561. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5562. #if PACKETVER < 20131223
  5563. const int cmd = 0x98;
  5564. #else
  5565. const int cmd = 0x9df;
  5566. #endif
  5567. if (!sd)
  5568. return;
  5569. WFIFOHEAD(fd,packet_len(cmd));
  5570. WFIFOW(fd,0) = cmd;
  5571. WFIFOB(fd,2) = (char)result;
  5572. #if PACKETVER >= 20131223
  5573. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5574. #endif
  5575. WFIFOSET(fd,packet_len(cmd));
  5576. }
  5577. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5578. /// 0194 <char id>.L <name>.24B
  5579. void clif_solved_charname(int fd, int charid, const char* name)
  5580. {
  5581. WFIFOHEAD(fd,packet_len(0x194));
  5582. WFIFOW(fd,0)=0x194;
  5583. WFIFOL(fd,2)=charid;
  5584. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5585. WFIFOSET(fd,packet_len(0x194));
  5586. }
  5587. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5588. /// 017b <packet len>.W { <name id>.W }*
  5589. void clif_use_card(struct map_session_data *sd,int idx)
  5590. {
  5591. int i,c,ep;
  5592. int fd=sd->fd;
  5593. nullpo_retv(sd);
  5594. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5595. return;
  5596. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5597. return; //Avoid parsing invalid item indexes (no card/no item)
  5598. ep=sd->inventory_data[idx]->equip;
  5599. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5600. WFIFOW(fd,0)=0x17b;
  5601. for(i=c=0;i<MAX_INVENTORY;i++){
  5602. int j;
  5603. if(sd->inventory_data[i] == NULL)
  5604. continue;
  5605. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5606. continue;
  5607. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5608. continue;
  5609. if(sd->status.inventory[i].identify==0 ) //Not identified
  5610. continue;
  5611. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5612. continue;
  5613. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5614. continue;
  5615. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5616. if( j == sd->inventory_data[i]->slot ) // No room
  5617. continue;
  5618. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5619. continue;
  5620. WFIFOW(fd,4+c*2)=i+2;
  5621. c++;
  5622. }
  5623. if( !c ) return; // no item is available for card insertion
  5624. WFIFOW(fd,2)=4+c*2;
  5625. WFIFOSET(fd,WFIFOW(fd,2));
  5626. }
  5627. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5628. /// 017d <equip index>.W <card index>.W <result>.B
  5629. /// result:
  5630. /// 0 = success
  5631. /// 1 = failure
  5632. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5633. {
  5634. int fd;
  5635. nullpo_retv(sd);
  5636. fd=sd->fd;
  5637. WFIFOHEAD(fd,packet_len(0x17d));
  5638. WFIFOW(fd,0)=0x17d;
  5639. WFIFOW(fd,2)=idx_equip+2;
  5640. WFIFOW(fd,4)=idx_card+2;
  5641. WFIFOB(fd,6)=flag;
  5642. WFIFOSET(fd,packet_len(0x17d));
  5643. }
  5644. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5645. /// 0177 <packet len>.W { <name id>.W }*
  5646. void clif_item_identify_list(struct map_session_data *sd)
  5647. {
  5648. int i,c;
  5649. int fd;
  5650. nullpo_retv(sd);
  5651. fd=sd->fd;
  5652. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5653. WFIFOW(fd,0)=0x177;
  5654. for(i=c=0;i<MAX_INVENTORY;i++){
  5655. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5656. WFIFOW(fd,c*2+4)=i+2;
  5657. c++;
  5658. }
  5659. }
  5660. if(c > 0) {
  5661. WFIFOW(fd,2)=c*2+4;
  5662. WFIFOSET(fd,WFIFOW(fd,2));
  5663. sd->menuskill_id = MC_IDENTIFY;
  5664. sd->menuskill_val = c;
  5665. sd->state.workinprogress = WIP_DISABLE_ALL;
  5666. }
  5667. }
  5668. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5669. /// 0179 <index>.W <result>.B
  5670. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5671. {
  5672. int fd;
  5673. nullpo_retv(sd);
  5674. fd=sd->fd;
  5675. WFIFOHEAD(fd,packet_len(0x179));
  5676. WFIFOW(fd, 0)=0x179;
  5677. WFIFOW(fd, 2)=idx+2;
  5678. WFIFOB(fd, 4)=flag;
  5679. WFIFOSET(fd,packet_len(0x179));
  5680. }
  5681. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5682. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5683. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5684. {
  5685. int i,c;
  5686. int fd;
  5687. nullpo_retv(sd);
  5688. nullpo_retv(dstsd);
  5689. fd=sd->fd;
  5690. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5691. WFIFOW(fd,0)=0x1fc;
  5692. for(i=c=0;i<MAX_INVENTORY;i++){
  5693. unsigned short nameid;
  5694. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5695. WFIFOW(fd,c*13+4) = i;
  5696. WFIFOW(fd,c*13+6) = nameid;
  5697. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5698. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5699. c++;
  5700. }
  5701. }
  5702. if(c > 0) {
  5703. WFIFOW(fd,2)=c*13+4;
  5704. WFIFOSET(fd,WFIFOW(fd,2));
  5705. sd->menuskill_id = BS_REPAIRWEAPON;
  5706. sd->menuskill_val = dstsd->bl.id;
  5707. sd->menuskill_val2 = lv;
  5708. }else
  5709. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5710. }
  5711. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5712. /// 01fe <index>.W <result>.B
  5713. /// index:
  5714. /// ignored (inventory index)
  5715. /// result:
  5716. /// 0 = Item repair success.
  5717. /// 1 = Item repair failure.
  5718. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5719. {
  5720. int fd;
  5721. nullpo_retv(sd);
  5722. fd = sd->fd;
  5723. WFIFOHEAD(fd,packet_len(0x1fe));
  5724. WFIFOW(fd, 0)=0x1fe;
  5725. WFIFOW(fd, 2)=idx+2;
  5726. WFIFOB(fd, 4)=flag;
  5727. WFIFOSET(fd,packet_len(0x1fe));
  5728. }
  5729. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5730. /// 02bb <equip location>.W <account id>.L
  5731. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5732. {
  5733. int fd = sd->fd;
  5734. WFIFOHEAD(fd,packet_len(0x2bb));
  5735. WFIFOW(fd,0) = 0x2bb;
  5736. WFIFOW(fd,2) = position;
  5737. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5738. WFIFOSET(fd,packet_len(0x2bb));
  5739. }
  5740. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5741. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5742. void clif_item_refine_list(struct map_session_data *sd)
  5743. {
  5744. int i,c;
  5745. int fd;
  5746. uint16 skill_lv;
  5747. int refine_item[5];
  5748. nullpo_retv(sd);
  5749. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5750. fd=sd->fd;
  5751. refine_item[0] = -1;
  5752. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5753. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5754. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5755. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5756. WFIFOW(fd,0)=0x221;
  5757. for(i=c=0;i<MAX_INVENTORY;i++){
  5758. unsigned char wlv;
  5759. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5760. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5761. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5762. WFIFOW(fd,c*13+ 4)=i+2;
  5763. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5764. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5765. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5766. c++;
  5767. }
  5768. }
  5769. WFIFOW(fd,2)=c*13+4;
  5770. WFIFOSET(fd,WFIFOW(fd,2));
  5771. if (c > 0) {
  5772. sd->menuskill_id = WS_WEAPONREFINE;
  5773. sd->menuskill_val = skill_lv;
  5774. }
  5775. }
  5776. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5777. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5778. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5779. {
  5780. int fd;
  5781. nullpo_retv(sd);
  5782. fd=sd->fd;
  5783. WFIFOHEAD(fd,packet_len(0x147));
  5784. WFIFOW(fd, 0)=0x147;
  5785. WFIFOW(fd, 2)=skill_id;
  5786. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5787. WFIFOW(fd, 6)=0;
  5788. WFIFOW(fd, 8)=skill_lv;
  5789. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5790. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5791. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5792. WFIFOB(fd,38)=0;
  5793. WFIFOSET(fd,packet_len(0x147));
  5794. }
  5795. /// Adds an item to character's cart.
  5796. /// 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)
  5797. /// 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)
  5798. /// 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)
  5799. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5800. {
  5801. #if PACKETVER < 5
  5802. const int cmd = 0x124;
  5803. #elif PACKETVER < 20150226
  5804. const int cmd = 0x1c5;
  5805. #else
  5806. const int cmd = 0xa0b;
  5807. #endif
  5808. int view,fd;
  5809. unsigned char *buf;
  5810. int offset = 0;
  5811. nullpo_retv(sd);
  5812. fd=sd->fd;
  5813. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5814. return;
  5815. WFIFOHEAD(fd,packet_len(cmd));
  5816. buf=WFIFOP(fd,0);
  5817. WBUFW(buf,0)=cmd;
  5818. WBUFW(buf,2)=n+2;
  5819. WBUFL(buf,4)=amount;
  5820. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5821. WBUFW(buf,8)=view;
  5822. else
  5823. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5824. #if PACKETVER >= 5
  5825. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5826. offset += 1;
  5827. #endif
  5828. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5829. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5830. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5831. clif_addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5832. #if PACKETVER >= 20150226
  5833. clif_add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5834. #endif
  5835. WFIFOSET(fd,packet_len(cmd));
  5836. }
  5837. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5838. /* Acknowledge an item have been added to cart
  5839. * 012c <result>B
  5840. * result :
  5841. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5842. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5843. */
  5844. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5845. {
  5846. int fd;
  5847. unsigned char *buf;
  5848. nullpo_retv(sd);
  5849. fd = sd->fd;
  5850. buf = WFIFOP(fd,0);
  5851. WBUFW(buf,0) = 0x12c;
  5852. WBUFB(buf,2) = flag;
  5853. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5854. }
  5855. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5856. void clif_bank_open(struct map_session_data *sd){
  5857. int fd;
  5858. nullpo_retv(sd);
  5859. fd = sd->fd;
  5860. WFIFOHEAD(fd,4);
  5861. WFIFOW(fd,0) = 0x09b7;
  5862. WFIFOW(fd,2) = 0;
  5863. WFIFOSET(fd,4);
  5864. }
  5865. /*
  5866. * Request to Open the banking system
  5867. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5868. */
  5869. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5870. //TODO check if preventing trade or stuff like that
  5871. //also mark something in case char ain't available for saving, should we check now ?
  5872. nullpo_retv(sd);
  5873. if( !battle_config.feature_banking ) {
  5874. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5875. return;
  5876. }
  5877. else {
  5878. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5879. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5880. if(sd->status.account_id == aid){
  5881. sd->state.banking = 1;
  5882. //request save ?
  5883. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5884. //on succes open bank ?
  5885. clif_bank_open(sd);
  5886. }
  5887. }
  5888. }
  5889. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5890. void clif_bank_close(struct map_session_data *sd){
  5891. int fd;
  5892. nullpo_retv(sd);
  5893. fd = sd->fd;
  5894. WFIFOHEAD(fd,4);
  5895. WFIFOW(fd,0) = 0x09B9;
  5896. WFIFOW(fd,2) = 0;
  5897. WFIFOSET(fd,4);
  5898. }
  5899. /*
  5900. * Request to close the banking system
  5901. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5902. */
  5903. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5904. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5905. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5906. nullpo_retv(sd);
  5907. if( !battle_config.feature_banking ) {
  5908. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5909. //still allow to go trough to not stuck player if we have disable it while they was in
  5910. }
  5911. if(sd->status.account_id == aid){
  5912. sd->state.banking = 0;
  5913. clif_bank_close(sd);
  5914. }
  5915. }
  5916. /*
  5917. * Display how much we got in bank (I suppose)
  5918. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5919. */
  5920. void clif_Bank_Check(struct map_session_data* sd) {
  5921. unsigned char buf[13];
  5922. struct s_packet_db* info;
  5923. int16 len;
  5924. int cmd = 0;
  5925. nullpo_retv(sd);
  5926. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5927. if(!cmd) cmd = 0x09A6; //default
  5928. info = &packet_db[sd->packet_ver][cmd];
  5929. len = info->len;
  5930. if(!len) return; //version as packet disable
  5931. // sd->state.banking = 1; //mark opening and closing
  5932. WBUFW(buf,0) = cmd;
  5933. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5934. WBUFW(buf,info->pos[1]) = 0; //reason
  5935. clif_send(buf,len,&sd->bl,SELF);
  5936. }
  5937. /*
  5938. * Requesting the data in bank
  5939. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5940. */
  5941. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5942. nullpo_retv(sd);
  5943. if( !battle_config.feature_banking ) {
  5944. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5945. return;
  5946. }
  5947. else {
  5948. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5949. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5950. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5951. clif_Bank_Check(sd);
  5952. }
  5953. }
  5954. /*
  5955. * Acknowledge of deposit some money in bank
  5956. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5957. */
  5958. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5959. unsigned char buf[17];
  5960. struct s_packet_db* info;
  5961. int16 len;
  5962. int cmd =0;
  5963. nullpo_retv(sd);
  5964. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5965. if(!cmd) cmd = 0x09A8;
  5966. info = &packet_db[sd->packet_ver][cmd];
  5967. len = info->len;
  5968. if(!len) return; //version as packet disable
  5969. WBUFW(buf,0) = cmd;
  5970. WBUFW(buf,info->pos[0]) = (short)reason;
  5971. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5972. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5973. clif_send(buf,len,&sd->bl,SELF);
  5974. }
  5975. /*
  5976. * Request saving some money in bank
  5977. * @author : original [Yommy/Hercules]
  5978. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5979. */
  5980. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5981. nullpo_retv(sd);
  5982. if( !battle_config.feature_banking ) {
  5983. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5984. return;
  5985. }
  5986. else {
  5987. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5988. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5989. int money = RFIFOL(fd,info->pos[1]);
  5990. if(sd->status.account_id == aid){
  5991. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5992. clif_bank_deposit(sd,reason);
  5993. }
  5994. }
  5995. }
  5996. /*
  5997. * Acknowledge of withdrawing some money from bank
  5998. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5999. */
  6000. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6001. unsigned char buf[17];
  6002. struct s_packet_db* info;
  6003. int16 len;
  6004. int cmd;
  6005. nullpo_retv(sd);
  6006. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  6007. if(!cmd) cmd = 0x09AA;
  6008. info = &packet_db[sd->packet_ver][cmd];
  6009. len = info->len;
  6010. if(!len) return; //version as packet disable
  6011. WBUFW(buf,0) = cmd;
  6012. WBUFW(buf,info->pos[0]) = (short)reason;
  6013. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6014. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6015. clif_send(buf,len,&sd->bl,SELF);
  6016. }
  6017. /*
  6018. * Request Withdrawing some money from bank
  6019. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6020. */
  6021. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6022. nullpo_retv(sd);
  6023. if( !battle_config.feature_banking ) {
  6024. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  6025. return;
  6026. }
  6027. else {
  6028. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  6029. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6030. int money = RFIFOL(fd,info->pos[1]);
  6031. if(sd->status.account_id == aid){
  6032. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6033. clif_bank_withdraw(sd,reason);
  6034. }
  6035. }
  6036. }
  6037. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6038. /// 0125 <index>.W <amount>.L
  6039. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6040. {
  6041. int fd;
  6042. nullpo_retv(sd);
  6043. fd=sd->fd;
  6044. WFIFOHEAD(fd,packet_len(0x125));
  6045. WFIFOW(fd,0)=0x125;
  6046. WFIFOW(fd,2)=n+2;
  6047. WFIFOL(fd,4)=amount;
  6048. WFIFOSET(fd,packet_len(0x125));
  6049. }
  6050. /// Opens the shop creation menu (ZC_OPENSTORE).
  6051. /// 012d <num>.W
  6052. /// num:
  6053. /// number of allowed item slots
  6054. void clif_openvendingreq(struct map_session_data* sd, int num)
  6055. {
  6056. int fd;
  6057. nullpo_retv(sd);
  6058. fd = sd->fd;
  6059. WFIFOHEAD(fd,packet_len(0x12d));
  6060. WFIFOW(fd,0) = 0x12d;
  6061. WFIFOW(fd,2) = num;
  6062. WFIFOSET(fd,packet_len(0x12d));
  6063. }
  6064. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6065. /// 0131 <owner id>.L <message>.80B
  6066. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6067. {
  6068. unsigned char buf[128];
  6069. nullpo_retv(bl);
  6070. WBUFW(buf,0) = 0x131;
  6071. WBUFL(buf,2) = bl->id;
  6072. safestrncpy((char*)WBUFP(buf,6), message, 80);
  6073. if( fd ) {
  6074. WFIFOHEAD(fd,packet_len(0x131));
  6075. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6076. WFIFOSET(fd,packet_len(0x131));
  6077. } else {
  6078. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6079. }
  6080. }
  6081. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6082. /// 0132 <owner id>.L
  6083. void clif_closevendingboard(struct block_list* bl, int fd)
  6084. {
  6085. unsigned char buf[16];
  6086. nullpo_retv(bl);
  6087. WBUFW(buf,0) = 0x132;
  6088. WBUFL(buf,2) = bl->id;
  6089. if( fd ) {
  6090. WFIFOHEAD(fd,packet_len(0x132));
  6091. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6092. WFIFOSET(fd,packet_len(0x132));
  6093. } else {
  6094. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6095. }
  6096. }
  6097. /// Sends a list of items in a shop.
  6098. /// 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)
  6099. /// 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)
  6100. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6101. {
  6102. int i,fd;
  6103. int count;
  6104. struct map_session_data* vsd;
  6105. #if PACKETVER < 20100105
  6106. const int cmd = 0x133;
  6107. const int offset = 8;
  6108. #else
  6109. const int cmd = 0x800;
  6110. const int offset = 12;
  6111. #endif
  6112. #if PACKETVER < 20150226
  6113. const int item_length = 22;
  6114. #else
  6115. const int item_length = 47;
  6116. #endif
  6117. nullpo_retv(sd);
  6118. nullpo_retv(vending);
  6119. nullpo_retv(vsd=map_id2sd(id));
  6120. fd = sd->fd;
  6121. count = vsd->vend_num;
  6122. WFIFOHEAD(fd, offset+count*item_length);
  6123. WFIFOW(fd,0) = cmd;
  6124. WFIFOW(fd,2) = offset+count*item_length;
  6125. WFIFOL(fd,4) = id;
  6126. #if PACKETVER >= 20100105
  6127. WFIFOL(fd,8) = vsd->vender_id;
  6128. #endif
  6129. for( i = 0; i < count; i++ )
  6130. {
  6131. int index = vending[i].index;
  6132. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  6133. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6134. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6135. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6136. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6137. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  6138. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  6139. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  6140. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  6141. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  6142. #if PACKETVER >= 20150226
  6143. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  6144. #endif
  6145. }
  6146. WFIFOSET(fd,WFIFOW(fd,2));
  6147. }
  6148. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6149. /// 0135 <index>.W <amount>.W <result>.B
  6150. /// result:
  6151. /// 0 = success
  6152. /// 1 = not enough zeny
  6153. /// 2 = overweight
  6154. /// 4 = out of stock
  6155. /// 5 = "cannot use an npc shop while in a trade"
  6156. /// 6 = Because the store information was incorrect the item was not purchased.
  6157. /// 7 = No sales information.
  6158. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6159. {
  6160. int fd;
  6161. nullpo_retv(sd);
  6162. fd = sd->fd;
  6163. WFIFOHEAD(fd,packet_len(0x135));
  6164. WFIFOW(fd,0) = 0x135;
  6165. WFIFOW(fd,2) = index+2;
  6166. WFIFOW(fd,4) = amount;
  6167. WFIFOB(fd,6) = fail;
  6168. WFIFOSET(fd,packet_len(0x135));
  6169. }
  6170. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6171. /// 0a28 <Result>.B
  6172. /// result:
  6173. /// 0 = Successed
  6174. /// 1 = Failed
  6175. void clif_openvending_ack(struct map_session_data* sd, int result)
  6176. {
  6177. int fd;
  6178. nullpo_retv(sd);
  6179. fd = sd->fd;
  6180. WFIFOHEAD(fd, 3);
  6181. WFIFOW(fd,0) = 0xa28;
  6182. WFIFOB(fd,2) = result;
  6183. WFIFOSET(fd, 3);
  6184. }
  6185. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6186. /// 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 }*
  6187. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6188. {
  6189. int i,fd;
  6190. int count;
  6191. #if PACKETVER < 20150226
  6192. const int item_length = 22;
  6193. #else
  6194. const int item_length = 47;
  6195. #endif
  6196. nullpo_retv(sd);
  6197. fd = sd->fd;
  6198. count = sd->vend_num;
  6199. WFIFOHEAD(fd, 8+count*item_length);
  6200. WFIFOW(fd,0) = 0x136;
  6201. WFIFOW(fd,2) = 8+count*item_length;
  6202. WFIFOL(fd,4) = id;
  6203. for( i = 0; i < count; i++ ) {
  6204. int index = vending[i].index;
  6205. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  6206. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6207. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6208. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6209. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6210. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  6211. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  6212. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  6213. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  6214. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  6215. #if PACKETVER >= 20150226
  6216. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->status.cart[index]);
  6217. #endif
  6218. }
  6219. WFIFOSET(fd,WFIFOW(fd,2));
  6220. #if PACKETVER >= 20141022
  6221. /// 0 = Successed
  6222. /// 1 = Failed
  6223. clif_openvending_ack(sd, 0);
  6224. #endif
  6225. }
  6226. /// Inform merchant that someone has bought an item.
  6227. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6228. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6229. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6230. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6231. const int cmd = 0x137;
  6232. #else
  6233. const int cmd = 0x9e5;
  6234. #endif
  6235. int fd = sd->fd;
  6236. nullpo_retv(sd);
  6237. WFIFOHEAD(fd,packet_len(cmd));
  6238. WFIFOW(fd,0) = cmd;
  6239. WFIFOW(fd,2) = index+2;
  6240. WFIFOW(fd,4) = amount;
  6241. #if PACKETVER >= 20141016
  6242. WFIFOL(fd,6) = char_id; // GID
  6243. WFIFOL(fd,10) = (int)time(NULL); // Date
  6244. WFIFOL(fd,14) = zeny; // zeny
  6245. #endif
  6246. WFIFOSET(fd,packet_len(cmd));
  6247. }
  6248. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6249. /// 00fa <result>.B
  6250. /// result:
  6251. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6252. /// 1 = MsgStringTable[78]="party name already exists"
  6253. /// 2 = MsgStringTable[79]="already in a party"
  6254. /// 3 = cannot organize parties on this map
  6255. /// ? = nothing
  6256. void clif_party_created(struct map_session_data *sd,int result)
  6257. {
  6258. int fd;
  6259. nullpo_retv(sd);
  6260. fd=sd->fd;
  6261. WFIFOHEAD(fd,packet_len(0xfa));
  6262. WFIFOW(fd,0)=0xfa;
  6263. WFIFOB(fd,2)=result;
  6264. WFIFOSET(fd,packet_len(0xfa));
  6265. }
  6266. /// Adds new member to a party.
  6267. /// 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)
  6268. /// 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)
  6269. /// role:
  6270. /// 0 = leader
  6271. /// 1 = normal
  6272. /// state:
  6273. /// 0 = connected
  6274. /// 1 = disconnected
  6275. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6276. {
  6277. unsigned char buf[81];
  6278. int i;
  6279. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6280. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6281. } else {
  6282. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6283. }
  6284. if (i >= MAX_PARTY) return; //Should never happen...
  6285. sd = p->data[i].sd;
  6286. WBUFW(buf, 0) = 0x1e9;
  6287. WBUFL(buf, 2) = sd->status.account_id;
  6288. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6289. WBUFW(buf,10) = sd->bl.x;
  6290. WBUFW(buf,12) = sd->bl.y;
  6291. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6292. safestrncpy((char*)WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6293. safestrncpy((char*)WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6294. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6295. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6296. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6297. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6298. }
  6299. /// Sends party information (ZC_GROUP_LIST).
  6300. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6301. /// role:
  6302. /// 0 = leader
  6303. /// 1 = normal
  6304. /// state:
  6305. /// 0 = connected
  6306. /// 1 = disconnected
  6307. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6308. {
  6309. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6310. struct map_session_data* party_sd = NULL;
  6311. int i, c;
  6312. nullpo_retv(p);
  6313. WBUFW(buf,0) = 0xfb;
  6314. safestrncpy((char*)WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6315. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6316. {
  6317. struct party_member* m = &p->party.member[i];
  6318. if(!m->account_id) continue;
  6319. if(party_sd == NULL) party_sd = p->data[i].sd;
  6320. WBUFL(buf,28+c*46) = m->account_id;
  6321. safestrncpy((char*)WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6322. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6323. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6324. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6325. c++;
  6326. }
  6327. WBUFW(buf,2) = 28+c*46;
  6328. if(sd) { // send only to self
  6329. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6330. } else if (party_sd) { // send to whole party
  6331. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6332. }
  6333. }
  6334. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6335. /// 02c9 <flag>.B
  6336. /// flag:
  6337. /// 0 = allow party invites
  6338. /// 1 = auto-deny party invites
  6339. void clif_partyinvitationstate(struct map_session_data* sd)
  6340. {
  6341. int fd;
  6342. nullpo_retv(sd);
  6343. fd = sd->fd;
  6344. WFIFOHEAD(fd, packet_len(0x2c9));
  6345. WFIFOW(fd, 0) = 0x2c9;
  6346. WFIFOB(fd, 2) = 0; // not implemented
  6347. WFIFOSET(fd, packet_len(0x2c9));
  6348. }
  6349. /// Party invitation request.
  6350. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6351. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6352. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6353. {
  6354. #if PACKETVER < 20070821
  6355. const int cmd = 0xfe;
  6356. #else
  6357. const int cmd = 0x2c6;
  6358. #endif
  6359. int fd;
  6360. struct party_data *p;
  6361. nullpo_retv(sd);
  6362. nullpo_retv(tsd);
  6363. fd=tsd->fd;
  6364. if( (p=party_search(sd->status.party_id))==NULL )
  6365. return;
  6366. WFIFOHEAD(fd,packet_len(cmd));
  6367. WFIFOW(fd,0)=cmd;
  6368. WFIFOL(fd,2)=sd->status.party_id;
  6369. safestrncpy((char*)WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6370. WFIFOSET(fd,packet_len(cmd));
  6371. }
  6372. /// Party invite result.
  6373. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6374. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6375. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6376. {
  6377. int fd;
  6378. nullpo_retv(sd);
  6379. fd=sd->fd;
  6380. #if PACKETVER < 20070904
  6381. if( reply == PARTY_REPLY_OFFLINE ) {
  6382. clif_displaymessage(fd, msg_txt(sd,3));
  6383. return;
  6384. }
  6385. #endif
  6386. #if PACKETVER < 20070821
  6387. WFIFOHEAD(fd,packet_len(0xfd));
  6388. WFIFOW(fd,0) = 0xfd;
  6389. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6390. WFIFOB(fd,26) = reply;
  6391. WFIFOSET(fd,packet_len(0xfd));
  6392. #else
  6393. WFIFOHEAD(fd,packet_len(0x2c5));
  6394. WFIFOW(fd,0) = 0x2c5;
  6395. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6396. WFIFOL(fd,26) = reply;
  6397. WFIFOSET(fd,packet_len(0x2c5));
  6398. #endif
  6399. }
  6400. /// Updates party settings.
  6401. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6402. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6403. /// exp option:
  6404. /// 0 = exp sharing disabled
  6405. /// 1 = exp sharing enabled
  6406. /// 2 = cannot change exp sharing
  6407. ///
  6408. /// flag:
  6409. /// 0 = send to party
  6410. /// 1 = send to sd
  6411. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6412. {
  6413. unsigned char buf[16];
  6414. #if PACKETVER < 20090603
  6415. const int cmd = 0x101;
  6416. #else
  6417. const int cmd = 0x7d8;
  6418. #endif
  6419. nullpo_retv(p);
  6420. if(!sd && flag==0){
  6421. int i;
  6422. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6423. if (i < MAX_PARTY)
  6424. sd = p->data[i].sd;
  6425. }
  6426. if(!sd) return;
  6427. WBUFW(buf,0)=cmd;
  6428. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6429. #if PACKETVER >= 20090603
  6430. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6431. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6432. #endif
  6433. if(flag==0)
  6434. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6435. else
  6436. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6437. }
  6438. /**
  6439. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6440. * @param sd Send the notification for this player
  6441. * @param account_id Account ID of kicked member
  6442. * @param name Name of kicked member
  6443. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6444. * @param target Send target
  6445. **/
  6446. void clif_party_withdraw(struct map_session_data *sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target) {
  6447. unsigned char buf[2+4+NAME_LENGTH+1];
  6448. if (!sd)
  6449. return;
  6450. WBUFW(buf,0) = 0x0105;
  6451. WBUFL(buf,2) = account_id;
  6452. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6453. WBUFB(buf,6+NAME_LENGTH) = result;
  6454. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6455. }
  6456. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6457. /// 0109 <packet len>.W <account id>.L <message>.?B
  6458. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6459. {
  6460. struct map_session_data *sd;
  6461. int i;
  6462. nullpo_retv(p);
  6463. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6464. if(i < MAX_PARTY){
  6465. unsigned char buf[1024];
  6466. if( len > sizeof(buf)-8 )
  6467. {
  6468. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6469. len = sizeof(buf)-8;
  6470. }
  6471. sd = p->data[i].sd;
  6472. WBUFW(buf,0)=0x109;
  6473. WBUFW(buf,2)=len+8;
  6474. WBUFL(buf,4)=account_id;
  6475. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6476. clif_send(buf,len+8,&sd->bl,PARTY);
  6477. }
  6478. }
  6479. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6480. /// 0107 <account id>.L <x>.W <y>.W
  6481. void clif_party_xy(struct map_session_data *sd)
  6482. {
  6483. unsigned char buf[16];
  6484. nullpo_retv(sd);
  6485. WBUFW(buf,0)=0x107;
  6486. WBUFL(buf,2)=sd->status.account_id;
  6487. WBUFW(buf,6)=sd->bl.x;
  6488. WBUFW(buf,8)=sd->bl.y;
  6489. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6490. }
  6491. /*==========================================
  6492. * Sends x/y dot to a single fd. [Skotlex]
  6493. *------------------------------------------*/
  6494. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6495. {
  6496. WFIFOHEAD(fd,packet_len(0x107));
  6497. WFIFOW(fd,0)=0x107;
  6498. WFIFOL(fd,2)=sd->status.account_id;
  6499. WFIFOW(fd,6)=sd->bl.x;
  6500. WFIFOW(fd,8)=sd->bl.y;
  6501. WFIFOSET(fd,packet_len(0x107));
  6502. }
  6503. /// Updates HP bar of a party member.
  6504. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6505. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6506. void clif_party_hp(struct map_session_data *sd)
  6507. {
  6508. unsigned char buf[16];
  6509. #if PACKETVER < 20100126
  6510. const int cmd = 0x106;
  6511. #else
  6512. const int cmd = 0x80e;
  6513. #endif
  6514. nullpo_retv(sd);
  6515. WBUFW(buf,0)=cmd;
  6516. WBUFL(buf,2)=sd->status.account_id;
  6517. #if PACKETVER < 20100126
  6518. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6519. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6520. WBUFW(buf,8) = 100;
  6521. } else {
  6522. WBUFW(buf,6) = sd->battle_status.hp;
  6523. WBUFW(buf,8) = sd->battle_status.max_hp;
  6524. }
  6525. #else
  6526. WBUFL(buf,6) = sd->battle_status.hp;
  6527. WBUFL(buf,10) = sd->battle_status.max_hp;
  6528. #endif
  6529. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6530. }
  6531. /*==========================================
  6532. * Sends HP bar to a single fd. [Skotlex]
  6533. *------------------------------------------*/
  6534. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6535. {
  6536. #if PACKETVER < 20100126
  6537. const int cmd = 0x106;
  6538. #else
  6539. const int cmd = 0x80e;
  6540. #endif
  6541. WFIFOHEAD(fd,packet_len(cmd));
  6542. WFIFOW(fd,0) = cmd;
  6543. WFIFOL(fd,2) = id;
  6544. #if PACKETVER < 20100126
  6545. if( maxhp > INT16_MAX )
  6546. {// To correctly display the %hp bar. [Skotlex]
  6547. WFIFOW(fd,6) = hp/(maxhp/100);
  6548. WFIFOW(fd,8) = 100;
  6549. } else {
  6550. WFIFOW(fd,6) = hp;
  6551. WFIFOW(fd,8) = maxhp;
  6552. }
  6553. #else
  6554. WFIFOL(fd,6) = hp;
  6555. WFIFOL(fd,10) = maxhp;
  6556. #endif
  6557. WFIFOSET(fd, packet_len(cmd));
  6558. }
  6559. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6560. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6561. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6562. {
  6563. int fd;
  6564. nullpo_retv(sd);
  6565. nullpo_retv(bl);
  6566. fd=sd->fd;
  6567. WFIFOHEAD(fd,packet_len(0x139));
  6568. WFIFOW(fd, 0)=0x139;
  6569. WFIFOL(fd, 2)=bl->id;
  6570. WFIFOW(fd, 6)=bl->x;
  6571. WFIFOW(fd, 8)=bl->y;
  6572. WFIFOW(fd,10)=sd->bl.x;
  6573. WFIFOW(fd,12)=sd->bl.y;
  6574. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6575. WFIFOSET(fd,packet_len(0x139));
  6576. }
  6577. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6578. /// 018f <result>.W <name id>.W
  6579. /// result:
  6580. /// 0 = success
  6581. /// 1 = failure
  6582. /// 2 = success (alchemist)
  6583. /// 3 = failure (alchemist)
  6584. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6585. {
  6586. int view,fd;
  6587. nullpo_retv(sd);
  6588. fd = sd->fd;
  6589. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6590. WFIFOHEAD(fd,packet_len(0x18f));
  6591. WFIFOW(fd, 0)=0x18f;
  6592. WFIFOW(fd, 2)=flag;
  6593. if((view = itemdb_viewid(nameid)) > 0)
  6594. WFIFOW(fd, 4)=view;
  6595. else
  6596. WFIFOW(fd, 4)=nameid;
  6597. WFIFOSET(fd,packet_len(0x18f));
  6598. }
  6599. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6600. /// 019e
  6601. void clif_catch_process(struct map_session_data *sd)
  6602. {
  6603. int fd;
  6604. nullpo_retv(sd);
  6605. fd=sd->fd;
  6606. WFIFOHEAD(fd,packet_len(0x19e));
  6607. WFIFOW(fd,0)=0x19e;
  6608. WFIFOSET(fd,packet_len(0x19e));
  6609. }
  6610. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6611. /// 01a0 <result>.B
  6612. /// 0 = failure
  6613. /// 1 = success
  6614. void clif_pet_roulette(struct map_session_data *sd,int data)
  6615. {
  6616. int fd;
  6617. nullpo_retv(sd);
  6618. fd=sd->fd;
  6619. WFIFOHEAD(fd,packet_len(0x1a0));
  6620. WFIFOW(fd,0)=0x1a0;
  6621. WFIFOB(fd,2)=data;
  6622. WFIFOSET(fd,packet_len(0x1a0));
  6623. }
  6624. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6625. /// 01a6 <packet len>.W { <index>.W }*
  6626. void clif_sendegg(struct map_session_data *sd)
  6627. {
  6628. int i,n=0,fd;
  6629. nullpo_retv(sd);
  6630. fd=sd->fd;
  6631. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6632. clif_displaymessage(fd, msg_txt(sd,666));
  6633. return;
  6634. }
  6635. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6636. WFIFOW(fd,0)=0x1a6;
  6637. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6638. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6639. sd->inventory_data[i]->type!=IT_PETEGG ||
  6640. sd->status.inventory[i].amount<=0)
  6641. continue;
  6642. WFIFOW(fd,n*2+4)=i+2;
  6643. n++;
  6644. }
  6645. WFIFOW(fd,2)=4+n*2;
  6646. WFIFOSET(fd,WFIFOW(fd,2));
  6647. sd->menuskill_id = SA_TAMINGMONSTER;
  6648. sd->menuskill_val = -1;
  6649. }
  6650. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6651. /// 01a4 <type>.B <id>.L <data>.L
  6652. /// type:
  6653. /// 0 = pre-init (data = 0)
  6654. /// 1 = intimacy (data = 0~4)
  6655. /// 2 = hunger (data = 0~4)
  6656. /// 3 = accessory
  6657. /// 4 = performance (data = 1~3: normal, 4: special)
  6658. /// 5 = hairstyle
  6659. ///
  6660. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6661. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6662. {
  6663. uint8 buf[16];
  6664. nullpo_retv(pd);
  6665. WBUFW(buf,0) = 0x1a4;
  6666. WBUFB(buf,2) = type;
  6667. WBUFL(buf,3) = pd->bl.id;
  6668. WBUFL(buf,7) = param;
  6669. if (sd)
  6670. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6671. else
  6672. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6673. }
  6674. /// Pet's base data (ZC_PROPERTY_PET).
  6675. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6676. void clif_send_petstatus(struct map_session_data *sd)
  6677. {
  6678. int fd;
  6679. struct s_pet *pet;
  6680. nullpo_retv(sd);
  6681. nullpo_retv(sd->pd);
  6682. fd=sd->fd;
  6683. pet = &sd->pd->pet;
  6684. WFIFOHEAD(fd,packet_len(0x1a2));
  6685. WFIFOW(fd,0)=0x1a2;
  6686. safestrncpy((char*)WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6687. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6688. WFIFOW(fd,27)=pet->level;
  6689. WFIFOW(fd,29)=pet->hungry;
  6690. WFIFOW(fd,31)=pet->intimate;
  6691. WFIFOW(fd,33)=pet->equip;
  6692. #if PACKETVER >= 20081126
  6693. WFIFOW(fd,35)=pet->class_;
  6694. #endif
  6695. WFIFOSET(fd,packet_len(0x1a2));
  6696. }
  6697. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6698. /// 01aa <id>.L <data>.L
  6699. /// data:
  6700. /// @see CZ_PET_ACT.
  6701. void clif_pet_emotion(struct pet_data *pd,int param)
  6702. {
  6703. unsigned char buf[16];
  6704. nullpo_retv(pd);
  6705. memset(buf,0,packet_len(0x1aa));
  6706. WBUFW(buf,0)=0x1aa;
  6707. WBUFL(buf,2)=pd->bl.id;
  6708. if(param >= 100 && pd->petDB->talk_convert_class) {
  6709. if(pd->petDB->talk_convert_class < 0)
  6710. return;
  6711. else if(pd->petDB->talk_convert_class > 0) {
  6712. // replace mob_id component of talk/act data
  6713. param -= (pd->pet.class_ - 100)*100;
  6714. param += (pd->petDB->talk_convert_class - 100)*100;
  6715. }
  6716. }
  6717. WBUFL(buf,6)=param;
  6718. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6719. }
  6720. /// Result of request to feed a pet (ZC_FEED_PET).
  6721. /// 01a3 <result>.B <name id>.W
  6722. /// result:
  6723. /// 0 = failure
  6724. /// 1 = success
  6725. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6726. {
  6727. int fd;
  6728. nullpo_retv(sd);
  6729. fd=sd->fd;
  6730. WFIFOHEAD(fd,packet_len(0x1a3));
  6731. WFIFOW(fd,0)=0x1a3;
  6732. WFIFOB(fd,2)=fail;
  6733. WFIFOW(fd,3)=foodid;
  6734. WFIFOSET(fd,packet_len(0x1a3));
  6735. }
  6736. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6737. /// 01cd { <skill id>.L }*7
  6738. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6739. {
  6740. int fd;
  6741. nullpo_retv(sd);
  6742. fd=sd->fd;
  6743. WFIFOHEAD(fd,packet_len(0x1cd));
  6744. WFIFOW(fd, 0)=0x1cd;
  6745. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6746. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6747. else
  6748. WFIFOL(fd,2)= 0x00000000;
  6749. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6750. WFIFOL(fd,6)= MG_COLDBOLT;
  6751. else
  6752. WFIFOL(fd,6)= 0x00000000;
  6753. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6754. WFIFOL(fd,10)= MG_FIREBOLT;
  6755. else
  6756. WFIFOL(fd,10)= 0x00000000;
  6757. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6758. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6759. else
  6760. WFIFOL(fd,14)= 0x00000000;
  6761. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6762. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6763. else
  6764. WFIFOL(fd,18)= 0x00000000;
  6765. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6766. WFIFOL(fd,22)= MG_FIREBALL;
  6767. else
  6768. WFIFOL(fd,22)= 0x00000000;
  6769. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6770. WFIFOL(fd,26)= MG_FROSTDIVER;
  6771. else
  6772. WFIFOL(fd,26)= 0x00000000;
  6773. WFIFOSET(fd,packet_len(0x1cd));
  6774. sd->menuskill_id = SA_AUTOSPELL;
  6775. sd->menuskill_val = skill_lv;
  6776. }
  6777. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6778. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6779. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6780. {
  6781. unsigned char buf[56];
  6782. nullpo_retv(src);
  6783. memset(buf,0,packet_len(0x1cf));
  6784. WBUFW(buf,0) = 0x1cf;
  6785. WBUFL(buf,2) = src->id;
  6786. if( src->type == BL_MER )
  6787. {
  6788. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6789. if( md && md->master && md->devotion_flag )
  6790. WBUFL(buf,6) = md->master->bl.id;
  6791. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6792. }
  6793. else
  6794. {
  6795. int i;
  6796. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6797. if( sd == NULL )
  6798. return;
  6799. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6800. WBUFL(buf,6+4*i) = sd->devotion[i];
  6801. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6802. }
  6803. if( tsd )
  6804. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6805. else
  6806. clif_send(buf, packet_len(0x1cf), src, AREA);
  6807. }
  6808. /*==========================================
  6809. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6810. * Notifies clients in an area of an object's spirits.
  6811. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6812. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6813. *------------------------------------------*/
  6814. void clif_spiritball(struct block_list *bl) {
  6815. unsigned char buf[16];
  6816. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6817. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6818. nullpo_retv(bl);
  6819. WBUFW(buf, 0) = 0x1d0;
  6820. WBUFL(buf, 2) = bl->id;
  6821. WBUFW(buf, 6) = 0; //init to 0
  6822. switch(bl->type){
  6823. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6824. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6825. }
  6826. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6827. }
  6828. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6829. /// 01d2 <account id>.L <delay>.L
  6830. void clif_combo_delay(struct block_list *bl,int wait)
  6831. {
  6832. unsigned char buf[32];
  6833. nullpo_retv(bl);
  6834. WBUFW(buf,0)=0x1d2;
  6835. WBUFL(buf,2)=bl->id;
  6836. WBUFL(buf,6)=wait;
  6837. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6838. }
  6839. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6840. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6841. /// flag:
  6842. /// 0 = inactive
  6843. /// 1 = active
  6844. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6845. {
  6846. unsigned char buf[32];
  6847. nullpo_retv(src);
  6848. WBUFW(buf,0)=0x1d1;
  6849. WBUFL(buf,2)=src->id;
  6850. WBUFL(buf,6)=dst_id;
  6851. WBUFL(buf,10)=active;
  6852. clif_send(buf,packet_len(0x1d1),src,AREA);
  6853. }
  6854. /// MVP effect (ZC_MVP).
  6855. /// 010c <account id>.L
  6856. void clif_mvp_effect(struct map_session_data *sd)
  6857. {
  6858. unsigned char buf[16];
  6859. nullpo_retv(sd);
  6860. WBUFW(buf,0)=0x10c;
  6861. WBUFL(buf,2)=sd->bl.id;
  6862. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6863. }
  6864. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6865. /// 010a <name id>.W
  6866. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6867. {
  6868. int view,fd;
  6869. nullpo_retv(sd);
  6870. fd=sd->fd;
  6871. WFIFOHEAD(fd,packet_len(0x10a));
  6872. WFIFOW(fd,0)=0x10a;
  6873. if((view = itemdb_viewid(nameid)) > 0)
  6874. WFIFOW(fd,2)=view;
  6875. else
  6876. WFIFOW(fd,2)=nameid;
  6877. WFIFOSET(fd,packet_len(0x10a));
  6878. }
  6879. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6880. /// 010b <exp>.L
  6881. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  6882. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  6883. if (battle_config.mvp_exp_reward_message) {
  6884. char e_msg[CHAT_SIZE_MAX];
  6885. sprintf(e_msg, msg_txt(sd, 717), exp);
  6886. clif_colormes(sd->fd, color_table[COLOR_CYAN], e_msg); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  6887. }
  6888. #else
  6889. int fd;
  6890. nullpo_retv(sd);
  6891. fd = sd->fd;
  6892. WFIFOHEAD(fd, packet_len(0x10b));
  6893. WFIFOW(fd,0) = 0x10b;
  6894. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  6895. WFIFOSET(fd, packet_len(0x10b));
  6896. #endif
  6897. }
  6898. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6899. /// 010d
  6900. ///
  6901. /// "You are the MVP, but cannot obtain the reward because
  6902. /// you are overweight."
  6903. void clif_mvp_noitem(struct map_session_data* sd)
  6904. {
  6905. int fd = sd->fd;
  6906. WFIFOHEAD(fd,packet_len(0x10d));
  6907. WFIFOW(fd,0) = 0x10d;
  6908. WFIFOSET(fd,packet_len(0x10d));
  6909. }
  6910. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6911. /// 0167 <result>.B
  6912. /// result:
  6913. /// 0 = "Guild has been created."
  6914. /// 1 = "You are already in a Guild."
  6915. /// 2 = "That Guild Name already exists."
  6916. /// 3 = "You need the neccessary item to create a Guild."
  6917. void clif_guild_created(struct map_session_data *sd,int flag)
  6918. {
  6919. int fd;
  6920. nullpo_retv(sd);
  6921. fd=sd->fd;
  6922. WFIFOHEAD(fd,packet_len(0x167));
  6923. WFIFOW(fd,0)=0x167;
  6924. WFIFOB(fd,2)=flag;
  6925. WFIFOSET(fd,packet_len(0x167));
  6926. }
  6927. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6928. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6929. /// mode:
  6930. /// &0x01 = allow invite
  6931. /// &0x10 = allow expel
  6932. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6933. {
  6934. int ps,fd;
  6935. nullpo_retv(sd);
  6936. nullpo_retv(g);
  6937. fd=sd->fd;
  6938. ps=guild_getposition(g,sd);
  6939. WFIFOHEAD(fd,packet_len(0x16c));
  6940. WFIFOW(fd,0)=0x16c;
  6941. WFIFOL(fd,2)=g->guild_id;
  6942. WFIFOL(fd,6)=g->emblem_id;
  6943. WFIFOL(fd,10)=g->position[ps].mode;
  6944. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6945. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6946. safestrncpy((char*)WFIFOP(fd,19),g->name,NAME_LENGTH);
  6947. WFIFOSET(fd,packet_len(0x16c));
  6948. }
  6949. /// Guild member login notice.
  6950. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6951. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6952. /// status:
  6953. /// 0 = offline
  6954. /// 1 = online
  6955. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6956. {
  6957. unsigned char buf[64];
  6958. struct map_session_data* sd;
  6959. nullpo_retv(g);
  6960. WBUFW(buf, 0)=0x1f2;
  6961. WBUFL(buf, 2)=g->member[idx].account_id;
  6962. WBUFL(buf, 6)=g->member[idx].char_id;
  6963. WBUFL(buf,10)=flag;
  6964. if( ( sd = g->member[idx].sd ) != NULL )
  6965. {
  6966. WBUFW(buf,14) = sd->status.sex;
  6967. WBUFW(buf,16) = sd->status.hair;
  6968. WBUFW(buf,18) = sd->status.hair_color;
  6969. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6970. }
  6971. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6972. {
  6973. WBUFW(buf,14) = 0;
  6974. WBUFW(buf,16) = 0;
  6975. WBUFW(buf,18) = 0;
  6976. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6977. }
  6978. }
  6979. // Function `clif_guild_memberlogin_notice` sends info about
  6980. // logins and logouts of a guild member to the rest members.
  6981. // But at the 1st time (after a player login or map changing)
  6982. // the client won't show the message.
  6983. // So I suggest use this function for sending "first-time-info"
  6984. // to some player on entering the game or changing location.
  6985. // At next time the client would always show the message.
  6986. // The function sends all the statuses in the single packet
  6987. // to economize traffic. [LuzZza]
  6988. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6989. {
  6990. struct guild *g;
  6991. unsigned char buf[14*128];
  6992. int i, count=0, p_len;
  6993. nullpo_retv(sd);
  6994. p_len = packet_len(0x16d);
  6995. if(!(g = sd->guild))
  6996. return;
  6997. for(i=0; i<g->max_member; i++) {
  6998. if(g->member[i].account_id > 0 &&
  6999. g->member[i].account_id != sd->status.account_id) {
  7000. WBUFW(buf,count*p_len) = 0x16d;
  7001. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7002. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7003. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7004. count++;
  7005. }
  7006. }
  7007. clif_send(buf, p_len*count, &sd->bl, SELF);
  7008. }
  7009. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7010. /// 014e <menu flag>.L
  7011. /// menu flag:
  7012. /// 0x00 = Basic Info (always on)
  7013. /// &0x01 = Member manager
  7014. /// &0x02 = Positions
  7015. /// &0x04 = Skills
  7016. /// &0x10 = Expulsion list
  7017. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7018. /// &0x80 = Notice
  7019. void clif_guild_masterormember(struct map_session_data *sd)
  7020. {
  7021. int fd;
  7022. nullpo_retv(sd);
  7023. fd=sd->fd;
  7024. WFIFOHEAD(fd,packet_len(0x14e));
  7025. WFIFOW(fd,0) = 0x14e;
  7026. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7027. WFIFOSET(fd,packet_len(0x14e));
  7028. }
  7029. /// Guild basic information (Territories [Valaris])
  7030. /// 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)
  7031. /// 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)
  7032. void clif_guild_basicinfo(struct map_session_data *sd) {
  7033. int fd;
  7034. struct guild *g;
  7035. nullpo_retv(sd);
  7036. fd = sd->fd;
  7037. if( (g = sd->guild) == NULL )
  7038. return;
  7039. WFIFOHEAD(fd,packet_len(0x1b6));
  7040. WFIFOW(fd, 0)=0x1b6;//0x150;
  7041. WFIFOL(fd, 2)=g->guild_id;
  7042. WFIFOL(fd, 6)=g->guild_lv;
  7043. WFIFOL(fd,10)=g->connect_member;
  7044. WFIFOL(fd,14)=g->max_member;
  7045. WFIFOL(fd,18)=g->average_lv;
  7046. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7047. WFIFOL(fd,26)=g->next_exp;
  7048. WFIFOL(fd,30)=0; // Tax Points
  7049. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7050. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7051. WFIFOL(fd,42)=g->emblem_id;
  7052. safestrncpy((char*)WFIFOP(fd,46),g->name, NAME_LENGTH);
  7053. safestrncpy((char*)WFIFOP(fd,70),g->master, NAME_LENGTH);
  7054. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7055. WFIFOL(fd,110) = 0; // zeny
  7056. WFIFOSET(fd,packet_len(0x1b6));
  7057. }
  7058. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7059. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7060. void clif_guild_allianceinfo(struct map_session_data *sd)
  7061. {
  7062. int fd,i,c;
  7063. struct guild *g;
  7064. nullpo_retv(sd);
  7065. if( (g = sd->guild) == NULL )
  7066. return;
  7067. fd = sd->fd;
  7068. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7069. WFIFOW(fd, 0)=0x14c;
  7070. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7071. struct guild_alliance *a=&g->alliance[i];
  7072. if(a->guild_id>0){
  7073. WFIFOL(fd,c*32+4)=a->opposition;
  7074. WFIFOL(fd,c*32+8)=a->guild_id;
  7075. safestrncpy((char*)WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  7076. c++;
  7077. }
  7078. }
  7079. WFIFOW(fd, 2)=c*32+4;
  7080. WFIFOSET(fd,WFIFOW(fd,2));
  7081. }
  7082. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  7083. /// 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 }*
  7084. /// state:
  7085. /// 0 = offline
  7086. /// 1 = online
  7087. /// memo:
  7088. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7089. void clif_guild_memberlist(struct map_session_data *sd)
  7090. {
  7091. int fd;
  7092. int i,c;
  7093. struct guild *g;
  7094. nullpo_retv(sd);
  7095. if( (fd = sd->fd) == 0 )
  7096. return;
  7097. if( (g = sd->guild) == NULL )
  7098. return;
  7099. WFIFOHEAD(fd, g->max_member * 104 + 4);
  7100. WFIFOW(fd, 0)=0x154;
  7101. for(i=0,c=0;i<g->max_member;i++){
  7102. struct guild_member *m=&g->member[i];
  7103. if(m->account_id==0)
  7104. continue;
  7105. WFIFOL(fd,c*104+ 4)=m->account_id;
  7106. WFIFOL(fd,c*104+ 8)=m->char_id;
  7107. WFIFOW(fd,c*104+12)=m->hair;
  7108. WFIFOW(fd,c*104+14)=m->hair_color;
  7109. WFIFOW(fd,c*104+16)=m->gender;
  7110. WFIFOW(fd,c*104+18)=m->class_;
  7111. WFIFOW(fd,c*104+20)=m->lv;
  7112. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7113. WFIFOL(fd,c*104+26)=m->online;
  7114. WFIFOL(fd,c*104+30)=m->position;
  7115. 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.
  7116. safestrncpy((char*)WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  7117. c++;
  7118. }
  7119. WFIFOW(fd, 2)=c*104+4;
  7120. WFIFOSET(fd,WFIFOW(fd,2));
  7121. }
  7122. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7123. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7124. void clif_guild_positionnamelist(struct map_session_data *sd)
  7125. {
  7126. int i,fd;
  7127. struct guild *g;
  7128. nullpo_retv(sd);
  7129. if( (g = sd->guild) == NULL )
  7130. return;
  7131. fd = sd->fd;
  7132. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7133. WFIFOW(fd, 0)=0x166;
  7134. for(i=0;i<MAX_GUILDPOSITION;i++){
  7135. WFIFOL(fd,i*28+4)=i;
  7136. safestrncpy((char*)WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7137. }
  7138. WFIFOW(fd,2)=i*28+4;
  7139. WFIFOSET(fd,WFIFOW(fd,2));
  7140. }
  7141. /// Guild position information (ZC_POSITION_INFO).
  7142. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7143. /// mode:
  7144. /// &0x01 = allow invite
  7145. /// &0x10 = allow expel
  7146. /// ranking:
  7147. /// TODO
  7148. void clif_guild_positioninfolist(struct map_session_data *sd)
  7149. {
  7150. int i,fd;
  7151. struct guild *g;
  7152. nullpo_retv(sd);
  7153. if( (g = sd->guild) == NULL )
  7154. return;
  7155. fd = sd->fd;
  7156. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7157. WFIFOW(fd, 0)=0x160;
  7158. for(i=0;i<MAX_GUILDPOSITION;i++){
  7159. struct guild_position *p=&g->position[i];
  7160. WFIFOL(fd,i*16+ 4)=i;
  7161. WFIFOL(fd,i*16+ 8)=p->mode;
  7162. WFIFOL(fd,i*16+12)=i;
  7163. WFIFOL(fd,i*16+16)=p->exp_mode;
  7164. }
  7165. WFIFOW(fd, 2)=i*16+4;
  7166. WFIFOSET(fd,WFIFOW(fd,2));
  7167. }
  7168. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7169. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7170. /// mode:
  7171. /// &0x01 = allow invite
  7172. /// &0x10 = allow expel
  7173. /// ranking:
  7174. /// TODO
  7175. void clif_guild_positionchanged(struct guild *g,int idx)
  7176. {
  7177. // FIXME: This packet is intended to update the clients after a
  7178. // commit of position info changes, not sending one packet per
  7179. // position.
  7180. struct map_session_data *sd;
  7181. unsigned char buf[128];
  7182. nullpo_retv(g);
  7183. WBUFW(buf, 0)=0x174;
  7184. WBUFW(buf, 2)=44; // packet len
  7185. // GUILD_REG_POSITION_INFO{
  7186. WBUFL(buf, 4)=idx;
  7187. WBUFL(buf, 8)=g->position[idx].mode;
  7188. WBUFL(buf,12)=idx;
  7189. WBUFL(buf,16)=g->position[idx].exp_mode;
  7190. safestrncpy((char*)WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  7191. // }*
  7192. if( (sd=guild_getavailablesd(g))!=NULL )
  7193. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7194. }
  7195. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7196. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7197. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7198. {
  7199. // FIXME: This packet is intended to update the clients after a
  7200. // commit of member position assignment changes, not sending one
  7201. // packet per position.
  7202. struct map_session_data *sd;
  7203. unsigned char buf[64];
  7204. nullpo_retv(g);
  7205. WBUFW(buf, 0)=0x156;
  7206. WBUFW(buf, 2)=16; // packet len
  7207. // MEMBER_POSITION_INFO{
  7208. WBUFL(buf, 4)=g->member[idx].account_id;
  7209. WBUFL(buf, 8)=g->member[idx].char_id;
  7210. WBUFL(buf,12)=g->member[idx].position;
  7211. // }*
  7212. if( (sd=guild_getavailablesd(g))!=NULL )
  7213. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7214. }
  7215. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7216. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7217. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7218. {
  7219. int fd;
  7220. nullpo_retv(sd);
  7221. nullpo_retv(g);
  7222. fd = sd->fd;
  7223. if( g->emblem_len <= 0 )
  7224. return;
  7225. WFIFOHEAD(fd,g->emblem_len+12);
  7226. WFIFOW(fd,0)=0x152;
  7227. WFIFOW(fd,2)=g->emblem_len+12;
  7228. WFIFOL(fd,4)=g->guild_id;
  7229. WFIFOL(fd,8)=g->emblem_id;
  7230. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7231. WFIFOSET(fd,WFIFOW(fd,2));
  7232. }
  7233. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7234. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7235. void clif_guild_emblem_area(struct block_list* bl)
  7236. {
  7237. uint8 buf[12];
  7238. nullpo_retv(bl);
  7239. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7240. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7241. WBUFW(buf,0) = 0x1b4;
  7242. WBUFL(buf,2) = bl->id;
  7243. WBUFL(buf,6) = status_get_guild_id(bl);
  7244. WBUFW(buf,10) = status_get_emblem_id(bl);
  7245. clif_send(buf, 12, bl, AREA_WOS);
  7246. }
  7247. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7248. /// 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 }*
  7249. void clif_guild_skillinfo(struct map_session_data* sd)
  7250. {
  7251. int fd;
  7252. struct guild* g;
  7253. int i,c;
  7254. nullpo_retv(sd);
  7255. if( (g = sd->guild) == NULL )
  7256. return;
  7257. fd = sd->fd;
  7258. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7259. WFIFOW(fd,0) = 0x0162;
  7260. WFIFOW(fd,4) = g->skill_point;
  7261. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7262. {
  7263. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7264. {
  7265. int id = g->skill[i].id;
  7266. int p = 6 + c*37;
  7267. WFIFOW(fd,p+0) = id;
  7268. WFIFOL(fd,p+2) = skill_get_inf(id);
  7269. WFIFOW(fd,p+6) = g->skill[i].lv;
  7270. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7271. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7272. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7273. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7274. c++;
  7275. }
  7276. }
  7277. WFIFOW(fd,2) = 6 + c*37;
  7278. WFIFOSET(fd,WFIFOW(fd,2));
  7279. }
  7280. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7281. /// 016f <subject>.60B <notice>.120B
  7282. void clif_guild_notice(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. if ( !session_isActive(fd) )
  7289. return;
  7290. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7291. return;
  7292. WFIFOHEAD(fd,packet_len(0x16f));
  7293. WFIFOW(fd,0) = 0x16f;
  7294. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7295. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7296. WFIFOSET(fd,packet_len(0x16f));
  7297. }
  7298. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7299. /// 016a <guild id>.L <guild name>.24B
  7300. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7301. {
  7302. int fd;
  7303. nullpo_retv(sd);
  7304. nullpo_retv(g);
  7305. fd=sd->fd;
  7306. WFIFOHEAD(fd,packet_len(0x16a));
  7307. WFIFOW(fd,0)=0x16a;
  7308. WFIFOL(fd,2)=g->guild_id;
  7309. safestrncpy((char*)WFIFOP(fd,6),g->name,NAME_LENGTH);
  7310. WFIFOSET(fd,packet_len(0x16a));
  7311. }
  7312. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7313. /// 0169 <answer>.B
  7314. /// answer:
  7315. /// 0 = Already in guild.
  7316. /// 1 = Offer rejected.
  7317. /// 2 = Offer accepted.
  7318. /// 3 = Guild full.
  7319. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7320. {
  7321. int fd;
  7322. nullpo_retv(sd);
  7323. fd=sd->fd;
  7324. WFIFOHEAD(fd,packet_len(0x169));
  7325. WFIFOW(fd,0)=0x169;
  7326. WFIFOB(fd,2)=flag;
  7327. WFIFOSET(fd,packet_len(0x169));
  7328. }
  7329. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7330. /// 015a <char name>.24B <reason>.40B
  7331. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7332. {
  7333. unsigned char buf[128];
  7334. nullpo_retv(sd);
  7335. WBUFW(buf, 0)=0x15a;
  7336. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  7337. memcpy(WBUFP(buf,26),mes,40);
  7338. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7339. }
  7340. /// Notifies clients of a guild of an expelled member.
  7341. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7342. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7343. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7344. {
  7345. unsigned char buf[128];
  7346. #if PACKETVER < 20100803
  7347. const unsigned short cmd = 0x15c;
  7348. #else
  7349. const unsigned short cmd = 0x839;
  7350. #endif
  7351. nullpo_retv(sd);
  7352. WBUFW(buf,0) = cmd;
  7353. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7354. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7355. #if PACKETVER < 20100803
  7356. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7357. #endif
  7358. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7359. }
  7360. /// Guild expulsion list (ZC_BAN_LIST).
  7361. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7362. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7363. void clif_guild_expulsionlist(struct map_session_data* sd)
  7364. {
  7365. #if PACKETVER < 20100803
  7366. const int offset = NAME_LENGTH*2+40;
  7367. #else
  7368. const int offset = NAME_LENGTH+40;
  7369. #endif
  7370. int fd, i, c = 0;
  7371. struct guild* g;
  7372. nullpo_retv(sd);
  7373. if( (g = sd->guild) == NULL )
  7374. return;
  7375. fd = sd->fd;
  7376. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7377. WFIFOW(fd,0) = 0x163;
  7378. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7379. {
  7380. struct guild_expulsion* e = &g->expulsion[i];
  7381. if( e->account_id > 0 )
  7382. {
  7383. safestrncpy((char*)WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7384. #if PACKETVER < 20100803
  7385. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7386. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7387. #else
  7388. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7389. #endif
  7390. c++;
  7391. }
  7392. }
  7393. WFIFOW(fd,2) = 4 + c*offset;
  7394. WFIFOSET(fd,WFIFOW(fd,2));
  7395. }
  7396. /// Guild chat message (ZC_GUILD_CHAT).
  7397. /// 017f <packet len>.W <message>.?B
  7398. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7399. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7400. struct map_session_data *sd;
  7401. uint8 buf[256];
  7402. if( len == 0 )
  7403. {
  7404. return;
  7405. }
  7406. else if( len > sizeof(buf)-5 )
  7407. {
  7408. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7409. len = sizeof(buf)-5;
  7410. }
  7411. WBUFW(buf, 0) = 0x17f;
  7412. WBUFW(buf, 2) = len + 5;
  7413. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7414. if ((sd = guild_getavailablesd(g)) != NULL)
  7415. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7416. }
  7417. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7418. /// 0171 <inviter account id>.L <guild name>.24B
  7419. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7420. {
  7421. int fd;
  7422. nullpo_retv(sd);
  7423. fd=sd->fd;
  7424. WFIFOHEAD(fd,packet_len(0x171));
  7425. WFIFOW(fd,0)=0x171;
  7426. WFIFOL(fd,2)=account_id;
  7427. safestrncpy((char*)WFIFOP(fd,6),name,NAME_LENGTH);
  7428. WFIFOSET(fd,packet_len(0x171));
  7429. }
  7430. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7431. /// 0173 <answer>.B
  7432. /// answer:
  7433. /// 0 = Already allied.
  7434. /// 1 = You rejected the offer.
  7435. /// 2 = You accepted the offer.
  7436. /// 3 = They have too any alliances.
  7437. /// 4 = You have too many alliances.
  7438. /// 5 = Alliances are disabled.
  7439. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7440. {
  7441. int fd;
  7442. nullpo_retv(sd);
  7443. fd=sd->fd;
  7444. WFIFOHEAD(fd,packet_len(0x173));
  7445. WFIFOW(fd,0)=0x173;
  7446. WFIFOL(fd,2)=flag;
  7447. WFIFOSET(fd,packet_len(0x173));
  7448. }
  7449. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7450. /// 0184 <other guild id>.L <relation>.L
  7451. /// relation:
  7452. /// 0 = Ally
  7453. /// 1 = Enemy
  7454. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7455. {
  7456. int fd;
  7457. nullpo_retv(sd);
  7458. fd = sd->fd;
  7459. if (fd <= 0)
  7460. return;
  7461. WFIFOHEAD(fd,packet_len(0x184));
  7462. WFIFOW(fd,0)=0x184;
  7463. WFIFOL(fd,2)=guild_id;
  7464. WFIFOL(fd,6)=flag;
  7465. WFIFOSET(fd,packet_len(0x184));
  7466. }
  7467. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7468. /// 0181 <result>.B
  7469. /// result:
  7470. /// 0 = Antagonist has been set.
  7471. /// 1 = Guild has too many Antagonists.
  7472. /// 2 = Already set as an Antagonist.
  7473. /// 3 = Antagonists are disabled.
  7474. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7475. {
  7476. int fd;
  7477. nullpo_retv(sd);
  7478. fd=sd->fd;
  7479. WFIFOHEAD(fd,packet_len(0x181));
  7480. WFIFOW(fd,0)=0x181;
  7481. WFIFOB(fd,2)=flag;
  7482. WFIFOSET(fd,packet_len(0x181));
  7483. }
  7484. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7485. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7486. /*
  7487. void clif_guild_allianceadded(struct guild *g,int idx)
  7488. {
  7489. unsigned char buf[64];
  7490. WBUFW(buf,0)=0x185;
  7491. WBUFL(buf,2)=g->alliance[idx].opposition;
  7492. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7493. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7494. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7495. }
  7496. */
  7497. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7498. /// 015e <reason>.L
  7499. /// 0 = success
  7500. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7501. /// 2 = there are still members in the guild
  7502. void clif_guild_broken(struct map_session_data *sd,int flag)
  7503. {
  7504. int fd;
  7505. nullpo_retv(sd);
  7506. fd=sd->fd;
  7507. WFIFOHEAD(fd,packet_len(0x15e));
  7508. WFIFOW(fd,0)=0x15e;
  7509. WFIFOL(fd,2)=flag;
  7510. WFIFOSET(fd,packet_len(0x15e));
  7511. }
  7512. /// Displays emotion on an object (ZC_EMOTION).
  7513. /// 00c0 <id>.L <type>.B
  7514. /// type:
  7515. /// enum emotion_type
  7516. void clif_emotion(struct block_list *bl,int type)
  7517. {
  7518. unsigned char buf[8];
  7519. nullpo_retv(bl);
  7520. WBUFW(buf,0)=0xc0;
  7521. WBUFL(buf,2)=bl->id;
  7522. WBUFB(buf,6)=type;
  7523. clif_send(buf,packet_len(0xc0),bl,AREA);
  7524. }
  7525. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7526. /// 0191 <id>.L <contents>.80B
  7527. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7528. {
  7529. unsigned char buf[MESSAGE_SIZE+6];
  7530. nullpo_retv(bl);
  7531. WBUFW(buf,0) = 0x191;
  7532. WBUFL(buf,2) = bl->id;
  7533. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7534. clif_send(buf,packet_len(0x191),bl,AREA);
  7535. }
  7536. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7537. /// 01ea <id>.L
  7538. void clif_wedding_effect(struct block_list *bl)
  7539. {
  7540. unsigned char buf[6];
  7541. nullpo_retv(bl);
  7542. WBUFW(buf,0) = 0x1ea;
  7543. WBUFL(buf,2) = bl->id;
  7544. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7545. }
  7546. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7547. /// 01e6 <partner name>.24B
  7548. void clif_callpartner(struct map_session_data *sd)
  7549. {
  7550. unsigned char buf[26];
  7551. nullpo_retv(sd);
  7552. WBUFW(buf,0) = 0x1e6;
  7553. if( sd->status.partner_id ) {
  7554. const char *p = map_charid2nick(sd->status.partner_id);
  7555. struct map_session_data *p_sd = pc_get_partner(sd);
  7556. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7557. safestrncpy((char*)WBUFP(buf,2), p, NAME_LENGTH);
  7558. else
  7559. WBUFB(buf,2) = 0;
  7560. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7561. WBUFB(buf,2) = 0;
  7562. }
  7563. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7564. }
  7565. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7566. /// 01e4
  7567. /// This packet while still implemented by the client is no longer being officially used.
  7568. /*
  7569. void clif_marriage_process(struct map_session_data *sd)
  7570. {
  7571. int fd;
  7572. nullpo_retv(sd);
  7573. fd=sd->fd;
  7574. WFIFOHEAD(fd,packet_len(0x1e4));
  7575. WFIFOW(fd,0)=0x1e4;
  7576. WFIFOSET(fd,packet_len(0x1e4));
  7577. }
  7578. */
  7579. /// Notice of divorce (ZC_DIVORCE).
  7580. /// 0205 <partner name>.24B
  7581. void clif_divorced(struct map_session_data* sd, const char* name)
  7582. {
  7583. int fd;
  7584. nullpo_retv(sd);
  7585. fd=sd->fd;
  7586. WFIFOHEAD(fd,packet_len(0x205));
  7587. WFIFOW(fd,0)=0x205;
  7588. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7589. WFIFOSET(fd, packet_len(0x205));
  7590. }
  7591. /// Marriage proposal (ZC_REQ_COUPLE).
  7592. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7593. /// This packet while still implemented by the client is no longer being officially used.
  7594. /*
  7595. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7596. {
  7597. nullpo_retv(sd);
  7598. WFIFOHEAD(fd,packet_len(0x1e2));
  7599. WFIFOW(fd,0) = 0x1e2;
  7600. WFIFOL(fd,2) = ssd->status.account_id;
  7601. WFIFOL(fd,6) = ssd->status.char_id;
  7602. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7603. WFIFOSET(fd, packet_len(0x1e2));
  7604. }
  7605. */
  7606. /*==========================================
  7607. *
  7608. *------------------------------------------*/
  7609. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7610. {
  7611. clif_disp_message(&sd->bl, mes, len, SELF);
  7612. }
  7613. /*==========================================
  7614. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7615. *------------------------------------------*/
  7616. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7617. {
  7618. unsigned char buf[256];
  7619. if( len == 0 ) {
  7620. return;
  7621. } else if( len > sizeof(buf)-5 ) {
  7622. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7623. len = sizeof(buf)-5;
  7624. }
  7625. WBUFW(buf, 0) = 0x17f;
  7626. WBUFW(buf, 2) = len + 5;
  7627. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7628. clif_send(buf, WBUFW(buf,2), src, target);
  7629. }
  7630. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7631. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7632. /// 00cd <result>.B
  7633. /// result:
  7634. /// 0 = failure
  7635. /// 1 = success
  7636. void clif_GM_kickack(struct map_session_data *sd, int id)
  7637. {
  7638. int fd;
  7639. nullpo_retv(sd);
  7640. fd = sd->fd;
  7641. WFIFOHEAD(fd,packet_len(0xcd));
  7642. WFIFOW(fd,0) = 0xcd;
  7643. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7644. WFIFOSET(fd, packet_len(0xcd));
  7645. }
  7646. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7647. {
  7648. int fd = tsd->fd;
  7649. if( fd > 0 )
  7650. clif_authfail_fd(fd, 15);
  7651. else {
  7652. // Close vending/buyingstore
  7653. if (sd) {
  7654. if (tsd->state.vending)
  7655. vending_closevending(tsd);
  7656. else if (tsd->state.buyingstore)
  7657. buyingstore_close(tsd);
  7658. }
  7659. map_quit(tsd);
  7660. }
  7661. if( sd )
  7662. clif_GM_kickack(sd,tsd->status.account_id);
  7663. }
  7664. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7665. /// 014a <result>.L
  7666. /// result:
  7667. /// 0 = "A manner point has been successfully aligned."
  7668. /// 1 = MP_FAILURE_EXHAUST
  7669. /// 2 = MP_FAILURE_ALREADY_GIVING
  7670. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7671. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7672. /// 5 = "You got a good point from %s."
  7673. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7674. {
  7675. int fd;
  7676. nullpo_retv(sd);
  7677. fd = sd->fd;
  7678. WFIFOHEAD(fd,packet_len(0x14a));
  7679. WFIFOW(fd,0) = 0x14a;
  7680. WFIFOL(fd,2) = type;
  7681. WFIFOSET(fd, packet_len(0x14a));
  7682. }
  7683. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7684. /// 014b <type>.B <GM name>.24B
  7685. /// type:
  7686. /// 0 = positive (unmute)
  7687. /// 1 = negative (mute)
  7688. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7689. {
  7690. int fd;
  7691. nullpo_retv(sd);
  7692. nullpo_retv(tsd);
  7693. fd = tsd->fd;
  7694. WFIFOHEAD(fd,packet_len(0x14b));
  7695. WFIFOW(fd,0) = 0x14b;
  7696. WFIFOB(fd,2) = type;
  7697. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7698. WFIFOSET(fd, packet_len(0x14b));
  7699. }
  7700. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7701. /// 00d1 <type>.B <result>.B
  7702. /// type:
  7703. /// 0 = /ex (deny)
  7704. /// 1 = /in (allow)
  7705. /// result:
  7706. /// 0 = success
  7707. /// 1 = failure
  7708. /// 2 = too many blocks
  7709. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7710. {
  7711. int fd;
  7712. nullpo_retv(sd);
  7713. fd=sd->fd;
  7714. WFIFOHEAD(fd,packet_len(0xd1));
  7715. WFIFOW(fd,0)=0xd1;
  7716. WFIFOB(fd,2)=type;
  7717. WFIFOB(fd,3)=flag;
  7718. WFIFOSET(fd,packet_len(0xd1));
  7719. }
  7720. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7721. /// 00d2 <type>.B <result>.B
  7722. /// type:
  7723. /// 0 = /exall (deny)
  7724. /// 1 = /inall (allow)
  7725. /// result:
  7726. /// 0 = success
  7727. /// 1 = failure
  7728. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7729. {
  7730. int fd;
  7731. nullpo_retv(sd);
  7732. fd=sd->fd;
  7733. WFIFOHEAD(fd,packet_len(0xd2));
  7734. WFIFOW(fd,0)=0xd2;
  7735. WFIFOB(fd,2)=type;
  7736. WFIFOB(fd,3)=flag;
  7737. WFIFOSET(fd,packet_len(0xd2));
  7738. }
  7739. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7740. /// 07fe <bgm>.24B
  7741. void clif_playBGM(struct map_session_data* sd, const char* name)
  7742. {
  7743. int fd;
  7744. nullpo_retv(sd);
  7745. fd = sd->fd;
  7746. WFIFOHEAD(fd,packet_len(0x7fe));
  7747. WFIFOW(fd,0) = 0x7fe;
  7748. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7749. WFIFOSET(fd,packet_len(0x7fe));
  7750. }
  7751. /// Plays/stops a wave sound (ZC_SOUND).
  7752. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7753. /// file name:
  7754. /// relative to data\wav
  7755. /// act:
  7756. /// 0 = play (once)
  7757. /// 1 = play (repeat, does not work)
  7758. /// 2 = stops all sound instances of file name (does not work)
  7759. /// term:
  7760. /// unknown purpose, only relevant to act = 1
  7761. /// npc id:
  7762. /// The accustic direction of the sound is determined by the
  7763. /// relative position of the NPC to the player (3D sound).
  7764. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7765. {
  7766. int fd;
  7767. nullpo_retv(sd);
  7768. nullpo_retv(bl);
  7769. fd = sd->fd;
  7770. WFIFOHEAD(fd,packet_len(0x1d3));
  7771. WFIFOW(fd,0) = 0x1d3;
  7772. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7773. WFIFOB(fd,26) = type;
  7774. WFIFOL(fd,27) = 0;
  7775. WFIFOL(fd,31) = bl->id;
  7776. WFIFOSET(fd,packet_len(0x1d3));
  7777. }
  7778. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7779. {
  7780. unsigned char buf[40];
  7781. nullpo_retv(bl);
  7782. WBUFW(buf,0) = 0x1d3;
  7783. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7784. WBUFB(buf,26) = type;
  7785. WBUFL(buf,27) = 0;
  7786. WBUFL(buf,31) = bl->id;
  7787. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7788. }
  7789. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7790. /// 01f3 <id>.L <effect id>.L
  7791. /// effect id:
  7792. /// @see doc/effect_list.txt
  7793. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7794. {
  7795. unsigned char buf[24];
  7796. nullpo_retv(bl);
  7797. memset(buf, 0, packet_len(0x1f3));
  7798. WBUFW(buf,0) = 0x1f3;
  7799. WBUFL(buf,2) = bl->id;
  7800. WBUFL(buf,6) = type;
  7801. clif_send(buf, packet_len(0x1f3), bl, target);
  7802. if (disguised(bl)) {
  7803. WBUFL(buf,2) = -bl->id;
  7804. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7805. }
  7806. }
  7807. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7808. {
  7809. WFIFOHEAD(fd,10);
  7810. WFIFOW(fd,0) = 0x1f3;
  7811. WFIFOL(fd,2) = bl->id;
  7812. WFIFOL(fd,6) = type;
  7813. WFIFOSET(fd,10);
  7814. }
  7815. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7816. /// 0284 <id>.L <effect id>.L <num data>.L
  7817. /// effect id:
  7818. /// @see doc/effect_list.txt
  7819. /// num data:
  7820. /// effect-dependent value
  7821. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7822. {
  7823. uint8 buf[14];
  7824. WBUFW(buf,0) = 0x284;
  7825. WBUFL(buf,2) = bl->id;
  7826. WBUFL(buf,6) = effect_id;
  7827. WBUFL(buf,10) = num;
  7828. clif_send(buf, packet_len(0x284), bl, target);
  7829. if( disguised(bl) )
  7830. {
  7831. WBUFL(buf,2) = -bl->id;
  7832. clif_send(buf, packet_len(0x284), bl, SELF);
  7833. }
  7834. }
  7835. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7836. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7837. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7838. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7839. WFIFOHEAD(fd,msg_len + 12);
  7840. WFIFOW(fd,0) = 0x2C1;
  7841. WFIFOW(fd,2) = msg_len + 12;
  7842. WFIFOL(fd,4) = 0;
  7843. WFIFOL(fd,8) = color; //either color_table or channel_table
  7844. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7845. WFIFOSET(fd, msg_len + 12);
  7846. return 0;
  7847. }
  7848. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7849. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7850. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7851. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7852. uint8 buf[256];
  7853. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7854. nullpo_retv(bl);
  7855. if( msg_len > sizeof(buf)-12 ) {
  7856. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7857. msg_len = sizeof(buf)-12;
  7858. }
  7859. WBUFW(buf,0) = 0x2C1;
  7860. WBUFW(buf,2) = msg_len + 12;
  7861. WBUFL(buf,4) = bl->id;
  7862. WBUFL(buf,8) = color;
  7863. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7864. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7865. }
  7866. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7867. {
  7868. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7869. nullpo_retv(sd);
  7870. if(msg_len > 0) {
  7871. int fd;
  7872. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7873. fd = sd->fd;
  7874. WFIFOHEAD(fd, msg_len+12);
  7875. WFIFOW(fd,0) = 0x2C1;
  7876. WFIFOW(fd,2) = msg_len+12;
  7877. WFIFOL(fd,4) = 0;
  7878. WFIFOL(fd,8) = color;
  7879. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7880. WFIFOSET(fd, WFIFOW(fd,2));
  7881. }
  7882. }
  7883. /**
  7884. * Notifies the client that the storage window is still open
  7885. *
  7886. * Should only be used in cases where the client closed the
  7887. * storage window without server's consent
  7888. */
  7889. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7890. // Notify the client that the storage is open
  7891. if( sd->state.storage_flag == 1 ) {
  7892. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7893. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7894. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7895. }
  7896. // Notify the client that the gstorage is open otherwise it will
  7897. // remain locked forever and nobody will be able to access it
  7898. if( sd->state.storage_flag == 2 ) {
  7899. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7900. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7901. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7902. else {
  7903. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7904. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7905. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7906. }
  7907. }
  7908. }
  7909. // refresh the client's screen, getting rid of any effects
  7910. void clif_refresh(struct map_session_data *sd)
  7911. {
  7912. nullpo_retv(sd);
  7913. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7914. clif_inventorylist(sd);
  7915. if(pc_iscarton(sd)) {
  7916. clif_cartlist(sd);
  7917. clif_updatestatus(sd,SP_CARTINFO);
  7918. }
  7919. clif_updatestatus(sd,SP_WEIGHT);
  7920. clif_updatestatus(sd,SP_MAXWEIGHT);
  7921. clif_updatestatus(sd,SP_STR);
  7922. clif_updatestatus(sd,SP_AGI);
  7923. clif_updatestatus(sd,SP_VIT);
  7924. clif_updatestatus(sd,SP_INT);
  7925. clif_updatestatus(sd,SP_DEX);
  7926. clif_updatestatus(sd,SP_LUK);
  7927. if (sd->spiritball)
  7928. clif_spiritball_single(sd->fd, sd);
  7929. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7930. clif_spiritcharm_single(sd->fd, sd);
  7931. if (sd->vd.cloth_color)
  7932. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7933. if (sd->vd.body_style)
  7934. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7935. if(hom_is_active(sd->hd))
  7936. clif_send_homdata(sd,SP_ACK,0);
  7937. if( sd->md ) {
  7938. clif_mercenary_info(sd);
  7939. clif_mercenary_skillblock(sd);
  7940. }
  7941. if( sd->ed )
  7942. clif_elemental_info(sd);
  7943. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7944. clif_weather_check(sd);
  7945. if( sd->chatID )
  7946. chat_leavechat(sd,0);
  7947. if( sd->state.vending )
  7948. clif_openvending(sd, sd->bl.id, sd->vending);
  7949. if( pc_issit(sd) )
  7950. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7951. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7952. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7953. else
  7954. clif_changed_dir(&sd->bl, SELF);
  7955. // unlike vending, resuming buyingstore crashes the client.
  7956. buyingstore_close(sd);
  7957. mail_clear(sd);
  7958. if( disguised(&sd->bl) ) {/* refresh-da */
  7959. short disguise = sd->disguise;
  7960. pc_disguise(sd, 0);
  7961. pc_disguise(sd, disguise);
  7962. }
  7963. clif_refresh_storagewindow(sd);
  7964. }
  7965. /// Updates the object's (bl) name on client.
  7966. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7967. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7968. void clif_charnameack (int fd, struct block_list *bl)
  7969. {
  7970. unsigned char buf[103];
  7971. int cmd = 0x95;
  7972. nullpo_retv(bl);
  7973. WBUFW(buf,0) = cmd;
  7974. WBUFL(buf,2) = bl->id;
  7975. switch( bl->type )
  7976. {
  7977. case BL_PC:
  7978. {
  7979. struct map_session_data *ssd = (struct map_session_data *)bl;
  7980. struct party_data *p = NULL;
  7981. struct guild *g = NULL;
  7982. int ps = -1;
  7983. //Requesting your own "shadow" name. [Skotlex]
  7984. if (ssd->fd == fd && ssd->disguise)
  7985. WBUFL(buf,2) = -bl->id;
  7986. if( ssd->fakename[0] ) {
  7987. WBUFW(buf, 0) = cmd = 0x195;
  7988. safestrncpy((char*)WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7989. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7990. break;
  7991. }
  7992. safestrncpy((char*)WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7993. if( ssd->status.party_id ) {
  7994. p = party_search(ssd->status.party_id);
  7995. }
  7996. if( ssd->status.guild_id ) {
  7997. if( ( g = ssd->guild ) != NULL ) {
  7998. int i;
  7999. 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);
  8000. if( i < g->max_member ) ps = g->member[i].position;
  8001. }
  8002. }
  8003. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  8004. p = NULL;
  8005. }
  8006. if (p == NULL && g == NULL)
  8007. break;
  8008. WBUFW(buf, 0) = cmd = 0x195;
  8009. if (p)
  8010. safestrncpy((char*)WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8011. else
  8012. WBUFB(buf,30) = 0;
  8013. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  8014. {
  8015. safestrncpy((char*)WBUFP(buf,54), g->name,NAME_LENGTH);
  8016. safestrncpy((char*)WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8017. } else { //Assume no guild.
  8018. WBUFB(buf,54) = 0;
  8019. WBUFB(buf,78) = 0;
  8020. }
  8021. }
  8022. break;
  8023. //[blackhole89]
  8024. case BL_HOM:
  8025. safestrncpy((char*)WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8026. break;
  8027. case BL_MER:
  8028. safestrncpy((char*)WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8029. break;
  8030. case BL_PET:
  8031. safestrncpy((char*)WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8032. break;
  8033. case BL_NPC:
  8034. safestrncpy((char*)WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8035. break;
  8036. case BL_MOB:
  8037. {
  8038. struct mob_data *md = (struct mob_data *)bl;
  8039. nullpo_retv(md);
  8040. safestrncpy((char*)WBUFP(buf,6), md->name, NAME_LENGTH);
  8041. if( md->guardian_data && md->guardian_data->guild_id )
  8042. {
  8043. WBUFW(buf, 0) = cmd = 0x195;
  8044. WBUFB(buf,30) = 0;
  8045. safestrncpy((char*)WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8046. safestrncpy((char*)WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8047. }
  8048. else if( battle_config.show_mob_info )
  8049. {
  8050. char mobhp[50], *str_p = mobhp;
  8051. WBUFW(buf, 0) = cmd = 0x195;
  8052. if( battle_config.show_mob_info&4 )
  8053. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8054. if( battle_config.show_mob_info&1 )
  8055. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8056. if( battle_config.show_mob_info&2 )
  8057. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8058. //Even thought mobhp ain't a name, we send it as one so the client
  8059. //can parse it. [Skotlex]
  8060. if( str_p != mobhp )
  8061. {
  8062. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8063. safestrncpy((char*)WBUFP(buf,30), mobhp, NAME_LENGTH);
  8064. WBUFB(buf,54) = 0;
  8065. WBUFB(buf,78) = 0;
  8066. }
  8067. }
  8068. }
  8069. break;
  8070. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8071. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8072. // break;
  8073. return;
  8074. case BL_ELEM:
  8075. safestrncpy((char*)WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8076. break;
  8077. default:
  8078. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  8079. return;
  8080. }
  8081. // if no receipient specified just update nearby clients
  8082. if (fd == 0)
  8083. clif_send(buf, packet_len(cmd), bl, AREA);
  8084. else {
  8085. WFIFOHEAD(fd, packet_len(cmd));
  8086. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  8087. WFIFOSET(fd, packet_len(cmd));
  8088. }
  8089. }
  8090. //Used to update when a char leaves a party/guild. [Skotlex]
  8091. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8092. void clif_charnameupdate (struct map_session_data *ssd)
  8093. {
  8094. unsigned char buf[103];
  8095. int cmd = 0x195, ps = -1;
  8096. struct party_data *p = NULL;
  8097. struct guild *g = NULL;
  8098. nullpo_retv(ssd);
  8099. if( ssd->fakename[0] )
  8100. return; //No need to update as the party/guild was not displayed anyway.
  8101. WBUFW(buf,0) = cmd;
  8102. WBUFL(buf,2) = ssd->bl.id;
  8103. safestrncpy((char*)WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  8104. if (!battle_config.display_party_name) {
  8105. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  8106. p = party_search(ssd->status.party_id);
  8107. }else{
  8108. if (ssd->status.party_id > 0)
  8109. p = party_search(ssd->status.party_id);
  8110. }
  8111. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  8112. {
  8113. int i;
  8114. 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);
  8115. if( i < g->max_member ) ps = g->member[i].position;
  8116. }
  8117. if( p )
  8118. safestrncpy((char*)WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8119. else
  8120. WBUFB(buf,30) = 0;
  8121. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  8122. {
  8123. safestrncpy((char*)WBUFP(buf,54), g->name,NAME_LENGTH);
  8124. safestrncpy((char*)WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8125. }
  8126. else
  8127. {
  8128. WBUFB(buf,54) = 0;
  8129. WBUFB(buf,78) = 0;
  8130. }
  8131. // Update nearby clients
  8132. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  8133. }
  8134. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8135. /// 01ff <id>.L <x>.W <y>.W
  8136. ///
  8137. /// Visually moves(instant) a character to x,y. The char moves even
  8138. /// when the target cell isn't walkable. If the char is sitting it
  8139. /// stays that way.
  8140. void clif_slide(struct block_list *bl, int x, int y)
  8141. {
  8142. unsigned char buf[10];
  8143. nullpo_retv(bl);
  8144. WBUFW(buf, 0) = 0x01ff;
  8145. WBUFL(buf, 2) = bl->id;
  8146. WBUFW(buf, 6) = x;
  8147. WBUFW(buf, 8) = y;
  8148. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8149. if( disguised(bl) )
  8150. {
  8151. WBUFL(buf,2) = -bl->id;
  8152. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8153. }
  8154. }
  8155. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8156. /// 008d <packet len>.W <id>.L <message>.?B
  8157. void clif_disp_overhead(struct block_list *bl, const char* mes)
  8158. {
  8159. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8160. int len_mes = strlen(mes)+1; //Account for \0
  8161. if (len_mes > sizeof(buf)-8) {
  8162. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8163. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8164. }
  8165. // send message to others
  8166. WBUFW(buf,0) = 0x8d;
  8167. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8168. WBUFL(buf,4) = bl->id;
  8169. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  8170. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8171. // send back message to the speaker
  8172. if( bl->type == BL_PC ) {
  8173. WBUFW(buf,0) = 0x8e;
  8174. WBUFW(buf, 2) = len_mes + 4;
  8175. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  8176. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8177. }
  8178. }
  8179. /*==========================
  8180. * Minimap fix [Kevin]
  8181. * Remove dot from minimap
  8182. *--------------------------*/
  8183. void clif_party_xy_remove(struct map_session_data *sd)
  8184. {
  8185. unsigned char buf[16];
  8186. nullpo_retv(sd);
  8187. WBUFW(buf,0)=0x107;
  8188. WBUFL(buf,2)=sd->status.account_id;
  8189. WBUFW(buf,6)=-1;
  8190. WBUFW(buf,8)=-1;
  8191. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8192. }
  8193. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8194. /// 0215 <msg id>.L
  8195. /// msg id:
  8196. /// 0x15 = End all negative status (PA_GOSPEL)
  8197. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8198. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8199. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8200. /// 0x19 = All stats +20 (PA_GOSPEL)
  8201. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8202. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8203. /// 0x1e = DEF +25% (PA_GOSPEL)
  8204. /// 0x1f = ATK +100% (PA_GOSPEL)
  8205. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8206. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8207. /// ? = nothing
  8208. void clif_gospel_info(struct map_session_data *sd, int type)
  8209. {
  8210. int fd=sd->fd;
  8211. WFIFOHEAD(fd,packet_len(0x215));
  8212. WFIFOW(fd,0)=0x215;
  8213. WFIFOL(fd,2)=type;
  8214. WFIFOSET(fd, packet_len(0x215));
  8215. }
  8216. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8217. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8218. /// result:
  8219. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8220. /// star:
  8221. /// 0 = Place of the Sun
  8222. /// 1 = Place of the Moon
  8223. /// 2 = Place of the Stars
  8224. /// 1 = Star Gladiator %s's %s: <mapname>
  8225. /// star:
  8226. /// 0 = Place of the Sun
  8227. /// 1 = Place of the Moon
  8228. /// 2 = Place of the Stars
  8229. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8230. /// star:
  8231. /// 0 = Target of the Sun
  8232. /// 1 = Target of the Moon
  8233. /// 2 = Target of the Stars
  8234. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8235. /// star:
  8236. /// 0 = Monster of the Sun
  8237. /// 1 = Monster of the Moon
  8238. /// 2 = Monster of the Stars
  8239. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8240. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8241. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8242. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8243. /// 40 = Target HP : <monster_id used as HP>
  8244. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8245. {
  8246. int fd = sd->fd;
  8247. WFIFOHEAD(fd,packet_len(0x20e));
  8248. WFIFOW(fd,0) = 0x20e;
  8249. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8250. WFIFOL(fd,26) = monster_id;
  8251. WFIFOB(fd,30) = star;
  8252. WFIFOB(fd,31) = result;
  8253. WFIFOSET(fd,packet_len(0x20e));
  8254. }
  8255. /*==========================================
  8256. * Info about Star Glaldiator save map [Komurka]
  8257. * type: 1: Information, 0: Map registered
  8258. *------------------------------------------*/
  8259. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8260. {
  8261. char mapname[MAP_NAME_LENGTH_EXT];
  8262. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8263. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8264. }
  8265. /*==========================================
  8266. * Info about Star Glaldiator hate mob [Komurka]
  8267. * type: 1: Register mob, 0: Information.
  8268. *------------------------------------------*/
  8269. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8270. {
  8271. if( pcdb_checkid(class_) ) {
  8272. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8273. } else if( mobdb_checkid(class_) ) {
  8274. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8275. } else {
  8276. 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);
  8277. }
  8278. }
  8279. /*==========================================
  8280. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8281. *------------------------------------------*/
  8282. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8283. {
  8284. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8285. }
  8286. /*==========================================
  8287. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8288. *------------------------------------------*/
  8289. void clif_feel_hate_reset(struct map_session_data *sd)
  8290. {
  8291. clif_starskill(sd, "", 0, 0, 30);
  8292. }
  8293. /// Equip window (un)tick ack (ZC_CONFIG).
  8294. /// 02d9 <type>.L <value>.L
  8295. /// type:
  8296. /// 0 = open equip window
  8297. /// value:
  8298. /// 0 = disabled
  8299. /// 1 = enabled
  8300. void clif_equiptickack(struct map_session_data* sd, int flag)
  8301. {
  8302. int fd;
  8303. nullpo_retv(sd);
  8304. fd = sd->fd;
  8305. WFIFOHEAD(fd, packet_len(0x2d9));
  8306. WFIFOW(fd, 0) = 0x2d9;
  8307. WFIFOL(fd, 2) = 0;
  8308. WFIFOL(fd, 6) = flag;
  8309. WFIFOSET(fd, packet_len(0x2d9));
  8310. }
  8311. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8312. /// 02da <open equip window>.B
  8313. /// open equip window:
  8314. /// 0 = disabled
  8315. /// 1 = enabled
  8316. void clif_equipcheckbox(struct map_session_data* sd)
  8317. {
  8318. int fd;
  8319. nullpo_retv(sd);
  8320. fd = sd->fd;
  8321. WFIFOHEAD(fd, packet_len(0x2da));
  8322. WFIFOW(fd, 0) = 0x2da;
  8323. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8324. WFIFOSET(fd, packet_len(0x2da));
  8325. }
  8326. /// Sends info about a player's equipped items.
  8327. /// 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)
  8328. /// 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)
  8329. /// 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)
  8330. /// 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)
  8331. /// 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)
  8332. /// 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)
  8333. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8334. {
  8335. uint8* buf;
  8336. int i, n, fd, offset = 0;
  8337. #if PACKETVER < 20100629
  8338. const int s = 26;
  8339. #elif PACKETVER < 20120925
  8340. const int s = 28;
  8341. #elif PACKETVER < 20150226
  8342. const int s = 31;
  8343. #else
  8344. const int s = 57;
  8345. #endif
  8346. nullpo_retv(sd);
  8347. nullpo_retv(tsd);
  8348. fd = sd->fd;
  8349. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8350. buf = WFIFOP(fd,0);
  8351. #if PACKETVER < 20101124
  8352. WBUFW(buf, 0) = 0x2d7;
  8353. #elif PACKETVER < 20120925
  8354. WBUFW(buf, 0) = 0x859;
  8355. #elif PACKETVER < 20150226
  8356. WBUFW(buf, 0) = 0x997;
  8357. #else
  8358. WBUFW(buf, 0) = 0xa2d;
  8359. #endif
  8360. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8361. WBUFW(buf,28) = tsd->status.class_;
  8362. WBUFW(buf,30) = tsd->vd.hair_style;
  8363. WBUFW(buf,32) = tsd->vd.head_bottom;
  8364. WBUFW(buf,34) = tsd->vd.head_mid;
  8365. WBUFW(buf,36) = tsd->vd.head_top;
  8366. #if PACKETVER >= 20110111
  8367. WBUFW(buf,38) = tsd->vd.robe;
  8368. offset+= 2;
  8369. buf = WBUFP(buf,2);
  8370. #endif
  8371. WBUFW(buf,38) = tsd->vd.hair_color;
  8372. WBUFW(buf,40) = tsd->vd.cloth_color;
  8373. WBUFB(buf,42) = tsd->vd.sex;
  8374. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8375. {
  8376. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8377. continue;
  8378. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8379. continue;
  8380. // Add item info : refine, identify flag, element, etc.
  8381. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8382. n++;
  8383. }
  8384. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8385. WFIFOSET(fd, WFIFOW(fd, 2));
  8386. }
  8387. /// Display msgstringtable.txt string (ZC_MSG).
  8388. /// 0291 <message>.W
  8389. void clif_msg(struct map_session_data* sd, unsigned short id)
  8390. {
  8391. int fd;
  8392. nullpo_retv(sd);
  8393. fd = sd->fd;
  8394. WFIFOHEAD(fd, packet_len(0x291));
  8395. WFIFOW(fd, 0) = 0x291;
  8396. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8397. WFIFOSET(fd, packet_len(0x291));
  8398. }
  8399. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8400. /// 0x7e2 <message>.W <value>.L
  8401. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8402. {
  8403. int fd = sd->fd;
  8404. WFIFOHEAD(fd, packet_len(0x7e2));
  8405. WFIFOW(fd,0) = 0x7e2;
  8406. WFIFOW(fd,2) = id;
  8407. WFIFOL(fd,4) = value;
  8408. WFIFOSET(fd, packet_len(0x7e2));
  8409. }
  8410. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8411. /// 07e6 <skill id>.W <msg id>.L
  8412. ///
  8413. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8414. /// "[SkillName] Message"
  8415. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8416. {
  8417. int fd = sd->fd;
  8418. WFIFOHEAD(fd, packet_len(0x7e6));
  8419. WFIFOW(fd,0) = 0x7e6;
  8420. WFIFOW(fd,2) = skill_id;
  8421. WFIFOL(fd,4) = msg_id;
  8422. WFIFOSET(fd, packet_len(0x7e6));
  8423. }
  8424. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8425. /// Returns true if the packet was parsed successfully.
  8426. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8427. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8428. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8429. char* seperator = " : ";
  8430. int fd;
  8431. struct s_packet_db* info;
  8432. uint16 packetLength, inputLength;
  8433. const char *input, *name, *message;
  8434. size_t nameLength, messageLength;
  8435. fd = sd->fd;
  8436. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8437. packetLength = RFIFOW(fd,info->pos[0]);
  8438. input = (const char*)RFIFOP(fd,info->pos[1]);
  8439. // basic structure check for the 4-byte header
  8440. if( packetLength < 4 ){
  8441. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8442. return false;
  8443. }else{
  8444. inputLength = packetLength - 4;
  8445. }
  8446. // process <name> part of the packet
  8447. if( whisperFormat ) {
  8448. // name has fixed width
  8449. if( inputLength < NAME_LENGTH + 1 ) {
  8450. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8451. return false;
  8452. }
  8453. name = input;
  8454. // validate name
  8455. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8456. // only restriction is that the name must be zero-terminated
  8457. if( name[nameLength] != '\0' ) {
  8458. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8459. return false;
  8460. }
  8461. message = input + NAME_LENGTH;
  8462. messageLength = inputLength - NAME_LENGTH;
  8463. }else{
  8464. // name and message are separated by ' : '
  8465. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8466. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8467. // check if there's enough data provided
  8468. if( inputLength < nameLength + seperatorLength + 1 ){
  8469. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8470. return false;
  8471. }
  8472. name = input;
  8473. // validate name
  8474. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8475. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8476. {
  8477. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8478. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8479. set_eof(sd->fd); // Just kick them out to correct it.
  8480. return false;
  8481. }
  8482. message = input + nameLength + seperatorLength;
  8483. messageLength = inputLength - nameLength - seperatorLength;
  8484. }
  8485. #if PACKETVER < 20151001
  8486. // the declared length must match real length
  8487. if( messageLength != strnlen(message, messageLength)+1 ) {
  8488. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8489. return false;
  8490. }
  8491. // verify <message> part of the packet
  8492. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8493. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8494. return false;
  8495. }
  8496. #else
  8497. // No zero termination anymore
  8498. messageLength += 1;
  8499. #endif
  8500. // messages mustn't be too long
  8501. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8502. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8503. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8504. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8505. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8506. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8507. return false;
  8508. }
  8509. // If it is not a whisper message, set the name to the fakename of the player
  8510. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8511. strcpy( out_name, sd->fakename );
  8512. }else{
  8513. safestrncpy( out_name, name, nameLength + 1 );
  8514. }
  8515. safestrncpy( out_message, message, messageLength );
  8516. if( whisperFormat ){
  8517. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8518. out_full_message[nameLength] = '\0';
  8519. }else{
  8520. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8521. }
  8522. if( is_atcommand( fd, sd, out_message, 1 ) )
  8523. return false;
  8524. if (sd->sc.cant.chat)
  8525. return false; //no "chatting" while muted.
  8526. if( battle_config.min_chat_delay ) { //[Skotlex]
  8527. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8528. return false;
  8529. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8530. }
  8531. if (battle_config.idletime_option&IDLE_CHAT)
  8532. sd->idletime = last_tick;
  8533. return true;
  8534. }
  8535. // ---------------------
  8536. // clif_guess_PacketVer
  8537. // ---------------------
  8538. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8539. // error codes:
  8540. // 0 - Success
  8541. // 1 - Unknown packet_ver
  8542. // 2 - Invalid account_id
  8543. // 3 - Invalid char_id
  8544. // 4 - Invalid login_id1 (reserved)
  8545. // 5 - Invalid client_tick (reserved)
  8546. // 6 - Invalid sex
  8547. // Only the first 'invalid' error that appears is used.
  8548. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8549. {
  8550. static int err = 1;
  8551. static int packet_ver = -1;
  8552. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8553. unsigned short cmd;
  8554. if (get_previous)
  8555. {//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]
  8556. if( error )
  8557. *error = err;
  8558. return packet_ver;
  8559. }
  8560. //By default, start searching on the default one.
  8561. err = 1;
  8562. packet_ver = clif_config.packet_db_ver;
  8563. cmd = clif_parse_cmd(fd, NULL);
  8564. packet_len = RFIFOREST(fd);
  8565. #define SET_ERROR(n) \
  8566. if( err == 1 )\
  8567. err = n;\
  8568. //define SET_ERROR
  8569. // FIXME: If the packet is not received at once, this will FAIL.
  8570. // Figure out, when it happens, that only part of the packet is
  8571. // received, or fix the function to be able to deal with that
  8572. // case.
  8573. #define CHECK_PACKET_VER() \
  8574. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8575. ;/* not wanttoconnection or wrong length */\
  8576. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8577. { SET_ERROR(2); }/* invalid account_id */\
  8578. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8579. { SET_ERROR(3); }/* invalid char_id */\
  8580. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8581. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8582. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8583. { SET_ERROR(6); }/* invalid sex */\
  8584. else\
  8585. {\
  8586. err = 0;\
  8587. if( error )\
  8588. *error = 0;\
  8589. return packet_ver;\
  8590. }\
  8591. //define CHECK_PACKET_VER
  8592. CHECK_PACKET_VER();//Default packet version found.
  8593. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8594. CHECK_PACKET_VER();
  8595. }
  8596. if( error )
  8597. *error = err;
  8598. packet_ver = -1;
  8599. return -1;
  8600. #undef SET_ERROR
  8601. #undef CHECK_PACKET_VER
  8602. }
  8603. // ------------
  8604. // clif_parse_*
  8605. // ------------
  8606. // Parses incoming (player) connection
  8607. /// Request to connect to map-server.
  8608. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8609. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8610. /// There are various variants of this packet, some of them have padding between fields.
  8611. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8612. {
  8613. struct block_list* bl;
  8614. struct auth_node* node;
  8615. int cmd, account_id, char_id, login_id1, sex;
  8616. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8617. 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])
  8618. if (sd) {
  8619. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8620. return;
  8621. }
  8622. // Only valid packet version get here
  8623. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8624. cmd = RFIFOW(fd,0);
  8625. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8626. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8627. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8628. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8629. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8630. if( packet_ver < 5 || // reject really old client versions
  8631. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8632. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8633. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8634. {// packet version rejected
  8635. 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));
  8636. WFIFOHEAD(fd,packet_len(0x6a));
  8637. WFIFOW(fd,0) = 0x6a;
  8638. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8639. WFIFOSET(fd,packet_len(0x6a));
  8640. set_eof(fd);
  8641. return;
  8642. }
  8643. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8644. clif_authfail_fd(fd,1);// server closed
  8645. return;
  8646. }
  8647. //Check for double login.
  8648. bl = map_id2bl(account_id);
  8649. if(bl && bl->type != BL_PC) {
  8650. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8651. WFIFOHEAD(fd,packet_len(0x6a));
  8652. WFIFOW(fd,0) = 0x6a;
  8653. WFIFOB(fd,2) = 3; // Rejected by server
  8654. WFIFOSET(fd,packet_len(0x6a));
  8655. set_eof(fd);
  8656. return;
  8657. }
  8658. if (bl ||
  8659. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8660. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8661. {
  8662. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8663. return;
  8664. }
  8665. CREATE(sd, TBL_PC, 1);
  8666. sd->fd = fd;
  8667. sd->packet_ver = packet_ver;
  8668. #ifdef PACKET_OBFUSCATION
  8669. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8670. #endif
  8671. session[fd]->session_data = sd;
  8672. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8673. #if PACKETVER < 20070521
  8674. WFIFOHEAD(fd,4);
  8675. WFIFOL(fd,0) = sd->bl.id;
  8676. WFIFOSET(fd,4);
  8677. #else
  8678. WFIFOHEAD(fd,packet_len(0x283));
  8679. WFIFOW(fd,0) = 0x283;
  8680. WFIFOL(fd,2) = sd->bl.id;
  8681. WFIFOSET(fd,packet_len(0x283));
  8682. #endif
  8683. chrif_authreq(sd,false);
  8684. }
  8685. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8686. /// 007d
  8687. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8688. {
  8689. bool guild_notice = false;
  8690. if(sd->bl.prev != NULL)
  8691. return;
  8692. if (!sd->state.active) { //Character loading is not complete yet!
  8693. //Let pc_reg_received reinvoke this when ready.
  8694. sd->state.connect_new = 0;
  8695. return;
  8696. }
  8697. if (sd->state.rewarp) { //Rewarp player.
  8698. sd->state.rewarp = 0;
  8699. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8700. return;
  8701. }
  8702. sd->state.warping = 0;
  8703. // look
  8704. #if PACKETVER < 4
  8705. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8706. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8707. #else
  8708. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8709. #endif
  8710. pc_set_costume_view(sd);
  8711. if(sd->vd.cloth_color)
  8712. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8713. if(sd->vd.body_style)
  8714. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8715. // item
  8716. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8717. pc_checkitem(sd);
  8718. // cart
  8719. if(pc_iscarton(sd)) {
  8720. clif_cartlist(sd);
  8721. clif_updatestatus(sd,SP_CARTINFO);
  8722. }
  8723. // weight
  8724. clif_updatestatus(sd,SP_WEIGHT);
  8725. clif_updatestatus(sd,SP_MAXWEIGHT);
  8726. // guild
  8727. // (needs to go before clif_spawn() to show guild emblems correctly)
  8728. if(sd->status.guild_id)
  8729. guild_send_memberinfoshort(sd,1);
  8730. if(battle_config.pc_invincible_time > 0) {
  8731. if(map_flag_gvg(sd->bl.m))
  8732. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8733. else
  8734. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8735. }
  8736. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8737. map_spawnmobs(sd->bl.m);
  8738. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8739. map[sd->bl.m].users_pvp++;
  8740. }
  8741. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8742. // reset the callshop flag if the player changes map
  8743. sd->state.callshop = 0;
  8744. if(map_addblock(&sd->bl))
  8745. return;
  8746. clif_spawn(&sd->bl);
  8747. // Party
  8748. // (needs to go after clif_spawn() to show hp bars correctly)
  8749. if(sd->status.party_id) {
  8750. party_send_movemap(sd);
  8751. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8752. }
  8753. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8754. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8755. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8756. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8757. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8758. sd->pvp_rank = 0;
  8759. sd->pvp_lastusers = 0;
  8760. sd->pvp_point = 5;
  8761. sd->pvp_won = 0;
  8762. sd->pvp_lost = 0;
  8763. }
  8764. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8765. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8766. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8767. else if (map[sd->bl.m].flag.gvg_dungeon)
  8768. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8769. else if( map_flag_gvg(sd->bl.m) )
  8770. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8771. else
  8772. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8773. // info about nearby objects
  8774. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8775. 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);
  8776. // pet
  8777. if( sd->pd ) {
  8778. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8779. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8780. pet_menu(sd, 3); //Option 3 is return to egg.
  8781. } else {
  8782. if(map_addblock(&sd->pd->bl))
  8783. return;
  8784. clif_spawn(&sd->pd->bl);
  8785. clif_send_petdata(sd,sd->pd,0,0);
  8786. clif_send_petstatus(sd);
  8787. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8788. }
  8789. }
  8790. //homunculus [blackhole89]
  8791. if( hom_is_active(sd->hd) ) {
  8792. if(map_addblock(&sd->hd->bl))
  8793. return;
  8794. clif_spawn(&sd->hd->bl);
  8795. clif_send_homdata(sd,SP_ACK,0);
  8796. clif_hominfo(sd,sd->hd,1);
  8797. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8798. clif_homskillinfoblock(sd);
  8799. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8800. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8801. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8802. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8803. }
  8804. if( sd->md ) {
  8805. if(map_addblock(&sd->md->bl))
  8806. return;
  8807. clif_spawn(&sd->md->bl);
  8808. clif_mercenary_info(sd);
  8809. clif_mercenary_skillblock(sd);
  8810. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8811. }
  8812. if( sd->ed ) {
  8813. if (map_addblock(&sd->ed->bl))
  8814. return;
  8815. clif_spawn(&sd->ed->bl);
  8816. clif_elemental_info(sd);
  8817. clif_elemental_updatestatus(sd,SP_HP);
  8818. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8819. clif_elemental_updatestatus(sd,SP_SP);
  8820. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8821. }
  8822. if(sd->state.connect_new) {
  8823. int lv;
  8824. guild_notice = true;
  8825. clif_skillinfoblock(sd);
  8826. clif_hotkeys_send(sd);
  8827. clif_updatestatus(sd,SP_BASEEXP);
  8828. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8829. clif_updatestatus(sd,SP_JOBEXP);
  8830. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8831. clif_updatestatus(sd,SP_SKILLPOINT);
  8832. clif_initialstatus(sd);
  8833. if (sd->sc.option&OPTION_FALCON)
  8834. clif_status_load(&sd->bl, SI_FALCON, 1);
  8835. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8836. clif_status_load(&sd->bl, SI_RIDING, 1);
  8837. else if (sd->sc.option&OPTION_WUGRIDER)
  8838. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8839. else if (sd->sc.data[SC_ALL_RIDING])
  8840. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8841. if(sd->status.manner < 0)
  8842. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8843. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8844. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8845. if(sd->bl.m == sd->feel_map[0].m
  8846. || sd->bl.m == sd->feel_map[1].m
  8847. || sd->bl.m == sd->feel_map[2].m)
  8848. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8849. }
  8850. if(sd->pd && sd->pd->pet.intimate > 900)
  8851. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8852. if(hom_is_active(sd->hd))
  8853. hom_init_timers(sd->hd);
  8854. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8855. sd->state.night = 1;
  8856. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8857. }
  8858. // Notify everyone that this char logged in [Skotlex].
  8859. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8860. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8861. //Login Event
  8862. npc_script_event(sd, NPCE_LOGIN);
  8863. }
  8864. } else {
  8865. //For some reason the client "loses" these on warp/map-change.
  8866. clif_updatestatus(sd,SP_STR);
  8867. clif_updatestatus(sd,SP_AGI);
  8868. clif_updatestatus(sd,SP_VIT);
  8869. clif_updatestatus(sd,SP_INT);
  8870. clif_updatestatus(sd,SP_DEX);
  8871. clif_updatestatus(sd,SP_LUK);
  8872. // abort currently running script
  8873. sd->state.using_fake_npc = 0;
  8874. sd->state.menu_or_input = 0;
  8875. sd->npc_menu = 0;
  8876. if(sd->npc_id)
  8877. npc_event_dequeue(sd);
  8878. }
  8879. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8880. #if PACKETVER >= 20070918
  8881. clif_partyinvitationstate(sd);
  8882. clif_equipcheckbox(sd);
  8883. #endif
  8884. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8885. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8886. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8887. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8888. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8889. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8890. { //Display night.
  8891. if( !sd->state.night )
  8892. {
  8893. sd->state.night = 1;
  8894. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8895. }
  8896. }
  8897. else if( sd->state.night )
  8898. { //Clear night display.
  8899. sd->state.night = 0;
  8900. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8901. }
  8902. if( map[sd->bl.m].flag.battleground )
  8903. {
  8904. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8905. if( map[sd->bl.m].flag.battleground == 2 )
  8906. clif_bg_updatescore_single(sd);
  8907. }
  8908. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8909. {
  8910. char output[128];
  8911. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8912. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8913. }
  8914. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8915. map[sd->bl.m].hpmeter_visible++;
  8916. sd->state.hpmeter_visible = 1;
  8917. }
  8918. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  8919. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8920. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8921. #ifdef VIP_ENABLE
  8922. if (!sd->state.connect_new &&
  8923. !sd->vip.disableshowrate &&
  8924. sd->state.pmap != sd->bl.m &&
  8925. map[sd->state.pmap].adjust.bexp != map[sd->bl.m].adjust.bexp
  8926. )
  8927. {
  8928. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8929. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8930. }
  8931. #endif
  8932. // Instances do not need their own channels
  8933. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8934. channel_mjoin(sd); //join new map
  8935. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8936. clif_guild_notice(sd, sd->guild); // Displays at end
  8937. mail_clear(sd);
  8938. /* Guild Aura Init */
  8939. if( sd->state.gmaster_flag ) {
  8940. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8941. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8942. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8943. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8944. }
  8945. if( sd->state.vending ) { /* show we have a vending */
  8946. clif_openvending(sd,sd->bl.id,sd->vending);
  8947. clif_showvendingboard(&sd->bl,sd->message,0);
  8948. }
  8949. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8950. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8951. npc_script_event(sd, NPCE_LOADMAP);
  8952. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  8953. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8954. if (sd->sc.opt2) //Client loses these on warp.
  8955. clif_changeoption(&sd->bl);
  8956. if ((sd->sc.data[SC_MONSTER_TRANSFORM] || sd->sc.data[SC_ACTIVE_MONSTER_TRANSFORM]) && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8957. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8958. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  8959. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8960. }
  8961. clif_weather_check(sd);
  8962. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8963. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8964. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8965. else
  8966. sd->areanpc_id = 0;
  8967. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8968. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8969. pc_setdead(sd);
  8970. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8971. if(pc_isdead(sd))
  8972. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8973. else {
  8974. skill_usave_trigger(sd);
  8975. if (battle_config.spawn_direction)
  8976. clif_changed_dir(&sd->bl, SELF);
  8977. }
  8978. // Trigger skill effects if you appear standing on them
  8979. if(!battle_config.pc_invincible_time)
  8980. skill_unit_move(&sd->bl,gettick(),1);
  8981. pc_show_questinfo_reinit(sd);
  8982. pc_show_questinfo(sd);
  8983. sd->state.connect_new = 0;
  8984. sd->state.changemap = false;
  8985. }
  8986. /// Server's tick (ZC_NOTIFY_TIME).
  8987. /// 007f <time>.L
  8988. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8989. {
  8990. int fd = sd->fd;
  8991. WFIFOHEAD(fd,packet_len(0x7f));
  8992. WFIFOW(fd,0) = 0x7f;
  8993. WFIFOL(fd,2) = time;
  8994. WFIFOSET(fd,packet_len(0x7f));
  8995. }
  8996. /// Request for server's tick.
  8997. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8998. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8999. /// There are various variants of this packet, some of them have padding between fields.
  9000. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9001. {
  9002. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9003. clif_notify_time(sd, gettick());
  9004. }
  9005. /// Sends hotkey bar.
  9006. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9007. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9008. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9009. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9010. void clif_hotkeys_send(struct map_session_data *sd) {
  9011. #ifdef HOTKEY_SAVING
  9012. const int fd = sd->fd;
  9013. int i;
  9014. int offset = 2;
  9015. #if PACKETVER < 20090603
  9016. const int cmd = 0x2b9;
  9017. #elif PACKETVER < 20141022
  9018. const int cmd = 0x7d9;
  9019. #else
  9020. char Rotate = sd->status.hotkey_rowshift;
  9021. const int cmd = 0xa00;
  9022. offset = 3;
  9023. #endif
  9024. if (!fd) return;
  9025. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9026. WFIFOW(fd, 0) = cmd;
  9027. #if PACKETVER >= 20141022
  9028. WFIFOB(fd, 2) = Rotate;
  9029. #endif
  9030. for(i = 0; i < MAX_HOTKEYS; i++) {
  9031. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9032. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9033. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9034. }
  9035. WFIFOSET(fd, packet_len(cmd));
  9036. #endif
  9037. }
  9038. /// Request to update a position on the hotkey row bar
  9039. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9040. int cmd = RFIFOW(fd, 0);
  9041. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  9042. }
  9043. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9044. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9045. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9046. #ifdef HOTKEY_SAVING
  9047. unsigned short idx;
  9048. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9049. idx = RFIFOW(fd, info->pos[0]);
  9050. if (idx >= MAX_HOTKEYS) return;
  9051. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9052. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9053. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9054. #endif
  9055. }
  9056. /// Displays cast-like progress bar (ZC_PROGRESS).
  9057. /// 02f0 <color>.L <time>.L
  9058. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9059. {
  9060. int fd = sd->fd;
  9061. WFIFOHEAD(fd,packet_len(0x2f0));
  9062. WFIFOW(fd,0) = 0x2f0;
  9063. WFIFOL(fd,2) = color;
  9064. WFIFOL(fd,6) = second;
  9065. WFIFOSET(fd,packet_len(0x2f0));
  9066. }
  9067. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9068. /// 02f2
  9069. void clif_progressbar_abort(struct map_session_data * sd)
  9070. {
  9071. int fd = sd->fd;
  9072. WFIFOHEAD(fd,packet_len(0x2f2));
  9073. WFIFOW(fd,0) = 0x2f2;
  9074. WFIFOSET(fd,packet_len(0x2f2));
  9075. }
  9076. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9077. /// 02f1
  9078. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9079. {
  9080. int npc_id = sd->progressbar.npc_id;
  9081. if( gettick() < sd->progressbar.timeout && sd->st )
  9082. sd->st->state = END;
  9083. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9084. sd->state.workinprogress = WIP_DISABLE_NONE;
  9085. npc_scriptcont(sd, npc_id, false);
  9086. }
  9087. /// Request to walk to a certain position on the current map.
  9088. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9089. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9090. /// There are various variants of this packet, some of them have padding between fields.
  9091. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9092. {
  9093. short x, y;
  9094. if (pc_isdead(sd)) {
  9095. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9096. return;
  9097. }
  9098. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9099. ; //You CAN walk on this OPT1 value.
  9100. else if (sd->progressbar.npc_id) {
  9101. clif_progressbar_abort(sd);
  9102. return; // First walk attempt cancels the progress bar
  9103. } else if (pc_cant_act(sd))
  9104. return;
  9105. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9106. return;
  9107. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9108. //A move command one cell west is only valid if the target cell is free
  9109. if(battle_config.official_cell_stack_limit > 0
  9110. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9111. return;
  9112. // Cloaking wall check is actually updated when you click to process next movement
  9113. // not when you move each cell. This is official behaviour.
  9114. if (sd->sc.data[SC_CLOAKING])
  9115. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9116. pc_delinvincibletimer(sd);
  9117. //Set last idle time... [Skotlex]
  9118. if (battle_config.idletime_option&IDLE_WALK)
  9119. sd->idletime = last_tick;
  9120. unit_walktoxy(&sd->bl, x, y, 4);
  9121. }
  9122. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9123. /// 018b <result>.W
  9124. /// result:
  9125. /// 0 = disconnect (quit)
  9126. /// 1 = cannot disconnect (wait 10 seconds)
  9127. /// ? = ignored
  9128. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9129. {
  9130. int fd = sd->fd;
  9131. WFIFOHEAD(fd,packet_len(0x18b));
  9132. WFIFOW(fd,0) = 0x18b;
  9133. WFIFOW(fd,2) = result;
  9134. WFIFOSET(fd,packet_len(0x18b));
  9135. }
  9136. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9137. /// 018a <type>.W
  9138. /// type:
  9139. /// 0 = quit
  9140. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9141. {
  9142. /* Rovert's prevent logout option fixed [Valaris] */
  9143. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9144. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9145. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9146. {
  9147. set_eof(fd);
  9148. pc_damage_log_clear(sd,0);
  9149. clif_disconnect_ack(sd, 0);
  9150. } else {
  9151. clif_disconnect_ack(sd, 1);
  9152. }
  9153. }
  9154. /// Requesting unit's name.
  9155. /// 0094 <id>.L (CZ_REQNAME)
  9156. /// 0368 <id>.L (CZ_REQNAME2)
  9157. /// There are various variants of this packet, some of them have padding between fields.
  9158. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9159. {
  9160. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9161. struct block_list* bl;
  9162. //struct status_change *sc;
  9163. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9164. id = sd->bl.id;
  9165. bl = map_id2bl(id);
  9166. if( bl == NULL )
  9167. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9168. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9169. return; // Block namerequests past view range
  9170. // 'see people in GM hide' cheat detection
  9171. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9172. sc = status_get_sc(bl);
  9173. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9174. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9175. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9176. ) {
  9177. char gm_msg[256];
  9178. 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);
  9179. ShowWarning(gm_msg);
  9180. // information is sent to all online GMs
  9181. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9182. return;
  9183. }
  9184. */
  9185. clif_charnameack(fd, bl);
  9186. }
  9187. /// Validates and processes global messages
  9188. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9189. /// There are various variants of this packet.
  9190. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9191. {
  9192. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9193. size_t length;
  9194. // validate packet and retrieve name and message
  9195. if( !clif_process_message(sd, false, name, message, output ) )
  9196. return;
  9197. if( sd->gcbind ) {
  9198. channel_send(sd->gcbind,sd,message);
  9199. return;
  9200. }
  9201. // send message to others (using the send buffer for temp. storage)
  9202. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9203. length = strlen(output) + 1;
  9204. // send back message to the speaker
  9205. WFIFOHEAD(fd,4+length);
  9206. WFIFOW(fd,0) = 0x8e;
  9207. WFIFOW(fd,2) = (uint16)(4+length);
  9208. safestrncpy((char*)WFIFOP(fd,4), output, length );
  9209. WFIFOSET(fd, WFIFOW(fd,2));
  9210. #ifdef PCRE_SUPPORT
  9211. // trigger listening npcs
  9212. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9213. #endif
  9214. // Chat logging type 'O' / Global Chat
  9215. 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);
  9216. }
  9217. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9218. /// Request to warp to a map on given coordinates.
  9219. /// 0140 <map name>.16B <x>.W <y>.W
  9220. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9221. {
  9222. char command[MAP_NAME_LENGTH_EXT+25];
  9223. char* map_name;
  9224. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9225. map_name = (char*)RFIFOP(fd,info->pos[0]);
  9226. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9227. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9228. RFIFOW(fd,info->pos[1]), //x
  9229. RFIFOW(fd,info->pos[2])); //y
  9230. is_atcommand(fd, sd, command, 1);
  9231. }
  9232. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9233. /// 009c <id>.L <head dir>.W <dir>.B
  9234. /// head dir:
  9235. /// 0 = straight
  9236. /// 1 = turned CW
  9237. /// 2 = turned CCW
  9238. /// dir:
  9239. /// 0 = north
  9240. /// 1 = northwest
  9241. /// 2 = west
  9242. /// 3 = southwest
  9243. /// 4 = south
  9244. /// 5 = southeast
  9245. /// 6 = east
  9246. /// 7 = northeast
  9247. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9248. {
  9249. unsigned char buf[64];
  9250. WBUFW(buf,0) = 0x9c;
  9251. WBUFL(buf,2) = bl->id;
  9252. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9253. WBUFB(buf,8) = unit_getdir(bl);
  9254. clif_send(buf, packet_len(0x9c), bl, target);
  9255. if (disguised(bl)) {
  9256. WBUFL(buf,2) = -bl->id;
  9257. WBUFW(buf,6) = 0;
  9258. clif_send(buf, packet_len(0x9c), bl, SELF);
  9259. }
  9260. }
  9261. /// Request to change own body and head direction.
  9262. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9263. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9264. /// There are various variants of this packet, some of them have padding between fields.
  9265. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9266. {
  9267. unsigned char headdir, dir;
  9268. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9269. headdir = RFIFOB(fd,info->pos[0]);
  9270. dir = RFIFOB(fd,info->pos[1]);
  9271. pc_setdir(sd, dir, headdir);
  9272. clif_changed_dir(&sd->bl, AREA_WOS);
  9273. }
  9274. /// Request to show an emotion (CZ_REQ_EMOTION).
  9275. /// 00bf <type>.B
  9276. /// type:
  9277. /// @see enum emotion_type
  9278. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9279. {
  9280. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9281. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9282. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9283. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9284. return;
  9285. }
  9286. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9287. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9288. sd->emotionlasttime = time(NULL);
  9289. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9290. return;
  9291. }
  9292. sd->emotionlasttime = time(NULL);
  9293. if (battle_config.idletime_option&IDLE_EMOTION)
  9294. sd->idletime = last_tick;
  9295. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9296. emoticon = rnd()%6+E_DICE1;
  9297. }
  9298. clif_emotion(&sd->bl, emoticon);
  9299. } else
  9300. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9301. }
  9302. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9303. /// 00c2 <count>.L
  9304. void clif_user_count(struct map_session_data* sd, int count)
  9305. {
  9306. int fd = sd->fd;
  9307. WFIFOHEAD(fd,packet_len(0xc2));
  9308. WFIFOW(fd,0) = 0xc2;
  9309. WFIFOL(fd,2) = count;
  9310. WFIFOSET(fd,packet_len(0xc2));
  9311. }
  9312. /// /w /who (CZ_REQ_USER_COUNT).
  9313. /// Request to display amount of currently connected players.
  9314. /// 00c1
  9315. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9316. {
  9317. clif_user_count(sd, map_getusers());
  9318. }
  9319. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9320. {
  9321. if (pc_isdead(sd)) {
  9322. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9323. return;
  9324. }
  9325. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9326. // (not all are included in pc_can_attack)
  9327. if (sd->sc.count &&
  9328. (sd->sc.data[SC_TRICKDEAD] ||
  9329. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9330. sd->sc.data[SC_BLADESTOP] ||
  9331. sd->sc.data[SC__MANHOLE] ||
  9332. sd->sc.data[SC_SUHIDE] ))
  9333. return;
  9334. if(action_type != 0x00 && action_type != 0x07)
  9335. pc_stop_walking(sd, 1);
  9336. pc_stop_attack(sd);
  9337. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9338. target_id = sd->bl.id;
  9339. switch(action_type)
  9340. {
  9341. case 0x00: // once attack
  9342. case 0x07: // continuous attack
  9343. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9344. return;
  9345. if( sd->sc.option&OPTION_COSTUME )
  9346. return;
  9347. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9348. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9349. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9350. return;
  9351. }
  9352. }
  9353. pc_delinvincibletimer(sd);
  9354. if (battle_config.idletime_option&IDLE_ATTACK)
  9355. sd->idletime = last_tick;
  9356. unit_attack(&sd->bl, target_id, action_type != 0);
  9357. break;
  9358. case 0x02: // sitdown
  9359. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9360. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9361. break;
  9362. }
  9363. if(pc_issit(sd)) {
  9364. //Bugged client? Just refresh them.
  9365. clif_sitting(&sd->bl);
  9366. return;
  9367. }
  9368. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9369. break;
  9370. if (sd->sc.count && (
  9371. sd->sc.data[SC_DANCING] ||
  9372. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9373. )) //No sitting during these states either.
  9374. break;
  9375. if (battle_config.idletime_option&IDLE_SIT)
  9376. sd->idletime = last_tick;
  9377. pc_setsit(sd);
  9378. skill_sit(sd, 1);
  9379. clif_sitting(&sd->bl);
  9380. break;
  9381. case 0x03: // standup
  9382. if (!pc_issit(sd)) {
  9383. //Bugged client? Just refresh them.
  9384. clif_standing(&sd->bl);
  9385. return;
  9386. }
  9387. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9388. break;
  9389. if (pc_setstand(sd, false)) {
  9390. if (battle_config.idletime_option&IDLE_SIT)
  9391. sd->idletime = last_tick;
  9392. skill_sit(sd, 0);
  9393. clif_standing(&sd->bl);
  9394. }
  9395. break;
  9396. }
  9397. }
  9398. /// Request for an action.
  9399. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9400. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9401. /// action:
  9402. /// 0 = attack
  9403. /// 1 = pick up item
  9404. /// 2 = sit down
  9405. /// 3 = stand up
  9406. /// 7 = continous attack
  9407. /// 12 = (touch skill?)
  9408. /// There are various variants of this packet, some of them have padding between fields.
  9409. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9410. {
  9411. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9412. clif_parse_ActionRequest_sub(sd,
  9413. RFIFOB(fd,info->pos[1]),
  9414. RFIFOL(fd,info->pos[0]),
  9415. gettick()
  9416. );
  9417. }
  9418. /// Response to the death/system menu (CZ_RESTART).
  9419. /// 00b2 <type>.B
  9420. /// type:
  9421. /// 0 = restart (respawn)
  9422. /// 1 = char-select (disconnect)
  9423. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9424. {
  9425. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9426. case 0x00:
  9427. pc_respawn(sd,CLR_OUTSIGHT);
  9428. break;
  9429. case 0x01:
  9430. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9431. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9432. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9433. { //Send to char-server for character selection.
  9434. pc_damage_log_clear(sd,0);
  9435. chrif_charselectreq(sd, session[fd]->client_addr);
  9436. } else {
  9437. clif_disconnect_ack(sd, 1);
  9438. }
  9439. break;
  9440. }
  9441. }
  9442. /// Validates and processes whispered messages (CZ_WHISPER).
  9443. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9444. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9445. {
  9446. struct map_session_data* dstsd;
  9447. int i;
  9448. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9449. // validate packet and retrieve name and message
  9450. if( !clif_process_message( sd, true, target, message, output ) )
  9451. return;
  9452. // Chat logging type 'W' / Whisper
  9453. 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);
  9454. //-------------------------------------------------------//
  9455. // Lordalfa - Paperboy - To whisper NPC commands //
  9456. //-------------------------------------------------------//
  9457. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9458. {
  9459. char* str = target+4; //Skip the NPC: string part.
  9460. struct npc_data* npc;
  9461. if ((npc = npc_name2id(str))) {
  9462. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9463. char *split;
  9464. char event[EVENT_NAME_LENGTH];
  9465. str = message;
  9466. // skip codepage indicator, if detected
  9467. if( str[0] == '|' && strlen(str) >= 4 )
  9468. str += 3;
  9469. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9470. split = strchr(str,'#');
  9471. if( split == NULL ) { // use the remaining string
  9472. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9473. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9474. split_data[i][0] = '\0';
  9475. break;
  9476. }
  9477. *split = '\0';
  9478. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9479. str = split+1;
  9480. }
  9481. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9482. char variablename[CHAT_SIZE_MAX];
  9483. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9484. set_var(sd,variablename,(char *) split_data[i]);
  9485. }
  9486. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9487. npc_event(sd,event,0); // Calls the NPC label
  9488. return;
  9489. }
  9490. } else if( target[0] == '#' ) {
  9491. struct Channel *channel = NULL;
  9492. char* chname = target;
  9493. channel = channel_name2channel(chname,sd,3);
  9494. if(channel){
  9495. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9496. channel_send(channel,sd,message);
  9497. }
  9498. else if( channel->pass[0] == '\0') { //no pass needed
  9499. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9500. }
  9501. else {
  9502. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9503. }
  9504. return;
  9505. }
  9506. }
  9507. // searching destination character
  9508. dstsd = map_nick2sd(target);
  9509. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9510. // player is not on this map-server
  9511. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9512. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9513. // and if we ask for 'Test', we must not contact 'test' player
  9514. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9515. intif_wis_message(sd, target, message, strlen(message));
  9516. return;
  9517. }
  9518. // if player ignores everyone
  9519. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9520. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9521. clif_wis_end(fd, 1); // 1: target character is not logged in
  9522. else
  9523. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9524. return;
  9525. }
  9526. // if player is autotrading
  9527. if (dstsd->state.autotrade == 1){
  9528. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9529. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9530. return;
  9531. }
  9532. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9533. // if player ignores the source character
  9534. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9535. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9536. clif_wis_end(fd, 2); // 2: ignored by target
  9537. return;
  9538. }
  9539. }
  9540. // notify sender of success
  9541. clif_wis_end(fd, 0); // 0: success to send wisper
  9542. // Normal message
  9543. clif_wis_message(dstsd->fd, sd->status.name, message, strlen(message)+1 );
  9544. }
  9545. /// /b /nb (CZ_BROADCAST).
  9546. /// Request to broadcast a message on whole server.
  9547. /// 0099 <packet len>.W <text>.?B 00
  9548. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9549. char command[CHAT_SIZE_MAX+11];
  9550. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9551. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9552. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9553. // as the length varies depending on the command used, just block unreasonably long strings
  9554. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9555. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9556. is_atcommand(fd, sd, command, 1);
  9557. }
  9558. /// Request to pick up an item.
  9559. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9560. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9561. /// There are various variants of this packet, some of them have padding between fields.
  9562. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9563. {
  9564. struct flooritem_data *fitem;
  9565. int map_object_id;
  9566. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9567. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9568. do {
  9569. if (pc_isdead(sd)) {
  9570. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9571. break;
  9572. }
  9573. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9574. break;
  9575. if (pc_cant_act(sd))
  9576. break;
  9577. if (!pc_takeitem(sd, fitem))
  9578. break;
  9579. return;
  9580. } while (0);
  9581. // Client REQUIRES a fail packet or you can no longer pick items.
  9582. clif_additem(sd,0,0,6);
  9583. }
  9584. /// Request to drop an item.
  9585. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9586. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9587. /// There are various variants of this packet, some of them have padding between fields.
  9588. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9589. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9590. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9591. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9592. for(;;) {
  9593. if (pc_isdead(sd))
  9594. break;
  9595. if (pc_cant_act2(sd) || sd->npc_id)
  9596. break;
  9597. if (sd->sc.count && (
  9598. sd->sc.data[SC_AUTOCOUNTER] ||
  9599. sd->sc.data[SC_BLADESTOP] ||
  9600. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9601. ))
  9602. break;
  9603. if (!pc_dropitem(sd, item_index, item_amount))
  9604. break;
  9605. if (battle_config.idletime_option&IDLE_DROPITEM)
  9606. sd->idletime = last_tick;
  9607. return;
  9608. }
  9609. //Because the client does not like being ignored.
  9610. clif_dropitem(sd, item_index,0);
  9611. }
  9612. /// Request to use an item.
  9613. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9614. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9615. /// There are various variants of this packet, some of them have padding between fields.
  9616. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9617. {
  9618. int n;
  9619. if (pc_isdead(sd)) {
  9620. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9621. return;
  9622. }
  9623. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9624. return;
  9625. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9626. if (battle_config.idletime_option&IDLE_USEITEM)
  9627. sd->idletime = last_tick;
  9628. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9629. if(n <0 || n >= MAX_INVENTORY)
  9630. return;
  9631. if (!pc_useitem(sd,n))
  9632. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9633. }
  9634. /// Request to equip an item
  9635. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9636. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9637. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9638. {
  9639. int index;
  9640. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9641. if(pc_isdead(sd)) {
  9642. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9643. return;
  9644. }
  9645. index = RFIFOW(fd,info->pos[0])-2;
  9646. if (index < 0 || index >= MAX_INVENTORY)
  9647. return; //Out of bounds check.
  9648. if(sd->npc_id && !sd->npc_item_flag) {
  9649. return;
  9650. } else if (sd->state.storage_flag || sd->sc.opt1)
  9651. ; //You can equip/unequip stuff while storage is open/under status changes
  9652. else if (pc_cant_act2(sd))
  9653. return;
  9654. if(!sd->status.inventory[index].identify) {
  9655. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9656. return;
  9657. }
  9658. if(!sd->inventory_data[index])
  9659. return;
  9660. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9661. pet_equipitem(sd,index);
  9662. return;
  9663. }
  9664. if (battle_config.idletime_option&IDLE_USEITEM)
  9665. sd->idletime = last_tick;
  9666. //Client doesn't send the position for ammo.
  9667. if(sd->inventory_data[index]->type == IT_AMMO)
  9668. pc_equipitem(sd,index,EQP_AMMO);
  9669. else {
  9670. int req_pos;
  9671. #if PACKETVER >= 20120925
  9672. req_pos = RFIFOL(fd,info->pos[1]);
  9673. #else
  9674. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9675. #endif
  9676. pc_equipitem(sd,index,req_pos);
  9677. }
  9678. }
  9679. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9680. /// 00ab <index>.W
  9681. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9682. {
  9683. int index;
  9684. if(pc_isdead(sd)) {
  9685. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9686. return;
  9687. }
  9688. if (sd->npc_id && !sd->npc_item_flag) {
  9689. return;
  9690. } else if (sd->state.storage_flag || sd->sc.opt1)
  9691. ; //You can equip/unequip stuff while storage is open/under status changes
  9692. else if (pc_cant_act2(sd))
  9693. return;
  9694. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9695. if (battle_config.idletime_option&IDLE_USEITEM)
  9696. sd->idletime = last_tick;
  9697. pc_unequipitem(sd,index,1);
  9698. }
  9699. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9700. /// 0090 <id>.L <type>.B
  9701. /// type:
  9702. /// 1 = click
  9703. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9704. {
  9705. struct block_list *bl;
  9706. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9707. if(pc_isdead(sd)) {
  9708. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9709. return;
  9710. }
  9711. #ifdef RENEWAL
  9712. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_NPC)) {
  9713. clif_msg(sd, WORK_IN_PROGRESS);
  9714. return;
  9715. }
  9716. #endif
  9717. if (pc_cant_act2(sd) || sd->npc_id)
  9718. return;
  9719. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9720. //type = RFIFOB(fd,info->pos[1]);
  9721. if (!bl) return;
  9722. switch (bl->type) {
  9723. case BL_MOB:
  9724. case BL_PC:
  9725. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9726. break;
  9727. case BL_NPC:
  9728. #ifdef RENEWAL
  9729. if (sd->ud.skill_id < RK_ENCHANTBLADE && sd->ud.skilltimer != INVALID_TIMER) { // Should only show an error message for non-3rd job skills with a running timer
  9730. clif_msg(sd, WORK_IN_PROGRESS);
  9731. break;
  9732. }
  9733. #endif
  9734. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9735. npc_click(sd,(TBL_NPC*)bl);
  9736. break;
  9737. }
  9738. }
  9739. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9740. /// 00c5 <id>.L <type>.B
  9741. /// type:
  9742. /// 0 = buy
  9743. /// 1 = sell
  9744. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9745. {
  9746. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9747. if (sd->state.trading)
  9748. return;
  9749. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9750. }
  9751. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9752. /// 00ca <result>.B
  9753. /// result:
  9754. /// 0 = "The deal has successfully completed."
  9755. /// 1 = "You do not have enough zeny."
  9756. /// 2 = "You are over your Weight Limit."
  9757. /// 3 = "Out of the maximum capacity, you have too many items."
  9758. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9759. {
  9760. int fd = sd->fd;
  9761. WFIFOHEAD(fd,packet_len(0xca));
  9762. WFIFOW(fd,0) = 0xca;
  9763. WFIFOB(fd,2) = result;
  9764. WFIFOSET(fd,packet_len(0xca));
  9765. }
  9766. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9767. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9768. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9769. {
  9770. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9771. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9772. int result;
  9773. if( sd->state.trading || !sd->npc_shopid )
  9774. result = 1;
  9775. else
  9776. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9777. sd->npc_shopid = 0; //Clear shop data.
  9778. clif_npc_buy_result(sd, result);
  9779. }
  9780. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9781. /// 00cb <result>.B
  9782. /// result:
  9783. /// 0 = "The deal has successfully completed."
  9784. /// 1 = "The deal has failed."
  9785. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9786. {
  9787. int fd = sd->fd;
  9788. WFIFOHEAD(fd,packet_len(0xcb));
  9789. WFIFOW(fd,0) = 0xcb;
  9790. WFIFOB(fd,2) = result;
  9791. WFIFOSET(fd,packet_len(0xcb));
  9792. }
  9793. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9794. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9795. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9796. {
  9797. int fail=0,n;
  9798. unsigned short *item_list;
  9799. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9800. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9801. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9802. if (sd->state.trading || !sd->npc_shopid)
  9803. fail = 1;
  9804. else
  9805. fail = npc_selllist(sd,n,item_list);
  9806. sd->npc_shopid = 0; //Clear shop data.
  9807. clif_npc_sell_result(sd, fail);
  9808. }
  9809. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9810. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9811. /// type:
  9812. /// 0 = private
  9813. /// 1 = public
  9814. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9815. {
  9816. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9817. int len = RFIFOW(fd,info->pos[0])-15;
  9818. int limit = RFIFOW(fd,info->pos[1]);
  9819. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9820. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9821. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9822. char s_password[CHATROOM_PASS_SIZE];
  9823. char s_title[CHATROOM_TITLE_SIZE];
  9824. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9825. return;
  9826. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9827. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9828. return;
  9829. }
  9830. if( npc_isnear(&sd->bl) ) {
  9831. // uncomment to send msg_txt.
  9832. //char output[150];
  9833. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9834. //clif_displaymessage(sd->fd, output);
  9835. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9836. return;
  9837. }
  9838. if( len <= 0 )
  9839. return; // invalid input
  9840. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9841. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9842. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9843. }
  9844. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9845. /// 00d9 <chat ID>.L <passwd>.8B
  9846. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9847. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9848. int chatid = RFIFOL(fd,info->pos[0]);
  9849. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9850. chat_joinchat(sd,chatid,password);
  9851. }
  9852. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9853. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9854. /// type:
  9855. /// 0 = private
  9856. /// 1 = public
  9857. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9858. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9859. int len = RFIFOW(fd,info->pos[0])-15;
  9860. int limit = RFIFOW(fd,info->pos[1]);
  9861. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9862. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9863. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9864. char s_password[CHATROOM_PASS_SIZE];
  9865. char s_title[CHATROOM_TITLE_SIZE];
  9866. if( len <= 0 )
  9867. return; // invalid input
  9868. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9869. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9870. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9871. }
  9872. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9873. /// 00e0 <role>.L <nick>.24B
  9874. /// role:
  9875. /// 0 = owner
  9876. /// 1 = normal
  9877. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9878. {
  9879. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9880. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9881. }
  9882. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9883. /// 00e2 <name>.24B
  9884. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9885. {
  9886. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9887. }
  9888. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9889. /// 00e3
  9890. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9891. {
  9892. chat_leavechat(sd,0);
  9893. }
  9894. //Handles notifying asker and rejecter of what has just ocurred.
  9895. //Type is used to determine the correct msg_txt to use:
  9896. //0:
  9897. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9898. {
  9899. const char* msg;
  9900. char output[256];
  9901. // Your request has been rejected by autoreject option.
  9902. msg = msg_txt(sd,392);
  9903. clif_disp_onlyself(sd, msg, strlen(msg));
  9904. //Notice that a request was rejected.
  9905. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9906. clif_disp_onlyself(tsd, output, strlen(output));
  9907. }
  9908. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9909. /// 00e4 <account id>.L
  9910. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9911. {
  9912. struct map_session_data *t_sd;
  9913. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9914. if(!sd->chatID && pc_cant_act(sd))
  9915. return; //You can trade while in a chatroom.
  9916. // @noask [LuzZza]
  9917. if(t_sd && t_sd->state.noask) {
  9918. clif_noask_sub(sd, t_sd, 0);
  9919. return;
  9920. }
  9921. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9922. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9923. return;
  9924. }
  9925. trade_traderequest(sd,t_sd);
  9926. }
  9927. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9928. /// 00e6 <result>.B
  9929. /// result:
  9930. /// 3 = accepted
  9931. /// 4 = rejected
  9932. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9933. {
  9934. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9935. }
  9936. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9937. /// 00e8 <index>.W <amount>.L
  9938. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9939. {
  9940. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9941. short index = RFIFOW(fd,info->pos[0]);
  9942. int amount = RFIFOL(fd,info->pos[1]);
  9943. if( index == 0 )
  9944. trade_tradeaddzeny(sd, amount);
  9945. else
  9946. trade_tradeadditem(sd, index, (short)amount);
  9947. }
  9948. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9949. /// 00eb
  9950. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9951. {
  9952. trade_tradeok(sd);
  9953. }
  9954. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9955. /// 00ed
  9956. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9957. {
  9958. trade_tradecancel(sd);
  9959. }
  9960. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9961. /// 00ef
  9962. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9963. {
  9964. trade_tradecommit(sd);
  9965. }
  9966. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9967. /// 0118
  9968. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9969. {
  9970. pc_stop_attack(sd);
  9971. if (sd) sd->ud.state.attack_continue = 0;
  9972. }
  9973. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9974. /// 0126 <index>.W <amount>.L
  9975. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9976. {
  9977. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9978. if (pc_istrading(sd))
  9979. return;
  9980. if (!pc_iscarton(sd))
  9981. return;
  9982. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9983. }
  9984. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9985. /// 0127 <index>.W <amount>.L
  9986. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9987. {
  9988. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9989. if (!pc_iscarton(sd))
  9990. return;
  9991. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9992. }
  9993. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9994. /// 012a
  9995. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9996. {
  9997. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9998. #ifdef NEW_CARTS
  9999. && sd->sc.data[SC_PUSH_CART] )
  10000. pc_setcart(sd,0);
  10001. #else
  10002. )
  10003. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10004. #endif
  10005. else // priority to remove this option before we can clear cart
  10006. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10007. }
  10008. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10009. /// 097f <Length>.W <identity>.L <type>.B
  10010. void clif_SelectCart(struct map_session_data *sd) {
  10011. #if PACKETVER >= 20150826
  10012. int i = 0, carts = 3;
  10013. int fd = sd->fd;
  10014. WFIFOHEAD(fd,8 + carts);
  10015. WFIFOW(fd,0) = 0x97f;
  10016. WFIFOW(fd,2) = 8 + carts;
  10017. WFIFOL(fd,4) = sd->status.account_id;
  10018. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10019. for( i = 0; i < carts; i++ ) {
  10020. WFIFOB(fd,8 + i) = 10 + i;
  10021. }
  10022. WFIFOSET(fd,8 + carts);
  10023. #endif
  10024. }
  10025. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10026. /// 0980 <identity>.L <type>.B
  10027. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10028. #if PACKETVER >= 20150826
  10029. int type;
  10030. // Check identity
  10031. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10032. return;
  10033. type = (int)RFIFOB(fd,6);
  10034. // Check type
  10035. if( type < 10 || type > MAX_CARTS )
  10036. return;
  10037. pc_setcart(sd, type);
  10038. #endif
  10039. }
  10040. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10041. /// 01af <num>.W
  10042. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10043. {// TODO: State tracking?
  10044. int type;
  10045. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10046. return;
  10047. #ifdef RENEWAL
  10048. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10049. clif_msg(sd, WORK_IN_PROGRESS);
  10050. return;
  10051. }
  10052. #endif
  10053. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10054. if(
  10055. #ifdef NEW_CARTS
  10056. (type == 9 && sd->status.base_level > 130) ||
  10057. (type == 8 && sd->status.base_level > 120) ||
  10058. (type == 7 && sd->status.base_level > 110) ||
  10059. (type == 6 && sd->status.base_level > 100) ||
  10060. #endif
  10061. (type == 5 && sd->status.base_level > 90) ||
  10062. (type == 4 && sd->status.base_level > 80) ||
  10063. (type == 3 && sd->status.base_level > 65) ||
  10064. (type == 2 && sd->status.base_level > 40) ||
  10065. (type == 1))
  10066. pc_setcart(sd, type);
  10067. }
  10068. /// Request to increase status (CZ_STATUS_CHANGE).
  10069. /// 00bb <status id>.W <amount>.B
  10070. /// status id:
  10071. /// SP_STR ~ SP_LUK
  10072. /// amount:
  10073. /// Old clients always send 1 for this, even when using /str+ and the like.
  10074. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10075. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10076. {
  10077. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10078. if( increase_amount < 0 ) {
  10079. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10080. fd, increase_amount);
  10081. }
  10082. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  10083. }
  10084. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10085. /// 0112 <skill id>.W
  10086. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10087. {
  10088. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10089. }
  10090. 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)
  10091. {
  10092. int lv;
  10093. if( !hd )
  10094. return;
  10095. if( skill_isNotOk_hom(skill_id, hd) ) {
  10096. clif_emotion(&hd->bl, E_DOTS);
  10097. return;
  10098. }
  10099. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10100. target_id = hd->bl.id;
  10101. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10102. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10103. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10104. clif_emotion(&hd->bl, E_DOTS);
  10105. if (hd->master)
  10106. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10107. return;
  10108. }
  10109. lv = hom_checkskill(hd, skill_id);
  10110. if( skill_lv > lv )
  10111. skill_lv = lv;
  10112. if( skill_lv )
  10113. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10114. }
  10115. 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)
  10116. {
  10117. int lv;
  10118. if( !hd )
  10119. return;
  10120. if( skill_isNotOk_hom(skill_id, hd) ) {
  10121. clif_emotion(&hd->bl, E_DOTS);
  10122. return;
  10123. }
  10124. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10125. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10126. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10127. clif_emotion(&hd->bl, E_DOTS);
  10128. if (hd->master)
  10129. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10130. return;
  10131. }
  10132. if( hd->sc.data[SC_BASILICA] )
  10133. return;
  10134. lv = hom_checkskill(hd, skill_id);
  10135. if( skill_lv > lv )
  10136. skill_lv = lv;
  10137. if( skill_lv )
  10138. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10139. }
  10140. 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)
  10141. {
  10142. int lv;
  10143. if( !md )
  10144. return;
  10145. if( skill_isNotOk_mercenary(skill_id, md) )
  10146. return;
  10147. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10148. target_id = md->bl.id;
  10149. if( md->ud.skilltimer != INVALID_TIMER )
  10150. {
  10151. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10152. }
  10153. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10154. return;
  10155. lv = mercenary_checkskill(md, skill_id);
  10156. if( skill_lv > lv )
  10157. skill_lv = lv;
  10158. if( skill_lv )
  10159. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10160. }
  10161. 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)
  10162. {
  10163. int lv;
  10164. if( !md )
  10165. return;
  10166. if( skill_isNotOk_mercenary(skill_id, md) )
  10167. return;
  10168. if( md->ud.skilltimer != INVALID_TIMER )
  10169. return;
  10170. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10171. {
  10172. if (md->master)
  10173. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10174. return;
  10175. }
  10176. if( md->sc.data[SC_BASILICA] )
  10177. return;
  10178. lv = mercenary_checkskill(md, skill_id);
  10179. if( skill_lv > lv )
  10180. skill_lv = lv;
  10181. if( skill_lv )
  10182. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10183. }
  10184. /// Request to use a targeted skill.
  10185. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10186. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10187. /// There are various variants of this packet, some of them have padding between fields.
  10188. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10189. {
  10190. uint16 skill_id, skill_lv;
  10191. int inf,target_id;
  10192. unsigned int tick = gettick();
  10193. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10194. skill_lv = RFIFOW(fd,info->pos[0]);
  10195. skill_id = RFIFOW(fd,info->pos[1]);
  10196. target_id = RFIFOL(fd,info->pos[2]);
  10197. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10198. inf = skill_get_inf(skill_id);
  10199. if (inf&INF_GROUND_SKILL || !inf)
  10200. return; //Using a ground/passive skill on a target? WRONG.
  10201. if( SKILL_CHK_HOMUN(skill_id) ) {
  10202. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10203. return;
  10204. }
  10205. if( SKILL_CHK_MERC(skill_id) ) {
  10206. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10207. return;
  10208. }
  10209. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10210. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10211. sd->idletime = last_tick;
  10212. if (sd->npc_id) {
  10213. #ifdef RENEWAL
  10214. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10215. clif_msg(sd, WORK_IN_PROGRESS);
  10216. return;
  10217. }
  10218. #else
  10219. if (!sd->npc_item_flag || !(inf&INF_SELF_SKILL))
  10220. return;
  10221. #endif
  10222. }
  10223. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10224. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10225. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10226. return;
  10227. if( pc_issit(sd) )
  10228. return;
  10229. if( skill_isNotOk(skill_id, sd) )
  10230. return;
  10231. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10232. target_id = sd->bl.id; // never trust the client
  10233. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10234. target_id = sd->bl.id;
  10235. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10236. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10237. return;
  10238. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10239. if( sd->skillitem != skill_id ) {
  10240. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10241. return;
  10242. }
  10243. }
  10244. if( sd->sc.option&OPTION_COSTUME )
  10245. return;
  10246. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10247. return; // On basilica only caster can use Basilica again to stop it.
  10248. if( sd->menuskill_id ) {
  10249. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10250. clif_menuskill_clear(sd); //Cancel pet capture.
  10251. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10252. return; //Can't use skills while a menu is open.
  10253. }
  10254. if( sd->skillitem == skill_id ) {
  10255. if( skill_lv != sd->skillitemlv )
  10256. skill_lv = sd->skillitemlv;
  10257. if( !(inf&INF_SELF_SKILL) )
  10258. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10259. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10260. return;
  10261. }
  10262. sd->skillitem = sd->skillitemlv = 0;
  10263. if( SKILL_CHK_GUILD(skill_id) ) {
  10264. if( sd->state.gmaster_flag )
  10265. skill_lv = guild_checkskill(sd->guild, skill_id);
  10266. else
  10267. skill_lv = 0;
  10268. } else {
  10269. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10270. }
  10271. pc_delinvincibletimer(sd);
  10272. if( skill_lv )
  10273. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10274. }
  10275. /*==========================================
  10276. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10277. *------------------------------------------*/
  10278. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10279. {
  10280. unsigned int tick = gettick();
  10281. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10282. return; //Using a target skill on the ground? WRONG.
  10283. if( SKILL_CHK_HOMUN(skill_id) ) {
  10284. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10285. return;
  10286. }
  10287. if( SKILL_CHK_MERC(skill_id) ) {
  10288. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10289. return;
  10290. }
  10291. #ifdef RENEWAL
  10292. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10293. clif_msg(sd, WORK_IN_PROGRESS);
  10294. return;
  10295. }
  10296. #endif
  10297. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10298. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10299. sd->idletime = last_tick;
  10300. if( skill_isNotOk(skill_id, sd) )
  10301. return;
  10302. if( skillmoreinfo != -1 ) {
  10303. if( pc_issit(sd) ) {
  10304. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10305. return;
  10306. }
  10307. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10308. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10309. }
  10310. if( sd->ud.skilltimer != INVALID_TIMER )
  10311. return;
  10312. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10313. if( sd->skillitem != skill_id ) {
  10314. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10315. return;
  10316. }
  10317. }
  10318. if( sd->sc.option&OPTION_COSTUME )
  10319. return;
  10320. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10321. return; // On basilica only caster can use Basilica again to stop it.
  10322. if( sd->menuskill_id ) {
  10323. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10324. clif_menuskill_clear(sd); //Cancel pet capture.
  10325. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10326. return; //Can't use skills while a menu is open.
  10327. }
  10328. pc_delinvincibletimer(sd);
  10329. if( sd->skillitem == skill_id ) {
  10330. if( skill_lv != sd->skillitemlv )
  10331. skill_lv = sd->skillitemlv;
  10332. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10333. } else {
  10334. int lv;
  10335. sd->skillitem = sd->skillitemlv = 0;
  10336. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10337. if( skill_lv > lv )
  10338. skill_lv = lv;
  10339. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10340. }
  10341. }
  10342. }
  10343. /// Request to use a ground skill.
  10344. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10345. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10346. /// There are various variants of this packet, some of them have padding between fields.
  10347. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10348. {
  10349. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10350. if (pc_cant_act(sd))
  10351. return;
  10352. if (pc_issit(sd))
  10353. return;
  10354. clif_parse_UseSkillToPosSub(fd, sd,
  10355. RFIFOW(fd,info->pos[0]), //skill lv
  10356. RFIFOW(fd,info->pos[1]), //skill num
  10357. RFIFOW(fd,info->pos[2]), //pos x
  10358. RFIFOW(fd,info->pos[3]), //pos y
  10359. -1 //Skill more info.
  10360. );
  10361. }
  10362. /// Request to use a ground skill with text.
  10363. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10364. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10365. /// There are various variants of this packet, some of them have padding between fields.
  10366. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10367. {
  10368. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10369. if (pc_cant_act(sd))
  10370. return;
  10371. if (pc_issit(sd))
  10372. return;
  10373. clif_parse_UseSkillToPosSub(fd, sd,
  10374. RFIFOW(fd,info->pos[0]), //Skill lv
  10375. RFIFOW(fd,info->pos[1]), //Skill num
  10376. RFIFOW(fd,info->pos[2]), //pos x
  10377. RFIFOW(fd,info->pos[3]), //pos y
  10378. info->pos[4] //skill more info
  10379. );
  10380. }
  10381. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10382. /// 011b <skill id>.W <map name>.16B
  10383. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10384. {
  10385. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10386. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10387. char map_name[MAP_NAME_LENGTH];
  10388. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10389. sd->state.workinprogress = WIP_DISABLE_NONE;
  10390. if(skill_id != sd->menuskill_id)
  10391. return;
  10392. //It is possible to use teleport with the storage window open bugreport:8027
  10393. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10394. clif_menuskill_clear(sd);
  10395. return;
  10396. }
  10397. pc_delinvincibletimer(sd);
  10398. skill_castend_map(sd,skill_id,map_name);
  10399. }
  10400. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10401. /// 011d
  10402. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10403. {
  10404. if (!pc_isdead(sd))
  10405. pc_memo(sd,-1);
  10406. }
  10407. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10408. /// 018e <name id>.W { <material id>.W }*3
  10409. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10410. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10411. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10412. int slot1 = RFIFOW(fd,info->pos[1]);
  10413. int slot2 = RFIFOW(fd,info->pos[2]);
  10414. int slot3 = RFIFOW(fd,info->pos[3]);
  10415. short produce_idx = -1;
  10416. switch( sd->menuskill_id ) {
  10417. case -1:
  10418. case AM_PHARMACY:
  10419. case RK_RUNEMASTERY:
  10420. case GC_RESEARCHNEWPOISON:
  10421. break;
  10422. default:
  10423. return;
  10424. }
  10425. if (pc_istrading(sd)) {
  10426. //Make it fail to avoid shop exploits where you sell something different than you see.
  10427. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10428. clif_menuskill_clear(sd);
  10429. return;
  10430. }
  10431. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10432. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10433. clif_menuskill_clear(sd);
  10434. }
  10435. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10436. /// 025b <mk type>.W <name id>.W
  10437. /// mk type:
  10438. /// 1 = cooking
  10439. /// 2 = arrow
  10440. /// 3 = elemental
  10441. /// 4 = GN_MIX_COOKING
  10442. /// 5 = GN_MAKEBOMB
  10443. /// 6 = GN_S_PHARMACY
  10444. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10445. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10446. int type = RFIFOW(fd,info->pos[0]);
  10447. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10448. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10449. short food_idx = -1;
  10450. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  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. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10459. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10460. clif_menuskill_clear(sd);
  10461. }
  10462. /// Answer to repair weapon item selection dialog
  10463. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10464. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10465. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10466. {
  10467. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10468. return;
  10469. if (pc_istrading(sd)) {
  10470. //Make it fail to avoid shop exploits where you sell something different than you see.
  10471. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10472. clif_menuskill_clear(sd);
  10473. return;
  10474. }
  10475. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10476. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10477. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10478. //for(i = 0; i<MAX_SLOTS; i++)
  10479. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10480. clif_menuskill_clear(sd);
  10481. }
  10482. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10483. /// 0222 <index>.L
  10484. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10485. {
  10486. int idx;
  10487. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10488. return;
  10489. if (pc_istrading(sd)) {
  10490. //Make it fail to avoid shop exploits where you sell something different than you see.
  10491. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10492. clif_menuskill_clear(sd);
  10493. return;
  10494. }
  10495. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10496. skill_weaponrefine(sd, idx-2);
  10497. clif_menuskill_clear(sd);
  10498. }
  10499. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10500. /// 00b8 <npc id>.L <choice>.B
  10501. /// choice:
  10502. /// 1~254 = menu item
  10503. /// 255 = cancel
  10504. /// NOTE: If there were more than 254 items in the list, choice
  10505. /// overflows to choice%256.
  10506. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10507. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10508. int npc_id = RFIFOL(fd,info->pos[0]);
  10509. uint8 select = RFIFOB(fd,info->pos[1]);
  10510. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10511. #ifdef SECURE_NPCTIMEOUT
  10512. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10513. #endif
  10514. TBL_NPC* nd = map_id2nd(npc_id);
  10515. 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);
  10516. clif_GM_kick(NULL,sd);
  10517. #ifdef SECURE_NPCTIMEOUT
  10518. }
  10519. #endif
  10520. return;
  10521. }
  10522. sd->npc_menu = select;
  10523. npc_scriptcont(sd,npc_id, false);
  10524. }
  10525. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10526. /// 00b9 <npc id>.L
  10527. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10528. {
  10529. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10530. }
  10531. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10532. /// 0143 <npc id>.L <value>.L
  10533. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10534. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10535. int npcid = RFIFOL(fd,info->pos[0]);
  10536. int amount = (int)RFIFOL(fd,info->pos[1]);
  10537. sd->npc_amount = amount;
  10538. npc_scriptcont(sd, npcid, false);
  10539. }
  10540. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10541. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10542. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10543. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10544. int message_len = RFIFOW(fd,info->pos[0])-8;
  10545. int npcid = RFIFOL(fd,info->pos[1]);
  10546. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10547. if( message_len <= 0 )
  10548. return; // invalid input
  10549. #if PACKETVER >= 20151001
  10550. message_len++;
  10551. #endif
  10552. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10553. npc_scriptcont(sd, npcid, false);
  10554. }
  10555. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10556. /// 0146 <npc id>.L
  10557. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10558. {
  10559. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10560. return;
  10561. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10562. }
  10563. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10564. /// 0178 <index>.W
  10565. /// index:
  10566. /// -1 = cancel
  10567. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10568. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2;
  10569. if (sd->menuskill_id != MC_IDENTIFY)
  10570. return;
  10571. // Ignore the request
  10572. // - Invalid item index
  10573. // - Invalid item ID or item doesn't exist
  10574. // - Item is already identified
  10575. if (idx < 0 || idx >= MAX_INVENTORY ||
  10576. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10577. sd->status.inventory[idx].identify) {// cancel pressed
  10578. sd->state.workinprogress = WIP_DISABLE_NONE;
  10579. clif_menuskill_clear(sd);
  10580. return;
  10581. }
  10582. skill_identify(sd, idx);
  10583. clif_menuskill_clear(sd);
  10584. }
  10585. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10586. /// 01ae <name id>.W
  10587. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10588. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10589. if (pc_istrading(sd)) {
  10590. //Make it fail to avoid shop exploits where you sell something different than you see.
  10591. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10592. clif_menuskill_clear(sd);
  10593. return;
  10594. }
  10595. switch (sd->menuskill_id) {
  10596. case AC_MAKINGARROW:
  10597. skill_arrow_create(sd,nameid);
  10598. break;
  10599. case SA_CREATECON:
  10600. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10601. break;
  10602. case WL_READING_SB:
  10603. skill_spellbook(sd,nameid);
  10604. break;
  10605. case GC_POISONINGWEAPON:
  10606. skill_poisoningweapon(sd,nameid);
  10607. break;
  10608. case NC_MAGICDECOY:
  10609. skill_magicdecoy(sd,nameid);
  10610. break;
  10611. }
  10612. clif_menuskill_clear(sd);
  10613. }
  10614. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10615. /// 01ce <skill id>.L
  10616. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10617. {
  10618. if (sd->menuskill_id != SA_AUTOSPELL)
  10619. return;
  10620. sd->state.workinprogress = WIP_DISABLE_NONE;
  10621. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10622. clif_menuskill_clear(sd);
  10623. }
  10624. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10625. /// 017a <card index>.W
  10626. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10627. {
  10628. if (sd->state.trading != 0)
  10629. return;
  10630. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10631. }
  10632. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10633. /// 017c <card index>.W <equip index>.W
  10634. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10635. {
  10636. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10637. if (sd->state.trading != 0)
  10638. return;
  10639. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10640. }
  10641. /// Request of character's name by char ID.
  10642. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10643. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10644. /// There are various variants of this packet, some of them have padding between fields.
  10645. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10646. {
  10647. int charid;
  10648. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10649. map_reqnickdb(sd, charid);
  10650. }
  10651. /// /resetskill /resetstate (CZ_RESET).
  10652. /// Request to reset stats or skills.
  10653. /// 0197 <type>.W
  10654. /// type:
  10655. /// 0 = state
  10656. /// 1 = skill
  10657. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10658. char cmd[15];
  10659. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10660. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10661. else
  10662. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10663. is_atcommand(fd, sd, cmd, 1);
  10664. }
  10665. /// /lb /nlb (CZ_LOCALBROADCAST).
  10666. /// Request to broadcast a message on current map.
  10667. /// 019c <packet len>.W <text>.?B
  10668. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10669. {
  10670. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10671. char command[CHAT_SIZE_MAX+16];
  10672. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10673. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10674. // as the length varies depending on the command used, just block unreasonably long strings
  10675. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10676. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10677. is_atcommand(fd, sd, command, 1);
  10678. }
  10679. /// Request to move an item from inventory to storage.
  10680. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10681. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10682. /// There are various variants of this packet, some of them have padding between fields.
  10683. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10684. {
  10685. int item_index, item_amount;
  10686. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10687. if (pc_istrading(sd))
  10688. return;
  10689. item_index = RFIFOW(fd,info->pos[0])-2;
  10690. item_amount = RFIFOL(fd,info->pos[1]);
  10691. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10692. return;
  10693. if (sd->state.storage_flag == 1)
  10694. storage_storageadd(sd, item_index, item_amount);
  10695. else
  10696. if (sd->state.storage_flag == 2)
  10697. gstorage_storageadd(sd, item_index, item_amount);
  10698. }
  10699. /// Request to move an item from storage to inventory.
  10700. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10701. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10702. /// There are various variants of this packet, some of them have padding between fields.
  10703. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10704. {
  10705. int item_index, item_amount;
  10706. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10707. item_index = RFIFOW(fd,info->pos[0])-1;
  10708. item_amount = RFIFOL(fd,info->pos[1]);
  10709. if (sd->state.storage_flag == 1)
  10710. storage_storageget(sd, item_index, item_amount);
  10711. else if(sd->state.storage_flag == 2)
  10712. gstorage_storageget(sd, item_index, item_amount);
  10713. }
  10714. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10715. /// 0129 <index>.W <amount>.L
  10716. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10717. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10718. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10719. int amount = RFIFOL(fd,info->pos[1]);
  10720. if( sd->state.vending )
  10721. return;
  10722. if (!pc_iscarton(sd))
  10723. return;
  10724. if (sd->state.storage_flag == 1)
  10725. storage_storageaddfromcart(sd, idx, amount);
  10726. else if (sd->state.storage_flag == 2)
  10727. gstorage_storageaddfromcart(sd, idx, amount);
  10728. }
  10729. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10730. /// 0128 <index>.W <amount>.L
  10731. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10732. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10733. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10734. int amount = RFIFOL(fd,info->pos[1]);
  10735. if( sd->state.vending )
  10736. return;
  10737. if (!pc_iscarton(sd))
  10738. return;
  10739. if (sd->state.storage_flag == 1)
  10740. storage_storagegettocart(sd, idx, amount);
  10741. else
  10742. if (sd->state.storage_flag == 2)
  10743. gstorage_storagegettocart(sd, idx, amount);
  10744. }
  10745. /// Request to close storage (CZ_CLOSE_STORE).
  10746. /// 00f7
  10747. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10748. {
  10749. if( sd->state.storage_flag == 1 )
  10750. storage_storageclose(sd);
  10751. else
  10752. if( sd->state.storage_flag == 2 )
  10753. gstorage_storageclose(sd);
  10754. }
  10755. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10756. /// 023a <info>.W
  10757. /// info:
  10758. /// 0 = password has not been set yet
  10759. /// 1 = storage is password-protected
  10760. /// 8 = too many wrong passwords
  10761. /// ? = ignored
  10762. /// NOTE: This packet is only available on certain non-kRO clients.
  10763. void clif_storagepassword(struct map_session_data* sd, short info)
  10764. {
  10765. int fd = sd->fd;
  10766. WFIFOHEAD(fd,packet_len(0x23a));
  10767. WFIFOW(fd,0) = 0x23a;
  10768. WFIFOW(fd,2) = info;
  10769. WFIFOSET(fd,packet_len(0x23a));
  10770. }
  10771. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10772. /// 023b <type>.W <password>.16B <new password>.16B
  10773. /// type:
  10774. /// 2 = change password
  10775. /// 3 = check password
  10776. /// NOTE: This packet is only available on certain non-kRO clients.
  10777. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10778. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10779. // int type = RFIFOW(fd,info->pos[0]);
  10780. // char* password = RFIFOP(fd,info->pos[1]);
  10781. // char* new_password = RFIFOP(fd,info->pos[2]);
  10782. // storage_changepass(sd,password,new_password);
  10783. }
  10784. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10785. /// 023c <result>.W <error count>.W
  10786. /// result:
  10787. /// 4 = password change success
  10788. /// 5 = password change failure
  10789. /// 6 = password check success
  10790. /// 7 = password check failure
  10791. /// 8 = too many wrong passwords
  10792. /// ? = ignored
  10793. /// NOTE: This packet is only available on certain non-kRO clients.
  10794. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10795. {
  10796. int fd = sd->fd;
  10797. WFIFOHEAD(fd,packet_len(0x23c));
  10798. WFIFOW(fd,0) = 0x23c;
  10799. WFIFOW(fd,2) = result;
  10800. WFIFOW(fd,4) = error_count;
  10801. WFIFOSET(fd,packet_len(0x23c));
  10802. }
  10803. /// Party creation request
  10804. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10805. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10806. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10807. name[NAME_LENGTH-1] = '\0';
  10808. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10809. clif_displaymessage(fd, msg_txt(sd,227));
  10810. return;
  10811. }
  10812. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10813. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10814. return;
  10815. }
  10816. party_create(sd,name,0,0);
  10817. }
  10818. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10819. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10820. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10821. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10822. int item1 = RFIFOB(fd,info->pos[1]);
  10823. int item2 = RFIFOB(fd,info->pos[2]);
  10824. name[NAME_LENGTH-1] = '\0';
  10825. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10826. clif_displaymessage(fd, msg_txt(sd,227));
  10827. return;
  10828. }
  10829. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10830. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10831. return;
  10832. }
  10833. party_create(sd,name,item1,item2);
  10834. }
  10835. /// Party invitation request
  10836. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10837. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10838. {
  10839. struct map_session_data *t_sd;
  10840. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10841. clif_displaymessage(fd, msg_txt(sd,227));
  10842. return;
  10843. }
  10844. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10845. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10846. clif_noask_sub(sd, t_sd, 1);
  10847. return;
  10848. }
  10849. party_invite(sd, t_sd);
  10850. }
  10851. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10852. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10853. struct map_session_data *t_sd;
  10854. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10855. name[NAME_LENGTH-1] = '\0';
  10856. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10857. clif_displaymessage(fd, msg_txt(sd,227));
  10858. return;
  10859. }
  10860. t_sd = map_nick2sd(name);
  10861. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10862. clif_noask_sub(sd, t_sd, 1);
  10863. return;
  10864. }
  10865. party_invite(sd, t_sd);
  10866. }
  10867. /// Party invitation reply
  10868. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10869. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10870. /// flag:
  10871. /// 0 = reject
  10872. /// 1 = accept
  10873. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10874. {
  10875. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10876. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10877. RFIFOL(fd,info->pos[1]));
  10878. }
  10879. //(CZ_PARTY_JOIN_REQ_ACK)
  10880. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10881. {
  10882. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10883. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10884. RFIFOB(fd,info->pos[1]));
  10885. }
  10886. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10887. /// 0100
  10888. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10889. {
  10890. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10891. clif_displaymessage(fd, msg_txt(sd,227));
  10892. return;
  10893. }
  10894. party_leave(sd);
  10895. }
  10896. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10897. /// 0103 <account id>.L <char name>.24B
  10898. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10899. {
  10900. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10901. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10902. clif_displaymessage(fd, msg_txt(sd,227));
  10903. return;
  10904. }
  10905. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10906. (char*)RFIFOP(fd,info->pos[1]));
  10907. }
  10908. /// Request to change party options.
  10909. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10910. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10911. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10912. {
  10913. struct party_data *p;
  10914. int i,expflag;
  10915. int cmd = RFIFOW(fd,0);
  10916. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10917. if( !sd->status.party_id )
  10918. return;
  10919. p = party_search(sd->status.party_id);
  10920. if( p == NULL )
  10921. return;
  10922. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10923. if( i == MAX_PARTY )
  10924. return; //Shouldn't happen
  10925. if( !p->party.member[i].leader )
  10926. return;
  10927. expflag = RFIFOL(fd,info->pos[0]);
  10928. if(cmd == 0x0102){ //Client can't change the item-field
  10929. party_changeoption(sd, expflag, p->party.item);
  10930. }
  10931. else {
  10932. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10933. party_changeoption(sd, expflag, itemflag);
  10934. }
  10935. }
  10936. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10937. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10938. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10939. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10940. // validate packet and retrieve name and message
  10941. if( !clif_process_message( sd, false, name, message, output ) )
  10942. return;
  10943. party_send_message(sd, output, strlen(output) + 1 );
  10944. }
  10945. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10946. /// 07da <account id>.L
  10947. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10948. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10949. }
  10950. /// Party Booking in KRO [Spiria]
  10951. ///
  10952. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10953. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10954. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10955. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10956. short level = RFIFOW(fd,info->pos[0]);
  10957. short mapid = RFIFOW(fd,info->pos[1]);
  10958. int idxpbj = info->pos[2];
  10959. short job[MAX_PARTY_BOOKING_JOBS];
  10960. int i;
  10961. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  10962. job[i] = RFIFOB(fd,idxpbj+i*2);
  10963. party_booking_register(sd, level, mapid, job);
  10964. }
  10965. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10966. /// 0803 <result>.W
  10967. /// result:
  10968. /// 0 = success
  10969. /// 1 = failure
  10970. /// 2 = already registered
  10971. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10972. {
  10973. int fd = sd->fd;
  10974. WFIFOHEAD(fd,packet_len(0x803));
  10975. WFIFOW(fd,0) = 0x803;
  10976. WFIFOW(fd,2) = flag;
  10977. WFIFOSET(fd,packet_len(0x803));
  10978. }
  10979. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10980. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10981. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10982. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10983. short level = RFIFOW(fd,info->pos[0]);
  10984. short mapid = RFIFOW(fd,info->pos[1]);
  10985. short job = RFIFOW(fd,info->pos[2]);
  10986. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10987. short resultcount = RFIFOW(fd,info->pos[4]);
  10988. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10989. }
  10990. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10991. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10992. /// more results:
  10993. /// 0 = no
  10994. /// 1 = yes
  10995. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10996. {
  10997. int i, j;
  10998. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10999. struct party_booking_ad_info *pb_ad;
  11000. WFIFOHEAD(fd,size*count + 5);
  11001. WFIFOW(fd,0) = 0x805;
  11002. WFIFOW(fd,2) = size*count + 5;
  11003. WFIFOB(fd,4) = more_result;
  11004. for(i=0; i<count; i++)
  11005. {
  11006. pb_ad = results[i];
  11007. WFIFOL(fd,i*size+5) = pb_ad->index;
  11008. safestrncpy((char*)WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11009. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11010. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11011. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11012. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11013. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11014. }
  11015. WFIFOSET(fd,WFIFOW(fd,2));
  11016. }
  11017. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11018. /// 0806
  11019. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11020. {
  11021. if(party_booking_delete(sd))
  11022. clif_PartyBookingDeleteAck(sd, 0);
  11023. }
  11024. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11025. /// 0807 <result>.W
  11026. /// result:
  11027. /// 0 = success
  11028. /// 1 = success (auto-removed expired ad)
  11029. /// 2 = failure
  11030. /// 3 = nothing registered
  11031. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11032. {
  11033. int fd = sd->fd;
  11034. WFIFOHEAD(fd,packet_len(0x807));
  11035. WFIFOW(fd,0) = 0x807;
  11036. WFIFOW(fd,2) = flag;
  11037. WFIFOSET(fd,packet_len(0x807));
  11038. }
  11039. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11040. /// 0808 { <job>.W }*6
  11041. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11042. {
  11043. short job[MAX_PARTY_BOOKING_JOBS];
  11044. int i;
  11045. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  11046. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11047. job[i] = RFIFOW(fd,idxpbu+i*2);
  11048. party_booking_update(sd, job);
  11049. }
  11050. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11051. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11052. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11053. {
  11054. int i;
  11055. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11056. if(pb_ad == NULL) return;
  11057. WBUFW(buf,0) = 0x809;
  11058. WBUFL(buf,2) = pb_ad->index;
  11059. safestrncpy((char*)WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  11060. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11061. WBUFW(buf,34) = pb_ad->p_detail.level;
  11062. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11063. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11064. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11065. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11066. }
  11067. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11068. /// 080a <index>.L { <job>.W }*6
  11069. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11070. {
  11071. int i;
  11072. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11073. if(pb_ad == NULL) return;
  11074. WBUFW(buf,0) = 0x80a;
  11075. WBUFL(buf,2) = pb_ad->index;
  11076. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11077. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11078. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11079. }
  11080. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11081. /// 080b <index>.L
  11082. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11083. {
  11084. uint8 buf[6];
  11085. WBUFW(buf,0) = 0x80b;
  11086. WBUFL(buf,2) = index;
  11087. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11088. }
  11089. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11090. /// 012e
  11091. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11092. {
  11093. vending_closevending(sd);
  11094. }
  11095. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11096. /// 0130 <account id>.L
  11097. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11098. {
  11099. if( sd->npc_id ) {// using an NPC
  11100. return;
  11101. }
  11102. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11103. }
  11104. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11105. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11106. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11107. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11108. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11109. int id = (int)RFIFOL(fd,info->pos[1]);
  11110. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11111. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11112. // whether it fails or not, the buy window is closed
  11113. sd->vended_id = 0;
  11114. }
  11115. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11116. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11117. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11118. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11119. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11120. int aid = (int)RFIFOL(fd,info->pos[1]);
  11121. int uid = (int)RFIFOL(fd,info->pos[2]);
  11122. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11123. vending_purchasereq(sd, aid, uid, data, len/4);
  11124. // whether it fails or not, the buy window is closed
  11125. sd->vended_id = 0;
  11126. }
  11127. /// Confirm or cancel the shop preparation window.
  11128. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11129. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11130. /// result:
  11131. /// 0 = canceled
  11132. /// 1 = open
  11133. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11134. int cmd = RFIFOW(fd,0);
  11135. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  11136. short len = (short)RFIFOW(fd,info->pos[0]);
  11137. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  11138. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11139. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11140. len -= 84;
  11141. }
  11142. else { //(CZ_REQ_OPENSTORE2)
  11143. bool flag;
  11144. len -= 85;
  11145. flag = (bool)RFIFOB(fd,info->pos[2]);
  11146. if (!flag) {
  11147. sd->state.prevend = 0;
  11148. sd->state.workinprogress = WIP_DISABLE_NONE;
  11149. }
  11150. }
  11151. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11152. return;
  11153. if( map[sd->bl.m].flag.novending ) {
  11154. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11155. return;
  11156. }
  11157. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11158. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11159. return;
  11160. }
  11161. if( message[0] == '\0' ) // invalid input
  11162. return;
  11163. vending_openvending(sd, message, data, len/8, NULL);
  11164. }
  11165. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11166. /// 0165 <char id>.L <guild name>.24B
  11167. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11168. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11169. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11170. name[NAME_LENGTH-1] = '\0';
  11171. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11172. clif_displaymessage(fd, msg_txt(sd,228));
  11173. return;
  11174. }
  11175. guild_create(sd, name);
  11176. }
  11177. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11178. /// 014d
  11179. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11180. {
  11181. clif_guild_masterormember(sd);
  11182. }
  11183. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11184. /// 014f <type>.L
  11185. /// type:
  11186. /// 0 = basic info
  11187. /// 1 = member manager
  11188. /// 2 = positions
  11189. /// 3 = skills
  11190. /// 4 = expulsion list
  11191. /// 5 = unknown (GM_ALLGUILDLIST)
  11192. /// 6 = notice
  11193. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11194. {
  11195. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11196. if( !sd->status.guild_id && !sd->bg_id )
  11197. return;
  11198. switch( type )
  11199. {
  11200. case 0: // Basic Information Guild, hostile alliance information
  11201. clif_guild_basicinfo(sd);
  11202. clif_guild_allianceinfo(sd);
  11203. break;
  11204. case 1: // Members list, list job title
  11205. clif_guild_positionnamelist(sd);
  11206. clif_guild_memberlist(sd);
  11207. break;
  11208. case 2: // List job title, title information list
  11209. clif_guild_positionnamelist(sd);
  11210. clif_guild_positioninfolist(sd);
  11211. break;
  11212. case 3: // Skill list
  11213. clif_guild_skillinfo(sd);
  11214. break;
  11215. case 4: // Expulsion list
  11216. clif_guild_expulsionlist(sd);
  11217. break;
  11218. default:
  11219. ShowError("clif: guild request info: unknown type %d\n", type);
  11220. break;
  11221. }
  11222. }
  11223. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11224. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11225. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11226. {
  11227. int i;
  11228. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11229. int len = RFIFOW(fd,info->pos[0]);
  11230. int idxgpos = info->pos[1];
  11231. if(!sd->state.gmaster_flag)
  11232. return;
  11233. for(i = idxgpos; i < len; i += 40 ){
  11234. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  11235. }
  11236. }
  11237. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11238. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11239. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11240. {
  11241. int i;
  11242. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11243. int len = RFIFOW(fd,info->pos[0]);
  11244. int idxgpos = info->pos[1];
  11245. if(!sd->state.gmaster_flag)
  11246. return;
  11247. for(i=idxgpos;i<len;i+=12){
  11248. guild_change_memberposition(sd->status.guild_id,
  11249. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11250. }
  11251. }
  11252. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11253. /// 0151 <guild id>.L
  11254. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11255. {
  11256. struct guild* g;
  11257. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11258. if( (g = guild_search(guild_id)) != NULL )
  11259. clif_guild_emblem(sd,g);
  11260. }
  11261. /// Validates data of a guild emblem (compressed bitmap)
  11262. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11263. EMBVALIDATE_SUCCESS = 0,
  11264. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11265. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11266. };
  11267. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11268. {
  11269. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11270. unsigned long buf_len = sizeof(buf);
  11271. int offset = 0;
  11272. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11273. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11274. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11275. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11276. ))
  11277. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11278. if(battle_config.emblem_transparency_limit != 100) {
  11279. int i, transcount = 1, tmp[3];
  11280. for(i = offset; i < buf_len-1; i++) {
  11281. int j = i%3;
  11282. tmp[j] = RBUFL(buf,i);
  11283. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11284. transcount++;
  11285. }
  11286. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11287. return EMBVALIDATE_ERR_TRANSPARENCY;
  11288. }
  11289. return EMBVALIDATE_SUCCESS;
  11290. }
  11291. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11292. /// 0153 <packet len>.W <emblem data>.?B
  11293. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11294. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11295. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11296. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11297. int emb_val=0;
  11298. if( !emblem_len || !sd->state.gmaster_flag )
  11299. return;
  11300. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11301. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  11302. return;
  11303. }
  11304. emb_val = clif_validate_emblem(emblem, emblem_len);
  11305. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11306. 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);
  11307. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11308. return;
  11309. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11310. char output[128];
  11311. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11312. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11313. return;
  11314. }
  11315. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11316. }
  11317. /// Guild notice update request (CZ_GUILD_NOTICE).
  11318. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11319. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11320. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11321. int guild_id = RFIFOL(fd,info->pos[0]);
  11322. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11323. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11324. if(!sd->state.gmaster_flag)
  11325. return;
  11326. // compensate for some client defects when using multilanguage mode
  11327. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11328. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11329. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11330. guild_change_notice(sd, guild_id, msg1, msg2);
  11331. }
  11332. // Helper function for guild invite functions
  11333. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11334. {
  11335. if (t_sd == NULL) // not online or does not exist
  11336. return 1;
  11337. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11338. clif_displaymessage(fd, msg_txt(sd,228));
  11339. return 1;
  11340. }
  11341. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11342. clif_noask_sub(sd, t_sd, 2);
  11343. return 1;
  11344. }
  11345. guild_invite(sd, t_sd);
  11346. return 0;
  11347. }
  11348. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11349. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11350. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11351. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11352. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11353. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11354. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11355. if (clif_sub_guild_invite(fd, sd, t_sd))
  11356. return;
  11357. }
  11358. /// Guild invite request (/guildinvite)
  11359. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11360. void
  11361. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11362. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11363. if (clif_sub_guild_invite(fd, sd, t_sd))
  11364. return;
  11365. }
  11366. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11367. /// 016b <guild id>.L <answer>.L
  11368. /// answer:
  11369. /// 0 = refuse
  11370. /// 1 = accept
  11371. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11372. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11373. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11374. RFIFOL(fd,info->pos[1]));
  11375. }
  11376. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11377. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11378. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11379. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11380. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11381. clif_displaymessage(fd, msg_txt(sd,228));
  11382. return;
  11383. }
  11384. if( sd->bg_id ) {
  11385. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11386. return;
  11387. }
  11388. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11389. RFIFOL(fd,info->pos[1]),
  11390. RFIFOL(fd,info->pos[2]),
  11391. (char*)RFIFOP(fd,info->pos[3]));
  11392. }
  11393. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11394. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11395. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11396. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11397. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11398. { // Guild locked.
  11399. clif_displaymessage(fd, msg_txt(sd,228));
  11400. return;
  11401. }
  11402. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11403. RFIFOL(fd,info->pos[1]),
  11404. RFIFOL(fd,info->pos[2]),
  11405. (char*)RFIFOP(fd,info->pos[3]));
  11406. }
  11407. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11408. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11409. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11410. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11411. // validate packet and retrieve name and message
  11412. if( !clif_process_message( sd, false, name, message, output ) )
  11413. return;
  11414. if( sd->bg_id )
  11415. bg_send_message(sd, output, strlen(output) );
  11416. else
  11417. guild_send_message(sd, output, strlen(output) );
  11418. }
  11419. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11420. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11421. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11422. {
  11423. struct map_session_data *t_sd;
  11424. if(!sd->state.gmaster_flag)
  11425. return;
  11426. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11427. clif_displaymessage(fd, msg_txt(sd,228));
  11428. return;
  11429. }
  11430. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11431. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11432. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11433. // @noask [LuzZza]
  11434. if(t_sd && t_sd->state.noask) {
  11435. clif_noask_sub(sd, t_sd, 3);
  11436. return;
  11437. }
  11438. guild_reqalliance(sd,t_sd);
  11439. }
  11440. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11441. /// 0172 <inviter account id>.L <answer>.L
  11442. /// answer:
  11443. /// 0 = refuse
  11444. /// 1 = accept
  11445. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11446. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11447. guild_reply_reqalliance(sd,
  11448. RFIFOL(fd,info->pos[0]),
  11449. RFIFOL(fd,info->pos[1]));
  11450. }
  11451. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11452. /// 0183 <opponent guild id>.L <relation>.L
  11453. /// relation:
  11454. /// 0 = Ally
  11455. /// 1 = Enemy
  11456. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11457. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11458. if(!sd->state.gmaster_flag)
  11459. return;
  11460. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11461. clif_displaymessage(fd, msg_txt(sd,228));
  11462. return;
  11463. }
  11464. guild_delalliance(sd,
  11465. RFIFOL(fd,info->pos[0]),
  11466. RFIFOL(fd,info->pos[1]));
  11467. }
  11468. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11469. /// 0180 <account id>.L
  11470. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11471. {
  11472. struct map_session_data *t_sd;
  11473. if(!sd->state.gmaster_flag)
  11474. return;
  11475. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11476. clif_displaymessage(fd, msg_txt(sd,228));
  11477. return;
  11478. }
  11479. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11480. // @noask [LuzZza]
  11481. if(t_sd && t_sd->state.noask) {
  11482. clif_noask_sub(sd, t_sd, 4);
  11483. return;
  11484. }
  11485. guild_opposition(sd,t_sd);
  11486. }
  11487. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11488. /// 015d <key>.40B
  11489. /// key:
  11490. /// now guild name; might have been (intended) email, since the
  11491. /// field name and size is same as the one in CH_DELETE_CHAR.
  11492. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11493. {
  11494. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11495. clif_displaymessage(fd, msg_txt(sd,228));
  11496. return;
  11497. }
  11498. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11499. }
  11500. /// Pet
  11501. ///
  11502. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11503. /// 01a1 <type>.B
  11504. /// type:
  11505. /// 0 = pet information
  11506. /// 1 = feed
  11507. /// 2 = performance
  11508. /// 3 = return to egg
  11509. /// 4 = unequip accessory
  11510. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11511. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11512. }
  11513. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11514. /// 019f <id>.L
  11515. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11516. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11517. }
  11518. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11519. /// 01a7 <index>.W
  11520. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11521. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11522. return;
  11523. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11524. clif_menuskill_clear(sd);
  11525. }
  11526. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11527. /// 01a9 <data>.L
  11528. /// data:
  11529. /// is either emotion (@see enum emotion_type) or a compound value
  11530. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11531. /// entry (given in parentheses) in data\pettalktable.xml
  11532. /// act id:
  11533. /// 0 = feeding
  11534. /// 1 = hunting
  11535. /// 2 = danger
  11536. /// 3 = dead
  11537. /// 4 = normal (stand)
  11538. /// 5 = special performance (perfor_s)
  11539. /// 6 = level up (levelup)
  11540. /// 7 = performance 1 (perfor_1)
  11541. /// 8 = performance 2 (perfor_2)
  11542. /// 9 = performance 3 (perfor_3)
  11543. /// 10 = log-in greeting (connect)
  11544. /// hungry value:
  11545. /// 0 = very hungry (hungry)
  11546. /// 1 = hungry (bit_hungry)
  11547. /// 2 = satisfied (noting)
  11548. /// 3 = stuffed (full)
  11549. /// 4 = full (so_full)
  11550. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11551. {
  11552. if(sd->pd)
  11553. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11554. }
  11555. /// Request to change pet's name (CZ_RENAME_PET).
  11556. /// 01a5 <name>.24B
  11557. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11558. {
  11559. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11560. }
  11561. /// /kill (CZ_DISCONNECT_CHARACTER).
  11562. /// Request to disconnect a character.
  11563. /// 00cc <account id>.L
  11564. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11565. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11566. {
  11567. struct block_list *target;
  11568. int tid;
  11569. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11570. target = map_id2bl(tid);
  11571. if (!target) {
  11572. clif_GM_kickack(sd, 0);
  11573. return;
  11574. }
  11575. switch (target->type) {
  11576. case BL_PC:
  11577. {
  11578. char command[NAME_LENGTH+6];
  11579. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11580. is_atcommand(fd, sd, command, 1);
  11581. }
  11582. break;
  11583. /**
  11584. * This one does not invoke any atcommand, so we need to check for permissions.
  11585. */
  11586. case BL_MOB:
  11587. {
  11588. char command[100];
  11589. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11590. clif_GM_kickack(sd, 0);
  11591. return;
  11592. }
  11593. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11594. log_atcommand(sd, command);
  11595. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11596. }
  11597. break;
  11598. case BL_NPC:
  11599. {
  11600. struct npc_data* nd = (struct npc_data *)target;
  11601. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11602. npc_unload_duplicates(nd);
  11603. npc_unload(nd,true);
  11604. npc_read_event_script();
  11605. }
  11606. }
  11607. break;
  11608. default:
  11609. clif_GM_kickack(sd, 0);
  11610. }
  11611. }
  11612. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11613. /// Request to disconnect all characters.
  11614. /// 00ce
  11615. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11616. char cmd[15];
  11617. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11618. is_atcommand(fd, sd, cmd, 1);
  11619. }
  11620. /// /remove (CZ_REMOVE_AID).
  11621. /// Request to warp to a character with given login ID.
  11622. /// 01ba <account name>.24B
  11623. /// /shift (CZ_SHIFT).
  11624. /// Request to warp to a character with given name.
  11625. /// 01bb <char name>.24B
  11626. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11627. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11628. char *player_name;
  11629. char command[NAME_LENGTH+8];
  11630. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11631. player_name[NAME_LENGTH-1] = '\0';
  11632. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11633. is_atcommand(fd, sd, command, 1);
  11634. }
  11635. /// /remove (CZ_REMOVE_AID_SSO).
  11636. /// Request to warp to a character with given account ID.
  11637. /// 0843 <account id>.L
  11638. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11639. {
  11640. uint32 account_id;
  11641. struct map_session_data* pl_sd;
  11642. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11643. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11644. char command[NAME_LENGTH+8];
  11645. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11646. is_atcommand(fd, sd, command, 1);
  11647. }
  11648. }
  11649. /// /recall (CZ_RECALL).
  11650. /// Request to summon a player with given login ID to own position.
  11651. /// 01bc <account name>.24B
  11652. /// /summon (CZ_RECALL_GID).
  11653. /// Request to summon a player with given name to own position.
  11654. /// 01bd <char name>.24B
  11655. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11656. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11657. char *player_name;
  11658. char command [NAME_LENGTH+8];
  11659. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11660. player_name[NAME_LENGTH-1] = '\0';
  11661. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11662. is_atcommand(fd, sd, command, 1);
  11663. }
  11664. /// /recall (CZ_RECALL_SSO).
  11665. /// Request to summon a player with given account ID to own position.
  11666. /// 0842 <account id>.L
  11667. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11668. {
  11669. uint32 account_id;
  11670. struct map_session_data* pl_sd;
  11671. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11672. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11673. char command[NAME_LENGTH+8];
  11674. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11675. is_atcommand(fd, sd, command, 1);
  11676. }
  11677. }
  11678. /// /item /monster (CZ_ITEM_CREATE).
  11679. /// Request to execute GM commands.
  11680. /// Usage:
  11681. /// /item n - summon n monster or acquire n item/s
  11682. /// /item money - grants 2147483647 zenies
  11683. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11684. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11685. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11686. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11687. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11688. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11689. /// 013f <item/mob name>.24B
  11690. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11691. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11692. {
  11693. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11694. int mob_id = 0;
  11695. struct item_data *id = NULL;
  11696. struct mob_db *mob = NULL;
  11697. StringBuf command;
  11698. char *str;
  11699. //#if PACKETVER >= 20131218
  11700. // char str[100];
  11701. //#else
  11702. // char str[24];
  11703. //#endif
  11704. str = (char*)RFIFOP(fd,info->pos[0]);
  11705. if (!str || str[0] == '\0')
  11706. return;
  11707. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11708. return;
  11709. trim(str);
  11710. // Zeny
  11711. if( strcmpi(str, "money") == 0 ) {
  11712. StringBuf_Init(&command);
  11713. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11714. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11715. StringBuf_Destroy(&command);
  11716. return;
  11717. }
  11718. // Item
  11719. if( (id = itemdb_searchname(str)) ) {
  11720. StringBuf_Init(&command);
  11721. if( !itemdb_isstackable2(id) ) //Nonstackable
  11722. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11723. else {
  11724. if (id->flag.guid)
  11725. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11726. else
  11727. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11728. }
  11729. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11730. StringBuf_Destroy(&command);
  11731. return;
  11732. }
  11733. // Monster
  11734. if ((mob_id = mobdb_searchname(str)) == 0)
  11735. mob_id = mobdb_checkid(atoi(str));
  11736. if( (mob = mob_db(mob_id)) ) {
  11737. StringBuf_Init(&command);
  11738. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11739. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11740. StringBuf_Destroy(&command);
  11741. return;
  11742. }
  11743. }
  11744. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11745. /// 019d <effect state>.L
  11746. /// effect state:
  11747. /// TODO: Any OPTION_* ?
  11748. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11749. char cmd[6];
  11750. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11751. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11752. is_atcommand(fd, sd, cmd, 1);
  11753. }
  11754. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11755. /// 0149 <account id>.L <type>.B <value>.W
  11756. /// type:
  11757. /// 0 = positive points
  11758. /// 1 = negative points
  11759. /// 2 = self mute (+10 minutes)
  11760. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11761. {
  11762. int id, type, value;
  11763. struct map_session_data *dstsd;
  11764. char command[NAME_LENGTH+15];
  11765. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11766. id = RFIFOL(fd,info->pos[0]);
  11767. type = RFIFOB(fd,info->pos[1]);
  11768. value = RFIFOW(fd,info->pos[2]);
  11769. if( type == 0 )
  11770. value = -value;
  11771. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11772. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11773. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11774. return;
  11775. dstsd = map_id2sd(id);
  11776. if( dstsd == NULL )
  11777. return;
  11778. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11779. is_atcommand(fd, sd, command, 1);
  11780. }
  11781. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11782. /// GM adjustment of a player's manner value by -60.
  11783. /// 0212 <char name>.24B
  11784. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11785. {
  11786. char command[NAME_LENGTH+15];
  11787. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11788. name[NAME_LENGTH-1] = '\0';
  11789. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11790. is_atcommand(fd, sd, command, 1);
  11791. }
  11792. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11793. /// 01e0 <account id>.L <account name>.24B
  11794. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11795. {
  11796. WFIFOHEAD(fd,packet_len(0x1e0));
  11797. WFIFOW(fd,0) = 0x1e0;
  11798. WFIFOL(fd,2) = account_id;
  11799. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11800. WFIFOSET(fd,packet_len(0x1e0));
  11801. }
  11802. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11803. /// 01df <account id>.L
  11804. //! TODO: Figure out how does this actually work
  11805. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11806. {
  11807. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11808. /*
  11809. char query[30];
  11810. safesnprintf(query,sizeof(query),"%d", account_id);
  11811. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11812. */
  11813. clif_account_name(fd, account_id, "");
  11814. }
  11815. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11816. /// GM single cell type change request.
  11817. /// 0198 <x>.W <y>.W <type>.W
  11818. /// type:
  11819. /// 0 = not walkable
  11820. /// 1 = walkable
  11821. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11822. {
  11823. int x,y,type;
  11824. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11825. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11826. return;
  11827. x = RFIFOW(fd,info->pos[0]);
  11828. y = RFIFOW(fd,info->pos[1]);
  11829. type = RFIFOW(fd,info->pos[2]);
  11830. map_setgatcell(sd->bl.m,x,y,type);
  11831. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11832. //FIXME: once players leave the map, the client 'forgets' this information.
  11833. }
  11834. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11835. /// Request to allow/deny whispers from a nick.
  11836. /// 00cf <nick>.24B <type>.B
  11837. /// type:
  11838. /// 0 = (/ex nick) deny speech from nick
  11839. /// 1 = (/in nick) allow speech from nick
  11840. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11841. {
  11842. char* nick;
  11843. uint8 type;
  11844. int i;
  11845. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11846. nick = (char*)RFIFOP(fd,info->pos[0]);
  11847. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11848. type = RFIFOB(fd,info->pos[1]);
  11849. if( type == 0 ) { // Add name to ignore list (block)
  11850. if (strcmp(wisp_server_name, nick) == 0) {
  11851. clif_wisexin(sd, type, 1); // fail
  11852. return;
  11853. }
  11854. // try to find a free spot, while checking for duplicates at the same time
  11855. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11856. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11857. clif_wisexin(sd, type, 2); // too many blocks
  11858. return;
  11859. }
  11860. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11861. clif_wisexin(sd, type, 0); // Aegis reports success.
  11862. return;
  11863. }
  11864. //Insert in position i
  11865. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11866. } else { // Remove name from ignore list (unblock)
  11867. // find entry
  11868. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11869. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11870. clif_wisexin(sd, type, 1); // fail
  11871. return;
  11872. }
  11873. // move everything one place down to overwrite removed entry
  11874. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11875. // wipe last entry
  11876. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11877. }
  11878. clif_wisexin(sd, type, 0); // success
  11879. }
  11880. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11881. /// Request to allow/deny all whispers.
  11882. /// 00d0 <type>.B
  11883. /// type:
  11884. /// 0 = (/exall) deny all speech
  11885. /// 1 = (/inall) allow all speech
  11886. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11887. {
  11888. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11889. if( type == 0 ) {// Deny all
  11890. if( sd->state.ignoreAll ) {
  11891. flag = 1; // fail
  11892. } else {
  11893. sd->state.ignoreAll = 1;
  11894. flag = 0; // success
  11895. }
  11896. } else {//Unblock everyone
  11897. if( sd->state.ignoreAll ) {
  11898. sd->state.ignoreAll = 0;
  11899. flag = 0; // success
  11900. } else {
  11901. if (sd->ignore[0].name[0] != '\0')
  11902. { //Wipe the ignore list.
  11903. memset(sd->ignore, 0, sizeof(sd->ignore));
  11904. flag = 0; // success
  11905. } else {
  11906. flag = 1; // fail
  11907. }
  11908. }
  11909. }
  11910. clif_wisall(sd, type, flag);
  11911. }
  11912. /// Whisper ignore list (ZC_WHISPER_LIST).
  11913. /// 00d4 <packet len>.W { <char name>.24B }*
  11914. void clif_PMIgnoreList(struct map_session_data* sd)
  11915. {
  11916. int i, fd = sd->fd;
  11917. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11918. WFIFOW(fd,0) = 0xd4;
  11919. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11920. safestrncpy((char*)WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11921. }
  11922. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11923. WFIFOSET(fd,WFIFOW(fd,2));
  11924. }
  11925. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11926. /// 00d3
  11927. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11928. {
  11929. clif_PMIgnoreList(sd);
  11930. }
  11931. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11932. /// 01e7
  11933. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11934. {
  11935. if (sd->state.doridori) return;
  11936. switch (sd->class_&MAPID_UPPERMASK) {
  11937. case MAPID_SOUL_LINKER:
  11938. case MAPID_STAR_GLADIATOR:
  11939. case MAPID_TAEKWON:
  11940. if (!sd->state.rest)
  11941. break;
  11942. case MAPID_SUPER_NOVICE:
  11943. case MAPID_SUPER_BABY:
  11944. case MAPID_SUPER_NOVICE_E:
  11945. case MAPID_SUPER_BABY_E:
  11946. sd->state.doridori=1;
  11947. break;
  11948. }
  11949. }
  11950. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11951. /// 01ed
  11952. /// Note: This packet is caused by 7 lines of any text, followed by
  11953. /// the prayer and an another line of any text. The prayer is
  11954. /// defined by lines 790~793 in data\msgstringtable.txt
  11955. /// "Dear angel, can you hear my voice?"
  11956. /// "I am" (space separated player name) "Super Novice~"
  11957. /// "Help me out~ Please~ T_T"
  11958. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11959. {
  11960. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11961. unsigned int next = pc_nextbaseexp(sd);
  11962. if( next ) {
  11963. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11964. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11965. 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]
  11966. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11967. }
  11968. }
  11969. }
  11970. }
  11971. /// Friends List
  11972. ///
  11973. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11974. /// 0206 <account id>.L <char id>.L <state>.B
  11975. /// state:
  11976. /// 0 = online
  11977. /// 1 = offline
  11978. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11979. {
  11980. int i, fd = sd->fd;
  11981. //Seek friend.
  11982. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11983. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11984. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11985. return; //Not found
  11986. WFIFOHEAD(fd,packet_len(0x206));
  11987. WFIFOW(fd, 0) = 0x206;
  11988. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11989. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11990. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11991. WFIFOSET(fd, packet_len(0x206));
  11992. }
  11993. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11994. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11995. {
  11996. uint32 account_id, char_id, online;
  11997. account_id = va_arg(ap, int);
  11998. char_id = va_arg(ap, int);
  11999. online = va_arg(ap, int);
  12000. clif_friendslist_toggle(sd, account_id, char_id, online);
  12001. return 0;
  12002. }
  12003. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12004. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12005. void clif_friendslist_send(struct map_session_data *sd)
  12006. {
  12007. int i = 0, n, fd = sd->fd;
  12008. // Send friends list
  12009. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  12010. WFIFOW(fd, 0) = 0x201;
  12011. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12012. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  12013. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  12014. safestrncpy((char*)WFIFOP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12015. }
  12016. if (i) {
  12017. WFIFOW(fd,2) = 4 + 32 * i;
  12018. WFIFOSET(fd, WFIFOW(fd,2));
  12019. }
  12020. for (n = 0; n < i; n++) { //Sending the online players
  12021. if (map_charid2sd(sd->status.friends[n].char_id))
  12022. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12023. }
  12024. }
  12025. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12026. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12027. /// result:
  12028. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12029. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12030. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12031. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12032. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12033. {
  12034. int fd;
  12035. nullpo_retv(sd);
  12036. fd = sd->fd;
  12037. WFIFOHEAD(fd,packet_len(0x209));
  12038. WFIFOW(fd,0) = 0x209;
  12039. WFIFOW(fd,2) = type;
  12040. if (f_sd) {
  12041. WFIFOL(fd,4) = f_sd->status.account_id;
  12042. WFIFOL(fd,8) = f_sd->status.char_id;
  12043. safestrncpy((char*)WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12044. }
  12045. WFIFOSET(fd, packet_len(0x209));
  12046. }
  12047. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12048. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12049. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12050. {
  12051. int fd = sd->fd;
  12052. WFIFOHEAD(fd,packet_len(0x207));
  12053. WFIFOW(fd,0) = 0x207;
  12054. WFIFOL(fd,2) = account_id;
  12055. WFIFOL(fd,6) = char_id;
  12056. safestrncpy((char*)WFIFOP(fd,10), name, NAME_LENGTH);
  12057. WFIFOSET(fd,packet_len(0x207));
  12058. }
  12059. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12060. /// 0202 <name>.24B
  12061. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12062. {
  12063. struct map_session_data *f_sd;
  12064. int i;
  12065. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12066. // ensure that the request player's friend list is not full
  12067. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12068. if( i == MAX_FRIENDS ) {
  12069. clif_friendslist_reqack(sd, f_sd, 2);
  12070. return;
  12071. }
  12072. // Friend doesn't exist (no player with this name)
  12073. if (f_sd == NULL) {
  12074. clif_displaymessage(fd, msg_txt(sd,3));
  12075. return;
  12076. }
  12077. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12078. return;
  12079. }
  12080. // @noask [LuzZza]
  12081. if(f_sd->state.noask) {
  12082. clif_noask_sub(sd, f_sd, 5);
  12083. return;
  12084. }
  12085. // Friend already exists
  12086. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12087. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12088. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12089. return;
  12090. }
  12091. }
  12092. f_sd->friend_req = sd->status.char_id;
  12093. sd->friend_req = f_sd->status.char_id;
  12094. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12095. }
  12096. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12097. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12098. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12099. /// reply:
  12100. /// 0 = rejected
  12101. /// 1 = accepted
  12102. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12103. {
  12104. struct map_session_data *f_sd;
  12105. uint32 account_id;
  12106. char reply;
  12107. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12108. account_id = RFIFOL(fd,info->pos[0]);
  12109. //char_id = RFIFOL(fd,info->pos[1]);
  12110. if(sd->packet_ver < 6)
  12111. reply = RFIFOB(fd,info->pos[2]);
  12112. else
  12113. reply = RFIFOL(fd,info->pos[2]);
  12114. if( sd->bl.id == account_id ) {// adding oneself as friend
  12115. return;
  12116. }
  12117. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12118. if (f_sd == NULL)
  12119. return;
  12120. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12121. clif_friendslist_reqack(f_sd, sd, 1);
  12122. else {
  12123. int i;
  12124. // Find an empty slot
  12125. for (i = 0; i < MAX_FRIENDS; i++)
  12126. if (f_sd->status.friends[i].char_id == 0)
  12127. break;
  12128. if (i == MAX_FRIENDS) {
  12129. clif_friendslist_reqack(f_sd, sd, 2);
  12130. return;
  12131. }
  12132. f_sd->status.friends[i].account_id = sd->status.account_id;
  12133. f_sd->status.friends[i].char_id = sd->status.char_id;
  12134. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12135. clif_friendslist_reqack(f_sd, sd, 0);
  12136. if (battle_config.friend_auto_add) {
  12137. // Also add f_sd to sd's friendlist.
  12138. for (i = 0; i < MAX_FRIENDS; i++) {
  12139. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12140. return; //No need to add anything.
  12141. if (sd->status.friends[i].char_id == 0)
  12142. break;
  12143. }
  12144. if (i == MAX_FRIENDS) {
  12145. clif_friendslist_reqack(sd, f_sd, 2);
  12146. return;
  12147. }
  12148. sd->status.friends[i].account_id = f_sd->status.account_id;
  12149. sd->status.friends[i].char_id = f_sd->status.char_id;
  12150. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12151. clif_friendslist_reqack(sd, f_sd, 0);
  12152. }
  12153. }
  12154. }
  12155. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12156. /// 0203 <account id>.L <char id>.L
  12157. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12158. {
  12159. struct map_session_data *f_sd = NULL;
  12160. uint32 account_id, char_id;
  12161. int i, j;
  12162. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12163. account_id = RFIFOL(fd,info->pos[0]);
  12164. char_id = RFIFOL(fd,info->pos[1]);
  12165. // Search friend
  12166. for (i = 0; i < MAX_FRIENDS &&
  12167. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12168. if (i == MAX_FRIENDS) {
  12169. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12170. return;
  12171. }
  12172. //remove from friend's list first
  12173. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12174. for (i = 0; i < MAX_FRIENDS &&
  12175. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12176. if (i != MAX_FRIENDS) {
  12177. // move all chars up
  12178. for(j = i + 1; j < MAX_FRIENDS; j++)
  12179. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12180. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12181. //should the guy be notified of some message? we should add it here if so
  12182. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12183. WFIFOW(f_sd->fd,0) = 0x20a;
  12184. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12185. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12186. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12187. }
  12188. } else { //friend not online -- ask char server to delete from his friendlist
  12189. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12190. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12191. return;
  12192. }
  12193. }
  12194. // We can now delete from original requester
  12195. for (i = 0; i < MAX_FRIENDS &&
  12196. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12197. // move all chars up
  12198. for(j = i + 1; j < MAX_FRIENDS; j++)
  12199. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12200. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12201. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12202. WFIFOHEAD(fd,packet_len(0x20a));
  12203. WFIFOW(fd,0) = 0x20a;
  12204. WFIFOL(fd,2) = account_id;
  12205. WFIFOL(fd,6) = char_id;
  12206. WFIFOSET(fd, packet_len(0x20a));
  12207. }
  12208. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12209. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12210. void clif_PVPInfo(struct map_session_data* sd)
  12211. {
  12212. int fd = sd->fd;
  12213. WFIFOHEAD(fd,packet_len(0x210));
  12214. WFIFOW(fd,0) = 0x210;
  12215. WFIFOL(fd,2) = sd->status.char_id;
  12216. WFIFOL(fd,6) = sd->status.account_id;
  12217. WFIFOL(fd,10) = sd->pvp_won; // times won
  12218. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12219. WFIFOL(fd,18) = sd->pvp_point;
  12220. WFIFOSET(fd, packet_len(0x210));
  12221. }
  12222. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12223. /// 020f <char id>.L <account id>.L
  12224. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12225. {
  12226. // TODO: Is there a way to use this on an another player (char/acc id)?
  12227. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12228. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12229. clif_PVPInfo(sd);
  12230. }
  12231. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  12232. /// 0219 { <name>.24B }*10 { <point>.L }*10
  12233. void clif_blacksmith(struct map_session_data* sd)
  12234. {
  12235. int i, fd = sd->fd;
  12236. const char* name;
  12237. WFIFOHEAD(fd,packet_len(0x219));
  12238. WFIFOW(fd,0) = 0x219;
  12239. //Packet size limits this list to 10 elements. [Skotlex]
  12240. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  12241. if (smith_fame_list[i].id > 0) {
  12242. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  12243. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  12244. {
  12245. safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  12246. } else
  12247. safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  12248. } else
  12249. safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  12250. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  12251. }
  12252. for(;i < 10; i++) { //In case the MAX is less than 10.
  12253. safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  12254. WFIFOL(fd, 242 + i * 4) = 0;
  12255. }
  12256. WFIFOSET(fd, packet_len(0x219));
  12257. }
  12258. /// /blacksmith (CZ_BLACKSMITH_RANK).
  12259. /// 0217
  12260. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  12261. {
  12262. clif_blacksmith(sd);
  12263. }
  12264. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  12265. /// 021b <points>.L <total points>.L
  12266. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  12267. {
  12268. int fd = sd->fd;
  12269. WFIFOHEAD(fd,packet_len(0x21b));
  12270. WFIFOW(fd,0) = 0x21b;
  12271. WFIFOL(fd,2) = points;
  12272. WFIFOL(fd,6) = sd->status.fame;
  12273. WFIFOSET(fd, packet_len(0x21b));
  12274. }
  12275. /// /alchemist list (ZC_ALCHEMIST_RANK).
  12276. /// 021a { <name>.24B }*10 { <point>.L }*10
  12277. void clif_alchemist(struct map_session_data* sd)
  12278. {
  12279. int i, fd = sd->fd;
  12280. const char* name;
  12281. WFIFOHEAD(fd,packet_len(0x21a));
  12282. WFIFOW(fd,0) = 0x21a;
  12283. //Packet size limits this list to 10 elements. [Skotlex]
  12284. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12285. if (chemist_fame_list[i].id > 0) {
  12286. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  12287. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12288. {
  12289. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12290. } else
  12291. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12292. } else
  12293. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12294. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12295. }
  12296. for(;i < 10; i++) { //In case the MAX is less than 10.
  12297. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12298. WFIFOL(fd, 242 + i * 4) = 0;
  12299. }
  12300. WFIFOSET(fd, packet_len(0x21a));
  12301. }
  12302. /// /alchemist (CZ_ALCHEMIST_RANK).
  12303. /// 0218
  12304. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12305. {
  12306. clif_alchemist(sd);
  12307. }
  12308. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12309. /// 021c <points>.L <total points>.L
  12310. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12311. {
  12312. int fd = sd->fd;
  12313. WFIFOHEAD(fd,packet_len(0x21c));
  12314. WFIFOW(fd,0) = 0x21c;
  12315. WFIFOL(fd,2) = points;
  12316. WFIFOL(fd,6) = sd->status.fame;
  12317. WFIFOSET(fd, packet_len(0x21c));
  12318. }
  12319. /// /taekwon list (ZC_TAEKWON_RANK).
  12320. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12321. void clif_taekwon(struct map_session_data* sd)
  12322. {
  12323. int i, fd = sd->fd;
  12324. const char* name;
  12325. WFIFOHEAD(fd,packet_len(0x226));
  12326. WFIFOW(fd,0) = 0x226;
  12327. //Packet size limits this list to 10 elements. [Skotlex]
  12328. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12329. if (taekwon_fame_list[i].id > 0) {
  12330. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12331. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12332. {
  12333. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12334. } else
  12335. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12336. } else
  12337. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12338. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12339. }
  12340. for(;i < 10; i++) { //In case the MAX is less than 10.
  12341. safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12342. WFIFOL(fd, 242 + i * 4) = 0;
  12343. }
  12344. WFIFOSET(fd, packet_len(0x226));
  12345. }
  12346. /// /taekwon (CZ_TAEKWON_RANK).
  12347. /// 0225
  12348. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12349. {
  12350. clif_taekwon(sd);
  12351. }
  12352. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12353. /// 0224 <points>.L <total points>.L
  12354. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12355. {
  12356. int fd = sd->fd;
  12357. WFIFOHEAD(fd,packet_len(0x224));
  12358. WFIFOW(fd,0) = 0x224;
  12359. WFIFOL(fd,2) = points;
  12360. WFIFOL(fd,6) = sd->status.fame;
  12361. WFIFOSET(fd, packet_len(0x224));
  12362. }
  12363. /// /pk list (ZC_KILLER_RANK).
  12364. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12365. void clif_ranking_pk(struct map_session_data* sd)
  12366. {
  12367. int i, fd = sd->fd;
  12368. WFIFOHEAD(fd,packet_len(0x238));
  12369. WFIFOW(fd,0) = 0x238;
  12370. for(i=0;i<10;i++){
  12371. safestrncpy((char*)WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12372. WFIFOL(fd,i*4+242) = 0;
  12373. }
  12374. WFIFOSET(fd, packet_len(0x238));
  12375. }
  12376. /// /pk (CZ_KILLER_RANK).
  12377. /// 0237
  12378. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12379. {
  12380. clif_ranking_pk(sd);
  12381. }
  12382. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12383. /// 0254 <which>.B
  12384. /// which: (unused atm for security purpose)
  12385. /// 0 = sun
  12386. /// 1 = moon
  12387. /// 2 = star
  12388. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12389. {
  12390. int i;
  12391. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12392. if (sd->menuskill_id != SG_FEEL)
  12393. return;
  12394. i = sd->menuskill_val-1;
  12395. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12396. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12397. sd->feel_map[i].m = sd->bl.m;
  12398. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12399. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12400. // clif_misceffect2(&sd->bl, 0x1b0);
  12401. // clif_misceffect2(&sd->bl, 0x21f);
  12402. clif_feel_info(sd, i, 0);
  12403. clif_menuskill_clear(sd);
  12404. }
  12405. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12406. /// 0253 <which>.B
  12407. /// which:
  12408. /// 0 = sun
  12409. /// 1 = moon
  12410. /// 2 = star
  12411. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12412. {
  12413. WFIFOHEAD(fd,packet_len(0x253));
  12414. WFIFOW(fd,0)=0x253;
  12415. WFIFOB(fd,2)=TOB(skill_lv-1);
  12416. WFIFOSET(fd, packet_len(0x253));
  12417. sd->menuskill_id = SG_FEEL;
  12418. sd->menuskill_val = skill_lv;
  12419. }
  12420. /// Request to change homunculus' name (CZ_RENAME_MER).
  12421. /// 0231 <name>.24B
  12422. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12423. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12424. }
  12425. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12426. /// 0234 <id>.L
  12427. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12428. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12429. struct block_list *bl = NULL;
  12430. struct unit_data *ud = NULL;
  12431. if( sd->md && sd->md->bl.id == id )
  12432. bl = &sd->md->bl;
  12433. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12434. bl = &sd->hd->bl; // Moving Homunculus
  12435. else
  12436. return;
  12437. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12438. ud = unit_bl2ud(bl);
  12439. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12440. }
  12441. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12442. /// 0232 <id>.L <position data>.3B
  12443. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12444. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12445. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12446. struct block_list *bl = NULL;
  12447. short x, y;
  12448. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12449. if( sd->md && sd->md->bl.id == id )
  12450. bl = &sd->md->bl; // Moving Mercenary
  12451. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12452. bl = &sd->hd->bl; // Moving Homunculus
  12453. else
  12454. return;
  12455. unit_walktoxy(bl, x, y, 4);
  12456. }
  12457. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12458. /// 0233 <id>.L <target id>.L <action>.B
  12459. /// action:
  12460. /// always 0
  12461. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12462. {
  12463. struct block_list *bl = NULL;
  12464. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12465. int id = RFIFOL(fd,info->pos[0]);
  12466. int target_id = RFIFOL(fd,info->pos[1]);
  12467. int action_type = RFIFOB(fd,info->pos[2]);
  12468. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12469. bl = &sd->hd->bl;
  12470. else if( sd->md && sd->md->bl.id == id )
  12471. bl = &sd->md->bl;
  12472. else return;
  12473. unit_stop_attack(bl);
  12474. unit_attack(bl, target_id, action_type != 0);
  12475. }
  12476. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12477. /// 022d <type>.W <command>.B
  12478. /// type:
  12479. /// always 0
  12480. /// command:
  12481. /// 0 = homunculus information
  12482. /// 1 = feed
  12483. /// 2 = delete
  12484. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12485. { //[orn]
  12486. int cmd = RFIFOW(fd,0);
  12487. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12488. if(!hom_is_active(sd->hd))
  12489. return;
  12490. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12491. }
  12492. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12493. /// 0292
  12494. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12495. {
  12496. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12497. uint8 hp = 100, sp = 100;
  12498. if (item_position < 0) {
  12499. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12500. // HP restored
  12501. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12502. sp = 0;
  12503. }
  12504. else
  12505. return;
  12506. }
  12507. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12508. return;
  12509. if (!status_revive(&sd->bl, hp, sp))
  12510. return;
  12511. if (item_position < 0)
  12512. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12513. else
  12514. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12515. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12516. }
  12517. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12518. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12519. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12520. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12521. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12522. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12523. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12524. void clif_check(int fd, struct map_session_data* pl_sd)
  12525. {
  12526. WFIFOHEAD(fd,packet_len(0x214));
  12527. WFIFOW(fd, 0) = 0x214;
  12528. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12529. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12530. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12531. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12532. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12533. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12534. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12535. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12536. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12537. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12538. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12539. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12540. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12541. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12542. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12543. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12544. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12545. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12546. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12547. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12548. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12549. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12550. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12551. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12552. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12553. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12554. WFIFOSET(fd,packet_len(0x214));
  12555. }
  12556. /// /check (CZ_REQ_STATUS_GM).
  12557. /// Request character's status values.
  12558. /// 0213 <char name>.24B
  12559. void clif_parse_Check(int fd, struct map_session_data *sd)
  12560. {
  12561. char charname[NAME_LENGTH];
  12562. struct map_session_data* pl_sd;
  12563. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12564. return;
  12565. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12566. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12567. {
  12568. return;
  12569. }
  12570. clif_check(fd, pl_sd);
  12571. }
  12572. /// MAIL SYSTEM
  12573. /// By Zephyrus
  12574. ///
  12575. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12576. /// 0255 <index>.W <result>.B
  12577. /// result:
  12578. /// 0 = success
  12579. /// 1 = failure
  12580. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12581. {
  12582. WFIFOHEAD(fd,packet_len(0x255));
  12583. WFIFOW(fd,0) = 0x255;
  12584. WFIFOW(fd,2) = index;
  12585. WFIFOB(fd,4) = flag;
  12586. WFIFOSET(fd,packet_len(0x255));
  12587. }
  12588. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12589. /// 0245 <result>.B
  12590. /// result:
  12591. /// 0 = success
  12592. /// 1 = failure
  12593. /// 2 = too many items
  12594. void clif_Mail_getattachment(int fd, uint8 result)
  12595. {
  12596. WFIFOHEAD(fd,packet_len(0x245));
  12597. WFIFOW(fd,0) = 0x245;
  12598. WFIFOB(fd,2) = result;
  12599. WFIFOSET(fd,packet_len(0x245));
  12600. }
  12601. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12602. /// 0249 <result>.B
  12603. /// result:
  12604. /// 0 = success
  12605. /// 1 = recipinent does not exist
  12606. void clif_Mail_send(int fd, bool fail)
  12607. {
  12608. WFIFOHEAD(fd,packet_len(0x249));
  12609. WFIFOW(fd,0) = 0x249;
  12610. WFIFOB(fd,2) = fail;
  12611. WFIFOSET(fd,packet_len(0x249));
  12612. }
  12613. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12614. /// 0257 <mail id>.L <result>.W
  12615. /// result:
  12616. /// 0 = success
  12617. /// 1 = failure
  12618. void clif_Mail_delete(int fd, int mail_id, short fail)
  12619. {
  12620. WFIFOHEAD(fd, packet_len(0x257));
  12621. WFIFOW(fd,0) = 0x257;
  12622. WFIFOL(fd,2) = mail_id;
  12623. WFIFOW(fd,6) = fail;
  12624. WFIFOSET(fd, packet_len(0x257));
  12625. }
  12626. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12627. /// 0274 <mail id>.L <result>.W
  12628. /// result:
  12629. /// 0 = success
  12630. /// 1 = failure
  12631. void clif_Mail_return(int fd, int mail_id, short fail)
  12632. {
  12633. WFIFOHEAD(fd,packet_len(0x274));
  12634. WFIFOW(fd,0) = 0x274;
  12635. WFIFOL(fd,2) = mail_id;
  12636. WFIFOW(fd,6) = fail;
  12637. WFIFOSET(fd,packet_len(0x274));
  12638. }
  12639. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12640. /// 024a <mail id>.L <title>.40B <sender>.24B
  12641. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12642. {
  12643. WFIFOHEAD(fd,packet_len(0x24a));
  12644. WFIFOW(fd,0) = 0x24a;
  12645. WFIFOL(fd,2) = mail_id;
  12646. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12647. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12648. WFIFOSET(fd,packet_len(0x24a));
  12649. }
  12650. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12651. /// 0260 <type>.L
  12652. /// type:
  12653. /// 0 = open
  12654. /// 1 = close
  12655. void clif_Mail_window(int fd, int flag)
  12656. {
  12657. WFIFOHEAD(fd,packet_len(0x260));
  12658. WFIFOW(fd,0) = 0x260;
  12659. WFIFOL(fd,2) = flag;
  12660. WFIFOSET(fd,packet_len(0x260));
  12661. }
  12662. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12663. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12664. /// read:
  12665. /// 0 = unread
  12666. /// 1 = read
  12667. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12668. {
  12669. int fd = sd->fd;
  12670. struct mail_data *md = &sd->mail.inbox;
  12671. struct mail_message *msg;
  12672. int len, i, j;
  12673. len = 8 + (73 * md->amount);
  12674. WFIFOHEAD(fd,len);
  12675. WFIFOW(fd,0) = 0x240;
  12676. WFIFOW(fd,2) = len;
  12677. WFIFOL(fd,4) = md->amount;
  12678. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12679. {
  12680. msg = &md->msg[i];
  12681. if (msg->id < 1)
  12682. continue;
  12683. WFIFOL(fd,8+73*j) = msg->id;
  12684. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12685. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12686. safestrncpy((char*)WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12687. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12688. j++;
  12689. }
  12690. WFIFOSET(fd,len);
  12691. if( md->full ) {// TODO: is this official?
  12692. char output[100];
  12693. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12694. clif_disp_onlyself(sd, output, strlen(output));
  12695. }
  12696. }
  12697. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12698. /// 023f
  12699. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12700. {
  12701. struct mail_data* md = &sd->mail.inbox;
  12702. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12703. intif_Mail_requestinbox(sd->status.char_id, 1);
  12704. else
  12705. clif_Mail_refreshinbox(sd);
  12706. mail_removeitem(sd, 0);
  12707. mail_removezeny(sd, 0);
  12708. }
  12709. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12710. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12711. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12712. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12713. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12714. {
  12715. int i, fd = sd->fd;
  12716. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12717. if( i == MAIL_MAX_INBOX ) {
  12718. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12719. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12720. return;
  12721. } else {
  12722. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12723. struct item *item = &msg->item;
  12724. struct item_data *data;
  12725. int msg_len = strlen(msg->body), len;
  12726. if( msg_len == 0 ) {
  12727. strcpy(msg->body, "(no message)");
  12728. msg_len = strlen(msg->body);
  12729. }
  12730. len = 101 + msg_len;
  12731. WFIFOHEAD(fd,len);
  12732. WFIFOW(fd,0) = 0x242;
  12733. WFIFOW(fd,2) = len;
  12734. WFIFOL(fd,4) = msg->id;
  12735. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12736. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12737. WFIFOL(fd,72) = 0;
  12738. WFIFOL(fd,76) = msg->zeny;
  12739. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12740. WFIFOL(fd,80) = item->amount;
  12741. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12742. WFIFOW(fd,86) = data->type;
  12743. WFIFOB(fd,88) = item->identify;
  12744. WFIFOB(fd,89) = item->attribute;
  12745. WFIFOB(fd,90) = item->refine;
  12746. WFIFOW(fd,91) = item->card[0];
  12747. WFIFOW(fd,93) = item->card[1];
  12748. WFIFOW(fd,95) = item->card[2];
  12749. WFIFOW(fd,97) = item->card[3];
  12750. } else // no item, set all to zero
  12751. memset(WFIFOP(fd,80), 0x00, 19);
  12752. WFIFOB(fd,99) = (unsigned char)msg_len;
  12753. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12754. WFIFOSET(fd,len);
  12755. if (msg->status == MAIL_UNREAD) {
  12756. msg->status = MAIL_READ;
  12757. intif_Mail_read(mail_id);
  12758. clif_parse_Mail_refreshinbox(fd, sd);
  12759. }
  12760. }
  12761. }
  12762. /// Request to open a mail (CZ_MAIL_OPEN).
  12763. /// 0241 <mail id>.L
  12764. void clif_parse_Mail_read(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. if( mail_id <= 0 )
  12768. return;
  12769. if( mail_invalid_operation(sd) )
  12770. return;
  12771. clif_Mail_read(sd, mail_id);
  12772. }
  12773. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12774. /// 0244 <mail id>.L
  12775. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12776. {
  12777. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12778. int i;
  12779. bool fail = false;
  12780. if( !chrif_isconnected() )
  12781. return;
  12782. if( mail_id <= 0 )
  12783. return;
  12784. if( mail_invalid_operation(sd) )
  12785. return;
  12786. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12787. if( i == MAIL_MAX_INBOX )
  12788. return;
  12789. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12790. return;
  12791. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12792. clif_Mail_getattachment(fd, 1); //too many zeny
  12793. return;
  12794. }
  12795. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12796. struct item_data *data;
  12797. unsigned int weight;
  12798. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12799. return;
  12800. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12801. case CHKADDITEM_NEW:
  12802. fail = ( pc_inventoryblank(sd) == 0 );
  12803. break;
  12804. case CHKADDITEM_OVERAMOUNT:
  12805. fail = true;
  12806. }
  12807. if( fail ) {
  12808. clif_Mail_getattachment(fd, 1);
  12809. return;
  12810. }
  12811. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12812. if( sd->weight + weight > sd->max_weight ) {
  12813. clif_Mail_getattachment(fd, 2);
  12814. return;
  12815. }
  12816. }
  12817. sd->mail.inbox.msg[i].zeny = 0;
  12818. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12819. clif_Mail_read(sd, mail_id);
  12820. intif_Mail_getattach(sd->status.char_id, mail_id);
  12821. }
  12822. /// Request to delete a mail (CZ_MAIL_DELETE).
  12823. /// 0243 <mail id>.L
  12824. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12825. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12826. int i;
  12827. if( !chrif_isconnected() )
  12828. return;
  12829. if( mail_id <= 0 )
  12830. return;
  12831. if( mail_invalid_operation(sd) )
  12832. return;
  12833. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12834. if (i < MAIL_MAX_INBOX) {
  12835. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12836. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12837. clif_Mail_delete(sd->fd, mail_id, 1);
  12838. return;
  12839. }
  12840. intif_Mail_delete(sd->status.char_id, mail_id);
  12841. }
  12842. }
  12843. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12844. /// 0273 <mail id>.L <receive name>.24B
  12845. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12846. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12847. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12848. int i;
  12849. if( mail_id <= 0 )
  12850. return;
  12851. if( mail_invalid_operation(sd) )
  12852. return;
  12853. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12854. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12855. intif_Mail_return(sd->status.char_id, mail_id);
  12856. else
  12857. clif_Mail_return(sd->fd, mail_id, 1);
  12858. }
  12859. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12860. /// 0247 <index>.W <amount>.L
  12861. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12862. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12863. int idx = RFIFOW(fd,info->pos[0]);
  12864. int amount = RFIFOL(fd,info->pos[1]);
  12865. unsigned char flag;
  12866. if( !chrif_isconnected() )
  12867. return;
  12868. if (idx < 0 || amount < 0)
  12869. return;
  12870. flag = mail_setitem(sd, idx, amount);
  12871. clif_Mail_setattachment(fd,idx,!flag);
  12872. }
  12873. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12874. /// 0246 <type>.W
  12875. /// type:
  12876. /// 0 = reset all
  12877. /// 1 = remove item
  12878. /// 2 = remove zeny
  12879. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12880. {
  12881. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12882. if (type == 0 || type == 1)
  12883. mail_removeitem(sd, 0);
  12884. if (type == 0 || type == 2)
  12885. mail_removezeny(sd, 0);
  12886. }
  12887. /// Request to send mail (CZ_MAIL_SEND).
  12888. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12889. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12890. {
  12891. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12892. if( !chrif_isconnected() )
  12893. return;
  12894. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12895. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12896. return;
  12897. }
  12898. 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]));
  12899. }
  12900. /// AUCTION SYSTEM
  12901. /// By Zephyrus
  12902. ///
  12903. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12904. /// 025f <type>.L
  12905. /// type:
  12906. /// 0 = open
  12907. /// 1 = close
  12908. void clif_Auction_openwindow(struct map_session_data *sd)
  12909. {
  12910. int fd = sd->fd;
  12911. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12912. return;
  12913. if( !battle_config.feature_auction )
  12914. return;
  12915. WFIFOHEAD(fd,packet_len(0x25f));
  12916. WFIFOW(fd,0) = 0x25f;
  12917. WFIFOL(fd,2) = 0;
  12918. WFIFOSET(fd,packet_len(0x25f));
  12919. }
  12920. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12921. /// 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 }*
  12922. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12923. {
  12924. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12925. struct auction_data auction;
  12926. struct item_data *item;
  12927. WFIFOHEAD(fd,12 + (count * 83));
  12928. WFIFOW(fd,0) = 0x252;
  12929. WFIFOW(fd,2) = 12 + (count * 83);
  12930. WFIFOL(fd,4) = pages;
  12931. WFIFOL(fd,8) = count;
  12932. for( i = 0; i < count; i++ ) {
  12933. int k = 12 + (i * 83);
  12934. memcpy(&auction, RBUFP(buf,i * len), len);
  12935. WFIFOL(fd,k) = auction.auction_id;
  12936. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12937. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12938. WFIFOW(fd,28+k) = item->view_id;
  12939. else
  12940. WFIFOW(fd,28+k) = auction.item.nameid;
  12941. WFIFOL(fd,30+k) = auction.type;
  12942. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12943. WFIFOB(fd,36+k) = auction.item.identify;
  12944. WFIFOB(fd,37+k) = auction.item.attribute;
  12945. WFIFOB(fd,38+k) = auction.item.refine;
  12946. WFIFOW(fd,39+k) = auction.item.card[0];
  12947. WFIFOW(fd,41+k) = auction.item.card[1];
  12948. WFIFOW(fd,43+k) = auction.item.card[2];
  12949. WFIFOW(fd,45+k) = auction.item.card[3];
  12950. WFIFOL(fd,47+k) = auction.price;
  12951. WFIFOL(fd,51+k) = auction.buynow;
  12952. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12953. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12954. }
  12955. WFIFOSET(fd,WFIFOW(fd,2));
  12956. }
  12957. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12958. /// 0256 <index>.W <result>.B
  12959. /// result:
  12960. /// 0 = success
  12961. /// 1 = failure
  12962. static void clif_Auction_setitem(int fd, int index, bool fail)
  12963. {
  12964. WFIFOHEAD(fd,packet_len(0x256));
  12965. WFIFOW(fd,0) = 0x256;
  12966. WFIFOW(fd,2) = index;
  12967. WFIFOB(fd,4) = fail;
  12968. WFIFOSET(fd,packet_len(0x256));
  12969. }
  12970. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12971. /// 024b <type>.W
  12972. /// type:
  12973. /// 0 = create (any other action in auction window)
  12974. /// 1 = cancel (cancel pressed on register tab)
  12975. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12976. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12977. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12978. if( sd->auction.amount > 0 )
  12979. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12980. sd->auction.amount = 0;
  12981. }
  12982. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12983. /// 024c <index>.W <count>.L
  12984. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12985. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12986. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12987. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12988. struct item_data *item;
  12989. if( !battle_config.feature_auction )
  12990. return;
  12991. if( sd->auction.amount > 0 )
  12992. sd->auction.amount = 0;
  12993. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12994. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12995. return;
  12996. }
  12997. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12998. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12999. return;
  13000. }
  13001. 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) )
  13002. { // Consumable or pets are not allowed
  13003. clif_Auction_setitem(sd->fd, idx, true);
  13004. return;
  13005. }
  13006. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  13007. !sd->status.inventory[idx].identify ||
  13008. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13009. !itemdb_available(sd->status.inventory[idx].nameid) ||
  13010. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  13011. ) {
  13012. clif_Auction_setitem(sd->fd, idx, true);
  13013. return;
  13014. }
  13015. sd->auction.index = idx;
  13016. sd->auction.amount = amount;
  13017. clif_Auction_setitem(fd, idx + 2, false);
  13018. }
  13019. /// Result from an auction action (ZC_AUCTION_RESULT).
  13020. /// 0250 <result>.B
  13021. /// result:
  13022. /// 0 = You have failed to bid into the auction
  13023. /// 1 = You have successfully bid in the auction
  13024. /// 2 = The auction has been canceled
  13025. /// 3 = An auction with at least one bidder cannot be canceled
  13026. /// 4 = You cannot register more than 5 items in an auction at a time
  13027. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13028. /// 6 = You have won the auction
  13029. /// 7 = You have failed to win the auction
  13030. /// 8 = You do not have enough Zeny
  13031. /// 9 = You cannot place more than 5 bids at a time
  13032. void clif_Auction_message(int fd, unsigned char flag)
  13033. {
  13034. WFIFOHEAD(fd,packet_len(0x250));
  13035. WFIFOW(fd,0) = 0x250;
  13036. WFIFOB(fd,2) = flag;
  13037. WFIFOSET(fd,packet_len(0x250));
  13038. }
  13039. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13040. /// 025e <result>.W
  13041. /// result:
  13042. /// 0 = You have ended the auction
  13043. /// 1 = You cannot end the auction
  13044. /// 2 = Auction ID is incorrect
  13045. void clif_Auction_close(int fd, unsigned char flag)
  13046. {
  13047. WFIFOHEAD(fd,packet_len(0x25e));
  13048. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13049. WFIFOW(fd,2) = flag;
  13050. WFIFOSET(fd,packet_len(0x25e));
  13051. }
  13052. /// Request to add an auction (CZ_AUCTION_ADD).
  13053. /// 024d <now money>.L <max money>.L <delete hour>.W
  13054. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13055. {
  13056. struct auction_data auction;
  13057. struct item_data *item;
  13058. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13059. if( !battle_config.feature_auction )
  13060. return;
  13061. auction.price = RFIFOL(fd,info->pos[0]);
  13062. auction.buynow = RFIFOL(fd,info->pos[1]);
  13063. auction.hours = RFIFOW(fd,info->pos[2]);
  13064. // Invalid Situations...
  13065. if( sd->auction.amount < 1 ) {
  13066. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13067. return;
  13068. }
  13069. if( auction.price >= auction.buynow ) {
  13070. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13071. return;
  13072. }
  13073. if( auction.hours < 1 || auction.hours > 48 ) {
  13074. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13075. return;
  13076. }
  13077. // Auction checks...
  13078. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13079. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13080. clif_Auction_message(fd, 2); // The auction has been canceled
  13081. return;
  13082. }
  13083. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13084. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13085. return;
  13086. }
  13087. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13088. auction.buynow = battle_config.auction_maximumprice;
  13089. if( auction.price >= auction.buynow )
  13090. auction.price = auction.buynow - 1;
  13091. }
  13092. auction.auction_id = 0;
  13093. auction.seller_id = sd->status.char_id;
  13094. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13095. auction.buyer_id = 0;
  13096. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13097. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  13098. {
  13099. clif_Auction_message(fd, 2); // The auction has been canceled
  13100. return;
  13101. }
  13102. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  13103. { // Just in case
  13104. clif_Auction_message(fd, 2); // The auction has been canceled
  13105. return;
  13106. }
  13107. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13108. auction.type = item->type;
  13109. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  13110. auction.item.amount = 1;
  13111. auction.timestamp = 0;
  13112. if( !intif_Auction_register(&auction) )
  13113. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13114. else
  13115. {
  13116. int zeny = auction.hours*battle_config.auction_feeperhour;
  13117. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13118. sd->auction.amount = 0;
  13119. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13120. }
  13121. }
  13122. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13123. /// 024e <auction id>.L
  13124. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13125. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13126. intif_Auction_cancel(sd->status.char_id, auction_id);
  13127. }
  13128. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13129. /// 025d <auction id>.L
  13130. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13131. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13132. intif_Auction_close(sd->status.char_id, auction_id);
  13133. }
  13134. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13135. /// 024f <auction id>.L <money>.L
  13136. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13137. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13138. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13139. int bid = RFIFOL(fd,info->pos[1]);
  13140. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13141. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13142. return;
  13143. }
  13144. if( bid <= 0 )
  13145. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13146. else if( bid > sd->status.zeny )
  13147. clif_Auction_message(fd, 8); // You do not have enough zeny
  13148. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13149. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13150. else {
  13151. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13152. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13153. }
  13154. }
  13155. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13156. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13157. /// search type:
  13158. /// 0 = armor
  13159. /// 1 = weapon
  13160. /// 2 = card
  13161. /// 3 = misc
  13162. /// 4 = name search
  13163. /// 5 = auction id search
  13164. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13165. char search_text[NAME_LENGTH];
  13166. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13167. short type = RFIFOW(fd,info->pos[0]);
  13168. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13169. int page = RFIFOW(fd,info->pos[3]);
  13170. if( !battle_config.feature_auction )
  13171. return;
  13172. clif_parse_Auction_cancelreg(fd, sd);
  13173. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  13174. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13175. }
  13176. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13177. /// 025c <type>.W
  13178. /// type:
  13179. /// 0 = sell (own auctions)
  13180. /// 1 = buy (own bids)
  13181. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13182. {
  13183. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  13184. if( !battle_config.feature_auction )
  13185. return;
  13186. clif_parse_Auction_cancelreg(fd, sd);
  13187. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13188. }
  13189. /// CASH/POINT SHOP
  13190. ///
  13191. void clif_cashshop_open( struct map_session_data* sd ){
  13192. WFIFOHEAD( sd->fd, 10 );
  13193. WFIFOW( sd->fd, 0 ) = 0x845;
  13194. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13195. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13196. WFIFOSET( sd->fd, 10 );
  13197. }
  13198. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13199. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13200. clif_cashshop_open( sd );
  13201. }
  13202. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13203. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13204. // No need to do anything here
  13205. }
  13206. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13207. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13208. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13209. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13210. int j;
  13211. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  13212. return;
  13213. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13214. WFIFOW(fd, 0) = 0x8c0;
  13215. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13216. WFIFOL(fd, 4) = tab;
  13217. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13218. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13219. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13220. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13221. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13222. }
  13223. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13224. }
  13225. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13226. void clif_cashshop_list( int fd ){
  13227. int tab;
  13228. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13229. int length = 8 + cash_shop_items[tab].count * 6;
  13230. int i, offset;
  13231. WFIFOHEAD( fd, length );
  13232. WFIFOW( fd, 0 ) = 0x8ca;
  13233. WFIFOW( fd, 2 ) = length;
  13234. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13235. WFIFOW( fd, 6 ) = tab;
  13236. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13237. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13238. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13239. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13240. }
  13241. WFIFOSET( fd, length );
  13242. }
  13243. }
  13244. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13245. if( !sd->status.cashshop_sent ) {
  13246. clif_cashshop_list( fd );
  13247. sd->status.cashshop_sent = true;
  13248. }
  13249. }
  13250. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13251. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13252. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13253. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13254. {
  13255. int fd, i, cost[2] = { 0, 0 };
  13256. #if PACKETVER < 20070711
  13257. const int offset = 8;
  13258. #else
  13259. const int offset = 12;
  13260. #endif
  13261. nullpo_retv(sd);
  13262. nullpo_retv(nd);
  13263. npc_shop_currency_type(sd, nd, cost, true);
  13264. fd = sd->fd;
  13265. sd->npc_shopid = nd->bl.id;
  13266. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13267. WFIFOW(fd,0) = 0x287;
  13268. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13269. WFIFOL(fd,4) = cost[0];
  13270. #if PACKETVER >= 20070711
  13271. WFIFOL(fd,8) = cost[1];
  13272. #endif
  13273. for( i = 0; i < nd->u.shop.count; i++ ) {
  13274. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13275. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13276. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13277. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13278. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13279. }
  13280. WFIFOSET(fd,WFIFOW(fd,2));
  13281. }
  13282. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13283. /// 0289 <cash point>.L <error>.W
  13284. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13285. /// error:
  13286. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13287. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13288. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13289. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13290. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13291. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13292. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13293. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13294. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13295. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13296. {
  13297. int fd, cost[2] = { 0, 0 };
  13298. struct npc_data *nd;
  13299. nullpo_retv(sd);
  13300. fd = sd->fd;
  13301. nd = map_id2nd(sd->npc_shopid);
  13302. npc_shop_currency_type(sd, nd, cost, false);
  13303. WFIFOHEAD(fd, packet_len(0x289));
  13304. WFIFOW(fd,0) = 0x289;
  13305. WFIFOL(fd,2) = cost[0];
  13306. #if PACKETVER < 20070711
  13307. WFIFOW(fd,6) = TOW(error);
  13308. #else
  13309. WFIFOL(fd,6) = cost[1];
  13310. WFIFOW(fd,10) = TOW(error);
  13311. #endif
  13312. WFIFOSET(fd, packet_len(0x289));
  13313. }
  13314. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13315. WFIFOHEAD( sd->fd, 16 );
  13316. WFIFOW( sd->fd, 0 ) = 0x849;
  13317. WFIFOL( sd->fd, 2 ) = item_id;
  13318. WFIFOW( sd->fd, 6 ) = result;
  13319. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13320. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13321. WFIFOSET( sd->fd, 16 );
  13322. }
  13323. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13324. /// 0288 <name id>.W <amount>.W
  13325. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13326. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13327. /// 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)
  13328. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13329. struct s_packet_db* info;
  13330. int cmd = RFIFOW(fd,0);
  13331. nullpo_retv(sd);
  13332. info = &packet_db[sd->packet_ver][cmd];
  13333. if( sd->state.trading || !sd->npc_shopid ) {
  13334. clif_cashshop_ack(sd,1);
  13335. return;
  13336. }
  13337. else {
  13338. #if PACKETVER < 20101116
  13339. short nameid = RFIFOW(fd,info->pos[0]);
  13340. short amount = RFIFOW(fd,info->pos[1]);
  13341. int points = RFIFOL(fd,info->pos[2]);
  13342. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13343. #else
  13344. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13345. int len = RFIFOW(fd,info->pos[0]);
  13346. int points = RFIFOL(fd,info->pos[1]);
  13347. int count = RFIFOW(fd,info->pos[2]);
  13348. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13349. if( len < 10 || len != 10 + count * s_itl){
  13350. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13351. return;
  13352. }
  13353. if(cmd==0x848){
  13354. if (cashshop_buylist( sd, points, count, item_list))
  13355. clif_cashshop_ack(sd,0);
  13356. return;
  13357. } else {
  13358. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13359. return;
  13360. }
  13361. #endif
  13362. }
  13363. }
  13364. /// Adoption System
  13365. ///
  13366. /// Adoption message (ZC_BABYMSG).
  13367. /// 0216 <msg>.L
  13368. /// msg:
  13369. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13370. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13371. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13372. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13373. {
  13374. int fd = sd->fd;
  13375. WFIFOHEAD(fd,6);
  13376. WFIFOW(fd,0) = 0x216;
  13377. WFIFOL(fd,2) = type;
  13378. WFIFOSET(fd,6);
  13379. }
  13380. /// Adoption confirmation (ZC_REQ_BABY).
  13381. /// 01f6 <account id>.L <char id>.L <name>.B
  13382. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13383. {
  13384. int fd = sd->fd;
  13385. WFIFOHEAD(fd,34);
  13386. WFIFOW(fd,0) = 0x1f6;
  13387. WFIFOL(fd,2) = src->status.account_id;
  13388. WFIFOL(fd,6) = p_id;
  13389. safestrncpy((char*)WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13390. WFIFOSET(fd,34);
  13391. }
  13392. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13393. /// 01f9 <account id>.L
  13394. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13395. {
  13396. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13397. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13398. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  13399. {
  13400. tsd->adopt_invite = sd->status.account_id;
  13401. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13402. }
  13403. }
  13404. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13405. /// 01f7 <account id>.L <char id>.L <answer>.L
  13406. /// answer:
  13407. /// 0 = rejected
  13408. /// 1 = accepted
  13409. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13410. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13411. int p1_id = RFIFOL(fd,info->pos[0]);
  13412. int p2_id = RFIFOL(fd,info->pos[1]);
  13413. int result = RFIFOL(fd,info->pos[2]);
  13414. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13415. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13416. int pid = sd->adopt_invite;
  13417. sd->adopt_invite = 0;
  13418. if( p1_sd == NULL || p2_sd == NULL )
  13419. return; // Both players need to be online
  13420. if( pid != p1_sd->status.account_id )
  13421. return; // Incorrect values
  13422. if( result == 0 )
  13423. return; // Rejected
  13424. pc_adoption(p1_sd, p2_sd, sd);
  13425. }
  13426. /// Convex Mirror (ZC_BOSS_INFO).
  13427. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13428. /// infoType:
  13429. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13430. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13431. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13432. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13433. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13434. {
  13435. WFIFOHEAD(fd,70);
  13436. memset(WFIFOP(fd,0),0,70);
  13437. WFIFOW(fd,0) = 0x293;
  13438. if( md != NULL ) {
  13439. if( md->bl.prev != NULL ) { // Boss on This Map
  13440. if( flag ) {
  13441. WFIFOB(fd,2) = 1;
  13442. WFIFOL(fd,3) = md->bl.x;
  13443. WFIFOL(fd,7) = md->bl.y;
  13444. } else
  13445. WFIFOB(fd,2) = 2; // First Time
  13446. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13447. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13448. unsigned int seconds;
  13449. int hours, minutes;
  13450. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13451. hours = seconds / (60 * 60);
  13452. seconds = seconds - (60 * 60 * hours);
  13453. minutes = seconds / 60;
  13454. WFIFOB(fd,2) = 3;
  13455. WFIFOW(fd,11) = hours; // Hours
  13456. WFIFOW(fd,13) = minutes; // Minutes
  13457. }
  13458. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13459. }
  13460. WFIFOSET(fd,70);
  13461. }
  13462. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13463. /// 02d6 <account id>.L
  13464. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13465. {
  13466. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13467. struct map_session_data* tsd = map_id2sd(aid);
  13468. if (!tsd)
  13469. return;
  13470. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13471. clif_viewequip_ack(sd, tsd);
  13472. else
  13473. clif_msg(sd, VIEW_EQUIP_FAIL);
  13474. }
  13475. /// Request to change equip window tick (CZ_CONFIG).
  13476. /// 02d8 <type>.L <flag>.L
  13477. /// type:
  13478. /// 0 = open equip window
  13479. /// flag:
  13480. /// 0 = disabled
  13481. /// 1 = enabled
  13482. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13483. {
  13484. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13485. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13486. sd->status.show_equip = flag;
  13487. clif_equiptickack(sd, flag);
  13488. }
  13489. /// Request to change party invitation tick.
  13490. /// value:
  13491. /// 0 = disabled
  13492. /// 1 = enabled
  13493. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13494. {
  13495. bool flag = RFIFOB(fd,6) ? true : false;
  13496. sd->status.allow_party = flag;
  13497. clif_partytickack(sd, flag);
  13498. }
  13499. /// Questlog System [Kevin] [Inkfish]
  13500. ///
  13501. /**
  13502. * Safe check to init packet len & quest num for player.
  13503. * @param def_len
  13504. * @param info_len Length of each quest info.
  13505. * @param avail_quests Avail quests that player has.
  13506. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13507. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13508. **/
  13509. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13510. (*limit_out) = (0xFFFF - def_len) / info_len;
  13511. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13512. (*len_out) = ((*limit_out) * info_len) + def_len;
  13513. }
  13514. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13515. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13516. /// 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)
  13517. /// 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!
  13518. void clif_quest_send_list(struct map_session_data *sd)
  13519. {
  13520. int fd = sd->fd;
  13521. int i;
  13522. int offset = 8;
  13523. int limit = 0;
  13524. #if PACKETVER >= 20141022
  13525. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13526. WFIFOHEAD(fd,i);
  13527. WFIFOW(fd, 0) = 0x97a;
  13528. WFIFOL(fd, 4) = limit;
  13529. for (i = 0; i < limit; i++) {
  13530. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13531. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13532. offset += 4;
  13533. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13534. offset++;
  13535. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13536. offset += 4;
  13537. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13538. offset += 4;
  13539. WFIFOW(fd, offset) = qi->objectives_count;
  13540. offset += 2;
  13541. if( qi->objectives_count > 0 ){
  13542. int j;
  13543. struct mob_db *mob;
  13544. for( j = 0; j < qi->objectives_count; j++ ){
  13545. mob = mob_db(qi->objectives[j].mob);
  13546. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13547. offset += 4;
  13548. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13549. offset += 2;
  13550. WFIFOW(fd, offset) = qi->objectives[j].count;
  13551. offset += 2;
  13552. safestrncpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13553. offset += NAME_LENGTH;
  13554. }
  13555. }
  13556. }
  13557. WFIFOW(fd, 2) = offset;
  13558. WFIFOSET(fd, offset);
  13559. #else
  13560. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13561. WFIFOHEAD(fd,i);
  13562. WFIFOW(fd, 0) = 0x2b1;
  13563. WFIFOL(fd, 4) = limit;
  13564. for (i = 0; i < limit; i++) {
  13565. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13566. offset += 4;
  13567. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13568. offset += 1;
  13569. }
  13570. WFIFOW(fd, 2) = offset;
  13571. WFIFOSET(fd, offset);
  13572. #endif
  13573. }
  13574. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13575. /// 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
  13576. void clif_quest_send_mission(struct map_session_data *sd)
  13577. {
  13578. int fd = sd->fd;
  13579. int i, j, limit = 0;
  13580. int len = sd->avail_quests*104+8;
  13581. struct mob_db *mob;
  13582. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13583. WFIFOHEAD(fd, len);
  13584. WFIFOW(fd, 0) = 0x2b2;
  13585. WFIFOW(fd, 2) = len;
  13586. WFIFOL(fd, 4) = limit;
  13587. for (i = 0; i < limit; i++) {
  13588. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13589. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13590. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13591. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13592. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13593. for (j = 0 ; j < qi->objectives_count; j++) {
  13594. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13595. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13596. mob = mob_db(qi->objectives[j].mob);
  13597. safestrncpy((char*)WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13598. }
  13599. }
  13600. WFIFOSET(fd, len);
  13601. }
  13602. /// Notification about a new quest (ZC_ADD_QUEST).
  13603. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13604. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13605. {
  13606. int fd = sd->fd;
  13607. int i;
  13608. struct quest_db *qi = quest_search(qd->quest_id);
  13609. WFIFOHEAD(fd, packet_len(0x2b3));
  13610. WFIFOW(fd, 0) = 0x2b3;
  13611. WFIFOL(fd, 2) = qd->quest_id;
  13612. WFIFOB(fd, 6) = qd->state;
  13613. WFIFOB(fd, 7) = qd->time - qi->time;
  13614. WFIFOL(fd, 11) = qd->time;
  13615. WFIFOW(fd, 15) = qi->objectives_count;
  13616. for (i = 0; i < qi->objectives_count; i++) {
  13617. struct mob_db *mob;
  13618. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13619. WFIFOW(fd, i*30+21) = qd->count[i];
  13620. mob = mob_db(qi->objectives[i].mob);
  13621. safestrncpy((char*)WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13622. }
  13623. WFIFOSET(fd, packet_len(0x2b3));
  13624. }
  13625. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13626. /// 02b4 <quest id>.L
  13627. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13628. {
  13629. int fd = sd->fd;
  13630. WFIFOHEAD(fd, packet_len(0x2b4));
  13631. WFIFOW(fd, 0) = 0x2b4;
  13632. WFIFOL(fd, 2) = quest_id;
  13633. WFIFOSET(fd, packet_len(0x2b4));
  13634. }
  13635. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13636. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13637. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  13638. {
  13639. int fd = sd->fd;
  13640. int i;
  13641. struct quest_db *qi = quest_search(qd->quest_id);
  13642. int len = qi->objectives_count * 12 + 6;
  13643. WFIFOHEAD(fd, len);
  13644. WFIFOW(fd, 0) = 0x2b5;
  13645. WFIFOW(fd, 2) = len;
  13646. WFIFOW(fd, 4) = qi->objectives_count;
  13647. for (i = 0; i < qi->objectives_count; i++) {
  13648. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  13649. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  13650. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  13651. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  13652. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  13653. }
  13654. }
  13655. WFIFOSET(fd, len);
  13656. }
  13657. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13658. /// 02b6 <quest id>.L <active>.B
  13659. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13660. {
  13661. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13662. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13663. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13664. }
  13665. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13666. /// 02b7 <quest id>.L <active>.B
  13667. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13668. {
  13669. int fd = sd->fd;
  13670. WFIFOHEAD(fd, packet_len(0x2b7));
  13671. WFIFOW(fd, 0) = 0x2b7;
  13672. WFIFOL(fd, 2) = quest_id;
  13673. WFIFOB(fd, 6) = active;
  13674. WFIFOSET(fd, packet_len(0x2b7));
  13675. }
  13676. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13677. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  13678. /// effect:
  13679. /// 0 = none
  13680. /// 1 = exclamation mark icon
  13681. /// 2 = question mark icon
  13682. /// color:
  13683. /// 0 = yellow
  13684. /// 1 = orange
  13685. /// 2 = green
  13686. /// 3 = purple
  13687. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  13688. {
  13689. #if PACKETVER >= 20090218
  13690. int fd = sd->fd;
  13691. WFIFOHEAD(fd, packet_len(0x446));
  13692. WFIFOW(fd, 0) = 0x446;
  13693. WFIFOL(fd, 2) = bl->id;
  13694. WFIFOW(fd, 6) = bl->x;
  13695. WFIFOW(fd, 8) = bl->y;
  13696. WFIFOW(fd, 10) = effect;
  13697. WFIFOW(fd, 12) = color;
  13698. WFIFOSET(fd, packet_len(0x446));
  13699. #endif
  13700. }
  13701. /// Mercenary System
  13702. ///
  13703. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13704. /// 02a2 <var id>.W <value>.L
  13705. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13706. {
  13707. struct mercenary_data *md;
  13708. struct status_data *status;
  13709. int fd;
  13710. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13711. return;
  13712. fd = sd->fd;
  13713. status = &md->battle_status;
  13714. WFIFOHEAD(fd,packet_len(0x2a2));
  13715. WFIFOW(fd,0) = 0x2a2;
  13716. WFIFOW(fd,2) = type;
  13717. switch( type ) {
  13718. case SP_ATK1:
  13719. {
  13720. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13721. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13722. }
  13723. break;
  13724. case SP_MATK1:
  13725. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13726. break;
  13727. case SP_HIT:
  13728. WFIFOL(fd,4) = status->hit;
  13729. break;
  13730. case SP_CRITICAL:
  13731. WFIFOL(fd,4) = status->cri/10;
  13732. break;
  13733. case SP_DEF1:
  13734. WFIFOL(fd,4) = status->def;
  13735. break;
  13736. case SP_MDEF1:
  13737. WFIFOL(fd,4) = status->mdef;
  13738. break;
  13739. case SP_MERCFLEE:
  13740. WFIFOL(fd,4) = status->flee;
  13741. break;
  13742. case SP_ASPD:
  13743. WFIFOL(fd,4) = status->amotion;
  13744. break;
  13745. case SP_HP:
  13746. WFIFOL(fd,4) = status->hp;
  13747. break;
  13748. case SP_MAXHP:
  13749. WFIFOL(fd,4) = status->max_hp;
  13750. break;
  13751. case SP_SP:
  13752. WFIFOL(fd,4) = status->sp;
  13753. break;
  13754. case SP_MAXSP:
  13755. WFIFOL(fd,4) = status->max_sp;
  13756. break;
  13757. case SP_MERCKILLS:
  13758. WFIFOL(fd,4) = md->mercenary.kill_count;
  13759. break;
  13760. case SP_MERCFAITH:
  13761. WFIFOL(fd,4) = mercenary_get_faith(md);
  13762. break;
  13763. }
  13764. WFIFOSET(fd,packet_len(0x2a2));
  13765. }
  13766. /// Mercenary base status data (ZC_MER_INIT).
  13767. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13768. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13769. /// <calls>.L <kills>.L <atk range>.W
  13770. void clif_mercenary_info(struct map_session_data *sd)
  13771. {
  13772. int fd;
  13773. struct mercenary_data *md;
  13774. struct status_data *status;
  13775. int atk;
  13776. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13777. return;
  13778. fd = sd->fd;
  13779. status = &md->battle_status;
  13780. WFIFOHEAD(fd,packet_len(0x29b));
  13781. WFIFOW(fd,0) = 0x29b;
  13782. WFIFOL(fd,2) = md->bl.id;
  13783. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13784. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13785. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13786. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13787. WFIFOW(fd,10) = status->hit;
  13788. WFIFOW(fd,12) = status->cri/10;
  13789. WFIFOW(fd,14) = status->def;
  13790. WFIFOW(fd,16) = status->mdef;
  13791. WFIFOW(fd,18) = status->flee;
  13792. WFIFOW(fd,20) = status->amotion;
  13793. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13794. WFIFOW(fd,46) = md->db->lv;
  13795. WFIFOL(fd,48) = status->hp;
  13796. WFIFOL(fd,52) = status->max_hp;
  13797. WFIFOL(fd,56) = status->sp;
  13798. WFIFOL(fd,60) = status->max_sp;
  13799. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13800. WFIFOW(fd,68) = mercenary_get_faith(md);
  13801. WFIFOL(fd,70) = mercenary_get_calls(md);
  13802. WFIFOL(fd,74) = md->mercenary.kill_count;
  13803. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13804. WFIFOSET(fd,packet_len(0x29b));
  13805. }
  13806. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13807. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13808. void clif_mercenary_skillblock(struct map_session_data *sd)
  13809. {
  13810. struct mercenary_data *md;
  13811. int fd, i, len = 4;
  13812. if( sd == NULL || (md = sd->md) == NULL )
  13813. return;
  13814. fd = sd->fd;
  13815. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13816. WFIFOW(fd,0) = 0x29d;
  13817. for( i = 0; i < MAX_MERCSKILL; i++ )
  13818. {
  13819. uint16 id;
  13820. short idx = -1;
  13821. if( (id = md->db->skill[i].id) == 0 )
  13822. continue;
  13823. if ((idx = mercenary_skill_get_index(id)) == -1)
  13824. continue;
  13825. WFIFOW(fd,len) = id;
  13826. WFIFOL(fd,len+2) = skill_get_inf(id);
  13827. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13828. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13829. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  13830. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13831. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13832. len += 37;
  13833. }
  13834. WFIFOW(fd,2) = len;
  13835. WFIFOSET(fd,len);
  13836. }
  13837. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13838. /// 029f <command>.B
  13839. /// 1 = mercenary information
  13840. /// 2 = delete
  13841. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13842. {
  13843. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13844. if( sd->md == NULL )
  13845. return;
  13846. if( option == 2 ) mercenary_delete(sd->md, 2);
  13847. }
  13848. /// Mercenary Message
  13849. /// message:
  13850. /// 0 = Mercenary soldier's duty hour is over.
  13851. /// 1 = Your mercenary soldier has been killed.
  13852. /// 2 = Your mercenary soldier has been fired.
  13853. /// 3 = Your mercenary soldier has ran away.
  13854. void clif_mercenary_message(struct map_session_data* sd, int message){
  13855. clif_msg(sd, MERC_MSG_BASE + message);
  13856. }
  13857. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13858. /// 0298 <name id>.W <seconds>.L
  13859. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13860. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13861. WFIFOHEAD(fd,packet_len(0x298));
  13862. WFIFOW(fd,0) = 0x298;
  13863. WFIFOW(fd,2) = nameid;
  13864. WFIFOL(fd,4) = seconds;
  13865. WFIFOSET(fd,packet_len(0x298));
  13866. }
  13867. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13868. /// 0299 <index>.W <name id>.W
  13869. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13870. { // '<ItemName>' item has been deleted from the Inventory
  13871. WFIFOHEAD(fd,packet_len(0x299));
  13872. WFIFOW(fd,0) = 0x299;
  13873. WFIFOW(fd,2) = index+2;
  13874. WFIFOW(fd,4) = nameid;
  13875. WFIFOSET(fd,packet_len(0x299));
  13876. }
  13877. /// Book Reading (ZC_READ_BOOK).
  13878. /// 0294 <book id>.L <page>.L
  13879. void clif_readbook(int fd, int book_id, int page)
  13880. {
  13881. WFIFOHEAD(fd,packet_len(0x294));
  13882. WFIFOW(fd,0) = 0x294;
  13883. WFIFOL(fd,2) = book_id;
  13884. WFIFOL(fd,6) = page;
  13885. WFIFOSET(fd,packet_len(0x294));
  13886. }
  13887. /// Battlegrounds
  13888. ///
  13889. /// Updates HP bar of a camp member.
  13890. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  13891. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  13892. void clif_bg_hp(struct map_session_data *sd) {
  13893. #if PACKETVER < 20140613
  13894. unsigned char buf[34];
  13895. const int cmd = 0x2e0;
  13896. #else
  13897. unsigned char buf[14];
  13898. const int cmd = 0xa0e;
  13899. #endif
  13900. nullpo_retv(sd);
  13901. WBUFW(buf,0) = cmd;
  13902. WBUFL(buf,2) = sd->status.account_id;
  13903. #if PACKETVER < 20140613
  13904. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13905. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  13906. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13907. WBUFW(buf,32) = 100;
  13908. } else {
  13909. WBUFW(buf,30) = sd->battle_status.hp;
  13910. WBUFW(buf,32) = sd->battle_status.max_hp;
  13911. }
  13912. #else
  13913. if( sd->battle_status.max_hp > INT32_MAX ) {
  13914. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13915. WBUFL(buf,10) = 100;
  13916. } else {
  13917. WBUFL(buf,6) = sd->battle_status.hp;
  13918. WBUFL(buf,10) = sd->battle_status.max_hp;
  13919. }
  13920. #endif
  13921. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13922. }
  13923. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13924. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13925. void clif_bg_xy(struct map_session_data *sd)
  13926. {
  13927. unsigned char buf[36];
  13928. nullpo_retv(sd);
  13929. WBUFW(buf,0)=0x2df;
  13930. WBUFL(buf,2)=sd->status.account_id;
  13931. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13932. WBUFW(buf,30)=sd->status.class_;
  13933. WBUFW(buf,32)=sd->bl.x;
  13934. WBUFW(buf,34)=sd->bl.y;
  13935. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13936. }
  13937. void clif_bg_xy_remove(struct map_session_data *sd)
  13938. {
  13939. unsigned char buf[36];
  13940. nullpo_retv(sd);
  13941. WBUFW(buf,0)=0x2df;
  13942. WBUFL(buf,2)=sd->status.account_id;
  13943. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13944. WBUFW(buf,30)=0;
  13945. WBUFW(buf,32)=-1;
  13946. WBUFW(buf,34)=-1;
  13947. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13948. }
  13949. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13950. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13951. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13952. {
  13953. struct map_session_data *sd;
  13954. unsigned char *buf;
  13955. if( (sd = bg_getavailablesd(bg)) == NULL )
  13956. return;
  13957. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13958. WBUFW(buf,0) = 0x2dc;
  13959. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13960. WBUFL(buf,4) = src_id;
  13961. safestrncpy((char*)WBUFP(buf,8), name, NAME_LENGTH);
  13962. memcpy(WBUFP(buf,32), mes, len);
  13963. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13964. if( buf )
  13965. aFree(buf);
  13966. }
  13967. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13968. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13969. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13970. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  13971. if( !clif_process_message( sd, false, name, message, output ) )
  13972. return;
  13973. bg_send_message(sd, output, strlen(output) );
  13974. }
  13975. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13976. /// 02de <camp A points>.W <camp B points>.W
  13977. void clif_bg_updatescore(int16 m)
  13978. {
  13979. struct block_list bl;
  13980. unsigned char buf[6];
  13981. bl.id = 0;
  13982. bl.type = BL_NUL;
  13983. bl.m = m;
  13984. WBUFW(buf,0) = 0x2de;
  13985. WBUFW(buf,2) = map[m].bgscore_lion;
  13986. WBUFW(buf,4) = map[m].bgscore_eagle;
  13987. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13988. }
  13989. void clif_bg_updatescore_single(struct map_session_data *sd)
  13990. {
  13991. int fd;
  13992. nullpo_retv(sd);
  13993. fd = sd->fd;
  13994. WFIFOHEAD(fd,packet_len(0x2de));
  13995. WFIFOW(fd,0) = 0x2de;
  13996. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13997. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13998. WFIFOSET(fd,packet_len(0x2de));
  13999. }
  14000. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14001. /// 02dd <account id>.L <name>.24B <camp>.W
  14002. void clif_sendbgemblem_area(struct map_session_data *sd)
  14003. {
  14004. unsigned char buf[33];
  14005. nullpo_retv(sd);
  14006. WBUFW(buf, 0) = 0x2dd;
  14007. WBUFL(buf,2) = sd->bl.id;
  14008. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14009. WBUFW(buf,30) = sd->bg_id;
  14010. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14011. }
  14012. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14013. {
  14014. nullpo_retv(sd);
  14015. WFIFOHEAD(fd,32);
  14016. WFIFOW(fd,0) = 0x2dd;
  14017. WFIFOL(fd,2) = sd->bl.id;
  14018. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  14019. WFIFOW(fd,30) = sd->bg_id;
  14020. WFIFOSET(fd,packet_len(0x2dd));
  14021. }
  14022. /// Custom Fonts (ZC_NOTIFY_FONT).
  14023. /// 02ef <account_id>.L <font id>.W
  14024. void clif_font(struct map_session_data *sd)
  14025. {
  14026. #if PACKETVER >= 20080102
  14027. unsigned char buf[8];
  14028. nullpo_retv(sd);
  14029. WBUFW(buf,0) = 0x2ef;
  14030. WBUFL(buf,2) = sd->bl.id;
  14031. WBUFW(buf,6) = sd->status.font;
  14032. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14033. #endif
  14034. }
  14035. /// Required to start the instancing information window on Client
  14036. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14037. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14038. void clif_instance_create(unsigned short instance_id, int num)
  14039. {
  14040. #if PACKETVER >= 20071128
  14041. struct instance_db *db = NULL;
  14042. struct map_session_data *sd = NULL;
  14043. enum send_target target = PARTY;
  14044. unsigned char buf[65];
  14045. instance_getsd(instance_id, &sd, &target);
  14046. if (!sd)
  14047. return;
  14048. db = instance_searchtype_db(instance_data[instance_id].type);
  14049. if (!db)
  14050. return;
  14051. WBUFW(buf,0) = 0x2cb;
  14052. safestrncpy((char *)WBUFP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14053. WBUFW(buf,63) = num;
  14054. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14055. #endif
  14056. return;
  14057. }
  14058. /// To announce Instancing queue creation if no maps available
  14059. /// S 0x2cc <Standby Position>.W
  14060. void clif_instance_changewait(unsigned short instance_id, int num)
  14061. {
  14062. #if PACKETVER >= 20071128
  14063. struct map_session_data *sd = NULL;
  14064. enum send_target target = PARTY;
  14065. unsigned char buf[4];
  14066. instance_getsd(instance_id, &sd, &target);
  14067. if (!sd)
  14068. return;
  14069. WBUFW(buf,0) = 0x2cc;
  14070. WBUFW(buf,2) = num;
  14071. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14072. #endif
  14073. return;
  14074. }
  14075. /// Notify the current status to members
  14076. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14077. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14078. {
  14079. #if PACKETVER >= 20071128
  14080. struct instance_db *db = NULL;
  14081. struct map_session_data *sd = NULL;
  14082. enum send_target target = PARTY;
  14083. unsigned char buf[71];
  14084. instance_getsd(instance_id, &sd, &target);
  14085. if (!sd)
  14086. return;
  14087. db = instance_searchtype_db(instance_data[instance_id].type);
  14088. if (!db)
  14089. return;
  14090. WBUFW(buf,0) = 0x2cd;
  14091. safestrncpy((char *)WBUFP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14092. WBUFL(buf,63) = limit1;
  14093. WBUFL(buf,67) = limit2;
  14094. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14095. #endif
  14096. return;
  14097. }
  14098. /// Notify a status change to members
  14099. /// S 0x2ce <Message ID>.L
  14100. /// 0 = Notification (EnterLimitDate update?)
  14101. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14102. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14103. /// 3 = The Memorial Dungeon has been removed.
  14104. /// 4 = Create failure (removes the instance window)
  14105. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14106. {
  14107. #if PACKETVER >= 20071128
  14108. struct map_session_data *sd = NULL;
  14109. enum send_target target = PARTY;
  14110. unsigned char buf[10];
  14111. instance_getsd(instance_id, &sd, &target);
  14112. if (!sd)
  14113. return;
  14114. WBUFW(buf,0) = 0x2ce;
  14115. WBUFL(buf,2) = type;
  14116. WBUFL(buf,6) = limit;
  14117. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14118. #endif
  14119. return;
  14120. }
  14121. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14122. /// 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
  14123. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14124. {
  14125. #if PACKETVER >= 20071002
  14126. unsigned char buf[22];
  14127. struct item_data* id = itemdb_search(item_data->nameid);
  14128. WBUFW(buf,0) = 0x2b8;
  14129. WBUFL(buf,2) = sd->status.account_id;
  14130. WBUFW(buf,6) = item_data->nameid;
  14131. WBUFB(buf,8) = item_data->identify;
  14132. WBUFB(buf,9) = item_data->attribute;
  14133. WBUFB(buf,10) = item_data->refine;
  14134. clif_addcards(WBUFP(buf,11), item_data);
  14135. WBUFW(buf,19) = id->equip; // equip location
  14136. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14137. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14138. #endif
  14139. }
  14140. /** Display gained exp (ZC_NOTIFY_EXP).
  14141. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14142. * amount: INT32_MIN ~ INT32_MAX
  14143. * var id:
  14144. * SP_BASEEXP, SP_JOBEXP
  14145. * exp type:
  14146. * 0 = normal exp gained/lost
  14147. * 1 = quest exp gained/lost
  14148. * @param sd Player
  14149. * @param exp EXP value gained/loss
  14150. * @param type SP_BASEEXP, SP_JOBEXP
  14151. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14152. * @param lost True:if lossing EXP
  14153. */
  14154. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14155. {
  14156. int fd;
  14157. nullpo_retv(sd);
  14158. fd = sd->fd;
  14159. WFIFOHEAD(fd, packet_len(0x7f6));
  14160. WFIFOW(fd,0) = 0x7f6;
  14161. WFIFOL(fd,2) = sd->bl.id;
  14162. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14163. WFIFOW(fd,10) = type;
  14164. WFIFOW(fd,12) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14165. WFIFOSET(fd,packet_len(0x7f6));
  14166. }
  14167. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14168. /// type:
  14169. /// 0 = Displays 'value' for 5 seconds.
  14170. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14171. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14172. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14173. /// value:
  14174. /// 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).
  14175. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14176. {
  14177. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14178. WFIFOW(sd->fd,0) = 0x1b1;
  14179. WFIFOB(sd->fd,2) = type;
  14180. WFIFOL(sd->fd,3) = value;
  14181. WFIFOSET(sd->fd, packet_len(0x1b1));
  14182. }
  14183. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14184. /// 021d <state>.L
  14185. /// state:
  14186. /// 0 = Full effects
  14187. /// 1 = Reduced effects
  14188. ///
  14189. /// NOTE: The state is used on Aegis for sending skill unit packet
  14190. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14191. /// whenever possible. Due to the way the decision check is
  14192. /// constructed, this state tracking was rendered useless,
  14193. /// as the only skill unit, that is sent with 0x1c9 is
  14194. /// Graffiti.
  14195. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14196. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14197. sd->state.lesseffect = ( isLess != 0 );
  14198. }
  14199. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14200. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  14201. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  14202. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14203. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14204. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14205. int type = RFIFOL(fd,info->pos[1]);
  14206. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14207. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14208. if( sd->state.trading || sd->npc_shopid )
  14209. return;
  14210. if( flag == 0 || n == 0) {
  14211. clif_menuskill_clear(sd);
  14212. return; // Canceled by player.
  14213. }
  14214. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14215. clif_menuskill_clear(sd);
  14216. return; // Prevent hacking.
  14217. }
  14218. switch( type ) {
  14219. case 0: // Change Material
  14220. skill_changematerial(sd,n,item_list);
  14221. break;
  14222. case 1: // Level 1: Pure to Rough
  14223. case 2: // Level 2: Rough to Pure
  14224. skill_elementalanalysis(sd,n,type,item_list);
  14225. break;
  14226. }
  14227. clif_menuskill_clear(sd);
  14228. return;
  14229. }
  14230. /*==========================================
  14231. * Elemental System
  14232. *==========================================*/
  14233. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14234. struct elemental_data *ed;
  14235. struct status_data *status;
  14236. int fd;
  14237. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14238. return;
  14239. fd = sd->fd;
  14240. status = &ed->battle_status;
  14241. WFIFOHEAD(fd,8);
  14242. WFIFOW(fd,0) = 0x81e;
  14243. WFIFOW(fd,2) = type;
  14244. switch( type ) {
  14245. case SP_HP:
  14246. WFIFOL(fd,4) = status->hp;
  14247. break;
  14248. case SP_MAXHP:
  14249. WFIFOL(fd,4) = status->max_hp;
  14250. break;
  14251. case SP_SP:
  14252. WFIFOL(fd,4) = status->sp;
  14253. break;
  14254. case SP_MAXSP:
  14255. WFIFOL(fd,4) = status->max_sp;
  14256. break;
  14257. }
  14258. WFIFOSET(fd,8);
  14259. }
  14260. void clif_elemental_info(struct map_session_data *sd) {
  14261. int fd;
  14262. struct elemental_data *ed;
  14263. struct status_data *status;
  14264. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14265. return;
  14266. fd = sd->fd;
  14267. status = &ed->battle_status;
  14268. WFIFOHEAD(fd,22);
  14269. WFIFOW(fd, 0) = 0x81d;
  14270. WFIFOL(fd, 2) = ed->bl.id;
  14271. WFIFOL(fd, 6) = status->hp;
  14272. WFIFOL(fd,10) = status->max_hp;
  14273. WFIFOL(fd,14) = status->sp;
  14274. WFIFOL(fd,18) = status->max_sp;
  14275. WFIFOSET(fd,22);
  14276. }
  14277. /// Buying Store System
  14278. ///
  14279. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14280. /// 0810 <slots>.B
  14281. void clif_buyingstore_open(struct map_session_data* sd)
  14282. {
  14283. int fd = sd->fd;
  14284. WFIFOHEAD(fd,packet_len(0x810));
  14285. WFIFOW(fd,0) = 0x810;
  14286. WFIFOB(fd,2) = sd->buyingstore.slots;
  14287. WFIFOSET(fd,packet_len(0x810));
  14288. }
  14289. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14290. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14291. /// result:
  14292. /// 0 = cancel
  14293. /// 1 = open
  14294. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14295. {
  14296. const unsigned int blocksize = 8;
  14297. uint8* itemlist;
  14298. char storename[MESSAGE_SIZE];
  14299. unsigned char result;
  14300. int zenylimit;
  14301. unsigned int count, packet_len;
  14302. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14303. packet_len = RFIFOW(fd,info->pos[0]);
  14304. // TODO: Make this check global for all variable length packets.
  14305. if( packet_len < 89 )
  14306. {// minimum packet length
  14307. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14308. return;
  14309. }
  14310. zenylimit = RFIFOL(fd,info->pos[1]);
  14311. result = RFIFOL(fd,info->pos[2]);
  14312. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  14313. itemlist = RFIFOP(fd,info->pos[4]);
  14314. // so that buyingstore_create knows, how many elements it has access to
  14315. packet_len-= info->pos[4];
  14316. if( packet_len%blocksize )
  14317. {
  14318. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14319. return;
  14320. }
  14321. count = packet_len/blocksize;
  14322. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14323. }
  14324. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14325. /// 0812 <result>.W <total weight>.L
  14326. /// result:
  14327. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14328. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14329. /// 8 = "No sale (purchase) information available." (0x705)
  14330. /// ? = nothing
  14331. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14332. {
  14333. int fd = sd->fd;
  14334. WFIFOHEAD(fd,packet_len(0x812));
  14335. WFIFOW(fd,0) = 0x812;
  14336. WFIFOW(fd,2) = result;
  14337. WFIFOL(fd,4) = weight;
  14338. WFIFOSET(fd,packet_len(0x812));
  14339. }
  14340. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14341. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14342. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14343. {
  14344. int fd = sd->fd;
  14345. unsigned int i;
  14346. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14347. WFIFOW(fd,0) = 0x813;
  14348. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14349. WFIFOL(fd,4) = sd->bl.id;
  14350. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14351. for( i = 0; i < sd->buyingstore.slots; i++ )
  14352. {
  14353. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14354. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14355. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14356. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14357. }
  14358. WFIFOSET(fd,WFIFOW(fd,2));
  14359. }
  14360. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14361. /// 0814 <account id>.L <store name>.80B
  14362. void clif_buyingstore_entry(struct map_session_data* sd)
  14363. {
  14364. uint8 buf[86];
  14365. WBUFW(buf,0) = 0x814;
  14366. WBUFL(buf,2) = sd->bl.id;
  14367. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14368. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14369. }
  14370. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14371. {
  14372. int fd = sd->fd;
  14373. WFIFOHEAD(fd,packet_len(0x814));
  14374. WFIFOW(fd,0) = 0x814;
  14375. WFIFOL(fd,2) = pl_sd->bl.id;
  14376. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14377. WFIFOSET(fd,packet_len(0x814));
  14378. }
  14379. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14380. /// 0815
  14381. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14382. {
  14383. buyingstore_close(sd);
  14384. }
  14385. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14386. /// 0816 <account id>.L
  14387. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14388. {
  14389. uint8 buf[6];
  14390. WBUFW(buf,0) = 0x816;
  14391. WBUFL(buf,2) = sd->bl.id;
  14392. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14393. }
  14394. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14395. {
  14396. int fd = sd->fd;
  14397. WFIFOHEAD(fd,packet_len(0x816));
  14398. WFIFOW(fd,0) = 0x816;
  14399. WFIFOL(fd,2) = pl_sd->bl.id;
  14400. WFIFOSET(fd,packet_len(0x816));
  14401. }
  14402. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14403. /// 0817 <account id>.L
  14404. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14405. {
  14406. uint32 account_id;
  14407. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14408. buyingstore_open(sd, account_id);
  14409. }
  14410. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14411. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14412. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14413. {
  14414. int fd = sd->fd;
  14415. unsigned int i;
  14416. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14417. WFIFOW(fd,0) = 0x818;
  14418. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14419. WFIFOL(fd,4) = pl_sd->bl.id;
  14420. WFIFOL(fd,8) = pl_sd->buyer_id;
  14421. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14422. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14423. {
  14424. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14425. 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.
  14426. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14427. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14428. }
  14429. WFIFOSET(fd,WFIFOW(fd,2));
  14430. }
  14431. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14432. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14433. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14434. {
  14435. const unsigned int blocksize = 6;
  14436. uint8* itemlist;
  14437. uint32 account_id;
  14438. unsigned int count, packet_len, buyer_id;
  14439. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14440. packet_len = RFIFOW(fd,info->pos[0]);
  14441. if( packet_len < 12 )
  14442. {// minimum packet length
  14443. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14444. return;
  14445. }
  14446. account_id = RFIFOL(fd,info->pos[1]);
  14447. buyer_id = RFIFOL(fd,info->pos[2]);
  14448. itemlist = RFIFOP(fd,info->pos[3]);
  14449. // so that buyingstore_trade knows, how many elements it has access to
  14450. packet_len-= info->pos[3];
  14451. if( packet_len%blocksize )
  14452. {
  14453. 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);
  14454. return;
  14455. }
  14456. count = packet_len/blocksize;
  14457. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14458. }
  14459. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14460. /// 081a <result>.W
  14461. /// result:
  14462. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14463. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14464. /// ? = nothing
  14465. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14466. {
  14467. int fd = sd->fd;
  14468. WFIFOHEAD(fd,packet_len(0x81a));
  14469. WFIFOW(fd,0) = 0x81a;
  14470. WFIFOW(fd,2) = result;
  14471. WFIFOSET(fd,packet_len(0x81a));
  14472. }
  14473. /// Updates the zeny limit and an item in the buying store item list.
  14474. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  14475. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  14476. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  14477. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  14478. const int cmd = 0x81b;
  14479. #else
  14480. const int cmd = 0x9e6;
  14481. #endif
  14482. int offset = 0;
  14483. int fd = sd->fd;
  14484. WFIFOHEAD(fd,packet_len(cmd));
  14485. WFIFOW(fd,0) = cmd;
  14486. WFIFOW(fd,2) = nameid;
  14487. WFIFOW(fd,4) = amount; // amount of nameid received
  14488. #if PACKETVER >= 20141016
  14489. WFIFOL(fd,6) = zeny; // zeny
  14490. offset += 4;
  14491. #endif
  14492. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  14493. #if PACKETVER >= 20141016
  14494. WFIFOL(fd,10+offset) = char_id; // GID
  14495. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  14496. #endif
  14497. WFIFOSET(fd,packet_len(cmd));
  14498. }
  14499. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14500. /// 081c <index>.W <amount>.W <price>.L
  14501. /// message:
  14502. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14503. ///
  14504. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14505. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14506. {
  14507. int fd = sd->fd;
  14508. WFIFOHEAD(fd,packet_len(0x81c));
  14509. WFIFOW(fd,0) = 0x81c;
  14510. WFIFOW(fd,2) = index+2;
  14511. WFIFOW(fd,4) = amount;
  14512. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14513. WFIFOSET(fd,packet_len(0x81c));
  14514. }
  14515. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14516. /// 0824 <result>.W <name id>.W
  14517. /// result:
  14518. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14519. /// 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)
  14520. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14521. /// ? = nothing
  14522. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14523. {
  14524. int fd = sd->fd;
  14525. WFIFOHEAD(fd,packet_len(0x824));
  14526. WFIFOW(fd,0) = 0x824;
  14527. WFIFOW(fd,2) = result;
  14528. WFIFOW(fd,4) = nameid;
  14529. WFIFOSET(fd,packet_len(0x824));
  14530. }
  14531. /// Search Store Info System
  14532. ///
  14533. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14534. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14535. /// type:
  14536. /// 0 = Vending
  14537. /// 1 = Buying Store
  14538. ///
  14539. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14540. /// amount of card slots. If the client does not know about the item it
  14541. /// cannot be searched.
  14542. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14543. {
  14544. const unsigned int blocksize = 2;
  14545. const uint8* itemlist;
  14546. const uint8* cardlist;
  14547. unsigned char type;
  14548. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14549. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14550. packet_len = RFIFOW(fd,info->pos[0]);
  14551. if( packet_len < 15 )
  14552. {// minimum packet length
  14553. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14554. return;
  14555. }
  14556. type = RFIFOB(fd,info->pos[1]);
  14557. max_price = RFIFOL(fd,info->pos[2]);
  14558. min_price = RFIFOL(fd,info->pos[3]);
  14559. item_count = RFIFOB(fd,info->pos[4]);
  14560. card_count = RFIFOB(fd,info->pos[5]);
  14561. itemlist = RFIFOP(fd,info->pos[6]);
  14562. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14563. // check, if there is enough data for the claimed count of items
  14564. packet_len-= info->pos[6];
  14565. if( packet_len%blocksize )
  14566. {
  14567. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14568. return;
  14569. }
  14570. count = packet_len/blocksize;
  14571. if( count < item_count+card_count )
  14572. {
  14573. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14574. return;
  14575. }
  14576. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14577. }
  14578. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14579. /// 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 }*
  14580. /// is first page:
  14581. /// 0 = appends to existing results
  14582. /// 1 = clears previous results before displaying this result set
  14583. /// is next page:
  14584. /// 0 = no "next" label
  14585. /// 1 = "next" label to retrieve more results
  14586. void clif_search_store_info_ack(struct map_session_data* sd)
  14587. {
  14588. #if PACKETVER >= 20150226
  14589. const unsigned int blocksize = MESSAGE_SIZE+26+5*MAX_ITEM_RDM_OPT;
  14590. #else
  14591. const unsigned int blocksize = MESSAGE_SIZE+26;
  14592. #endif
  14593. int fd = sd->fd;
  14594. unsigned int i, start, end;
  14595. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14596. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14597. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14598. WFIFOW(fd,0) = 0x836;
  14599. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14600. WFIFOB(fd,4) = !sd->searchstore.pages;
  14601. WFIFOB(fd,5) = searchstore_querynext(sd);
  14602. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14603. for( i = start; i < end; i++ ) {
  14604. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14605. struct item it;
  14606. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14607. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14608. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14609. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14610. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14611. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14612. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14613. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14614. // make-up an item for clif_addcards
  14615. memset(&it, 0, sizeof(it));
  14616. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14617. it.nameid = ssitem->nameid;
  14618. it.amount = ssitem->amount;
  14619. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14620. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  14621. }
  14622. WFIFOSET(fd,WFIFOW(fd,2));
  14623. }
  14624. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14625. /// 0837 <reason>.B
  14626. /// reason:
  14627. /// 0 = "No matching stores were found." (0x70b)
  14628. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14629. /// 2 = "You cannot search anymore." (0x706)
  14630. /// 3 = "You cannot search yet." (0x708)
  14631. /// 4 = "No sale (purchase) information available." (0x705)
  14632. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14633. {
  14634. int fd = sd->fd;
  14635. WFIFOHEAD(fd,packet_len(0x837));
  14636. WFIFOW(fd,0) = 0x837;
  14637. WFIFOB(fd,2) = reason;
  14638. WFIFOSET(fd,packet_len(0x837));
  14639. }
  14640. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14641. /// 0838
  14642. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14643. {
  14644. searchstore_next(sd);
  14645. }
  14646. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14647. /// 083a <type>.W <remaining uses>.B
  14648. /// type:
  14649. /// 0 = Search Stores
  14650. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14651. void clif_open_search_store_info(struct map_session_data* sd)
  14652. {
  14653. int fd = sd->fd;
  14654. WFIFOHEAD(fd,packet_len(0x83a));
  14655. WFIFOW(fd,0) = 0x83a;
  14656. WFIFOW(fd,2) = sd->searchstore.effect;
  14657. #if PACKETVER > 20100701
  14658. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14659. #endif
  14660. WFIFOSET(fd,packet_len(0x83a));
  14661. }
  14662. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14663. /// 083b
  14664. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14665. {
  14666. searchstore_close(sd);
  14667. }
  14668. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14669. /// 083c <account id>.L <store id>.L <nameid>.W
  14670. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14671. {
  14672. unsigned short nameid;
  14673. uint32 account_id, store_id;
  14674. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14675. account_id = RFIFOL(fd,info->pos[0]);
  14676. store_id = RFIFOL(fd,info->pos[1]);
  14677. nameid = RFIFOW(fd,info->pos[2]);
  14678. searchstore_click(sd, account_id, store_id, nameid);
  14679. }
  14680. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14681. /// 083d <xPos>.W <yPos>.W
  14682. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14683. {
  14684. int fd = sd->fd;
  14685. WFIFOHEAD(fd,packet_len(0x83d));
  14686. WFIFOW(fd,0) = 0x83d;
  14687. WFIFOW(fd,2) = x;
  14688. WFIFOW(fd,4) = y;
  14689. WFIFOSET(fd,packet_len(0x83d));
  14690. }
  14691. /// Parse function for packet debugging.
  14692. void clif_parse_debug(int fd,struct map_session_data *sd)
  14693. {
  14694. int cmd, packet_len;
  14695. // clif_parse ensures, that there is at least 2 bytes of data
  14696. cmd = RFIFOW(fd,0);
  14697. if( sd ) {
  14698. packet_len = packet_db[sd->packet_ver][cmd].len;
  14699. if( packet_len == 0 )
  14700. {// unknown
  14701. packet_len = RFIFOREST(fd);
  14702. }
  14703. else if( packet_len == -1 )
  14704. {// variable length
  14705. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14706. }
  14707. 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);
  14708. }
  14709. else
  14710. {
  14711. packet_len = RFIFOREST(fd);
  14712. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14713. }
  14714. ShowDump(RFIFOP(fd,0), packet_len);
  14715. }
  14716. /*==========================================
  14717. * Server tells client to display a window similar to Magnifier (item) one
  14718. * Server populates the window with avilable elemental converter options according to player's inventory
  14719. *------------------------------------------*/
  14720. int clif_elementalconverter_list(struct map_session_data *sd) {
  14721. int i,c,view,fd;
  14722. nullpo_ret(sd);
  14723. /// Main client packet processing function
  14724. fd=sd->fd;
  14725. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14726. WFIFOW(fd, 0)=0x1ad;
  14727. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14728. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14729. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14730. WFIFOW(fd,c*2+ 4)= view;
  14731. else
  14732. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14733. c++;
  14734. }
  14735. }
  14736. WFIFOW(fd,2) = c*2+4;
  14737. WFIFOSET(fd, WFIFOW(fd,2));
  14738. if (c > 0) {
  14739. sd->menuskill_id = SA_CREATECON;
  14740. sd->menuskill_val = c;
  14741. }
  14742. return 0;
  14743. }
  14744. /**
  14745. * Rune Knight
  14746. **/
  14747. void clif_millenniumshield(struct block_list *bl, short shields) {
  14748. #if PACKETVER >= 20081217
  14749. unsigned char buf[10];
  14750. WBUFW(buf,0) = 0x440;
  14751. WBUFL(buf,2) = bl->id;
  14752. WBUFW(buf,6) = shields;
  14753. WBUFW(buf,8) = 0;
  14754. clif_send(buf,packet_len(0x440),bl,AREA);
  14755. #endif
  14756. }
  14757. /**
  14758. * Warlock
  14759. **/
  14760. /*==========================================
  14761. * Spellbook list [LimitLine/3CeAM]
  14762. *------------------------------------------*/
  14763. int clif_spellbook_list(struct map_session_data *sd)
  14764. {
  14765. int i, c;
  14766. int fd;
  14767. nullpo_ret(sd);
  14768. fd = sd->fd;
  14769. WFIFOHEAD(fd, 8 * 8 + 8);
  14770. WFIFOW(fd,0) = 0x1ad;
  14771. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14772. {
  14773. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14774. {
  14775. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14776. c++;
  14777. }
  14778. }
  14779. if( c > 0 )
  14780. {
  14781. WFIFOW(fd,2) = c * 2 + 4;
  14782. WFIFOSET(fd, WFIFOW(fd, 2));
  14783. sd->menuskill_id = WL_READING_SB;
  14784. sd->menuskill_val = c;
  14785. }
  14786. else{
  14787. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14788. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14789. }
  14790. return 1;
  14791. }
  14792. /**
  14793. * Mechanic
  14794. **/
  14795. /*==========================================
  14796. * Magic Decoy Material List
  14797. *------------------------------------------*/
  14798. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14799. int i, c;
  14800. int fd;
  14801. nullpo_ret(sd);
  14802. fd = sd->fd;
  14803. WFIFOHEAD(fd, 8 * 8 + 8);
  14804. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14805. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14806. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14807. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14808. c ++;
  14809. }
  14810. }
  14811. if( c > 0 ) {
  14812. sd->menuskill_id = NC_MAGICDECOY;
  14813. sd->menuskill_val = skill_lv;
  14814. sd->sc.comet_x = x;
  14815. sd->sc.comet_y = y;
  14816. WFIFOW(fd,2) = c * 2 + 4;
  14817. WFIFOSET(fd, WFIFOW(fd, 2));
  14818. } else {
  14819. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14820. return 0;
  14821. }
  14822. return 1;
  14823. }
  14824. /*==========================================
  14825. * Guillotine Cross Poisons List
  14826. *------------------------------------------*/
  14827. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14828. int i, c;
  14829. int fd;
  14830. nullpo_ret(sd);
  14831. fd = sd->fd;
  14832. WFIFOHEAD(fd, 8 * 8 + 8);
  14833. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14834. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14835. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14836. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14837. c ++;
  14838. }
  14839. }
  14840. if( c > 0 ) {
  14841. sd->menuskill_id = GC_POISONINGWEAPON;
  14842. sd->menuskill_val = skill_lv;
  14843. WFIFOW(fd,2) = c * 2 + 4;
  14844. WFIFOSET(fd, WFIFOW(fd, 2));
  14845. } else {
  14846. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14847. return 0;
  14848. }
  14849. return 1;
  14850. }
  14851. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  14852. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14853. int fd, i, c;
  14854. nullpo_ret(sd);
  14855. fd = sd->fd;
  14856. if( !fd )
  14857. return 0;
  14858. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14859. return 0;
  14860. WFIFOHEAD(fd, 2 * 6 + 4);
  14861. WFIFOW(fd,0) = 0x442;
  14862. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14863. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14864. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14865. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14866. {
  14867. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14868. c++;
  14869. }
  14870. if( c > 0 ) {
  14871. WFIFOW(fd,2) = 8 + c * 2;
  14872. WFIFOL(fd,4) = c;
  14873. WFIFOSET(fd,WFIFOW(fd,2));
  14874. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14875. sd->menuskill_val = c;
  14876. } else {
  14877. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14878. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14879. }
  14880. return 1;
  14881. }
  14882. /*===========================================
  14883. * Skill list for Four Elemental Analysis
  14884. * and Change Material skills.
  14885. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  14886. *------------------------------------------*/
  14887. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  14888. #if PACKETVER >= 20090922
  14889. int fd = sd->fd;
  14890. nullpo_ret(sd);
  14891. sd->menuskill_id = skill_id; // To prevent hacking.
  14892. sd->menuskill_val = skill_lv;
  14893. if( skill_id == GN_CHANGEMATERIAL )
  14894. skill_lv = 0; // Changematerial
  14895. WFIFOHEAD(fd, packet_len(0x7e3));
  14896. WFIFOW(fd,0) = 0x7e3;
  14897. WFIFOL(fd,2) = skill_lv;
  14898. WFIFOL(fd,4) = 0;
  14899. WFIFOSET(fd, packet_len(0x7e3));
  14900. #endif
  14901. return 1;
  14902. }
  14903. /*==========================================
  14904. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14905. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14906. * RFIFOL(fd,2) - type (currently not used)
  14907. *------------------------------------------*/
  14908. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14909. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14910. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14911. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14912. return;
  14913. if( pc_istrading(sd) ) {
  14914. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14915. clif_menuskill_clear(sd);
  14916. return;
  14917. }
  14918. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14919. clif_menuskill_clear(sd);
  14920. }
  14921. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  14922. /// 08cf <id>.L <type>.W <num>.W
  14923. void clif_spiritcharm(struct map_session_data *sd) {
  14924. unsigned char buf[10];
  14925. nullpo_retv(sd);
  14926. WBUFW(buf,0) = 0x08cf;
  14927. WBUFL(buf,2) = sd->bl.id;
  14928. WBUFW(buf,6) = sd->spiritcharm_type;
  14929. WBUFW(buf,8) = sd->spiritcharm;
  14930. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  14931. }
  14932. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14933. /// 0907 <index>.W
  14934. ///
  14935. /// R 0908 <index>.w <type>.b
  14936. /// type:
  14937. /// 0 = move item to personal tab
  14938. /// 1 = move item to normal tab
  14939. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14940. #if PACKETVER >= 20111122
  14941. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14942. int index = RFIFOW(fd,info->pos[0]) - 2;
  14943. int type = RFIFOB(fd, info->pos[1]);
  14944. /* can't move while dead. */
  14945. if(pc_isdead(sd)) {
  14946. return;
  14947. }
  14948. if (index < 0 || index >= MAX_INVENTORY)
  14949. return;
  14950. if ( sd->status.inventory[index].favorite && type == 1 )
  14951. sd->status.inventory[index].favorite = 0;
  14952. else if( type == 0 )
  14953. sd->status.inventory[index].favorite = 1;
  14954. else
  14955. return;/* nothing to do. */
  14956. clif_favorite_item(sd, index);
  14957. #endif
  14958. }
  14959. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14960. /// 0900 <index>.W <favorite>.B
  14961. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14962. int fd = sd->fd;
  14963. WFIFOHEAD(fd,packet_len(0x908));
  14964. WFIFOW(fd,0) = 0x908;
  14965. WFIFOW(fd,2) = index+2;
  14966. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14967. WFIFOSET(fd,packet_len(0x908));
  14968. }
  14969. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  14970. void clif_snap( struct block_list *bl, short x, short y ) {
  14971. unsigned char buf[10];
  14972. WBUFW(buf,0) = 0x8d2;
  14973. WBUFL(buf,2) = bl->id;
  14974. WBUFW(buf,6) = x;
  14975. WBUFW(buf,8) = y;
  14976. if( disguised(bl) )
  14977. {
  14978. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14979. WBUFL(buf,2) = -bl->id;
  14980. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14981. } else
  14982. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14983. }
  14984. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  14985. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14986. #if PACKETVER >= 20120404
  14987. WFIFOHEAD(fd,packet_len(0x977));
  14988. WFIFOW(fd,0) = 0x977;
  14989. WFIFOL(fd,2) = md->bl.id;
  14990. WFIFOL(fd,6) = md->status.hp;
  14991. WFIFOL(fd,10) = md->status.max_hp;
  14992. WFIFOSET(fd,packet_len(0x977));
  14993. #endif
  14994. }
  14995. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14996. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14997. return;
  14998. }
  14999. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15000. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15001. WFIFOW(sd->fd,0) = 0x2c9;
  15002. WFIFOB(sd->fd,2) = flag;
  15003. WFIFOSET(sd->fd, packet_len(0x2c9));
  15004. }
  15005. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15006. /// 0979 <world name>.24B <char name>.24B
  15007. void clif_ackworldinfo(struct map_session_data* sd) {
  15008. int fd;
  15009. nullpo_retv(sd);
  15010. fd = sd->fd;
  15011. WFIFOHEAD(fd,packet_len(0x979));
  15012. WFIFOW(fd,0)=0x979;
  15013. //AID -> world name ?
  15014. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  15015. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  15016. WFIFOSET(fd,packet_len(0x979));
  15017. }
  15018. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15019. /// 0978 <AID>.L
  15020. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15021. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15022. if(sd)
  15023. clif_ackworldinfo(sd);
  15024. }
  15025. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15026. /// 0447
  15027. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15028. //if(sd)
  15029. ;
  15030. }
  15031. /// req world info (CZ_CLIENT_VERSION)
  15032. /// 044A <version>.L
  15033. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15034. //if(sd)
  15035. ;
  15036. }
  15037. /// Ranking list
  15038. /// ranking pointlist { <name>.24B <point>.L }*10
  15039. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  15040. struct fame_list* list;
  15041. int skip = 0;
  15042. switch(rankingtype+1) { //to keep the same case as char.c
  15043. case 1: list = smith_fame_list; break;
  15044. case 2: list = chemist_fame_list; break;
  15045. case 3: list = taekwon_fame_list; break;
  15046. default: skip=1; break;
  15047. }
  15048. if(!skip) {
  15049. int i;
  15050. //Packet size limits this list to 10 elements. [Skotlex]
  15051. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  15052. if (list[i].id > 0) {
  15053. const char* name;
  15054. if (strcmp(list[i].name, "-") == 0 &&
  15055. (name = map_charid2nick(list[i].id)) != NULL)
  15056. {
  15057. safestrncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  15058. } else {
  15059. safestrncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  15060. }
  15061. } else {
  15062. safestrncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  15063. }
  15064. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  15065. }
  15066. for(;i < 10; i++) { //In case the MAX is less than 10.
  15067. safestrncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  15068. WBUFL(buf, idx+24*10 + i * 4) = 0;
  15069. }
  15070. }
  15071. }
  15072. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15073. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15074. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  15075. int mypoint = 0;
  15076. WBUFW(buf,0) = 0x97d;
  15077. WBUFW(buf,2) = rankingType;
  15078. clif_sub_ranklist(buf,4,sd,rankingType);
  15079. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15080. case MAPID_BLACKSMITH:
  15081. case MAPID_ALCHEMIST:
  15082. case MAPID_TAEKWON:
  15083. mypoint = sd->status.fame;
  15084. }
  15085. WBUFL(buf,284) = mypoint; //mypoint
  15086. clif_send(buf, 288, &sd->bl, SELF);
  15087. }
  15088. /*
  15089. * 097c <type> (CZ_REQ_RANKING)
  15090. * type
  15091. * 0: /blacksmith
  15092. * 1: /alchemist
  15093. * 2: /taekwon
  15094. * 3: /pk
  15095. * */
  15096. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15097. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  15098. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15099. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  15100. }
  15101. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15102. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15103. #if PACKETVER < 20130710
  15104. switch(rankingtype){
  15105. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  15106. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  15107. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  15108. }
  15109. #else
  15110. int fd=sd->fd;
  15111. WFIFOHEAD(fd,14);
  15112. WFIFOW(fd,0) = 0x97e;
  15113. WFIFOW(fd,2) = rankingtype;
  15114. WFIFOL(fd,4) = point;
  15115. WFIFOL(fd,8) = sd->status.fame;
  15116. WFIFOSET(fd,12);
  15117. #endif
  15118. }
  15119. /**
  15120. * Transmit personal information to player. (rates)
  15121. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15122. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15123. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15124. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15125. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15126. * FIXME!
  15127. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15128. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15129. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15130. */
  15131. #ifdef VIP_ENABLE
  15132. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15133. if (sd) {
  15134. struct s_packet_db* info;
  15135. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15136. int cmd = 0, fd, i = 0;
  15137. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15138. int details_bexp[PINFO_MAX];
  15139. int details_drop[PINFO_MAX];
  15140. int details_penalty[PINFO_MAX];
  15141. /**
  15142. * Set for EXP
  15143. */
  15144. //0:PCRoom
  15145. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15146. if (details_bexp[0] == 100 || !details_bexp[0])
  15147. details_bexp[0] = 0;
  15148. else {
  15149. if (details_bexp[0] < 100) {
  15150. details_bexp[0] = 100 - details_bexp[0];
  15151. details_bexp[0] = 0 - details_bexp[0];
  15152. }
  15153. else
  15154. details_bexp[0] = details_bexp[0] - 100;
  15155. }
  15156. //1:Premium
  15157. if (pc_isvip(sd)) {
  15158. details_bexp[1] = battle_config.vip_base_exp_increase;
  15159. if (details_bexp[1] < 0)
  15160. details_bexp[1] = 0 - details_bexp[1];
  15161. }
  15162. else
  15163. details_bexp[1] = 0;
  15164. //2:Server
  15165. details_bexp[2] = battle_config.base_exp_rate;
  15166. if (details_bexp[2] == 100)
  15167. details_bexp[2] = 0;
  15168. else {
  15169. if (details_bexp[2] < 100) {
  15170. details_bexp[2] = 100 - details_bexp[2];
  15171. details_bexp[2] = 0 - details_bexp[2];
  15172. }
  15173. else
  15174. details_bexp[2] = details_bexp[2] - 100;
  15175. }
  15176. //3:TPLUS
  15177. details_bexp[3] = 0;
  15178. /* End - EXP set*/
  15179. /**
  15180. * Set for Drop rate
  15181. */
  15182. //0:PCRoom
  15183. details_drop[0] = 0;
  15184. //1:Premium
  15185. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15186. if (pc_isvip(sd)) {
  15187. if (details_drop[1] < 0)
  15188. details_drop[1] = 0 - details_drop[1];
  15189. }
  15190. else
  15191. details_drop[1] = 0;
  15192. //2:Server
  15193. details_drop[2] = battle_config.item_rate_common;
  15194. if (details_drop[2] == 100)
  15195. details_drop[2] = 0;
  15196. else {
  15197. if (details_drop[2] < 100) {
  15198. details_drop[2] = 100 - details_drop[2];
  15199. details_drop[2] = 0 - details_drop[2];
  15200. }
  15201. else
  15202. details_drop[2] = details_drop[2] - 100;
  15203. }
  15204. //3:TPLUS
  15205. details_drop[3] = 0;
  15206. /* End - Drop set*/
  15207. /**
  15208. * Set for Penalty rate
  15209. */
  15210. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  15211. //0:PCRoom
  15212. details_penalty[0] = 0;
  15213. //1:Premium
  15214. if (pc_isvip(sd)) {
  15215. details_penalty[1] = battle_config.vip_exp_penalty_base;
  15216. if (details_penalty[1] == 100)
  15217. details_penalty[1] = 0;
  15218. else {
  15219. if (details_penalty[1] < 100) {
  15220. details_penalty[1] = 100 - details_penalty[1];
  15221. details_penalty[1] = 0 - details_penalty[1];
  15222. }
  15223. else
  15224. details_penalty[1] = details_penalty[1] - 100;
  15225. }
  15226. }
  15227. else
  15228. details_penalty[1] = 0;
  15229. //2:Server
  15230. details_penalty[2] = battle_config.death_penalty_base;
  15231. if (details_penalty[2] == 100)
  15232. details_penalty[2] = 0;
  15233. else {
  15234. if (details_penalty[2] < 100) {
  15235. details_penalty[2] = 100 - details_penalty[2];
  15236. details_penalty[2] = 0 - details_penalty[2];
  15237. }
  15238. else
  15239. details_penalty[2] = details_penalty[2] - 100;
  15240. }
  15241. //3:TPLUS
  15242. details_penalty[3] = 0;
  15243. /* End - Penalty set*/
  15244. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  15245. info = &packet_db[sd->packet_ver][cmd];
  15246. len = info->len; //this is the base len without details
  15247. if(!len) return; //version as packet disable
  15248. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15249. szdetails = 7;
  15250. factor = 1;
  15251. }
  15252. else if (cmd == 0x097b) {
  15253. tot_baseexp *= factor;
  15254. tot_drop *= factor;
  15255. tot_penalty *= factor;
  15256. }
  15257. fd = sd->fd;
  15258. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15259. WFIFOW(fd,0) = cmd;
  15260. for (i = 0; i < maxinfotype; i++) {
  15261. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15262. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15263. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15264. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15265. tot_baseexp += details_bexp[i]*factor;
  15266. tot_drop += details_penalty[i]*factor;
  15267. tot_penalty += details_drop[i]*factor;
  15268. len += szdetails;
  15269. }
  15270. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15271. if (cmd == 0x08cb) { //0x08cb version
  15272. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15273. WFIFOW(fd,info->pos[2]) = tot_drop;
  15274. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15275. }
  15276. else { //2013-08-07aRagexe uses 0x097b
  15277. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15278. WFIFOL(fd,info->pos[2]) = tot_drop;
  15279. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15280. }
  15281. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15282. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15283. WFIFOSET(fd,len);
  15284. }
  15285. }
  15286. #endif
  15287. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15288. char cmd[30];
  15289. int t_aid = RFIFOL(fd,2);
  15290. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15291. is_atcommand(fd, sd, cmd, 1);
  15292. }
  15293. /**
  15294. * Marks Crimson Marker target on mini-map to the caster
  15295. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15296. * @param fd
  15297. * @param bl Crimson Marker target
  15298. **/
  15299. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15300. struct s_packet_db* info;
  15301. int cmd = 0;
  15302. int16 len;
  15303. unsigned char buf[11];
  15304. nullpo_retv(sd);
  15305. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  15306. if (!cmd)
  15307. cmd = 0x09C1; //default
  15308. info = &packet_db[sd->packet_ver][cmd];
  15309. if (!(len = info->len))
  15310. return;
  15311. WBUFW(buf, 0) = cmd;
  15312. WBUFL(buf, info->pos[0]) = bl->id;
  15313. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15314. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15315. clif_send(buf, len, &sd->bl, SELF);
  15316. }
  15317. /**
  15318. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15319. **/
  15320. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15321. struct s_packet_db *info = NULL;
  15322. int cmd = 0;
  15323. nullpo_retv(sd);
  15324. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  15325. info = &packet_db[sd->packet_ver][cmd];
  15326. if (!cmd || !info->len)
  15327. return;
  15328. WFIFOHEAD(sd->fd, info->len);
  15329. WFIFOW(sd->fd, 0) = cmd;
  15330. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15331. WFIFOSET(sd->fd, info->len);
  15332. }
  15333. /**
  15334. * [Ind/Hercules]
  15335. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  15336. **/
  15337. void clif_showscript(struct block_list* bl, const char* message) {
  15338. char buf[256];
  15339. size_t len;
  15340. nullpo_retv(bl);
  15341. if(!message)
  15342. return;
  15343. len = strlen(message)+1;
  15344. if( len > sizeof(buf)-8 ) {
  15345. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15346. len = sizeof(buf)-8;
  15347. }
  15348. WBUFW(buf,0) = 0x8b3;
  15349. WBUFW(buf,2) = (uint16)(len+8);
  15350. WBUFL(buf,4) = bl->id;
  15351. safestrncpy((char *) WBUFP(buf,8), message, len);
  15352. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, AREA);
  15353. }
  15354. /**
  15355. * [Ind/Hercules]
  15356. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  15357. **/
  15358. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15359. unsigned char buf[10];
  15360. nullpo_retv(sd);
  15361. WBUFW(buf,0) = 0x7fc;
  15362. WBUFL(buf,2) = prev_leader_aid;
  15363. WBUFL(buf,6) = new_leader_aid;
  15364. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  15365. }
  15366. /**
  15367. * Decrypt packet identifier for player
  15368. * @param fd
  15369. * @param sd
  15370. * @param packet_ver
  15371. * Orig author [Ind/Hercules]
  15372. **/
  15373. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15374. #ifndef PACKET_OBFUSCATION
  15375. return RFIFOW(fd, 0);
  15376. #else
  15377. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15378. if (sd)
  15379. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15380. else
  15381. 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.
  15382. return cmd; // Return the decrypted packet ID.
  15383. #endif
  15384. }
  15385. #ifdef DUMP_UNKNOWN_PACKET
  15386. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15387. {
  15388. const char* packet_txt = "save/packet.txt";
  15389. FILE* fp;
  15390. time_t time_server;
  15391. struct tm *datetime;
  15392. char datestr[512];
  15393. time(&time_server); // get time in seconds since 1/1/1970
  15394. datetime = localtime(&time_server); // convert seconds in structure
  15395. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15396. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15397. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15398. if( sd ) {
  15399. 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);
  15400. } else {
  15401. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15402. }
  15403. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15404. fprintf(fp, "\n");
  15405. fclose(fp);
  15406. } else {
  15407. ShowError("Failed to write '%s'.\n", packet_txt);
  15408. // Dump on console instead
  15409. if( sd ) {
  15410. 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);
  15411. } else {
  15412. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15413. }
  15414. ShowDump(RFIFOP(fd,0), packet_len);
  15415. }
  15416. }
  15417. #endif
  15418. /// Roulette System
  15419. /// Author: Yommy
  15420. /**
  15421. * Opens Roulette window
  15422. * @param fd
  15423. * @param sd
  15424. */
  15425. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15426. {
  15427. nullpo_retv(sd);
  15428. if (!battle_config.feature_roulette) {
  15429. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15430. return;
  15431. }
  15432. WFIFOHEAD(fd,packet_len(0xa1a));
  15433. WFIFOW(fd,0) = 0xa1a;
  15434. WFIFOB(fd,2) = 0; // result
  15435. WFIFOL(fd,3) = 0; // serial
  15436. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15437. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15438. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15439. WFIFOL(fd,11) = sd->roulette_point.gold;
  15440. WFIFOL(fd,15) = sd->roulette_point.silver;
  15441. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15442. WFIFOSET(fd,packet_len(0xa1a));
  15443. }
  15444. /**
  15445. * Generates information to be displayed
  15446. * @param fd
  15447. * @param sd
  15448. */
  15449. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15450. {
  15451. unsigned short i, j, count = 0;
  15452. int len = 8 + (42 * 8);
  15453. nullpo_retv(sd);
  15454. if (!battle_config.feature_roulette) {
  15455. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15456. return;
  15457. }
  15458. WFIFOHEAD(fd,len);
  15459. WFIFOW(fd,0) = 0xa1c;
  15460. WFIFOW(fd,2) = len;
  15461. WFIFOL(fd,4) = 1; // serial
  15462. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15463. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15464. WFIFOW(fd,8 * count + 8) = i;
  15465. WFIFOW(fd,8 * count + 10) = j;
  15466. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15467. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15468. count++;
  15469. }
  15470. }
  15471. WFIFOSET(fd,len);
  15472. return;
  15473. }
  15474. /**
  15475. * Closes Roulette window
  15476. * @param fd
  15477. * @param sd
  15478. */
  15479. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15480. {
  15481. nullpo_retv(sd);
  15482. if (!battle_config.feature_roulette) {
  15483. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15484. return;
  15485. }
  15486. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15487. return;
  15488. }
  15489. /**
  15490. *
  15491. **/
  15492. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15493. #if PACKETVER >= 20141016
  15494. uint16 cmd = 0xa22;
  15495. unsigned char buf[5];
  15496. nullpo_retv(sd);
  15497. if (packet_db[sd->packet_ver][cmd].len == 0)
  15498. return;
  15499. WBUFW(buf,0) = cmd;
  15500. WBUFB(buf,2) = type;
  15501. WBUFW(buf,3) = 0; //! TODO: Additional item
  15502. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15503. #endif
  15504. }
  15505. /**
  15506. * Claim roulette reward
  15507. * @param sd Player
  15508. * @return 0:Success
  15509. **/
  15510. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15511. struct item it;
  15512. uint8 res = 1;
  15513. nullpo_retr(1, sd);
  15514. if (sd->roulette.prizeIdx < 0)
  15515. return RECV_ITEM_FAILED;
  15516. memset(&it, 0, sizeof(it));
  15517. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15518. it.identify = 1;
  15519. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15520. ; // onSuccess
  15521. }
  15522. sd->roulette.claimPrize = false;
  15523. sd->roulette.prizeStage = 0;
  15524. sd->roulette.prizeIdx = -1;
  15525. sd->roulette.stage = 0;
  15526. return res;
  15527. }
  15528. /**
  15529. * Process the stage and attempt to give a prize
  15530. * @param fd
  15531. * @param sd
  15532. */
  15533. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15534. {
  15535. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15536. short stage = sd->roulette.stage;
  15537. nullpo_retv(sd);
  15538. if (!battle_config.feature_roulette) {
  15539. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15540. return;
  15541. }
  15542. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15543. stage = sd->roulette.stage = 0;
  15544. if (!stage) {
  15545. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15546. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15547. }
  15548. if (result == GENERATE_ROULETTE_SUCCESS) {
  15549. if (!stage) {
  15550. if (sd->roulette_point.bronze > 0) {
  15551. sd->roulette_point.bronze -= 1;
  15552. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15553. } else if (sd->roulette_point.silver > 9) {
  15554. sd->roulette_point.silver -= 10;
  15555. stage = sd->roulette.stage = 2;
  15556. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15557. } else if (sd->roulette_point.gold > 9) {
  15558. sd->roulette_point.gold -= 10;
  15559. stage = sd->roulette.stage = 4;
  15560. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15561. }
  15562. }
  15563. sd->roulette.prizeStage = stage;
  15564. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15565. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15566. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15567. clif_roulette_getitem(sd);
  15568. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15569. return;
  15570. }
  15571. else {
  15572. sd->roulette.claimPrize = true;
  15573. sd->roulette.stage++;
  15574. }
  15575. }
  15576. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15577. }
  15578. /**
  15579. * Request to cash in prize
  15580. * @param fd
  15581. * @param sd
  15582. */
  15583. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15584. {
  15585. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15586. nullpo_retv(sd);
  15587. if (!battle_config.feature_roulette) {
  15588. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15589. return;
  15590. }
  15591. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15592. switch (clif_roulette_getitem(sd)) {
  15593. case 0:
  15594. type = RECV_ITEM_SUCCESS;
  15595. break;
  15596. case 1:
  15597. case 4:
  15598. case 5:
  15599. type = RECV_ITEM_OVERCOUNT;
  15600. break;
  15601. case 2:
  15602. type = RECV_ITEM_OVERWEIGHT;
  15603. break;
  15604. case 7:
  15605. default:
  15606. type = RECV_ITEM_FAILED;
  15607. break;
  15608. }
  15609. }
  15610. clif_roulette_recvitem_ack(sd,type);
  15611. return;
  15612. }
  15613. /**
  15614. * Update Roulette window with current stats
  15615. * @param sd
  15616. * @param result
  15617. * @param stage
  15618. * @param prizeIdx
  15619. * @param bonusItemID
  15620. */
  15621. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15622. {
  15623. int fd = sd->fd;
  15624. nullpo_retv(sd);
  15625. WFIFOHEAD(fd,packet_len(0xa20));
  15626. WFIFOW(fd,0) = 0xa20;
  15627. WFIFOB(fd,2) = result;
  15628. WFIFOW(fd,3) = stage;
  15629. WFIFOW(fd,5) = prizeIdx;
  15630. WFIFOW(fd,7) = bonusItemID;
  15631. WFIFOL(fd,9) = sd->roulette_point.gold;
  15632. WFIFOL(fd,13) = sd->roulette_point.silver;
  15633. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15634. WFIFOSET(fd,packet_len(0xa20));
  15635. }
  15636. /// MERGE ITEM
  15637. /**
  15638. * Acknowledge the client about item merger result
  15639. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15640. * @param fd
  15641. * @param sd
  15642. **/
  15643. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15644. unsigned char buf[9];
  15645. struct s_packet_db *info = NULL;
  15646. short cmd = 0;
  15647. nullpo_retv(sd);
  15648. if (!clif_session_isValid(sd))
  15649. return;
  15650. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15651. return;
  15652. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15653. return;
  15654. WBUFW(buf, 0) = cmd;
  15655. WBUFW(buf, info->pos[0]) = index;
  15656. WBUFW(buf, info->pos[1]) = count;
  15657. WBUFB(buf, info->pos[2]) = type;
  15658. clif_send(buf, info->len, &sd->bl, SELF);
  15659. }
  15660. /**
  15661. * Check if item has the pair to be merged
  15662. * @param sd
  15663. * @param it Item
  15664. * @return True if has pair, False if not
  15665. **/
  15666. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15667. struct item *it_;
  15668. unsigned short i;
  15669. nullpo_retr(false, sd);
  15670. 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);
  15671. if (i < MAX_INVENTORY)
  15672. return true;
  15673. return false;
  15674. }
  15675. /**
  15676. * Check if item can be merged
  15677. * @param id Item Data
  15678. * @param it Item
  15679. * @return True if can be merged, False if not
  15680. **/
  15681. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15682. if (!id || !it)
  15683. return false;
  15684. if (id->type == IT_CASH)
  15685. return false;
  15686. if (!itemdb_isstackable2(id))
  15687. return false;
  15688. if (itemdb_isspecial(it->card[0]))
  15689. return false;
  15690. if (!it->unique_id)
  15691. return false;
  15692. return true;
  15693. }
  15694. /**
  15695. * Open available item to be merged.
  15696. * Only show 1 item in 1 process.
  15697. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15698. * @param sd
  15699. **/
  15700. void clif_merge_item_open(struct map_session_data *sd) {
  15701. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15702. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15703. int len = 0;
  15704. struct s_packet_db *info = NULL;
  15705. struct item *it;
  15706. nullpo_retv(sd);
  15707. if (!clif_session_isValid(sd))
  15708. return;
  15709. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15710. return;
  15711. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15712. return;
  15713. // Get entries
  15714. for (i = 0; i < MAX_INVENTORY; i++) {
  15715. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15716. continue;
  15717. if (clif_merge_item_has_pair(sd, it))
  15718. indexes[n++] = i;
  15719. }
  15720. if (n < 2) { // No item need to be merged
  15721. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15722. return;
  15723. }
  15724. WBUFW(buf, 0) = cmd;
  15725. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15726. for (i = 0; i < n; i++) {
  15727. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15728. }
  15729. clif_send(buf, len, &sd->bl, SELF);
  15730. }
  15731. /**
  15732. * Process item merger
  15733. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15734. * @param fd
  15735. * @param sd
  15736. **/
  15737. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15738. struct s_packet_db *info = NULL;
  15739. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15740. unsigned int count = 0;
  15741. struct item_data *id = NULL;
  15742. nullpo_retv(sd);
  15743. if (!clif_session_isValid(sd))
  15744. return;
  15745. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15746. return;
  15747. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15748. if (n < 2) { // No item need to be merged
  15749. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15750. return;
  15751. }
  15752. for (i = 0, j = 0; i < n; i++) {
  15753. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15754. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15755. continue;
  15756. indexes[j] = idx;
  15757. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15758. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15759. return;
  15760. }
  15761. count += sd->status.inventory[idx].amount;
  15762. j++;
  15763. }
  15764. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15765. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15766. return;
  15767. }
  15768. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15769. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15770. return;
  15771. }
  15772. // Merrrrge!!!!
  15773. for (i = 1; i < n; i++) {
  15774. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15775. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15776. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15777. sd->inventory_data[idx] = NULL;
  15778. clif_delitem(sd, idx, amt, 0);
  15779. }
  15780. sd->status.inventory[indexes[0]].amount = count;
  15781. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15782. }
  15783. /**
  15784. * Cancel item merge
  15785. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15786. * @param fd
  15787. * @param sd
  15788. **/
  15789. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15790. return; // Nothing todo yet
  15791. }
  15792. /**
  15793. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15794. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15795. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15796. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15797. **/
  15798. 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) {
  15799. unsigned char buf[9 + NAME_LENGTH * 2];
  15800. unsigned short cmd = 0;
  15801. struct s_packet_db *info = NULL;
  15802. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15803. return;
  15804. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15805. return;
  15806. WBUFW(buf, 0) = 0x7fd;
  15807. WBUFB(buf, 4) = type;
  15808. WBUFW(buf, 5) = nameid;
  15809. WBUFB(buf, 7) = NAME_LENGTH;
  15810. safestrncpy((char *)WBUFP(buf, 8), char_name, NAME_LENGTH);
  15811. switch (type) {
  15812. case ITEMOBTAIN_TYPE_BOXITEM:
  15813. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15814. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15815. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15816. break;
  15817. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15818. {
  15819. struct mob_db *db = mob_db(container);
  15820. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15821. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15822. safestrncpy((char *)WBUFP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15823. }
  15824. break;
  15825. case ITEMOBTAIN_TYPE_NPC:
  15826. default:
  15827. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15828. break;
  15829. }
  15830. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15831. }
  15832. /// Show body view windows (ZC_DRESSROOM_OPEN).
  15833. /// 0A02 <view>.W
  15834. /// Value <flag> has the following effects:
  15835. /// 1: Open a Dress Room window.
  15836. void clif_dressing_room(struct map_session_data *sd, int flag) {
  15837. #if PACKETVER >= 20150513
  15838. int fd = sd->fd;
  15839. nullpo_retv(sd);
  15840. WFIFOHEAD(fd, packet_len(0xa02));
  15841. WFIFOW(fd,0) = 0xa02;
  15842. WFIFOW(fd,2) = flag;
  15843. WFIFOSET(fd, packet_len(0xa02));
  15844. #endif
  15845. }
  15846. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  15847. /// 0A35 <result>.W
  15848. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  15849. #if PACKETVER >= 20150513
  15850. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  15851. // Ignore the request
  15852. // - Invalid item index
  15853. // - Invalid item ID or item doesn't exist
  15854. // - Item is already identified
  15855. if (idx < 0 || idx >= MAX_INVENTORY ||
  15856. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  15857. sd->status.inventory[idx].identify)
  15858. return;
  15859. // Ignore the request - No magnifiers in inventory
  15860. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  15861. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  15862. return;
  15863. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  15864. return;
  15865. skill_identify(sd, idx);
  15866. #endif
  15867. }
  15868. /// Starts navigation to the given target on client side
  15869. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  15870. #if PACKETVER >= 20111010
  15871. int fd = sd->fd;
  15872. WFIFOHEAD(fd,27);
  15873. WFIFOW(fd,0) = 0x08e2;
  15874. // How detailed will our navigation be?
  15875. if( mob_id > 0 ){
  15876. x = 0;
  15877. y = 0;
  15878. WFIFOB(fd,2) = 3; // monster with destination field
  15879. }else if( x > 0 && y > 0 ){
  15880. WFIFOB(fd,2) = 0; // with coordinates
  15881. }else{
  15882. x = 0;
  15883. y = 0;
  15884. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  15885. }
  15886. // Which services can be used for transportation?
  15887. WFIFOB(fd,3) = flag;
  15888. // If this flag is set, the navigation window will not be opened up
  15889. WFIFOB(fd,4) = hideWindow;
  15890. // Target map
  15891. safestrncpy( (char*)WFIFOP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  15892. // Target x
  15893. WFIFOW(fd,21) = x;
  15894. // Target y
  15895. WFIFOW(fd,23) = y;
  15896. // Target monster ID
  15897. WFIFOW(fd,25) = mob_id;
  15898. WFIFOSET(fd,27);
  15899. #endif
  15900. }
  15901. /// Send hat effects to the client (ZC_HAT_EFFECT).
  15902. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  15903. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  15904. #if PACKETVER >= 20150513
  15905. unsigned char* buf;
  15906. int len,i;
  15907. struct map_session_data *tsd;
  15908. struct block_list* tbl;
  15909. if( target == SELF ){
  15910. tsd = BL_CAST(BL_PC,bl);
  15911. tbl = &sd->bl;
  15912. }else{
  15913. tsd = sd;
  15914. tbl = bl;
  15915. }
  15916. if( !tsd->hatEffectCount )
  15917. return;
  15918. len = 9 + tsd->hatEffectCount * 2;
  15919. buf = (unsigned char*)aMalloc( len );
  15920. WBUFW(buf,0) = 0xa3b;
  15921. WBUFW(buf,2) = len;
  15922. WBUFL(buf,4) = tsd->bl.id;
  15923. WBUFB(buf,8) = 1;
  15924. for( i = 0; i < tsd->hatEffectCount; i++ ){
  15925. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  15926. }
  15927. clif_send(buf, len,tbl,target);
  15928. aFree(buf);
  15929. #endif
  15930. }
  15931. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  15932. #if PACKETVER >= 20150513
  15933. unsigned char buf[13];
  15934. WBUFW(buf,0) = 0xa3b;
  15935. WBUFW(buf,2) = 13;
  15936. WBUFL(buf,4) = sd->bl.id;
  15937. WBUFB(buf,8) = enable;
  15938. WBUFL(buf,9) = effectId;
  15939. clif_send(buf,13,&sd->bl,AREA);
  15940. #endif
  15941. }
  15942. /*==========================================
  15943. * Main client packet processing function
  15944. *------------------------------------------*/
  15945. static int clif_parse(int fd)
  15946. {
  15947. int cmd, packet_ver, packet_len, err;
  15948. TBL_PC* sd;
  15949. int pnum;
  15950. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15951. // Note: "click masters" can do 80+ clicks in 10 seconds
  15952. 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]
  15953. { // begin main client packet processing loop
  15954. sd = (TBL_PC *)session[fd]->session_data;
  15955. if (session[fd]->flag.eof) {
  15956. if (sd) {
  15957. if (sd->state.autotrade) {
  15958. //Disassociate character from the socket connection.
  15959. session[fd]->session_data = NULL;
  15960. sd->fd = 0;
  15961. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15962. } else
  15963. if (sd->state.active) {
  15964. // Player logout display [Valaris]
  15965. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15966. clif_quitsave(fd, sd);
  15967. } else {
  15968. //Unusual logout (during log on/off/map-changer procedure)
  15969. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15970. map_quit(sd);
  15971. }
  15972. } else {
  15973. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15974. }
  15975. do_close(fd);
  15976. return 0;
  15977. }
  15978. if (RFIFOREST(fd) < 2)
  15979. return 0;
  15980. cmd = clif_parse_cmd(fd, sd);
  15981. // identify client's packet version
  15982. if (sd) {
  15983. packet_ver = sd->packet_ver;
  15984. } else {
  15985. // check authentification packet to know packet version
  15986. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15987. if( err ) {// failed to identify packet version
  15988. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15989. err == 1 ? "" :
  15990. err == 2 ? ", possibly for having an invalid account_id" :
  15991. err == 3 ? ", possibly for having an invalid char_id." :
  15992. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15993. err == 4 ? ", possibly for having an invalid login_id1." :
  15994. err == 5 ? ", possibly for having an invalid client_tick." :
  15995. */
  15996. err == 6 ? ", possibly for having an invalid sex." :
  15997. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15998. WFIFOHEAD(fd,packet_len(0x6a));
  15999. WFIFOW(fd,0) = 0x6a;
  16000. WFIFOB(fd,2) = 3; // Rejected from Server
  16001. WFIFOSET(fd,packet_len(0x6a));
  16002. #ifdef DUMP_INVALID_PACKET
  16003. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  16004. #endif
  16005. RFIFOSKIP(fd, RFIFOREST(fd));
  16006. set_eof(fd);
  16007. return 0;
  16008. }
  16009. }
  16010. // filter out invalid / unsupported packets
  16011. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  16012. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  16013. #ifdef DUMP_INVALID_PACKET
  16014. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  16015. #endif
  16016. set_eof(fd);
  16017. return 0;
  16018. }
  16019. // determine real packet length
  16020. packet_len = packet_db[packet_ver][cmd].len;
  16021. if (packet_len == -1) { // variable-length packet
  16022. if (RFIFOREST(fd) < 4)
  16023. return 0;
  16024. packet_len = RFIFOW(fd,2);
  16025. if (packet_len < 4 || packet_len > 32768) {
  16026. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  16027. #ifdef DUMP_INVALID_PACKET
  16028. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  16029. #endif
  16030. set_eof(fd);
  16031. return 0;
  16032. }
  16033. }
  16034. if ((int)RFIFOREST(fd) < packet_len)
  16035. return 0; // not enough data received to form the packet
  16036. #ifdef PACKET_OBFUSCATION
  16037. RFIFOW(fd, 0) = cmd;
  16038. if (sd)
  16039. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  16040. #endif
  16041. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  16042. packet_db[packet_ver][cmd].func(fd, sd);
  16043. else if( packet_db[packet_ver][cmd].func != NULL ) {
  16044. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  16045. ; //Only valid packet when there is no session
  16046. else
  16047. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  16048. ; //Only valid packet when player is not on a map
  16049. else
  16050. packet_db[packet_ver][cmd].func(fd, sd);
  16051. }
  16052. #ifdef DUMP_UNKNOWN_PACKET
  16053. else DumpUnknown(fd,sd,cmd,packet_len);
  16054. #endif
  16055. RFIFOSKIP(fd, packet_len);
  16056. }; // main loop end
  16057. return 0;
  16058. }
  16059. /*==========================================
  16060. * Reads packet_db.txt and setups its array reference
  16061. *------------------------------------------*/
  16062. void packetdb_readdb(bool reload)
  16063. {
  16064. char line[1024];
  16065. int cmd,i,j;
  16066. int max_cmd=-1;
  16067. bool skip_ver = false;
  16068. int warned = 0;
  16069. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  16070. #ifdef PACKET_OBFUSCATION
  16071. bool key_defined = false;
  16072. int last_key_defined = -1;
  16073. #endif
  16074. int packet_len_table[MAX_PACKET_DB] = {
  16075. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16079. //#0x0040
  16080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16082. #if PACKETVER <= 20081217
  16083. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  16084. #else
  16085. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  16086. #endif
  16087. #if PACKETVER < 2
  16088. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  16089. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  16090. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  16091. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  16092. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  16093. #else
  16094. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  16095. #endif
  16096. //#0x0080
  16097. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  16098. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  16099. #if PACKETVER <= 20100622
  16100. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  16101. #else
  16102. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  16103. #endif
  16104. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  16105. //#0x00C0
  16106. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  16107. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  16108. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  16109. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  16110. //#0x0100
  16111. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  16112. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  16113. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  16114. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  16115. //#0x0140
  16116. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  16117. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  16118. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  16119. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  16120. //#0x0180
  16121. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  16122. #if PACKETVER < 1
  16123. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16124. #else // 196 comodo icon status display for later
  16125. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16126. #endif
  16127. #if PACKETVER < 20081126
  16128. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16129. #else // 0x1a2 changed (35->37)
  16130. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16131. #endif
  16132. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  16133. //#0x01C0, Set 0x1d5=-1
  16134. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  16135. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  16136. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  16137. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  16138. //#0x0200
  16139. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  16140. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  16141. #if PACKETVER < 20071106
  16142. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  16143. #else // 0x22c changed
  16144. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  16145. #endif
  16146. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  16147. //#0x0240
  16148. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  16149. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  16150. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16151. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16152. //#0x0280
  16153. #if PACKETVER < 20070711
  16154. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  16155. #else
  16156. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  16157. #endif
  16158. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  16159. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16160. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  16161. //#0x02C0
  16162. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  16163. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  16164. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  16165. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16166. //#0x0300
  16167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0340
  16172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0380
  16177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x03C0
  16182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0400
  16187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 8, 0, 25,
  16191. //#0x0440
  16192. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  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. //#0x0480
  16197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16201. //#0x04C0
  16202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16206. //#0x0500
  16207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16211. //#0x0540
  16212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16216. //#0x0580
  16217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16221. //#0x05C0
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16226. //#0x0600
  16227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16231. //#0x0640
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16236. //#0x0680
  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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16241. //#0x06C0
  16242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16246. //#0x0700
  16247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16251. //#0x0740
  16252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16256. //#0x0780
  16257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16261. //#0x07C0
  16262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16263. #if PACKETVER < 20090617
  16264. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  16265. #else // 0x7d9 changed
  16266. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  16267. #endif
  16268. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  16269. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  16270. //#0x0800
  16271. #if PACKETVER < 20091229
  16272. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  16273. #else // for Party booking ( PACKETVER >= 20091229 )
  16274. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  16275. #endif
  16276. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  16277. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16278. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  16279. //#0x0840
  16280. #if PACKETVER < 20130000
  16281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16282. #else
  16283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  16284. #endif
  16285. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  16286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16288. //#0x0880
  16289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16292. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16293. //#0x08C0
  16294. 0, 0, 0, 0, 0, 0, 0, 20, 34, 0, 0, 0, 0, 0, 0, 10,
  16295. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24,
  16298. //#0x0900
  16299. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1,
  16300. 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16303. //#0x0940
  16304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  16307. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, -1, 0, 0, 0, 0, -1,
  16308. //#0x0980
  16309. 7, 0, 0, 29, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16310. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  16311. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  16312. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  16313. //#0x09C0
  16314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 17, 0, 0,102, 0,
  16315. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, -1, -1, -1, 0, 7,
  16316. 0, 0, 0, 0, 0, 18, 22, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  16317. 0, 11, 12, 11, 0, 0, 0, 75, -1,143, 0, 0, 0, -1, -1, -1,
  16318. //#0x0A00
  16319. #if PACKETVER >= 20141022
  16320. 269, 3, 4, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 14, -1,
  16321. #else
  16322. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 14, 0,
  16323. #endif
  16324. -1, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  16325. 21, 3, 5, 0, 66, 0, 0, 8, 3, 0, 0, -1, 0, -1, 0, 0,
  16326. 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16327. };
  16328. struct {
  16329. void (*func)(int, struct map_session_data *);
  16330. char *name;
  16331. } clif_parse_func[]={
  16332. {clif_parse_WantToConnection,"wanttoconnection"},
  16333. {clif_parse_LoadEndAck,"loadendack"},
  16334. {clif_parse_TickSend,"ticksend"},
  16335. {clif_parse_WalkToXY,"walktoxy"},
  16336. {clif_parse_QuitGame,"quitgame"},
  16337. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  16338. {clif_parse_GlobalMessage,"globalmessage"},
  16339. {clif_parse_MapMove,"mapmove"},
  16340. {clif_parse_ChangeDir,"changedir"},
  16341. {clif_parse_Emotion,"emotion"},
  16342. {clif_parse_HowManyConnections,"howmanyconnections"},
  16343. {clif_parse_ActionRequest,"actionrequest"},
  16344. {clif_parse_Restart,"restart"},
  16345. {clif_parse_WisMessage,"wis"},
  16346. {clif_parse_Broadcast,"broadcast"},
  16347. {clif_parse_TakeItem,"takeitem"},
  16348. {clif_parse_DropItem,"dropitem"},
  16349. {clif_parse_UseItem,"useitem"},
  16350. {clif_parse_EquipItem,"equipitem"},
  16351. {clif_parse_UnequipItem,"unequipitem"},
  16352. {clif_parse_NpcClicked,"npcclicked"},
  16353. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  16354. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  16355. {clif_parse_NpcSellListSend,"npcselllistsend"},
  16356. {clif_parse_CreateChatRoom,"createchatroom"},
  16357. {clif_parse_ChatAddMember,"chataddmember"},
  16358. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  16359. {clif_parse_ChangeChatOwner,"changechatowner"},
  16360. {clif_parse_KickFromChat,"kickfromchat"},
  16361. {clif_parse_ChatLeave,"chatleave"},
  16362. {clif_parse_TradeRequest,"traderequest"},
  16363. {clif_parse_TradeAck,"tradeack"},
  16364. {clif_parse_TradeAddItem,"tradeadditem"},
  16365. {clif_parse_TradeOk,"tradeok"},
  16366. {clif_parse_TradeCancel,"tradecancel"},
  16367. {clif_parse_TradeCommit,"tradecommit"},
  16368. {clif_parse_StopAttack,"stopattack"},
  16369. {clif_parse_PutItemToCart,"putitemtocart"},
  16370. {clif_parse_GetItemFromCart,"getitemfromcart"},
  16371. {clif_parse_RemoveOption,"removeoption"},
  16372. {clif_parse_ChangeCart,"changecart"},
  16373. {clif_parse_StatusUp,"statusup"},
  16374. {clif_parse_SkillUp,"skillup"},
  16375. {clif_parse_UseSkillToId,"useskilltoid"},
  16376. {clif_parse_UseSkillToPos,"useskilltopos"},
  16377. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  16378. {clif_parse_UseSkillMap,"useskillmap"},
  16379. {clif_parse_RequestMemo,"requestmemo"},
  16380. {clif_parse_ProduceMix,"producemix"},
  16381. {clif_parse_Cooking,"cooking"},
  16382. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  16383. {clif_parse_NpcNextClicked,"npcnextclicked"},
  16384. {clif_parse_NpcAmountInput,"npcamountinput"},
  16385. {clif_parse_NpcStringInput,"npcstringinput"},
  16386. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  16387. {clif_parse_ItemIdentify,"itemidentify"},
  16388. {clif_parse_SelectArrow,"selectarrow"},
  16389. {clif_parse_AutoSpell,"autospell"},
  16390. {clif_parse_UseCard,"usecard"},
  16391. {clif_parse_InsertCard,"insertcard"},
  16392. {clif_parse_RepairItem,"repairitem"},
  16393. {clif_parse_WeaponRefine,"weaponrefine"},
  16394. {clif_parse_SolveCharName,"solvecharname"},
  16395. {clif_parse_ResetChar,"resetchar"},
  16396. {clif_parse_LocalBroadcast,"localbroadcast"},
  16397. {clif_parse_MoveToKafra,"movetokafra"},
  16398. {clif_parse_MoveFromKafra,"movefromkafra"},
  16399. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  16400. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  16401. {clif_parse_CloseKafra,"closekafra"},
  16402. {clif_parse_CreateParty,"createparty"},
  16403. {clif_parse_CreateParty2,"createparty2"},
  16404. {clif_parse_PartyInvite,"partyinvite"},
  16405. {clif_parse_PartyInvite2,"partyinvite2"},
  16406. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  16407. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  16408. {clif_parse_LeaveParty,"leaveparty"},
  16409. {clif_parse_RemovePartyMember,"removepartymember"},
  16410. {clif_parse_PartyChangeOption,"partychangeoption"},
  16411. {clif_parse_PartyMessage,"partymessage"},
  16412. {clif_parse_PartyChangeLeader,"partychangeleader"},
  16413. {clif_parse_CloseVending,"closevending"},
  16414. {clif_parse_VendingListReq,"vendinglistreq"},
  16415. {clif_parse_PurchaseReq,"purchasereq"},
  16416. {clif_parse_PurchaseReq2,"purchasereq2"},
  16417. {clif_parse_OpenVending,"openvending"},
  16418. {clif_parse_CreateGuild,"createguild"},
  16419. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  16420. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  16421. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  16422. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  16423. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  16424. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  16425. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  16426. {clif_parse_GuildInvite,"guildinvite"},
  16427. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  16428. {clif_parse_GuildLeave,"guildleave"},
  16429. {clif_parse_GuildExpulsion,"guildexpulsion"},
  16430. {clif_parse_GuildMessage,"guildmessage"},
  16431. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  16432. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  16433. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  16434. {clif_parse_GuildOpposition,"guildopposition"},
  16435. {clif_parse_GuildBreak,"guildbreak"},
  16436. {clif_parse_PetMenu,"petmenu"},
  16437. {clif_parse_CatchPet,"catchpet"},
  16438. {clif_parse_SelectEgg,"selectegg"},
  16439. {clif_parse_SendEmotion,"sendemotion"},
  16440. {clif_parse_ChangePetName,"changepetname"},
  16441. {clif_parse_GMKick,"gmkick"},
  16442. {clif_parse_GMHide,"gmhide"},
  16443. {clif_parse_GMReqNoChat,"gmreqnochat"},
  16444. {clif_parse_GMReqAccountName,"gmreqaccname"},
  16445. {clif_parse_GMKickAll,"killall"},
  16446. {clif_parse_GMRecall,"recall"},
  16447. {clif_parse_GMRecall,"summon"},
  16448. {clif_parse_GM_Item_Monster,"itemmonster"},
  16449. {clif_parse_GMShift,"remove"},
  16450. {clif_parse_GMShift,"shift"},
  16451. {clif_parse_GMChangeMapType,"changemaptype"},
  16452. {clif_parse_GMRc,"rc"},
  16453. {clif_parse_GMRecall2,"recall2"},
  16454. {clif_parse_GMRemove2,"remove2"},
  16455. {clif_parse_GMFullStrip,"gmfullstrip"},
  16456. {clif_parse_NoviceDoriDori,"sndoridori"},
  16457. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  16458. {clif_parse_PMIgnore,"wisexin"},
  16459. {clif_parse_PMIgnoreList,"wisexlist"},
  16460. {clif_parse_PMIgnoreAll,"wisall"},
  16461. {clif_parse_FriendsListAdd,"friendslistadd"},
  16462. {clif_parse_FriendsListRemove,"friendslistremove"},
  16463. {clif_parse_FriendsListReply,"friendslistreply"},
  16464. {clif_parse_Blacksmith,"blacksmith"},
  16465. {clif_parse_Alchemist,"alchemist"},
  16466. {clif_parse_Taekwon,"taekwon"},
  16467. {clif_parse_RankingPk,"rankingpk"},
  16468. {clif_parse_FeelSaveOk,"feelsaveok"},
  16469. {clif_parse_debug,"debug"},
  16470. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16471. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16472. {clif_parse_HomMoveTo,"hommoveto"},
  16473. {clif_parse_HomAttack,"homattack"},
  16474. {clif_parse_HomMenu,"hommenu"},
  16475. {clif_parse_StoragePassword,"storagepassword"},
  16476. {clif_parse_Hotkey,"hotkey"},
  16477. {clif_parse_AutoRevive,"autorevive"},
  16478. {clif_parse_Check,"check"},
  16479. {clif_parse_Adopt_request,"adoptrequest"},
  16480. {clif_parse_Adopt_reply,"adoptreply"},
  16481. // MAIL SYSTEM
  16482. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16483. {clif_parse_Mail_read,"mailread"},
  16484. {clif_parse_Mail_getattach,"mailgetattach"},
  16485. {clif_parse_Mail_delete,"maildelete"},
  16486. {clif_parse_Mail_return,"mailreturn"},
  16487. {clif_parse_Mail_setattach,"mailsetattach"},
  16488. {clif_parse_Mail_winopen,"mailwinopen"},
  16489. {clif_parse_Mail_send,"mailsend"},
  16490. // AUCTION SYSTEM
  16491. {clif_parse_Auction_search,"auctionsearch"},
  16492. {clif_parse_Auction_buysell,"auctionbuysell"},
  16493. {clif_parse_Auction_setitem,"auctionsetitem"},
  16494. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16495. {clif_parse_Auction_register,"auctionregister"},
  16496. {clif_parse_Auction_cancel,"auctioncancel"},
  16497. {clif_parse_Auction_close,"auctionclose"},
  16498. {clif_parse_Auction_bid,"auctionbid"},
  16499. // Quest Log System
  16500. {clif_parse_questStateAck,"queststate"},
  16501. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16502. {clif_parse_EquipTick,"equiptickbox"},
  16503. {clif_parse_BattleChat,"battlechat"},
  16504. {clif_parse_mercenary_action,"mermenu"},
  16505. {clif_parse_progressbar,"progressbar"},
  16506. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16507. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16508. #if PACKETVER >= 20091229
  16509. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16510. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16511. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16512. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16513. #endif
  16514. {clif_parse_BankCheck,"bankcheck"},
  16515. {clif_parse_BankDeposit,"bankdeposit"},
  16516. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16517. {clif_parse_BankOpen,"bankopen"},
  16518. {clif_parse_BankClose,"bankclose"},
  16519. {clif_parse_PVPInfo,"pvpinfo"},
  16520. {clif_parse_LessEffect,"lesseffect"},
  16521. // Buying Store
  16522. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16523. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16524. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16525. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16526. // Store Search
  16527. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16528. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16529. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16530. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16531. // Cashshop
  16532. { clif_parse_cashshop_open_request, "cashshopopen" },
  16533. { clif_parse_cashshop_close, "cashshopclose" },
  16534. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16535. { clif_parse_cashshop_buy, "cashshopbuy" },
  16536. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16537. /* */
  16538. { clif_parse_MoveItem , "moveitem" },
  16539. { clif_parse_PartyTick, "partytick" },
  16540. { clif_parse_dull, "dull" },
  16541. { clif_parse_GuildInvite2 , "guildinvite2" },
  16542. { clif_parse_reqworldinfo, "reqworldinfo"},
  16543. { clif_parse_client_version, "clientversion"},
  16544. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16545. { clif_parse_ranklist, "ranklist"},
  16546. // Market NPC
  16547. { clif_parse_NPCShopClosed, "npcshopclosed" },
  16548. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16549. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16550. // Roulette
  16551. { clif_parse_RouletteOpen, "rouletteopen" },
  16552. { clif_parse_RouletteInfo, "rouletteinfo" },
  16553. { clif_parse_RouletteClose, "rouletteclose" },
  16554. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16555. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16556. // Merge Item
  16557. { clif_parse_merge_item_req, "mergeitem_req"},
  16558. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16559. // HotkeyRowShift
  16560. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16561. // OneClick Item Identify
  16562. { clif_parse_Oneclick_Itemidentify, "oneclick_itemidentify" },
  16563. // NewChange Cart2
  16564. { clif_parse_SelectCart, "selectcart" },
  16565. {NULL,NULL}
  16566. };
  16567. struct {
  16568. char *name; //function name
  16569. int funcidx; //
  16570. } clif_ack_func[]={ //hash
  16571. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16572. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16573. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16574. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16575. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16576. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16577. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16578. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16579. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16580. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16581. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16582. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16583. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16584. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16585. };
  16586. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16587. int f;
  16588. memset(packet_db,0,sizeof(packet_db));
  16589. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16590. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16591. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16592. packet_len(i) = packet_len_table[i];
  16593. clif_config.packet_db_ver = MAX_PACKET_VER;
  16594. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16595. FILE *fp;
  16596. int ln = 0;
  16597. int entries = 0;
  16598. char *str[64], *p, *str2[64], *p2;
  16599. sprintf(line, "%s/%s", db_path, filename[f]);
  16600. if( (fp = fopen(line,"r")) == NULL ) {
  16601. if (f == 0) {
  16602. ShowFatalError("Can't read %s\n", line);
  16603. exit(EXIT_FAILURE);
  16604. }
  16605. return;
  16606. }
  16607. while( fgets(line, sizeof(line), fp) ) {
  16608. char w1[256],w2[256];
  16609. ln++;
  16610. if(line[0]=='/' && line[1]=='/')
  16611. continue;
  16612. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16613. if (strcmpi(w1,"packet_ver") == 0) {
  16614. int prev_ver = packet_ver;
  16615. skip_ver = false;
  16616. packet_ver = atoi(w2);
  16617. if ( packet_ver > MAX_PACKET_VER )
  16618. { //Check to avoid overflowing. [Skotlex]
  16619. if( (warned&1) == 0 )
  16620. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16621. warned &= 1;
  16622. skip_ver = true;
  16623. }
  16624. else if( packet_ver < 0 )
  16625. {
  16626. if( (warned&2) == 0 )
  16627. ShowWarning("Negative packet versions are not supported.\n");
  16628. warned &= 2;
  16629. skip_ver = true;
  16630. }
  16631. else if( packet_ver == SERVER )
  16632. {
  16633. if( (warned&4) == 0 )
  16634. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16635. warned &= 4;
  16636. skip_ver = true;
  16637. }
  16638. if( skip_ver )
  16639. {
  16640. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16641. packet_ver = prev_ver;
  16642. continue;
  16643. }
  16644. // copy from previous version into new version and continue
  16645. // - indicating all following packets should be read into the newer version
  16646. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16647. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16648. continue;
  16649. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16650. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16651. clif_config.packet_db_ver = MAX_PACKET_VER;
  16652. else // to manually set the packet DB version
  16653. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16654. continue;
  16655. }
  16656. #ifdef PACKET_OBFUSCATION
  16657. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16658. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16659. trim(w2);
  16660. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16661. if (!packet_keys[packet_ver])
  16662. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16663. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16664. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16665. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16666. last_key_defined = packet_ver;
  16667. if (battle_config.etc_log)
  16668. 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]);
  16669. }
  16670. continue;
  16671. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16672. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16673. trim(w2);
  16674. if (strcmpi(w2,"default") == 0)
  16675. continue;
  16676. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16677. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16678. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16679. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16680. key_defined = true;
  16681. if (battle_config.etc_log)
  16682. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16683. }
  16684. continue;
  16685. }
  16686. #endif
  16687. }
  16688. if( skip_ver )
  16689. continue; // Skipping current packet version
  16690. memset(str,0,sizeof(str));
  16691. for (j = 0, p = line; j < 4 && p; ++j) {
  16692. str[j] = p;
  16693. p = strchr(p,',');
  16694. if (p)
  16695. *p++=0;
  16696. }
  16697. if (str[0] == NULL)
  16698. continue;
  16699. cmd = strtol(str[0],(char **)NULL,0);
  16700. if(max_cmd < cmd)
  16701. max_cmd = cmd;
  16702. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16703. continue;
  16704. if(str[1]==NULL){
  16705. ShowError("packet_db: packet len error\n");
  16706. continue;
  16707. }
  16708. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16709. if(str[2]==NULL){
  16710. packet_db[packet_ver][cmd].func = NULL;
  16711. ln++;
  16712. continue;
  16713. }
  16714. // look up processing function by name
  16715. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16716. if( j < ARRAYLENGTH(clif_parse_func) )
  16717. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16718. else { //search if it's a mapped ack func
  16719. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16720. if( j < ARRAYLENGTH(clif_ack_func)) {
  16721. int fidx = clif_ack_func[j].funcidx;
  16722. packet_db_ack[packet_ver][fidx] = cmd;
  16723. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16724. }
  16725. }
  16726. // set the identifying cmd for the packet_db version
  16727. if (strcmp(str[2],"wanttoconnection")==0)
  16728. clif_config.connect_cmd[packet_ver] = cmd;
  16729. if(str[3]==NULL){
  16730. ShowError("packet_db: packet error\n");
  16731. exit(EXIT_FAILURE);
  16732. }
  16733. for(j = 0, p2 = str[3]; p2; j++){
  16734. short k;
  16735. str2[j] = p2;
  16736. p2 = strchr(p2,':');
  16737. if(p2)
  16738. *p2++=0;
  16739. k = atoi(str2[j]);
  16740. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16741. if( j >= MAX_PACKET_POS )
  16742. {
  16743. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16744. break;
  16745. }
  16746. packet_db[packet_ver][cmd].pos[j] = k;
  16747. }
  16748. entries++;
  16749. }
  16750. fclose(fp);
  16751. if(max_cmd > MAX_PACKET_DB) {
  16752. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16753. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16754. }
  16755. //Locate the nearest version that we still support. [Skotlex]
  16756. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16757. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16758. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16759. }
  16760. sprintf(line, "%s/%s", db_path,filename[f]);
  16761. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16762. }
  16763. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16764. #ifdef PACKET_OBFUSCATION
  16765. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16766. int use_key = last_key_defined;
  16767. if (last_key_defined == -1)
  16768. ShowError("Can't find packet obfuscation keys!\n");
  16769. else {
  16770. if (packet_keys[clif_config.packet_db_ver])
  16771. use_key = clif_config.packet_db_ver;
  16772. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16773. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16774. }
  16775. }
  16776. 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]);
  16777. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16778. if (packet_keys[i]) {
  16779. aFree(packet_keys[i]);
  16780. packet_keys[i] = NULL;
  16781. }
  16782. }
  16783. #endif
  16784. }
  16785. /*==========================================
  16786. *
  16787. *------------------------------------------*/
  16788. void do_init_clif(void) {
  16789. const char* colors[COLOR_MAX] = {
  16790. "0x00FF00",
  16791. "0xFF0000",
  16792. "0xFFFFFF",
  16793. "0xFFFF00",
  16794. "0x00FFFF",
  16795. };
  16796. int i;
  16797. /**
  16798. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16799. **/
  16800. for(i = 0; i < COLOR_MAX; i++) {
  16801. color_table[i] = strtoul(colors[i],NULL,0);
  16802. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16803. }
  16804. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16805. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16806. #ifdef PACKET_OBFUSCATION
  16807. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16808. #endif
  16809. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16810. packetdb_readdb(false);
  16811. set_defaultparse(clif_parse);
  16812. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16813. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16814. exit(EXIT_FAILURE);
  16815. }
  16816. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16817. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16818. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16819. }
  16820. void do_final_clif(void) {
  16821. ers_destroy(delay_clearunit_ers);
  16822. }