clif.c 550 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218
  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. #else
  842. WBUFW(buf,0) = spawn?0x858:0x857;
  843. #endif
  844. #if PACKETVER >= 20091103
  845. name = status_get_name(bl);
  846. #if PACKETVER < 20110111
  847. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  848. #else
  849. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  850. #endif
  851. WBUFB(buf,4) = clif_bl_type(bl);
  852. offset+=3;
  853. buf = WBUFP(buffer,offset);
  854. #elif PACKETVER >= 20071106
  855. if (type) { //Non-player packets
  856. WBUFB(buf,2) = clif_bl_type(bl);
  857. offset++;
  858. buf = WBUFP(buffer,offset);
  859. }
  860. #endif
  861. WBUFL(buf, 2) = bl->id;
  862. WBUFW(buf, 6) = status_get_speed(bl);
  863. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  864. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  865. #if PACKETVER < 20091103
  866. if (type&&spawn) { //uses an older and different packet structure
  867. WBUFW(buf,12) = (sc)? sc->option : 0;
  868. WBUFW(buf,14) = vd->hair_style;
  869. WBUFW(buf,16) = vd->weapon;
  870. WBUFW(buf,18) = vd->head_bottom;
  871. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  872. WBUFW(buf,22) = vd->shield;
  873. } else {
  874. #endif
  875. #if PACKETVER >= 20091103
  876. WBUFL(buf,12) = (sc)? sc->option : 0;
  877. offset+=2;
  878. buf = WBUFP(buffer,offset);
  879. #elif PACKETVER >= 7
  880. if (!type) {
  881. WBUFL(buf,12) = (sc)? sc->option : 0;
  882. offset+=2;
  883. buf = WBUFP(buffer,offset);
  884. } else
  885. WBUFW(buf,12) = (sc)? sc->option : 0;
  886. #else
  887. WBUFW(buf,12) = (sc)? sc->option : 0;
  888. #endif
  889. WBUFW(buf,14) = vd->class_;
  890. WBUFW(buf,16) = vd->hair_style;
  891. WBUFW(buf,18) = vd->weapon;
  892. #if PACKETVER < 4
  893. WBUFW(buf,20) = vd->head_bottom;
  894. WBUFW(buf,22) = vd->shield;
  895. #else
  896. WBUFW(buf,20) = vd->shield;
  897. WBUFW(buf,22) = vd->head_bottom;
  898. #endif
  899. #if PACKETVER < 20091103
  900. }
  901. #endif
  902. WBUFW(buf,24) = vd->head_top;
  903. WBUFW(buf,26) = vd->head_mid;
  904. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  905. { //The hell, why flags work like this?
  906. WBUFW(buf,22) = status_get_emblem_id(bl);
  907. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  908. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  909. }
  910. WBUFW(buf,28) = vd->hair_color;
  911. WBUFW(buf,30) = vd->cloth_color;
  912. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  913. #if PACKETVER < 20091103
  914. if (type&&spawn) { //End of packet 0x7c
  915. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  916. WBUFB(buf,35) = vd->sex;
  917. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  918. WBUFB(buf,39) = 0;
  919. WBUFB(buf,40) = 0;
  920. return packet_len(0x7c);
  921. }
  922. #endif
  923. #if PACKETVER >= 20110111
  924. WBUFW(buf,34) = vd->robe;
  925. offset+= 2;
  926. buf = WBUFP(buffer,offset);
  927. #endif
  928. WBUFL(buf,34) = status_get_guild_id(bl);
  929. WBUFW(buf,38) = status_get_emblem_id(bl);
  930. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  931. #if PACKETVER >= 20091103
  932. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  933. offset+=2;
  934. buf = WBUFP(buffer,offset);
  935. #elif PACKETVER >= 7
  936. if (!type) {
  937. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  938. offset+=2;
  939. buf = WBUFP(buffer,offset);
  940. } else
  941. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  942. #else
  943. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  944. #endif
  945. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  946. WBUFB(buf,45) = vd->sex;
  947. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  948. WBUFB(buf,49) = (sd)? 5 : 0;
  949. WBUFB(buf,50) = (sd)? 5 : 0;
  950. if (!spawn) {
  951. WBUFB(buf,51) = vd->dead_sit;
  952. offset++;
  953. buf = WBUFP(buffer,offset);
  954. }
  955. WBUFW(buf,51) = clif_setlevel(bl);
  956. #if PACKETVER < 20091103
  957. if (type) //End for non-player packet
  958. return packet_len(WBUFW(buffer,0));
  959. #endif
  960. #if PACKETVER >= 20080102
  961. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  962. #endif
  963. #if PACKETVER >= 20091103
  964. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  965. return WBUFW(buffer,2);
  966. #else
  967. return packet_len(WBUFW(buffer,0));
  968. #endif
  969. }
  970. /*==========================================
  971. * Prepares 'unit walking' packet
  972. *------------------------------------------*/
  973. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  974. {
  975. struct map_session_data* sd;
  976. struct status_change* sc = status_get_sc(bl);
  977. struct view_data* vd = status_get_viewdata(bl);
  978. unsigned char* buf = WBUFP(buffer,0);
  979. #if PACKETVER >= 7
  980. unsigned short offset = 0;
  981. #endif
  982. #if PACKETVER >= 20091103
  983. const char *name;
  984. #endif
  985. sd = BL_CAST(BL_PC, bl);
  986. #if PACKETVER < 4
  987. WBUFW(buf, 0) = 0x7b;
  988. #elif PACKETVER < 7
  989. WBUFW(buf, 0) = 0x1da;
  990. #elif PACKETVER < 20080102
  991. WBUFW(buf, 0) = 0x22c;
  992. #elif PACKETVER < 20091103
  993. WBUFW(buf, 0) = 0x2ec;
  994. #elif PACKETVER < 20101124
  995. WBUFW(buf, 0) = 0x7f7;
  996. #else
  997. WBUFW(buf, 0) = 0x856;
  998. #endif
  999. #if PACKETVER >= 20091103
  1000. name = status_get_name(bl);
  1001. #if PACKETVER < 20110111
  1002. WBUFW(buf, 2) = 69+strlen(name);
  1003. #else
  1004. WBUFW(buf, 2) = 71+strlen(name);
  1005. #endif
  1006. offset+=2;
  1007. buf = WBUFP(buffer,offset);
  1008. #endif
  1009. #if PACKETVER >= 20071106
  1010. WBUFB(buf, 2) = clif_bl_type(bl);
  1011. offset++;
  1012. buf = WBUFP(buffer,offset);
  1013. #endif
  1014. WBUFL(buf, 2) = bl->id;
  1015. WBUFW(buf, 6) = status_get_speed(bl);
  1016. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1017. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1018. #if PACKETVER < 7
  1019. WBUFW(buf,12) = (sc)? sc->option : 0;
  1020. #else
  1021. WBUFL(buf,12) = (sc)? sc->option : 0;
  1022. offset+=2; //Shift the rest of elements by 2 bytes.
  1023. buf = WBUFP(buffer,offset);
  1024. #endif
  1025. WBUFW(buf,14) = vd->class_;
  1026. WBUFW(buf,16) = vd->hair_style;
  1027. WBUFW(buf,18) = vd->weapon;
  1028. #if PACKETVER < 4
  1029. WBUFW(buf,20) = vd->head_bottom;
  1030. WBUFL(buf,22) = gettick();
  1031. WBUFW(buf,26) = vd->shield;
  1032. #else
  1033. WBUFW(buf,20) = vd->shield;
  1034. WBUFW(buf,22) = vd->head_bottom;
  1035. WBUFL(buf,24) = gettick();
  1036. #endif
  1037. WBUFW(buf,28) = vd->head_top;
  1038. WBUFW(buf,30) = vd->head_mid;
  1039. WBUFW(buf,32) = vd->hair_color;
  1040. WBUFW(buf,34) = vd->cloth_color;
  1041. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1042. #if PACKETVER >= 20110111
  1043. WBUFW(buf,38) = vd->robe;
  1044. offset+= 2;
  1045. buf = WBUFP(buffer,offset);
  1046. #endif
  1047. WBUFL(buf,38) = status_get_guild_id(bl);
  1048. WBUFW(buf,42) = status_get_emblem_id(bl);
  1049. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1050. #if PACKETVER < 7
  1051. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1052. #else
  1053. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1054. offset+=2; //Shift the rest of elements by 2 bytes.
  1055. buf = WBUFP(buffer,offset);
  1056. #endif
  1057. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1058. WBUFB(buf,49) = vd->sex;
  1059. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1060. WBUFB(buf,56) = (sd)? 5 : 0;
  1061. WBUFB(buf,57) = (sd)? 5 : 0;
  1062. WBUFW(buf,58) = clif_setlevel(bl);
  1063. #if PACKETVER >= 20080102
  1064. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1065. #endif
  1066. #if PACKETVER >= 20091103
  1067. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1068. return WBUFW(buffer,2);
  1069. #else
  1070. return packet_len(WBUFW(buffer,0));
  1071. #endif
  1072. }
  1073. //Modifies the buffer for disguise characters and sends it to self.
  1074. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1075. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1076. {
  1077. #if PACKETVER >= 20091103
  1078. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1079. WBUFL(buf,5)=-bl->id;
  1080. #elif PACKETVER >= 20071106
  1081. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1082. WBUFL(buf,3)=-bl->id;
  1083. #else
  1084. WBUFL(buf,2)=-bl->id;
  1085. #endif
  1086. clif_send(buf, len, bl, SELF);
  1087. }
  1088. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1089. /// 01b0 <id>.L <type>.B <value>.L
  1090. /// type:
  1091. /// unused
  1092. void clif_class_change(struct block_list *bl,int class_,int type)
  1093. {
  1094. nullpo_retv(bl);
  1095. if(!pcdb_checkid(class_))
  1096. {// player classes yield missing sprites
  1097. unsigned char buf[16];
  1098. WBUFW(buf,0)=0x1b0;
  1099. WBUFL(buf,2)=bl->id;
  1100. WBUFB(buf,6)=type;
  1101. WBUFL(buf,7)=class_;
  1102. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1103. }
  1104. }
  1105. /// Notifies the client of an object's spirits.
  1106. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1107. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1108. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1109. {
  1110. WFIFOHEAD(fd, packet_len(0x1e1));
  1111. WFIFOW(fd,0)=0x1e1;
  1112. WFIFOL(fd,2)=sd->bl.id;
  1113. WFIFOW(fd,6)=sd->spiritball;
  1114. WFIFOSET(fd, packet_len(0x1e1));
  1115. }
  1116. /*==========================================
  1117. * Kagerou/Oboro amulet spirit
  1118. *------------------------------------------*/
  1119. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1120. {
  1121. WFIFOHEAD(fd, packet_len(0x08cf));
  1122. WFIFOW(fd,0)=0x08cf;
  1123. WFIFOL(fd,2)=sd->bl.id;
  1124. WFIFOW(fd,6)=sd->spiritcharm_type;
  1125. WFIFOW(fd,8)=sd->spiritcharm;
  1126. WFIFOSET(fd, packet_len(0x08cf));
  1127. }
  1128. /*==========================================
  1129. * Run when player changes map / refreshes
  1130. * Tells its client to display all weather settings being used by this map
  1131. *------------------------------------------*/
  1132. static void clif_weather_check(struct map_session_data *sd)
  1133. {
  1134. int16 m = sd->bl.m;
  1135. int fd = sd->fd;
  1136. if (map[m].flag.snow
  1137. || map[m].flag.clouds
  1138. || map[m].flag.fog
  1139. || map[m].flag.fireworks
  1140. || map[m].flag.sakura
  1141. || map[m].flag.leaves
  1142. || map[m].flag.clouds2)
  1143. {
  1144. if (map[m].flag.snow)
  1145. clif_specialeffect_single(&sd->bl, 162, fd);
  1146. if (map[m].flag.clouds)
  1147. clif_specialeffect_single(&sd->bl, 233, fd);
  1148. if (map[m].flag.clouds2)
  1149. clif_specialeffect_single(&sd->bl, 516, fd);
  1150. if (map[m].flag.fog)
  1151. clif_specialeffect_single(&sd->bl, 515, fd);
  1152. if (map[m].flag.fireworks) {
  1153. clif_specialeffect_single(&sd->bl, 297, fd);
  1154. clif_specialeffect_single(&sd->bl, 299, fd);
  1155. clif_specialeffect_single(&sd->bl, 301, fd);
  1156. }
  1157. if (map[m].flag.sakura)
  1158. clif_specialeffect_single(&sd->bl, 163, fd);
  1159. if (map[m].flag.leaves)
  1160. clif_specialeffect_single(&sd->bl, 333, fd);
  1161. }
  1162. }
  1163. /**
  1164. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1165. **/
  1166. void clif_weather(int16 m)
  1167. {
  1168. struct s_mapiterator* iter;
  1169. struct map_session_data *sd=NULL;
  1170. iter = mapit_getallusers();
  1171. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1172. {
  1173. if( sd->bl.m == m )
  1174. clif_weather_check(sd);
  1175. }
  1176. mapit_free(iter);
  1177. }
  1178. /**
  1179. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1180. **/
  1181. int clif_spawn(struct block_list *bl)
  1182. {
  1183. unsigned char buf[128];
  1184. struct view_data *vd;
  1185. struct status_change *sc = status_get_sc(bl);
  1186. int len;
  1187. vd = status_get_viewdata(bl);
  1188. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1189. return 0;
  1190. /**
  1191. * Hide NPC from maya purple card.
  1192. **/
  1193. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1194. return 0;
  1195. len = clif_set_unit_idle(bl, buf,true);
  1196. clif_send(buf, len, bl, AREA_WOS);
  1197. if (disguised(bl))
  1198. clif_setdisguise(bl, buf, len);
  1199. if (vd->cloth_color)
  1200. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1201. switch (bl->type)
  1202. {
  1203. case BL_PC:
  1204. {
  1205. TBL_PC *sd = ((TBL_PC*)bl);
  1206. int i;
  1207. if (sd->spiritball > 0)
  1208. clif_spiritball(&sd->bl);
  1209. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1210. clif_specialeffect(bl,423,AREA);
  1211. else if(sd->state.size==SZ_MEDIUM)
  1212. clif_specialeffect(bl,421,AREA);
  1213. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1214. clif_sendbgemblem_area(sd);
  1215. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1216. clif_spiritcharm(sd);
  1217. for (i = 0; i < sd->sc_display_count; i++) {
  1218. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1219. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1220. else
  1221. clif_status_change2(&sd->bl,sd->bl.id,AREA,StatusIconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3);
  1222. }
  1223. if (sd->status.robe)
  1224. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1225. }
  1226. break;
  1227. case BL_MOB:
  1228. {
  1229. TBL_MOB *md = ((TBL_MOB*)bl);
  1230. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1231. clif_specialeffect(&md->bl,423,AREA);
  1232. else if(md->special_state.size==SZ_MEDIUM)
  1233. clif_specialeffect(&md->bl,421,AREA);
  1234. }
  1235. break;
  1236. case BL_NPC:
  1237. {
  1238. TBL_NPC *nd = ((TBL_NPC*)bl);
  1239. if( nd->size == SZ_BIG )
  1240. clif_specialeffect(&nd->bl,423,AREA);
  1241. else if( nd->size == SZ_MEDIUM )
  1242. clif_specialeffect(&nd->bl,421,AREA);
  1243. }
  1244. break;
  1245. case BL_PET:
  1246. if (vd->head_bottom)
  1247. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1248. break;
  1249. }
  1250. return 0;
  1251. }
  1252. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1253. /// 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
  1254. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1255. {
  1256. struct status_data *status;
  1257. unsigned char buf[128];
  1258. int htype;
  1259. nullpo_retv(hd);
  1260. if (!clif_session_isValid(sd))
  1261. return;
  1262. status = &hd->battle_status;
  1263. htype = hom_class2type(hd->homunculus.class_);
  1264. memset(buf,0,packet_len(0x22e));
  1265. WBUFW(buf,0)=0x22e;
  1266. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1267. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1268. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1269. WBUFW(buf,27)=hd->homunculus.level;
  1270. WBUFW(buf,29)=hd->homunculus.hunger;
  1271. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1272. WBUFW(buf,33)=0; // equip id
  1273. #ifdef RENEWAL
  1274. WBUFW(buf,35)=cap_value(status->rhw.atk2, 0, INT16_MAX);
  1275. #else
  1276. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1277. #endif
  1278. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1279. WBUFW(buf,39)=status->hit;
  1280. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1281. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1282. else
  1283. WBUFW(buf,41)=status->cri/10;
  1284. #ifdef RENEWAL
  1285. WBUFW(buf,43)=status->def + status->def2;
  1286. WBUFW(buf,45)=status->mdef + status->mdef2;
  1287. #else
  1288. WBUFW(buf,43)=status->def + status->vit;
  1289. WBUFW(buf,45)=status->mdef;
  1290. #endif
  1291. WBUFW(buf,47)=status->flee;
  1292. WBUFW(buf,49)=(flag)?0:status->amotion;
  1293. if (status->max_hp > INT16_MAX) {
  1294. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1295. WBUFW(buf,53) = 100;
  1296. } else {
  1297. WBUFW(buf,51)=status->hp;
  1298. WBUFW(buf,53)=status->max_hp;
  1299. }
  1300. if (status->max_sp > INT16_MAX) {
  1301. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1302. WBUFW(buf,57) = 100;
  1303. } else {
  1304. WBUFW(buf,55)=status->sp;
  1305. WBUFW(buf,57)=status->max_sp;
  1306. }
  1307. WBUFL(buf,59)=hd->homunculus.exp;
  1308. WBUFL(buf,63)=hd->exp_next;
  1309. switch( htype ) {
  1310. case HT_REG:
  1311. case HT_EVO:
  1312. if( hd->homunculus.level >= battle_config.hom_max_level )
  1313. WBUFL(buf,63)=0;
  1314. break;
  1315. case HT_S:
  1316. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1317. WBUFL(buf,63)=0;
  1318. break;
  1319. }
  1320. WBUFW(buf,67)=hd->homunculus.skillpts;
  1321. WBUFW(buf,69)=status_get_range(&hd->bl);
  1322. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1323. }
  1324. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1325. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1326. /// type:
  1327. /// unused
  1328. /// state:
  1329. /// 0 = pre-init
  1330. /// 1 = intimacy
  1331. /// 2 = hunger
  1332. /// 3 = accessory?
  1333. /// ? = ignored
  1334. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1335. { //[orn]
  1336. int fd = sd->fd;
  1337. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1338. hom_calc_skilltree(sd->hd, 0);
  1339. WFIFOHEAD(fd, packet_len(0x230));
  1340. WFIFOW(fd,0)=0x230;
  1341. WFIFOB(fd,2)=0;
  1342. WFIFOB(fd,3)=state;
  1343. WFIFOL(fd,4)=sd->hd->bl.id;
  1344. WFIFOL(fd,8)=param;
  1345. WFIFOSET(fd,packet_len(0x230));
  1346. }
  1347. int clif_homskillinfoblock(struct map_session_data *sd)
  1348. { //[orn]
  1349. struct homun_data *hd;
  1350. int fd = sd->fd;
  1351. int i, len=4;
  1352. nullpo_ret(sd);
  1353. hd = sd->hd;
  1354. if ( !hd )
  1355. return 0 ;
  1356. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1357. WFIFOW(fd,0)=0x235;
  1358. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1359. int id = hd->homunculus.hskill[i].id;
  1360. if( id != 0 ){
  1361. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1362. short idx = hom_skill_get_index(id);
  1363. if (idx == -1)
  1364. continue;
  1365. WFIFOW(fd,len ) = id;
  1366. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1367. WFIFOW(fd,len+4) = 0;
  1368. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1369. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1370. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[idx].lv);
  1371. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1372. 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;
  1373. len+=37;
  1374. }
  1375. }
  1376. WFIFOW(fd,2)=len;
  1377. WFIFOSET(fd,len);
  1378. return 0;
  1379. }
  1380. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1381. { //[orn]
  1382. struct homun_data *hd;
  1383. int fd;
  1384. short idx = -1;
  1385. nullpo_retv(sd);
  1386. if ((idx = hom_skill_get_index(skill_id) == -1))
  1387. return;
  1388. fd = sd->fd;
  1389. hd = sd->hd;
  1390. WFIFOHEAD(fd, packet_len(0x239));
  1391. WFIFOW(fd,0) = 0x239;
  1392. WFIFOW(fd,2) = skill_id;
  1393. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1394. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1395. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1396. 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;
  1397. WFIFOSET(fd,packet_len(0x239));
  1398. }
  1399. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1400. {
  1401. int fd=sd->fd;
  1402. WFIFOHEAD(fd,packet_len(0x22f));
  1403. WFIFOW(fd,0)=0x22f;
  1404. WFIFOB(fd,2)=fail;
  1405. WFIFOW(fd,3)=foodid;
  1406. WFIFOSET(fd,packet_len(0x22f));
  1407. return 0;
  1408. }
  1409. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1410. /// 0087 <walk start time>.L <walk data>.6B
  1411. void clif_walkok(struct map_session_data *sd)
  1412. {
  1413. int fd=sd->fd;
  1414. WFIFOHEAD(fd, packet_len(0x87));
  1415. WFIFOW(fd,0)=0x87;
  1416. WFIFOL(fd,2)=gettick();
  1417. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1418. WFIFOSET(fd,packet_len(0x87));
  1419. }
  1420. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1421. {
  1422. uint8 buf[128];
  1423. int len;
  1424. struct status_change *sc = NULL;
  1425. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1426. clif_ally_only = true;
  1427. len = clif_set_unit_walking(bl,ud,buf);
  1428. clif_send(buf,len,bl,AREA_WOS);
  1429. if (disguised(bl))
  1430. clif_setdisguise(bl, buf, len);
  1431. if(vd->cloth_color)
  1432. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1433. switch(bl->type) {
  1434. case BL_PC:
  1435. {
  1436. TBL_PC *sd = ((TBL_PC*)bl);
  1437. // clif_movepc(sd);
  1438. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1439. clif_specialeffect(&sd->bl,423,AREA);
  1440. else if(sd->state.size==SZ_MEDIUM)
  1441. clif_specialeffect(&sd->bl,421,AREA);
  1442. }
  1443. break;
  1444. case BL_MOB:
  1445. {
  1446. TBL_MOB *md = ((TBL_MOB*)bl);
  1447. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1448. clif_specialeffect(&md->bl,423,AREA);
  1449. else if(md->special_state.size==SZ_MEDIUM)
  1450. clif_specialeffect(&md->bl,421,AREA);
  1451. }
  1452. break;
  1453. case BL_PET:
  1454. if(vd->head_bottom) // needed to display pet equip properly
  1455. clif_pet_equip_area((TBL_PET*)bl);
  1456. break;
  1457. }
  1458. clif_ally_only = false;
  1459. }
  1460. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1461. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1462. /// Note: unit must not be self
  1463. void clif_move(struct unit_data *ud)
  1464. {
  1465. unsigned char buf[16];
  1466. struct view_data* vd;
  1467. struct block_list* bl = ud->bl;
  1468. struct status_change *sc = NULL;
  1469. vd = status_get_viewdata(bl);
  1470. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1471. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1472. /**
  1473. * Hide NPC from maya purple card.
  1474. **/
  1475. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1476. return;
  1477. if (ud->state.speed_changed) {
  1478. // Since we don't know how to update the speed of other objects,
  1479. // use the old walk packet to update the data.
  1480. ud->state.speed_changed = 0;
  1481. clif_move2(bl, vd, ud);
  1482. return;
  1483. }
  1484. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1485. clif_ally_only = true;
  1486. WBUFW(buf,0)=0x86;
  1487. WBUFL(buf,2)=bl->id;
  1488. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1489. WBUFL(buf,12)=gettick();
  1490. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1491. if (disguised(bl)) {
  1492. WBUFL(buf,2)=-bl->id;
  1493. clif_send(buf, packet_len(0x86), bl, SELF);
  1494. }
  1495. clif_ally_only = false;
  1496. }
  1497. /*==========================================
  1498. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1499. *------------------------------------------*/
  1500. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1501. {
  1502. struct map_session_data *sd = NULL;
  1503. //Remove player from map server
  1504. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1505. map_quit(sd);
  1506. return 0;
  1507. }
  1508. /*==========================================
  1509. *
  1510. *------------------------------------------*/
  1511. void clif_quitsave(int fd,struct map_session_data *sd) {
  1512. if (!battle_config.prevent_logout ||
  1513. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1514. map_quit(sd);
  1515. else if (sd->fd) {
  1516. //Disassociate session from player (session is deleted after this function was called)
  1517. //And set a timer to make him quit later.
  1518. session[sd->fd]->session_data = NULL;
  1519. sd->fd = 0;
  1520. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1521. }
  1522. }
  1523. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1524. /// 0091 <map name>.16B <x>.W <y>.W
  1525. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1526. {
  1527. int fd;
  1528. nullpo_retv(sd);
  1529. fd = sd->fd;
  1530. WFIFOHEAD(fd,packet_len(0x91));
  1531. WFIFOW(fd,0) = 0x91;
  1532. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1533. WFIFOW(fd,18) = x;
  1534. WFIFOW(fd,20) = y;
  1535. WFIFOSET(fd,packet_len(0x91));
  1536. }
  1537. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1538. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1539. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1540. {
  1541. int fd;
  1542. nullpo_retv(sd);
  1543. fd = sd->fd;
  1544. WFIFOHEAD(fd,packet_len(0x92));
  1545. WFIFOW(fd,0) = 0x92;
  1546. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1547. WFIFOW(fd,18) = x;
  1548. WFIFOW(fd,20) = y;
  1549. WFIFOL(fd,22) = htonl(ip);
  1550. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1551. WFIFOSET(fd,packet_len(0x92));
  1552. }
  1553. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1554. /// This function combines both calls and allows to simplify the calling code
  1555. void clif_blown(struct block_list *bl)
  1556. {
  1557. clif_slide(bl, bl->x, bl->y);
  1558. clif_fixpos(bl);
  1559. }
  1560. /// Visually moves(slides) a character to x,y. If the target cell
  1561. /// isn't walkable, the char doesn't move at all. If the char is
  1562. /// sitting it will stand up (ZC_STOPMOVE).
  1563. /// 0088 <id>.L <x>.W <y>.W
  1564. void clif_fixpos(struct block_list *bl)
  1565. {
  1566. unsigned char buf[10];
  1567. nullpo_retv(bl);
  1568. WBUFW(buf,0) = 0x88;
  1569. WBUFL(buf,2) = bl->id;
  1570. WBUFW(buf,6) = bl->x;
  1571. WBUFW(buf,8) = bl->y;
  1572. clif_send(buf, packet_len(0x88), bl, AREA);
  1573. if( disguised(bl) ) {
  1574. WBUFL(buf,2) = -bl->id;
  1575. clif_send(buf, packet_len(0x88), bl, SELF);
  1576. }
  1577. }
  1578. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1579. /// 00c4 <shop id>.L
  1580. void clif_npcbuysell(struct map_session_data* sd, int id)
  1581. {
  1582. int fd;
  1583. nullpo_retv(sd);
  1584. fd=sd->fd;
  1585. WFIFOHEAD(fd, packet_len(0xc4));
  1586. WFIFOW(fd,0)=0xc4;
  1587. WFIFOL(fd,2)=id;
  1588. WFIFOSET(fd,packet_len(0xc4));
  1589. }
  1590. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1591. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1592. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1593. {
  1594. int fd,i,c;
  1595. bool discount;
  1596. nullpo_retv(sd);
  1597. nullpo_retv(nd);
  1598. fd = sd->fd;
  1599. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1600. WFIFOW(fd,0) = 0xc6;
  1601. c = 0;
  1602. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1603. for( i = 0; i < nd->u.shop.count; i++ )
  1604. {
  1605. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1606. int val = nd->u.shop.shop_item[i].value;
  1607. if( id == NULL )
  1608. continue;
  1609. WFIFOL(fd, 4+c*11) = val;
  1610. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1611. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1612. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1613. c++;
  1614. }
  1615. WFIFOW(fd,2) = 4 + c*11;
  1616. WFIFOSET(fd,WFIFOW(fd,2));
  1617. }
  1618. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1619. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1620. void clif_selllist(struct map_session_data *sd)
  1621. {
  1622. int fd,i,c=0,val;
  1623. nullpo_retv(sd);
  1624. fd=sd->fd;
  1625. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1626. WFIFOW(fd,0)=0xc7;
  1627. for( i = 0; i < MAX_INVENTORY; i++ )
  1628. {
  1629. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1630. {
  1631. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1632. continue;
  1633. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1634. continue; // Cannot Sell Rental Items or Account Bounded Items
  1635. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1636. continue; // Don't allow sale of bound items
  1637. val=sd->inventory_data[i]->value_sell;
  1638. if( val < 0 )
  1639. continue;
  1640. WFIFOW(fd,4+c*10)=i+2;
  1641. WFIFOL(fd,6+c*10)=val;
  1642. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1643. c++;
  1644. }
  1645. }
  1646. WFIFOW(fd,2)=c*10+4;
  1647. WFIFOSET(fd,WFIFOW(fd,2));
  1648. }
  1649. /**
  1650. * Presents list of items, that can be sold to a Market shop.
  1651. * @author: Ind and Yommy
  1652. **/
  1653. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1654. #if PACKETVER >= 20131223
  1655. struct npc_item_list *shop = nd->u.shop.shop_item;
  1656. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1657. struct item_data *id = NULL;
  1658. struct s_packet_db *info;
  1659. int fd;
  1660. nullpo_retv(sd);
  1661. if (sd->state.trading)
  1662. return;
  1663. info = &packet_db[sd->packet_ver][cmd];
  1664. if (!info || info->len == 0)
  1665. return;
  1666. fd = sd->fd;
  1667. WFIFOHEAD(fd, 4 + shop_size * 13);
  1668. WFIFOW(fd,0) = cmd;
  1669. for (i = 0, c = 0; i < shop_size; i++) {
  1670. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1671. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1672. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1673. WFIFOL(fd, 7+c*13) = shop[i].value;
  1674. WFIFOL(fd,11+c*13) = shop[i].qty;
  1675. WFIFOW(fd,15+c*13) = (id->view_id > 0) ? id->view_id : id->nameid;
  1676. c++;
  1677. }
  1678. }
  1679. WFIFOW(fd,2) = 4 + c*13;
  1680. WFIFOSET(fd,WFIFOW(fd,2));
  1681. sd->state.trading = 1;
  1682. #endif
  1683. }
  1684. /// Closes the Market shop window.
  1685. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1686. nullpo_retv(sd);
  1687. sd->npc_shopid = 0;
  1688. sd->state.trading = 0;
  1689. }
  1690. /// Purchase item from Market shop.
  1691. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1692. #if PACKETVER >= 20131223
  1693. unsigned short cmd = 0x9d7, len = 0;
  1694. struct npc_data* nd;
  1695. uint8 result = (res == 0 ? 1 : 0);
  1696. int fd = 0;
  1697. struct s_packet_db *info;
  1698. nullpo_retv(sd);
  1699. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1700. info = &packet_db[sd->packet_ver][cmd];
  1701. if (!info || info->len == 0)
  1702. return;
  1703. fd = sd->fd;
  1704. len = 5 + 8*n;
  1705. WFIFOHEAD(fd, len);
  1706. WFIFOW(fd, 0) = cmd;
  1707. WFIFOW(fd, 2) = len;
  1708. if (result) {
  1709. uint8 i, j;
  1710. struct npc_item_list *shop = nd->u.shop.shop_item;
  1711. unsigned short count = nd->u.shop.count;
  1712. for (i = 0; i < n; i++) {
  1713. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1714. WFIFOW(fd, 7+i*8) = list[i].qty;
  1715. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1716. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1717. }
  1718. }
  1719. WFIFOB(fd, 4) = n;
  1720. WFIFOSET(fd, len);
  1721. #endif
  1722. }
  1723. /// Purchase item from Market shop.
  1724. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1725. #if PACKETVER >= 20131223
  1726. struct s_packet_db* info;
  1727. struct s_npc_buy_list *item_list;
  1728. uint16 len = 0, i = 0;
  1729. uint8 res = 0, n = 0;
  1730. nullpo_retv(sd);
  1731. if (!sd->npc_shopid)
  1732. return;
  1733. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  1734. if (!info || info->len == 0)
  1735. return;
  1736. len = RFIFOW(fd,info->pos[0]);
  1737. n = (len-4) / 6;
  1738. CREATE(item_list, struct s_npc_buy_list, n);
  1739. for (i = 0; i < n; i++) {
  1740. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1741. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1742. }
  1743. res = npc_buylist(sd, n, item_list);
  1744. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1745. aFree(item_list);
  1746. #endif
  1747. }
  1748. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1749. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1750. /// Client behavior (dialog window):
  1751. /// - disable mouse targeting
  1752. /// - open the dialog window
  1753. /// - set npcid of dialog window (0 by default)
  1754. /// - if set to clear on next mes, clear contents
  1755. /// - append this text
  1756. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1757. {
  1758. int fd = sd->fd;
  1759. int slen = strlen(mes) + 9;
  1760. WFIFOHEAD(fd, slen);
  1761. WFIFOW(fd,0)=0xb4;
  1762. WFIFOW(fd,2)=slen;
  1763. WFIFOL(fd,4)=npcid;
  1764. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1765. WFIFOSET(fd,WFIFOW(fd,2));
  1766. }
  1767. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1768. /// 00b5 <npc id>.L
  1769. /// Client behavior (dialog window):
  1770. /// - disable mouse targeting
  1771. /// - open the dialog window
  1772. /// - add 'next' button
  1773. /// When 'next' is pressed:
  1774. /// - 00B9 <npcid of dialog window>.L
  1775. /// - set to clear on next mes
  1776. /// - remove 'next' button
  1777. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1778. {
  1779. int fd;
  1780. nullpo_retv(sd);
  1781. fd=sd->fd;
  1782. WFIFOHEAD(fd, packet_len(0xb5));
  1783. WFIFOW(fd,0)=0xb5;
  1784. WFIFOL(fd,2)=npcid;
  1785. WFIFOSET(fd,packet_len(0xb5));
  1786. }
  1787. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1788. /// 00b6 <npc id>.L
  1789. /// Client behavior:
  1790. /// - if dialog window is open:
  1791. /// - remove 'next' button
  1792. /// - add 'close' button
  1793. /// - else:
  1794. /// - enable mouse targeting
  1795. /// - close the dialog window
  1796. /// - close the menu window
  1797. /// When 'close' is pressed:
  1798. /// - enable mouse targeting
  1799. /// - close the dialog window
  1800. /// - close the menu window
  1801. /// - 0146 <npcid of dialog window>.L
  1802. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1803. {
  1804. int fd;
  1805. nullpo_retv(sd);
  1806. fd=sd->fd;
  1807. WFIFOHEAD(fd, packet_len(0xb6));
  1808. WFIFOW(fd,0)=0xb6;
  1809. WFIFOL(fd,2)=npcid;
  1810. WFIFOSET(fd,packet_len(0xb6));
  1811. }
  1812. /**
  1813. * Close script when player is idle
  1814. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1815. * @author [Ind/Hercules]
  1816. * @param sd : player pointer
  1817. * @param npcid : npc gid to close
  1818. */
  1819. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1820. {
  1821. struct s_packet_db* info;
  1822. int16 len;
  1823. int cmd = 0;
  1824. int fd;
  1825. nullpo_retv(sd);
  1826. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1827. if(!cmd) cmd = 0x8d6; //default
  1828. info = &packet_db[sd->packet_ver][cmd];
  1829. len = info->len;
  1830. fd = sd->fd;
  1831. WFIFOHEAD(fd, len);
  1832. WFIFOW(fd,0)=0x8d6;
  1833. WFIFOL(fd,info->pos[0])=npcid;
  1834. WFIFOSET(fd,len);
  1835. }
  1836. /*==========================================
  1837. *
  1838. *------------------------------------------*/
  1839. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1840. unsigned char *buf;
  1841. int fd = sd->fd;
  1842. sd->state.using_fake_npc = 1;
  1843. WFIFOHEAD(fd, packet_len(0x78));
  1844. buf = WFIFOP(fd,0);
  1845. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1846. WBUFW(buf,0)=0x78;
  1847. #if PACKETVER >= 20071106
  1848. WBUFB(buf,2) = 0; // object type
  1849. buf = WFIFOP(fd,1);
  1850. #endif
  1851. WBUFL(buf,2)=npcid;
  1852. WBUFW(buf,14)=111;
  1853. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1854. WBUFB(buf,49)=5;
  1855. WBUFB(buf,50)=5;
  1856. WFIFOSET(fd, packet_len(0x78));
  1857. }
  1858. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1859. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1860. /// Client behavior:
  1861. /// - disable mouse targeting
  1862. /// - close the menu window
  1863. /// - open the menu window
  1864. /// - add options to the menu (separated in the text by ":")
  1865. /// - set npcid of menu window
  1866. /// - if dialog window is open:
  1867. /// - remove 'next' button
  1868. /// When 'ok' is pressed:
  1869. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1870. /// - close the menu window
  1871. /// When 'cancel' is pressed:
  1872. /// - 00B8 <npcid of menu window>.L <-1>.B
  1873. /// - enable mouse targeting
  1874. /// - close a bunch of windows...
  1875. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1876. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1877. /// TODO investigate behavior of other windows [FlavioJS]
  1878. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1879. {
  1880. int fd = sd->fd;
  1881. int slen = strlen(mes) + 9;
  1882. struct block_list *bl = NULL;
  1883. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1884. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1885. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1886. clif_sendfakenpc(sd, npcid);
  1887. WFIFOHEAD(fd, slen);
  1888. WFIFOW(fd,0)=0xb7;
  1889. WFIFOW(fd,2)=slen;
  1890. WFIFOL(fd,4)=npcid;
  1891. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1892. WFIFOSET(fd,WFIFOW(fd,2));
  1893. }
  1894. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1895. /// 0142 <npc id>.L
  1896. /// Client behavior (inputnum window):
  1897. /// - if npcid exists in the client:
  1898. /// - open the inputnum window
  1899. /// - set npcid of inputnum window
  1900. /// When 'ok' is pressed:
  1901. /// - if inputnum window has text:
  1902. /// - if npcid exists in the client:
  1903. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1904. /// - close inputnum window
  1905. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1906. {
  1907. int fd;
  1908. struct block_list *bl = NULL;
  1909. nullpo_retv(sd);
  1910. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1911. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1912. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1913. clif_sendfakenpc(sd, npcid);
  1914. fd=sd->fd;
  1915. WFIFOHEAD(fd, packet_len(0x142));
  1916. WFIFOW(fd,0)=0x142;
  1917. WFIFOL(fd,2)=npcid;
  1918. WFIFOSET(fd,packet_len(0x142));
  1919. }
  1920. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1921. /// 01d4 <npc id>.L
  1922. /// Client behavior (inputstr window):
  1923. /// - if npcid is 0 or npcid exists in the client:
  1924. /// - open the inputstr window
  1925. /// - set npcid of inputstr window
  1926. /// When 'ok' is pressed:
  1927. /// - if inputstr window has text and isn't an insult(manner.txt):
  1928. /// - if npcid is 0 or npcid exists in the client:
  1929. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1930. /// - close inputstr window
  1931. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1932. {
  1933. int fd;
  1934. struct block_list *bl = NULL;
  1935. nullpo_retv(sd);
  1936. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1937. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1938. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1939. clif_sendfakenpc(sd, npcid);
  1940. fd=sd->fd;
  1941. WFIFOHEAD(fd, packet_len(0x1d4));
  1942. WFIFOW(fd,0)=0x1d4;
  1943. WFIFOL(fd,2)=npcid;
  1944. WFIFOSET(fd,packet_len(0x1d4));
  1945. }
  1946. /// Marks a position on client's minimap (ZC_COMPASS).
  1947. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1948. /// npc id:
  1949. /// is ignored in the client
  1950. /// type:
  1951. /// 0 = display mark for 15 seconds
  1952. /// 1 = display mark until dead or teleported
  1953. /// 2 = remove mark
  1954. /// color:
  1955. /// 0x00RRGGBB
  1956. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1957. {
  1958. int fd;
  1959. nullpo_retv(sd);
  1960. fd=sd->fd;
  1961. WFIFOHEAD(fd, packet_len(0x144));
  1962. WFIFOW(fd,0)=0x144;
  1963. WFIFOL(fd,2)=npc_id;
  1964. WFIFOL(fd,6)=type;
  1965. WFIFOL(fd,10)=x;
  1966. WFIFOL(fd,14)=y;
  1967. WFIFOB(fd,18)=id;
  1968. WFIFOL(fd,19)=color;
  1969. WFIFOSET(fd,packet_len(0x144));
  1970. }
  1971. /// Displays an illustration image.
  1972. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1973. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1974. /// type:
  1975. /// 0 = bottom left corner
  1976. /// 1 = bottom middle
  1977. /// 2 = bottom right corner
  1978. /// 3 = middle of screen, inside a movable window
  1979. /// 4 = middle of screen, movable with a close button, chrome-less
  1980. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1981. {
  1982. int fd;
  1983. nullpo_retv(sd);
  1984. fd=sd->fd;
  1985. WFIFOHEAD(fd, packet_len(0x1b3));
  1986. WFIFOW(fd,0)=0x1b3;
  1987. strncpy((char*)WFIFOP(fd,2),image,64);
  1988. WFIFOB(fd,66)=type;
  1989. WFIFOSET(fd,packet_len(0x1b3));
  1990. }
  1991. /*==========================================
  1992. * Fills in card data from the given item and into the buffer. [Skotlex]
  1993. *------------------------------------------*/
  1994. static void clif_addcards(unsigned char* buf, struct item* item)
  1995. {
  1996. int i=0,j;
  1997. if( item == NULL ) { //Blank data
  1998. WBUFW(buf,0) = 0;
  1999. WBUFW(buf,2) = 0;
  2000. WBUFW(buf,4) = 0;
  2001. WBUFW(buf,6) = 0;
  2002. return;
  2003. }
  2004. if( item->card[0] == CARD0_PET ) { //pet eggs
  2005. WBUFW(buf,0) = 0;
  2006. WBUFW(buf,2) = 0;
  2007. WBUFW(buf,4) = 0;
  2008. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2009. return;
  2010. }
  2011. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2012. WBUFW(buf,0) = item->card[0];
  2013. WBUFW(buf,2) = item->card[1];
  2014. WBUFW(buf,4) = item->card[2];
  2015. WBUFW(buf,6) = item->card[3];
  2016. return;
  2017. }
  2018. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2019. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2020. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2021. //Normal items.
  2022. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2023. WBUFW(buf,0) = j;
  2024. else
  2025. WBUFW(buf,0) = item->card[i];
  2026. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2027. WBUFW(buf,2) = j;
  2028. else
  2029. WBUFW(buf,2) = item->card[i];
  2030. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2031. WBUFW(buf,4) = j;
  2032. else
  2033. WBUFW(buf,4) = item->card[i];
  2034. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2035. WBUFW(buf,6) = j;
  2036. else
  2037. WBUFW(buf,6) = item->card[i];
  2038. }
  2039. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2040. /// 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)
  2041. /// 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)
  2042. /// 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)
  2043. /// 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)
  2044. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2045. {
  2046. int fd, header, offs=0;
  2047. #if PACKETVER < 20061218
  2048. header = 0xa0;
  2049. #elif PACKETVER < 20071002
  2050. header = 0x29a;
  2051. #elif PACKETVER < 20120925
  2052. header = 0x2d4;
  2053. #else
  2054. header = 0x990;
  2055. #endif
  2056. nullpo_retv(sd);
  2057. fd = sd->fd;
  2058. if( !session_isActive(fd) ) //Sasuke-
  2059. return;
  2060. WFIFOHEAD(fd,packet_len(header));
  2061. if( fail )
  2062. {
  2063. WFIFOW(fd,offs+0) = header;
  2064. WFIFOW(fd,offs+2) = n+2;
  2065. WFIFOW(fd,offs+4) = amount;
  2066. WFIFOW(fd,offs+6) = 0;
  2067. WFIFOB(fd,offs+8) = 0;
  2068. WFIFOB(fd,offs+9) = 0;
  2069. WFIFOB(fd,offs+10) = 0;
  2070. WFIFOW(fd,offs+11) = 0;
  2071. WFIFOW(fd,offs+13) = 0;
  2072. WFIFOW(fd,offs+15) = 0;
  2073. WFIFOW(fd,offs+17) = 0;
  2074. #if PACKETVER < 20120925
  2075. WFIFOW(fd,offs+19) = 0;
  2076. #else
  2077. WFIFOL(fd,offs+19) = 0;
  2078. offs += 2;
  2079. #endif
  2080. WFIFOB(fd,offs+21) = 0;
  2081. WFIFOB(fd,offs+22) = fail;
  2082. #if PACKETVER >= 20061218
  2083. WFIFOL(fd,offs+23) = 0;
  2084. #endif
  2085. #if PACKETVER >= 20071002
  2086. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2087. #endif
  2088. }
  2089. else
  2090. {
  2091. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2092. return;
  2093. WFIFOW(fd,offs+0) = header;
  2094. WFIFOW(fd,offs+2) = n+2;
  2095. WFIFOW(fd,offs+4) = amount;
  2096. if (sd->inventory_data[n]->view_id > 0)
  2097. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2098. else
  2099. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  2100. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  2101. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  2102. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  2103. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  2104. #if PACKETVER < 20120925
  2105. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2106. #else
  2107. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2108. offs += 2;
  2109. #endif
  2110. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2111. WFIFOB(fd,offs+22) = fail;
  2112. #if PACKETVER >= 20061218
  2113. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  2114. #endif
  2115. #if PACKETVER >= 20071002
  2116. /* Yellow color only for non-stackable item */
  2117. 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;
  2118. #endif
  2119. }
  2120. WFIFOSET(fd,packet_len(header));
  2121. }
  2122. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2123. /// 00af <index>.W <amount>.W
  2124. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2125. {
  2126. int fd;
  2127. nullpo_retv(sd);
  2128. fd=sd->fd;
  2129. WFIFOHEAD(fd, packet_len(0xaf));
  2130. WFIFOW(fd,0)=0xaf;
  2131. WFIFOW(fd,2)=n+2;
  2132. WFIFOW(fd,4)=amount;
  2133. WFIFOSET(fd,packet_len(0xaf));
  2134. }
  2135. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2136. /// 07fa <delete type>.W <index>.W <amount>.W
  2137. /// delete type:
  2138. /// 0 = Normal
  2139. /// 1 = Item used for a skill
  2140. /// 2 = Refine failed
  2141. /// 3 = Material changed
  2142. /// 4 = Moved to storage
  2143. /// 5 = Moved to cart
  2144. /// 6 = Item sold
  2145. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2146. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2147. {
  2148. #if PACKETVER < 20091117
  2149. clif_dropitem(sd,n,amount);
  2150. #else
  2151. int fd;
  2152. nullpo_retv(sd);
  2153. fd=sd->fd;
  2154. WFIFOHEAD(fd, packet_len(0x7fa));
  2155. WFIFOW(fd,0)=0x7fa;
  2156. WFIFOW(fd,2)=reason;
  2157. WFIFOW(fd,4)=n+2;
  2158. WFIFOW(fd,6)=amount;
  2159. WFIFOSET(fd,packet_len(0x7fa));
  2160. #endif
  2161. }
  2162. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2163. char normal = (equip < 0);
  2164. WBUFW(buf,n) = idx; //index
  2165. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2166. WBUFB(buf,n+4) = itemtype(id->nameid);
  2167. if (!normal){ //equip 31B
  2168. WBUFL(buf,n+5) = equip; //location
  2169. WBUFL(buf,n+9) = it->equip; //wear state
  2170. WBUFB(buf,n+13) = it->refine; //refine lvl
  2171. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2172. WBUFL(buf,n+22) = it->expire_time;
  2173. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2174. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2175. //V5_ITEM_flag
  2176. WBUFB(buf,n+30) = it->identify; //0x1 IsIdentified
  2177. WBUFB(buf,n+30) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2178. WBUFB(buf,n+30) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2179. }
  2180. else { //normal 24B
  2181. WBUFW(buf,n+5) = it->amount;
  2182. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2183. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2184. WBUFL(buf,n+19) = it->expire_time;
  2185. //V5_ITEM_flag
  2186. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2187. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2188. }
  2189. }
  2190. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2191. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2192. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2193. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2194. #if PACKETVER >= 20120925
  2195. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2196. #else
  2197. WBUFW(buf,n) = idx; //index
  2198. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2199. WBUFB(buf,n+4) = itemtype(id->nameid);
  2200. WBUFB(buf,n+5) = it->identify;
  2201. if (equip >= 0) { //Equippable item 28.B
  2202. WBUFW(buf,n+6) = equip;
  2203. WBUFW(buf,n+8) = it->equip;
  2204. WBUFB(buf,n+10) = it->attribute;
  2205. WBUFB(buf,n+11) = it->refine;
  2206. clif_addcards(WBUFP(buf, n+12), it); //8B
  2207. #if PACKETVER >= 20071002
  2208. WBUFL(buf,n+20) = it->expire_time;
  2209. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2210. #endif
  2211. #if PACKETVER >= 20100629
  2212. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2213. #endif
  2214. } else { //Stackable item. 22.B
  2215. WBUFW(buf,n+6) = it->amount;
  2216. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2217. clif_addcards(WBUFP(buf, n+10), it); //8B
  2218. #if PACKETVER >= 20071002
  2219. WBUFL(buf,n+18) = it->expire_time;
  2220. #endif
  2221. }
  2222. #endif
  2223. }
  2224. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2225. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2226. void clif_inventorylist(struct map_session_data *sd) {
  2227. int i,n,ne,arrow=-1;
  2228. unsigned char *buf;
  2229. unsigned char *bufe;
  2230. #if PACKETVER < 5
  2231. const int s = 10; //Entry size
  2232. #elif PACKETVER < 20080102
  2233. const int s = 18;
  2234. #elif PACKETVER < 20120925
  2235. const int s = 22;
  2236. #else
  2237. const int s = 24;
  2238. #endif
  2239. #if PACKETVER < 20071002
  2240. const int se = 20;
  2241. #elif PACKETVER < 20100629
  2242. const int se = 26;
  2243. #elif PACKETVER < 20120925
  2244. const int se = 28;
  2245. #else
  2246. const int se = 31;
  2247. #endif
  2248. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2249. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2250. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2251. {
  2252. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2253. continue;
  2254. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2255. { //Non-stackable (Equippable)
  2256. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2257. ne++;
  2258. }
  2259. else { //Stackable.
  2260. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2261. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2262. arrow=i;
  2263. n++;
  2264. }
  2265. }
  2266. if( n )
  2267. {
  2268. #if PACKETVER < 5
  2269. WBUFW(buf,0)=0xa3;
  2270. #elif PACKETVER < 20080102
  2271. WBUFW(buf,0)=0x1ee;
  2272. #elif PACKETVER < 20120925
  2273. WBUFW(buf,0)=0x2e8;
  2274. #else
  2275. WBUFW(buf,0)=0x991;
  2276. #endif
  2277. WBUFW(buf,2)=4+n*s;
  2278. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2279. }
  2280. if( arrow >= 0 )
  2281. clif_arrowequip(sd,arrow);
  2282. if( ne ) {
  2283. #if PACKETVER < 20071002
  2284. WBUFW(bufe,0)=0xa4;
  2285. #elif PACKETVER < 20120925
  2286. WBUFW(bufe,0)=0x2d0;
  2287. #else
  2288. WBUFW(bufe,0)=0x992;
  2289. #endif
  2290. WBUFW(bufe,2)=4+ne*se;
  2291. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2292. }
  2293. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2294. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2295. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2296. continue;
  2297. if ( sd->status.inventory[i].favorite )
  2298. clif_favorite_item(sd, i);
  2299. }
  2300. #endif
  2301. if( buf ) aFree(buf);
  2302. if( bufe ) aFree(bufe);
  2303. }
  2304. //Required when items break/get-repaired. Only sends equippable item list.
  2305. void clif_equiplist(struct map_session_data *sd)
  2306. {
  2307. int i,n,fd = sd->fd;
  2308. unsigned char *buf;
  2309. #if PACKETVER < 20071002
  2310. const int cmd = 20;
  2311. #elif PACKETVER < 20100629
  2312. const int cmd = 26;
  2313. #elif PACKETVER < 20120925
  2314. const int cmd = 28;
  2315. #else
  2316. const int cmd = 31;
  2317. #endif
  2318. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2319. buf = WFIFOP(fd,0);
  2320. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2321. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2322. continue;
  2323. if(itemdb_isstackable2(sd->inventory_data[i]))
  2324. continue;
  2325. //Equippable
  2326. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2327. n++;
  2328. }
  2329. if (n) {
  2330. #if PACKETVER < 20071002
  2331. WBUFW(buf,0)=0xa4;
  2332. #elif PACKETVER < 20120925
  2333. WBUFW(buf,0)=0x2d0;
  2334. #else
  2335. WBUFW(buf,0)=0x992;
  2336. #endif
  2337. WBUFW(buf,2)=4+n*cmd;
  2338. WFIFOSET(fd,WFIFOW(fd,2));
  2339. }
  2340. }
  2341. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2342. {
  2343. static const int client_buf = 0x5000; // Max buffer to send
  2344. struct item_data *id;
  2345. int i,n,ne,nn;
  2346. unsigned char *buf;
  2347. unsigned char *bufe;
  2348. #if PACKETVER < 5
  2349. const int s = 10; //Entry size.normal item
  2350. const int sidx=4; //start itemlist idx
  2351. const int cmd = 0xa5;
  2352. #elif PACKETVER < 20080102
  2353. const int s = 18;
  2354. const int sidx=4;
  2355. const int cmd = 0x1f0;
  2356. #elif PACKETVER < 20120925
  2357. const int s = 22;
  2358. const int sidx=4;
  2359. const int cmd = 0x2ea;
  2360. #else
  2361. const int s = 24;
  2362. const int sidx = 4+24;
  2363. const int cmd = 0x995;
  2364. #endif
  2365. #if PACKETVER < 20071002
  2366. const int se = 20; //entry size equip
  2367. const int sidxe = 4; //start itemlist idx
  2368. const int cmde = 0xa6;
  2369. #elif PACKETVER < 20100629
  2370. const int se = 26;
  2371. const int sidxe = 4;
  2372. const int cmde = 0x2d1;
  2373. #elif PACKETVER < 20120925
  2374. const int se = 28;
  2375. const int sidxe = 4;
  2376. const int cmde = 0x2d1;
  2377. #else
  2378. const int se = 31;
  2379. const int sidxe = 4+24;
  2380. const int cmde = 0x996;
  2381. #endif
  2382. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2383. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2384. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2385. {
  2386. if( items[i].nameid <= 0 )
  2387. continue;
  2388. id = itemdb_search(items[i].nameid);
  2389. if( !itemdb_isstackable2(id) ) { //Equippable
  2390. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2391. ne++;
  2392. }
  2393. else { //Stackable
  2394. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2395. n++;
  2396. }
  2397. }
  2398. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2399. {
  2400. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2401. WFIFOHEAD(sd->fd,sidx+nn*s);
  2402. WFIFOW(sd->fd,0)=cmd;
  2403. WFIFOW(sd->fd,2)=sidx+nn*s;
  2404. #if PACKETVER >= 20120925
  2405. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2406. #endif
  2407. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2408. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2409. }
  2410. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2411. {
  2412. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2413. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2414. WFIFOW(sd->fd,0)=cmde;
  2415. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2416. #if PACKETVER >= 20120925
  2417. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2418. #endif
  2419. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2420. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2421. }
  2422. if( buf ) aFree(buf);
  2423. if( bufe ) aFree(bufe);
  2424. }
  2425. void clif_cartlist(struct map_session_data *sd)
  2426. {
  2427. struct item_data *id;
  2428. int i,n,ne;
  2429. unsigned char *buf;
  2430. unsigned char *bufe;
  2431. #if PACKETVER < 5
  2432. const int s = 10; //Entry size.
  2433. #elif PACKETVER < 20080102
  2434. const int s = 18;
  2435. #elif PACKETVER < 20120925
  2436. const int s = 22;
  2437. #else
  2438. const int s = 24;
  2439. #endif
  2440. #if PACKETVER < 20071002
  2441. const int cmd = 20;
  2442. #elif PACKETVER < 20100629
  2443. const int cmd = 26;
  2444. #elif PACKETVER < 20120925
  2445. const int cmd = 28;
  2446. #else
  2447. const int cmd = 31;
  2448. #endif
  2449. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2450. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2451. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2452. {
  2453. if( sd->status.cart[i].nameid <= 0 )
  2454. continue;
  2455. id = itemdb_search(sd->status.cart[i].nameid);
  2456. if( !itemdb_isstackable2(id) ) { //Equippable
  2457. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2458. ne++;
  2459. }
  2460. else { //Stackable
  2461. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2462. n++;
  2463. }
  2464. }
  2465. if( n )
  2466. {
  2467. #if PACKETVER < 5
  2468. WBUFW(buf,0)=0x123;
  2469. #elif PACKETVER < 20080102
  2470. WBUFW(buf,0)=0x1ef;
  2471. #elif PACKETVER < 20120925
  2472. WBUFW(buf,0)=0x2e9;
  2473. #else
  2474. WBUFW(buf,0)=0x993;
  2475. #endif
  2476. WBUFW(buf,2)=4+n*s;
  2477. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2478. }
  2479. if( ne )
  2480. {
  2481. #if PACKETVER < 20071002
  2482. WBUFW(bufe,0)=0x122;
  2483. #elif PACKETVER < 20120925
  2484. WBUFW(bufe,0)=0x2d2;
  2485. #else
  2486. WBUFW(bufe,0)=0x994;
  2487. #endif
  2488. WBUFW(bufe,2)=4+ne*cmd;
  2489. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2490. }
  2491. if( buf ) aFree(buf);
  2492. if( bufe ) aFree(bufe);
  2493. }
  2494. /// Removes cart (ZC_CARTOFF).
  2495. /// 012b
  2496. /// Client behaviour:
  2497. /// Closes the cart storage and removes all it's items from memory.
  2498. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2499. void clif_clearcart(int fd)
  2500. {
  2501. WFIFOHEAD(fd, packet_len(0x12b));
  2502. WFIFOW(fd,0) = 0x12b;
  2503. WFIFOSET(fd, packet_len(0x12b));
  2504. }
  2505. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2506. /// 01eb <account id>.L <x>.W <y>.W
  2507. void clif_guild_xy(struct map_session_data *sd)
  2508. {
  2509. unsigned char buf[10];
  2510. nullpo_retv(sd);
  2511. WBUFW(buf,0)=0x1eb;
  2512. WBUFL(buf,2)=sd->status.account_id;
  2513. WBUFW(buf,6)=sd->bl.x;
  2514. WBUFW(buf,8)=sd->bl.y;
  2515. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2516. }
  2517. /*==========================================
  2518. * Sends x/y dot to a single fd. [Skotlex]
  2519. *------------------------------------------*/
  2520. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2521. {
  2522. if( sd->bg_id )
  2523. return;
  2524. WFIFOHEAD(fd,packet_len(0x1eb));
  2525. WFIFOW(fd,0)=0x1eb;
  2526. WFIFOL(fd,2)=sd->status.account_id;
  2527. WFIFOW(fd,6)=sd->bl.x;
  2528. WFIFOW(fd,8)=sd->bl.y;
  2529. WFIFOSET(fd,packet_len(0x1eb));
  2530. }
  2531. // Guild XY locators [Valaris]
  2532. void clif_guild_xy_remove(struct map_session_data *sd)
  2533. {
  2534. unsigned char buf[10];
  2535. nullpo_retv(sd);
  2536. WBUFW(buf,0)=0x1eb;
  2537. WBUFL(buf,2)=sd->status.account_id;
  2538. WBUFW(buf,6)=-1;
  2539. WBUFW(buf,8)=-1;
  2540. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2541. }
  2542. /*==========================================
  2543. *
  2544. *------------------------------------------*/
  2545. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2546. {
  2547. struct map_session_data *sd, *tsd;
  2548. #if PACKETVER < 20100126
  2549. const int cmd = 0x106;
  2550. #else
  2551. const int cmd = 0x80e;
  2552. #endif
  2553. sd = va_arg(ap, struct map_session_data *);
  2554. tsd = (TBL_PC *)bl;
  2555. nullpo_ret(sd);
  2556. nullpo_ret(tsd);
  2557. if( !tsd->fd || tsd == sd )
  2558. return 0;
  2559. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2560. return 0;
  2561. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2562. WFIFOW(tsd->fd,0) = cmd;
  2563. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2564. #if PACKETVER < 20100126
  2565. if( sd->battle_status.max_hp > INT16_MAX )
  2566. { //To correctly display the %hp bar. [Skotlex]
  2567. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2568. WFIFOW(tsd->fd,8) = 100;
  2569. } else {
  2570. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2571. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2572. }
  2573. #else
  2574. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2575. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2576. #endif
  2577. WFIFOSET(tsd->fd,packet_len(cmd));
  2578. return 0;
  2579. }
  2580. /*==========================================
  2581. * Server tells all players that are allowed to view HP bars
  2582. * and are nearby 'sd' that 'sd' hp bar was updated.
  2583. *------------------------------------------*/
  2584. static int clif_hpmeter(struct map_session_data *sd)
  2585. {
  2586. nullpo_ret(sd);
  2587. 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);
  2588. return 0;
  2589. }
  2590. /// Notifies client of a character parameter change.
  2591. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2592. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2593. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2594. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2595. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2596. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2597. /// TODO: Extract individual packets.
  2598. /// FIXME: Packet lengths from packet_len(cmd)
  2599. void clif_updatestatus(struct map_session_data *sd,int type)
  2600. {
  2601. int fd,len=8;
  2602. nullpo_retv(sd);
  2603. fd=sd->fd;
  2604. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2605. return;
  2606. WFIFOHEAD(fd, 14);
  2607. WFIFOW(fd,0)=0xb0;
  2608. WFIFOW(fd,2)=type;
  2609. switch(type){
  2610. // 00b0
  2611. case SP_WEIGHT:
  2612. pc_updateweightstatus(sd);
  2613. WFIFOHEAD(fd,14);
  2614. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2615. WFIFOW(fd,2)=type;
  2616. WFIFOL(fd,4)=sd->weight;
  2617. break;
  2618. case SP_MAXWEIGHT:
  2619. WFIFOL(fd,4)=sd->max_weight;
  2620. break;
  2621. case SP_SPEED:
  2622. WFIFOL(fd,4)=sd->battle_status.speed;
  2623. break;
  2624. case SP_BASELEVEL:
  2625. WFIFOL(fd,4)=sd->status.base_level;
  2626. break;
  2627. case SP_JOBLEVEL:
  2628. WFIFOL(fd,4)=sd->status.job_level;
  2629. break;
  2630. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2631. WFIFOL(fd,4)=sd->status.karma;
  2632. break;
  2633. case SP_MANNER:
  2634. WFIFOL(fd,4)=sd->status.manner;
  2635. break;
  2636. case SP_STATUSPOINT:
  2637. WFIFOL(fd,4)=sd->status.status_point;
  2638. break;
  2639. case SP_SKILLPOINT:
  2640. WFIFOL(fd,4)=sd->status.skill_point;
  2641. break;
  2642. case SP_HIT:
  2643. WFIFOL(fd,4)=sd->battle_status.hit;
  2644. break;
  2645. case SP_FLEE1:
  2646. WFIFOL(fd,4)=sd->battle_status.flee;
  2647. break;
  2648. case SP_FLEE2:
  2649. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2650. break;
  2651. case SP_MAXHP:
  2652. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2653. break;
  2654. case SP_MAXSP:
  2655. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2656. break;
  2657. case SP_HP:
  2658. WFIFOL(fd,4)=sd->battle_status.hp;
  2659. // TODO: Won't these overwrite the current packet?
  2660. if( map[sd->bl.m].hpmeter_visible )
  2661. clif_hpmeter(sd);
  2662. if( !battle_config.party_hp_mode && sd->status.party_id )
  2663. clif_party_hp(sd);
  2664. if( sd->bg_id )
  2665. clif_bg_hp(sd);
  2666. break;
  2667. case SP_SP:
  2668. WFIFOL(fd,4)=sd->battle_status.sp;
  2669. break;
  2670. case SP_ASPD:
  2671. WFIFOL(fd,4)=sd->battle_status.amotion;
  2672. break;
  2673. case SP_ATK1:
  2674. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2675. break;
  2676. case SP_DEF1:
  2677. WFIFOL(fd,4)=pc_leftside_def(sd);
  2678. break;
  2679. case SP_MDEF1:
  2680. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2681. break;
  2682. case SP_ATK2:
  2683. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2684. break;
  2685. case SP_DEF2:
  2686. WFIFOL(fd,4)=pc_rightside_def(sd);
  2687. break;
  2688. case SP_MDEF2: {
  2689. //negative check (in case you have something like Berserk active)
  2690. int mdef2 = pc_rightside_mdef(sd);
  2691. WFIFOL(fd,4)=
  2692. #ifndef RENEWAL
  2693. ( mdef2 < 0 ) ? 0 :
  2694. #endif
  2695. mdef2;
  2696. }
  2697. break;
  2698. case SP_CRITICAL:
  2699. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2700. break;
  2701. case SP_MATK1:
  2702. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2703. break;
  2704. case SP_MATK2:
  2705. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2706. break;
  2707. case SP_ZENY:
  2708. WFIFOW(fd,0)=0xb1;
  2709. WFIFOL(fd,4)=sd->status.zeny;
  2710. break;
  2711. case SP_BASEEXP:
  2712. WFIFOW(fd,0)=0xb1;
  2713. WFIFOL(fd,4)=sd->status.base_exp;
  2714. break;
  2715. case SP_JOBEXP:
  2716. WFIFOW(fd,0)=0xb1;
  2717. WFIFOL(fd,4)=sd->status.job_exp;
  2718. break;
  2719. case SP_NEXTBASEEXP:
  2720. WFIFOW(fd,0)=0xb1;
  2721. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2722. break;
  2723. case SP_NEXTJOBEXP:
  2724. WFIFOW(fd,0)=0xb1;
  2725. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2726. break;
  2727. /**
  2728. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2729. **/
  2730. case SP_USTR:
  2731. case SP_UAGI:
  2732. case SP_UVIT:
  2733. case SP_UINT:
  2734. case SP_UDEX:
  2735. case SP_ULUK:
  2736. WFIFOW(fd,0)=0xbe;
  2737. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2738. len=5;
  2739. break;
  2740. /**
  2741. * Tells the client how far it is allowed to attack (weapon range)
  2742. **/
  2743. case SP_ATTACKRANGE:
  2744. WFIFOW(fd,0)=0x13a;
  2745. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2746. len=4;
  2747. break;
  2748. case SP_STR:
  2749. WFIFOW(fd,0)=0x141;
  2750. WFIFOL(fd,2)=type;
  2751. WFIFOL(fd,6)=sd->status.str;
  2752. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2753. len=14;
  2754. break;
  2755. case SP_AGI:
  2756. WFIFOW(fd,0)=0x141;
  2757. WFIFOL(fd,2)=type;
  2758. WFIFOL(fd,6)=sd->status.agi;
  2759. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2760. len=14;
  2761. break;
  2762. case SP_VIT:
  2763. WFIFOW(fd,0)=0x141;
  2764. WFIFOL(fd,2)=type;
  2765. WFIFOL(fd,6)=sd->status.vit;
  2766. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2767. len=14;
  2768. break;
  2769. case SP_INT:
  2770. WFIFOW(fd,0)=0x141;
  2771. WFIFOL(fd,2)=type;
  2772. WFIFOL(fd,6)=sd->status.int_;
  2773. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2774. len=14;
  2775. break;
  2776. case SP_DEX:
  2777. WFIFOW(fd,0)=0x141;
  2778. WFIFOL(fd,2)=type;
  2779. WFIFOL(fd,6)=sd->status.dex;
  2780. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2781. len=14;
  2782. break;
  2783. case SP_LUK:
  2784. WFIFOW(fd,0)=0x141;
  2785. WFIFOL(fd,2)=type;
  2786. WFIFOL(fd,6)=sd->status.luk;
  2787. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2788. len=14;
  2789. break;
  2790. case SP_CARTINFO:
  2791. WFIFOW(fd,0)=0x121;
  2792. WFIFOW(fd,2)=sd->cart_num;
  2793. WFIFOW(fd,4)=MAX_CART;
  2794. WFIFOL(fd,6)=sd->cart_weight;
  2795. WFIFOL(fd,10)=sd->cart_weight_max;
  2796. len=14;
  2797. break;
  2798. default:
  2799. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2800. return;
  2801. }
  2802. WFIFOSET(fd,len);
  2803. }
  2804. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2805. /// 01ab <account id>.L <var id>.W <value>.L
  2806. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2807. {
  2808. unsigned char buf[12];
  2809. nullpo_retv(sd);
  2810. WBUFW(buf,0)=0x1ab;
  2811. WBUFL(buf,2)=sd->bl.id;
  2812. WBUFW(buf,6)=type;
  2813. switch(type)
  2814. {
  2815. case SP_MANNER:
  2816. WBUFL(buf,8)=val;
  2817. break;
  2818. default:
  2819. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2820. return;
  2821. }
  2822. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2823. }
  2824. /// Updates sprite/style properties of an object.
  2825. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2826. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2827. void clif_changelook(struct block_list *bl,int type,int val)
  2828. {
  2829. unsigned char buf[16];
  2830. struct map_session_data* sd;
  2831. struct status_change* sc;
  2832. struct view_data* vd;
  2833. enum send_target target = AREA;
  2834. nullpo_retv(bl);
  2835. sd = BL_CAST(BL_PC, bl);
  2836. sc = status_get_sc(bl);
  2837. vd = status_get_viewdata(bl);
  2838. //nullpo_ret(vd);
  2839. if( vd ) //temp hack to let Warp Portal change appearance
  2840. switch(type)
  2841. {
  2842. case LOOK_WEAPON:
  2843. if (sd)
  2844. {
  2845. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2846. val = vd->weapon;
  2847. }
  2848. else vd->weapon = val;
  2849. break;
  2850. case LOOK_SHIELD:
  2851. if (sd)
  2852. {
  2853. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2854. val = vd->shield;
  2855. }
  2856. else vd->shield = val;
  2857. break;
  2858. case LOOK_BASE:
  2859. if (!sd) break;
  2860. if (sd->sc.option&OPTION_COSTUME)
  2861. vd->weapon = vd->shield = 0;
  2862. if (!vd->cloth_color)
  2863. break;
  2864. if (sd) {
  2865. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2866. vd->cloth_color = 0;
  2867. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2868. vd->cloth_color = 0;
  2869. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2870. vd->cloth_color = 0;
  2871. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2872. vd->cloth_color = 0;
  2873. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2874. vd->cloth_color = 0;
  2875. }
  2876. break;
  2877. case LOOK_HAIR:
  2878. vd->hair_style = val;
  2879. break;
  2880. case LOOK_HEAD_BOTTOM:
  2881. vd->head_bottom = val;
  2882. break;
  2883. case LOOK_HEAD_TOP:
  2884. vd->head_top = val;
  2885. break;
  2886. case LOOK_HEAD_MID:
  2887. vd->head_mid = val;
  2888. break;
  2889. case LOOK_HAIR_COLOR:
  2890. vd->hair_color = val;
  2891. break;
  2892. case LOOK_CLOTHES_COLOR:
  2893. if (val && sd) {
  2894. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2895. val = 0;
  2896. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2897. val = 0;
  2898. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2899. val = 0;
  2900. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2901. val = 0;
  2902. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2903. val = 0;
  2904. }
  2905. vd->cloth_color = val;
  2906. break;
  2907. case LOOK_SHOES:
  2908. #if PACKETVER > 3
  2909. if (sd) {
  2910. int n;
  2911. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2912. if(sd->inventory_data[n]->view_id > 0)
  2913. val = sd->inventory_data[n]->view_id;
  2914. else
  2915. val = sd->status.inventory[n].nameid;
  2916. } else
  2917. val = 0;
  2918. }
  2919. #endif
  2920. //Shoes? No packet uses this....
  2921. break;
  2922. case LOOK_BODY:
  2923. // unknown purpose
  2924. break;
  2925. case LOOK_ROBE:
  2926. #if PACKETVER < 20110111
  2927. return;
  2928. #else
  2929. vd->robe = val;
  2930. #endif
  2931. break;
  2932. }
  2933. // prevent leaking the presence of GM-hidden objects
  2934. if( sc && sc->option&OPTION_INVISIBLE )
  2935. target = SELF;
  2936. #if PACKETVER < 4
  2937. WBUFW(buf,0)=0xc3;
  2938. WBUFL(buf,2)=bl->id;
  2939. WBUFB(buf,6)=type;
  2940. WBUFB(buf,7)=val;
  2941. clif_send(buf,packet_len(0xc3),bl,target);
  2942. #else
  2943. WBUFW(buf,0)=0x1d7;
  2944. WBUFL(buf,2)=bl->id;
  2945. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2946. WBUFB(buf,6)=LOOK_WEAPON;
  2947. WBUFW(buf,7)=vd->weapon;
  2948. WBUFW(buf,9)=vd->shield;
  2949. } else {
  2950. WBUFB(buf,6)=type;
  2951. WBUFL(buf,7)=val;
  2952. }
  2953. clif_send(buf,packet_len(0x1d7),bl,target);
  2954. #endif
  2955. }
  2956. //Sends a change-base-look packet required for traps as they are triggered.
  2957. void clif_changetraplook(struct block_list *bl,int val)
  2958. {
  2959. unsigned char buf[32];
  2960. #if PACKETVER < 4
  2961. WBUFW(buf,0)=0xc3;
  2962. WBUFL(buf,2)=bl->id;
  2963. WBUFB(buf,6)=LOOK_BASE;
  2964. WBUFB(buf,7)=val;
  2965. clif_send(buf,packet_len(0xc3),bl,AREA);
  2966. #else
  2967. WBUFW(buf,0)=0x1d7;
  2968. WBUFL(buf,2)=bl->id;
  2969. WBUFB(buf,6)=LOOK_BASE;
  2970. WBUFW(buf,7)=val;
  2971. WBUFW(buf,9)=0;
  2972. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2973. #endif
  2974. }
  2975. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2976. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2977. {
  2978. unsigned char buf[32];
  2979. #if PACKETVER < 4
  2980. WBUFW(buf,0)=0xc3;
  2981. WBUFL(buf,2)=id;
  2982. WBUFB(buf,6)=type;
  2983. WBUFB(buf,7)=val;
  2984. clif_send(buf,packet_len(0xc3),bl,target);
  2985. #else
  2986. WBUFW(buf,0)=0x1d7;
  2987. WBUFL(buf,2)=id;
  2988. WBUFB(buf,6)=type;
  2989. WBUFW(buf,7)=val;
  2990. WBUFW(buf,9)=0;
  2991. clif_send(buf,packet_len(0x1d7),bl,target);
  2992. #endif
  2993. }
  2994. /// Character status (ZC_STATUS).
  2995. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2996. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2997. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2998. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2999. void clif_initialstatus(struct map_session_data *sd) {
  3000. int fd, mdef2;
  3001. unsigned char *buf;
  3002. nullpo_retv(sd);
  3003. fd=sd->fd;
  3004. WFIFOHEAD(fd,packet_len(0xbd));
  3005. buf=WFIFOP(fd,0);
  3006. WBUFW(buf,0)=0xbd;
  3007. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  3008. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  3009. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  3010. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  3011. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  3012. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  3013. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  3014. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  3015. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  3016. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  3017. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  3018. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  3019. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  3020. WBUFW(buf,16) = pc_leftside_atk(sd);
  3021. WBUFW(buf,18) = pc_rightside_atk(sd);
  3022. WBUFW(buf,20) = pc_rightside_matk(sd);
  3023. WBUFW(buf,22) = pc_leftside_matk(sd);
  3024. WBUFW(buf,24) = pc_leftside_def(sd);
  3025. WBUFW(buf,26) = pc_rightside_def(sd);
  3026. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3027. mdef2 = pc_rightside_mdef(sd);
  3028. WBUFW(buf,30) =
  3029. #ifndef RENEWAL
  3030. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3031. #endif
  3032. mdef2;
  3033. WBUFW(buf,32) = sd->battle_status.hit;
  3034. WBUFW(buf,34) = sd->battle_status.flee;
  3035. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3036. WBUFW(buf,38) = sd->battle_status.cri/10;
  3037. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3038. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3039. WFIFOSET(fd,packet_len(0xbd));
  3040. clif_updatestatus(sd,SP_STR);
  3041. clif_updatestatus(sd,SP_AGI);
  3042. clif_updatestatus(sd,SP_VIT);
  3043. clif_updatestatus(sd,SP_INT);
  3044. clif_updatestatus(sd,SP_DEX);
  3045. clif_updatestatus(sd,SP_LUK);
  3046. clif_updatestatus(sd,SP_ATTACKRANGE);
  3047. clif_updatestatus(sd,SP_ASPD);
  3048. }
  3049. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3050. /// 013c <index>.W
  3051. void clif_arrowequip(struct map_session_data *sd,int val)
  3052. {
  3053. int fd;
  3054. nullpo_retv(sd);
  3055. #if PACKETVER >= 20121128
  3056. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3057. #endif
  3058. fd=sd->fd;
  3059. WFIFOHEAD(fd, packet_len(0x013c));
  3060. WFIFOW(fd,0)=0x013c;
  3061. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  3062. WFIFOSET(fd,packet_len(0x013c));
  3063. }
  3064. /// Ammunition action message (ZC_ACTION_FAILURE).
  3065. /// 013b <type>.W
  3066. /// type:
  3067. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3068. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3069. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3070. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3071. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3072. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3073. void clif_arrow_fail(struct map_session_data *sd,int type)
  3074. {
  3075. int fd;
  3076. nullpo_retv(sd);
  3077. fd=sd->fd;
  3078. WFIFOHEAD(fd, packet_len(0x013b));
  3079. WFIFOW(fd,0)=0x013b;
  3080. WFIFOW(fd,2)=type;
  3081. WFIFOSET(fd,packet_len(0x013b));
  3082. }
  3083. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3084. /// 01ad <packet len>.W { <name id>.W }*
  3085. void clif_arrow_create_list(struct map_session_data *sd)
  3086. {
  3087. int i, c;
  3088. int fd;
  3089. nullpo_retv(sd);
  3090. fd = sd->fd;
  3091. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3092. WFIFOW(fd,0) = 0x1ad;
  3093. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3094. short j, nameid = skill_arrow_db[i].nameid;
  3095. if (nameid > 0 && itemdb_exists(nameid) &&
  3096. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3097. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3098. {
  3099. if ((j = itemdb_viewid(nameid)) > 0)
  3100. WFIFOW(fd,c*2+4) = j;
  3101. else
  3102. WFIFOW(fd,c*2+4) = nameid;
  3103. c++;
  3104. }
  3105. }
  3106. WFIFOW(fd,2) = c*2+4;
  3107. WFIFOSET(fd, WFIFOW(fd,2));
  3108. if (c > 0) {
  3109. sd->menuskill_id = AC_MAKINGARROW;
  3110. sd->menuskill_val = c;
  3111. }
  3112. }
  3113. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3114. /// 00bc <status id>.W <result>.B <value>.B
  3115. /// status id:
  3116. /// SP_STR ~ SP_LUK
  3117. /// result:
  3118. /// 0 = failure
  3119. /// 1 = success
  3120. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3121. {
  3122. int fd;
  3123. nullpo_retv(sd);
  3124. fd=sd->fd;
  3125. WFIFOHEAD(fd,packet_len(0xbc));
  3126. WFIFOW(fd,0)=0xbc;
  3127. WFIFOW(fd,2)=type;
  3128. WFIFOB(fd,4)=ok;
  3129. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3130. WFIFOSET(fd,packet_len(0xbc));
  3131. }
  3132. /// Notifies the client about the result of a request to equip an item.
  3133. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3134. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3135. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3136. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3137. /// @ok: //inversed forv2 v5
  3138. /// 0 = failure
  3139. /// 1 = success
  3140. /// 2 = failure due to low level
  3141. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3142. {
  3143. int fd = 0, cmd = 0, look = 0;
  3144. struct s_packet_db *info = NULL;
  3145. nullpo_retv(sd);
  3146. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3147. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3148. return;
  3149. fd = sd->fd;
  3150. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3151. look = sd->inventory_data[n]->look;
  3152. WFIFOHEAD(fd, info->len);
  3153. WFIFOW(fd, 0) = cmd;
  3154. WFIFOW(fd, info->pos[0]) = n+2;
  3155. switch (cmd) {
  3156. case 0xaa:
  3157. WFIFOW(fd, info->pos[1]) = pos;
  3158. if (sd->packet_ver < date2version(20100629))
  3159. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3160. else {
  3161. WFIFOL(fd, info->pos[2]) = look;
  3162. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3163. }
  3164. break;
  3165. case 0x8d0:
  3166. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3167. flag = 1;
  3168. case 0x999:
  3169. if (cmd == 0x999)
  3170. WFIFOL(fd, info->pos[1]) = pos;
  3171. else
  3172. WFIFOW(fd, info->pos[1]) = pos;
  3173. WFIFOL(fd, info->pos[2]) = look;
  3174. WFIFOW(fd, info->pos[3]) = flag;
  3175. break;
  3176. }
  3177. WFIFOSET(fd, info->len);
  3178. }
  3179. /// Notifies the client about the result of a request to take off an item.
  3180. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3181. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3182. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3183. /// @ok : //inversed for v2 v5
  3184. /// 0 = failure
  3185. /// 1 = success
  3186. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3187. {
  3188. int fd,header,offs=0;
  3189. #if PACKETVER >= 20130000
  3190. header = 0x99a;
  3191. ok = ok ? 0:1;
  3192. #elif PACKETVER >= 20110824
  3193. header = 0x8d1;
  3194. ok = ok ? 0:1;
  3195. #else
  3196. header = 0xac;
  3197. #endif
  3198. nullpo_retv(sd);
  3199. fd=sd->fd;
  3200. WFIFOHEAD(fd,packet_len(header));
  3201. WFIFOW(fd,offs+0)=header;
  3202. WFIFOW(fd,offs+2)=n+2;
  3203. #if PACKETVER >= 20130000
  3204. WFIFOL(fd,offs+4)=pos;
  3205. offs +=2;
  3206. #else
  3207. WFIFOW(fd,offs+4)=pos;
  3208. #endif
  3209. WFIFOB(fd,offs+6)=ok;
  3210. WFIFOSET(fd,packet_len(header));
  3211. }
  3212. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3213. /// 019b <id>.L <effect id>.L
  3214. /// effect id:
  3215. /// 0 = base level up
  3216. /// 1 = job level up
  3217. /// 2 = refine failure
  3218. /// 3 = refine success
  3219. /// 4 = game over
  3220. /// 5 = pharmacy success
  3221. /// 6 = pharmacy failure
  3222. /// 7 = base level up (super novice)
  3223. /// 8 = job level up (super novice)
  3224. /// 9 = base level up (taekwon)
  3225. void clif_misceffect(struct block_list* bl,int type)
  3226. {
  3227. unsigned char buf[32];
  3228. nullpo_retv(bl);
  3229. WBUFW(buf,0) = 0x19b;
  3230. WBUFL(buf,2) = bl->id;
  3231. WBUFL(buf,6) = type;
  3232. clif_send(buf,packet_len(0x19b),bl,AREA);
  3233. }
  3234. /// Notifies clients in the area of a state change.
  3235. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3236. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3237. void clif_changeoption(struct block_list* bl)
  3238. {
  3239. unsigned char buf[32];
  3240. struct status_change *sc;
  3241. struct map_session_data* sd;
  3242. nullpo_retv(bl);
  3243. sc = status_get_sc(bl);
  3244. if (!sc) return; //How can an option change if there's no sc?
  3245. sd = BL_CAST(BL_PC, bl);
  3246. #if PACKETVER >= 7
  3247. WBUFW(buf,0) = 0x229;
  3248. WBUFL(buf,2) = bl->id;
  3249. WBUFW(buf,6) = sc->opt1;
  3250. WBUFW(buf,8) = sc->opt2;
  3251. WBUFL(buf,10) = sc->option;
  3252. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3253. if(disguised(bl)) {
  3254. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3255. WBUFL(buf,2) = -bl->id;
  3256. clif_send(buf,packet_len(0x229),bl,SELF);
  3257. WBUFL(buf,2) = bl->id;
  3258. WBUFL(buf,10) = OPTION_INVISIBLE;
  3259. clif_send(buf,packet_len(0x229),bl,SELF);
  3260. } else
  3261. clif_send(buf,packet_len(0x229),bl,AREA);
  3262. #else
  3263. WBUFW(buf,0) = 0x119;
  3264. WBUFL(buf,2) = bl->id;
  3265. WBUFW(buf,6) = sc->opt1;
  3266. WBUFW(buf,8) = sc->opt2;
  3267. WBUFW(buf,10) = sc->option;
  3268. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3269. if(disguised(bl)) {
  3270. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3271. WBUFL(buf,2) = -bl->id;
  3272. clif_send(buf,packet_len(0x119),bl,SELF);
  3273. WBUFL(buf,2) = bl->id;
  3274. WBUFW(buf,10) = OPTION_INVISIBLE;
  3275. clif_send(buf,packet_len(0x119),bl,SELF);
  3276. } else
  3277. clif_send(buf,packet_len(0x119),bl,AREA);
  3278. #endif
  3279. }
  3280. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3281. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3282. void clif_changeoption2(struct block_list* bl)
  3283. {
  3284. unsigned char buf[20];
  3285. struct status_change *sc;
  3286. sc = status_get_sc(bl);
  3287. if (!sc) return; //How can an option change if there's no sc?
  3288. WBUFW(buf,0) = 0x28a;
  3289. WBUFL(buf,2) = bl->id;
  3290. WBUFL(buf,6) = sc->option;
  3291. WBUFL(buf,10) = clif_setlevel(bl);
  3292. WBUFL(buf,14) = sc->opt3;
  3293. if(disguised(bl)) {
  3294. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3295. WBUFL(buf,2) = -bl->id;
  3296. clif_send(buf,packet_len(0x28a),bl,SELF);
  3297. WBUFL(buf,2) = bl->id;
  3298. WBUFL(buf,6) = OPTION_INVISIBLE;
  3299. clif_send(buf,packet_len(0x28a),bl,SELF);
  3300. } else
  3301. clif_send(buf,packet_len(0x28a),bl,AREA);
  3302. }
  3303. /// Notifies the client about the result of an item use request.
  3304. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3305. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3306. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3307. {
  3308. nullpo_retv(sd);
  3309. if(!ok) {
  3310. int fd=sd->fd;
  3311. WFIFOHEAD(fd,packet_len(0xa8));
  3312. WFIFOW(fd,0)=0xa8;
  3313. WFIFOW(fd,2)=index+2;
  3314. WFIFOW(fd,4)=amount;
  3315. WFIFOB(fd,6)=ok;
  3316. WFIFOSET(fd,packet_len(0xa8));
  3317. }
  3318. else {
  3319. #if PACKETVER < 3
  3320. int fd=sd->fd;
  3321. WFIFOHEAD(fd,packet_len(0xa8));
  3322. WFIFOW(fd,0)=0xa8;
  3323. WFIFOW(fd,2)=index+2;
  3324. WFIFOW(fd,4)=amount;
  3325. WFIFOB(fd,6)=ok;
  3326. WFIFOSET(fd,packet_len(0xa8));
  3327. #else
  3328. unsigned char buf[32];
  3329. WBUFW(buf,0)=0x1c8;
  3330. WBUFW(buf,2)=index+2;
  3331. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3332. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3333. else
  3334. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3335. WBUFL(buf,6)=sd->bl.id;
  3336. WBUFW(buf,10)=amount;
  3337. WBUFB(buf,12)=ok;
  3338. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3339. #endif
  3340. }
  3341. }
  3342. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3343. /// 00d6 <flag>.B
  3344. /// flag:
  3345. /// 0 = Room has been successfully created (opens chat room)
  3346. /// 1 = Room limit exceeded
  3347. /// 2 = Same room already exists
  3348. void clif_createchat(struct map_session_data* sd, int flag)
  3349. {
  3350. int fd;
  3351. nullpo_retv(sd);
  3352. fd = sd->fd;
  3353. WFIFOHEAD(fd,packet_len(0xd6));
  3354. WFIFOW(fd,0) = 0xd6;
  3355. WFIFOB(fd,2) = flag;
  3356. WFIFOSET(fd,packet_len(0xd6));
  3357. }
  3358. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3359. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3360. /// type:
  3361. /// 0 = private (password protected)
  3362. /// 1 = public
  3363. /// 2 = arena (npc waiting room)
  3364. /// 3 = PK zone (non-clickable)
  3365. void clif_dispchat(struct chat_data* cd, int fd)
  3366. {
  3367. unsigned char buf[128];
  3368. uint8 type;
  3369. if( cd == NULL || cd->owner == NULL )
  3370. return;
  3371. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3372. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3373. : 1;
  3374. WBUFW(buf, 0) = 0xd7;
  3375. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3376. WBUFL(buf, 4) = cd->owner->id;
  3377. WBUFL(buf, 8) = cd->bl.id;
  3378. WBUFW(buf,12) = cd->limit;
  3379. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3380. WBUFB(buf,16) = type;
  3381. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3382. if( fd ) {
  3383. WFIFOHEAD(fd,WBUFW(buf,2));
  3384. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3385. WFIFOSET(fd,WBUFW(buf,2));
  3386. } else {
  3387. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3388. }
  3389. }
  3390. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3391. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3392. /// type:
  3393. /// 0 = private (password protected)
  3394. /// 1 = public
  3395. /// 2 = arena (npc waiting room)
  3396. /// 3 = PK zone (non-clickable)
  3397. void clif_changechatstatus(struct chat_data* cd)
  3398. {
  3399. unsigned char buf[128];
  3400. uint8 type;
  3401. if( cd == NULL || cd->usersd[0] == NULL )
  3402. return;
  3403. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3404. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3405. : 1;
  3406. WBUFW(buf, 0) = 0xdf;
  3407. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3408. WBUFL(buf, 4) = cd->owner->id;
  3409. WBUFL(buf, 8) = cd->bl.id;
  3410. WBUFW(buf,12) = cd->limit;
  3411. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3412. WBUFB(buf,16) = type;
  3413. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3414. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3415. }
  3416. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3417. /// 00d8 <chat id>.L
  3418. void clif_clearchat(struct chat_data *cd,int fd)
  3419. {
  3420. unsigned char buf[32];
  3421. nullpo_retv(cd);
  3422. WBUFW(buf,0) = 0xd8;
  3423. WBUFL(buf,2) = cd->bl.id;
  3424. if( fd ) {
  3425. WFIFOHEAD(fd,packet_len(0xd8));
  3426. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3427. WFIFOSET(fd,packet_len(0xd8));
  3428. } else {
  3429. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3430. }
  3431. }
  3432. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3433. /// 00da <result>.B
  3434. /// result:
  3435. /// 0 = room full
  3436. /// 1 = wrong password
  3437. /// 2 = kicked
  3438. /// 3 = success (no message)
  3439. /// 4 = no enough zeny
  3440. /// 5 = too low level
  3441. /// 6 = too high level
  3442. /// 7 = unsuitable job class
  3443. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3444. {
  3445. int fd;
  3446. nullpo_retv(sd);
  3447. fd = sd->fd;
  3448. WFIFOHEAD(fd,packet_len(0xda));
  3449. WFIFOW(fd,0) = 0xda;
  3450. WFIFOB(fd,2) = flag;
  3451. WFIFOSET(fd,packet_len(0xda));
  3452. }
  3453. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3454. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3455. /// role:
  3456. /// 0 = owner (menu)
  3457. /// 1 = normal
  3458. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3459. {
  3460. int fd;
  3461. int i,t;
  3462. nullpo_retv(sd);
  3463. nullpo_retv(cd);
  3464. fd = sd->fd;
  3465. if (!session_isActive(fd))
  3466. return;
  3467. t = (int)(cd->owner->type == BL_NPC);
  3468. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3469. WFIFOW(fd, 0) = 0xdb;
  3470. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3471. WFIFOL(fd, 4) = cd->bl.id;
  3472. if(cd->owner->type == BL_NPC){
  3473. WFIFOL(fd, 30) = 1;
  3474. WFIFOL(fd, 8) = 0;
  3475. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3476. for (i = 0; i < cd->users; i++) {
  3477. WFIFOL(fd, 8+(i+1)*28) = 1;
  3478. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3479. }
  3480. } else
  3481. for (i = 0; i < cd->users; i++) {
  3482. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3483. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3484. }
  3485. WFIFOSET(fd, WFIFOW(fd, 2));
  3486. }
  3487. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3488. /// 00dc <users>.W <name>.24B
  3489. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3490. {
  3491. unsigned char buf[29];
  3492. nullpo_retv(sd);
  3493. nullpo_retv(cd);
  3494. WBUFW(buf, 0) = 0xdc;
  3495. WBUFW(buf, 2) = cd->users;
  3496. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3497. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3498. }
  3499. /// Announce the new owner (ZC_ROLE_CHANGE).
  3500. /// 00e1 <role>.L <nick>.24B
  3501. /// role:
  3502. /// 0 = owner (menu)
  3503. /// 1 = normal
  3504. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3505. {
  3506. unsigned char buf[64];
  3507. nullpo_retv(sd);
  3508. nullpo_retv(cd);
  3509. WBUFW(buf, 0) = 0xe1;
  3510. WBUFL(buf, 2) = 1;
  3511. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3512. WBUFW(buf,30) = 0xe1;
  3513. WBUFL(buf,32) = 0;
  3514. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3515. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3516. }
  3517. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3518. /// 00dd <users>.W <nick>.24B <flag>.B
  3519. /// flag:
  3520. /// 0 = left
  3521. /// 1 = kicked
  3522. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3523. {
  3524. unsigned char buf[32];
  3525. nullpo_retv(sd);
  3526. nullpo_retv(cd);
  3527. WBUFW(buf, 0) = 0xdd;
  3528. WBUFW(buf, 2) = cd->users-1;
  3529. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3530. WBUFB(buf,28) = flag;
  3531. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3532. }
  3533. /// Opens a trade request window from char 'name'.
  3534. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3535. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3536. void clif_traderequest(struct map_session_data* sd, const char* name)
  3537. {
  3538. int fd = sd->fd;
  3539. #if PACKETVER < 6
  3540. WFIFOHEAD(fd,packet_len(0xe5));
  3541. WFIFOW(fd,0) = 0xe5;
  3542. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3543. WFIFOSET(fd,packet_len(0xe5));
  3544. #else
  3545. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3546. if( !tsd ) return;
  3547. WFIFOHEAD(fd,packet_len(0x1f4));
  3548. WFIFOW(fd,0) = 0x1f4;
  3549. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3550. WFIFOL(fd,26) = tsd->status.char_id;
  3551. WFIFOW(fd,30) = tsd->status.base_level;
  3552. WFIFOSET(fd,packet_len(0x1f4));
  3553. #endif
  3554. }
  3555. /// Reply to a trade-request.
  3556. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3557. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3558. /// result:
  3559. /// 0 = Char is too far
  3560. /// 1 = Character does not exist
  3561. /// 2 = Trade failed
  3562. /// 3 = Accept
  3563. /// 4 = Cancel
  3564. /// 5 = Busy
  3565. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3566. {
  3567. int fd = sd->fd;
  3568. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3569. if( PACKETVER < 6 || !tsd ) {
  3570. WFIFOHEAD(fd,packet_len(0xe7));
  3571. WFIFOW(fd,0) = 0xe7;
  3572. WFIFOB(fd,2) = type;
  3573. WFIFOSET(fd,packet_len(0xe7));
  3574. } else {
  3575. WFIFOHEAD(fd,packet_len(0x1f5));
  3576. WFIFOW(fd,0) = 0x1f5;
  3577. WFIFOB(fd,2) = type;
  3578. WFIFOL(fd,3) = tsd->status.char_id;
  3579. WFIFOW(fd,7) = tsd->status.base_level;
  3580. WFIFOSET(fd,packet_len(0x1f5));
  3581. }
  3582. }
  3583. /// Notifies the client about an item from other player in current trade.
  3584. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3585. /// 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)
  3586. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3587. {
  3588. int fd;
  3589. unsigned char *buf;
  3590. #if PACKETVER < 20100223
  3591. const int cmd = 0xe9;
  3592. #else
  3593. const int cmd = 0x80f;
  3594. #endif
  3595. nullpo_retv(sd);
  3596. nullpo_retv(tsd);
  3597. fd = tsd->fd;
  3598. buf = WFIFOP(fd,0);
  3599. WFIFOHEAD(fd,packet_len(cmd));
  3600. WBUFW(buf,0) = cmd;
  3601. if( index == 0 )
  3602. {
  3603. #if PACKETVER < 20100223
  3604. WBUFL(buf,2) = amount; //amount
  3605. WBUFW(buf,6) = 0; // type id
  3606. #else
  3607. WBUFW(buf,2) = 0; // type id
  3608. WBUFB(buf,4) = 0; // item type
  3609. WBUFL(buf,5) = amount; // amount
  3610. buf = WBUFP(buf,1); //Advance 1B
  3611. #endif
  3612. WBUFB(buf,8) = 0; //identify flag
  3613. WBUFB(buf,9) = 0; // attribute
  3614. WBUFB(buf,10)= 0; //refine
  3615. WBUFW(buf,11)= 0; //card (4w)
  3616. WBUFW(buf,13)= 0; //card (4w)
  3617. WBUFW(buf,15)= 0; //card (4w)
  3618. WBUFW(buf,17)= 0; //card (4w)
  3619. }
  3620. else
  3621. {
  3622. index -= 2; //index fix
  3623. #if PACKETVER < 20100223
  3624. WBUFL(buf,2) = amount; //amount
  3625. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3626. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3627. else
  3628. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3629. #else
  3630. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3631. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3632. else
  3633. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3634. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3635. WBUFL(buf,5) = amount; // amount
  3636. buf = WBUFP(buf,1); //Advance 1B
  3637. #endif
  3638. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3639. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3640. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3641. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3642. }
  3643. WFIFOSET(fd,packet_len(cmd));
  3644. }
  3645. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3646. /// 00ea <index>.W <result>.B
  3647. /// result:
  3648. /// 0 = success
  3649. /// 1 = overweight
  3650. /// 2 = trade canceled
  3651. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3652. {
  3653. int fd;
  3654. nullpo_retv(sd);
  3655. fd = sd->fd;
  3656. WFIFOHEAD(fd,packet_len(0xea));
  3657. WFIFOW(fd,0) = 0xea;
  3658. WFIFOW(fd,2) = index;
  3659. WFIFOB(fd,4) = fail;
  3660. WFIFOSET(fd,packet_len(0xea));
  3661. }
  3662. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3663. /// 00ec <who>.B
  3664. /// who:
  3665. /// 0 = self
  3666. /// 1 = other player
  3667. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3668. {
  3669. int fd;
  3670. nullpo_retv(sd);
  3671. fd = sd->fd;
  3672. WFIFOHEAD(fd,packet_len(0xec));
  3673. WFIFOW(fd,0) = 0xec;
  3674. WFIFOB(fd,2) = fail;
  3675. WFIFOSET(fd,packet_len(0xec));
  3676. }
  3677. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3678. /// 00ee
  3679. void clif_tradecancelled(struct map_session_data* sd)
  3680. {
  3681. int fd;
  3682. nullpo_retv(sd);
  3683. fd = sd->fd;
  3684. WFIFOHEAD(fd,packet_len(0xee));
  3685. WFIFOW(fd,0) = 0xee;
  3686. WFIFOSET(fd,packet_len(0xee));
  3687. }
  3688. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3689. /// 00f0 <result>.B
  3690. /// result:
  3691. /// 0 = success
  3692. /// 1 = failure
  3693. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3694. {
  3695. int fd;
  3696. nullpo_retv(sd);
  3697. fd = sd->fd;
  3698. WFIFOHEAD(fd,packet_len(0xf0));
  3699. WFIFOW(fd,0) = 0xf0;
  3700. WFIFOB(fd,2) = fail;
  3701. WFIFOSET(fd,packet_len(0xf0));
  3702. }
  3703. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3704. /// 00f1
  3705. /// NOTE: Unknown purpose. Items are not removed until the window is
  3706. /// refreshed (ex. by putting another item in there).
  3707. void clif_tradeundo(struct map_session_data* sd)
  3708. {
  3709. int fd = sd->fd;
  3710. WFIFOHEAD(fd,packet_len(0xf1));
  3711. WFIFOW(fd,0) = 0xf1;
  3712. WFIFOSET(fd,packet_len(0xf1));
  3713. }
  3714. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3715. /// 00f2 <current count>.W <max count>.W
  3716. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3717. {
  3718. int fd;
  3719. nullpo_retv(sd);
  3720. fd=sd->fd;
  3721. WFIFOHEAD(fd,packet_len(0xf2));
  3722. WFIFOW(fd,0) = 0xf2;
  3723. WFIFOW(fd,2) = amount;
  3724. WFIFOW(fd,4) = max_amount;
  3725. WFIFOSET(fd,packet_len(0xf2));
  3726. }
  3727. /// Notifies the client of an item being added to the storage.
  3728. /// 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)
  3729. /// 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)
  3730. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3731. {
  3732. int view,fd;
  3733. nullpo_retv(sd);
  3734. nullpo_retv(i);
  3735. fd=sd->fd;
  3736. view = itemdb_viewid(i->nameid);
  3737. #if PACKETVER < 5
  3738. WFIFOHEAD(fd,packet_len(0xf4));
  3739. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3740. WFIFOW(fd, 2) = index+1; // index
  3741. WFIFOL(fd, 4) = amount; // amount
  3742. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3743. WFIFOB(fd,10) = i->identify; //identify flag
  3744. WFIFOB(fd,11) = i->attribute; // attribute
  3745. WFIFOB(fd,12) = i->refine; //refine
  3746. clif_addcards(WFIFOP(fd,13), i);
  3747. WFIFOSET(fd,packet_len(0xf4));
  3748. #else
  3749. WFIFOHEAD(fd,packet_len(0x1c4));
  3750. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3751. WFIFOW(fd, 2) = index+1; // index
  3752. WFIFOL(fd, 4) = amount; // amount
  3753. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3754. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3755. WFIFOB(fd,11) = i->identify; //identify flag
  3756. WFIFOB(fd,12) = i->attribute; // attribute
  3757. WFIFOB(fd,13) = i->refine; //refine
  3758. clif_addcards(WFIFOP(fd,14), i);
  3759. WFIFOSET(fd,packet_len(0x1c4));
  3760. #endif
  3761. }
  3762. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3763. /// 00f6 <index>.W <amount>.L
  3764. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3765. {
  3766. int fd;
  3767. nullpo_retv(sd);
  3768. fd=sd->fd;
  3769. WFIFOHEAD(fd,packet_len(0xf6));
  3770. WFIFOW(fd,0)=0xf6; // Storage item removed
  3771. WFIFOW(fd,2)=index+1;
  3772. WFIFOL(fd,4)=amount;
  3773. WFIFOSET(fd,packet_len(0xf6));
  3774. }
  3775. /// Closes storage (ZC_CLOSE_STORE).
  3776. /// 00f8
  3777. void clif_storageclose(struct map_session_data* sd)
  3778. {
  3779. int fd;
  3780. nullpo_retv(sd);
  3781. fd=sd->fd;
  3782. WFIFOHEAD(fd,packet_len(0xf8));
  3783. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3784. WFIFOSET(fd,packet_len(0xf8));
  3785. }
  3786. /*==========================================
  3787. * Server tells 'sd' player client the abouts of 'dstsd' player
  3788. *------------------------------------------*/
  3789. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3790. {
  3791. struct block_list *d_bl;
  3792. int i;
  3793. if( dstsd->chatID ) {
  3794. struct chat_data *cd = NULL;
  3795. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3796. clif_dispchat(cd,sd->fd);
  3797. } else if( dstsd->state.vending )
  3798. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3799. else if( dstsd->state.buyingstore )
  3800. clif_buyingstore_entry_single(sd, dstsd);
  3801. if(dstsd->spiritball > 0)
  3802. clif_spiritball_single(sd->fd, dstsd);
  3803. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3804. clif_spiritcharm_single(sd->fd, dstsd);
  3805. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3806. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3807. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3808. else
  3809. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, StatusIconChangeTable[dstsd->sc_display[i]->type], dstsd->sc_display[i]->val1, dstsd->sc_display[i]->val2, dstsd->sc_display[i]->val3);
  3810. }
  3811. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3812. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3813. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3814. )
  3815. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3816. // display link (sd - dstsd) to sd
  3817. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3818. if( i < MAX_DEVOTION )
  3819. clif_devotion(&sd->bl, sd);
  3820. // display links (dstsd - devotees) to sd
  3821. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3822. if( i < MAX_DEVOTION )
  3823. clif_devotion(&dstsd->bl, sd);
  3824. // display link (dstsd - crusader) to sd
  3825. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3826. clif_devotion(d_bl, sd);
  3827. }
  3828. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3829. {
  3830. uint8 buf[128];
  3831. struct unit_data *ud;
  3832. struct view_data *vd;
  3833. int len;
  3834. vd = status_get_viewdata(bl);
  3835. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3836. return;
  3837. /**
  3838. * Hide NPC from maya purple card.
  3839. **/
  3840. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3841. return;
  3842. ud = unit_bl2ud(bl);
  3843. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3844. clif_send(buf,len,&sd->bl,SELF);
  3845. if (vd->cloth_color)
  3846. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3847. switch (bl->type)
  3848. {
  3849. case BL_PC:
  3850. {
  3851. TBL_PC* tsd = (TBL_PC*)bl;
  3852. clif_getareachar_pc(sd, tsd);
  3853. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3854. clif_specialeffect_single(bl,423,sd->fd);
  3855. else if(tsd->state.size==SZ_MEDIUM)
  3856. clif_specialeffect_single(bl,421,sd->fd);
  3857. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3858. clif_sendbgemblem_single(sd->fd,tsd);
  3859. if ( tsd->status.robe )
  3860. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3861. if (!&tsd->sc)
  3862. break;
  3863. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3864. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3865. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3866. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3867. if( tsd->sc.data[SC_MOONSTAR] )
  3868. clif_status_load(bl,SI_MOONSTAR,1);
  3869. if( tsd->sc.data[SC_SUPER_STAR] )
  3870. clif_status_load(bl,SI_SUPER_STAR,1);
  3871. if( tsd->sc.data[SC_ALL_RIDING] )
  3872. clif_status_load(bl,SI_ALL_RIDING,1);
  3873. }
  3874. break;
  3875. case BL_MER: // Devotion Effects
  3876. if( ((TBL_MER*)bl)->devotion_flag )
  3877. clif_devotion(bl, sd);
  3878. break;
  3879. case BL_NPC:
  3880. {
  3881. TBL_NPC* nd = (TBL_NPC*)bl;
  3882. if( nd->chat_id )
  3883. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3884. if( nd->size == SZ_BIG )
  3885. clif_specialeffect_single(bl,423,sd->fd);
  3886. else if( nd->size == SZ_MEDIUM )
  3887. clif_specialeffect_single(bl,421,sd->fd);
  3888. }
  3889. break;
  3890. case BL_MOB:
  3891. {
  3892. TBL_MOB* md = (TBL_MOB*)bl;
  3893. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3894. clif_specialeffect_single(bl,423,sd->fd);
  3895. else if(md->special_state.size==SZ_MEDIUM)
  3896. clif_specialeffect_single(bl,421,sd->fd);
  3897. #if PACKETVER >= 20120404
  3898. if( !(md->status.mode&MD_BOSS) ){
  3899. int i;
  3900. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3901. if( md->dmglog[i].id == sd->status.char_id )
  3902. clif_monster_hp_bar(md, sd->fd);
  3903. }
  3904. #endif
  3905. }
  3906. break;
  3907. case BL_PET:
  3908. if (vd->head_bottom)
  3909. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3910. break;
  3911. }
  3912. }
  3913. //Modifies the type of damage according to status changes [Skotlex]
  3914. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3915. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  3916. {
  3917. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  3918. }
  3919. /*==========================================
  3920. * Estimates walk delay based on the damage criteria. [Skotlex]
  3921. *------------------------------------------*/
  3922. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  3923. {
  3924. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  3925. return 0;
  3926. if (bl->type == BL_PC) {
  3927. if (battle_config.pc_walk_delay_rate != 100)
  3928. delay = delay*battle_config.pc_walk_delay_rate/100;
  3929. } else
  3930. if (battle_config.walk_delay_rate != 100)
  3931. delay = delay*battle_config.walk_delay_rate/100;
  3932. if (div_ > 1) //Multi-hit skills mean higher delays.
  3933. delay += battle_config.multihit_delay*(div_-1);
  3934. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3935. }
  3936. /// Sends a 'damage' packet (src performs action on dst)
  3937. /// 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)
  3938. /// 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)
  3939. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3) //! TODO
  3940. /// type:
  3941. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3942. /// 1 = pick up item
  3943. /// 2 = sit down
  3944. /// 3 = stand up
  3945. /// 4 = damage (endure)
  3946. /// 5 = (splash?)
  3947. /// 6 = (skill?)
  3948. /// 7 = (repeat damage?)
  3949. /// 8 = multi-hit damage
  3950. /// 9 = multi-hit damage (endure)
  3951. /// 10 = critical hit
  3952. /// 11 = lucky dodge
  3953. /// 12 = (touch skill?)
  3954. 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)
  3955. {
  3956. unsigned char buf[33];
  3957. struct status_change *sc;
  3958. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3959. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3960. #if PACKETVER < 20071113
  3961. const int cmd = 0x8a;
  3962. #else
  3963. const int cmd = 0x2e1;
  3964. #endif
  3965. nullpo_ret(src);
  3966. nullpo_ret(dst);
  3967. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3968. sc = status_get_sc(dst);
  3969. if(sc && sc->count) {
  3970. if(sc->data[SC_HALLUCINATION]) {
  3971. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3972. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3973. }
  3974. }
  3975. WBUFW(buf,0)=cmd;
  3976. WBUFL(buf,2)=src->id;
  3977. WBUFL(buf,6)=dst->id;
  3978. WBUFL(buf,10)=tick;
  3979. WBUFL(buf,14)=sdelay;
  3980. WBUFL(buf,18)=ddelay;
  3981. #if PACKETVER < 20071113
  3982. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3983. WBUFW(buf,22)=damage?div:0;
  3984. WBUFW(buf,27)=damage2?div:0;
  3985. } else {
  3986. WBUFW(buf,22)=min(damage, INT16_MAX);
  3987. WBUFW(buf,27)=damage2;
  3988. }
  3989. WBUFW(buf,24)=div;
  3990. WBUFB(buf,26)=type;
  3991. #else
  3992. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3993. WBUFL(buf,22)=damage?div:0;
  3994. WBUFL(buf,29)=damage2?div:0;
  3995. } else {
  3996. WBUFL(buf,22)=damage;
  3997. WBUFL(buf,29)=damage2;
  3998. }
  3999. WBUFW(buf,26)=div;
  4000. WBUFB(buf,28)=type;
  4001. #endif
  4002. if(disguised(dst)) {
  4003. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  4004. WBUFL(buf,6) = -dst->id;
  4005. clif_send(buf,packet_len(cmd),dst,SELF);
  4006. } else
  4007. clif_send(buf,packet_len(cmd),dst,AREA);
  4008. if(disguised(src)) {
  4009. WBUFL(buf,2) = -src->id;
  4010. if (disguised(dst))
  4011. WBUFL(buf,6) = dst->id;
  4012. #if PACKETVER < 20071113
  4013. if(damage > 0) WBUFW(buf,22) = -1;
  4014. if(damage2 > 0) WBUFW(buf,27) = -1;
  4015. #else
  4016. if(damage > 0) WBUFL(buf,22) = -1;
  4017. if(damage2 > 0) WBUFL(buf,29) = -1;
  4018. #endif
  4019. clif_send(buf,packet_len(cmd),src,SELF);
  4020. }
  4021. if(src == dst) {
  4022. unit_setdir(src,unit_getdir(src));
  4023. }
  4024. //Return adjusted can't walk delay for further processing.
  4025. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  4026. }
  4027. /*==========================================
  4028. * src picks up dst
  4029. *------------------------------------------*/
  4030. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4031. {
  4032. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  4033. unsigned char buf[32];
  4034. nullpo_retv(src);
  4035. nullpo_retv(dst);
  4036. WBUFW(buf, 0) = 0x8a;
  4037. WBUFL(buf, 2) = src->id;
  4038. WBUFL(buf, 6) = dst->id;
  4039. WBUFB(buf,26) = 1;
  4040. clif_send(buf, packet_len(0x8a), src, AREA);
  4041. }
  4042. /*==========================================
  4043. * inform clients in area that `bl` is sitting
  4044. *------------------------------------------*/
  4045. void clif_sitting(struct block_list* bl)
  4046. {
  4047. unsigned char buf[32];
  4048. nullpo_retv(bl);
  4049. WBUFW(buf, 0) = 0x8a;
  4050. WBUFL(buf, 2) = bl->id;
  4051. WBUFB(buf,26) = 2;
  4052. clif_send(buf, packet_len(0x8a), bl, AREA);
  4053. if(disguised(bl)) {
  4054. WBUFL(buf, 2) = - bl->id;
  4055. clif_send(buf, packet_len(0x8a), bl, SELF);
  4056. }
  4057. }
  4058. /*==========================================
  4059. * inform clients in area that `bl` is standing
  4060. *------------------------------------------*/
  4061. void clif_standing(struct block_list* bl)
  4062. {
  4063. unsigned char buf[32];
  4064. nullpo_retv(bl);
  4065. WBUFW(buf, 0) = 0x8a;
  4066. WBUFL(buf, 2) = bl->id;
  4067. WBUFB(buf,26) = 3;
  4068. clif_send(buf, packet_len(0x8a), bl, AREA);
  4069. if(disguised(bl)) {
  4070. WBUFL(buf, 2) = - bl->id;
  4071. clif_send(buf, packet_len(0x8a), bl, SELF);
  4072. }
  4073. }
  4074. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4075. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4076. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4077. {
  4078. unsigned char buf[32];
  4079. WBUFW(buf,0) = 0x192;
  4080. WBUFW(buf,2) = x;
  4081. WBUFW(buf,4) = y;
  4082. WBUFW(buf,6) = type;
  4083. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  4084. if( fd )
  4085. {
  4086. WFIFOHEAD(fd,packet_len(0x192));
  4087. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4088. WFIFOSET(fd,packet_len(0x192));
  4089. }
  4090. else
  4091. {
  4092. struct block_list dummy_bl;
  4093. dummy_bl.type = BL_NUL;
  4094. dummy_bl.x = x;
  4095. dummy_bl.y = y;
  4096. dummy_bl.m = m;
  4097. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4098. }
  4099. }
  4100. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4101. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4102. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4103. {
  4104. int view,fd;
  4105. fd=sd->fd;
  4106. WFIFOHEAD(fd,packet_len(0x9d));
  4107. WFIFOW(fd,0)=0x9d;
  4108. WFIFOL(fd,2)=fitem->bl.id;
  4109. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4110. WFIFOW(fd,6)=view;
  4111. else
  4112. WFIFOW(fd,6)=fitem->item.nameid;
  4113. WFIFOB(fd,8)=fitem->item.identify;
  4114. WFIFOW(fd,9)=fitem->bl.x;
  4115. WFIFOW(fd,11)=fitem->bl.y;
  4116. WFIFOW(fd,13)=fitem->item.amount;
  4117. WFIFOB(fd,15)=fitem->subx;
  4118. WFIFOB(fd,16)=fitem->suby;
  4119. WFIFOSET(fd,packet_len(0x9d));
  4120. }
  4121. /// Notifes client about Graffiti
  4122. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4123. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4124. unsigned char buf[128];
  4125. nullpo_retv(bl);
  4126. nullpo_retv(unit);
  4127. WBUFW(buf, 0) = 0x1c9;
  4128. WBUFL(buf, 2) = unit->bl.id;
  4129. WBUFL(buf, 6) = unit->group->src_id;
  4130. WBUFW(buf,10) = unit->bl.x;
  4131. WBUFW(buf,12) = unit->bl.y;
  4132. WBUFB(buf,14) = unit->group->unit_id;
  4133. WBUFB(buf,15) = 1;
  4134. WBUFB(buf,16) = 1;
  4135. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4136. clif_send(buf,packet_len(0x1c9),bl,target);
  4137. }
  4138. /// Notifies the client of a skill unit.
  4139. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4140. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4141. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4142. /// 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)
  4143. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, uint8 flag) {
  4144. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4145. unsigned char buf[128];
  4146. nullpo_retv(bl);
  4147. nullpo_retv(unit);
  4148. if (bl->type == BL_PC)
  4149. fd = ((TBL_PC*)bl)->fd;
  4150. if (unit->group->state.guildaura)
  4151. return;
  4152. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4153. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4154. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4155. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4156. else
  4157. unit_id = unit->group->unit_id;
  4158. if (flag && battle_config.traps_setting&1) {
  4159. switch(unit->group->skill_id) {
  4160. case HT_ANKLESNARE:
  4161. if (!map_flag_vs(((TBL_PC*)bl)->bl.m))
  4162. break;
  4163. case HT_SKIDTRAP:
  4164. case MA_SKIDTRAP:
  4165. case HT_SHOCKWAVE:
  4166. case HT_SANDMAN:
  4167. case MA_SANDMAN:
  4168. case HT_FLASHER:
  4169. case HT_FREEZINGTRAP:
  4170. case MA_FREEZINGTRAP:
  4171. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for Hunter's traps
  4172. break;
  4173. }
  4174. }
  4175. #if PACKETVER >= 3
  4176. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4177. clif_graffiti(bl, unit, target);
  4178. return;
  4179. }
  4180. #endif
  4181. #if PACKETVER <= 20120702
  4182. header = 0x011f;
  4183. //#if PACKETVER < 20110718
  4184. // header = 0x011f;
  4185. //#elif PACKETVER < 20121212
  4186. // header = 0x08c7;
  4187. #elif PACKETVER < 20130731
  4188. header = 0x099f;
  4189. #else
  4190. header = 0x09ca;
  4191. #endif
  4192. len = packet_len(header);
  4193. WBUFW(buf,pos) = header;
  4194. if (header != 0x011f) {
  4195. WBUFW(buf, pos+2) = len;
  4196. pos += 2;
  4197. }
  4198. WBUFL(buf,pos+2) = unit->bl.id;
  4199. WBUFL(buf,pos+6) = unit->group->src_id;
  4200. WBUFW(buf,pos+10) = unit->bl.x;
  4201. WBUFW(buf,pos+12) = unit->bl.y;
  4202. switch (header) {
  4203. case 0x011f:
  4204. WBUFB(buf,pos+14) = unit_id;
  4205. WBUFB(buf,pos+15) = 1;
  4206. break;
  4207. case 0x08c7:
  4208. WBUFB(buf,pos+14) = unit_id;
  4209. WBUFW(buf,pos+15) = unit->range;
  4210. WBUFB(buf,pos+17) = 1;
  4211. break;
  4212. case 0x099f:
  4213. WBUFL(buf,pos+14) = unit_id;
  4214. WBUFW(buf,pos+18) = unit->range;
  4215. WBUFB(buf,pos+20) = 1;
  4216. break;
  4217. case 0x09ca:
  4218. WBUFL(buf,pos+14) = unit_id;
  4219. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4220. WBUFB(buf,pos+19) = 1;
  4221. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4222. break;
  4223. }
  4224. clif_send(buf, len, bl, target);
  4225. if (unit->group->skill_id == WZ_ICEWALL)
  4226. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4227. }
  4228. /*==========================================
  4229. * Server tells client to remove unit of id 'unit->bl.id'
  4230. *------------------------------------------*/
  4231. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4232. {
  4233. nullpo_retv(unit);
  4234. WFIFOHEAD(fd,packet_len(0x120));
  4235. WFIFOW(fd, 0)=0x120;
  4236. WFIFOL(fd, 2)=unit->bl.id;
  4237. WFIFOSET(fd,packet_len(0x120));
  4238. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4239. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4240. }
  4241. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4242. /// 0120 <id>.L
  4243. void clif_skill_delunit(struct skill_unit *unit)
  4244. {
  4245. unsigned char buf[16];
  4246. nullpo_retv(unit);
  4247. WBUFW(buf, 0)=0x120;
  4248. WBUFL(buf, 2)=unit->bl.id;
  4249. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4250. }
  4251. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4252. /// 01ac <id>.L
  4253. /// Only affects units with class [139,153] client-side.
  4254. void clif_skillunit_update(struct block_list* bl)
  4255. {
  4256. unsigned char buf[6];
  4257. nullpo_retv(bl);
  4258. WBUFW(buf,0) = 0x1ac;
  4259. WBUFL(buf,2) = bl->id;
  4260. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4261. }
  4262. /*==========================================
  4263. *
  4264. *------------------------------------------*/
  4265. static int clif_getareachar(struct block_list* bl,va_list ap)
  4266. {
  4267. struct map_session_data *sd;
  4268. nullpo_ret(bl);
  4269. sd=va_arg(ap,struct map_session_data*);
  4270. if (sd == NULL || !sd->fd)
  4271. return 0;
  4272. switch(bl->type){
  4273. case BL_ITEM:
  4274. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4275. break;
  4276. case BL_SKILL:
  4277. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF, 1);
  4278. break;
  4279. default:
  4280. if(&sd->bl == bl)
  4281. break;
  4282. clif_getareachar_unit(sd,bl);
  4283. break;
  4284. }
  4285. return 0;
  4286. }
  4287. /*==========================================
  4288. * tbl has gone out of view-size of bl
  4289. *------------------------------------------*/
  4290. int clif_outsight(struct block_list *bl,va_list ap)
  4291. {
  4292. struct block_list *tbl;
  4293. struct view_data *vd;
  4294. TBL_PC *sd, *tsd;
  4295. tbl=va_arg(ap,struct block_list*);
  4296. if(bl == tbl) return 0;
  4297. sd = BL_CAST(BL_PC, bl);
  4298. tsd = BL_CAST(BL_PC, tbl);
  4299. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4300. nullpo_ret(bl);
  4301. switch(bl->type){
  4302. case BL_PC:
  4303. if(sd->vd.class_ != INVISIBLE_CLASS)
  4304. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4305. if(sd->chatID){
  4306. struct chat_data *cd;
  4307. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4308. if(cd->usersd[0]==sd)
  4309. clif_dispchat(cd,tsd->fd);
  4310. }
  4311. if(sd->state.vending)
  4312. clif_closevendingboard(bl,tsd->fd);
  4313. if(sd->state.buyingstore)
  4314. clif_buyingstore_disappear_entry_single(tsd, sd);
  4315. break;
  4316. case BL_ITEM:
  4317. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4318. break;
  4319. case BL_SKILL:
  4320. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4321. break;
  4322. case BL_NPC:
  4323. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4324. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4325. break;
  4326. default:
  4327. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4328. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4329. break;
  4330. }
  4331. }
  4332. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4333. nullpo_ret(tbl);
  4334. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4335. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4336. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4337. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4338. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4339. }
  4340. return 0;
  4341. }
  4342. /*==========================================
  4343. * tbl has come into view of bl
  4344. *------------------------------------------*/
  4345. int clif_insight(struct block_list *bl,va_list ap)
  4346. {
  4347. struct block_list *tbl;
  4348. TBL_PC *sd, *tsd;
  4349. tbl=va_arg(ap,struct block_list*);
  4350. if (bl == tbl) return 0;
  4351. sd = BL_CAST(BL_PC, bl);
  4352. tsd = BL_CAST(BL_PC, tbl);
  4353. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4354. switch(bl->type){
  4355. case BL_ITEM:
  4356. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4357. break;
  4358. case BL_SKILL:
  4359. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF, 1);
  4360. break;
  4361. default:
  4362. clif_getareachar_unit(tsd,bl);
  4363. break;
  4364. }
  4365. }
  4366. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4367. clif_getareachar_unit(sd,tbl);
  4368. }
  4369. return 0;
  4370. }
  4371. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4372. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4373. void clif_skillinfoblock(struct map_session_data *sd)
  4374. {
  4375. int fd;
  4376. int i,len,id;
  4377. nullpo_retv(sd);
  4378. fd = sd->fd;
  4379. if (!fd)
  4380. return;
  4381. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4382. WFIFOW(fd,0) = 0x10f;
  4383. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4384. {
  4385. if( (id = sd->status.skill[i].id) != 0 )
  4386. {
  4387. // workaround for bugreport:5348
  4388. if (len + 37 > 8192)
  4389. break;
  4390. WFIFOW(fd,len) = id;
  4391. WFIFOL(fd,len+2) = skill_get_inf(id);
  4392. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4393. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4394. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4395. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4396. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4397. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4398. else
  4399. WFIFOB(fd,len+36) = 0;
  4400. len += 37;
  4401. }
  4402. }
  4403. WFIFOW(fd,2)=len;
  4404. WFIFOSET(fd,len);
  4405. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4406. for ( ; i < MAX_SKILL; i++)
  4407. {
  4408. if( (id = sd->status.skill[i].id) != 0 )
  4409. {
  4410. clif_addskill(sd, id);
  4411. clif_skillinfo(sd, id, 0);
  4412. }
  4413. }
  4414. }
  4415. /**
  4416. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4417. **/
  4418. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4419. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4420. void clif_addskill(struct map_session_data *sd, int skill_id)
  4421. {
  4422. int fd;
  4423. uint16 idx = 0;
  4424. nullpo_retv(sd);
  4425. fd = sd->fd;
  4426. if (!fd || !(idx = skill_get_index(skill_id)))
  4427. return;
  4428. if( sd->status.skill[idx].id <= 0 )
  4429. return;
  4430. WFIFOHEAD(fd, packet_len(0x111));
  4431. WFIFOW(fd,0) = 0x111;
  4432. WFIFOW(fd,2) = skill_id;
  4433. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4434. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4435. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4436. WFIFOW(fd,12)= skill_get_range2(&sd->bl, skill_id,sd->status.skill[idx].lv);
  4437. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4438. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4439. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4440. else
  4441. WFIFOB(fd,38) = 0;
  4442. WFIFOSET(fd,packet_len(0x111));
  4443. }
  4444. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4445. /// 0441 <skill id>.W
  4446. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4447. {
  4448. #if PACKETVER >= 20081217
  4449. int fd;
  4450. uint16 idx = 0;
  4451. nullpo_retv(sd);
  4452. fd = sd->fd;
  4453. if (!fd || !(idx = skill_get_index(skill_id)))
  4454. return;
  4455. WFIFOHEAD(fd,packet_len(0x441));
  4456. WFIFOW(fd,0) = 0x441;
  4457. WFIFOW(fd,2) = skill_id;
  4458. WFIFOSET(fd,packet_len(0x441));
  4459. #endif
  4460. clif_skillinfoblock(sd);
  4461. }
  4462. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4463. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4464. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4465. int fd;
  4466. nullpo_retv(sd);
  4467. fd = sd->fd;
  4468. WFIFOHEAD(fd, packet_len(0x10e));
  4469. WFIFOW(fd, 0) = 0x10e;
  4470. WFIFOW(fd, 2) = skill_id;
  4471. WFIFOW(fd, 4) = lv;
  4472. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4473. WFIFOW(fd, 8) = range;
  4474. WFIFOB(fd, 10) = upgradable;
  4475. WFIFOSET(fd, packet_len(0x10e));
  4476. }
  4477. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4478. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4479. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4480. {
  4481. const int fd = sd->fd;
  4482. uint16 idx = skill_get_index(skill_id);
  4483. if (!idx)
  4484. return;
  4485. WFIFOHEAD(fd,packet_len(0x7e1));
  4486. WFIFOW(fd,0) = 0x7e1;
  4487. WFIFOW(fd,2) = skill_id;
  4488. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4489. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4490. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4491. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv);
  4492. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4493. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4494. else
  4495. WFIFOB(fd,14) = 0;
  4496. WFIFOSET(fd,packet_len(0x7e1));
  4497. }
  4498. /// Notifies clients in area, that an object is about to use a skill.
  4499. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4500. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4501. /// property:
  4502. /// 0 = Yellow cast aura
  4503. /// 1 = Water elemental cast aura
  4504. /// 2 = Earth elemental cast aura
  4505. /// 3 = Fire elemental cast aura
  4506. /// 4 = Wind elemental cast aura
  4507. /// 5 = Poison elemental cast aura
  4508. /// 6 = Holy elemental cast aura
  4509. /// ? = like 0
  4510. /// is disposable:
  4511. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4512. /// 1 = no text
  4513. 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)
  4514. {
  4515. #if PACKETVER < 20091124
  4516. const int cmd = 0x13e;
  4517. #else
  4518. const int cmd = 0x7fb;
  4519. #endif
  4520. unsigned char buf[32];
  4521. WBUFW(buf,0) = cmd;
  4522. WBUFL(buf,2) = src_id;
  4523. WBUFL(buf,6) = dst_id;
  4524. WBUFW(buf,10) = dst_x;
  4525. WBUFW(buf,12) = dst_y;
  4526. WBUFW(buf,14) = skill_id;
  4527. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4528. WBUFL(buf,20) = casttime;
  4529. #if PACKETVER >= 20091124
  4530. WBUFB(buf,24) = 0; // isDisposable
  4531. #endif
  4532. if (disguised(bl)) {
  4533. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4534. WBUFL(buf,2) = -src_id;
  4535. clif_send(buf,packet_len(cmd), bl, SELF);
  4536. } else
  4537. clif_send(buf,packet_len(cmd), bl, AREA);
  4538. }
  4539. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4540. /// 01b9 <id>.L
  4541. void clif_skillcastcancel(struct block_list* bl)
  4542. {
  4543. unsigned char buf[16];
  4544. nullpo_retv(bl);
  4545. WBUFW(buf,0) = 0x1b9;
  4546. WBUFL(buf,2) = bl->id;
  4547. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4548. }
  4549. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4550. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4551. /// num (only used when skill id = NV_BASIC and cause = 0):
  4552. /// 0 = "skill failed" MsgStringTable[159]
  4553. /// 1 = "no emotions" MsgStringTable[160]
  4554. /// 2 = "no sit" MsgStringTable[161]
  4555. /// 3 = "no chat" MsgStringTable[162]
  4556. /// 4 = "no party" MsgStringTable[163]
  4557. /// 5 = "no shout" MsgStringTable[164]
  4558. /// 6 = "no PKing" MsgStringTable[165]
  4559. /// 7 = "no alligning" MsgStringTable[383]
  4560. /// ? = ignored
  4561. /// cause:
  4562. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4563. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4564. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4565. /// "skill failed" MsgStringTable[204] (otherwise)
  4566. /// ... = @see enum useskill_fail_cause
  4567. /// ? = ignored
  4568. ///
  4569. /// if(result!=0) doesn't display any of the previous messages
  4570. /// Note: when this packet is received an unknown flag is always set to 0,
  4571. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4572. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4573. {
  4574. int fd;
  4575. if (!sd) { //Since this is the most common nullpo....
  4576. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4577. return;
  4578. }
  4579. fd=sd->fd;
  4580. if (!fd) return;
  4581. if(battle_config.display_skill_fail&1)
  4582. return; //Disable all skill failed messages
  4583. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4584. return; //Disable delay failed messages
  4585. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4586. return;
  4587. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4588. return;
  4589. WFIFOHEAD(fd,packet_len(0x110));
  4590. WFIFOW(fd,0) = 0x110;
  4591. WFIFOW(fd,2) = skill_id;
  4592. WFIFOL(fd,4) = btype;
  4593. WFIFOB(fd,8) = 0;// success
  4594. WFIFOB(fd,9) = cause;
  4595. WFIFOSET(fd,packet_len(0x110));
  4596. }
  4597. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4598. /// 043d <skill ID>.W <tick>.L
  4599. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4600. {
  4601. #if PACKETVER>=20081112
  4602. int fd;
  4603. nullpo_retv(sd);
  4604. fd=sd->fd;
  4605. WFIFOHEAD(fd,packet_len(0x43d));
  4606. WFIFOW(fd,0) = 0x43d;
  4607. WFIFOW(fd,2) = skill_id;
  4608. WFIFOL(fd,4) = tick;
  4609. WFIFOSET(fd,packet_len(0x43d));
  4610. #endif
  4611. }
  4612. /// Skill attack effect and damage.
  4613. /// 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)
  4614. /// 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)
  4615. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4616. {
  4617. unsigned char buf[64];
  4618. struct status_change *sc;
  4619. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4620. nullpo_ret(src);
  4621. nullpo_ret(dst);
  4622. type = clif_calc_delay(type,div,damage,ddelay);
  4623. #if PACKETVER >= 20131223
  4624. if ( type == DMG_SKILL )
  4625. type = DMG_MULTI_HIT; /* Temporary Fix */
  4626. #endif
  4627. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4628. if(sc->data[SC_HALLUCINATION] && damage)
  4629. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4630. }
  4631. #if PACKETVER < 3
  4632. WBUFW(buf,0)=0x114;
  4633. WBUFW(buf,2)=skill_id;
  4634. WBUFL(buf,4)=src->id;
  4635. WBUFL(buf,8)=dst->id;
  4636. WBUFL(buf,12)=tick;
  4637. WBUFL(buf,16)=sdelay;
  4638. WBUFL(buf,20)=ddelay;
  4639. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4640. WBUFW(buf,24)=damage?div:0;
  4641. } else {
  4642. WBUFW(buf,24)=damage;
  4643. }
  4644. WBUFW(buf,26)=skill_lv;
  4645. WBUFW(buf,28)=div;
  4646. WBUFB(buf,30)=type;
  4647. if (disguised(dst)) {
  4648. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4649. WBUFL(buf,8)=-dst->id;
  4650. clif_send(buf,packet_len(0x114),dst,SELF);
  4651. } else
  4652. clif_send(buf,packet_len(0x114),dst,AREA);
  4653. if(disguised(src)) {
  4654. WBUFL(buf,4)=-src->id;
  4655. if (disguised(dst))
  4656. WBUFL(buf,8)=dst->id;
  4657. if(damage > 0)
  4658. WBUFW(buf,24)=-1;
  4659. clif_send(buf,packet_len(0x114),src,SELF);
  4660. }
  4661. #else
  4662. WBUFW(buf,0)=0x1de;
  4663. WBUFW(buf,2)=skill_id;
  4664. WBUFL(buf,4)=src->id;
  4665. WBUFL(buf,8)=dst->id;
  4666. WBUFL(buf,12)=tick;
  4667. WBUFL(buf,16)=sdelay;
  4668. WBUFL(buf,20)=ddelay;
  4669. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4670. WBUFL(buf,24)=damage?div:0;
  4671. } else {
  4672. WBUFL(buf,24)=damage;
  4673. }
  4674. WBUFW(buf,28)=skill_lv;
  4675. WBUFW(buf,30)=div;
  4676. WBUFB(buf,32)=type;
  4677. if (disguised(dst)) {
  4678. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4679. WBUFL(buf,8)=-dst->id;
  4680. clif_send(buf,packet_len(0x1de),dst,SELF);
  4681. } else
  4682. clif_send(buf,packet_len(0x1de),dst,AREA);
  4683. if(disguised(src)) {
  4684. WBUFL(buf,4)=-src->id;
  4685. if (disguised(dst))
  4686. WBUFL(buf,8)=dst->id;
  4687. if(damage > 0)
  4688. WBUFL(buf,24)=-1;
  4689. clif_send(buf,packet_len(0x1de),src,SELF);
  4690. }
  4691. #endif
  4692. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4693. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4694. }
  4695. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4696. /// 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
  4697. /*
  4698. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4699. {
  4700. unsigned char buf[64];
  4701. struct status_change *sc;
  4702. nullpo_ret(src);
  4703. nullpo_ret(dst);
  4704. type = (type>0)?type:skill_get_hit(skill_id);
  4705. type = clif_calc_delay(type,div,damage,ddelay);
  4706. sc = status_get_sc(dst);
  4707. if(sc && sc->count) {
  4708. if(sc->data[SC_HALLUCINATION] && damage)
  4709. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4710. }
  4711. WBUFW(buf,0)=0x115;
  4712. WBUFW(buf,2)=skill_id;
  4713. WBUFL(buf,4)=src->id;
  4714. WBUFL(buf,8)=dst->id;
  4715. WBUFL(buf,12)=tick;
  4716. WBUFL(buf,16)=sdelay;
  4717. WBUFL(buf,20)=ddelay;
  4718. WBUFW(buf,24)=dst->x;
  4719. WBUFW(buf,26)=dst->y;
  4720. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4721. WBUFW(buf,28)=damage?div:0;
  4722. } else {
  4723. WBUFW(buf,28)=damage;
  4724. }
  4725. WBUFW(buf,30)=skill_lv;
  4726. WBUFW(buf,32)=div;
  4727. WBUFB(buf,34)=type;
  4728. clif_send(buf,packet_len(0x115),src,AREA);
  4729. if(disguised(src)) {
  4730. WBUFL(buf,4)=-src->id;
  4731. if(damage > 0)
  4732. WBUFW(buf,28)=-1;
  4733. clif_send(buf,packet_len(0x115),src,SELF);
  4734. }
  4735. if (disguised(dst)) {
  4736. WBUFL(buf,8)=-dst->id;
  4737. if (disguised(src))
  4738. WBUFL(buf,4)=src->id;
  4739. else if(damage > 0)
  4740. WBUFW(buf,28)=-1;
  4741. clif_send(buf,packet_len(0x115),dst,SELF);
  4742. }
  4743. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4744. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4745. }
  4746. */
  4747. /// Non-damaging skill effect (ZC_USE_SKILL).
  4748. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4749. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4750. {
  4751. unsigned char buf[32];
  4752. nullpo_ret(dst);
  4753. WBUFW(buf,0)=0x11a;
  4754. WBUFW(buf,2)=skill_id;
  4755. WBUFW(buf,4)=min(heal, INT16_MAX);
  4756. WBUFL(buf,6)=dst->id;
  4757. WBUFL(buf,10)=src?src->id:0;
  4758. WBUFB(buf,14)=fail;
  4759. if (disguised(dst)) {
  4760. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4761. WBUFL(buf,6)=-dst->id;
  4762. clif_send(buf,packet_len(0x11a),dst,SELF);
  4763. } else
  4764. clif_send(buf,packet_len(0x11a),dst,AREA);
  4765. if(src && disguised(src)) {
  4766. WBUFL(buf,10)=-src->id;
  4767. if (disguised(dst))
  4768. WBUFL(buf,6)=dst->id;
  4769. clif_send(buf,packet_len(0x11a),src,SELF);
  4770. }
  4771. return fail;
  4772. }
  4773. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4774. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4775. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4776. {
  4777. unsigned char buf[32];
  4778. nullpo_retv(src);
  4779. WBUFW(buf,0)=0x117;
  4780. WBUFW(buf,2)=skill_id;
  4781. WBUFL(buf,4)=src->id;
  4782. WBUFW(buf,8)=val;
  4783. WBUFW(buf,10)=x;
  4784. WBUFW(buf,12)=y;
  4785. WBUFL(buf,14)=tick;
  4786. if(disguised(src)) {
  4787. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4788. WBUFL(buf,4)=-src->id;
  4789. clif_send(buf,packet_len(0x117),src,SELF);
  4790. } else
  4791. clif_send(buf,packet_len(0x117),src,AREA);
  4792. }
  4793. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4794. /// 011c <skill id>.W { <map name>.16B }*4
  4795. 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)
  4796. {
  4797. int fd;
  4798. nullpo_retv(sd);
  4799. fd = sd->fd;
  4800. WFIFOHEAD(fd,packet_len(0x11c));
  4801. WFIFOW(fd,0) = 0x11c;
  4802. WFIFOW(fd,2) = skill_id;
  4803. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4804. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4805. else // normal map name
  4806. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4807. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4808. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4809. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4810. WFIFOSET(fd,packet_len(0x11c));
  4811. sd->menuskill_id = skill_id;
  4812. if (skill_id == AL_WARP)
  4813. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4814. else
  4815. sd->menuskill_val = skill_lv;
  4816. }
  4817. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4818. /// 011e <type>.B
  4819. /// type:
  4820. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4821. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4822. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4823. ///
  4824. /// @param sd Who receives the message
  4825. /// @param type What message
  4826. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4827. {
  4828. int fd;
  4829. nullpo_retv(sd);
  4830. fd=sd->fd;
  4831. WFIFOHEAD(fd,packet_len(0x11e));
  4832. WFIFOW(fd,0)=0x11e;
  4833. WFIFOB(fd,2)=type;
  4834. WFIFOSET(fd,packet_len(0x11e));
  4835. }
  4836. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4837. /// 0189 <type>.W
  4838. /// type:
  4839. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4840. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4841. ///
  4842. /// @param sd Who receives the message
  4843. /// @param type What message
  4844. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4845. {
  4846. int fd;
  4847. nullpo_retv(sd);
  4848. fd=sd->fd;
  4849. WFIFOHEAD(fd,packet_len(0x189));
  4850. WFIFOW(fd,0)=0x189;
  4851. WFIFOW(fd,2)=type;
  4852. WFIFOSET(fd,packet_len(0x189));
  4853. }
  4854. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4855. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4856. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4857. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4858. {
  4859. struct status_data *status;
  4860. unsigned char buf[64];
  4861. int i;//, fix;
  4862. nullpo_retv(sd);
  4863. nullpo_retv(dst);
  4864. if( dst->type != BL_MOB )
  4865. return;
  4866. status = status_get_status_data(dst);
  4867. WBUFW(buf, 0)=0x18c;
  4868. WBUFW(buf, 2)=status_get_class(dst);
  4869. WBUFW(buf, 4)=status_get_lv(dst);
  4870. WBUFW(buf, 6)=status->size;
  4871. WBUFL(buf, 8)=status->hp;
  4872. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4873. +(battle_config.estimation_type&2?status->def2:0);
  4874. WBUFW(buf,14)=status->race;
  4875. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4876. +(battle_config.estimation_type&2?status->mdef2:0);
  4877. WBUFW(buf,18)= status->def_ele;
  4878. for(i=0;i<9;i++)
  4879. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4880. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4881. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4882. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4883. }
  4884. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4885. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4886. /// material id:
  4887. /// unused by the client
  4888. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4889. {
  4890. int i,c,view,fd;
  4891. nullpo_retv(sd);
  4892. if (sd->menuskill_id == skill_id)
  4893. return; //Avoid resending the menu twice or more times...
  4894. if (skill_id == GC_CREATENEWPOISON)
  4895. skill_id = GC_RESEARCHNEWPOISON;
  4896. fd = sd->fd;
  4897. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4898. WFIFOW(fd, 0) = 0x18d;
  4899. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  4900. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4901. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  4902. )
  4903. {
  4904. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4905. WFIFOW(fd,c*8+ 4) = view;
  4906. else
  4907. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  4908. WFIFOW(fd,c*8+ 6) = 0;
  4909. WFIFOW(fd,c*8+ 8) = 0;
  4910. WFIFOW(fd,c*8+10) = 0;
  4911. c++;
  4912. }
  4913. }
  4914. WFIFOW(fd, 2) = c*8+8;
  4915. WFIFOSET(fd,WFIFOW(fd,2));
  4916. if (c > 0) {
  4917. sd->menuskill_id = skill_id;
  4918. sd->menuskill_val = trigger;
  4919. return;
  4920. }
  4921. }
  4922. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4923. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4924. /// mk type:
  4925. /// 1 = cooking
  4926. /// 2 = arrow
  4927. /// 3 = elemental
  4928. /// 4 = GN_MIX_COOKING
  4929. /// 5 = GN_MAKEBOMB
  4930. /// 6 = GN_S_PHARMACY
  4931. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4932. {
  4933. int fd;
  4934. int i, c;
  4935. int view;
  4936. nullpo_retv(sd);
  4937. fd = sd->fd;
  4938. if(sd->menuskill_id == skill_id)
  4939. return; //Avoid resending the menu twice or more times...
  4940. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4941. WFIFOW(fd,0) = 0x25a;
  4942. WFIFOW(fd,4) = list_type; // list type
  4943. c = 0;
  4944. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4945. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4946. continue;
  4947. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4948. WFIFOW(fd, 6 + 2 * c) = view;
  4949. else
  4950. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4951. c++;
  4952. }
  4953. if( c > 0 || skill_id == AM_PHARMACY) {
  4954. sd->menuskill_id = skill_id;
  4955. sd->menuskill_val = trigger;
  4956. sd->menuskill_val2 = qty; // amount.
  4957. WFIFOW(fd,2) = 6 + 2 * c;
  4958. WFIFOSET(fd,WFIFOW(fd,2));
  4959. } else {
  4960. clif_menuskill_clear(sd);
  4961. #if PACKETVER >= 20090922
  4962. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  4963. #else
  4964. WFIFOW(fd,2) = 6 + 2 * c;
  4965. WFIFOSET(fd,WFIFOW(fd,2));
  4966. #endif
  4967. }
  4968. }
  4969. /// Notifies clients of a status change.
  4970. /// 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)]
  4971. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4972. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  4973. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4974. {
  4975. unsigned char buf[32];
  4976. struct map_session_data *sd;
  4977. if (type == SI_BLANK) //It shows nothing on the client...
  4978. return;
  4979. nullpo_retv(bl);
  4980. sd = BL_CAST(BL_PC, bl);
  4981. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4982. return;
  4983. #if PACKETVER >= 20120618
  4984. if(flag && battle_config.display_status_timers && sd)
  4985. WBUFW(buf,0)=0x983;
  4986. else
  4987. #elif PACKETVER >= 20090121
  4988. if(flag && battle_config.display_status_timers && sd)
  4989. WBUFW(buf,0)=0x43f;
  4990. else
  4991. #endif
  4992. WBUFW(buf,0)=0x196;
  4993. WBUFW(buf,2)=type;
  4994. WBUFL(buf,4)=bl->id;
  4995. WBUFB(buf,8)=flag;
  4996. #if PACKETVER >= 20120618
  4997. if(flag && battle_config.display_status_timers && sd) {
  4998. if (tick <= 0)
  4999. tick = 9999; // this is indeed what official servers do
  5000. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  5001. WBUFL(buf,13)=tick;
  5002. WBUFL(buf,17) = val1;
  5003. WBUFL(buf,21) = val2;
  5004. WBUFL(buf,25) = val3;
  5005. }
  5006. #elif PACKETVER >= 20090121
  5007. if(flag && battle_config.display_status_timers && sd) {
  5008. if (tick <= 0)
  5009. tick = 9999; // this is indeed what official servers do
  5010. WBUFL(buf,9) = tick;
  5011. WBUFL(buf,13) = val1;
  5012. WBUFL(buf,17) = val2;
  5013. WBUFL(buf,21) = val3;
  5014. }
  5015. #endif
  5016. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  5017. }
  5018. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  5019. unsigned char buf[32];
  5020. if (type == SI_BLANK) //It shows nothing on the client
  5021. return;
  5022. nullpo_retv(bl);
  5023. WBUFW(buf,0) = 0x43f;
  5024. WBUFW(buf,2) = type;
  5025. WBUFL(buf,4) = tid;
  5026. WBUFB(buf,8) = 1;
  5027. WBUFL(buf,9) = 9999;
  5028. WBUFL(buf,13) = val1;
  5029. WBUFL(buf,17) = val2;
  5030. WBUFL(buf,21) = val3;
  5031. clif_send(buf,packet_len(0x43f),bl,target);
  5032. }
  5033. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5034. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5035. //! TODO
  5036. //void clif_efst_enter();
  5037. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5038. /// 008e <packet len>.W <message>.?B
  5039. void clif_displaymessage(const int fd, const char* mes)
  5040. {
  5041. nullpo_retv(mes);
  5042. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5043. if (fd == 0)
  5044. ;
  5045. else {
  5046. char *message, *line;
  5047. message = aStrdup(mes);
  5048. line = strtok(message, "\n");
  5049. #if PACKETVER == 20141022
  5050. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5051. /** so we redirect to ZC_NPC_CHAT **/
  5052. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5053. while(line != NULL) {
  5054. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5055. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5056. if (len > 0) {
  5057. WFIFOHEAD(fd, 13 + len);
  5058. WFIFOW(fd, 0) = 0x2C1;
  5059. WFIFOW(fd, 2) = 13 + len;
  5060. WFIFOL(fd, 4) = 0;
  5061. WFIFOL(fd, 8) = color;
  5062. safestrncpy((char*)WFIFOP(fd, 12), line, len + 1);
  5063. WFIFOSET(fd, WFIFOW(fd, 2));
  5064. }
  5065. #else
  5066. while(line != NULL) {
  5067. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5068. int len = strnlen(line, CHAT_SIZE_MAX);
  5069. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5070. WFIFOHEAD(fd, 5 + len);
  5071. WFIFOW(fd,0) = 0x8e;
  5072. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5073. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5074. WFIFOSET(fd, 5 + len);
  5075. }
  5076. #endif
  5077. line = strtok(NULL, "\n");
  5078. }
  5079. aFree(message);
  5080. }
  5081. }
  5082. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5083. /// 009a <packet len>.W <message>.?B
  5084. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5085. {
  5086. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5087. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5088. WBUFW(buf,0) = 0x9a;
  5089. WBUFW(buf,2) = 4 + lp + len;
  5090. if (type&BC_BLUE)
  5091. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5092. else if (type&BC_WOE)
  5093. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5094. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5095. clif_send(buf, WBUFW(buf,2), bl, target);
  5096. if (buf)
  5097. aFree(buf);
  5098. }
  5099. /*==========================================
  5100. * Displays a message on a 'bl' to all it's nearby clients
  5101. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5102. *------------------------------------------*/
  5103. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5104. char buf[100];
  5105. int len;
  5106. nullpo_retv(bl);
  5107. if(!message)
  5108. return;
  5109. len = strlen(message)+1;
  5110. if( len > sizeof(buf)-8 ) {
  5111. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5112. len = sizeof(buf)-8;
  5113. }
  5114. WBUFW(buf,0)=0x8d;
  5115. WBUFW(buf,2)=len+8;
  5116. WBUFL(buf,4)=bl->id;
  5117. safestrncpy((char *) WBUFP(buf,8),message,len);
  5118. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5119. }
  5120. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5121. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5122. 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)
  5123. {
  5124. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5125. WBUFW(buf,0) = 0x1c3;
  5126. WBUFW(buf,2) = len + 16;
  5127. WBUFL(buf,4) = fontColor;
  5128. WBUFW(buf,8) = fontType;
  5129. WBUFW(buf,10) = fontSize;
  5130. WBUFW(buf,12) = fontAlign;
  5131. WBUFW(buf,14) = fontY;
  5132. memcpy(WBUFP(buf,16), mes, len);
  5133. clif_send(buf, WBUFW(buf,2), bl, target);
  5134. if (buf)
  5135. aFree(buf);
  5136. }
  5137. /*
  5138. * Display *msg from *sd to all *users in channel
  5139. */
  5140. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5141. DBIterator *iter;
  5142. struct map_session_data *user;
  5143. unsigned short msg_len = strlen(msg) + 1;
  5144. WFIFOHEAD(sd->fd,msg_len + 12);
  5145. WFIFOW(sd->fd,0) = 0x2C1;
  5146. WFIFOW(sd->fd,2) = msg_len + 12;
  5147. WFIFOL(sd->fd,4) = 0;
  5148. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5149. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5150. iter = db_iterator(channel->users);
  5151. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5152. if( user->fd == sd->fd )
  5153. continue;
  5154. WFIFOHEAD(user->fd,msg_len + 12);
  5155. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5156. WFIFOSET(user->fd, msg_len + 12);
  5157. }
  5158. dbi_destroy(iter);
  5159. WFIFOSET(sd->fd, msg_len + 12);
  5160. }
  5161. /// Displays heal effect (ZC_RECOVERY).
  5162. /// 013d <var id>.W <amount>.W
  5163. /// var id:
  5164. /// 5 = HP (SP_HP)
  5165. /// 7 = SP (SP_SP)
  5166. /// ? = ignored
  5167. void clif_heal(int fd,int type,int val)
  5168. {
  5169. WFIFOHEAD(fd,packet_len(0x13d));
  5170. WFIFOW(fd,0)=0x13d;
  5171. WFIFOW(fd,2)=type;
  5172. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  5173. WFIFOSET(fd,packet_len(0x13d));
  5174. }
  5175. /// Displays resurrection effect (ZC_RESURRECTION).
  5176. /// 0148 <id>.L <type>.W
  5177. /// type:
  5178. /// ignored
  5179. void clif_resurrection(struct block_list *bl,int type)
  5180. {
  5181. unsigned char buf[16];
  5182. nullpo_retv(bl);
  5183. WBUFW(buf,0)=0x148;
  5184. WBUFL(buf,2)=bl->id;
  5185. WBUFW(buf,6)=0;
  5186. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5187. if (disguised(bl))
  5188. clif_spawn(bl);
  5189. }
  5190. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5191. /// 0199 <type>.W
  5192. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5193. {
  5194. int fd;
  5195. nullpo_retv(sd);
  5196. fd=sd->fd;
  5197. WFIFOHEAD(fd,packet_len(0x199));
  5198. WFIFOW(fd,0)=0x199;
  5199. WFIFOW(fd,2)=property;
  5200. WFIFOSET(fd,packet_len(0x199));
  5201. }
  5202. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5203. #if PACKETVER >= 20121010
  5204. unsigned char buf[8];
  5205. unsigned int NotifyProperty =
  5206. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5207. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5208. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5209. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5210. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5211. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5212. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5213. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5214. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5215. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5216. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5217. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5218. WBUFW(buf,0)=0x99b;
  5219. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5220. WBUFL(buf,4)=NotifyProperty;
  5221. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5222. clif_send(buf,packet_len(0x99b),bl,t);
  5223. #endif
  5224. }
  5225. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5226. /// 01d6 <type>.W
  5227. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5228. {
  5229. int fd;
  5230. nullpo_retv(sd);
  5231. fd=sd->fd;
  5232. WFIFOHEAD(fd,packet_len(0x1D6));
  5233. WFIFOW(fd,0)=0x1D6;
  5234. WFIFOW(fd,2)=type;
  5235. WFIFOSET(fd,packet_len(0x1D6));
  5236. }
  5237. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5238. /// 019a <id>.L <ranking>.L <total>.L
  5239. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5240. {
  5241. if(type == 2) {
  5242. int fd = sd->fd;
  5243. WFIFOHEAD(fd,packet_len(0x19a));
  5244. WFIFOW(fd,0) = 0x19a;
  5245. WFIFOL(fd,2) = sd->bl.id;
  5246. WFIFOL(fd,6) = pvprank;
  5247. WFIFOL(fd,10) = pvpnum;
  5248. WFIFOSET(fd,packet_len(0x19a));
  5249. } else {
  5250. unsigned char buf[32];
  5251. WBUFW(buf,0) = 0x19a;
  5252. WBUFL(buf,2) = sd->bl.id;
  5253. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5254. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5255. else
  5256. WBUFL(buf,6) = pvprank;
  5257. WBUFL(buf,10) = pvpnum;
  5258. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5259. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5260. else if(!type)
  5261. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5262. else
  5263. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5264. }
  5265. }
  5266. /*==========================================
  5267. *
  5268. *------------------------------------------*/
  5269. void clif_map_property_mapall(int map_idx, enum map_property property)
  5270. {
  5271. struct block_list bl;
  5272. unsigned char buf[16];
  5273. bl.id = 0;
  5274. bl.type = BL_NUL;
  5275. bl.m = map_idx;
  5276. WBUFW(buf,0)=0x199;
  5277. WBUFW(buf,2)=property;
  5278. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5279. }
  5280. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5281. /// 0188 <result>.W <index>.W <refine>.W
  5282. /// result:
  5283. /// 0 = success
  5284. /// 1 = failure
  5285. /// 2 = downgrade
  5286. void clif_refine(int fd, int fail, int index, int val)
  5287. {
  5288. WFIFOHEAD(fd,packet_len(0x188));
  5289. WFIFOW(fd,0)=0x188;
  5290. WFIFOW(fd,2)=fail;
  5291. WFIFOW(fd,4)=index+2;
  5292. WFIFOW(fd,6)=val;
  5293. WFIFOSET(fd,packet_len(0x188));
  5294. }
  5295. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5296. /// 0223 <result>.L <nameid>.W
  5297. /// result:
  5298. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5299. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5300. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5301. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5302. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5303. {
  5304. WFIFOHEAD(fd,packet_len(0x223));
  5305. WFIFOW(fd,0)=0x223;
  5306. WFIFOL(fd,2)=result;
  5307. WFIFOW(fd,6)=item_id;
  5308. WFIFOSET(fd,packet_len(0x223));
  5309. }
  5310. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5311. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5312. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5313. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5314. {
  5315. #if PACKETVER < 20091104
  5316. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5317. WFIFOW(fd,0) = 0x97;
  5318. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5319. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5320. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5321. WFIFOSET(fd,WFIFOW(fd,2));
  5322. #else
  5323. struct map_session_data *ssd = map_nick2sd(nick);
  5324. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5325. WFIFOW(fd,0) = 0x97;
  5326. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5327. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5328. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5329. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5330. WFIFOSET(fd,WFIFOW(fd,2));
  5331. #endif
  5332. }
  5333. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5334. /// 0098 <result>.B
  5335. /// result:
  5336. /// 0 = success to send wisper
  5337. /// 1 = target character is not loged in
  5338. /// 2 = ignored by target
  5339. /// 3 = everyone ignored by target
  5340. void clif_wis_end(int fd, int result)
  5341. {
  5342. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5343. if (!sd)
  5344. return;
  5345. #if PACKETVER >= 20131223
  5346. WFIFOHEAD(fd,packet_len(0x9df));
  5347. WFIFOW(fd,0) = 0x9df;
  5348. WFIFOB(fd,2) = (char)result;
  5349. WFIFOL(fd,3) = 0;
  5350. WFIFOSET(fd,packet_len(0x9df));
  5351. #else
  5352. WFIFOHEAD(fd,packet_len(0x98));
  5353. WFIFOW(fd,0) = 0x98;
  5354. WFIFOB(fd,2) = (char)result;
  5355. WFIFOSET(fd,packet_len(0x98));
  5356. #endif
  5357. }
  5358. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5359. /// 0194 <char id>.L <name>.24B
  5360. void clif_solved_charname(int fd, int charid, const char* name)
  5361. {
  5362. WFIFOHEAD(fd,packet_len(0x194));
  5363. WFIFOW(fd,0)=0x194;
  5364. WFIFOL(fd,2)=charid;
  5365. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5366. WFIFOSET(fd,packet_len(0x194));
  5367. }
  5368. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5369. /// 017b <packet len>.W { <name id>.W }*
  5370. void clif_use_card(struct map_session_data *sd,int idx)
  5371. {
  5372. int i,c,ep;
  5373. int fd=sd->fd;
  5374. nullpo_retv(sd);
  5375. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5376. return;
  5377. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5378. return; //Avoid parsing invalid item indexes (no card/no item)
  5379. ep=sd->inventory_data[idx]->equip;
  5380. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5381. WFIFOW(fd,0)=0x17b;
  5382. for(i=c=0;i<MAX_INVENTORY;i++){
  5383. int j;
  5384. if(sd->inventory_data[i] == NULL)
  5385. continue;
  5386. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5387. continue;
  5388. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5389. continue;
  5390. if(sd->status.inventory[i].identify==0 ) //Not identified
  5391. continue;
  5392. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5393. continue;
  5394. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5395. continue;
  5396. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5397. if( j == sd->inventory_data[i]->slot ) // No room
  5398. continue;
  5399. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5400. continue;
  5401. WFIFOW(fd,4+c*2)=i+2;
  5402. c++;
  5403. }
  5404. if( !c ) return; // no item is available for card insertion
  5405. WFIFOW(fd,2)=4+c*2;
  5406. WFIFOSET(fd,WFIFOW(fd,2));
  5407. }
  5408. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5409. /// 017d <equip index>.W <card index>.W <result>.B
  5410. /// result:
  5411. /// 0 = success
  5412. /// 1 = failure
  5413. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5414. {
  5415. int fd;
  5416. nullpo_retv(sd);
  5417. fd=sd->fd;
  5418. WFIFOHEAD(fd,packet_len(0x17d));
  5419. WFIFOW(fd,0)=0x17d;
  5420. WFIFOW(fd,2)=idx_equip+2;
  5421. WFIFOW(fd,4)=idx_card+2;
  5422. WFIFOB(fd,6)=flag;
  5423. WFIFOSET(fd,packet_len(0x17d));
  5424. }
  5425. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5426. /// 0177 <packet len>.W { <name id>.W }*
  5427. void clif_item_identify_list(struct map_session_data *sd)
  5428. {
  5429. int i,c;
  5430. int fd;
  5431. nullpo_retv(sd);
  5432. fd=sd->fd;
  5433. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5434. WFIFOW(fd,0)=0x177;
  5435. for(i=c=0;i<MAX_INVENTORY;i++){
  5436. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5437. WFIFOW(fd,c*2+4)=i+2;
  5438. c++;
  5439. }
  5440. }
  5441. if(c > 0) {
  5442. WFIFOW(fd,2)=c*2+4;
  5443. WFIFOSET(fd,WFIFOW(fd,2));
  5444. sd->menuskill_id = MC_IDENTIFY;
  5445. sd->menuskill_val = c;
  5446. }
  5447. }
  5448. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5449. /// 0179 <index>.W <result>.B
  5450. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5451. {
  5452. int fd;
  5453. nullpo_retv(sd);
  5454. fd=sd->fd;
  5455. WFIFOHEAD(fd,packet_len(0x179));
  5456. WFIFOW(fd, 0)=0x179;
  5457. WFIFOW(fd, 2)=idx+2;
  5458. WFIFOB(fd, 4)=flag;
  5459. WFIFOSET(fd,packet_len(0x179));
  5460. }
  5461. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5462. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5463. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5464. {
  5465. int i,c;
  5466. int fd;
  5467. nullpo_retv(sd);
  5468. nullpo_retv(dstsd);
  5469. fd=sd->fd;
  5470. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5471. WFIFOW(fd,0)=0x1fc;
  5472. for(i=c=0;i<MAX_INVENTORY;i++){
  5473. unsigned short nameid;
  5474. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5475. WFIFOW(fd,c*13+4) = i;
  5476. WFIFOW(fd,c*13+6) = nameid;
  5477. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5478. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5479. c++;
  5480. }
  5481. }
  5482. if(c > 0) {
  5483. WFIFOW(fd,2)=c*13+4;
  5484. WFIFOSET(fd,WFIFOW(fd,2));
  5485. sd->menuskill_id = BS_REPAIRWEAPON;
  5486. sd->menuskill_val = dstsd->bl.id;
  5487. sd->menuskill_val2 = lv;
  5488. }else
  5489. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5490. }
  5491. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5492. /// 01fe <index>.W <result>.B
  5493. /// index:
  5494. /// ignored (inventory index)
  5495. /// result:
  5496. /// 0 = Item repair success.
  5497. /// 1 = Item repair failure.
  5498. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5499. {
  5500. int fd;
  5501. nullpo_retv(sd);
  5502. fd = sd->fd;
  5503. WFIFOHEAD(fd,packet_len(0x1fe));
  5504. WFIFOW(fd, 0)=0x1fe;
  5505. WFIFOW(fd, 2)=idx+2;
  5506. WFIFOB(fd, 4)=flag;
  5507. WFIFOSET(fd,packet_len(0x1fe));
  5508. }
  5509. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5510. /// 02bb <equip location>.W <account id>.L
  5511. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5512. {
  5513. int fd = sd->fd;
  5514. WFIFOHEAD(fd,packet_len(0x2bb));
  5515. WFIFOW(fd,0) = 0x2bb;
  5516. WFIFOW(fd,2) = position;
  5517. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5518. WFIFOSET(fd,packet_len(0x2bb));
  5519. }
  5520. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5521. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5522. void clif_item_refine_list(struct map_session_data *sd)
  5523. {
  5524. int i,c;
  5525. int fd;
  5526. uint16 skill_lv;
  5527. int refine_item[5];
  5528. nullpo_retv(sd);
  5529. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5530. fd=sd->fd;
  5531. refine_item[0] = -1;
  5532. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5533. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5534. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5535. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5536. WFIFOW(fd,0)=0x221;
  5537. for(i=c=0;i<MAX_INVENTORY;i++){
  5538. unsigned char wlv;
  5539. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5540. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5541. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5542. WFIFOW(fd,c*13+ 4)=i+2;
  5543. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5544. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5545. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5546. c++;
  5547. }
  5548. }
  5549. WFIFOW(fd,2)=c*13+4;
  5550. WFIFOSET(fd,WFIFOW(fd,2));
  5551. if (c > 0) {
  5552. sd->menuskill_id = WS_WEAPONREFINE;
  5553. sd->menuskill_val = skill_lv;
  5554. }
  5555. }
  5556. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5557. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5558. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5559. {
  5560. int fd;
  5561. nullpo_retv(sd);
  5562. fd=sd->fd;
  5563. WFIFOHEAD(fd,packet_len(0x147));
  5564. WFIFOW(fd, 0)=0x147;
  5565. WFIFOW(fd, 2)=skill_id;
  5566. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5567. WFIFOW(fd, 6)=0;
  5568. WFIFOW(fd, 8)=skill_lv;
  5569. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5570. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5571. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5572. WFIFOB(fd,38)=0;
  5573. WFIFOSET(fd,packet_len(0x147));
  5574. }
  5575. /// Adds an item to character's cart.
  5576. /// 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)
  5577. /// 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)
  5578. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5579. {
  5580. int view,fd;
  5581. unsigned char *buf;
  5582. nullpo_retv(sd);
  5583. fd=sd->fd;
  5584. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5585. return;
  5586. #if PACKETVER < 5
  5587. WFIFOHEAD(fd,packet_len(0x124));
  5588. buf=WFIFOP(fd,0);
  5589. WBUFW(buf,0)=0x124;
  5590. WBUFW(buf,2)=n+2;
  5591. WBUFL(buf,4)=amount;
  5592. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5593. WBUFW(buf,8)=view;
  5594. else
  5595. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5596. WBUFB(buf,10)=sd->status.cart[n].identify;
  5597. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5598. WBUFB(buf,12)=sd->status.cart[n].refine;
  5599. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5600. WFIFOSET(fd,packet_len(0x124));
  5601. #else
  5602. WFIFOHEAD(fd,packet_len(0x1c5));
  5603. buf=WFIFOP(fd,0);
  5604. WBUFW(buf,0)=0x1c5;
  5605. WBUFW(buf,2)=n+2;
  5606. WBUFL(buf,4)=amount;
  5607. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5608. WBUFW(buf,8)=view;
  5609. else
  5610. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5611. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5612. WBUFB(buf,11)=sd->status.cart[n].identify;
  5613. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5614. WBUFB(buf,13)=sd->status.cart[n].refine;
  5615. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5616. WFIFOSET(fd,packet_len(0x1c5));
  5617. #endif
  5618. }
  5619. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5620. /* Acknowledge an item have been added to cart
  5621. * 012c <result>B
  5622. * result :
  5623. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5624. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5625. */
  5626. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5627. {
  5628. int fd;
  5629. unsigned char *buf;
  5630. nullpo_retv(sd);
  5631. fd = sd->fd;
  5632. buf = WFIFOP(fd,0);
  5633. WBUFW(buf,0) = 0x12c;
  5634. WBUFB(buf,2) = flag;
  5635. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5636. }
  5637. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5638. void clif_bank_open(struct map_session_data *sd){
  5639. int fd;
  5640. nullpo_retv(sd);
  5641. fd = sd->fd;
  5642. WFIFOHEAD(fd,4);
  5643. WFIFOW(fd,0) = 0x09b7;
  5644. WFIFOW(fd,2) = 0;
  5645. WFIFOSET(fd,4);
  5646. }
  5647. /*
  5648. * Request to Open the banking system
  5649. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5650. */
  5651. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5652. //TODO check if preventing trade or stuff like that
  5653. //also mark something in case char ain't available for saving, should we check now ?
  5654. nullpo_retv(sd);
  5655. if( !battle_config.feature_banking ) {
  5656. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5657. return;
  5658. }
  5659. else {
  5660. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5661. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5662. if(sd->status.account_id == aid){
  5663. sd->state.banking = 1;
  5664. //request save ?
  5665. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5666. //on succes open bank ?
  5667. clif_bank_open(sd);
  5668. }
  5669. }
  5670. }
  5671. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5672. void clif_bank_close(struct map_session_data *sd){
  5673. int fd;
  5674. nullpo_retv(sd);
  5675. fd = sd->fd;
  5676. WFIFOHEAD(fd,4);
  5677. WFIFOW(fd,0) = 0x09B9;
  5678. WFIFOW(fd,2) = 0;
  5679. WFIFOSET(fd,4);
  5680. }
  5681. /*
  5682. * Request to close the banking system
  5683. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5684. */
  5685. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5686. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5687. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5688. nullpo_retv(sd);
  5689. if( !battle_config.feature_banking ) {
  5690. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5691. //still allow to go trough to not stuck player if we have disable it while they was in
  5692. }
  5693. if(sd->status.account_id == aid){
  5694. sd->state.banking = 0;
  5695. clif_bank_close(sd);
  5696. }
  5697. }
  5698. /*
  5699. * Display how much we got in bank (I suppose)
  5700. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5701. */
  5702. void clif_Bank_Check(struct map_session_data* sd) {
  5703. unsigned char buf[13];
  5704. struct s_packet_db* info;
  5705. int16 len;
  5706. int cmd = 0;
  5707. nullpo_retv(sd);
  5708. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5709. if(!cmd) cmd = 0x09A6; //default
  5710. info = &packet_db[sd->packet_ver][cmd];
  5711. len = info->len;
  5712. if(!len) return; //version as packet disable
  5713. // sd->state.banking = 1; //mark opening and closing
  5714. WBUFW(buf,0) = cmd;
  5715. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5716. WBUFW(buf,info->pos[1]) = 0; //reason
  5717. clif_send(buf,len,&sd->bl,SELF);
  5718. }
  5719. /*
  5720. * Requesting the data in bank
  5721. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5722. */
  5723. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5724. nullpo_retv(sd);
  5725. if( !battle_config.feature_banking ) {
  5726. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5727. return;
  5728. }
  5729. else {
  5730. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5731. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5732. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5733. clif_Bank_Check(sd);
  5734. }
  5735. }
  5736. /*
  5737. * Acknowledge of deposit some money in bank
  5738. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5739. */
  5740. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5741. unsigned char buf[17];
  5742. struct s_packet_db* info;
  5743. int16 len;
  5744. int cmd =0;
  5745. nullpo_retv(sd);
  5746. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5747. if(!cmd) cmd = 0x09A8;
  5748. info = &packet_db[sd->packet_ver][cmd];
  5749. len = info->len;
  5750. if(!len) return; //version as packet disable
  5751. WBUFW(buf,0) = cmd;
  5752. WBUFW(buf,info->pos[0]) = (short)reason;
  5753. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5754. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5755. clif_send(buf,len,&sd->bl,SELF);
  5756. }
  5757. /*
  5758. * Request saving some money in bank
  5759. * @author : original [Yommy/Hercules]
  5760. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5761. */
  5762. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5763. nullpo_retv(sd);
  5764. if( !battle_config.feature_banking ) {
  5765. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5766. return;
  5767. }
  5768. else {
  5769. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5770. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5771. int money = RFIFOL(fd,info->pos[1]);
  5772. if(sd->status.account_id == aid){
  5773. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5774. clif_bank_deposit(sd,reason);
  5775. }
  5776. }
  5777. }
  5778. /*
  5779. * Acknowledge of withdrawing some money from bank
  5780. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5781. */
  5782. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5783. unsigned char buf[17];
  5784. struct s_packet_db* info;
  5785. int16 len;
  5786. int cmd;
  5787. nullpo_retv(sd);
  5788. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5789. if(!cmd) cmd = 0x09AA;
  5790. info = &packet_db[sd->packet_ver][cmd];
  5791. len = info->len;
  5792. if(!len) return; //version as packet disable
  5793. WBUFW(buf,0) = cmd;
  5794. WBUFW(buf,info->pos[0]) = (short)reason;
  5795. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5796. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5797. clif_send(buf,len,&sd->bl,SELF);
  5798. }
  5799. /*
  5800. * Request Withdrawing some money from bank
  5801. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5802. */
  5803. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5804. nullpo_retv(sd);
  5805. if( !battle_config.feature_banking ) {
  5806. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5807. return;
  5808. }
  5809. else {
  5810. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5811. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5812. int money = RFIFOL(fd,info->pos[1]);
  5813. if(sd->status.account_id == aid){
  5814. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5815. clif_bank_withdraw(sd,reason);
  5816. }
  5817. }
  5818. }
  5819. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5820. /// 0125 <index>.W <amount>.L
  5821. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5822. {
  5823. int fd;
  5824. nullpo_retv(sd);
  5825. fd=sd->fd;
  5826. WFIFOHEAD(fd,packet_len(0x125));
  5827. WFIFOW(fd,0)=0x125;
  5828. WFIFOW(fd,2)=n+2;
  5829. WFIFOL(fd,4)=amount;
  5830. WFIFOSET(fd,packet_len(0x125));
  5831. }
  5832. /// Opens the shop creation menu (ZC_OPENSTORE).
  5833. /// 012d <num>.W
  5834. /// num:
  5835. /// number of allowed item slots
  5836. void clif_openvendingreq(struct map_session_data* sd, int num)
  5837. {
  5838. int fd;
  5839. nullpo_retv(sd);
  5840. fd = sd->fd;
  5841. WFIFOHEAD(fd,packet_len(0x12d));
  5842. WFIFOW(fd,0) = 0x12d;
  5843. WFIFOW(fd,2) = num;
  5844. WFIFOSET(fd,packet_len(0x12d));
  5845. }
  5846. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5847. /// 0131 <owner id>.L <message>.80B
  5848. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5849. {
  5850. unsigned char buf[128];
  5851. nullpo_retv(bl);
  5852. WBUFW(buf,0) = 0x131;
  5853. WBUFL(buf,2) = bl->id;
  5854. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5855. if( fd ) {
  5856. WFIFOHEAD(fd,packet_len(0x131));
  5857. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5858. WFIFOSET(fd,packet_len(0x131));
  5859. } else {
  5860. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5861. }
  5862. }
  5863. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5864. /// 0132 <owner id>.L
  5865. void clif_closevendingboard(struct block_list* bl, int fd)
  5866. {
  5867. unsigned char buf[16];
  5868. nullpo_retv(bl);
  5869. WBUFW(buf,0) = 0x132;
  5870. WBUFL(buf,2) = bl->id;
  5871. if( fd ) {
  5872. WFIFOHEAD(fd,packet_len(0x132));
  5873. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5874. WFIFOSET(fd,packet_len(0x132));
  5875. } else {
  5876. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5877. }
  5878. }
  5879. /// Sends a list of items in a shop.
  5880. /// 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)
  5881. /// 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)
  5882. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5883. {
  5884. int i,fd;
  5885. int count;
  5886. struct map_session_data* vsd;
  5887. #if PACKETVER < 20100105
  5888. const int cmd = 0x133;
  5889. const int offset = 8;
  5890. #else
  5891. const int cmd = 0x800;
  5892. const int offset = 12;
  5893. #endif
  5894. nullpo_retv(sd);
  5895. nullpo_retv(vending);
  5896. nullpo_retv(vsd=map_id2sd(id));
  5897. fd = sd->fd;
  5898. count = vsd->vend_num;
  5899. WFIFOHEAD(fd, offset+count*22);
  5900. WFIFOW(fd,0) = cmd;
  5901. WFIFOW(fd,2) = offset+count*22;
  5902. WFIFOL(fd,4) = id;
  5903. #if PACKETVER >= 20100105
  5904. WFIFOL(fd,8) = vsd->vender_id;
  5905. #endif
  5906. for( i = 0; i < count; i++ )
  5907. {
  5908. int index = vending[i].index;
  5909. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5910. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5911. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5912. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5913. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5914. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5915. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5916. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5917. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5918. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5919. }
  5920. WFIFOSET(fd,WFIFOW(fd,2));
  5921. }
  5922. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5923. /// 0135 <index>.W <amount>.W <result>.B
  5924. /// result:
  5925. /// 0 = success
  5926. /// 1 = not enough zeny
  5927. /// 2 = overweight
  5928. /// 4 = out of stock
  5929. /// 5 = "cannot use an npc shop while in a trade"
  5930. /// 6 = Because the store information was incorrect the item was not purchased.
  5931. /// 7 = No sales information.
  5932. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5933. {
  5934. int fd;
  5935. nullpo_retv(sd);
  5936. fd = sd->fd;
  5937. WFIFOHEAD(fd,packet_len(0x135));
  5938. WFIFOW(fd,0) = 0x135;
  5939. WFIFOW(fd,2) = index+2;
  5940. WFIFOW(fd,4) = amount;
  5941. WFIFOB(fd,6) = fail;
  5942. WFIFOSET(fd,packet_len(0x135));
  5943. }
  5944. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5945. /// 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 }*
  5946. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5947. {
  5948. int i,fd;
  5949. int count;
  5950. nullpo_retv(sd);
  5951. fd = sd->fd;
  5952. count = sd->vend_num;
  5953. WFIFOHEAD(fd, 8+count*22);
  5954. WFIFOW(fd,0) = 0x136;
  5955. WFIFOW(fd,2) = 8+count*22;
  5956. WFIFOL(fd,4) = id;
  5957. for( i = 0; i < count; i++ ) {
  5958. int index = vending[i].index;
  5959. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5960. WFIFOL(fd, 8+i*22) = vending[i].value;
  5961. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5962. WFIFOW(fd,14+i*22) = vending[i].amount;
  5963. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5964. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5965. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5966. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5967. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5968. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5969. }
  5970. WFIFOSET(fd,WFIFOW(fd,2));
  5971. #if PACKETVER >= 20141022
  5972. // Should go elsewhere perhaps? It has to be bundled with this however.
  5973. WFIFOHEAD(fd, 3);
  5974. WFIFOW(fd, 0) = 0xa28;
  5975. WFIFOB(fd, 2) = 0; // 1 is failure. Our current responses to failure are working so not yet implemented.
  5976. WFIFOSET(fd, 3);
  5977. #endif
  5978. }
  5979. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5980. /// 0137 <index>.W <amount>.W
  5981. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5982. {
  5983. int fd;
  5984. nullpo_retv(sd);
  5985. fd = sd->fd;
  5986. WFIFOHEAD(fd,packet_len(0x137));
  5987. WFIFOW(fd,0) = 0x137;
  5988. WFIFOW(fd,2) = index+2;
  5989. WFIFOW(fd,4) = amount;
  5990. WFIFOSET(fd,packet_len(0x137));
  5991. }
  5992. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5993. /// 00fa <result>.B
  5994. /// result:
  5995. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5996. /// 1 = MsgStringTable[78]="party name already exists"
  5997. /// 2 = MsgStringTable[79]="already in a party"
  5998. /// 3 = cannot organize parties on this map
  5999. /// ? = nothing
  6000. void clif_party_created(struct map_session_data *sd,int result)
  6001. {
  6002. int fd;
  6003. nullpo_retv(sd);
  6004. fd=sd->fd;
  6005. WFIFOHEAD(fd,packet_len(0xfa));
  6006. WFIFOW(fd,0)=0xfa;
  6007. WFIFOB(fd,2)=result;
  6008. WFIFOSET(fd,packet_len(0xfa));
  6009. }
  6010. /// Adds new member to a party.
  6011. /// 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)
  6012. /// 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)
  6013. /// role:
  6014. /// 0 = leader
  6015. /// 1 = normal
  6016. /// state:
  6017. /// 0 = connected
  6018. /// 1 = disconnected
  6019. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6020. {
  6021. unsigned char buf[81];
  6022. int i;
  6023. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6024. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6025. } else {
  6026. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6027. }
  6028. if (i >= MAX_PARTY) return; //Should never happen...
  6029. sd = p->data[i].sd;
  6030. WBUFW(buf, 0) = 0x1e9;
  6031. WBUFL(buf, 2) = sd->status.account_id;
  6032. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6033. WBUFW(buf,10) = sd->bl.x;
  6034. WBUFW(buf,12) = sd->bl.y;
  6035. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6036. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6037. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6038. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6039. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6040. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6041. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6042. }
  6043. /// Sends party information (ZC_GROUP_LIST).
  6044. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6045. /// role:
  6046. /// 0 = leader
  6047. /// 1 = normal
  6048. /// state:
  6049. /// 0 = connected
  6050. /// 1 = disconnected
  6051. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6052. {
  6053. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6054. struct map_session_data* party_sd = NULL;
  6055. int i, c;
  6056. nullpo_retv(p);
  6057. WBUFW(buf,0) = 0xfb;
  6058. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6059. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6060. {
  6061. struct party_member* m = &p->party.member[i];
  6062. if(!m->account_id) continue;
  6063. if(party_sd == NULL) party_sd = p->data[i].sd;
  6064. WBUFL(buf,28+c*46) = m->account_id;
  6065. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6066. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6067. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6068. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6069. c++;
  6070. }
  6071. WBUFW(buf,2) = 28+c*46;
  6072. if(sd) { // send only to self
  6073. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6074. } else if (party_sd) { // send to whole party
  6075. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6076. }
  6077. }
  6078. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6079. /// 02c9 <flag>.B
  6080. /// flag:
  6081. /// 0 = allow party invites
  6082. /// 1 = auto-deny party invites
  6083. void clif_partyinvitationstate(struct map_session_data* sd)
  6084. {
  6085. int fd;
  6086. nullpo_retv(sd);
  6087. fd = sd->fd;
  6088. WFIFOHEAD(fd, packet_len(0x2c9));
  6089. WFIFOW(fd, 0) = 0x2c9;
  6090. WFIFOB(fd, 2) = 0; // not implemented
  6091. WFIFOSET(fd, packet_len(0x2c9));
  6092. }
  6093. /// Party invitation request.
  6094. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6095. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6096. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6097. {
  6098. #if PACKETVER < 20070821
  6099. const int cmd = 0xfe;
  6100. #else
  6101. const int cmd = 0x2c6;
  6102. #endif
  6103. int fd;
  6104. struct party_data *p;
  6105. nullpo_retv(sd);
  6106. nullpo_retv(tsd);
  6107. fd=tsd->fd;
  6108. if( (p=party_search(sd->status.party_id))==NULL )
  6109. return;
  6110. WFIFOHEAD(fd,packet_len(cmd));
  6111. WFIFOW(fd,0)=cmd;
  6112. WFIFOL(fd,2)=sd->status.party_id;
  6113. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6114. WFIFOSET(fd,packet_len(cmd));
  6115. }
  6116. /// Party invite result.
  6117. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6118. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6119. /// result=0 : char is already in a party -> MsgStringTable[80]
  6120. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6121. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6122. /// result=3 : party is full -> MsgStringTable[83]
  6123. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6124. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6125. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6126. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  6127. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  6128. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  6129. {
  6130. int fd;
  6131. nullpo_retv(sd);
  6132. fd=sd->fd;
  6133. #if PACKETVER < 20070904
  6134. if( result == 7 ) {
  6135. clif_displaymessage(fd, msg_txt(sd,3));
  6136. return;
  6137. }
  6138. #endif
  6139. #if PACKETVER < 20070821
  6140. WFIFOHEAD(fd,packet_len(0xfd));
  6141. WFIFOW(fd,0) = 0xfd;
  6142. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6143. WFIFOB(fd,26) = result;
  6144. WFIFOSET(fd,packet_len(0xfd));
  6145. #else
  6146. WFIFOHEAD(fd,packet_len(0x2c5));
  6147. WFIFOW(fd,0) = 0x2c5;
  6148. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6149. WFIFOL(fd,26) = result;
  6150. WFIFOSET(fd,packet_len(0x2c5));
  6151. #endif
  6152. }
  6153. /// Updates party settings.
  6154. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6155. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6156. /// exp option:
  6157. /// 0 = exp sharing disabled
  6158. /// 1 = exp sharing enabled
  6159. /// 2 = cannot change exp sharing
  6160. ///
  6161. /// flag:
  6162. /// 0 = send to party
  6163. /// 1 = send to sd
  6164. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6165. {
  6166. unsigned char buf[16];
  6167. #if PACKETVER < 20090603
  6168. const int cmd = 0x101;
  6169. #else
  6170. const int cmd = 0x7d8;
  6171. #endif
  6172. nullpo_retv(p);
  6173. if(!sd && flag==0){
  6174. int i;
  6175. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6176. if (i < MAX_PARTY)
  6177. sd = p->data[i].sd;
  6178. }
  6179. if(!sd) return;
  6180. WBUFW(buf,0)=cmd;
  6181. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6182. #if PACKETVER >= 20090603
  6183. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6184. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6185. #endif
  6186. if(flag==0)
  6187. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6188. else
  6189. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6190. }
  6191. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6192. /// result:
  6193. /// 0 = leave
  6194. /// 1 = expel
  6195. /// 2 = cannot leave party on this map
  6196. /// 3 = cannot expel from party on this map
  6197. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6198. {
  6199. unsigned char buf[64];
  6200. nullpo_retv(p);
  6201. if(!sd && (flag&0xf0)==0)
  6202. {
  6203. int i;
  6204. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6205. if (i < MAX_PARTY)
  6206. sd = p->data[i].sd;
  6207. }
  6208. if(!sd) return;
  6209. WBUFW(buf,0)=0x105;
  6210. WBUFL(buf,2)=account_id;
  6211. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6212. WBUFB(buf,30)=flag&0x0f;
  6213. if((flag&0xf0)==0)
  6214. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6215. else
  6216. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6217. }
  6218. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6219. /// 0109 <packet len>.W <account id>.L <message>.?B
  6220. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6221. {
  6222. struct map_session_data *sd;
  6223. int i;
  6224. nullpo_retv(p);
  6225. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6226. if(i < MAX_PARTY){
  6227. unsigned char buf[1024];
  6228. if( len > sizeof(buf)-8 )
  6229. {
  6230. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6231. len = sizeof(buf)-8;
  6232. }
  6233. sd = p->data[i].sd;
  6234. WBUFW(buf,0)=0x109;
  6235. WBUFW(buf,2)=len+8;
  6236. WBUFL(buf,4)=account_id;
  6237. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6238. clif_send(buf,len+8,&sd->bl,PARTY);
  6239. }
  6240. }
  6241. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6242. /// 0107 <account id>.L <x>.W <y>.W
  6243. void clif_party_xy(struct map_session_data *sd)
  6244. {
  6245. unsigned char buf[16];
  6246. nullpo_retv(sd);
  6247. WBUFW(buf,0)=0x107;
  6248. WBUFL(buf,2)=sd->status.account_id;
  6249. WBUFW(buf,6)=sd->bl.x;
  6250. WBUFW(buf,8)=sd->bl.y;
  6251. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6252. }
  6253. /*==========================================
  6254. * Sends x/y dot to a single fd. [Skotlex]
  6255. *------------------------------------------*/
  6256. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6257. {
  6258. WFIFOHEAD(fd,packet_len(0x107));
  6259. WFIFOW(fd,0)=0x107;
  6260. WFIFOL(fd,2)=sd->status.account_id;
  6261. WFIFOW(fd,6)=sd->bl.x;
  6262. WFIFOW(fd,8)=sd->bl.y;
  6263. WFIFOSET(fd,packet_len(0x107));
  6264. }
  6265. /// Updates HP bar of a party member.
  6266. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6267. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6268. void clif_party_hp(struct map_session_data *sd)
  6269. {
  6270. unsigned char buf[16];
  6271. #if PACKETVER < 20100126
  6272. const int cmd = 0x106;
  6273. #else
  6274. const int cmd = 0x80e;
  6275. #endif
  6276. nullpo_retv(sd);
  6277. WBUFW(buf,0)=cmd;
  6278. WBUFL(buf,2)=sd->status.account_id;
  6279. #if PACKETVER < 20100126
  6280. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6281. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6282. WBUFW(buf,8) = 100;
  6283. } else {
  6284. WBUFW(buf,6) = sd->battle_status.hp;
  6285. WBUFW(buf,8) = sd->battle_status.max_hp;
  6286. }
  6287. #else
  6288. WBUFL(buf,6) = sd->battle_status.hp;
  6289. WBUFL(buf,10) = sd->battle_status.max_hp;
  6290. #endif
  6291. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6292. }
  6293. /*==========================================
  6294. * Sends HP bar to a single fd. [Skotlex]
  6295. *------------------------------------------*/
  6296. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6297. {
  6298. #if PACKETVER < 20100126
  6299. const int cmd = 0x106;
  6300. #else
  6301. const int cmd = 0x80e;
  6302. #endif
  6303. WFIFOHEAD(fd,packet_len(cmd));
  6304. WFIFOW(fd,0) = cmd;
  6305. WFIFOL(fd,2) = id;
  6306. #if PACKETVER < 20100126
  6307. if( maxhp > INT16_MAX )
  6308. {// To correctly display the %hp bar. [Skotlex]
  6309. WFIFOW(fd,6) = hp/(maxhp/100);
  6310. WFIFOW(fd,8) = 100;
  6311. } else {
  6312. WFIFOW(fd,6) = hp;
  6313. WFIFOW(fd,8) = maxhp;
  6314. }
  6315. #else
  6316. WFIFOL(fd,6) = hp;
  6317. WFIFOL(fd,10) = maxhp;
  6318. #endif
  6319. WFIFOSET(fd, packet_len(cmd));
  6320. }
  6321. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6322. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6323. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6324. {
  6325. int fd;
  6326. nullpo_retv(sd);
  6327. nullpo_retv(bl);
  6328. fd=sd->fd;
  6329. WFIFOHEAD(fd,packet_len(0x139));
  6330. WFIFOW(fd, 0)=0x139;
  6331. WFIFOL(fd, 2)=bl->id;
  6332. WFIFOW(fd, 6)=bl->x;
  6333. WFIFOW(fd, 8)=bl->y;
  6334. WFIFOW(fd,10)=sd->bl.x;
  6335. WFIFOW(fd,12)=sd->bl.y;
  6336. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6337. WFIFOSET(fd,packet_len(0x139));
  6338. }
  6339. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6340. /// 018f <result>.W <name id>.W
  6341. /// result:
  6342. /// 0 = success
  6343. /// 1 = failure
  6344. /// 2 = success (alchemist)
  6345. /// 3 = failure (alchemist)
  6346. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6347. {
  6348. int view,fd;
  6349. nullpo_retv(sd);
  6350. fd = sd->fd;
  6351. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6352. WFIFOHEAD(fd,packet_len(0x18f));
  6353. WFIFOW(fd, 0)=0x18f;
  6354. WFIFOW(fd, 2)=flag;
  6355. if((view = itemdb_viewid(nameid)) > 0)
  6356. WFIFOW(fd, 4)=view;
  6357. else
  6358. WFIFOW(fd, 4)=nameid;
  6359. WFIFOSET(fd,packet_len(0x18f));
  6360. }
  6361. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6362. /// 019e
  6363. void clif_catch_process(struct map_session_data *sd)
  6364. {
  6365. int fd;
  6366. nullpo_retv(sd);
  6367. fd=sd->fd;
  6368. WFIFOHEAD(fd,packet_len(0x19e));
  6369. WFIFOW(fd,0)=0x19e;
  6370. WFIFOSET(fd,packet_len(0x19e));
  6371. }
  6372. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6373. /// 01a0 <result>.B
  6374. /// 0 = failure
  6375. /// 1 = success
  6376. void clif_pet_roulette(struct map_session_data *sd,int data)
  6377. {
  6378. int fd;
  6379. nullpo_retv(sd);
  6380. fd=sd->fd;
  6381. WFIFOHEAD(fd,packet_len(0x1a0));
  6382. WFIFOW(fd,0)=0x1a0;
  6383. WFIFOB(fd,2)=data;
  6384. WFIFOSET(fd,packet_len(0x1a0));
  6385. }
  6386. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6387. /// 01a6 <packet len>.W { <index>.W }*
  6388. void clif_sendegg(struct map_session_data *sd)
  6389. {
  6390. int i,n=0,fd;
  6391. nullpo_retv(sd);
  6392. fd=sd->fd;
  6393. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6394. clif_displaymessage(fd, msg_txt(sd,666));
  6395. return;
  6396. }
  6397. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6398. WFIFOW(fd,0)=0x1a6;
  6399. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6400. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6401. sd->inventory_data[i]->type!=IT_PETEGG ||
  6402. sd->status.inventory[i].amount<=0)
  6403. continue;
  6404. WFIFOW(fd,n*2+4)=i+2;
  6405. n++;
  6406. }
  6407. WFIFOW(fd,2)=4+n*2;
  6408. WFIFOSET(fd,WFIFOW(fd,2));
  6409. sd->menuskill_id = SA_TAMINGMONSTER;
  6410. sd->menuskill_val = -1;
  6411. }
  6412. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6413. /// 01a4 <type>.B <id>.L <data>.L
  6414. /// type:
  6415. /// 0 = pre-init (data = 0)
  6416. /// 1 = intimacy (data = 0~4)
  6417. /// 2 = hunger (data = 0~4)
  6418. /// 3 = accessory
  6419. /// 4 = performance (data = 1~3: normal, 4: special)
  6420. /// 5 = hairstyle
  6421. ///
  6422. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6423. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6424. {
  6425. uint8 buf[16];
  6426. nullpo_retv(pd);
  6427. WBUFW(buf,0) = 0x1a4;
  6428. WBUFB(buf,2) = type;
  6429. WBUFL(buf,3) = pd->bl.id;
  6430. WBUFL(buf,7) = param;
  6431. if (sd)
  6432. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6433. else
  6434. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6435. }
  6436. /// Pet's base data (ZC_PROPERTY_PET).
  6437. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6438. void clif_send_petstatus(struct map_session_data *sd)
  6439. {
  6440. int fd;
  6441. struct s_pet *pet;
  6442. nullpo_retv(sd);
  6443. nullpo_retv(sd->pd);
  6444. fd=sd->fd;
  6445. pet = &sd->pd->pet;
  6446. WFIFOHEAD(fd,packet_len(0x1a2));
  6447. WFIFOW(fd,0)=0x1a2;
  6448. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6449. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6450. WFIFOW(fd,27)=pet->level;
  6451. WFIFOW(fd,29)=pet->hungry;
  6452. WFIFOW(fd,31)=pet->intimate;
  6453. WFIFOW(fd,33)=pet->equip;
  6454. #if PACKETVER >= 20081126
  6455. WFIFOW(fd,35)=pet->class_;
  6456. #endif
  6457. WFIFOSET(fd,packet_len(0x1a2));
  6458. }
  6459. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6460. /// 01aa <id>.L <data>.L
  6461. /// data:
  6462. /// @see CZ_PET_ACT.
  6463. void clif_pet_emotion(struct pet_data *pd,int param)
  6464. {
  6465. unsigned char buf[16];
  6466. nullpo_retv(pd);
  6467. memset(buf,0,packet_len(0x1aa));
  6468. WBUFW(buf,0)=0x1aa;
  6469. WBUFL(buf,2)=pd->bl.id;
  6470. if(param >= 100 && pd->petDB->talk_convert_class) {
  6471. if(pd->petDB->talk_convert_class < 0)
  6472. return;
  6473. else if(pd->petDB->talk_convert_class > 0) {
  6474. // replace mob_id component of talk/act data
  6475. param -= (pd->pet.class_ - 100)*100;
  6476. param += (pd->petDB->talk_convert_class - 100)*100;
  6477. }
  6478. }
  6479. WBUFL(buf,6)=param;
  6480. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6481. }
  6482. /// Result of request to feed a pet (ZC_FEED_PET).
  6483. /// 01a3 <result>.B <name id>.W
  6484. /// result:
  6485. /// 0 = failure
  6486. /// 1 = success
  6487. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6488. {
  6489. int fd;
  6490. nullpo_retv(sd);
  6491. fd=sd->fd;
  6492. WFIFOHEAD(fd,packet_len(0x1a3));
  6493. WFIFOW(fd,0)=0x1a3;
  6494. WFIFOB(fd,2)=fail;
  6495. WFIFOW(fd,3)=foodid;
  6496. WFIFOSET(fd,packet_len(0x1a3));
  6497. }
  6498. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6499. /// 01cd { <skill id>.L }*7
  6500. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6501. {
  6502. int fd;
  6503. nullpo_retv(sd);
  6504. fd=sd->fd;
  6505. WFIFOHEAD(fd,packet_len(0x1cd));
  6506. WFIFOW(fd, 0)=0x1cd;
  6507. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6508. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6509. else
  6510. WFIFOL(fd,2)= 0x00000000;
  6511. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6512. WFIFOL(fd,6)= MG_COLDBOLT;
  6513. else
  6514. WFIFOL(fd,6)= 0x00000000;
  6515. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6516. WFIFOL(fd,10)= MG_FIREBOLT;
  6517. else
  6518. WFIFOL(fd,10)= 0x00000000;
  6519. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6520. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6521. else
  6522. WFIFOL(fd,14)= 0x00000000;
  6523. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6524. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6525. else
  6526. WFIFOL(fd,18)= 0x00000000;
  6527. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6528. WFIFOL(fd,22)= MG_FIREBALL;
  6529. else
  6530. WFIFOL(fd,22)= 0x00000000;
  6531. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6532. WFIFOL(fd,26)= MG_FROSTDIVER;
  6533. else
  6534. WFIFOL(fd,26)= 0x00000000;
  6535. WFIFOSET(fd,packet_len(0x1cd));
  6536. sd->menuskill_id = SA_AUTOSPELL;
  6537. sd->menuskill_val = skill_lv;
  6538. }
  6539. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6540. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6541. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6542. {
  6543. unsigned char buf[56];
  6544. nullpo_retv(src);
  6545. memset(buf,0,packet_len(0x1cf));
  6546. WBUFW(buf,0) = 0x1cf;
  6547. WBUFL(buf,2) = src->id;
  6548. if( src->type == BL_MER )
  6549. {
  6550. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6551. if( md && md->master && md->devotion_flag )
  6552. WBUFL(buf,6) = md->master->bl.id;
  6553. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6554. }
  6555. else
  6556. {
  6557. int i;
  6558. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6559. if( sd == NULL )
  6560. return;
  6561. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6562. WBUFL(buf,6+4*i) = sd->devotion[i];
  6563. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6564. }
  6565. if( tsd )
  6566. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6567. else
  6568. clif_send(buf, packet_len(0x1cf), src, AREA);
  6569. }
  6570. /*==========================================
  6571. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6572. * Notifies clients in an area of an object's spirits.
  6573. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6574. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6575. *------------------------------------------*/
  6576. void clif_spiritball(struct block_list *bl) {
  6577. unsigned char buf[16];
  6578. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6579. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6580. nullpo_retv(bl);
  6581. WBUFW(buf, 0) = 0x1d0;
  6582. WBUFL(buf, 2) = bl->id;
  6583. WBUFW(buf, 6) = 0; //init to 0
  6584. switch(bl->type){
  6585. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6586. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6587. }
  6588. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6589. }
  6590. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6591. /// 01d2 <account id>.L <delay>.L
  6592. void clif_combo_delay(struct block_list *bl,int wait)
  6593. {
  6594. unsigned char buf[32];
  6595. nullpo_retv(bl);
  6596. WBUFW(buf,0)=0x1d2;
  6597. WBUFL(buf,2)=bl->id;
  6598. WBUFL(buf,6)=wait;
  6599. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6600. }
  6601. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6602. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6603. /// flag:
  6604. /// 0 = inactive
  6605. /// 1 = active
  6606. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6607. {
  6608. unsigned char buf[32];
  6609. nullpo_retv(src);
  6610. WBUFW(buf,0)=0x1d1;
  6611. WBUFL(buf,2)=src->id;
  6612. WBUFL(buf,6)=dst_id;
  6613. WBUFL(buf,10)=active;
  6614. clif_send(buf,packet_len(0x1d1),src,AREA);
  6615. }
  6616. /// MVP effect (ZC_MVP).
  6617. /// 010c <account id>.L
  6618. void clif_mvp_effect(struct map_session_data *sd)
  6619. {
  6620. unsigned char buf[16];
  6621. nullpo_retv(sd);
  6622. WBUFW(buf,0)=0x10c;
  6623. WBUFL(buf,2)=sd->bl.id;
  6624. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6625. }
  6626. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6627. /// 010a <name id>.W
  6628. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6629. {
  6630. int view,fd;
  6631. nullpo_retv(sd);
  6632. fd=sd->fd;
  6633. WFIFOHEAD(fd,packet_len(0x10a));
  6634. WFIFOW(fd,0)=0x10a;
  6635. if((view = itemdb_viewid(nameid)) > 0)
  6636. WFIFOW(fd,2)=view;
  6637. else
  6638. WFIFOW(fd,2)=nameid;
  6639. WFIFOSET(fd,packet_len(0x10a));
  6640. }
  6641. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6642. /// 010b <exp>.L
  6643. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6644. {
  6645. int fd;
  6646. nullpo_retv(sd);
  6647. fd=sd->fd;
  6648. WFIFOHEAD(fd,packet_len(0x10b));
  6649. WFIFOW(fd,0)=0x10b;
  6650. WFIFOL(fd,2)=min(exp,(unsigned int)INT32_MAX);
  6651. WFIFOSET(fd,packet_len(0x10b));
  6652. }
  6653. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6654. /// 010d
  6655. ///
  6656. /// "You are the MVP, but cannot obtain the reward because
  6657. /// you are overweight."
  6658. void clif_mvp_noitem(struct map_session_data* sd)
  6659. {
  6660. int fd = sd->fd;
  6661. WFIFOHEAD(fd,packet_len(0x10d));
  6662. WFIFOW(fd,0) = 0x10d;
  6663. WFIFOSET(fd,packet_len(0x10d));
  6664. }
  6665. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6666. /// 0167 <result>.B
  6667. /// result:
  6668. /// 0 = "Guild has been created."
  6669. /// 1 = "You are already in a Guild."
  6670. /// 2 = "That Guild Name already exists."
  6671. /// 3 = "You need the neccessary item to create a Guild."
  6672. void clif_guild_created(struct map_session_data *sd,int flag)
  6673. {
  6674. int fd;
  6675. nullpo_retv(sd);
  6676. fd=sd->fd;
  6677. WFIFOHEAD(fd,packet_len(0x167));
  6678. WFIFOW(fd,0)=0x167;
  6679. WFIFOB(fd,2)=flag;
  6680. WFIFOSET(fd,packet_len(0x167));
  6681. }
  6682. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6683. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6684. /// mode:
  6685. /// &0x01 = allow invite
  6686. /// &0x10 = allow expel
  6687. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6688. {
  6689. int ps,fd;
  6690. nullpo_retv(sd);
  6691. nullpo_retv(g);
  6692. fd=sd->fd;
  6693. ps=guild_getposition(g,sd);
  6694. WFIFOHEAD(fd,packet_len(0x16c));
  6695. WFIFOW(fd,0)=0x16c;
  6696. WFIFOL(fd,2)=g->guild_id;
  6697. WFIFOL(fd,6)=g->emblem_id;
  6698. WFIFOL(fd,10)=g->position[ps].mode;
  6699. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6700. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6701. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6702. WFIFOSET(fd,packet_len(0x16c));
  6703. }
  6704. /// Guild member login notice.
  6705. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6706. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6707. /// status:
  6708. /// 0 = offline
  6709. /// 1 = online
  6710. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6711. {
  6712. unsigned char buf[64];
  6713. struct map_session_data* sd;
  6714. nullpo_retv(g);
  6715. WBUFW(buf, 0)=0x1f2;
  6716. WBUFL(buf, 2)=g->member[idx].account_id;
  6717. WBUFL(buf, 6)=g->member[idx].char_id;
  6718. WBUFL(buf,10)=flag;
  6719. if( ( sd = g->member[idx].sd ) != NULL )
  6720. {
  6721. WBUFW(buf,14) = sd->status.sex;
  6722. WBUFW(buf,16) = sd->status.hair;
  6723. WBUFW(buf,18) = sd->status.hair_color;
  6724. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6725. }
  6726. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6727. {
  6728. WBUFW(buf,14) = 0;
  6729. WBUFW(buf,16) = 0;
  6730. WBUFW(buf,18) = 0;
  6731. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6732. }
  6733. }
  6734. // Function `clif_guild_memberlogin_notice` sends info about
  6735. // logins and logouts of a guild member to the rest members.
  6736. // But at the 1st time (after a player login or map changing)
  6737. // the client won't show the message.
  6738. // So I suggest use this function for sending "first-time-info"
  6739. // to some player on entering the game or changing location.
  6740. // At next time the client would always show the message.
  6741. // The function sends all the statuses in the single packet
  6742. // to economize traffic. [LuzZza]
  6743. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6744. {
  6745. struct guild *g;
  6746. unsigned char buf[14*128];
  6747. int i, count=0, p_len;
  6748. nullpo_retv(sd);
  6749. p_len = packet_len(0x16d);
  6750. if(!(g = sd->guild))
  6751. return;
  6752. for(i=0; i<g->max_member; i++) {
  6753. if(g->member[i].account_id > 0 &&
  6754. g->member[i].account_id != sd->status.account_id) {
  6755. WBUFW(buf,count*p_len) = 0x16d;
  6756. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6757. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6758. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6759. count++;
  6760. }
  6761. }
  6762. clif_send(buf, p_len*count, &sd->bl, SELF);
  6763. }
  6764. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6765. /// 014e <menu flag>.L
  6766. /// menu flag:
  6767. /// 0x00 = Basic Info (always on)
  6768. /// &0x01 = Member manager
  6769. /// &0x02 = Positions
  6770. /// &0x04 = Skills
  6771. /// &0x10 = Expulsion list
  6772. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6773. /// &0x80 = Notice
  6774. void clif_guild_masterormember(struct map_session_data *sd)
  6775. {
  6776. int fd;
  6777. nullpo_retv(sd);
  6778. fd=sd->fd;
  6779. WFIFOHEAD(fd,packet_len(0x14e));
  6780. WFIFOW(fd,0) = 0x14e;
  6781. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6782. WFIFOSET(fd,packet_len(0x14e));
  6783. }
  6784. /// Guild basic information (Territories [Valaris])
  6785. /// 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)
  6786. /// 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)
  6787. void clif_guild_basicinfo(struct map_session_data *sd) {
  6788. int fd;
  6789. struct guild *g;
  6790. nullpo_retv(sd);
  6791. fd = sd->fd;
  6792. if( (g = sd->guild) == NULL )
  6793. return;
  6794. WFIFOHEAD(fd,packet_len(0x1b6));
  6795. WFIFOW(fd, 0)=0x1b6;//0x150;
  6796. WFIFOL(fd, 2)=g->guild_id;
  6797. WFIFOL(fd, 6)=g->guild_lv;
  6798. WFIFOL(fd,10)=g->connect_member;
  6799. WFIFOL(fd,14)=g->max_member;
  6800. WFIFOL(fd,18)=g->average_lv;
  6801. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6802. WFIFOL(fd,26)=g->next_exp;
  6803. WFIFOL(fd,30)=0; // Tax Points
  6804. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6805. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6806. WFIFOL(fd,42)=g->emblem_id;
  6807. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6808. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6809. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6810. WFIFOL(fd,110) = 0; // zeny
  6811. WFIFOSET(fd,packet_len(0x1b6));
  6812. }
  6813. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6814. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6815. void clif_guild_allianceinfo(struct map_session_data *sd)
  6816. {
  6817. int fd,i,c;
  6818. struct guild *g;
  6819. nullpo_retv(sd);
  6820. if( (g = sd->guild) == NULL )
  6821. return;
  6822. fd = sd->fd;
  6823. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6824. WFIFOW(fd, 0)=0x14c;
  6825. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6826. struct guild_alliance *a=&g->alliance[i];
  6827. if(a->guild_id>0){
  6828. WFIFOL(fd,c*32+4)=a->opposition;
  6829. WFIFOL(fd,c*32+8)=a->guild_id;
  6830. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6831. c++;
  6832. }
  6833. }
  6834. WFIFOW(fd, 2)=c*32+4;
  6835. WFIFOSET(fd,WFIFOW(fd,2));
  6836. }
  6837. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6838. /// 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 }*
  6839. /// state:
  6840. /// 0 = offline
  6841. /// 1 = online
  6842. /// memo:
  6843. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6844. void clif_guild_memberlist(struct map_session_data *sd)
  6845. {
  6846. int fd;
  6847. int i,c;
  6848. struct guild *g;
  6849. nullpo_retv(sd);
  6850. if( (fd = sd->fd) == 0 )
  6851. return;
  6852. if( (g = sd->guild) == NULL )
  6853. return;
  6854. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6855. WFIFOW(fd, 0)=0x154;
  6856. for(i=0,c=0;i<g->max_member;i++){
  6857. struct guild_member *m=&g->member[i];
  6858. if(m->account_id==0)
  6859. continue;
  6860. WFIFOL(fd,c*104+ 4)=m->account_id;
  6861. WFIFOL(fd,c*104+ 8)=m->char_id;
  6862. WFIFOW(fd,c*104+12)=m->hair;
  6863. WFIFOW(fd,c*104+14)=m->hair_color;
  6864. WFIFOW(fd,c*104+16)=m->gender;
  6865. WFIFOW(fd,c*104+18)=m->class_;
  6866. WFIFOW(fd,c*104+20)=m->lv;
  6867. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6868. WFIFOL(fd,c*104+26)=m->online;
  6869. WFIFOL(fd,c*104+30)=m->position;
  6870. 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.
  6871. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6872. c++;
  6873. }
  6874. WFIFOW(fd, 2)=c*104+4;
  6875. WFIFOSET(fd,WFIFOW(fd,2));
  6876. }
  6877. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6878. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6879. void clif_guild_positionnamelist(struct map_session_data *sd)
  6880. {
  6881. int i,fd;
  6882. struct guild *g;
  6883. nullpo_retv(sd);
  6884. if( (g = sd->guild) == NULL )
  6885. return;
  6886. fd = sd->fd;
  6887. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6888. WFIFOW(fd, 0)=0x166;
  6889. for(i=0;i<MAX_GUILDPOSITION;i++){
  6890. WFIFOL(fd,i*28+4)=i;
  6891. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6892. }
  6893. WFIFOW(fd,2)=i*28+4;
  6894. WFIFOSET(fd,WFIFOW(fd,2));
  6895. }
  6896. /// Guild position information (ZC_POSITION_INFO).
  6897. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6898. /// mode:
  6899. /// &0x01 = allow invite
  6900. /// &0x10 = allow expel
  6901. /// ranking:
  6902. /// TODO
  6903. void clif_guild_positioninfolist(struct map_session_data *sd)
  6904. {
  6905. int i,fd;
  6906. struct guild *g;
  6907. nullpo_retv(sd);
  6908. if( (g = sd->guild) == NULL )
  6909. return;
  6910. fd = sd->fd;
  6911. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6912. WFIFOW(fd, 0)=0x160;
  6913. for(i=0;i<MAX_GUILDPOSITION;i++){
  6914. struct guild_position *p=&g->position[i];
  6915. WFIFOL(fd,i*16+ 4)=i;
  6916. WFIFOL(fd,i*16+ 8)=p->mode;
  6917. WFIFOL(fd,i*16+12)=i;
  6918. WFIFOL(fd,i*16+16)=p->exp_mode;
  6919. }
  6920. WFIFOW(fd, 2)=i*16+4;
  6921. WFIFOSET(fd,WFIFOW(fd,2));
  6922. }
  6923. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6924. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6925. /// mode:
  6926. /// &0x01 = allow invite
  6927. /// &0x10 = allow expel
  6928. /// ranking:
  6929. /// TODO
  6930. void clif_guild_positionchanged(struct guild *g,int idx)
  6931. {
  6932. // FIXME: This packet is intended to update the clients after a
  6933. // commit of position info changes, not sending one packet per
  6934. // position.
  6935. struct map_session_data *sd;
  6936. unsigned char buf[128];
  6937. nullpo_retv(g);
  6938. WBUFW(buf, 0)=0x174;
  6939. WBUFW(buf, 2)=44; // packet len
  6940. // GUILD_REG_POSITION_INFO{
  6941. WBUFL(buf, 4)=idx;
  6942. WBUFL(buf, 8)=g->position[idx].mode;
  6943. WBUFL(buf,12)=idx;
  6944. WBUFL(buf,16)=g->position[idx].exp_mode;
  6945. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6946. // }*
  6947. if( (sd=guild_getavailablesd(g))!=NULL )
  6948. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6949. }
  6950. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6951. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6952. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6953. {
  6954. // FIXME: This packet is intended to update the clients after a
  6955. // commit of member position assignment changes, not sending one
  6956. // packet per position.
  6957. struct map_session_data *sd;
  6958. unsigned char buf[64];
  6959. nullpo_retv(g);
  6960. WBUFW(buf, 0)=0x156;
  6961. WBUFW(buf, 2)=16; // packet len
  6962. // MEMBER_POSITION_INFO{
  6963. WBUFL(buf, 4)=g->member[idx].account_id;
  6964. WBUFL(buf, 8)=g->member[idx].char_id;
  6965. WBUFL(buf,12)=g->member[idx].position;
  6966. // }*
  6967. if( (sd=guild_getavailablesd(g))!=NULL )
  6968. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6969. }
  6970. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6971. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6972. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6973. {
  6974. int fd;
  6975. nullpo_retv(sd);
  6976. nullpo_retv(g);
  6977. fd = sd->fd;
  6978. if( g->emblem_len <= 0 )
  6979. return;
  6980. WFIFOHEAD(fd,g->emblem_len+12);
  6981. WFIFOW(fd,0)=0x152;
  6982. WFIFOW(fd,2)=g->emblem_len+12;
  6983. WFIFOL(fd,4)=g->guild_id;
  6984. WFIFOL(fd,8)=g->emblem_id;
  6985. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6986. WFIFOSET(fd,WFIFOW(fd,2));
  6987. }
  6988. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6989. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6990. void clif_guild_emblem_area(struct block_list* bl)
  6991. {
  6992. uint8 buf[12];
  6993. nullpo_retv(bl);
  6994. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6995. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6996. WBUFW(buf,0) = 0x1b4;
  6997. WBUFL(buf,2) = bl->id;
  6998. WBUFL(buf,6) = status_get_guild_id(bl);
  6999. WBUFW(buf,10) = status_get_emblem_id(bl);
  7000. clif_send(buf, 12, bl, AREA_WOS);
  7001. }
  7002. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7003. /// 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 }*
  7004. void clif_guild_skillinfo(struct map_session_data* sd)
  7005. {
  7006. int fd;
  7007. struct guild* g;
  7008. int i,c;
  7009. nullpo_retv(sd);
  7010. if( (g = sd->guild) == NULL )
  7011. return;
  7012. fd = sd->fd;
  7013. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7014. WFIFOW(fd,0) = 0x0162;
  7015. WFIFOW(fd,4) = g->skill_point;
  7016. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7017. {
  7018. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7019. {
  7020. int id = g->skill[i].id;
  7021. int p = 6 + c*37;
  7022. WFIFOW(fd,p+0) = id;
  7023. WFIFOL(fd,p+2) = skill_get_inf(id);
  7024. WFIFOW(fd,p+6) = g->skill[i].lv;
  7025. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7026. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7027. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7028. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7029. c++;
  7030. }
  7031. }
  7032. WFIFOW(fd,2) = 6 + c*37;
  7033. WFIFOSET(fd,WFIFOW(fd,2));
  7034. }
  7035. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7036. /// 016f <subject>.60B <notice>.120B
  7037. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  7038. {
  7039. int fd;
  7040. nullpo_retv(sd);
  7041. nullpo_retv(g);
  7042. fd = sd->fd;
  7043. if ( !session_isActive(fd) )
  7044. return;
  7045. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7046. return;
  7047. WFIFOHEAD(fd,packet_len(0x16f));
  7048. WFIFOW(fd,0) = 0x16f;
  7049. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7050. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7051. WFIFOSET(fd,packet_len(0x16f));
  7052. }
  7053. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7054. /// 016a <guild id>.L <guild name>.24B
  7055. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7056. {
  7057. int fd;
  7058. nullpo_retv(sd);
  7059. nullpo_retv(g);
  7060. fd=sd->fd;
  7061. WFIFOHEAD(fd,packet_len(0x16a));
  7062. WFIFOW(fd,0)=0x16a;
  7063. WFIFOL(fd,2)=g->guild_id;
  7064. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  7065. WFIFOSET(fd,packet_len(0x16a));
  7066. }
  7067. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7068. /// 0169 <answer>.B
  7069. /// answer:
  7070. /// 0 = Already in guild.
  7071. /// 1 = Offer rejected.
  7072. /// 2 = Offer accepted.
  7073. /// 3 = Guild full.
  7074. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7075. {
  7076. int fd;
  7077. nullpo_retv(sd);
  7078. fd=sd->fd;
  7079. WFIFOHEAD(fd,packet_len(0x169));
  7080. WFIFOW(fd,0)=0x169;
  7081. WFIFOB(fd,2)=flag;
  7082. WFIFOSET(fd,packet_len(0x169));
  7083. }
  7084. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7085. /// 015a <char name>.24B <reason>.40B
  7086. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7087. {
  7088. unsigned char buf[128];
  7089. nullpo_retv(sd);
  7090. WBUFW(buf, 0)=0x15a;
  7091. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  7092. memcpy(WBUFP(buf,26),mes,40);
  7093. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7094. }
  7095. /// Notifies clients of a guild of an expelled member.
  7096. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7097. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7098. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7099. {
  7100. unsigned char buf[128];
  7101. #if PACKETVER < 20100803
  7102. const unsigned short cmd = 0x15c;
  7103. #else
  7104. const unsigned short cmd = 0x839;
  7105. #endif
  7106. nullpo_retv(sd);
  7107. WBUFW(buf,0) = cmd;
  7108. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7109. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7110. #if PACKETVER < 20100803
  7111. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7112. #endif
  7113. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7114. }
  7115. /// Guild expulsion list (ZC_BAN_LIST).
  7116. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7117. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7118. void clif_guild_expulsionlist(struct map_session_data* sd)
  7119. {
  7120. #if PACKETVER < 20100803
  7121. const int offset = NAME_LENGTH*2+40;
  7122. #else
  7123. const int offset = NAME_LENGTH+40;
  7124. #endif
  7125. int fd, i, c = 0;
  7126. struct guild* g;
  7127. nullpo_retv(sd);
  7128. if( (g = sd->guild) == NULL )
  7129. return;
  7130. fd = sd->fd;
  7131. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7132. WFIFOW(fd,0) = 0x163;
  7133. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7134. {
  7135. struct guild_expulsion* e = &g->expulsion[i];
  7136. if( e->account_id > 0 )
  7137. {
  7138. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7139. #if PACKETVER < 20100803
  7140. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7141. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7142. #else
  7143. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7144. #endif
  7145. c++;
  7146. }
  7147. }
  7148. WFIFOW(fd,2) = 4 + c*offset;
  7149. WFIFOSET(fd,WFIFOW(fd,2));
  7150. }
  7151. /// Guild chat message (ZC_GUILD_CHAT).
  7152. /// 017f <packet len>.W <message>.?B
  7153. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7154. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7155. struct map_session_data *sd;
  7156. uint8 buf[256];
  7157. if( len == 0 )
  7158. {
  7159. return;
  7160. }
  7161. else if( len > sizeof(buf)-5 )
  7162. {
  7163. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7164. len = sizeof(buf)-5;
  7165. }
  7166. WBUFW(buf, 0) = 0x17f;
  7167. WBUFW(buf, 2) = len + 5;
  7168. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7169. if ((sd = guild_getavailablesd(g)) != NULL)
  7170. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7171. }
  7172. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7173. /// 0171 <inviter account id>.L <guild name>.24B
  7174. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7175. {
  7176. int fd;
  7177. nullpo_retv(sd);
  7178. fd=sd->fd;
  7179. WFIFOHEAD(fd,packet_len(0x171));
  7180. WFIFOW(fd,0)=0x171;
  7181. WFIFOL(fd,2)=account_id;
  7182. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7183. WFIFOSET(fd,packet_len(0x171));
  7184. }
  7185. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7186. /// 0173 <answer>.B
  7187. /// answer:
  7188. /// 0 = Already allied.
  7189. /// 1 = You rejected the offer.
  7190. /// 2 = You accepted the offer.
  7191. /// 3 = They have too any alliances.
  7192. /// 4 = You have too many alliances.
  7193. /// 5 = Alliances are disabled.
  7194. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7195. {
  7196. int fd;
  7197. nullpo_retv(sd);
  7198. fd=sd->fd;
  7199. WFIFOHEAD(fd,packet_len(0x173));
  7200. WFIFOW(fd,0)=0x173;
  7201. WFIFOL(fd,2)=flag;
  7202. WFIFOSET(fd,packet_len(0x173));
  7203. }
  7204. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7205. /// 0184 <other guild id>.L <relation>.L
  7206. /// relation:
  7207. /// 0 = Ally
  7208. /// 1 = Enemy
  7209. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7210. {
  7211. int fd;
  7212. nullpo_retv(sd);
  7213. fd = sd->fd;
  7214. if (fd <= 0)
  7215. return;
  7216. WFIFOHEAD(fd,packet_len(0x184));
  7217. WFIFOW(fd,0)=0x184;
  7218. WFIFOL(fd,2)=guild_id;
  7219. WFIFOL(fd,6)=flag;
  7220. WFIFOSET(fd,packet_len(0x184));
  7221. }
  7222. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7223. /// 0181 <result>.B
  7224. /// result:
  7225. /// 0 = Antagonist has been set.
  7226. /// 1 = Guild has too many Antagonists.
  7227. /// 2 = Already set as an Antagonist.
  7228. /// 3 = Antagonists are disabled.
  7229. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7230. {
  7231. int fd;
  7232. nullpo_retv(sd);
  7233. fd=sd->fd;
  7234. WFIFOHEAD(fd,packet_len(0x181));
  7235. WFIFOW(fd,0)=0x181;
  7236. WFIFOB(fd,2)=flag;
  7237. WFIFOSET(fd,packet_len(0x181));
  7238. }
  7239. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7240. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7241. /*
  7242. void clif_guild_allianceadded(struct guild *g,int idx)
  7243. {
  7244. unsigned char buf[64];
  7245. WBUFW(buf,0)=0x185;
  7246. WBUFL(buf,2)=g->alliance[idx].opposition;
  7247. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7248. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7249. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7250. }
  7251. */
  7252. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7253. /// 015e <reason>.L
  7254. /// 0 = success
  7255. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7256. /// 2 = there are still members in the guild
  7257. void clif_guild_broken(struct map_session_data *sd,int flag)
  7258. {
  7259. int fd;
  7260. nullpo_retv(sd);
  7261. fd=sd->fd;
  7262. WFIFOHEAD(fd,packet_len(0x15e));
  7263. WFIFOW(fd,0)=0x15e;
  7264. WFIFOL(fd,2)=flag;
  7265. WFIFOSET(fd,packet_len(0x15e));
  7266. }
  7267. /// Displays emotion on an object (ZC_EMOTION).
  7268. /// 00c0 <id>.L <type>.B
  7269. /// type:
  7270. /// enum emotion_type
  7271. void clif_emotion(struct block_list *bl,int type)
  7272. {
  7273. unsigned char buf[8];
  7274. nullpo_retv(bl);
  7275. WBUFW(buf,0)=0xc0;
  7276. WBUFL(buf,2)=bl->id;
  7277. WBUFB(buf,6)=type;
  7278. clif_send(buf,packet_len(0xc0),bl,AREA);
  7279. }
  7280. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7281. /// 0191 <id>.L <contents>.80B
  7282. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7283. {
  7284. unsigned char buf[MESSAGE_SIZE+6];
  7285. nullpo_retv(bl);
  7286. WBUFW(buf,0) = 0x191;
  7287. WBUFL(buf,2) = bl->id;
  7288. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7289. clif_send(buf,packet_len(0x191),bl,AREA);
  7290. }
  7291. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7292. /// 01ea <id>.L
  7293. void clif_wedding_effect(struct block_list *bl)
  7294. {
  7295. unsigned char buf[6];
  7296. nullpo_retv(bl);
  7297. WBUFW(buf,0) = 0x1ea;
  7298. WBUFL(buf,2) = bl->id;
  7299. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7300. }
  7301. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7302. /// 01e6 <partner name>.24B
  7303. void clif_callpartner(struct map_session_data *sd)
  7304. {
  7305. unsigned char buf[26];
  7306. nullpo_retv(sd);
  7307. WBUFW(buf,0) = 0x1e6;
  7308. if( sd->status.partner_id ) {
  7309. const char *p = map_charid2nick(sd->status.partner_id);
  7310. struct map_session_data *p_sd = pc_get_partner(sd);
  7311. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7312. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7313. else
  7314. WBUFB(buf,2) = 0;
  7315. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7316. WBUFB(buf,2) = 0;
  7317. }
  7318. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7319. }
  7320. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7321. /// 01e4
  7322. /// This packet while still implemented by the client is no longer being officially used.
  7323. /*
  7324. void clif_marriage_process(struct map_session_data *sd)
  7325. {
  7326. int fd;
  7327. nullpo_retv(sd);
  7328. fd=sd->fd;
  7329. WFIFOHEAD(fd,packet_len(0x1e4));
  7330. WFIFOW(fd,0)=0x1e4;
  7331. WFIFOSET(fd,packet_len(0x1e4));
  7332. }
  7333. */
  7334. /// Notice of divorce (ZC_DIVORCE).
  7335. /// 0205 <partner name>.24B
  7336. void clif_divorced(struct map_session_data* sd, const char* name)
  7337. {
  7338. int fd;
  7339. nullpo_retv(sd);
  7340. fd=sd->fd;
  7341. WFIFOHEAD(fd,packet_len(0x205));
  7342. WFIFOW(fd,0)=0x205;
  7343. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7344. WFIFOSET(fd, packet_len(0x205));
  7345. }
  7346. /// Marriage proposal (ZC_REQ_COUPLE).
  7347. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7348. /// This packet while still implemented by the client is no longer being officially used.
  7349. /*
  7350. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7351. {
  7352. nullpo_retv(sd);
  7353. WFIFOHEAD(fd,packet_len(0x1e2));
  7354. WFIFOW(fd,0) = 0x1e2;
  7355. WFIFOL(fd,2) = ssd->status.account_id;
  7356. WFIFOL(fd,6) = ssd->status.char_id;
  7357. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7358. WFIFOSET(fd, packet_len(0x1e2));
  7359. }
  7360. */
  7361. /*==========================================
  7362. *
  7363. *------------------------------------------*/
  7364. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7365. {
  7366. clif_disp_message(&sd->bl, mes, len, SELF);
  7367. }
  7368. /*==========================================
  7369. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7370. *------------------------------------------*/
  7371. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7372. {
  7373. unsigned char buf[256];
  7374. if( len == 0 ) {
  7375. return;
  7376. } else if( len > sizeof(buf)-5 ) {
  7377. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7378. len = sizeof(buf)-5;
  7379. }
  7380. WBUFW(buf, 0) = 0x17f;
  7381. WBUFW(buf, 2) = len + 5;
  7382. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7383. clif_send(buf, WBUFW(buf,2), src, target);
  7384. }
  7385. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7386. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7387. /// 00cd <result>.B
  7388. /// result:
  7389. /// 0 = failure
  7390. /// 1 = success
  7391. void clif_GM_kickack(struct map_session_data *sd, int id)
  7392. {
  7393. int fd;
  7394. nullpo_retv(sd);
  7395. fd = sd->fd;
  7396. WFIFOHEAD(fd,packet_len(0xcd));
  7397. WFIFOW(fd,0) = 0xcd;
  7398. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7399. WFIFOSET(fd, packet_len(0xcd));
  7400. }
  7401. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7402. {
  7403. int fd = tsd->fd;
  7404. if( fd > 0 )
  7405. clif_authfail_fd(fd, 15);
  7406. else {
  7407. // Close vending/buyingstore
  7408. if (sd) {
  7409. if (tsd->state.vending)
  7410. vending_closevending(tsd);
  7411. else if (tsd->state.buyingstore)
  7412. buyingstore_close(tsd);
  7413. }
  7414. map_quit(tsd);
  7415. }
  7416. if( sd )
  7417. clif_GM_kickack(sd,tsd->status.account_id);
  7418. }
  7419. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7420. /// 014a <result>.L
  7421. /// result:
  7422. /// 0 = "A manner point has been successfully aligned."
  7423. /// 1 = MP_FAILURE_EXHAUST
  7424. /// 2 = MP_FAILURE_ALREADY_GIVING
  7425. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7426. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7427. /// 5 = "You got a good point from %s."
  7428. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7429. {
  7430. int fd;
  7431. nullpo_retv(sd);
  7432. fd = sd->fd;
  7433. WFIFOHEAD(fd,packet_len(0x14a));
  7434. WFIFOW(fd,0) = 0x14a;
  7435. WFIFOL(fd,2) = type;
  7436. WFIFOSET(fd, packet_len(0x14a));
  7437. }
  7438. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7439. /// 014b <type>.B <GM name>.24B
  7440. /// type:
  7441. /// 0 = positive (unmute)
  7442. /// 1 = negative (mute)
  7443. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7444. {
  7445. int fd;
  7446. nullpo_retv(sd);
  7447. nullpo_retv(tsd);
  7448. fd = tsd->fd;
  7449. WFIFOHEAD(fd,packet_len(0x14b));
  7450. WFIFOW(fd,0) = 0x14b;
  7451. WFIFOB(fd,2) = type;
  7452. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7453. WFIFOSET(fd, packet_len(0x14b));
  7454. }
  7455. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7456. /// 00d1 <type>.B <result>.B
  7457. /// type:
  7458. /// 0 = /ex (deny)
  7459. /// 1 = /in (allow)
  7460. /// result:
  7461. /// 0 = success
  7462. /// 1 = failure
  7463. /// 2 = too many blocks
  7464. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7465. {
  7466. int fd;
  7467. nullpo_retv(sd);
  7468. fd=sd->fd;
  7469. WFIFOHEAD(fd,packet_len(0xd1));
  7470. WFIFOW(fd,0)=0xd1;
  7471. WFIFOB(fd,2)=type;
  7472. WFIFOB(fd,3)=flag;
  7473. WFIFOSET(fd,packet_len(0xd1));
  7474. }
  7475. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7476. /// 00d2 <type>.B <result>.B
  7477. /// type:
  7478. /// 0 = /exall (deny)
  7479. /// 1 = /inall (allow)
  7480. /// result:
  7481. /// 0 = success
  7482. /// 1 = failure
  7483. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7484. {
  7485. int fd;
  7486. nullpo_retv(sd);
  7487. fd=sd->fd;
  7488. WFIFOHEAD(fd,packet_len(0xd2));
  7489. WFIFOW(fd,0)=0xd2;
  7490. WFIFOB(fd,2)=type;
  7491. WFIFOB(fd,3)=flag;
  7492. WFIFOSET(fd,packet_len(0xd2));
  7493. }
  7494. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7495. /// 07fe <bgm>.24B
  7496. void clif_playBGM(struct map_session_data* sd, const char* name)
  7497. {
  7498. int fd;
  7499. nullpo_retv(sd);
  7500. fd = sd->fd;
  7501. WFIFOHEAD(fd,packet_len(0x7fe));
  7502. WFIFOW(fd,0) = 0x7fe;
  7503. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7504. WFIFOSET(fd,packet_len(0x7fe));
  7505. }
  7506. /// Plays/stops a wave sound (ZC_SOUND).
  7507. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7508. /// file name:
  7509. /// relative to data\wav
  7510. /// act:
  7511. /// 0 = play (once)
  7512. /// 1 = play (repeat, does not work)
  7513. /// 2 = stops all sound instances of file name (does not work)
  7514. /// term:
  7515. /// unknown purpose, only relevant to act = 1
  7516. /// npc id:
  7517. /// The accustic direction of the sound is determined by the
  7518. /// relative position of the NPC to the player (3D sound).
  7519. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7520. {
  7521. int fd;
  7522. nullpo_retv(sd);
  7523. nullpo_retv(bl);
  7524. fd = sd->fd;
  7525. WFIFOHEAD(fd,packet_len(0x1d3));
  7526. WFIFOW(fd,0) = 0x1d3;
  7527. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7528. WFIFOB(fd,26) = type;
  7529. WFIFOL(fd,27) = 0;
  7530. WFIFOL(fd,31) = bl->id;
  7531. WFIFOSET(fd,packet_len(0x1d3));
  7532. }
  7533. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7534. {
  7535. unsigned char buf[40];
  7536. nullpo_retv(bl);
  7537. WBUFW(buf,0) = 0x1d3;
  7538. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7539. WBUFB(buf,26) = type;
  7540. WBUFL(buf,27) = 0;
  7541. WBUFL(buf,31) = bl->id;
  7542. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7543. }
  7544. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7545. /// 01f3 <id>.L <effect id>.L
  7546. /// effect id:
  7547. /// @see doc/effect_list.txt
  7548. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7549. {
  7550. unsigned char buf[24];
  7551. nullpo_retv(bl);
  7552. memset(buf, 0, packet_len(0x1f3));
  7553. WBUFW(buf,0) = 0x1f3;
  7554. WBUFL(buf,2) = bl->id;
  7555. WBUFL(buf,6) = type;
  7556. clif_send(buf, packet_len(0x1f3), bl, target);
  7557. if (disguised(bl)) {
  7558. WBUFL(buf,2) = -bl->id;
  7559. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7560. }
  7561. }
  7562. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7563. {
  7564. WFIFOHEAD(fd,10);
  7565. WFIFOW(fd,0) = 0x1f3;
  7566. WFIFOL(fd,2) = bl->id;
  7567. WFIFOL(fd,6) = type;
  7568. WFIFOSET(fd,10);
  7569. }
  7570. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7571. /// 0284 <id>.L <effect id>.L <num data>.L
  7572. /// effect id:
  7573. /// @see doc/effect_list.txt
  7574. /// num data:
  7575. /// effect-dependent value
  7576. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7577. {
  7578. uint8 buf[14];
  7579. WBUFW(buf,0) = 0x284;
  7580. WBUFL(buf,2) = bl->id;
  7581. WBUFL(buf,6) = effect_id;
  7582. WBUFL(buf,10) = num;
  7583. clif_send(buf, packet_len(0x284), bl, target);
  7584. if( disguised(bl) )
  7585. {
  7586. WBUFL(buf,2) = -bl->id;
  7587. clif_send(buf, packet_len(0x284), bl, SELF);
  7588. }
  7589. }
  7590. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7591. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7592. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7593. unsigned short msg_len = strlen(msg) + 1;
  7594. WFIFOHEAD(fd,msg_len + 12);
  7595. WFIFOW(fd,0) = 0x2C1;
  7596. WFIFOW(fd,2) = msg_len + 12;
  7597. WFIFOL(fd,4) = 0;
  7598. WFIFOL(fd,8) = color; //either color_table or channel_table
  7599. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7600. WFIFOSET(fd, msg_len + 12);
  7601. return 0;
  7602. }
  7603. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7604. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7605. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7606. unsigned short msg_len = strlen(msg) + 1;
  7607. uint8 buf[256];
  7608. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7609. nullpo_retv(bl);
  7610. if( msg_len > sizeof(buf)-12 ) {
  7611. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7612. msg_len = sizeof(buf)-12;
  7613. }
  7614. WBUFW(buf,0) = 0x2C1;
  7615. WBUFW(buf,2) = msg_len + 12;
  7616. WBUFL(buf,4) = bl->id;
  7617. WBUFL(buf,8) = color;
  7618. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7619. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7620. }
  7621. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7622. {
  7623. int fd;
  7624. unsigned short msg_len = strlen(msg) + 1;
  7625. nullpo_retv(sd);
  7626. if(msg_len > 0) {
  7627. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7628. fd = sd->fd;
  7629. WFIFOHEAD(fd, msg_len+12);
  7630. WFIFOW(fd,0) = 0x2C1;
  7631. WFIFOW(fd,2) = msg_len+12;
  7632. WFIFOL(fd,4) = 0;
  7633. WFIFOL(fd,8) = color;
  7634. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7635. WFIFOSET(fd, WFIFOW(fd,2));
  7636. }
  7637. }
  7638. /**
  7639. * Notifies the client that the storage window is still open
  7640. *
  7641. * Should only be used in cases where the client closed the
  7642. * storage window without server's consent
  7643. */
  7644. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7645. // Notify the client that the storage is open
  7646. if( sd->state.storage_flag == 1 ) {
  7647. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7648. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7649. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7650. }
  7651. // Notify the client that the gstorage is open otherwise it will
  7652. // remain locked forever and nobody will be able to access it
  7653. if( sd->state.storage_flag == 2 ) {
  7654. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7655. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7656. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7657. else {
  7658. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7659. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7660. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7661. }
  7662. }
  7663. }
  7664. // refresh the client's screen, getting rid of any effects
  7665. void clif_refresh(struct map_session_data *sd)
  7666. {
  7667. nullpo_retv(sd);
  7668. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7669. clif_inventorylist(sd);
  7670. if(pc_iscarton(sd)) {
  7671. clif_cartlist(sd);
  7672. clif_updatestatus(sd,SP_CARTINFO);
  7673. }
  7674. clif_updatestatus(sd,SP_WEIGHT);
  7675. clif_updatestatus(sd,SP_MAXWEIGHT);
  7676. clif_updatestatus(sd,SP_STR);
  7677. clif_updatestatus(sd,SP_AGI);
  7678. clif_updatestatus(sd,SP_VIT);
  7679. clif_updatestatus(sd,SP_INT);
  7680. clif_updatestatus(sd,SP_DEX);
  7681. clif_updatestatus(sd,SP_LUK);
  7682. if (sd->spiritball)
  7683. clif_spiritball_single(sd->fd, sd);
  7684. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7685. clif_spiritcharm_single(sd->fd, sd);
  7686. if (sd->vd.cloth_color)
  7687. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7688. if(hom_is_active(sd->hd))
  7689. clif_send_homdata(sd,SP_ACK,0);
  7690. if( sd->md ) {
  7691. clif_mercenary_info(sd);
  7692. clif_mercenary_skillblock(sd);
  7693. }
  7694. if( sd->ed )
  7695. clif_elemental_info(sd);
  7696. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7697. clif_weather_check(sd);
  7698. if( sd->chatID )
  7699. chat_leavechat(sd,0);
  7700. if( sd->state.vending )
  7701. clif_openvending(sd, sd->bl.id, sd->vending);
  7702. if( pc_issit(sd) )
  7703. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7704. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7705. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7706. else
  7707. clif_changed_dir(&sd->bl, SELF);
  7708. // unlike vending, resuming buyingstore crashes the client.
  7709. buyingstore_close(sd);
  7710. mail_clear(sd);
  7711. if( disguised(&sd->bl) ) {/* refresh-da */
  7712. short disguise = sd->disguise;
  7713. pc_disguise(sd, 0);
  7714. pc_disguise(sd, disguise);
  7715. }
  7716. clif_refresh_storagewindow(sd);
  7717. }
  7718. /// Updates the object's (bl) name on client.
  7719. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7720. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7721. void clif_charnameack (int fd, struct block_list *bl)
  7722. {
  7723. unsigned char buf[103];
  7724. int cmd = 0x95;
  7725. nullpo_retv(bl);
  7726. WBUFW(buf,0) = cmd;
  7727. WBUFL(buf,2) = bl->id;
  7728. switch( bl->type )
  7729. {
  7730. case BL_PC:
  7731. {
  7732. struct map_session_data *ssd = (struct map_session_data *)bl;
  7733. struct party_data *p = NULL;
  7734. struct guild *g = NULL;
  7735. int ps = -1;
  7736. //Requesting your own "shadow" name. [Skotlex]
  7737. if (ssd->fd == fd && ssd->disguise)
  7738. WBUFL(buf,2) = -bl->id;
  7739. if( ssd->fakename[0] ) {
  7740. WBUFW(buf, 0) = cmd = 0x195;
  7741. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7742. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7743. break;
  7744. }
  7745. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7746. if( ssd->status.party_id ) {
  7747. p = party_search(ssd->status.party_id);
  7748. }
  7749. if( ssd->status.guild_id ) {
  7750. if( ( g = ssd->guild ) != NULL ) {
  7751. int i;
  7752. 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);
  7753. if( i < g->max_member ) ps = g->member[i].position;
  7754. }
  7755. }
  7756. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7757. p = NULL;
  7758. }
  7759. if (p == NULL && g == NULL)
  7760. break;
  7761. WBUFW(buf, 0) = cmd = 0x195;
  7762. if (p)
  7763. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7764. else
  7765. WBUFB(buf,30) = 0;
  7766. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7767. {
  7768. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7769. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7770. } else { //Assume no guild.
  7771. WBUFB(buf,54) = 0;
  7772. WBUFB(buf,78) = 0;
  7773. }
  7774. }
  7775. break;
  7776. //[blackhole89]
  7777. case BL_HOM:
  7778. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7779. break;
  7780. case BL_MER:
  7781. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7782. break;
  7783. case BL_PET:
  7784. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7785. break;
  7786. case BL_NPC:
  7787. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7788. break;
  7789. case BL_MOB:
  7790. {
  7791. struct mob_data *md = (struct mob_data *)bl;
  7792. nullpo_retv(md);
  7793. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7794. if( md->guardian_data && md->guardian_data->guild_id )
  7795. {
  7796. WBUFW(buf, 0) = cmd = 0x195;
  7797. WBUFB(buf,30) = 0;
  7798. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7799. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7800. }
  7801. else if( battle_config.show_mob_info )
  7802. {
  7803. char mobhp[50], *str_p = mobhp;
  7804. WBUFW(buf, 0) = cmd = 0x195;
  7805. if( battle_config.show_mob_info&4 )
  7806. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7807. if( battle_config.show_mob_info&1 )
  7808. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7809. if( battle_config.show_mob_info&2 )
  7810. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7811. //Even thought mobhp ain't a name, we send it as one so the client
  7812. //can parse it. [Skotlex]
  7813. if( str_p != mobhp )
  7814. {
  7815. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7816. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7817. WBUFB(buf,54) = 0;
  7818. WBUFB(buf,78) = 0;
  7819. }
  7820. }
  7821. }
  7822. break;
  7823. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7824. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7825. // break;
  7826. return;
  7827. case BL_ELEM:
  7828. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7829. break;
  7830. default:
  7831. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7832. return;
  7833. }
  7834. // if no receipient specified just update nearby clients
  7835. if (fd == 0)
  7836. clif_send(buf, packet_len(cmd), bl, AREA);
  7837. else {
  7838. WFIFOHEAD(fd, packet_len(cmd));
  7839. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7840. WFIFOSET(fd, packet_len(cmd));
  7841. }
  7842. }
  7843. //Used to update when a char leaves a party/guild. [Skotlex]
  7844. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7845. void clif_charnameupdate (struct map_session_data *ssd)
  7846. {
  7847. unsigned char buf[103];
  7848. int cmd = 0x195, ps = -1;
  7849. struct party_data *p = NULL;
  7850. struct guild *g = NULL;
  7851. nullpo_retv(ssd);
  7852. if( ssd->fakename[0] )
  7853. return; //No need to update as the party/guild was not displayed anyway.
  7854. WBUFW(buf,0) = cmd;
  7855. WBUFL(buf,2) = ssd->bl.id;
  7856. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7857. if (!battle_config.display_party_name) {
  7858. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7859. p = party_search(ssd->status.party_id);
  7860. }else{
  7861. if (ssd->status.party_id > 0)
  7862. p = party_search(ssd->status.party_id);
  7863. }
  7864. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7865. {
  7866. int i;
  7867. 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);
  7868. if( i < g->max_member ) ps = g->member[i].position;
  7869. }
  7870. if( p )
  7871. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7872. else
  7873. WBUFB(buf,30) = 0;
  7874. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7875. {
  7876. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7877. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7878. }
  7879. else
  7880. {
  7881. WBUFB(buf,54) = 0;
  7882. WBUFB(buf,78) = 0;
  7883. }
  7884. // Update nearby clients
  7885. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7886. }
  7887. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7888. /// 01ff <id>.L <x>.W <y>.W
  7889. ///
  7890. /// Visually moves(instant) a character to x,y. The char moves even
  7891. /// when the target cell isn't walkable. If the char is sitting it
  7892. /// stays that way.
  7893. void clif_slide(struct block_list *bl, int x, int y)
  7894. {
  7895. unsigned char buf[10];
  7896. nullpo_retv(bl);
  7897. WBUFW(buf, 0) = 0x01ff;
  7898. WBUFL(buf, 2) = bl->id;
  7899. WBUFW(buf, 6) = x;
  7900. WBUFW(buf, 8) = y;
  7901. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7902. if( disguised(bl) )
  7903. {
  7904. WBUFL(buf,2) = -bl->id;
  7905. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7906. }
  7907. }
  7908. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7909. /// 008d <packet len>.W <id>.L <message>.?B
  7910. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7911. {
  7912. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7913. int len_mes = strlen(mes)+1; //Account for \0
  7914. if (len_mes > sizeof(buf)-8) {
  7915. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7916. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7917. }
  7918. // send message to others
  7919. WBUFW(buf,0) = 0x8d;
  7920. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7921. WBUFL(buf,4) = bl->id;
  7922. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7923. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7924. // send back message to the speaker
  7925. if( bl->type == BL_PC ) {
  7926. WBUFW(buf,0) = 0x8e;
  7927. WBUFW(buf, 2) = len_mes + 4;
  7928. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7929. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7930. }
  7931. }
  7932. /*==========================
  7933. * Minimap fix [Kevin]
  7934. * Remove dot from minimap
  7935. *--------------------------*/
  7936. void clif_party_xy_remove(struct map_session_data *sd)
  7937. {
  7938. unsigned char buf[16];
  7939. nullpo_retv(sd);
  7940. WBUFW(buf,0)=0x107;
  7941. WBUFL(buf,2)=sd->status.account_id;
  7942. WBUFW(buf,6)=-1;
  7943. WBUFW(buf,8)=-1;
  7944. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7945. }
  7946. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7947. /// 0215 <msg id>.L
  7948. /// msg id:
  7949. /// 0x15 = End all negative status (PA_GOSPEL)
  7950. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7951. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7952. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7953. /// 0x19 = All stats +20 (PA_GOSPEL)
  7954. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7955. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7956. /// 0x1e = DEF +25% (PA_GOSPEL)
  7957. /// 0x1f = ATK +100% (PA_GOSPEL)
  7958. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7959. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7960. /// ? = nothing
  7961. void clif_gospel_info(struct map_session_data *sd, int type)
  7962. {
  7963. int fd=sd->fd;
  7964. WFIFOHEAD(fd,packet_len(0x215));
  7965. WFIFOW(fd,0)=0x215;
  7966. WFIFOL(fd,2)=type;
  7967. WFIFOSET(fd, packet_len(0x215));
  7968. }
  7969. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7970. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7971. /// result:
  7972. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7973. /// star:
  7974. /// 0 = Place of the Sun
  7975. /// 1 = Place of the Moon
  7976. /// 2 = Place of the Stars
  7977. /// 1 = Star Gladiator %s's %s: <mapname>
  7978. /// star:
  7979. /// 0 = Place of the Sun
  7980. /// 1 = Place of the Moon
  7981. /// 2 = Place of the Stars
  7982. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7983. /// star:
  7984. /// 0 = Target of the Sun
  7985. /// 1 = Target of the Moon
  7986. /// 2 = Target of the Stars
  7987. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7988. /// star:
  7989. /// 0 = Monster of the Sun
  7990. /// 1 = Monster of the Moon
  7991. /// 2 = Monster of the Stars
  7992. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7993. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7994. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7995. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7996. /// 40 = Target HP : <monster_id used as HP>
  7997. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7998. {
  7999. int fd = sd->fd;
  8000. WFIFOHEAD(fd,packet_len(0x20e));
  8001. WFIFOW(fd,0) = 0x20e;
  8002. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8003. WFIFOL(fd,26) = monster_id;
  8004. WFIFOB(fd,30) = star;
  8005. WFIFOB(fd,31) = result;
  8006. WFIFOSET(fd,packet_len(0x20e));
  8007. }
  8008. /*==========================================
  8009. * Info about Star Glaldiator save map [Komurka]
  8010. * type: 1: Information, 0: Map registered
  8011. *------------------------------------------*/
  8012. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8013. {
  8014. char mapname[MAP_NAME_LENGTH_EXT];
  8015. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8016. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8017. }
  8018. /*==========================================
  8019. * Info about Star Glaldiator hate mob [Komurka]
  8020. * type: 1: Register mob, 0: Information.
  8021. *------------------------------------------*/
  8022. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8023. {
  8024. if( pcdb_checkid(class_) ) {
  8025. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8026. } else if( mobdb_checkid(class_) ) {
  8027. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8028. } else {
  8029. 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);
  8030. }
  8031. }
  8032. /*==========================================
  8033. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8034. *------------------------------------------*/
  8035. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8036. {
  8037. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8038. }
  8039. /*==========================================
  8040. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8041. *------------------------------------------*/
  8042. void clif_feel_hate_reset(struct map_session_data *sd)
  8043. {
  8044. clif_starskill(sd, "", 0, 0, 30);
  8045. }
  8046. /// Equip window (un)tick ack (ZC_CONFIG).
  8047. /// 02d9 <type>.L <value>.L
  8048. /// type:
  8049. /// 0 = open equip window
  8050. /// value:
  8051. /// 0 = disabled
  8052. /// 1 = enabled
  8053. void clif_equiptickack(struct map_session_data* sd, int flag)
  8054. {
  8055. int fd;
  8056. nullpo_retv(sd);
  8057. fd = sd->fd;
  8058. WFIFOHEAD(fd, packet_len(0x2d9));
  8059. WFIFOW(fd, 0) = 0x2d9;
  8060. WFIFOL(fd, 2) = 0;
  8061. WFIFOL(fd, 6) = flag;
  8062. WFIFOSET(fd, packet_len(0x2d9));
  8063. }
  8064. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8065. /// 02da <open equip window>.B
  8066. /// open equip window:
  8067. /// 0 = disabled
  8068. /// 1 = enabled
  8069. void clif_equipcheckbox(struct map_session_data* sd)
  8070. {
  8071. int fd;
  8072. nullpo_retv(sd);
  8073. fd = sd->fd;
  8074. WFIFOHEAD(fd, packet_len(0x2da));
  8075. WFIFOW(fd, 0) = 0x2da;
  8076. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8077. WFIFOSET(fd, packet_len(0x2da));
  8078. }
  8079. /// Sends info about a player's equipped items.
  8080. /// 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)
  8081. /// 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)
  8082. /// 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)
  8083. /// 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)
  8084. /// 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)
  8085. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8086. {
  8087. uint8* buf;
  8088. int i, n, fd, offset = 0;
  8089. #if PACKETVER < 20100629
  8090. const int s = 26;
  8091. #elif PACKETVER < 20120925
  8092. const int s = 28;
  8093. #else
  8094. const int s = 31;
  8095. #endif
  8096. nullpo_retv(sd);
  8097. nullpo_retv(tsd);
  8098. fd = sd->fd;
  8099. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8100. buf = WFIFOP(fd,0);
  8101. #if PACKETVER < 20101124
  8102. WBUFW(buf, 0) = 0x2d7;
  8103. #elif PACKETVER < 20120925
  8104. WBUFW(buf, 0) = 0x859;
  8105. #else
  8106. WBUFW(buf, 0) = 0x997;
  8107. #endif
  8108. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8109. WBUFW(buf,28) = tsd->status.class_;
  8110. WBUFW(buf,30) = tsd->vd.hair_style;
  8111. WBUFW(buf,32) = tsd->vd.head_bottom;
  8112. WBUFW(buf,34) = tsd->vd.head_mid;
  8113. WBUFW(buf,36) = tsd->vd.head_top;
  8114. #if PACKETVER >= 20110111
  8115. WBUFW(buf,38) = tsd->vd.robe;
  8116. offset+= 2;
  8117. buf = WBUFP(buf,2);
  8118. #endif
  8119. WBUFW(buf,38) = tsd->vd.hair_color;
  8120. WBUFW(buf,40) = tsd->vd.cloth_color;
  8121. WBUFB(buf,42) = tsd->vd.sex;
  8122. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8123. {
  8124. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8125. continue;
  8126. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8127. continue;
  8128. // Add item info : refine, identify flag, element, etc.
  8129. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8130. n++;
  8131. }
  8132. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8133. WFIFOSET(fd, WFIFOW(fd, 2));
  8134. }
  8135. /// Display msgstringtable.txt string (ZC_MSG).
  8136. /// 0291 <message>.W
  8137. void clif_msg(struct map_session_data* sd, unsigned short id)
  8138. {
  8139. int fd;
  8140. nullpo_retv(sd);
  8141. fd = sd->fd;
  8142. WFIFOHEAD(fd, packet_len(0x291));
  8143. WFIFOW(fd, 0) = 0x291;
  8144. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8145. WFIFOSET(fd, packet_len(0x291));
  8146. }
  8147. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8148. /// 0x7e2 <message>.W <value>.L
  8149. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8150. {
  8151. int fd = sd->fd;
  8152. WFIFOHEAD(fd, packet_len(0x7e2));
  8153. WFIFOW(fd,0) = 0x7e2;
  8154. WFIFOW(fd,2) = id;
  8155. WFIFOL(fd,4) = value;
  8156. WFIFOSET(fd, packet_len(0x7e2));
  8157. }
  8158. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8159. /// 07e6 <skill id>.W <msg id>.L
  8160. ///
  8161. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8162. /// "[SkillName] Message"
  8163. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8164. {
  8165. int fd = sd->fd;
  8166. WFIFOHEAD(fd, packet_len(0x7e6));
  8167. WFIFOW(fd,0) = 0x7e6;
  8168. WFIFOW(fd,2) = skill_id;
  8169. WFIFOL(fd,4) = msg_id;
  8170. WFIFOSET(fd, packet_len(0x7e6));
  8171. }
  8172. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8173. /// Returns true if the packet was parsed successfully.
  8174. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8175. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8176. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  8177. {
  8178. char *text, *name, *message;
  8179. unsigned int packetlen, textlen, namelen, messagelen;
  8180. int fd = sd->fd;
  8181. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8182. *name_ = NULL;
  8183. *namelen_ = 0;
  8184. *message_ = NULL;
  8185. *messagelen_ = 0;
  8186. packetlen = RFIFOW(fd,info->pos[0]);
  8187. // basic structure checks
  8188. if( packetlen < 4 + 1 )
  8189. { // 4-byte header and at least an empty string is expected
  8190. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8191. return false;
  8192. }
  8193. text = (char*)RFIFOP(fd,info->pos[1]);
  8194. textlen = packetlen - 4;
  8195. // process <name> part of the packet
  8196. if( format == 0 )
  8197. {// name and message are separated by ' : '
  8198. // validate name
  8199. name = text;
  8200. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8201. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8202. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8203. {
  8204. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8205. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8206. set_eof(fd); // Just kick them out to correct it.
  8207. return false;
  8208. }
  8209. message = name + namelen + 3;
  8210. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8211. }
  8212. else
  8213. {// name has fixed width
  8214. if( textlen < NAME_LENGTH + 1 )
  8215. {
  8216. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8217. return false;
  8218. }
  8219. // validate name
  8220. name = text;
  8221. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8222. if( name[namelen] != '\0' )
  8223. { // only restriction is that the name must be zero-terminated
  8224. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8225. return false;
  8226. }
  8227. message = name + NAME_LENGTH;
  8228. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8229. }
  8230. if( messagelen != strnlen(message, messagelen)+1 )
  8231. { // the declared length must match real length
  8232. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8233. return false;
  8234. }
  8235. // verify <message> part of the packet
  8236. if( message[messagelen-1] != '\0' )
  8237. { // message must be zero-terminated
  8238. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8239. return false;
  8240. }
  8241. if( messagelen > CHAT_SIZE_MAX-1 )
  8242. { // messages mustn't be too long
  8243. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8244. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8245. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8246. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8247. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8248. return false;
  8249. }
  8250. *name_ = name;
  8251. *namelen_ = namelen;
  8252. *message_ = message;
  8253. *messagelen_ = messagelen;
  8254. return true;
  8255. }
  8256. // ---------------------
  8257. // clif_guess_PacketVer
  8258. // ---------------------
  8259. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8260. // error codes:
  8261. // 0 - Success
  8262. // 1 - Unknown packet_ver
  8263. // 2 - Invalid account_id
  8264. // 3 - Invalid char_id
  8265. // 4 - Invalid login_id1 (reserved)
  8266. // 5 - Invalid client_tick (reserved)
  8267. // 6 - Invalid sex
  8268. // Only the first 'invalid' error that appears is used.
  8269. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8270. {
  8271. static int err = 1;
  8272. static int packet_ver = -1;
  8273. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8274. unsigned short cmd;
  8275. if (get_previous)
  8276. {//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]
  8277. if( error )
  8278. *error = err;
  8279. return packet_ver;
  8280. }
  8281. //By default, start searching on the default one.
  8282. err = 1;
  8283. packet_ver = clif_config.packet_db_ver;
  8284. cmd = clif_parse_cmd(fd, NULL);
  8285. packet_len = RFIFOREST(fd);
  8286. #define SET_ERROR(n) \
  8287. if( err == 1 )\
  8288. err = n;\
  8289. //define SET_ERROR
  8290. // FIXME: If the packet is not received at once, this will FAIL.
  8291. // Figure out, when it happens, that only part of the packet is
  8292. // received, or fix the function to be able to deal with that
  8293. // case.
  8294. #define CHECK_PACKET_VER() \
  8295. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8296. ;/* not wanttoconnection or wrong length */\
  8297. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8298. { SET_ERROR(2); }/* invalid account_id */\
  8299. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8300. { SET_ERROR(3); }/* invalid char_id */\
  8301. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8302. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8303. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8304. { SET_ERROR(6); }/* invalid sex */\
  8305. else\
  8306. {\
  8307. err = 0;\
  8308. if( error )\
  8309. *error = 0;\
  8310. return packet_ver;\
  8311. }\
  8312. //define CHECK_PACKET_VER
  8313. CHECK_PACKET_VER();//Default packet version found.
  8314. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8315. CHECK_PACKET_VER();
  8316. }
  8317. if( error )
  8318. *error = err;
  8319. packet_ver = -1;
  8320. return -1;
  8321. #undef SET_ERROR
  8322. #undef CHECK_PACKET_VER
  8323. }
  8324. // ------------
  8325. // clif_parse_*
  8326. // ------------
  8327. // Parses incoming (player) connection
  8328. /// Request to connect to map-server.
  8329. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8330. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8331. /// There are various variants of this packet, some of them have padding between fields.
  8332. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8333. {
  8334. struct block_list* bl;
  8335. struct auth_node* node;
  8336. int cmd, account_id, char_id, login_id1, sex;
  8337. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8338. 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])
  8339. if (sd) {
  8340. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8341. return;
  8342. }
  8343. // Only valid packet version get here
  8344. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8345. cmd = RFIFOW(fd,0);
  8346. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8347. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8348. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8349. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8350. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8351. if( packet_ver < 5 || // reject really old client versions
  8352. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8353. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8354. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8355. {// packet version rejected
  8356. 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));
  8357. WFIFOHEAD(fd,packet_len(0x6a));
  8358. WFIFOW(fd,0) = 0x6a;
  8359. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8360. WFIFOSET(fd,packet_len(0x6a));
  8361. set_eof(fd);
  8362. return;
  8363. }
  8364. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8365. clif_authfail_fd(fd,1);// server closed
  8366. return;
  8367. }
  8368. //Check for double login.
  8369. bl = map_id2bl(account_id);
  8370. if(bl && bl->type != BL_PC) {
  8371. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8372. WFIFOHEAD(fd,packet_len(0x6a));
  8373. WFIFOW(fd,0) = 0x6a;
  8374. WFIFOB(fd,2) = 3; // Rejected by server
  8375. WFIFOSET(fd,packet_len(0x6a));
  8376. set_eof(fd);
  8377. return;
  8378. }
  8379. if (bl ||
  8380. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8381. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8382. {
  8383. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8384. return;
  8385. }
  8386. CREATE(sd, TBL_PC, 1);
  8387. sd->fd = fd;
  8388. sd->packet_ver = packet_ver;
  8389. #ifdef PACKET_OBFUSCATION
  8390. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8391. #endif
  8392. session[fd]->session_data = sd;
  8393. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8394. #if PACKETVER < 20070521
  8395. WFIFOHEAD(fd,4);
  8396. WFIFOL(fd,0) = sd->bl.id;
  8397. WFIFOSET(fd,4);
  8398. #else
  8399. WFIFOHEAD(fd,packet_len(0x283));
  8400. WFIFOW(fd,0) = 0x283;
  8401. WFIFOL(fd,2) = sd->bl.id;
  8402. WFIFOSET(fd,packet_len(0x283));
  8403. #endif
  8404. chrif_authreq(sd,false);
  8405. }
  8406. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8407. /// 007d
  8408. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8409. {
  8410. bool guild_notice = false;
  8411. if(sd->bl.prev != NULL)
  8412. return;
  8413. if (!sd->state.active) { //Character loading is not complete yet!
  8414. //Let pc_reg_received reinvoke this when ready.
  8415. sd->state.connect_new = 0;
  8416. return;
  8417. }
  8418. if (sd->state.rewarp) { //Rewarp player.
  8419. sd->state.rewarp = 0;
  8420. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8421. return;
  8422. }
  8423. sd->state.warping = 0;
  8424. // look
  8425. #if PACKETVER < 4
  8426. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8427. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8428. #else
  8429. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8430. #endif
  8431. if(sd->vd.cloth_color)
  8432. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8433. // item
  8434. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8435. pc_checkitem(sd);
  8436. // cart
  8437. if(pc_iscarton(sd)) {
  8438. clif_cartlist(sd);
  8439. clif_updatestatus(sd,SP_CARTINFO);
  8440. }
  8441. // weight
  8442. clif_updatestatus(sd,SP_WEIGHT);
  8443. clif_updatestatus(sd,SP_MAXWEIGHT);
  8444. // guild
  8445. // (needs to go before clif_spawn() to show guild emblems correctly)
  8446. if(sd->status.guild_id)
  8447. guild_send_memberinfoshort(sd,1);
  8448. if(battle_config.pc_invincible_time > 0) {
  8449. if(map_flag_gvg(sd->bl.m))
  8450. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8451. else
  8452. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8453. }
  8454. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8455. map_spawnmobs(sd->bl.m);
  8456. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8457. map[sd->bl.m].users_pvp++;
  8458. }
  8459. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8460. // reset the callshop flag if the player changes map
  8461. sd->state.callshop = 0;
  8462. if(map_addblock(&sd->bl))
  8463. return;
  8464. clif_spawn(&sd->bl);
  8465. // Party
  8466. // (needs to go after clif_spawn() to show hp bars correctly)
  8467. if(sd->status.party_id) {
  8468. party_send_movemap(sd);
  8469. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8470. }
  8471. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8472. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8473. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8474. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8475. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8476. sd->pvp_rank = 0;
  8477. sd->pvp_lastusers = 0;
  8478. sd->pvp_point = 5;
  8479. sd->pvp_won = 0;
  8480. sd->pvp_lost = 0;
  8481. }
  8482. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8483. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8484. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8485. if (map[sd->bl.m].flag.gvg_dungeon)
  8486. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8487. if( map_flag_gvg(sd->bl.m) )
  8488. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8489. // info about nearby objects
  8490. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8491. 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);
  8492. // pet
  8493. if( sd->pd ) {
  8494. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8495. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8496. pet_menu(sd, 3); //Option 3 is return to egg.
  8497. } else {
  8498. if(map_addblock(&sd->pd->bl))
  8499. return;
  8500. clif_spawn(&sd->pd->bl);
  8501. clif_send_petdata(sd,sd->pd,0,0);
  8502. clif_send_petstatus(sd);
  8503. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8504. }
  8505. }
  8506. //homunculus [blackhole89]
  8507. if( hom_is_active(sd->hd) ) {
  8508. if(map_addblock(&sd->hd->bl))
  8509. return;
  8510. clif_spawn(&sd->hd->bl);
  8511. clif_send_homdata(sd,SP_ACK,0);
  8512. clif_hominfo(sd,sd->hd,1);
  8513. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8514. clif_homskillinfoblock(sd);
  8515. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8516. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8517. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8518. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8519. }
  8520. if( sd->md ) {
  8521. if(map_addblock(&sd->md->bl))
  8522. return;
  8523. clif_spawn(&sd->md->bl);
  8524. clif_mercenary_info(sd);
  8525. clif_mercenary_skillblock(sd);
  8526. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8527. }
  8528. if( sd->ed ) {
  8529. if (map_addblock(&sd->ed->bl))
  8530. return;
  8531. clif_spawn(&sd->ed->bl);
  8532. clif_elemental_info(sd);
  8533. clif_elemental_updatestatus(sd,SP_HP);
  8534. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8535. clif_elemental_updatestatus(sd,SP_SP);
  8536. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8537. }
  8538. if(sd->state.connect_new) {
  8539. int lv;
  8540. guild_notice = true;
  8541. sd->state.connect_new = 0;
  8542. clif_skillinfoblock(sd);
  8543. clif_hotkeys_send(sd);
  8544. clif_updatestatus(sd,SP_BASEEXP);
  8545. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8546. clif_updatestatus(sd,SP_JOBEXP);
  8547. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8548. clif_updatestatus(sd,SP_SKILLPOINT);
  8549. clif_initialstatus(sd);
  8550. if (sd->sc.option&OPTION_FALCON)
  8551. clif_status_load(&sd->bl, SI_FALCON, 1);
  8552. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8553. clif_status_load(&sd->bl, SI_RIDING, 1);
  8554. else if (sd->sc.option&OPTION_WUGRIDER)
  8555. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8556. else if (sd->sc.data[SC_ALL_RIDING])
  8557. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8558. if(sd->status.manner < 0)
  8559. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8560. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8561. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8562. if(sd->bl.m == sd->feel_map[0].m
  8563. || sd->bl.m == sd->feel_map[1].m
  8564. || sd->bl.m == sd->feel_map[2].m)
  8565. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8566. }
  8567. if(sd->pd && sd->pd->pet.intimate > 900)
  8568. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8569. if(hom_is_active(sd->hd))
  8570. hom_init_timers(sd->hd);
  8571. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8572. sd->state.night = 1;
  8573. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8574. }
  8575. // Notify everyone that this char logged in [Skotlex].
  8576. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8577. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8578. //Login Event
  8579. npc_script_event(sd, NPCE_LOGIN);
  8580. }
  8581. } else {
  8582. //For some reason the client "loses" these on warp/map-change.
  8583. clif_updatestatus(sd,SP_STR);
  8584. clif_updatestatus(sd,SP_AGI);
  8585. clif_updatestatus(sd,SP_VIT);
  8586. clif_updatestatus(sd,SP_INT);
  8587. clif_updatestatus(sd,SP_DEX);
  8588. clif_updatestatus(sd,SP_LUK);
  8589. // abort currently running script
  8590. sd->state.using_fake_npc = 0;
  8591. sd->state.menu_or_input = 0;
  8592. sd->npc_menu = 0;
  8593. if(sd->npc_id)
  8594. npc_event_dequeue(sd);
  8595. }
  8596. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8597. #if PACKETVER >= 20070918
  8598. clif_partyinvitationstate(sd);
  8599. clif_equipcheckbox(sd);
  8600. #endif
  8601. #ifdef VIP_ENABLE
  8602. if (!sd->disableshowrate) {
  8603. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8604. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8605. }
  8606. #endif
  8607. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8608. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8609. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8610. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8611. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8612. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8613. { //Display night.
  8614. if( !sd->state.night )
  8615. {
  8616. sd->state.night = 1;
  8617. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8618. }
  8619. }
  8620. else if( sd->state.night )
  8621. { //Clear night display.
  8622. sd->state.night = 0;
  8623. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8624. }
  8625. if( map[sd->bl.m].flag.battleground )
  8626. {
  8627. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8628. if( map[sd->bl.m].flag.battleground == 2 )
  8629. clif_bg_updatescore_single(sd);
  8630. }
  8631. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8632. {
  8633. char output[128];
  8634. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8635. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8636. }
  8637. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8638. map[sd->bl.m].hpmeter_visible++;
  8639. sd->state.hpmeter_visible = 1;
  8640. }
  8641. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8642. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8643. sd->state.changemap = false;
  8644. // Instances do not need their own channels
  8645. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8646. channel_mjoin(sd); //join new map
  8647. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8648. clif_guild_notice(sd, sd->guild); // Displays at end
  8649. mail_clear(sd);
  8650. clif_maptypeproperty2(&sd->bl,SELF);
  8651. /* Guild Aura Init */
  8652. if( sd->state.gmaster_flag ) {
  8653. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8654. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8655. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8656. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8657. }
  8658. if( sd->state.vending ) { /* show we have a vending */
  8659. clif_openvending(sd,sd->bl.id,sd->vending);
  8660. clif_showvendingboard(&sd->bl,sd->message,0);
  8661. }
  8662. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8663. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8664. npc_script_event(sd, NPCE_LOADMAP);
  8665. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8666. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8667. if (sd->sc.opt2) //Client loses these on warp.
  8668. clif_changeoption(&sd->bl);
  8669. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8670. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8671. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8672. }
  8673. clif_weather_check(sd);
  8674. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8675. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8676. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8677. else
  8678. sd->areanpc_id = 0;
  8679. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8680. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8681. pc_setdead(sd);
  8682. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8683. if(pc_isdead(sd))
  8684. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8685. else {
  8686. skill_usave_trigger(sd);
  8687. if (battle_config.spawn_direction)
  8688. clif_changed_dir(&sd->bl, SELF);
  8689. }
  8690. // Trigger skill effects if you appear standing on them
  8691. if(!battle_config.pc_invincible_time)
  8692. skill_unit_move(&sd->bl,gettick(),1);
  8693. #if PACKETVER >= 20090218
  8694. pc_show_questinfo_reinit(sd);
  8695. pc_show_questinfo(sd);
  8696. #endif
  8697. }
  8698. /// Server's tick (ZC_NOTIFY_TIME).
  8699. /// 007f <time>.L
  8700. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8701. {
  8702. int fd = sd->fd;
  8703. WFIFOHEAD(fd,packet_len(0x7f));
  8704. WFIFOW(fd,0) = 0x7f;
  8705. WFIFOL(fd,2) = time;
  8706. WFIFOSET(fd,packet_len(0x7f));
  8707. }
  8708. /// Request for server's tick.
  8709. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8710. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8711. /// There are various variants of this packet, some of them have padding between fields.
  8712. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8713. {
  8714. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8715. clif_notify_time(sd, gettick());
  8716. }
  8717. /// Sends hotkey bar.
  8718. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8719. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8720. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8721. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8722. void clif_hotkeys_send(struct map_session_data *sd) {
  8723. #ifdef HOTKEY_SAVING
  8724. const int fd = sd->fd;
  8725. int i;
  8726. int offset = 2;
  8727. #if PACKETVER < 20090603
  8728. const int cmd = 0x2b9;
  8729. #elif PACKETVER < 20141022
  8730. const int cmd = 0x7d9;
  8731. #else
  8732. char Rotate = sd->status.hotkey_rowshift;
  8733. const int cmd = 0xa00;
  8734. offset = 3;
  8735. #endif
  8736. if (!fd) return;
  8737. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8738. WFIFOW(fd, 0) = cmd;
  8739. #if PACKETVER >= 20141022
  8740. WFIFOB(fd, 2) = Rotate;
  8741. #endif
  8742. for(i = 0; i < MAX_HOTKEYS; i++) {
  8743. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8744. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8745. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8746. }
  8747. WFIFOSET(fd, packet_len(cmd));
  8748. #endif
  8749. }
  8750. /// Request to update a position on the hotkey row bar
  8751. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  8752. int cmd = RFIFOW(fd, 0);
  8753. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8754. }
  8755. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8756. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8757. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8758. #ifdef HOTKEY_SAVING
  8759. unsigned short idx;
  8760. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8761. idx = RFIFOW(fd, info->pos[0]);
  8762. if (idx >= MAX_HOTKEYS) return;
  8763. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8764. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8765. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8766. #endif
  8767. }
  8768. /// Displays cast-like progress bar (ZC_PROGRESS).
  8769. /// 02f0 <color>.L <time>.L
  8770. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8771. {
  8772. int fd = sd->fd;
  8773. WFIFOHEAD(fd,packet_len(0x2f0));
  8774. WFIFOW(fd,0) = 0x2f0;
  8775. WFIFOL(fd,2) = color;
  8776. WFIFOL(fd,6) = second;
  8777. WFIFOSET(fd,packet_len(0x2f0));
  8778. }
  8779. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8780. /// 02f2
  8781. void clif_progressbar_abort(struct map_session_data * sd)
  8782. {
  8783. int fd = sd->fd;
  8784. WFIFOHEAD(fd,packet_len(0x2f2));
  8785. WFIFOW(fd,0) = 0x2f2;
  8786. WFIFOSET(fd,packet_len(0x2f2));
  8787. }
  8788. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8789. /// 02f1
  8790. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8791. {
  8792. int npc_id = sd->progressbar.npc_id;
  8793. if( gettick() < sd->progressbar.timeout && sd->st )
  8794. sd->st->state = END;
  8795. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8796. npc_scriptcont(sd, npc_id, false);
  8797. }
  8798. /// Request to walk to a certain position on the current map.
  8799. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8800. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8801. /// There are various variants of this packet, some of them have padding between fields.
  8802. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8803. {
  8804. short x, y;
  8805. if (pc_isdead(sd)) {
  8806. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8807. return;
  8808. }
  8809. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8810. ; //You CAN walk on this OPT1 value.
  8811. else if( sd->progressbar.npc_id )
  8812. clif_progressbar_abort(sd);
  8813. else if (pc_cant_act(sd))
  8814. return;
  8815. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8816. return;
  8817. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8818. //A move command one cell west is only valid if the target cell is free
  8819. if(battle_config.official_cell_stack_limit > 0
  8820. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  8821. return;
  8822. // Cloaking wall check is actually updated when you click to process next movement
  8823. // not when you move each cell. This is official behaviour.
  8824. if (sd->sc.data[SC_CLOAKING])
  8825. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8826. pc_delinvincibletimer(sd);
  8827. //Set last idle time... [Skotlex]
  8828. if (battle_config.idletime_option&IDLE_WALK)
  8829. sd->idletime = last_tick;
  8830. unit_walktoxy(&sd->bl, x, y, 4);
  8831. }
  8832. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8833. /// 018b <result>.W
  8834. /// result:
  8835. /// 0 = disconnect (quit)
  8836. /// 1 = cannot disconnect (wait 10 seconds)
  8837. /// ? = ignored
  8838. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8839. {
  8840. int fd = sd->fd;
  8841. WFIFOHEAD(fd,packet_len(0x18b));
  8842. WFIFOW(fd,0) = 0x18b;
  8843. WFIFOW(fd,2) = result;
  8844. WFIFOSET(fd,packet_len(0x18b));
  8845. }
  8846. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8847. /// 018a <type>.W
  8848. /// type:
  8849. /// 0 = quit
  8850. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8851. {
  8852. /* Rovert's prevent logout option fixed [Valaris] */
  8853. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8854. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8855. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8856. {
  8857. set_eof(fd);
  8858. pc_damage_log_clear(sd,0);
  8859. clif_disconnect_ack(sd, 0);
  8860. } else {
  8861. clif_disconnect_ack(sd, 1);
  8862. }
  8863. }
  8864. /// Requesting unit's name.
  8865. /// 0094 <id>.L (CZ_REQNAME)
  8866. /// 0368 <id>.L (CZ_REQNAME2)
  8867. /// There are various variants of this packet, some of them have padding between fields.
  8868. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8869. {
  8870. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8871. struct block_list* bl;
  8872. //struct status_change *sc;
  8873. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8874. id = sd->bl.id;
  8875. bl = map_id2bl(id);
  8876. if( bl == NULL )
  8877. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8878. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8879. return; // Block namerequests past view range
  8880. // 'see people in GM hide' cheat detection
  8881. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8882. sc = status_get_sc(bl);
  8883. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8884. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8885. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8886. ) {
  8887. char gm_msg[256];
  8888. 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);
  8889. ShowWarning(gm_msg);
  8890. // information is sent to all online GMs
  8891. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8892. return;
  8893. }
  8894. */
  8895. clif_charnameack(fd, bl);
  8896. }
  8897. /// Validates and processes global messages
  8898. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8899. /// There are various variants of this packet.
  8900. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8901. {
  8902. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8903. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8904. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8905. char *name, *message, *fakename = NULL;
  8906. int namelen, messagelen;
  8907. bool is_fake;
  8908. // validate packet and retrieve name and message
  8909. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8910. return;
  8911. if( is_atcommand(fd, sd, message, 1) )
  8912. return;
  8913. if (sd->sc.cant.chat)
  8914. return; //no "chatting" while muted.
  8915. if( battle_config.min_chat_delay ) { //[Skotlex]
  8916. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8917. return;
  8918. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8919. }
  8920. if (battle_config.idletime_option&IDLE_CHAT)
  8921. sd->idletime = last_tick;
  8922. if( sd->gcbind ) {
  8923. channel_send(sd->gcbind,sd,message);
  8924. return;
  8925. }
  8926. /**
  8927. * Fake Name Design by FatalEror (bug report #9)
  8928. **/
  8929. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8930. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8931. strcpy(fakename, sd->fakename);
  8932. strcat(fakename, " : ");
  8933. strcat(fakename, message);
  8934. textlen = strlen(fakename) + 1;
  8935. }
  8936. // send message to others (using the send buffer for temp. storage)
  8937. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8938. // send back message to the speaker
  8939. if( is_fake ) {
  8940. WFIFOW(fd,0) = 0x8e;
  8941. WFIFOW(fd,2) = textlen + 4;
  8942. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8943. aFree(fakename);
  8944. } else {
  8945. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8946. WFIFOW(fd,0) = 0x8e;
  8947. }
  8948. WFIFOSET(fd, WFIFOW(fd,2));
  8949. #ifdef PCRE_SUPPORT
  8950. // trigger listening npcs
  8951. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8952. #endif
  8953. // Chat logging type 'O' / Global Chat
  8954. 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);
  8955. }
  8956. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8957. /// Request to warp to a map on given coordinates.
  8958. /// 0140 <map name>.16B <x>.W <y>.W
  8959. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8960. {
  8961. char command[MAP_NAME_LENGTH_EXT+25];
  8962. char* map_name;
  8963. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8964. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8965. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8966. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8967. RFIFOW(fd,info->pos[1]), //x
  8968. RFIFOW(fd,info->pos[2])); //y
  8969. is_atcommand(fd, sd, command, 1);
  8970. }
  8971. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8972. /// 009c <id>.L <head dir>.W <dir>.B
  8973. /// head dir:
  8974. /// 0 = straight
  8975. /// 1 = turned CW
  8976. /// 2 = turned CCW
  8977. /// dir:
  8978. /// 0 = north
  8979. /// 1 = northwest
  8980. /// 2 = west
  8981. /// 3 = southwest
  8982. /// 4 = south
  8983. /// 5 = southeast
  8984. /// 6 = east
  8985. /// 7 = northeast
  8986. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8987. {
  8988. unsigned char buf[64];
  8989. WBUFW(buf,0) = 0x9c;
  8990. WBUFL(buf,2) = bl->id;
  8991. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8992. WBUFB(buf,8) = unit_getdir(bl);
  8993. clif_send(buf, packet_len(0x9c), bl, target);
  8994. if (disguised(bl)) {
  8995. WBUFL(buf,2) = -bl->id;
  8996. WBUFW(buf,6) = 0;
  8997. clif_send(buf, packet_len(0x9c), bl, SELF);
  8998. }
  8999. }
  9000. /// Request to change own body and head direction.
  9001. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9002. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9003. /// There are various variants of this packet, some of them have padding between fields.
  9004. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9005. {
  9006. unsigned char headdir, dir;
  9007. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9008. headdir = RFIFOB(fd,info->pos[0]);
  9009. dir = RFIFOB(fd,info->pos[1]);
  9010. pc_setdir(sd, dir, headdir);
  9011. clif_changed_dir(&sd->bl, AREA_WOS);
  9012. }
  9013. /// Request to show an emotion (CZ_REQ_EMOTION).
  9014. /// 00bf <type>.B
  9015. /// type:
  9016. /// @see enum emotion_type
  9017. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9018. {
  9019. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9020. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  9021. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9022. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9023. return;
  9024. }
  9025. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9026. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9027. sd->emotionlasttime = time(NULL);
  9028. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9029. return;
  9030. }
  9031. sd->emotionlasttime = time(NULL);
  9032. if (battle_config.idletime_option&IDLE_EMOTION)
  9033. sd->idletime = last_tick;
  9034. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9035. emoticon = rnd()%6+E_DICE1;
  9036. }
  9037. clif_emotion(&sd->bl, emoticon);
  9038. } else
  9039. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9040. }
  9041. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9042. /// 00c2 <count>.L
  9043. void clif_user_count(struct map_session_data* sd, int count)
  9044. {
  9045. int fd = sd->fd;
  9046. WFIFOHEAD(fd,packet_len(0xc2));
  9047. WFIFOW(fd,0) = 0xc2;
  9048. WFIFOL(fd,2) = count;
  9049. WFIFOSET(fd,packet_len(0xc2));
  9050. }
  9051. /// /w /who (CZ_REQ_USER_COUNT).
  9052. /// Request to display amount of currently connected players.
  9053. /// 00c1
  9054. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9055. {
  9056. clif_user_count(sd, map_getusers());
  9057. }
  9058. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9059. {
  9060. if (pc_isdead(sd)) {
  9061. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9062. return;
  9063. }
  9064. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9065. // (not all are included in pc_can_attack)
  9066. if (sd->sc.count &&
  9067. (sd->sc.data[SC_TRICKDEAD] ||
  9068. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9069. sd->sc.data[SC_BLADESTOP] ||
  9070. sd->sc.data[SC__MANHOLE] ))
  9071. return;
  9072. if(action_type != 0x00 && action_type != 0x07)
  9073. pc_stop_walking(sd, 1);
  9074. pc_stop_attack(sd);
  9075. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9076. target_id = sd->bl.id;
  9077. switch(action_type)
  9078. {
  9079. case 0x00: // once attack
  9080. case 0x07: // continuous attack
  9081. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9082. return;
  9083. if( sd->sc.option&OPTION_COSTUME )
  9084. return;
  9085. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9086. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9087. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9088. return;
  9089. }
  9090. }
  9091. pc_delinvincibletimer(sd);
  9092. if (battle_config.idletime_option&IDLE_ATTACK)
  9093. sd->idletime = last_tick;
  9094. unit_attack(&sd->bl, target_id, action_type != 0);
  9095. break;
  9096. case 0x02: // sitdown
  9097. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  9098. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9099. break;
  9100. }
  9101. if(pc_issit(sd)) {
  9102. //Bugged client? Just refresh them.
  9103. clif_sitting(&sd->bl);
  9104. return;
  9105. }
  9106. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  9107. break;
  9108. if (sd->sc.count && (
  9109. sd->sc.data[SC_DANCING] ||
  9110. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9111. )) //No sitting during these states either.
  9112. break;
  9113. if (battle_config.idletime_option&IDLE_SIT)
  9114. sd->idletime = last_tick;
  9115. pc_setsit(sd);
  9116. skill_sit(sd, 1);
  9117. clif_sitting(&sd->bl);
  9118. break;
  9119. case 0x03: // standup
  9120. if (!pc_issit(sd)) {
  9121. //Bugged client? Just refresh them.
  9122. clif_standing(&sd->bl);
  9123. return;
  9124. }
  9125. if (pc_setstand(sd, false)) {
  9126. if (battle_config.idletime_option&IDLE_SIT)
  9127. sd->idletime = last_tick;
  9128. skill_sit(sd, 0);
  9129. clif_standing(&sd->bl);
  9130. }
  9131. break;
  9132. }
  9133. }
  9134. /// Request for an action.
  9135. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9136. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9137. /// action:
  9138. /// 0 = attack
  9139. /// 1 = pick up item
  9140. /// 2 = sit down
  9141. /// 3 = stand up
  9142. /// 7 = continous attack
  9143. /// 12 = (touch skill?)
  9144. /// There are various variants of this packet, some of them have padding between fields.
  9145. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9146. {
  9147. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9148. clif_parse_ActionRequest_sub(sd,
  9149. RFIFOB(fd,info->pos[1]),
  9150. RFIFOL(fd,info->pos[0]),
  9151. gettick()
  9152. );
  9153. }
  9154. /// Response to the death/system menu (CZ_RESTART).
  9155. /// 00b2 <type>.B
  9156. /// type:
  9157. /// 0 = restart (respawn)
  9158. /// 1 = char-select (disconnect)
  9159. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9160. {
  9161. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9162. case 0x00:
  9163. pc_respawn(sd,CLR_OUTSIGHT);
  9164. break;
  9165. case 0x01:
  9166. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9167. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9168. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9169. { //Send to char-server for character selection.
  9170. pc_damage_log_clear(sd,0);
  9171. chrif_charselectreq(sd, session[fd]->client_addr);
  9172. } else {
  9173. clif_disconnect_ack(sd, 1);
  9174. }
  9175. break;
  9176. }
  9177. }
  9178. /// Validates and processes whispered messages (CZ_WHISPER).
  9179. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9180. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9181. {
  9182. struct map_session_data* dstsd;
  9183. int i;
  9184. char *target, *message;
  9185. int namelen, messagelen;
  9186. // validate packet and retrieve name and message
  9187. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9188. return;
  9189. if ( is_atcommand(fd, sd, message, 1) )
  9190. return;
  9191. if (sd->sc.cant.chat)
  9192. return; //no "chatting" while muted.
  9193. if (battle_config.min_chat_delay) { //[Skotlex]
  9194. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9195. return;
  9196. }
  9197. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9198. }
  9199. if (battle_config.idletime_option&IDLE_CHAT)
  9200. sd->idletime = last_tick;
  9201. // Chat logging type 'W' / Whisper
  9202. 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);
  9203. //-------------------------------------------------------//
  9204. // Lordalfa - Paperboy - To whisper NPC commands //
  9205. //-------------------------------------------------------//
  9206. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9207. {
  9208. char* str = target+4; //Skip the NPC: string part.
  9209. struct npc_data* npc;
  9210. if ((npc = npc_name2id(str))) {
  9211. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9212. char *split;
  9213. char output[256];
  9214. str = message;
  9215. // skip codepage indicator, if detected
  9216. if( str[0] == '|' && strlen(str) >= 4 )
  9217. str += 3;
  9218. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9219. split = strchr(str,'#');
  9220. if( split == NULL ) { // use the remaining string
  9221. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9222. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9223. split_data[i][0] = '\0';
  9224. break;
  9225. }
  9226. *split = '\0';
  9227. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9228. str = split+1;
  9229. }
  9230. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9231. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9232. set_var(sd,output,(char *) split_data[i]);
  9233. }
  9234. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9235. npc_event(sd,output,0); // Calls the NPC label
  9236. return;
  9237. }
  9238. } else if( target[0] == '#' ) {
  9239. struct Channel *channel = NULL;
  9240. char* chname = target;
  9241. channel = channel_name2channel(chname,sd,3);
  9242. if(channel){
  9243. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9244. channel_send(channel,sd,message);
  9245. }
  9246. else if( channel->pass[0] == '\0') { //no pass needed
  9247. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9248. }
  9249. else {
  9250. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9251. }
  9252. return;
  9253. }
  9254. }
  9255. // searching destination character
  9256. dstsd = map_nick2sd(target);
  9257. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9258. // player is not on this map-server
  9259. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9260. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9261. // and if we ask for 'Test', we must not contact 'test' player
  9262. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9263. intif_wis_message(sd, target, message, messagelen);
  9264. return;
  9265. }
  9266. // if player ignores everyone
  9267. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9268. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9269. clif_wis_end(fd, 1); // 1: target character is not logged in
  9270. else
  9271. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9272. return;
  9273. }
  9274. // if player is autotrading
  9275. if (dstsd->state.autotrade == 1) {
  9276. char output[256];
  9277. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9278. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9279. return;
  9280. }
  9281. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9282. // if player ignores the source character
  9283. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9284. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9285. clif_wis_end(fd, 2); // 2: ignored by target
  9286. return;
  9287. }
  9288. }
  9289. // notify sender of success
  9290. clif_wis_end(fd, 0); // 0: success to send wisper
  9291. // Normal message
  9292. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9293. }
  9294. /// /b /nb (CZ_BROADCAST).
  9295. /// Request to broadcast a message on whole server.
  9296. /// 0099 <packet len>.W <text>.?B 00
  9297. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9298. char command[CHAT_SIZE_MAX+11];
  9299. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9300. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9301. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9302. // as the length varies depending on the command used, just block unreasonably long strings
  9303. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9304. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9305. is_atcommand(fd, sd, command, 1);
  9306. }
  9307. /// Request to pick up an item.
  9308. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9309. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9310. /// There are various variants of this packet, some of them have padding between fields.
  9311. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9312. {
  9313. struct flooritem_data *fitem;
  9314. int map_object_id;
  9315. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9316. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9317. do {
  9318. if (pc_isdead(sd)) {
  9319. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9320. break;
  9321. }
  9322. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9323. break;
  9324. if (pc_cant_act(sd))
  9325. break;
  9326. if (!pc_takeitem(sd, fitem))
  9327. break;
  9328. return;
  9329. } while (0);
  9330. // Client REQUIRES a fail packet or you can no longer pick items.
  9331. clif_additem(sd,0,0,6);
  9332. }
  9333. /// Request to drop an item.
  9334. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9335. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9336. /// There are various variants of this packet, some of them have padding between fields.
  9337. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9338. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9339. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9340. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9341. for(;;) {
  9342. if (pc_isdead(sd))
  9343. break;
  9344. if (pc_cant_act2(sd) || sd->npc_id)
  9345. break;
  9346. if (sd->sc.count && (
  9347. sd->sc.data[SC_AUTOCOUNTER] ||
  9348. sd->sc.data[SC_BLADESTOP] ||
  9349. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9350. ))
  9351. break;
  9352. if (!pc_dropitem(sd, item_index, item_amount))
  9353. break;
  9354. if (battle_config.idletime_option&IDLE_DROPITEM)
  9355. sd->idletime = last_tick;
  9356. return;
  9357. }
  9358. //Because the client does not like being ignored.
  9359. clif_dropitem(sd, item_index,0);
  9360. }
  9361. /// Request to use an item.
  9362. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9363. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9364. /// There are various variants of this packet, some of them have padding between fields.
  9365. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9366. {
  9367. int n;
  9368. if (pc_isdead(sd)) {
  9369. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9370. return;
  9371. }
  9372. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9373. return;
  9374. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9375. if (battle_config.idletime_option&IDLE_USEITEM)
  9376. sd->idletime = last_tick;
  9377. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9378. if(n <0 || n >= MAX_INVENTORY)
  9379. return;
  9380. if (!pc_useitem(sd,n))
  9381. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9382. }
  9383. /// Request to equip an item
  9384. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9385. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9386. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9387. {
  9388. int index;
  9389. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9390. if(pc_isdead(sd)) {
  9391. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9392. return;
  9393. }
  9394. index = RFIFOW(fd,info->pos[0])-2;
  9395. if (index < 0 || index >= MAX_INVENTORY)
  9396. return; //Out of bounds check.
  9397. if(sd->npc_id && !sd->npc_item_flag) {
  9398. return;
  9399. } else if (sd->state.storage_flag || sd->sc.opt1)
  9400. ; //You can equip/unequip stuff while storage is open/under status changes
  9401. else if (pc_cant_act2(sd))
  9402. return;
  9403. if(!sd->status.inventory[index].identify) {
  9404. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9405. return;
  9406. }
  9407. if(!sd->inventory_data[index])
  9408. return;
  9409. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9410. pet_equipitem(sd,index);
  9411. return;
  9412. }
  9413. if (battle_config.idletime_option&IDLE_USEITEM)
  9414. sd->idletime = last_tick;
  9415. //Client doesn't send the position for ammo.
  9416. if(sd->inventory_data[index]->type == IT_AMMO)
  9417. pc_equipitem(sd,index,EQP_AMMO);
  9418. else {
  9419. int req_pos;
  9420. #if PACKETVER >= 20120925
  9421. req_pos = RFIFOL(fd,info->pos[1]);
  9422. #else
  9423. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9424. #endif
  9425. pc_equipitem(sd,index,req_pos);
  9426. }
  9427. }
  9428. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9429. /// 00ab <index>.W
  9430. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9431. {
  9432. int index;
  9433. if(pc_isdead(sd)) {
  9434. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9435. return;
  9436. }
  9437. if (sd->npc_id && !sd->npc_item_flag) {
  9438. return;
  9439. } else if (sd->state.storage_flag || sd->sc.opt1)
  9440. ; //You can equip/unequip stuff while storage is open/under status changes
  9441. else if (pc_cant_act2(sd))
  9442. return;
  9443. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9444. if (battle_config.idletime_option&IDLE_USEITEM)
  9445. sd->idletime = last_tick;
  9446. pc_unequipitem(sd,index,1);
  9447. }
  9448. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9449. /// 0090 <id>.L <type>.B
  9450. /// type:
  9451. /// 1 = click
  9452. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9453. {
  9454. struct block_list *bl;
  9455. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9456. if(pc_isdead(sd)) {
  9457. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9458. return;
  9459. }
  9460. if (pc_cant_act2(sd) || sd->npc_id)
  9461. return;
  9462. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9463. //type = RFIFOB(fd,info->pos[1]);
  9464. if (!bl) return;
  9465. switch (bl->type) {
  9466. case BL_MOB:
  9467. case BL_PC:
  9468. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9469. break;
  9470. case BL_NPC:
  9471. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9472. npc_click(sd,(TBL_NPC*)bl);
  9473. break;
  9474. }
  9475. }
  9476. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9477. /// 00c5 <id>.L <type>.B
  9478. /// type:
  9479. /// 0 = buy
  9480. /// 1 = sell
  9481. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9482. {
  9483. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9484. if (sd->state.trading)
  9485. return;
  9486. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9487. }
  9488. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9489. /// 00ca <result>.B
  9490. /// result:
  9491. /// 0 = "The deal has successfully completed."
  9492. /// 1 = "You do not have enough zeny."
  9493. /// 2 = "You are over your Weight Limit."
  9494. /// 3 = "Out of the maximum capacity, you have too many items."
  9495. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9496. {
  9497. int fd = sd->fd;
  9498. WFIFOHEAD(fd,packet_len(0xca));
  9499. WFIFOW(fd,0) = 0xca;
  9500. WFIFOB(fd,2) = result;
  9501. WFIFOSET(fd,packet_len(0xca));
  9502. }
  9503. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9504. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9505. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9506. {
  9507. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9508. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9509. int result;
  9510. if( sd->state.trading || !sd->npc_shopid )
  9511. result = 1;
  9512. else
  9513. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9514. sd->npc_shopid = 0; //Clear shop data.
  9515. clif_npc_buy_result(sd, result);
  9516. }
  9517. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9518. /// 00cb <result>.B
  9519. /// result:
  9520. /// 0 = "The deal has successfully completed."
  9521. /// 1 = "The deal has failed."
  9522. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9523. {
  9524. int fd = sd->fd;
  9525. WFIFOHEAD(fd,packet_len(0xcb));
  9526. WFIFOW(fd,0) = 0xcb;
  9527. WFIFOB(fd,2) = result;
  9528. WFIFOSET(fd,packet_len(0xcb));
  9529. }
  9530. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9531. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9532. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9533. {
  9534. int fail=0,n;
  9535. unsigned short *item_list;
  9536. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9537. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9538. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9539. if (sd->state.trading || !sd->npc_shopid)
  9540. fail = 1;
  9541. else
  9542. fail = npc_selllist(sd,n,item_list);
  9543. sd->npc_shopid = 0; //Clear shop data.
  9544. clif_npc_sell_result(sd, fail);
  9545. }
  9546. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9547. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9548. /// type:
  9549. /// 0 = private
  9550. /// 1 = public
  9551. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9552. {
  9553. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9554. int len = RFIFOW(fd,info->pos[0])-15;
  9555. int limit = RFIFOW(fd,info->pos[1]);
  9556. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9557. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9558. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9559. char s_password[CHATROOM_PASS_SIZE];
  9560. char s_title[CHATROOM_TITLE_SIZE];
  9561. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9562. return;
  9563. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9564. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9565. return;
  9566. }
  9567. if( npc_isnear(&sd->bl) ) {
  9568. // uncomment to send msg_txt.
  9569. //char output[150];
  9570. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9571. //clif_displaymessage(sd->fd, output);
  9572. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9573. return;
  9574. }
  9575. if( len <= 0 )
  9576. return; // invalid input
  9577. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9578. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9579. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9580. }
  9581. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9582. /// 00d9 <chat ID>.L <passwd>.8B
  9583. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9584. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9585. int chatid = RFIFOL(fd,info->pos[0]);
  9586. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9587. chat_joinchat(sd,chatid,password);
  9588. }
  9589. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9590. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9591. /// type:
  9592. /// 0 = private
  9593. /// 1 = public
  9594. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9595. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9596. int len = RFIFOW(fd,info->pos[0])-15;
  9597. int limit = RFIFOW(fd,info->pos[1]);
  9598. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9599. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9600. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9601. char s_password[CHATROOM_PASS_SIZE];
  9602. char s_title[CHATROOM_TITLE_SIZE];
  9603. if( len <= 0 )
  9604. return; // invalid input
  9605. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9606. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9607. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9608. }
  9609. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9610. /// 00e0 <role>.L <nick>.24B
  9611. /// role:
  9612. /// 0 = owner
  9613. /// 1 = normal
  9614. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9615. {
  9616. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9617. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9618. }
  9619. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9620. /// 00e2 <name>.24B
  9621. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9622. {
  9623. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9624. }
  9625. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9626. /// 00e3
  9627. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9628. {
  9629. chat_leavechat(sd,0);
  9630. }
  9631. //Handles notifying asker and rejecter of what has just ocurred.
  9632. //Type is used to determine the correct msg_txt to use:
  9633. //0:
  9634. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9635. {
  9636. const char* msg;
  9637. char output[256];
  9638. // Your request has been rejected by autoreject option.
  9639. msg = msg_txt(sd,392);
  9640. clif_disp_onlyself(sd, msg, strlen(msg));
  9641. //Notice that a request was rejected.
  9642. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9643. clif_disp_onlyself(tsd, output, strlen(output));
  9644. }
  9645. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9646. /// 00e4 <account id>.L
  9647. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9648. {
  9649. struct map_session_data *t_sd;
  9650. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9651. if(!sd->chatID && pc_cant_act(sd))
  9652. return; //You can trade while in a chatroom.
  9653. // @noask [LuzZza]
  9654. if(t_sd && t_sd->state.noask) {
  9655. clif_noask_sub(sd, t_sd, 0);
  9656. return;
  9657. }
  9658. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9659. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9660. return;
  9661. }
  9662. trade_traderequest(sd,t_sd);
  9663. }
  9664. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9665. /// 00e6 <result>.B
  9666. /// result:
  9667. /// 3 = accepted
  9668. /// 4 = rejected
  9669. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9670. {
  9671. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9672. }
  9673. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9674. /// 00e8 <index>.W <amount>.L
  9675. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9676. {
  9677. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9678. short index = RFIFOW(fd,info->pos[0]);
  9679. int amount = RFIFOL(fd,info->pos[1]);
  9680. if( index == 0 )
  9681. trade_tradeaddzeny(sd, amount);
  9682. else
  9683. trade_tradeadditem(sd, index, (short)amount);
  9684. }
  9685. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9686. /// 00eb
  9687. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9688. {
  9689. trade_tradeok(sd);
  9690. }
  9691. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9692. /// 00ed
  9693. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9694. {
  9695. trade_tradecancel(sd);
  9696. }
  9697. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9698. /// 00ef
  9699. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9700. {
  9701. trade_tradecommit(sd);
  9702. }
  9703. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9704. /// 0118
  9705. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9706. {
  9707. pc_stop_attack(sd);
  9708. }
  9709. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9710. /// 0126 <index>.W <amount>.L
  9711. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9712. {
  9713. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9714. if (pc_istrading(sd))
  9715. return;
  9716. if (!pc_iscarton(sd))
  9717. return;
  9718. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9719. }
  9720. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9721. /// 0127 <index>.W <amount>.L
  9722. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9723. {
  9724. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9725. if (!pc_iscarton(sd))
  9726. return;
  9727. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9728. }
  9729. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9730. /// 012a
  9731. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9732. {
  9733. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9734. #ifdef NEW_CARTS
  9735. && sd->sc.data[SC_PUSH_CART] )
  9736. pc_setcart(sd,0);
  9737. #else
  9738. )
  9739. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9740. #endif
  9741. else // priority to remove this option before we can clear cart
  9742. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9743. }
  9744. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9745. /// 01af <num>.W
  9746. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9747. {// TODO: State tracking?
  9748. int type;
  9749. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9750. return;
  9751. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9752. #ifdef NEW_CARTS
  9753. if( (type == 9 && sd->status.base_level > 131) ||
  9754. (type == 8 && sd->status.base_level > 121) ||
  9755. (type == 7 && sd->status.base_level > 111) ||
  9756. (type == 6 && sd->status.base_level > 101) ||
  9757. (type == 5 && sd->status.base_level > 90) ||
  9758. (type == 4 && sd->status.base_level > 80) ||
  9759. (type == 3 && sd->status.base_level > 65) ||
  9760. (type == 2 && sd->status.base_level > 40) ||
  9761. (type == 1))
  9762. #else
  9763. if( (type == 5 && sd->status.base_level > 90) ||
  9764. (type == 4 && sd->status.base_level > 80) ||
  9765. (type == 3 && sd->status.base_level > 65) ||
  9766. (type == 2 && sd->status.base_level > 40) ||
  9767. (type == 1))
  9768. #endif
  9769. pc_setcart(sd,type);
  9770. }
  9771. /// Request to increase status (CZ_STATUS_CHANGE).
  9772. /// 00bb <status id>.W <amount>.B
  9773. /// status id:
  9774. /// SP_STR ~ SP_LUK
  9775. /// amount:
  9776. /// Old clients always send 1 for this, even when using /str+ and the like.
  9777. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9778. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9779. {
  9780. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9781. if( increase_amount < 0 ) {
  9782. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9783. fd, increase_amount);
  9784. }
  9785. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9786. }
  9787. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9788. /// 0112 <skill id>.W
  9789. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9790. {
  9791. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9792. }
  9793. 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)
  9794. {
  9795. int lv;
  9796. if( !hd )
  9797. return;
  9798. if( skill_isNotOk_hom(skill_id, hd) ) {
  9799. clif_emotion(&hd->bl, E_DOTS);
  9800. return;
  9801. }
  9802. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9803. target_id = hd->bl.id;
  9804. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9805. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9806. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9807. clif_emotion(&hd->bl, E_DOTS);
  9808. if (hd->master)
  9809. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9810. return;
  9811. }
  9812. lv = hom_checkskill(hd, skill_id);
  9813. if( skill_lv > lv )
  9814. skill_lv = lv;
  9815. if( skill_lv )
  9816. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9817. }
  9818. 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)
  9819. {
  9820. int lv;
  9821. if( !hd )
  9822. return;
  9823. if( skill_isNotOk_hom(skill_id, hd) ) {
  9824. clif_emotion(&hd->bl, E_DOTS);
  9825. return;
  9826. }
  9827. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9828. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9829. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9830. clif_emotion(&hd->bl, E_DOTS);
  9831. if (hd->master)
  9832. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9833. return;
  9834. }
  9835. if( hd->sc.data[SC_BASILICA] )
  9836. return;
  9837. lv = hom_checkskill(hd, skill_id);
  9838. if( skill_lv > lv )
  9839. skill_lv = lv;
  9840. if( skill_lv )
  9841. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9842. }
  9843. 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)
  9844. {
  9845. int lv;
  9846. if( !md )
  9847. return;
  9848. if( skill_isNotOk_mercenary(skill_id, md) )
  9849. return;
  9850. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9851. target_id = md->bl.id;
  9852. if( md->ud.skilltimer != INVALID_TIMER )
  9853. {
  9854. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9855. }
  9856. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9857. return;
  9858. lv = mercenary_checkskill(md, skill_id);
  9859. if( skill_lv > lv )
  9860. skill_lv = lv;
  9861. if( skill_lv )
  9862. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9863. }
  9864. 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)
  9865. {
  9866. int lv;
  9867. if( !md )
  9868. return;
  9869. if( skill_isNotOk_mercenary(skill_id, md) )
  9870. return;
  9871. if( md->ud.skilltimer != INVALID_TIMER )
  9872. return;
  9873. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9874. {
  9875. if (md->master)
  9876. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9877. return;
  9878. }
  9879. if( md->sc.data[SC_BASILICA] )
  9880. return;
  9881. lv = mercenary_checkskill(md, skill_id);
  9882. if( skill_lv > lv )
  9883. skill_lv = lv;
  9884. if( skill_lv )
  9885. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9886. }
  9887. /// Request to use a targeted skill.
  9888. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9889. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9890. /// There are various variants of this packet, some of them have padding between fields.
  9891. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9892. {
  9893. uint16 skill_id, skill_lv;
  9894. int tmp, target_id;
  9895. unsigned int tick = gettick();
  9896. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9897. skill_lv = RFIFOW(fd,info->pos[0]);
  9898. skill_id = RFIFOW(fd,info->pos[1]);
  9899. target_id = RFIFOL(fd,info->pos[2]);
  9900. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9901. tmp = skill_get_inf(skill_id);
  9902. if (tmp&INF_GROUND_SKILL || !tmp)
  9903. return; //Using a ground/passive skill on a target? WRONG.
  9904. if( SKILL_CHK_HOMUN(skill_id) ) {
  9905. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9906. return;
  9907. }
  9908. if( SKILL_CHK_MERC(skill_id) ) {
  9909. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9910. return;
  9911. }
  9912. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9913. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  9914. sd->idletime = last_tick;
  9915. if( sd->npc_id ){
  9916. #ifdef RENEWAL
  9917. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9918. return;
  9919. #else
  9920. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9921. return;
  9922. #endif
  9923. }
  9924. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9925. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9926. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9927. return;
  9928. if( pc_issit(sd) )
  9929. return;
  9930. if( skill_isNotOk(skill_id, sd) )
  9931. return;
  9932. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9933. target_id = sd->bl.id; // never trust the client
  9934. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9935. target_id = sd->bl.id;
  9936. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9937. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9938. return;
  9939. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9940. if( sd->skillitem != skill_id ) {
  9941. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9942. return;
  9943. }
  9944. }
  9945. if( sd->sc.option&OPTION_COSTUME )
  9946. return;
  9947. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9948. return; // On basilica only caster can use Basilica again to stop it.
  9949. if( sd->menuskill_id ) {
  9950. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9951. clif_menuskill_clear(sd); //Cancel pet capture.
  9952. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9953. return; //Can't use skills while a menu is open.
  9954. }
  9955. if( sd->skillitem == skill_id ) {
  9956. if( skill_lv != sd->skillitemlv )
  9957. skill_lv = sd->skillitemlv;
  9958. if( !(tmp&INF_SELF_SKILL) )
  9959. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9960. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9961. return;
  9962. }
  9963. sd->skillitem = sd->skillitemlv = 0;
  9964. if( SKILL_CHK_GUILD(skill_id) ) {
  9965. if( sd->state.gmaster_flag )
  9966. skill_lv = guild_checkskill(sd->guild, skill_id);
  9967. else
  9968. skill_lv = 0;
  9969. } else {
  9970. tmp = pc_checkskill(sd, skill_id);
  9971. if( skill_lv > tmp )
  9972. skill_lv = tmp;
  9973. }
  9974. pc_delinvincibletimer(sd);
  9975. if( skill_lv )
  9976. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9977. }
  9978. /*==========================================
  9979. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9980. *------------------------------------------*/
  9981. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9982. {
  9983. unsigned int tick = gettick();
  9984. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9985. return; //Using a target skill on the ground? WRONG.
  9986. if( SKILL_CHK_HOMUN(skill_id) ) {
  9987. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9988. return;
  9989. }
  9990. if( SKILL_CHK_MERC(skill_id) ) {
  9991. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9992. return;
  9993. }
  9994. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9995. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  9996. sd->idletime = last_tick;
  9997. if( skill_isNotOk(skill_id, sd) )
  9998. return;
  9999. if( skillmoreinfo != -1 ) {
  10000. if( pc_issit(sd) ) {
  10001. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10002. return;
  10003. }
  10004. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10005. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10006. }
  10007. if( sd->ud.skilltimer != INVALID_TIMER )
  10008. return;
  10009. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10010. if( sd->skillitem != skill_id ) {
  10011. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10012. return;
  10013. }
  10014. }
  10015. if( sd->sc.option&OPTION_COSTUME )
  10016. return;
  10017. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10018. return; // On basilica only caster can use Basilica again to stop it.
  10019. if( sd->menuskill_id ) {
  10020. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10021. clif_menuskill_clear(sd); //Cancel pet capture.
  10022. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10023. return; //Can't use skills while a menu is open.
  10024. }
  10025. pc_delinvincibletimer(sd);
  10026. if( sd->skillitem == skill_id ) {
  10027. if( skill_lv != sd->skillitemlv )
  10028. skill_lv = sd->skillitemlv;
  10029. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10030. } else {
  10031. int lv;
  10032. sd->skillitem = sd->skillitemlv = 0;
  10033. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10034. if( skill_lv > lv )
  10035. skill_lv = lv;
  10036. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10037. }
  10038. }
  10039. }
  10040. /// Request to use a ground skill.
  10041. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10042. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10043. /// There are various variants of this packet, some of them have padding between fields.
  10044. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10045. {
  10046. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10047. if (pc_cant_act(sd))
  10048. return;
  10049. if (pc_issit(sd))
  10050. return;
  10051. clif_parse_UseSkillToPosSub(fd, sd,
  10052. RFIFOW(fd,info->pos[0]), //skill lv
  10053. RFIFOW(fd,info->pos[1]), //skill num
  10054. RFIFOW(fd,info->pos[2]), //pos x
  10055. RFIFOW(fd,info->pos[3]), //pos y
  10056. -1 //Skill more info.
  10057. );
  10058. }
  10059. /// Request to use a ground skill with text.
  10060. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10061. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10062. /// There are various variants of this packet, some of them have padding between fields.
  10063. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10064. {
  10065. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10066. if (pc_cant_act(sd))
  10067. return;
  10068. if (pc_issit(sd))
  10069. return;
  10070. clif_parse_UseSkillToPosSub(fd, sd,
  10071. RFIFOW(fd,info->pos[0]), //Skill lv
  10072. RFIFOW(fd,info->pos[1]), //Skill num
  10073. RFIFOW(fd,info->pos[2]), //pos x
  10074. RFIFOW(fd,info->pos[3]), //pos y
  10075. info->pos[4] //skill more info
  10076. );
  10077. }
  10078. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10079. /// 011b <skill id>.W <map name>.16B
  10080. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10081. {
  10082. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10083. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10084. char map_name[MAP_NAME_LENGTH];
  10085. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10086. if(skill_id != sd->menuskill_id)
  10087. return;
  10088. //It is possible to use teleport with the storage window open bugreport:8027
  10089. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10090. clif_menuskill_clear(sd);
  10091. return;
  10092. }
  10093. pc_delinvincibletimer(sd);
  10094. skill_castend_map(sd,skill_id,map_name);
  10095. }
  10096. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10097. /// 011d
  10098. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10099. {
  10100. if (!pc_isdead(sd))
  10101. pc_memo(sd,-1);
  10102. }
  10103. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10104. /// 018e <name id>.W { <material id>.W }*3
  10105. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10106. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10107. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10108. int slot1 = RFIFOW(fd,info->pos[1]);
  10109. int slot2 = RFIFOW(fd,info->pos[2]);
  10110. int slot3 = RFIFOW(fd,info->pos[3]);
  10111. short produce_idx = -1;
  10112. switch( sd->menuskill_id ) {
  10113. case -1:
  10114. case AM_PHARMACY:
  10115. case RK_RUNEMASTERY:
  10116. case GC_RESEARCHNEWPOISON:
  10117. break;
  10118. default:
  10119. return;
  10120. }
  10121. if (pc_istrading(sd)) {
  10122. //Make it fail to avoid shop exploits where you sell something different than you see.
  10123. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10124. clif_menuskill_clear(sd);
  10125. return;
  10126. }
  10127. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10128. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10129. clif_menuskill_clear(sd);
  10130. }
  10131. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10132. /// 025b <mk type>.W <name id>.W
  10133. /// mk type:
  10134. /// 1 = cooking
  10135. /// 2 = arrow
  10136. /// 3 = elemental
  10137. /// 4 = GN_MIX_COOKING
  10138. /// 5 = GN_MAKEBOMB
  10139. /// 6 = GN_S_PHARMACY
  10140. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10141. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10142. int type = RFIFOW(fd,info->pos[0]);
  10143. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10144. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10145. short food_idx = -1;
  10146. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10147. return;
  10148. if (pc_istrading(sd)) {
  10149. //Make it fail to avoid shop exploits where you sell something different than you see.
  10150. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10151. clif_menuskill_clear(sd);
  10152. return;
  10153. }
  10154. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10155. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10156. clif_menuskill_clear(sd);
  10157. }
  10158. /// Answer to repair weapon item selection dialog
  10159. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10160. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10161. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10162. {
  10163. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10164. return;
  10165. if (pc_istrading(sd)) {
  10166. //Make it fail to avoid shop exploits where you sell something different than you see.
  10167. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10168. clif_menuskill_clear(sd);
  10169. return;
  10170. }
  10171. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10172. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10173. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10174. //for(i = 0; i<MAX_SLOTS; i++)
  10175. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10176. clif_menuskill_clear(sd);
  10177. }
  10178. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10179. /// 0222 <index>.L
  10180. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10181. {
  10182. int idx;
  10183. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10184. return;
  10185. if (pc_istrading(sd)) {
  10186. //Make it fail to avoid shop exploits where you sell something different than you see.
  10187. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10188. clif_menuskill_clear(sd);
  10189. return;
  10190. }
  10191. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10192. skill_weaponrefine(sd, idx-2);
  10193. clif_menuskill_clear(sd);
  10194. }
  10195. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10196. /// 00b8 <npc id>.L <choice>.B
  10197. /// choice:
  10198. /// 1~254 = menu item
  10199. /// 255 = cancel
  10200. /// NOTE: If there were more than 254 items in the list, choice
  10201. /// overflows to choice%256.
  10202. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10203. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10204. int npc_id = RFIFOL(fd,info->pos[0]);
  10205. uint8 select = RFIFOB(fd,info->pos[1]);
  10206. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10207. #ifdef SECURE_NPCTIMEOUT
  10208. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10209. #endif
  10210. TBL_NPC* nd = map_id2nd(npc_id);
  10211. 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);
  10212. clif_GM_kick(NULL,sd);
  10213. #ifdef SECURE_NPCTIMEOUT
  10214. }
  10215. #endif
  10216. return;
  10217. }
  10218. sd->npc_menu = select;
  10219. npc_scriptcont(sd,npc_id, false);
  10220. }
  10221. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10222. /// 00b9 <npc id>.L
  10223. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10224. {
  10225. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10226. }
  10227. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10228. /// 0143 <npc id>.L <value>.L
  10229. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10230. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10231. int npcid = RFIFOL(fd,info->pos[0]);
  10232. int amount = (int)RFIFOL(fd,info->pos[1]);
  10233. sd->npc_amount = amount;
  10234. npc_scriptcont(sd, npcid, false);
  10235. }
  10236. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10237. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10238. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10239. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10240. int message_len = RFIFOW(fd,info->pos[0])-8;
  10241. int npcid = RFIFOL(fd,info->pos[1]);
  10242. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10243. if( message_len <= 0 )
  10244. return; // invalid input
  10245. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10246. npc_scriptcont(sd, npcid, false);
  10247. }
  10248. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10249. /// 0146 <npc id>.L
  10250. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10251. {
  10252. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10253. return;
  10254. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10255. }
  10256. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10257. /// 0178 <index>.W
  10258. /// index:
  10259. /// -1 = cancel
  10260. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10261. {
  10262. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10263. if (sd->menuskill_id != MC_IDENTIFY)
  10264. return;
  10265. if( idx == -1 ) {// cancel pressed
  10266. clif_menuskill_clear(sd);
  10267. return;
  10268. }
  10269. skill_identify(sd,idx-2);
  10270. clif_menuskill_clear(sd);
  10271. }
  10272. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10273. /// 01ae <name id>.W
  10274. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10275. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10276. if (pc_istrading(sd)) {
  10277. //Make it fail to avoid shop exploits where you sell something different than you see.
  10278. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10279. clif_menuskill_clear(sd);
  10280. return;
  10281. }
  10282. switch (sd->menuskill_id) {
  10283. case AC_MAKINGARROW:
  10284. skill_arrow_create(sd,nameid);
  10285. break;
  10286. case SA_CREATECON:
  10287. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10288. break;
  10289. case WL_READING_SB:
  10290. skill_spellbook(sd,nameid);
  10291. break;
  10292. case GC_POISONINGWEAPON:
  10293. skill_poisoningweapon(sd,nameid);
  10294. break;
  10295. case NC_MAGICDECOY:
  10296. skill_magicdecoy(sd,nameid);
  10297. break;
  10298. }
  10299. clif_menuskill_clear(sd);
  10300. }
  10301. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10302. /// 01ce <skill id>.L
  10303. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10304. {
  10305. if (sd->menuskill_id != SA_AUTOSPELL)
  10306. return;
  10307. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10308. clif_menuskill_clear(sd);
  10309. }
  10310. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10311. /// 017a <card index>.W
  10312. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10313. {
  10314. if (sd->state.trading != 0)
  10315. return;
  10316. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10317. }
  10318. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10319. /// 017c <card index>.W <equip index>.W
  10320. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10321. {
  10322. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10323. if (sd->state.trading != 0)
  10324. return;
  10325. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10326. }
  10327. /// Request of character's name by char ID.
  10328. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10329. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10330. /// There are various variants of this packet, some of them have padding between fields.
  10331. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10332. {
  10333. int charid;
  10334. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10335. map_reqnickdb(sd, charid);
  10336. }
  10337. /// /resetskill /resetstate (CZ_RESET).
  10338. /// Request to reset stats or skills.
  10339. /// 0197 <type>.W
  10340. /// type:
  10341. /// 0 = state
  10342. /// 1 = skill
  10343. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10344. char cmd[15];
  10345. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10346. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10347. else
  10348. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10349. is_atcommand(fd, sd, cmd, 1);
  10350. }
  10351. /// /lb /nlb (CZ_LOCALBROADCAST).
  10352. /// Request to broadcast a message on current map.
  10353. /// 019c <packet len>.W <text>.?B
  10354. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10355. {
  10356. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10357. char command[CHAT_SIZE_MAX+16];
  10358. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10359. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10360. // as the length varies depending on the command used, just block unreasonably long strings
  10361. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10362. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10363. is_atcommand(fd, sd, command, 1);
  10364. }
  10365. /// Request to move an item from inventory to storage.
  10366. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10367. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10368. /// There are various variants of this packet, some of them have padding between fields.
  10369. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10370. {
  10371. int item_index, item_amount;
  10372. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10373. if (pc_istrading(sd))
  10374. return;
  10375. item_index = RFIFOW(fd,info->pos[0])-2;
  10376. item_amount = RFIFOL(fd,info->pos[1]);
  10377. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10378. return;
  10379. if (sd->state.storage_flag == 1)
  10380. storage_storageadd(sd, item_index, item_amount);
  10381. else
  10382. if (sd->state.storage_flag == 2)
  10383. gstorage_storageadd(sd, item_index, item_amount);
  10384. }
  10385. /// Request to move an item from storage to inventory.
  10386. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10387. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10388. /// There are various variants of this packet, some of them have padding between fields.
  10389. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10390. {
  10391. int item_index, item_amount;
  10392. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10393. item_index = RFIFOW(fd,info->pos[0])-1;
  10394. item_amount = RFIFOL(fd,info->pos[1]);
  10395. if (sd->state.storage_flag == 1)
  10396. storage_storageget(sd, item_index, item_amount);
  10397. else if(sd->state.storage_flag == 2)
  10398. gstorage_storageget(sd, item_index, item_amount);
  10399. }
  10400. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10401. /// 0129 <index>.W <amount>.L
  10402. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10403. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10404. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10405. int amount = RFIFOL(fd,info->pos[1]);
  10406. if( sd->state.vending )
  10407. return;
  10408. if (!pc_iscarton(sd))
  10409. return;
  10410. if (sd->state.storage_flag == 1)
  10411. storage_storageaddfromcart(sd, idx, amount);
  10412. else if (sd->state.storage_flag == 2)
  10413. gstorage_storageaddfromcart(sd, idx, amount);
  10414. }
  10415. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10416. /// 0128 <index>.W <amount>.L
  10417. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10418. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10419. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10420. int amount = RFIFOL(fd,info->pos[1]);
  10421. if( sd->state.vending )
  10422. return;
  10423. if (!pc_iscarton(sd))
  10424. return;
  10425. if (sd->state.storage_flag == 1)
  10426. storage_storagegettocart(sd, idx, amount);
  10427. else
  10428. if (sd->state.storage_flag == 2)
  10429. gstorage_storagegettocart(sd, idx, amount);
  10430. }
  10431. /// Request to close storage (CZ_CLOSE_STORE).
  10432. /// 00f7
  10433. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10434. {
  10435. if( sd->state.storage_flag == 1 )
  10436. storage_storageclose(sd);
  10437. else
  10438. if( sd->state.storage_flag == 2 )
  10439. gstorage_storageclose(sd);
  10440. }
  10441. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10442. /// 023a <info>.W
  10443. /// info:
  10444. /// 0 = password has not been set yet
  10445. /// 1 = storage is password-protected
  10446. /// 8 = too many wrong passwords
  10447. /// ? = ignored
  10448. /// NOTE: This packet is only available on certain non-kRO clients.
  10449. void clif_storagepassword(struct map_session_data* sd, short info)
  10450. {
  10451. int fd = sd->fd;
  10452. WFIFOHEAD(fd,packet_len(0x23a));
  10453. WFIFOW(fd,0) = 0x23a;
  10454. WFIFOW(fd,2) = info;
  10455. WFIFOSET(fd,packet_len(0x23a));
  10456. }
  10457. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10458. /// 023b <type>.W <password>.16B <new password>.16B
  10459. /// type:
  10460. /// 2 = change password
  10461. /// 3 = check password
  10462. /// NOTE: This packet is only available on certain non-kRO clients.
  10463. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10464. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10465. // int type = RFIFOW(fd,info->pos[0]);
  10466. // char* password = RFIFOP(fd,info->pos[1]);
  10467. // char* new_password = RFIFOP(fd,info->pos[2]);
  10468. // storage_changepass(sd,password,new_password);
  10469. }
  10470. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10471. /// 023c <result>.W <error count>.W
  10472. /// result:
  10473. /// 4 = password change success
  10474. /// 5 = password change failure
  10475. /// 6 = password check success
  10476. /// 7 = password check failure
  10477. /// 8 = too many wrong passwords
  10478. /// ? = ignored
  10479. /// NOTE: This packet is only available on certain non-kRO clients.
  10480. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10481. {
  10482. int fd = sd->fd;
  10483. WFIFOHEAD(fd,packet_len(0x23c));
  10484. WFIFOW(fd,0) = 0x23c;
  10485. WFIFOW(fd,2) = result;
  10486. WFIFOW(fd,4) = error_count;
  10487. WFIFOSET(fd,packet_len(0x23c));
  10488. }
  10489. /// Party creation request
  10490. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10491. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10492. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10493. name[NAME_LENGTH-1] = '\0';
  10494. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10495. clif_displaymessage(fd, msg_txt(sd,227));
  10496. return;
  10497. }
  10498. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10499. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10500. return;
  10501. }
  10502. party_create(sd,name,0,0);
  10503. }
  10504. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10505. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10506. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10507. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10508. int item1 = RFIFOB(fd,info->pos[1]);
  10509. int item2 = RFIFOB(fd,info->pos[2]);
  10510. name[NAME_LENGTH-1] = '\0';
  10511. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10512. clif_displaymessage(fd, msg_txt(sd,227));
  10513. return;
  10514. }
  10515. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10516. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10517. return;
  10518. }
  10519. party_create(sd,name,item1,item2);
  10520. }
  10521. /// Party invitation request
  10522. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10523. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10524. {
  10525. struct map_session_data *t_sd;
  10526. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10527. clif_displaymessage(fd, msg_txt(sd,227));
  10528. return;
  10529. }
  10530. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10531. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10532. clif_noask_sub(sd, t_sd, 1);
  10533. return;
  10534. }
  10535. party_invite(sd, t_sd);
  10536. }
  10537. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10538. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10539. struct map_session_data *t_sd;
  10540. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10541. name[NAME_LENGTH-1] = '\0';
  10542. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10543. clif_displaymessage(fd, msg_txt(sd,227));
  10544. return;
  10545. }
  10546. t_sd = map_nick2sd(name);
  10547. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10548. clif_noask_sub(sd, t_sd, 1);
  10549. return;
  10550. }
  10551. party_invite(sd, t_sd);
  10552. }
  10553. /// Party invitation reply
  10554. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10555. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10556. /// flag:
  10557. /// 0 = reject
  10558. /// 1 = accept
  10559. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10560. {
  10561. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10562. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10563. RFIFOL(fd,info->pos[1]));
  10564. }
  10565. //(CZ_PARTY_JOIN_REQ_ACK)
  10566. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10567. {
  10568. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10569. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10570. RFIFOB(fd,info->pos[1]));
  10571. }
  10572. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10573. /// 0100
  10574. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10575. {
  10576. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10577. clif_displaymessage(fd, msg_txt(sd,227));
  10578. return;
  10579. }
  10580. party_leave(sd);
  10581. }
  10582. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10583. /// 0103 <account id>.L <char name>.24B
  10584. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10585. {
  10586. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10587. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10588. clif_displaymessage(fd, msg_txt(sd,227));
  10589. return;
  10590. }
  10591. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10592. (char*)RFIFOP(fd,info->pos[1]));
  10593. }
  10594. /// Request to change party options.
  10595. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10596. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10597. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10598. {
  10599. struct party_data *p;
  10600. int i,expflag;
  10601. int cmd = RFIFOW(fd,0);
  10602. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10603. if( !sd->status.party_id )
  10604. return;
  10605. p = party_search(sd->status.party_id);
  10606. if( p == NULL )
  10607. return;
  10608. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10609. if( i == MAX_PARTY )
  10610. return; //Shouldn't happen
  10611. if( !p->party.member[i].leader )
  10612. return;
  10613. expflag = RFIFOL(fd,info->pos[0]);
  10614. if(cmd == 0x0102){ //Client can't change the item-field
  10615. party_changeoption(sd, expflag, p->party.item);
  10616. }
  10617. else {
  10618. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10619. party_changeoption(sd, expflag, itemflag);
  10620. }
  10621. }
  10622. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10623. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10624. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10625. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10626. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10627. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10628. char *name, *message;
  10629. int namelen, messagelen;
  10630. // validate packet and retrieve name and message
  10631. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10632. return;
  10633. if( is_atcommand(fd, sd, message, 1) )
  10634. return;
  10635. if (sd->sc.cant.chat)
  10636. return; //no "chatting" while muted.
  10637. if( battle_config.min_chat_delay )
  10638. { //[Skotlex]
  10639. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10640. return;
  10641. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10642. }
  10643. if (battle_config.idletime_option&IDLE_CHAT)
  10644. sd->idletime = last_tick;
  10645. party_send_message(sd, text, textlen);
  10646. }
  10647. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10648. /// 07da <account id>.L
  10649. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10650. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10651. }
  10652. /// Party Booking in KRO [Spiria]
  10653. ///
  10654. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10655. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10656. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10657. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10658. short level = RFIFOW(fd,info->pos[0]);
  10659. short mapid = RFIFOW(fd,info->pos[1]);
  10660. int idxpbj = info->pos[2];
  10661. short job[PARTY_BOOKING_JOBS];
  10662. int i;
  10663. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10664. job[i] = RFIFOB(fd,idxpbj+i*2);
  10665. party_booking_register(sd, level, mapid, job);
  10666. }
  10667. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10668. /// 0803 <result>.W
  10669. /// result:
  10670. /// 0 = success
  10671. /// 1 = failure
  10672. /// 2 = already registered
  10673. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10674. {
  10675. int fd = sd->fd;
  10676. WFIFOHEAD(fd,packet_len(0x803));
  10677. WFIFOW(fd,0) = 0x803;
  10678. WFIFOW(fd,2) = flag;
  10679. WFIFOSET(fd,packet_len(0x803));
  10680. }
  10681. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10682. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10683. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10684. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10685. short level = RFIFOW(fd,info->pos[0]);
  10686. short mapid = RFIFOW(fd,info->pos[1]);
  10687. short job = RFIFOW(fd,info->pos[2]);
  10688. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10689. short resultcount = RFIFOW(fd,info->pos[4]);
  10690. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10691. }
  10692. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10693. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10694. /// more results:
  10695. /// 0 = no
  10696. /// 1 = yes
  10697. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10698. {
  10699. int i, j;
  10700. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10701. struct party_booking_ad_info *pb_ad;
  10702. WFIFOHEAD(fd,size*count + 5);
  10703. WFIFOW(fd,0) = 0x805;
  10704. WFIFOW(fd,2) = size*count + 5;
  10705. WFIFOB(fd,4) = more_result;
  10706. for(i=0; i<count; i++)
  10707. {
  10708. pb_ad = results[i];
  10709. WFIFOL(fd,i*size+5) = pb_ad->index;
  10710. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10711. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10712. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10713. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10714. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10715. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10716. }
  10717. WFIFOSET(fd,WFIFOW(fd,2));
  10718. }
  10719. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10720. /// 0806
  10721. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10722. {
  10723. if(party_booking_delete(sd))
  10724. clif_PartyBookingDeleteAck(sd, 0);
  10725. }
  10726. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10727. /// 0807 <result>.W
  10728. /// result:
  10729. /// 0 = success
  10730. /// 1 = success (auto-removed expired ad)
  10731. /// 2 = failure
  10732. /// 3 = nothing registered
  10733. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10734. {
  10735. int fd = sd->fd;
  10736. WFIFOHEAD(fd,packet_len(0x807));
  10737. WFIFOW(fd,0) = 0x807;
  10738. WFIFOW(fd,2) = flag;
  10739. WFIFOSET(fd,packet_len(0x807));
  10740. }
  10741. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10742. /// 0808 { <job>.W }*6
  10743. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10744. {
  10745. short job[PARTY_BOOKING_JOBS];
  10746. int i;
  10747. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10748. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10749. job[i] = RFIFOW(fd,idxpbu+i*2);
  10750. party_booking_update(sd, job);
  10751. }
  10752. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10753. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10754. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10755. {
  10756. int i;
  10757. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10758. if(pb_ad == NULL) return;
  10759. WBUFW(buf,0) = 0x809;
  10760. WBUFL(buf,2) = pb_ad->index;
  10761. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10762. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10763. WBUFW(buf,34) = pb_ad->p_detail.level;
  10764. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10765. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10766. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10767. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10768. }
  10769. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10770. /// 080a <index>.L { <job>.W }*6
  10771. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10772. {
  10773. int i;
  10774. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10775. if(pb_ad == NULL) return;
  10776. WBUFW(buf,0) = 0x80a;
  10777. WBUFL(buf,2) = pb_ad->index;
  10778. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10779. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10780. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10781. }
  10782. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10783. /// 080b <index>.L
  10784. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10785. {
  10786. uint8 buf[6];
  10787. WBUFW(buf,0) = 0x80b;
  10788. WBUFL(buf,2) = index;
  10789. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10790. }
  10791. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10792. /// 012e
  10793. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10794. {
  10795. vending_closevending(sd);
  10796. }
  10797. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10798. /// 0130 <account id>.L
  10799. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10800. {
  10801. if( sd->npc_id ) {// using an NPC
  10802. return;
  10803. }
  10804. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10805. }
  10806. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10807. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10808. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10809. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10810. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10811. int id = (int)RFIFOL(fd,info->pos[1]);
  10812. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10813. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10814. // whether it fails or not, the buy window is closed
  10815. sd->vended_id = 0;
  10816. }
  10817. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10818. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10819. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10820. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10821. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10822. int aid = (int)RFIFOL(fd,info->pos[1]);
  10823. int uid = (int)RFIFOL(fd,info->pos[2]);
  10824. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10825. vending_purchasereq(sd, aid, uid, data, len/4);
  10826. // whether it fails or not, the buy window is closed
  10827. sd->vended_id = 0;
  10828. }
  10829. /// Confirm or cancel the shop preparation window.
  10830. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10831. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10832. /// result:
  10833. /// 0 = canceled
  10834. /// 1 = open
  10835. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10836. int cmd = RFIFOW(fd,0);
  10837. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10838. short len = (short)RFIFOW(fd,info->pos[0]);
  10839. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10840. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10841. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10842. len -= 84;
  10843. }
  10844. else { //(CZ_REQ_OPENSTORE2)
  10845. bool flag;
  10846. len -= 85;
  10847. flag = (bool)RFIFOB(fd,info->pos[2]);
  10848. if( !flag )
  10849. sd->state.prevend = 0;
  10850. }
  10851. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10852. return;
  10853. if( map[sd->bl.m].flag.novending ) {
  10854. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10855. return;
  10856. }
  10857. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10858. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10859. return;
  10860. }
  10861. if( message[0] == '\0' ) // invalid input
  10862. return;
  10863. vending_openvending(sd, message, data, len/8, NULL);
  10864. }
  10865. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10866. /// 0165 <char id>.L <guild name>.24B
  10867. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10868. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10869. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10870. name[NAME_LENGTH-1] = '\0';
  10871. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10872. clif_displaymessage(fd, msg_txt(sd,228));
  10873. return;
  10874. }
  10875. guild_create(sd, name);
  10876. }
  10877. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10878. /// 014d
  10879. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10880. {
  10881. clif_guild_masterormember(sd);
  10882. }
  10883. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10884. /// 014f <type>.L
  10885. /// type:
  10886. /// 0 = basic info
  10887. /// 1 = member manager
  10888. /// 2 = positions
  10889. /// 3 = skills
  10890. /// 4 = expulsion list
  10891. /// 5 = unknown (GM_ALLGUILDLIST)
  10892. /// 6 = notice
  10893. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10894. {
  10895. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10896. if( !sd->status.guild_id && !sd->bg_id )
  10897. return;
  10898. switch( type )
  10899. {
  10900. case 0: // Basic Information Guild, hostile alliance information
  10901. clif_guild_basicinfo(sd);
  10902. clif_guild_allianceinfo(sd);
  10903. break;
  10904. case 1: // Members list, list job title
  10905. clif_guild_positionnamelist(sd);
  10906. clif_guild_memberlist(sd);
  10907. break;
  10908. case 2: // List job title, title information list
  10909. clif_guild_positionnamelist(sd);
  10910. clif_guild_positioninfolist(sd);
  10911. break;
  10912. case 3: // Skill list
  10913. clif_guild_skillinfo(sd);
  10914. break;
  10915. case 4: // Expulsion list
  10916. clif_guild_expulsionlist(sd);
  10917. break;
  10918. default:
  10919. ShowError("clif: guild request info: unknown type %d\n", type);
  10920. break;
  10921. }
  10922. }
  10923. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10924. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10925. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10926. {
  10927. int i;
  10928. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10929. int len = RFIFOW(fd,info->pos[0]);
  10930. int idxgpos = info->pos[1];
  10931. if(!sd->state.gmaster_flag)
  10932. return;
  10933. for(i = idxgpos; i < len; i += 40 ){
  10934. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10935. }
  10936. }
  10937. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10938. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10939. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10940. {
  10941. int i;
  10942. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10943. int len = RFIFOW(fd,info->pos[0]);
  10944. int idxgpos = info->pos[1];
  10945. if(!sd->state.gmaster_flag)
  10946. return;
  10947. for(i=idxgpos;i<len;i+=12){
  10948. guild_change_memberposition(sd->status.guild_id,
  10949. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10950. }
  10951. }
  10952. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10953. /// 0151 <guild id>.L
  10954. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10955. {
  10956. struct guild* g;
  10957. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10958. if( (g = guild_search(guild_id)) != NULL )
  10959. clif_guild_emblem(sd,g);
  10960. }
  10961. /// Validates data of a guild emblem (compressed bitmap)
  10962. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10963. {
  10964. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10965. unsigned long buf_len = sizeof(buf);
  10966. int offset = 0;
  10967. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10968. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10969. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10970. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10971. ))
  10972. return -1;
  10973. if(battle_config.emblem_transparency_limit != 100) {
  10974. int i, transcount = 1, tmp[3];
  10975. for(i = offset; i < buf_len-1; i++) {
  10976. int j = i%3;
  10977. tmp[j] = RBUFL(buf,i);
  10978. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10979. transcount++;
  10980. }
  10981. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10982. return -2;
  10983. }
  10984. return 0;
  10985. }
  10986. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10987. /// 0153 <packet len>.W <emblem data>.?B
  10988. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10989. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10990. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10991. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10992. int emb_val=0;
  10993. if( !emblem_len || !sd->state.gmaster_flag )
  10994. return;
  10995. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10996. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10997. return;
  10998. }
  10999. emb_val = clif_validate_emblem(emblem, emblem_len);
  11000. if(emb_val ==-1 ){
  11001. 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);
  11002. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11003. return;
  11004. } else if(emb_val == -2){
  11005. char output[128];
  11006. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11007. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11008. return;
  11009. }
  11010. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11011. }
  11012. /// Guild notice update request (CZ_GUILD_NOTICE).
  11013. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11014. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11015. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11016. int guild_id = RFIFOL(fd,info->pos[0]);
  11017. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11018. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11019. if(!sd->state.gmaster_flag)
  11020. return;
  11021. // compensate for some client defects when using multilanguage mode
  11022. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11023. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11024. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11025. guild_change_notice(sd, guild_id, msg1, msg2);
  11026. }
  11027. // Helper function for guild invite functions
  11028. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11029. {
  11030. if (t_sd == NULL) // not online or does not exist
  11031. return 1;
  11032. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11033. clif_displaymessage(fd, msg_txt(sd,228));
  11034. return 1;
  11035. }
  11036. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11037. clif_noask_sub(sd, t_sd, 2);
  11038. return 1;
  11039. }
  11040. guild_invite(sd, t_sd);
  11041. return 0;
  11042. }
  11043. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11044. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11045. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11046. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11047. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11048. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11049. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11050. if (clif_sub_guild_invite(fd, sd, t_sd))
  11051. return;
  11052. }
  11053. /// Guild invite request (/guildinvite)
  11054. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11055. void
  11056. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11057. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11058. if (clif_sub_guild_invite(fd, sd, t_sd))
  11059. return;
  11060. }
  11061. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11062. /// 016b <guild id>.L <answer>.L
  11063. /// answer:
  11064. /// 0 = refuse
  11065. /// 1 = accept
  11066. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11067. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11068. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11069. RFIFOL(fd,info->pos[1]));
  11070. }
  11071. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11072. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11073. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11074. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11075. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11076. clif_displaymessage(fd, msg_txt(sd,228));
  11077. return;
  11078. }
  11079. if( sd->bg_id ) {
  11080. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11081. return;
  11082. }
  11083. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11084. RFIFOL(fd,info->pos[1]),
  11085. RFIFOL(fd,info->pos[2]),
  11086. (char*)RFIFOP(fd,info->pos[3]));
  11087. }
  11088. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11089. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11090. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11091. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11092. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11093. { // Guild locked.
  11094. clif_displaymessage(fd, msg_txt(sd,228));
  11095. return;
  11096. }
  11097. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11098. RFIFOL(fd,info->pos[1]),
  11099. RFIFOL(fd,info->pos[2]),
  11100. (char*)RFIFOP(fd,info->pos[3]));
  11101. }
  11102. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11103. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11104. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11105. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11106. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  11107. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  11108. char *name, *message;
  11109. int namelen, messagelen;
  11110. // validate packet and retrieve name and message
  11111. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11112. return;
  11113. if( is_atcommand(fd, sd, message, 1) )
  11114. return;
  11115. if (sd->sc.cant.chat)
  11116. return; //no "chatting" while muted.
  11117. if( battle_config.min_chat_delay )
  11118. { //[Skotlex]
  11119. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  11120. return;
  11121. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11122. }
  11123. if (battle_config.idletime_option&IDLE_CHAT)
  11124. sd->idletime = last_tick;
  11125. if( sd->bg_id )
  11126. bg_send_message(sd, text, textlen);
  11127. else
  11128. guild_send_message(sd, text, textlen);
  11129. }
  11130. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11131. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11132. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11133. {
  11134. struct map_session_data *t_sd;
  11135. if(!sd->state.gmaster_flag)
  11136. return;
  11137. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11138. clif_displaymessage(fd, msg_txt(sd,228));
  11139. return;
  11140. }
  11141. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11142. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11143. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11144. // @noask [LuzZza]
  11145. if(t_sd && t_sd->state.noask) {
  11146. clif_noask_sub(sd, t_sd, 3);
  11147. return;
  11148. }
  11149. guild_reqalliance(sd,t_sd);
  11150. }
  11151. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11152. /// 0172 <inviter account id>.L <answer>.L
  11153. /// answer:
  11154. /// 0 = refuse
  11155. /// 1 = accept
  11156. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11157. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11158. guild_reply_reqalliance(sd,
  11159. RFIFOL(fd,info->pos[0]),
  11160. RFIFOL(fd,info->pos[1]));
  11161. }
  11162. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11163. /// 0183 <opponent guild id>.L <relation>.L
  11164. /// relation:
  11165. /// 0 = Ally
  11166. /// 1 = Enemy
  11167. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11168. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11169. if(!sd->state.gmaster_flag)
  11170. return;
  11171. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11172. clif_displaymessage(fd, msg_txt(sd,228));
  11173. return;
  11174. }
  11175. guild_delalliance(sd,
  11176. RFIFOL(fd,info->pos[0]),
  11177. RFIFOL(fd,info->pos[1]));
  11178. }
  11179. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11180. /// 0180 <account id>.L
  11181. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11182. {
  11183. struct map_session_data *t_sd;
  11184. if(!sd->state.gmaster_flag)
  11185. return;
  11186. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11187. clif_displaymessage(fd, msg_txt(sd,228));
  11188. return;
  11189. }
  11190. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11191. // @noask [LuzZza]
  11192. if(t_sd && t_sd->state.noask) {
  11193. clif_noask_sub(sd, t_sd, 4);
  11194. return;
  11195. }
  11196. guild_opposition(sd,t_sd);
  11197. }
  11198. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11199. /// 015d <key>.40B
  11200. /// key:
  11201. /// now guild name; might have been (intended) email, since the
  11202. /// field name and size is same as the one in CH_DELETE_CHAR.
  11203. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11204. {
  11205. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11206. clif_displaymessage(fd, msg_txt(sd,228));
  11207. return;
  11208. }
  11209. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11210. }
  11211. /// Pet
  11212. ///
  11213. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11214. /// 01a1 <type>.B
  11215. /// type:
  11216. /// 0 = pet information
  11217. /// 1 = feed
  11218. /// 2 = performance
  11219. /// 3 = return to egg
  11220. /// 4 = unequip accessory
  11221. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11222. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11223. }
  11224. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11225. /// 019f <id>.L
  11226. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11227. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11228. }
  11229. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11230. /// 01a7 <index>.W
  11231. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11232. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11233. return;
  11234. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11235. clif_menuskill_clear(sd);
  11236. }
  11237. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11238. /// 01a9 <data>.L
  11239. /// data:
  11240. /// is either emotion (@see enum emotion_type) or a compound value
  11241. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11242. /// entry (given in parentheses) in data\pettalktable.xml
  11243. /// act id:
  11244. /// 0 = feeding
  11245. /// 1 = hunting
  11246. /// 2 = danger
  11247. /// 3 = dead
  11248. /// 4 = normal (stand)
  11249. /// 5 = special performance (perfor_s)
  11250. /// 6 = level up (levelup)
  11251. /// 7 = performance 1 (perfor_1)
  11252. /// 8 = performance 2 (perfor_2)
  11253. /// 9 = performance 3 (perfor_3)
  11254. /// 10 = log-in greeting (connect)
  11255. /// hungry value:
  11256. /// 0 = very hungry (hungry)
  11257. /// 1 = hungry (bit_hungry)
  11258. /// 2 = satisfied (noting)
  11259. /// 3 = stuffed (full)
  11260. /// 4 = full (so_full)
  11261. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11262. {
  11263. if(sd->pd)
  11264. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11265. }
  11266. /// Request to change pet's name (CZ_RENAME_PET).
  11267. /// 01a5 <name>.24B
  11268. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11269. {
  11270. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11271. }
  11272. /// /kill (CZ_DISCONNECT_CHARACTER).
  11273. /// Request to disconnect a character.
  11274. /// 00cc <account id>.L
  11275. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11276. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11277. {
  11278. struct block_list *target;
  11279. int tid;
  11280. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11281. target = map_id2bl(tid);
  11282. if (!target) {
  11283. clif_GM_kickack(sd, 0);
  11284. return;
  11285. }
  11286. switch (target->type) {
  11287. case BL_PC:
  11288. {
  11289. char command[NAME_LENGTH+6];
  11290. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11291. is_atcommand(fd, sd, command, 1);
  11292. }
  11293. break;
  11294. /**
  11295. * This one does not invoke any atcommand, so we need to check for permissions.
  11296. */
  11297. case BL_MOB:
  11298. {
  11299. char command[100];
  11300. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11301. clif_GM_kickack(sd, 0);
  11302. return;
  11303. }
  11304. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11305. log_atcommand(sd, command);
  11306. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11307. }
  11308. break;
  11309. case BL_NPC:
  11310. {
  11311. struct npc_data* nd = (struct npc_data *)target;
  11312. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11313. npc_unload_duplicates(nd);
  11314. npc_unload(nd,true);
  11315. npc_read_event_script();
  11316. }
  11317. }
  11318. break;
  11319. default:
  11320. clif_GM_kickack(sd, 0);
  11321. }
  11322. }
  11323. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11324. /// Request to disconnect all characters.
  11325. /// 00ce
  11326. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11327. char cmd[15];
  11328. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11329. is_atcommand(fd, sd, cmd, 1);
  11330. }
  11331. /// /remove (CZ_REMOVE_AID).
  11332. /// Request to warp to a character with given login ID.
  11333. /// 01ba <account name>.24B
  11334. /// /shift (CZ_SHIFT).
  11335. /// Request to warp to a character with given name.
  11336. /// 01bb <char name>.24B
  11337. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11338. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11339. char *player_name;
  11340. char command[NAME_LENGTH+8];
  11341. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11342. player_name[NAME_LENGTH-1] = '\0';
  11343. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11344. is_atcommand(fd, sd, command, 1);
  11345. }
  11346. /// /remove (CZ_REMOVE_AID_SSO).
  11347. /// Request to warp to a character with given account ID.
  11348. /// 0843 <account id>.L
  11349. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11350. {
  11351. uint32 account_id;
  11352. struct map_session_data* pl_sd;
  11353. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11354. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11355. char command[NAME_LENGTH+8];
  11356. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11357. is_atcommand(fd, sd, command, 1);
  11358. }
  11359. }
  11360. /// /recall (CZ_RECALL).
  11361. /// Request to summon a player with given login ID to own position.
  11362. /// 01bc <account name>.24B
  11363. /// /summon (CZ_RECALL_GID).
  11364. /// Request to summon a player with given name to own position.
  11365. /// 01bd <char name>.24B
  11366. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11367. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11368. char *player_name;
  11369. char command [NAME_LENGTH+8];
  11370. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11371. player_name[NAME_LENGTH-1] = '\0';
  11372. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11373. is_atcommand(fd, sd, command, 1);
  11374. }
  11375. /// /recall (CZ_RECALL_SSO).
  11376. /// Request to summon a player with given account ID to own position.
  11377. /// 0842 <account id>.L
  11378. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11379. {
  11380. uint32 account_id;
  11381. struct map_session_data* pl_sd;
  11382. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11383. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11384. char command[NAME_LENGTH+8];
  11385. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11386. is_atcommand(fd, sd, command, 1);
  11387. }
  11388. }
  11389. /// /item /monster (CZ_ITEM_CREATE).
  11390. /// Request to execute GM commands.
  11391. /// Usage:
  11392. /// /item n - summon n monster or acquire n item/s
  11393. /// /item money - grants 2147483647 zenies
  11394. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11395. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11396. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11397. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11398. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11399. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11400. /// 013f <item/mob name>.24B
  11401. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11402. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11403. {
  11404. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11405. int mob_id = 0;
  11406. struct item_data *id = NULL;
  11407. struct mob_db *mob = NULL;
  11408. StringBuf command;
  11409. char *str;
  11410. //#if PACKETVER >= 20131218
  11411. // char str[100];
  11412. //#else
  11413. // char str[24];
  11414. //#endif
  11415. str = (char*)RFIFOP(fd,info->pos[0]);
  11416. if (!str || str[0] == '\0')
  11417. return;
  11418. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11419. return;
  11420. trim(str);
  11421. // Zeny
  11422. if( strcmpi(str, "money") == 0 ) {
  11423. StringBuf_Init(&command);
  11424. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11425. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11426. StringBuf_Destroy(&command);
  11427. return;
  11428. }
  11429. // Item
  11430. if( (id = itemdb_searchname(str)) ) {
  11431. StringBuf_Init(&command);
  11432. if( !itemdb_isstackable2(id) ) //Nonstackable
  11433. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11434. else {
  11435. if (id->flag.guid)
  11436. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11437. else
  11438. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11439. }
  11440. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11441. StringBuf_Destroy(&command);
  11442. return;
  11443. }
  11444. // Monster
  11445. if ((mob_id = mobdb_searchname(str)) == 0)
  11446. mob_id = mobdb_checkid(atoi(str));
  11447. if( (mob = mob_db(mob_id)) ) {
  11448. StringBuf_Init(&command);
  11449. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11450. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11451. StringBuf_Destroy(&command);
  11452. return;
  11453. }
  11454. }
  11455. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11456. /// 019d <effect state>.L
  11457. /// effect state:
  11458. /// TODO: Any OPTION_* ?
  11459. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11460. char cmd[6];
  11461. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11462. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11463. is_atcommand(fd, sd, cmd, 1);
  11464. }
  11465. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11466. /// 0149 <account id>.L <type>.B <value>.W
  11467. /// type:
  11468. /// 0 = positive points
  11469. /// 1 = negative points
  11470. /// 2 = self mute (+10 minutes)
  11471. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11472. {
  11473. int id, type, value;
  11474. struct map_session_data *dstsd;
  11475. char command[NAME_LENGTH+15];
  11476. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11477. id = RFIFOL(fd,info->pos[0]);
  11478. type = RFIFOB(fd,info->pos[1]);
  11479. value = RFIFOW(fd,info->pos[2]);
  11480. if( type == 0 )
  11481. value = -value;
  11482. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11483. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11484. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11485. return;
  11486. dstsd = map_id2sd(id);
  11487. if( dstsd == NULL )
  11488. return;
  11489. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11490. is_atcommand(fd, sd, command, 1);
  11491. }
  11492. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11493. /// GM adjustment of a player's manner value by -60.
  11494. /// 0212 <char name>.24B
  11495. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11496. {
  11497. char command[NAME_LENGTH+15];
  11498. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11499. name[NAME_LENGTH-1] = '\0';
  11500. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11501. is_atcommand(fd, sd, command, 1);
  11502. }
  11503. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11504. /// 01e0 <account id>.L <account name>.24B
  11505. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11506. {
  11507. WFIFOHEAD(fd,packet_len(0x1e0));
  11508. WFIFOW(fd,0) = 0x1e0;
  11509. WFIFOL(fd,2) = account_id;
  11510. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11511. WFIFOSET(fd,packet_len(0x1e0));
  11512. }
  11513. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11514. /// 01df <account id>.L
  11515. //! TODO: Figure out how does this actually work
  11516. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11517. {
  11518. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11519. /*
  11520. char query[30];
  11521. safesnprintf(query,sizeof(query),"%d", account_id);
  11522. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11523. */
  11524. clif_account_name(fd, account_id, "");
  11525. }
  11526. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11527. /// GM single cell type change request.
  11528. /// 0198 <x>.W <y>.W <type>.W
  11529. /// type:
  11530. /// 0 = not walkable
  11531. /// 1 = walkable
  11532. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11533. {
  11534. int x,y,type;
  11535. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11536. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11537. return;
  11538. x = RFIFOW(fd,info->pos[0]);
  11539. y = RFIFOW(fd,info->pos[1]);
  11540. type = RFIFOW(fd,info->pos[2]);
  11541. map_setgatcell(sd->bl.m,x,y,type);
  11542. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11543. //FIXME: once players leave the map, the client 'forgets' this information.
  11544. }
  11545. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11546. /// Request to allow/deny whispers from a nick.
  11547. /// 00cf <nick>.24B <type>.B
  11548. /// type:
  11549. /// 0 = (/ex nick) deny speech from nick
  11550. /// 1 = (/in nick) allow speech from nick
  11551. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11552. {
  11553. char* nick;
  11554. uint8 type;
  11555. int i;
  11556. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11557. nick = (char*)RFIFOP(fd,info->pos[0]);
  11558. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11559. type = RFIFOB(fd,info->pos[1]);
  11560. if( type == 0 ) { // Add name to ignore list (block)
  11561. if (strcmp(wisp_server_name, nick) == 0) {
  11562. clif_wisexin(sd, type, 1); // fail
  11563. return;
  11564. }
  11565. // try to find a free spot, while checking for duplicates at the same time
  11566. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11567. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11568. clif_wisexin(sd, type, 2); // too many blocks
  11569. return;
  11570. }
  11571. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11572. clif_wisexin(sd, type, 0); // Aegis reports success.
  11573. return;
  11574. }
  11575. //Insert in position i
  11576. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11577. } else { // Remove name from ignore list (unblock)
  11578. // find entry
  11579. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11580. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11581. clif_wisexin(sd, type, 1); // fail
  11582. return;
  11583. }
  11584. // move everything one place down to overwrite removed entry
  11585. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11586. // wipe last entry
  11587. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11588. }
  11589. clif_wisexin(sd, type, 0); // success
  11590. }
  11591. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11592. /// Request to allow/deny all whispers.
  11593. /// 00d0 <type>.B
  11594. /// type:
  11595. /// 0 = (/exall) deny all speech
  11596. /// 1 = (/inall) allow all speech
  11597. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11598. {
  11599. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11600. if( type == 0 ) {// Deny all
  11601. if( sd->state.ignoreAll ) {
  11602. flag = 1; // fail
  11603. } else {
  11604. sd->state.ignoreAll = 1;
  11605. flag = 0; // success
  11606. }
  11607. } else {//Unblock everyone
  11608. if( sd->state.ignoreAll ) {
  11609. sd->state.ignoreAll = 0;
  11610. flag = 0; // success
  11611. } else {
  11612. if (sd->ignore[0].name[0] != '\0')
  11613. { //Wipe the ignore list.
  11614. memset(sd->ignore, 0, sizeof(sd->ignore));
  11615. flag = 0; // success
  11616. } else {
  11617. flag = 1; // fail
  11618. }
  11619. }
  11620. }
  11621. clif_wisall(sd, type, flag);
  11622. }
  11623. /// Whisper ignore list (ZC_WHISPER_LIST).
  11624. /// 00d4 <packet len>.W { <char name>.24B }*
  11625. void clif_PMIgnoreList(struct map_session_data* sd)
  11626. {
  11627. int i, fd = sd->fd;
  11628. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11629. WFIFOW(fd,0) = 0xd4;
  11630. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11631. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11632. }
  11633. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11634. WFIFOSET(fd,WFIFOW(fd,2));
  11635. }
  11636. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11637. /// 00d3
  11638. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11639. {
  11640. clif_PMIgnoreList(sd);
  11641. }
  11642. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11643. /// 01e7
  11644. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11645. {
  11646. if (sd->state.doridori) return;
  11647. switch (sd->class_&MAPID_UPPERMASK) {
  11648. case MAPID_SOUL_LINKER:
  11649. case MAPID_STAR_GLADIATOR:
  11650. case MAPID_TAEKWON:
  11651. if (!sd->state.rest)
  11652. break;
  11653. case MAPID_SUPER_NOVICE:
  11654. case MAPID_SUPER_BABY:
  11655. case MAPID_SUPER_NOVICE_E:
  11656. case MAPID_SUPER_BABY_E:
  11657. sd->state.doridori=1;
  11658. break;
  11659. }
  11660. }
  11661. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11662. /// 01ed
  11663. /// Note: This packet is caused by 7 lines of any text, followed by
  11664. /// the prayer and an another line of any text. The prayer is
  11665. /// defined by lines 790~793 in data\msgstringtable.txt
  11666. /// "Dear angel, can you hear my voice?"
  11667. /// "I am" (space separated player name) "Super Novice~"
  11668. /// "Help me out~ Please~ T_T"
  11669. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11670. {
  11671. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11672. unsigned int next = pc_nextbaseexp(sd);
  11673. if( next == 0 ) next = pc_thisbaseexp(sd);
  11674. if( next ) {
  11675. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11676. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11677. 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]
  11678. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11679. }
  11680. }
  11681. }
  11682. }
  11683. /// Friends List
  11684. ///
  11685. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11686. /// 0206 <account id>.L <char id>.L <state>.B
  11687. /// state:
  11688. /// 0 = online
  11689. /// 1 = offline
  11690. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11691. {
  11692. int i, fd = sd->fd;
  11693. //Seek friend.
  11694. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11695. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11696. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11697. return; //Not found
  11698. WFIFOHEAD(fd,packet_len(0x206));
  11699. WFIFOW(fd, 0) = 0x206;
  11700. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11701. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11702. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11703. WFIFOSET(fd, packet_len(0x206));
  11704. }
  11705. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11706. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11707. {
  11708. uint32 account_id, char_id, online;
  11709. account_id = va_arg(ap, int);
  11710. char_id = va_arg(ap, int);
  11711. online = va_arg(ap, int);
  11712. clif_friendslist_toggle(sd, account_id, char_id, online);
  11713. return 0;
  11714. }
  11715. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11716. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11717. void clif_friendslist_send(struct map_session_data *sd)
  11718. {
  11719. int i = 0, n, fd = sd->fd;
  11720. // Send friends list
  11721. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11722. WFIFOW(fd, 0) = 0x201;
  11723. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11724. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11725. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11726. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11727. }
  11728. if (i) {
  11729. WFIFOW(fd,2) = 4 + 32 * i;
  11730. WFIFOSET(fd, WFIFOW(fd,2));
  11731. }
  11732. for (n = 0; n < i; n++) { //Sending the online players
  11733. if (map_charid2sd(sd->status.friends[n].char_id))
  11734. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11735. }
  11736. }
  11737. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11738. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11739. /// result:
  11740. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11741. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11742. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11743. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11744. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11745. {
  11746. int fd;
  11747. nullpo_retv(sd);
  11748. fd = sd->fd;
  11749. WFIFOHEAD(fd,packet_len(0x209));
  11750. WFIFOW(fd,0) = 0x209;
  11751. WFIFOW(fd,2) = type;
  11752. if (f_sd) {
  11753. WFIFOL(fd,4) = f_sd->status.account_id;
  11754. WFIFOL(fd,8) = f_sd->status.char_id;
  11755. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11756. }
  11757. WFIFOSET(fd, packet_len(0x209));
  11758. }
  11759. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11760. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11761. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  11762. {
  11763. int fd = sd->fd;
  11764. WFIFOHEAD(fd,packet_len(0x207));
  11765. WFIFOW(fd,0) = 0x207;
  11766. WFIFOL(fd,2) = account_id;
  11767. WFIFOL(fd,6) = char_id;
  11768. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11769. WFIFOSET(fd,packet_len(0x207));
  11770. }
  11771. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11772. /// 0202 <name>.24B
  11773. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11774. {
  11775. struct map_session_data *f_sd;
  11776. int i;
  11777. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11778. // ensure that the request player's friend list is not full
  11779. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11780. if( i == MAX_FRIENDS ) {
  11781. clif_friendslist_reqack(sd, f_sd, 2);
  11782. return;
  11783. }
  11784. // Friend doesn't exist (no player with this name)
  11785. if (f_sd == NULL) {
  11786. clif_displaymessage(fd, msg_txt(sd,3));
  11787. return;
  11788. }
  11789. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11790. return;
  11791. }
  11792. // @noask [LuzZza]
  11793. if(f_sd->state.noask) {
  11794. clif_noask_sub(sd, f_sd, 5);
  11795. return;
  11796. }
  11797. // Friend already exists
  11798. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11799. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11800. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11801. return;
  11802. }
  11803. }
  11804. f_sd->friend_req = sd->status.char_id;
  11805. sd->friend_req = f_sd->status.char_id;
  11806. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11807. }
  11808. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11809. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11810. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11811. /// reply:
  11812. /// 0 = rejected
  11813. /// 1 = accepted
  11814. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11815. {
  11816. struct map_session_data *f_sd;
  11817. uint32 account_id;
  11818. char reply;
  11819. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11820. account_id = RFIFOL(fd,info->pos[0]);
  11821. //char_id = RFIFOL(fd,info->pos[1]);
  11822. if(sd->packet_ver < 6)
  11823. reply = RFIFOB(fd,info->pos[2]);
  11824. else
  11825. reply = RFIFOL(fd,info->pos[2]);
  11826. if( sd->bl.id == account_id ) {// adding oneself as friend
  11827. return;
  11828. }
  11829. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11830. if (f_sd == NULL)
  11831. return;
  11832. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11833. clif_friendslist_reqack(f_sd, sd, 1);
  11834. else {
  11835. int i;
  11836. // Find an empty slot
  11837. for (i = 0; i < MAX_FRIENDS; i++)
  11838. if (f_sd->status.friends[i].char_id == 0)
  11839. break;
  11840. if (i == MAX_FRIENDS) {
  11841. clif_friendslist_reqack(f_sd, sd, 2);
  11842. return;
  11843. }
  11844. f_sd->status.friends[i].account_id = sd->status.account_id;
  11845. f_sd->status.friends[i].char_id = sd->status.char_id;
  11846. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11847. clif_friendslist_reqack(f_sd, sd, 0);
  11848. if (battle_config.friend_auto_add) {
  11849. // Also add f_sd to sd's friendlist.
  11850. for (i = 0; i < MAX_FRIENDS; i++) {
  11851. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11852. return; //No need to add anything.
  11853. if (sd->status.friends[i].char_id == 0)
  11854. break;
  11855. }
  11856. if (i == MAX_FRIENDS) {
  11857. clif_friendslist_reqack(sd, f_sd, 2);
  11858. return;
  11859. }
  11860. sd->status.friends[i].account_id = f_sd->status.account_id;
  11861. sd->status.friends[i].char_id = f_sd->status.char_id;
  11862. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11863. clif_friendslist_reqack(sd, f_sd, 0);
  11864. }
  11865. }
  11866. }
  11867. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11868. /// 0203 <account id>.L <char id>.L
  11869. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11870. {
  11871. struct map_session_data *f_sd = NULL;
  11872. uint32 account_id, char_id;
  11873. int i, j;
  11874. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11875. account_id = RFIFOL(fd,info->pos[0]);
  11876. char_id = RFIFOL(fd,info->pos[1]);
  11877. // Search friend
  11878. for (i = 0; i < MAX_FRIENDS &&
  11879. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11880. if (i == MAX_FRIENDS) {
  11881. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11882. return;
  11883. }
  11884. //remove from friend's list first
  11885. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11886. for (i = 0; i < MAX_FRIENDS &&
  11887. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11888. if (i != MAX_FRIENDS) {
  11889. // move all chars up
  11890. for(j = i + 1; j < MAX_FRIENDS; j++)
  11891. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11892. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11893. //should the guy be notified of some message? we should add it here if so
  11894. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11895. WFIFOW(f_sd->fd,0) = 0x20a;
  11896. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11897. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11898. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11899. }
  11900. } else { //friend not online -- ask char server to delete from his friendlist
  11901. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11902. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11903. return;
  11904. }
  11905. }
  11906. // We can now delete from original requester
  11907. for (i = 0; i < MAX_FRIENDS &&
  11908. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11909. // move all chars up
  11910. for(j = i + 1; j < MAX_FRIENDS; j++)
  11911. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11912. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11913. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11914. WFIFOHEAD(fd,packet_len(0x20a));
  11915. WFIFOW(fd,0) = 0x20a;
  11916. WFIFOL(fd,2) = account_id;
  11917. WFIFOL(fd,6) = char_id;
  11918. WFIFOSET(fd, packet_len(0x20a));
  11919. }
  11920. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11921. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11922. void clif_PVPInfo(struct map_session_data* sd)
  11923. {
  11924. int fd = sd->fd;
  11925. WFIFOHEAD(fd,packet_len(0x210));
  11926. WFIFOW(fd,0) = 0x210;
  11927. WFIFOL(fd,2) = sd->status.char_id;
  11928. WFIFOL(fd,6) = sd->status.account_id;
  11929. WFIFOL(fd,10) = sd->pvp_won; // times won
  11930. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11931. WFIFOL(fd,18) = sd->pvp_point;
  11932. WFIFOSET(fd, packet_len(0x210));
  11933. }
  11934. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11935. /// 020f <char id>.L <account id>.L
  11936. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11937. {
  11938. // TODO: Is there a way to use this on an another player (char/acc id)?
  11939. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11940. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11941. clif_PVPInfo(sd);
  11942. }
  11943. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11944. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11945. void clif_blacksmith(struct map_session_data* sd)
  11946. {
  11947. int i, fd = sd->fd;
  11948. const char* name;
  11949. WFIFOHEAD(fd,packet_len(0x219));
  11950. WFIFOW(fd,0) = 0x219;
  11951. //Packet size limits this list to 10 elements. [Skotlex]
  11952. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11953. if (smith_fame_list[i].id > 0) {
  11954. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11955. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11956. {
  11957. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11958. } else
  11959. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11960. } else
  11961. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11962. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11963. }
  11964. for(;i < 10; i++) { //In case the MAX is less than 10.
  11965. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11966. WFIFOL(fd, 242 + i * 4) = 0;
  11967. }
  11968. WFIFOSET(fd, packet_len(0x219));
  11969. }
  11970. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11971. /// 0217
  11972. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11973. {
  11974. clif_blacksmith(sd);
  11975. }
  11976. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11977. /// 021b <points>.L <total points>.L
  11978. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11979. {
  11980. int fd = sd->fd;
  11981. WFIFOHEAD(fd,packet_len(0x21b));
  11982. WFIFOW(fd,0) = 0x21b;
  11983. WFIFOL(fd,2) = points;
  11984. WFIFOL(fd,6) = sd->status.fame;
  11985. WFIFOSET(fd, packet_len(0x21b));
  11986. }
  11987. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11988. /// 021a { <name>.24B }*10 { <point>.L }*10
  11989. void clif_alchemist(struct map_session_data* sd)
  11990. {
  11991. int i, fd = sd->fd;
  11992. const char* name;
  11993. WFIFOHEAD(fd,packet_len(0x21a));
  11994. WFIFOW(fd,0) = 0x21a;
  11995. //Packet size limits this list to 10 elements. [Skotlex]
  11996. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11997. if (chemist_fame_list[i].id > 0) {
  11998. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11999. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12000. {
  12001. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12002. } else
  12003. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12004. } else
  12005. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12006. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12007. }
  12008. for(;i < 10; i++) { //In case the MAX is less than 10.
  12009. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12010. WFIFOL(fd, 242 + i * 4) = 0;
  12011. }
  12012. WFIFOSET(fd, packet_len(0x21a));
  12013. }
  12014. /// /alchemist (CZ_ALCHEMIST_RANK).
  12015. /// 0218
  12016. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12017. {
  12018. clif_alchemist(sd);
  12019. }
  12020. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12021. /// 021c <points>.L <total points>.L
  12022. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12023. {
  12024. int fd = sd->fd;
  12025. WFIFOHEAD(fd,packet_len(0x21c));
  12026. WFIFOW(fd,0) = 0x21c;
  12027. WFIFOL(fd,2) = points;
  12028. WFIFOL(fd,6) = sd->status.fame;
  12029. WFIFOSET(fd, packet_len(0x21c));
  12030. }
  12031. /// /taekwon list (ZC_TAEKWON_RANK).
  12032. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12033. void clif_taekwon(struct map_session_data* sd)
  12034. {
  12035. int i, fd = sd->fd;
  12036. const char* name;
  12037. WFIFOHEAD(fd,packet_len(0x226));
  12038. WFIFOW(fd,0) = 0x226;
  12039. //Packet size limits this list to 10 elements. [Skotlex]
  12040. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12041. if (taekwon_fame_list[i].id > 0) {
  12042. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12043. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12044. {
  12045. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12046. } else
  12047. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12048. } else
  12049. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12050. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12051. }
  12052. for(;i < 10; i++) { //In case the MAX is less than 10.
  12053. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12054. WFIFOL(fd, 242 + i * 4) = 0;
  12055. }
  12056. WFIFOSET(fd, packet_len(0x226));
  12057. }
  12058. /// /taekwon (CZ_TAEKWON_RANK).
  12059. /// 0225
  12060. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12061. {
  12062. clif_taekwon(sd);
  12063. }
  12064. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12065. /// 0224 <points>.L <total points>.L
  12066. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12067. {
  12068. int fd = sd->fd;
  12069. WFIFOHEAD(fd,packet_len(0x224));
  12070. WFIFOW(fd,0) = 0x224;
  12071. WFIFOL(fd,2) = points;
  12072. WFIFOL(fd,6) = sd->status.fame;
  12073. WFIFOSET(fd, packet_len(0x224));
  12074. }
  12075. /// /pk list (ZC_KILLER_RANK).
  12076. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12077. void clif_ranking_pk(struct map_session_data* sd)
  12078. {
  12079. int i, fd = sd->fd;
  12080. WFIFOHEAD(fd,packet_len(0x238));
  12081. WFIFOW(fd,0) = 0x238;
  12082. for(i=0;i<10;i++){
  12083. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12084. WFIFOL(fd,i*4+242) = 0;
  12085. }
  12086. WFIFOSET(fd, packet_len(0x238));
  12087. }
  12088. /// /pk (CZ_KILLER_RANK).
  12089. /// 0237
  12090. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12091. {
  12092. clif_ranking_pk(sd);
  12093. }
  12094. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12095. /// 0254 <which>.B
  12096. /// which: (unused atm for security purpose)
  12097. /// 0 = sun
  12098. /// 1 = moon
  12099. /// 2 = star
  12100. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12101. {
  12102. int i;
  12103. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12104. if (sd->menuskill_id != SG_FEEL)
  12105. return;
  12106. i = sd->menuskill_val-1;
  12107. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12108. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12109. sd->feel_map[i].m = sd->bl.m;
  12110. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12111. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12112. // clif_misceffect2(&sd->bl, 0x1b0);
  12113. // clif_misceffect2(&sd->bl, 0x21f);
  12114. clif_feel_info(sd, i, 0);
  12115. clif_menuskill_clear(sd);
  12116. }
  12117. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12118. /// 0253 <which>.B
  12119. /// which:
  12120. /// 0 = sun
  12121. /// 1 = moon
  12122. /// 2 = star
  12123. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12124. {
  12125. WFIFOHEAD(fd,packet_len(0x253));
  12126. WFIFOW(fd,0)=0x253;
  12127. WFIFOB(fd,2)=TOB(skill_lv-1);
  12128. WFIFOSET(fd, packet_len(0x253));
  12129. sd->menuskill_id = SG_FEEL;
  12130. sd->menuskill_val = skill_lv;
  12131. }
  12132. /// Request to change homunculus' name (CZ_RENAME_MER).
  12133. /// 0231 <name>.24B
  12134. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12135. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12136. }
  12137. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12138. /// 0234 <id>.L
  12139. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12140. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12141. struct block_list *bl = NULL;
  12142. struct unit_data *ud = NULL;
  12143. if( sd->md && sd->md->bl.id == id )
  12144. bl = &sd->md->bl;
  12145. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12146. bl = &sd->hd->bl; // Moving Homunculus
  12147. else
  12148. return;
  12149. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12150. ud = unit_bl2ud(bl);
  12151. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12152. }
  12153. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12154. /// 0232 <id>.L <position data>.3B
  12155. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12156. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12157. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12158. struct block_list *bl = NULL;
  12159. short x, y;
  12160. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12161. if( sd->md && sd->md->bl.id == id )
  12162. bl = &sd->md->bl; // Moving Mercenary
  12163. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12164. bl = &sd->hd->bl; // Moving Homunculus
  12165. else
  12166. return;
  12167. unit_walktoxy(bl, x, y, 4);
  12168. }
  12169. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12170. /// 0233 <id>.L <target id>.L <action>.B
  12171. /// action:
  12172. /// always 0
  12173. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12174. {
  12175. struct block_list *bl = NULL;
  12176. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12177. int id = RFIFOL(fd,info->pos[0]);
  12178. int target_id = RFIFOL(fd,info->pos[1]);
  12179. int action_type = RFIFOB(fd,info->pos[2]);
  12180. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12181. bl = &sd->hd->bl;
  12182. else if( sd->md && sd->md->bl.id == id )
  12183. bl = &sd->md->bl;
  12184. else return;
  12185. unit_stop_attack(bl);
  12186. unit_attack(bl, target_id, action_type != 0);
  12187. }
  12188. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12189. /// 022d <type>.W <command>.B
  12190. /// type:
  12191. /// always 0
  12192. /// command:
  12193. /// 0 = homunculus information
  12194. /// 1 = feed
  12195. /// 2 = delete
  12196. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12197. { //[orn]
  12198. int cmd = RFIFOW(fd,0);
  12199. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12200. if(!hom_is_active(sd->hd))
  12201. return;
  12202. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12203. }
  12204. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12205. /// 0292
  12206. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12207. {
  12208. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12209. uint8 hp = 100, sp = 100;
  12210. if (item_position < 0) {
  12211. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12212. // HP restored
  12213. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12214. sp = 0;
  12215. }
  12216. else
  12217. return;
  12218. }
  12219. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12220. return;
  12221. if (!status_revive(&sd->bl, hp, sp))
  12222. return;
  12223. if (item_position < 0)
  12224. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12225. else
  12226. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12227. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12228. }
  12229. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12230. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12231. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12232. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12233. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12234. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12235. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12236. void clif_check(int fd, struct map_session_data* pl_sd)
  12237. {
  12238. WFIFOHEAD(fd,packet_len(0x214));
  12239. WFIFOW(fd, 0) = 0x214;
  12240. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12241. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12242. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12243. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12244. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12245. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12246. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12247. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12248. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12249. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12250. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12251. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12252. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12253. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12254. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12255. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12256. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12257. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12258. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12259. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12260. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12261. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12262. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12263. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12264. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12265. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12266. WFIFOSET(fd,packet_len(0x214));
  12267. }
  12268. /// /check (CZ_REQ_STATUS_GM).
  12269. /// Request character's status values.
  12270. /// 0213 <char name>.24B
  12271. void clif_parse_Check(int fd, struct map_session_data *sd)
  12272. {
  12273. char charname[NAME_LENGTH];
  12274. struct map_session_data* pl_sd;
  12275. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12276. return;
  12277. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12278. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12279. {
  12280. return;
  12281. }
  12282. clif_check(fd, pl_sd);
  12283. }
  12284. /// MAIL SYSTEM
  12285. /// By Zephyrus
  12286. ///
  12287. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12288. /// 0255 <index>.W <result>.B
  12289. /// result:
  12290. /// 0 = success
  12291. /// 1 = failure
  12292. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12293. {
  12294. WFIFOHEAD(fd,packet_len(0x255));
  12295. WFIFOW(fd,0) = 0x255;
  12296. WFIFOW(fd,2) = index;
  12297. WFIFOB(fd,4) = flag;
  12298. WFIFOSET(fd,packet_len(0x255));
  12299. }
  12300. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12301. /// 0245 <result>.B
  12302. /// result:
  12303. /// 0 = success
  12304. /// 1 = failure
  12305. /// 2 = too many items
  12306. void clif_Mail_getattachment(int fd, uint8 flag)
  12307. {
  12308. WFIFOHEAD(fd,packet_len(0x245));
  12309. WFIFOW(fd,0) = 0x245;
  12310. WFIFOB(fd,2) = flag;
  12311. WFIFOSET(fd,packet_len(0x245));
  12312. }
  12313. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12314. /// 0249 <result>.B
  12315. /// result:
  12316. /// 0 = success
  12317. /// 1 = recipinent does not exist
  12318. void clif_Mail_send(int fd, bool fail)
  12319. {
  12320. WFIFOHEAD(fd,packet_len(0x249));
  12321. WFIFOW(fd,0) = 0x249;
  12322. WFIFOB(fd,2) = fail;
  12323. WFIFOSET(fd,packet_len(0x249));
  12324. }
  12325. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12326. /// 0257 <mail id>.L <result>.W
  12327. /// result:
  12328. /// 0 = success
  12329. /// 1 = failure
  12330. void clif_Mail_delete(int fd, int mail_id, short fail)
  12331. {
  12332. WFIFOHEAD(fd, packet_len(0x257));
  12333. WFIFOW(fd,0) = 0x257;
  12334. WFIFOL(fd,2) = mail_id;
  12335. WFIFOW(fd,6) = fail;
  12336. WFIFOSET(fd, packet_len(0x257));
  12337. }
  12338. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12339. /// 0274 <mail id>.L <result>.W
  12340. /// result:
  12341. /// 0 = success
  12342. /// 1 = failure
  12343. void clif_Mail_return(int fd, int mail_id, short fail)
  12344. {
  12345. WFIFOHEAD(fd,packet_len(0x274));
  12346. WFIFOW(fd,0) = 0x274;
  12347. WFIFOL(fd,2) = mail_id;
  12348. WFIFOW(fd,6) = fail;
  12349. WFIFOSET(fd,packet_len(0x274));
  12350. }
  12351. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12352. /// 024a <mail id>.L <title>.40B <sender>.24B
  12353. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12354. {
  12355. WFIFOHEAD(fd,packet_len(0x24a));
  12356. WFIFOW(fd,0) = 0x24a;
  12357. WFIFOL(fd,2) = mail_id;
  12358. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12359. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12360. WFIFOSET(fd,packet_len(0x24a));
  12361. }
  12362. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12363. /// 0260 <type>.L
  12364. /// type:
  12365. /// 0 = open
  12366. /// 1 = close
  12367. void clif_Mail_window(int fd, int flag)
  12368. {
  12369. WFIFOHEAD(fd,packet_len(0x260));
  12370. WFIFOW(fd,0) = 0x260;
  12371. WFIFOL(fd,2) = flag;
  12372. WFIFOSET(fd,packet_len(0x260));
  12373. }
  12374. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12375. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12376. /// read:
  12377. /// 0 = unread
  12378. /// 1 = read
  12379. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12380. {
  12381. int fd = sd->fd;
  12382. struct mail_data *md = &sd->mail.inbox;
  12383. struct mail_message *msg;
  12384. int len, i, j;
  12385. len = 8 + (73 * md->amount);
  12386. WFIFOHEAD(fd,len);
  12387. WFIFOW(fd,0) = 0x240;
  12388. WFIFOW(fd,2) = len;
  12389. WFIFOL(fd,4) = md->amount;
  12390. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12391. {
  12392. msg = &md->msg[i];
  12393. if (msg->id < 1)
  12394. continue;
  12395. WFIFOL(fd,8+73*j) = msg->id;
  12396. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12397. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12398. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12399. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12400. j++;
  12401. }
  12402. WFIFOSET(fd,len);
  12403. if( md->full ) {// TODO: is this official?
  12404. char output[100];
  12405. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12406. clif_disp_onlyself(sd, output, strlen(output));
  12407. }
  12408. }
  12409. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12410. /// 023f
  12411. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12412. {
  12413. struct mail_data* md = &sd->mail.inbox;
  12414. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12415. intif_Mail_requestinbox(sd->status.char_id, 1);
  12416. else
  12417. clif_Mail_refreshinbox(sd);
  12418. mail_removeitem(sd, 0);
  12419. mail_removezeny(sd, 0);
  12420. }
  12421. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12422. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12423. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12424. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12425. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12426. {
  12427. int i, fd = sd->fd;
  12428. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12429. if( i == MAIL_MAX_INBOX ) {
  12430. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12431. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12432. return;
  12433. } else {
  12434. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12435. struct item *item = &msg->item;
  12436. struct item_data *data;
  12437. int msg_len = strlen(msg->body), len;
  12438. if( msg_len == 0 ) {
  12439. strcpy(msg->body, "(no message)");
  12440. msg_len = strlen(msg->body);
  12441. }
  12442. len = 101 + msg_len;
  12443. WFIFOHEAD(fd,len);
  12444. WFIFOW(fd,0) = 0x242;
  12445. WFIFOW(fd,2) = len;
  12446. WFIFOL(fd,4) = msg->id;
  12447. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12448. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12449. WFIFOL(fd,72) = 0;
  12450. WFIFOL(fd,76) = msg->zeny;
  12451. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12452. WFIFOL(fd,80) = item->amount;
  12453. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12454. WFIFOW(fd,86) = data->type;
  12455. WFIFOB(fd,88) = item->identify;
  12456. WFIFOB(fd,89) = item->attribute;
  12457. WFIFOB(fd,90) = item->refine;
  12458. WFIFOW(fd,91) = item->card[0];
  12459. WFIFOW(fd,93) = item->card[1];
  12460. WFIFOW(fd,95) = item->card[2];
  12461. WFIFOW(fd,97) = item->card[3];
  12462. } else // no item, set all to zero
  12463. memset(WFIFOP(fd,80), 0x00, 19);
  12464. WFIFOB(fd,99) = (unsigned char)msg_len;
  12465. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12466. WFIFOSET(fd,len);
  12467. if (msg->status == MAIL_UNREAD) {
  12468. msg->status = MAIL_READ;
  12469. intif_Mail_read(mail_id);
  12470. clif_parse_Mail_refreshinbox(fd, sd);
  12471. }
  12472. }
  12473. }
  12474. /// Request to open a mail (CZ_MAIL_OPEN).
  12475. /// 0241 <mail id>.L
  12476. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12477. {
  12478. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12479. if( mail_id <= 0 )
  12480. return;
  12481. if( mail_invalid_operation(sd) )
  12482. return;
  12483. clif_Mail_read(sd, mail_id);
  12484. }
  12485. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12486. /// 0244 <mail id>.L
  12487. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12488. {
  12489. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12490. int i;
  12491. bool fail = false;
  12492. if( !chrif_isconnected() )
  12493. return;
  12494. if( mail_id <= 0 )
  12495. return;
  12496. if( mail_invalid_operation(sd) )
  12497. return;
  12498. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12499. if( i == MAIL_MAX_INBOX )
  12500. return;
  12501. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12502. return;
  12503. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12504. clif_Mail_getattachment(fd, 1);
  12505. return;
  12506. }
  12507. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12508. struct item_data *data;
  12509. unsigned int weight;
  12510. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12511. return;
  12512. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12513. case CHKADDITEM_NEW:
  12514. fail = ( pc_inventoryblank(sd) == 0 );
  12515. break;
  12516. case CHKADDITEM_OVERAMOUNT:
  12517. fail = true;
  12518. }
  12519. if( fail ) {
  12520. clif_Mail_getattachment(fd, 1);
  12521. return;
  12522. }
  12523. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12524. if( sd->weight + weight > sd->max_weight ) {
  12525. clif_Mail_getattachment(fd, 2);
  12526. return;
  12527. }
  12528. }
  12529. sd->mail.inbox.msg[i].zeny = 0;
  12530. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12531. clif_Mail_read(sd, mail_id);
  12532. intif_Mail_getattach(sd->status.char_id, mail_id);
  12533. }
  12534. /// Request to delete a mail (CZ_MAIL_DELETE).
  12535. /// 0243 <mail id>.L
  12536. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12537. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12538. int i;
  12539. if( !chrif_isconnected() )
  12540. return;
  12541. if( mail_id <= 0 )
  12542. return;
  12543. if( mail_invalid_operation(sd) )
  12544. return;
  12545. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12546. if (i < MAIL_MAX_INBOX) {
  12547. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12548. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12549. clif_Mail_delete(sd->fd, mail_id, 1);
  12550. return;
  12551. }
  12552. intif_Mail_delete(sd->status.char_id, mail_id);
  12553. }
  12554. }
  12555. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12556. /// 0273 <mail id>.L <receive name>.24B
  12557. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12558. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12559. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12560. int i;
  12561. if( mail_id <= 0 )
  12562. return;
  12563. if( mail_invalid_operation(sd) )
  12564. return;
  12565. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12566. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12567. intif_Mail_return(sd->status.char_id, mail_id);
  12568. else
  12569. clif_Mail_return(sd->fd, mail_id, 1);
  12570. }
  12571. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12572. /// 0247 <index>.W <amount>.L
  12573. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12574. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12575. int idx = RFIFOW(fd,info->pos[0]);
  12576. int amount = RFIFOL(fd,info->pos[1]);
  12577. unsigned char flag;
  12578. if( !chrif_isconnected() )
  12579. return;
  12580. if (idx < 0 || amount < 0)
  12581. return;
  12582. flag = mail_setitem(sd, idx, amount);
  12583. clif_Mail_setattachment(fd,idx,!flag);
  12584. }
  12585. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12586. /// 0246 <type>.W
  12587. /// type:
  12588. /// 0 = reset all
  12589. /// 1 = remove item
  12590. /// 2 = remove zeny
  12591. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12592. {
  12593. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12594. if (type == 0 || type == 1)
  12595. mail_removeitem(sd, 0);
  12596. if (type == 0 || type == 2)
  12597. mail_removezeny(sd, 0);
  12598. }
  12599. /// Request to send mail (CZ_MAIL_SEND).
  12600. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12601. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12602. {
  12603. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12604. if( !chrif_isconnected() )
  12605. return;
  12606. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12607. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12608. return;
  12609. }
  12610. 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]));
  12611. }
  12612. /// AUCTION SYSTEM
  12613. /// By Zephyrus
  12614. ///
  12615. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12616. /// 025f <type>.L
  12617. /// type:
  12618. /// 0 = open
  12619. /// 1 = close
  12620. void clif_Auction_openwindow(struct map_session_data *sd)
  12621. {
  12622. int fd = sd->fd;
  12623. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12624. return;
  12625. if( !battle_config.feature_auction )
  12626. return;
  12627. WFIFOHEAD(fd,packet_len(0x25f));
  12628. WFIFOW(fd,0) = 0x25f;
  12629. WFIFOL(fd,2) = 0;
  12630. WFIFOSET(fd,packet_len(0x25f));
  12631. }
  12632. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12633. /// 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 }*
  12634. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12635. {
  12636. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12637. struct auction_data auction;
  12638. struct item_data *item;
  12639. WFIFOHEAD(fd,12 + (count * 83));
  12640. WFIFOW(fd,0) = 0x252;
  12641. WFIFOW(fd,2) = 12 + (count * 83);
  12642. WFIFOL(fd,4) = pages;
  12643. WFIFOL(fd,8) = count;
  12644. for( i = 0; i < count; i++ ) {
  12645. int k = 12 + (i * 83);
  12646. memcpy(&auction, RBUFP(buf,i * len), len);
  12647. WFIFOL(fd,k) = auction.auction_id;
  12648. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12649. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12650. WFIFOW(fd,28+k) = item->view_id;
  12651. else
  12652. WFIFOW(fd,28+k) = auction.item.nameid;
  12653. WFIFOL(fd,30+k) = auction.type;
  12654. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12655. WFIFOB(fd,36+k) = auction.item.identify;
  12656. WFIFOB(fd,37+k) = auction.item.attribute;
  12657. WFIFOB(fd,38+k) = auction.item.refine;
  12658. WFIFOW(fd,39+k) = auction.item.card[0];
  12659. WFIFOW(fd,41+k) = auction.item.card[1];
  12660. WFIFOW(fd,43+k) = auction.item.card[2];
  12661. WFIFOW(fd,45+k) = auction.item.card[3];
  12662. WFIFOL(fd,47+k) = auction.price;
  12663. WFIFOL(fd,51+k) = auction.buynow;
  12664. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12665. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12666. }
  12667. WFIFOSET(fd,WFIFOW(fd,2));
  12668. }
  12669. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12670. /// 0256 <index>.W <result>.B
  12671. /// result:
  12672. /// 0 = success
  12673. /// 1 = failure
  12674. static void clif_Auction_setitem(int fd, int index, bool fail)
  12675. {
  12676. WFIFOHEAD(fd,packet_len(0x256));
  12677. WFIFOW(fd,0) = 0x256;
  12678. WFIFOW(fd,2) = index;
  12679. WFIFOB(fd,4) = fail;
  12680. WFIFOSET(fd,packet_len(0x256));
  12681. }
  12682. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12683. /// 024b <type>.W
  12684. /// type:
  12685. /// 0 = create (any other action in auction window)
  12686. /// 1 = cancel (cancel pressed on register tab)
  12687. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12688. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12689. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12690. if( sd->auction.amount > 0 )
  12691. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12692. sd->auction.amount = 0;
  12693. }
  12694. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12695. /// 024c <index>.W <count>.L
  12696. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12697. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12698. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12699. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12700. struct item_data *item;
  12701. if( !battle_config.feature_auction )
  12702. return;
  12703. if( sd->auction.amount > 0 )
  12704. sd->auction.amount = 0;
  12705. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12706. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12707. return;
  12708. }
  12709. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12710. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12711. return;
  12712. }
  12713. 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) )
  12714. { // Consumable or pets are not allowed
  12715. clif_Auction_setitem(sd->fd, idx, true);
  12716. return;
  12717. }
  12718. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12719. !sd->status.inventory[idx].identify ||
  12720. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12721. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12722. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12723. ) {
  12724. clif_Auction_setitem(sd->fd, idx, true);
  12725. return;
  12726. }
  12727. sd->auction.index = idx;
  12728. sd->auction.amount = amount;
  12729. clif_Auction_setitem(fd, idx + 2, false);
  12730. }
  12731. /// Result from an auction action (ZC_AUCTION_RESULT).
  12732. /// 0250 <result>.B
  12733. /// result:
  12734. /// 0 = You have failed to bid into the auction
  12735. /// 1 = You have successfully bid in the auction
  12736. /// 2 = The auction has been canceled
  12737. /// 3 = An auction with at least one bidder cannot be canceled
  12738. /// 4 = You cannot register more than 5 items in an auction at a time
  12739. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12740. /// 6 = You have won the auction
  12741. /// 7 = You have failed to win the auction
  12742. /// 8 = You do not have enough Zeny
  12743. /// 9 = You cannot place more than 5 bids at a time
  12744. void clif_Auction_message(int fd, unsigned char flag)
  12745. {
  12746. WFIFOHEAD(fd,packet_len(0x250));
  12747. WFIFOW(fd,0) = 0x250;
  12748. WFIFOB(fd,2) = flag;
  12749. WFIFOSET(fd,packet_len(0x250));
  12750. }
  12751. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12752. /// 025e <result>.W
  12753. /// result:
  12754. /// 0 = You have ended the auction
  12755. /// 1 = You cannot end the auction
  12756. /// 2 = Auction ID is incorrect
  12757. void clif_Auction_close(int fd, unsigned char flag)
  12758. {
  12759. WFIFOHEAD(fd,packet_len(0x25e));
  12760. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12761. WFIFOW(fd,2) = flag;
  12762. WFIFOSET(fd,packet_len(0x25e));
  12763. }
  12764. /// Request to add an auction (CZ_AUCTION_ADD).
  12765. /// 024d <now money>.L <max money>.L <delete hour>.W
  12766. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12767. {
  12768. struct auction_data auction;
  12769. struct item_data *item;
  12770. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12771. if( !battle_config.feature_auction )
  12772. return;
  12773. auction.price = RFIFOL(fd,info->pos[0]);
  12774. auction.buynow = RFIFOL(fd,info->pos[1]);
  12775. auction.hours = RFIFOW(fd,info->pos[2]);
  12776. // Invalid Situations...
  12777. if( sd->auction.amount < 1 ) {
  12778. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12779. return;
  12780. }
  12781. if( auction.price >= auction.buynow ) {
  12782. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12783. return;
  12784. }
  12785. if( auction.hours < 1 || auction.hours > 48 ) {
  12786. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12787. return;
  12788. }
  12789. // Auction checks...
  12790. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12791. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12792. clif_Auction_message(fd, 2); // The auction has been canceled
  12793. return;
  12794. }
  12795. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12796. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12797. return;
  12798. }
  12799. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12800. auction.buynow = battle_config.auction_maximumprice;
  12801. if( auction.price >= auction.buynow )
  12802. auction.price = auction.buynow - 1;
  12803. }
  12804. auction.auction_id = 0;
  12805. auction.seller_id = sd->status.char_id;
  12806. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12807. auction.buyer_id = 0;
  12808. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12809. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12810. {
  12811. clif_Auction_message(fd, 2); // The auction has been canceled
  12812. return;
  12813. }
  12814. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12815. { // Just in case
  12816. clif_Auction_message(fd, 2); // The auction has been canceled
  12817. return;
  12818. }
  12819. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12820. auction.type = item->type;
  12821. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12822. auction.item.amount = 1;
  12823. auction.timestamp = 0;
  12824. if( !intif_Auction_register(&auction) )
  12825. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12826. else
  12827. {
  12828. int zeny = auction.hours*battle_config.auction_feeperhour;
  12829. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12830. sd->auction.amount = 0;
  12831. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12832. }
  12833. }
  12834. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12835. /// 024e <auction id>.L
  12836. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12837. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12838. intif_Auction_cancel(sd->status.char_id, auction_id);
  12839. }
  12840. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12841. /// 025d <auction id>.L
  12842. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12843. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12844. intif_Auction_close(sd->status.char_id, auction_id);
  12845. }
  12846. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12847. /// 024f <auction id>.L <money>.L
  12848. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12849. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12850. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12851. int bid = RFIFOL(fd,info->pos[1]);
  12852. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12853. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12854. return;
  12855. }
  12856. if( bid <= 0 )
  12857. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12858. else if( bid > sd->status.zeny )
  12859. clif_Auction_message(fd, 8); // You do not have enough zeny
  12860. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12861. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12862. else {
  12863. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12864. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12865. }
  12866. }
  12867. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12868. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12869. /// search type:
  12870. /// 0 = armor
  12871. /// 1 = weapon
  12872. /// 2 = card
  12873. /// 3 = misc
  12874. /// 4 = name search
  12875. /// 5 = auction id search
  12876. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12877. char search_text[NAME_LENGTH];
  12878. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12879. short type = RFIFOW(fd,info->pos[0]);
  12880. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12881. int page = RFIFOW(fd,info->pos[3]);
  12882. if( !battle_config.feature_auction )
  12883. return;
  12884. clif_parse_Auction_cancelreg(fd, sd);
  12885. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12886. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12887. }
  12888. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12889. /// 025c <type>.W
  12890. /// type:
  12891. /// 0 = sell (own auctions)
  12892. /// 1 = buy (own bids)
  12893. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12894. {
  12895. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12896. if( !battle_config.feature_auction )
  12897. return;
  12898. clif_parse_Auction_cancelreg(fd, sd);
  12899. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12900. }
  12901. /// CASH/POINT SHOP
  12902. ///
  12903. void clif_cashshop_open( struct map_session_data* sd ){
  12904. WFIFOHEAD( sd->fd, 10 );
  12905. WFIFOW( sd->fd, 0 ) = 0x845;
  12906. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12907. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12908. WFIFOSET( sd->fd, 10 );
  12909. }
  12910. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12911. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12912. clif_cashshop_open( sd );
  12913. }
  12914. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12915. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12916. // No need to do anything here
  12917. }
  12918. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12919. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12920. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12921. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12922. int j;
  12923. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12924. return;
  12925. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12926. WFIFOW(fd, 0) = 0x8c0;
  12927. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12928. WFIFOL(fd, 4) = tab;
  12929. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12930. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12931. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  12932. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  12933. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12934. }
  12935. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12936. }
  12937. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12938. void clif_cashshop_list( int fd ){
  12939. int tab;
  12940. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12941. int length = 8 + cash_shop_items[tab].count * 6;
  12942. int i, offset;
  12943. WFIFOHEAD( fd, length );
  12944. WFIFOW( fd, 0 ) = 0x8ca;
  12945. WFIFOW( fd, 2 ) = length;
  12946. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12947. WFIFOW( fd, 6 ) = tab;
  12948. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12949. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  12950. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  12951. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12952. }
  12953. WFIFOSET( fd, length );
  12954. }
  12955. }
  12956. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12957. if( !sd->status.cashshop_sent ) {
  12958. clif_cashshop_list( fd );
  12959. sd->status.cashshop_sent = true;
  12960. }
  12961. }
  12962. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12963. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12964. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12965. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12966. {
  12967. int fd,i;
  12968. #if PACKETVER < 20070711
  12969. const int offset = 8;
  12970. #else
  12971. const int offset = 12;
  12972. #endif
  12973. nullpo_retv(sd);
  12974. nullpo_retv(nd);
  12975. fd = sd->fd;
  12976. sd->npc_shopid = nd->bl.id;
  12977. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12978. WFIFOW(fd,0) = 0x287;
  12979. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12980. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12981. #if PACKETVER >= 20070711
  12982. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12983. #endif
  12984. for( i = 0; i < nd->u.shop.count; i++ ) {
  12985. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12986. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12987. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12988. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12989. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12990. }
  12991. WFIFOSET(fd,WFIFOW(fd,2));
  12992. }
  12993. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12994. /// 0289 <cash point>.L <error>.W
  12995. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12996. /// error:
  12997. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12998. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12999. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13000. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13001. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13002. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13003. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13004. /// 7 = You can purchase up to 10 items.
  13005. /// 8 = Some items could not be purchased.
  13006. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13007. {
  13008. int fd = sd->fd;
  13009. WFIFOHEAD(fd, packet_len(0x289));
  13010. WFIFOW(fd,0) = 0x289;
  13011. WFIFOL(fd,2) = sd->cashPoints;
  13012. #if PACKETVER < 20070711
  13013. WFIFOW(fd,6) = TOW(error);
  13014. #else
  13015. WFIFOL(fd,6) = sd->kafraPoints;
  13016. WFIFOW(fd,10) = TOW(error);
  13017. #endif
  13018. WFIFOSET(fd, packet_len(0x289));
  13019. }
  13020. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13021. WFIFOHEAD( sd->fd, 16 );
  13022. WFIFOW( sd->fd, 0 ) = 0x849;
  13023. WFIFOL( sd->fd, 2 ) = item_id;
  13024. WFIFOW( sd->fd, 6 ) = result;
  13025. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13026. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13027. WFIFOSET( sd->fd, 16 );
  13028. }
  13029. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13030. /// 0288 <name id>.W <amount>.W
  13031. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13032. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13033. /// 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)
  13034. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  13035. struct s_packet_db* info;
  13036. int cmd = RFIFOW(fd,0);
  13037. nullpo_retv(sd);
  13038. info = &packet_db[sd->packet_ver][cmd];
  13039. if( sd->state.trading || !sd->npc_shopid || !cash_shop_defined) {
  13040. clif_cashshop_ack(sd,1);
  13041. return;
  13042. } else {
  13043. #if PACKETVER < 20101116
  13044. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  13045. short amount = RFIFOW(fd,info->pos[1]);
  13046. int points = RFIFOL(fd,info->pos[2]);
  13047. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13048. #else
  13049. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13050. int len = RFIFOW(fd,info->pos[0]);
  13051. int points = RFIFOL(fd,info->pos[1]);
  13052. int count = RFIFOW(fd,info->pos[2]);
  13053. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13054. if( len < 10 || len != 10 + count * s_itl) {
  13055. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13056. return;
  13057. }
  13058. if(cmd == 0x848) {
  13059. if (cashshop_buylist( sd, points, count, item_list))
  13060. clif_cashshop_ack(sd,0);
  13061. return;
  13062. } else {
  13063. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13064. return;
  13065. }
  13066. #endif
  13067. }
  13068. }
  13069. /// Adoption System
  13070. ///
  13071. /// Adoption message (ZC_BABYMSG).
  13072. /// 0216 <msg>.L
  13073. /// msg:
  13074. /// 0 = "You cannot adopt more than 1 child."
  13075. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13076. /// 2 = "You cannot adopt a married person."
  13077. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13078. {
  13079. int fd = sd->fd;
  13080. WFIFOHEAD(fd,6);
  13081. WFIFOW(fd,0) = 0x216;
  13082. WFIFOL(fd,2) = type;
  13083. WFIFOSET(fd,6);
  13084. }
  13085. /// Adoption confirmation (ZC_REQ_BABY).
  13086. /// 01f6 <account id>.L <char id>.L <name>.B
  13087. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13088. {
  13089. int fd = sd->fd;
  13090. WFIFOHEAD(fd,34);
  13091. WFIFOW(fd,0) = 0x1f6;
  13092. WFIFOL(fd,2) = src->status.account_id;
  13093. WFIFOL(fd,6) = p_id;
  13094. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13095. WFIFOSET(fd,34);
  13096. }
  13097. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13098. /// 01f9 <account id>.L
  13099. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13100. {
  13101. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13102. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13103. if( pc_can_Adopt(sd, p_sd, tsd) )
  13104. {
  13105. tsd->adopt_invite = sd->status.account_id;
  13106. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13107. }
  13108. }
  13109. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13110. /// 01f7 <account id>.L <char id>.L <answer>.L
  13111. /// answer:
  13112. /// 0 = rejected
  13113. /// 1 = accepted
  13114. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13115. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13116. int p1_id = RFIFOL(fd,info->pos[0]);
  13117. int p2_id = RFIFOL(fd,info->pos[1]);
  13118. int result = RFIFOL(fd,info->pos[2]);
  13119. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13120. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13121. int pid = sd->adopt_invite;
  13122. sd->adopt_invite = 0;
  13123. if( p1_sd == NULL || p2_sd == NULL )
  13124. return; // Both players need to be online
  13125. if( pid != p1_sd->status.account_id )
  13126. return; // Incorrect values
  13127. if( result == 0 )
  13128. return; // Rejected
  13129. pc_adoption(p1_sd, p2_sd, sd);
  13130. }
  13131. /// Convex Mirror (ZC_BOSS_INFO).
  13132. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13133. /// infoType:
  13134. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13135. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13136. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13137. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13138. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13139. {
  13140. WFIFOHEAD(fd,70);
  13141. memset(WFIFOP(fd,0),0,70);
  13142. WFIFOW(fd,0) = 0x293;
  13143. if( md != NULL ) {
  13144. if( md->bl.prev != NULL ) { // Boss on This Map
  13145. if( flag ) {
  13146. WFIFOB(fd,2) = 1;
  13147. WFIFOL(fd,3) = md->bl.x;
  13148. WFIFOL(fd,7) = md->bl.y;
  13149. } else
  13150. WFIFOB(fd,2) = 2; // First Time
  13151. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13152. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13153. unsigned int seconds;
  13154. int hours, minutes;
  13155. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13156. hours = seconds / (60 * 60);
  13157. seconds = seconds - (60 * 60 * hours);
  13158. minutes = seconds / 60;
  13159. WFIFOB(fd,2) = 3;
  13160. WFIFOW(fd,11) = hours; // Hours
  13161. WFIFOW(fd,13) = minutes; // Minutes
  13162. }
  13163. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13164. }
  13165. WFIFOSET(fd,70);
  13166. }
  13167. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13168. /// 02d6 <account id>.L
  13169. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13170. {
  13171. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13172. struct map_session_data* tsd = map_id2sd(aid);
  13173. if (!tsd)
  13174. return;
  13175. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13176. clif_viewequip_ack(sd, tsd);
  13177. else
  13178. clif_msg(sd, VIEW_EQUIP_FAIL);
  13179. }
  13180. /// Request to change equip window tick (CZ_CONFIG).
  13181. /// 02d8 <type>.L <flag>.L
  13182. /// type:
  13183. /// 0 = open equip window
  13184. /// flag:
  13185. /// 0 = disabled
  13186. /// 1 = enabled
  13187. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13188. {
  13189. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13190. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13191. sd->status.show_equip = flag;
  13192. clif_equiptickack(sd, flag);
  13193. }
  13194. /// Request to change party invitation tick.
  13195. /// value:
  13196. /// 0 = disabled
  13197. /// 1 = enabled
  13198. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13199. {
  13200. bool flag = RFIFOB(fd,6) ? true : false;
  13201. sd->status.allow_party = flag;
  13202. clif_partytickack(sd, flag);
  13203. }
  13204. /// Questlog System [Kevin] [Inkfish]
  13205. ///
  13206. /**
  13207. * Safe check to init packet len & quest num for player.
  13208. * @param def_len
  13209. * @param info_len Length of each quest info.
  13210. * @param avail_quests Avail quests that player has.
  13211. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13212. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13213. **/
  13214. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13215. (*limit_out) = (0xFFFF - def_len) / info_len;
  13216. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13217. (*len_out) = ((*limit_out) * info_len) + def_len;
  13218. }
  13219. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13220. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13221. /// 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
  13222. void clif_quest_send_list(struct map_session_data *sd)
  13223. {
  13224. int fd = sd->fd;
  13225. int i;
  13226. int offset = 8;
  13227. int limit = 0;
  13228. #if PACKETVER >= 20141022
  13229. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13230. WFIFOHEAD(fd,i);
  13231. WFIFOW(fd, 0) = 0x97a;
  13232. WFIFOL(fd, 4) = limit;
  13233. for (i = 0; i < limit; i++) {
  13234. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13235. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13236. offset += 4;
  13237. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13238. offset++;
  13239. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13240. offset += 4;
  13241. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13242. offset += 4;
  13243. WFIFOW(fd, offset) = qi->objectives_count;
  13244. offset += 2;
  13245. if( qi->objectives_count > 0 ){
  13246. int j;
  13247. struct mob_db *mob;
  13248. for( j = 0; j < qi->objectives_count; j++ ){
  13249. mob = mob_db(qi->objectives[j].mob);
  13250. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13251. offset += 4;
  13252. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13253. offset += 2;
  13254. WFIFOW(fd, offset) = qi->objectives[j].count;
  13255. offset += 2;
  13256. memcpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13257. offset += NAME_LENGTH;
  13258. }
  13259. }
  13260. }
  13261. WFIFOW(fd, 2) = offset;
  13262. WFIFOSET(fd, offset);
  13263. #else
  13264. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13265. WFIFOHEAD(fd,i);
  13266. WFIFOW(fd, 0) = 0x2b1;
  13267. WFIFOL(fd, 4) = limit;
  13268. for (i = 0; i < limit; i++) {
  13269. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13270. offset += 4;
  13271. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13272. offset += 1;
  13273. }
  13274. WFIFOW(fd, 2) = offset;
  13275. WFIFOSET(fd, offset);
  13276. #endif
  13277. }
  13278. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13279. /// 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
  13280. void clif_quest_send_mission(struct map_session_data *sd)
  13281. {
  13282. int fd = sd->fd;
  13283. int i, j, limit = 0;
  13284. int len = sd->avail_quests*104+8;
  13285. struct mob_db *mob;
  13286. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13287. WFIFOHEAD(fd, len);
  13288. WFIFOW(fd, 0) = 0x2b2;
  13289. WFIFOW(fd, 2) = len;
  13290. WFIFOL(fd, 4) = limit;
  13291. for (i = 0; i < limit; i++) {
  13292. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13293. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13294. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13295. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13296. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13297. for (j = 0 ; j < qi->objectives_count; j++) {
  13298. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13299. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13300. mob = mob_db(qi->objectives[j].mob);
  13301. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13302. }
  13303. }
  13304. WFIFOSET(fd, len);
  13305. }
  13306. /// Notification about a new quest (ZC_ADD_QUEST).
  13307. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13308. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13309. {
  13310. int fd = sd->fd;
  13311. int i;
  13312. struct quest_db *qi = quest_search(qd->quest_id);
  13313. WFIFOHEAD(fd, packet_len(0x2b3));
  13314. WFIFOW(fd, 0) = 0x2b3;
  13315. WFIFOL(fd, 2) = qd->quest_id;
  13316. WFIFOB(fd, 6) = qd->state;
  13317. WFIFOB(fd, 7) = qd->time - qi->time;
  13318. WFIFOL(fd, 11) = qd->time;
  13319. WFIFOW(fd, 15) = qi->objectives_count;
  13320. for (i = 0; i < qi->objectives_count; i++) {
  13321. struct mob_db *mob;
  13322. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13323. WFIFOW(fd, i*30+21) = qd->count[i];
  13324. mob = mob_db(qi->objectives[i].mob);
  13325. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13326. }
  13327. WFIFOSET(fd, packet_len(0x2b3));
  13328. }
  13329. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13330. /// 02b4 <quest id>.L
  13331. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13332. {
  13333. int fd = sd->fd;
  13334. WFIFOHEAD(fd, packet_len(0x2b4));
  13335. WFIFOW(fd, 0) = 0x2b4;
  13336. WFIFOL(fd, 2) = quest_id;
  13337. WFIFOSET(fd, packet_len(0x2b4));
  13338. }
  13339. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13340. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13341. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  13342. {
  13343. int fd = sd->fd;
  13344. int i;
  13345. struct quest_db *qi = quest_search(qd->quest_id);
  13346. int len = qi->objectives_count * 12 + 6;
  13347. WFIFOHEAD(fd, len);
  13348. WFIFOW(fd, 0) = 0x2b5;
  13349. WFIFOW(fd, 2) = len;
  13350. WFIFOW(fd, 4) = qi->objectives_count;
  13351. for (i = 0; i < qi->objectives_count; i++) {
  13352. WFIFOL(fd, i*12+6) = qd->quest_id;
  13353. WFIFOL(fd, i*12+10) = qi->objectives[i].mob;
  13354. WFIFOW(fd, i*12+14) = qi->objectives[i].count;
  13355. WFIFOW(fd, i*12+16) = qd->count[i];
  13356. }
  13357. WFIFOSET(fd, len);
  13358. }
  13359. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13360. /// 02b6 <quest id>.L <active>.B
  13361. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13362. {
  13363. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13364. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13365. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13366. }
  13367. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13368. /// 02b7 <quest id>.L <active>.B
  13369. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13370. {
  13371. int fd = sd->fd;
  13372. WFIFOHEAD(fd, packet_len(0x2b7));
  13373. WFIFOW(fd, 0) = 0x2b7;
  13374. WFIFOL(fd, 2) = quest_id;
  13375. WFIFOB(fd, 6) = active;
  13376. WFIFOSET(fd, packet_len(0x2b7));
  13377. }
  13378. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13379. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13380. /// effect:
  13381. /// 0 = none
  13382. /// 1 = exclamation mark icon
  13383. /// 2 = question mark icon
  13384. /// type:
  13385. /// 0 = yellow
  13386. /// 1 = orange
  13387. /// 2 = green
  13388. /// 3 = purple
  13389. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13390. {
  13391. #if PACKETVER >= 20090218
  13392. int fd = sd->fd;
  13393. WFIFOHEAD(fd, packet_len(0x446));
  13394. WFIFOW(fd, 0) = 0x446;
  13395. WFIFOL(fd, 2) = bl->id;
  13396. WFIFOW(fd, 6) = bl->x;
  13397. WFIFOW(fd, 8) = bl->y;
  13398. WFIFOW(fd, 10) = state;
  13399. WFIFOW(fd, 12) = color;
  13400. WFIFOSET(fd, packet_len(0x446));
  13401. #endif
  13402. }
  13403. /// Mercenary System
  13404. ///
  13405. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13406. /// 02a2 <var id>.W <value>.L
  13407. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13408. {
  13409. struct mercenary_data *md;
  13410. struct status_data *status;
  13411. int fd;
  13412. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13413. return;
  13414. fd = sd->fd;
  13415. status = &md->battle_status;
  13416. WFIFOHEAD(fd,packet_len(0x2a2));
  13417. WFIFOW(fd,0) = 0x2a2;
  13418. WFIFOW(fd,2) = type;
  13419. switch( type ) {
  13420. case SP_ATK1:
  13421. {
  13422. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13423. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13424. }
  13425. break;
  13426. case SP_MATK1:
  13427. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13428. break;
  13429. case SP_HIT:
  13430. WFIFOL(fd,4) = status->hit;
  13431. break;
  13432. case SP_CRITICAL:
  13433. WFIFOL(fd,4) = status->cri/10;
  13434. break;
  13435. case SP_DEF1:
  13436. WFIFOL(fd,4) = status->def;
  13437. break;
  13438. case SP_MDEF1:
  13439. WFIFOL(fd,4) = status->mdef;
  13440. break;
  13441. case SP_MERCFLEE:
  13442. WFIFOL(fd,4) = status->flee;
  13443. break;
  13444. case SP_ASPD:
  13445. WFIFOL(fd,4) = status->amotion;
  13446. break;
  13447. case SP_HP:
  13448. WFIFOL(fd,4) = status->hp;
  13449. break;
  13450. case SP_MAXHP:
  13451. WFIFOL(fd,4) = status->max_hp;
  13452. break;
  13453. case SP_SP:
  13454. WFIFOL(fd,4) = status->sp;
  13455. break;
  13456. case SP_MAXSP:
  13457. WFIFOL(fd,4) = status->max_sp;
  13458. break;
  13459. case SP_MERCKILLS:
  13460. WFIFOL(fd,4) = md->mercenary.kill_count;
  13461. break;
  13462. case SP_MERCFAITH:
  13463. WFIFOL(fd,4) = mercenary_get_faith(md);
  13464. break;
  13465. }
  13466. WFIFOSET(fd,packet_len(0x2a2));
  13467. }
  13468. /// Mercenary base status data (ZC_MER_INIT).
  13469. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13470. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13471. /// <calls>.L <kills>.L <atk range>.W
  13472. void clif_mercenary_info(struct map_session_data *sd)
  13473. {
  13474. int fd;
  13475. struct mercenary_data *md;
  13476. struct status_data *status;
  13477. int atk;
  13478. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13479. return;
  13480. fd = sd->fd;
  13481. status = &md->battle_status;
  13482. WFIFOHEAD(fd,packet_len(0x29b));
  13483. WFIFOW(fd,0) = 0x29b;
  13484. WFIFOL(fd,2) = md->bl.id;
  13485. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13486. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13487. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13488. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13489. WFIFOW(fd,10) = status->hit;
  13490. WFIFOW(fd,12) = status->cri/10;
  13491. WFIFOW(fd,14) = status->def;
  13492. WFIFOW(fd,16) = status->mdef;
  13493. WFIFOW(fd,18) = status->flee;
  13494. WFIFOW(fd,20) = status->amotion;
  13495. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13496. WFIFOW(fd,46) = md->db->lv;
  13497. WFIFOL(fd,48) = status->hp;
  13498. WFIFOL(fd,52) = status->max_hp;
  13499. WFIFOL(fd,56) = status->sp;
  13500. WFIFOL(fd,60) = status->max_sp;
  13501. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13502. WFIFOW(fd,68) = mercenary_get_faith(md);
  13503. WFIFOL(fd,70) = mercenary_get_calls(md);
  13504. WFIFOL(fd,74) = md->mercenary.kill_count;
  13505. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13506. WFIFOSET(fd,packet_len(0x29b));
  13507. }
  13508. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13509. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13510. void clif_mercenary_skillblock(struct map_session_data *sd)
  13511. {
  13512. struct mercenary_data *md;
  13513. int fd, i, len = 4;
  13514. if( sd == NULL || (md = sd->md) == NULL )
  13515. return;
  13516. fd = sd->fd;
  13517. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13518. WFIFOW(fd,0) = 0x29d;
  13519. for( i = 0; i < MAX_MERCSKILL; i++ )
  13520. {
  13521. uint16 id;
  13522. short idx = -1;
  13523. if( (id = md->db->skill[i].id) == 0 )
  13524. continue;
  13525. if ((idx = mercenary_skill_get_index(id)) == -1)
  13526. continue;
  13527. WFIFOW(fd,len) = id;
  13528. WFIFOL(fd,len+2) = skill_get_inf(id);
  13529. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13530. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13531. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv);
  13532. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13533. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13534. len += 37;
  13535. }
  13536. WFIFOW(fd,2) = len;
  13537. WFIFOSET(fd,len);
  13538. }
  13539. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13540. /// 029f <command>.B
  13541. /// 1 = mercenary information
  13542. /// 2 = delete
  13543. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13544. {
  13545. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13546. if( sd->md == NULL )
  13547. return;
  13548. if( option == 2 ) mercenary_delete(sd->md, 2);
  13549. }
  13550. /// Mercenary Message
  13551. /// message:
  13552. /// 0 = Mercenary soldier's duty hour is over.
  13553. /// 1 = Your mercenary soldier has been killed.
  13554. /// 2 = Your mercenary soldier has been fired.
  13555. /// 3 = Your mercenary soldier has ran away.
  13556. void clif_mercenary_message(struct map_session_data* sd, int message){
  13557. clif_msg(sd, MERC_MSG_BASE + message);
  13558. }
  13559. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13560. /// 0298 <name id>.W <seconds>.L
  13561. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13562. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13563. WFIFOHEAD(fd,packet_len(0x298));
  13564. WFIFOW(fd,0) = 0x298;
  13565. WFIFOW(fd,2) = nameid;
  13566. WFIFOL(fd,4) = seconds;
  13567. WFIFOSET(fd,packet_len(0x298));
  13568. }
  13569. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13570. /// 0299 <index>.W <name id>.W
  13571. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13572. { // '<ItemName>' item has been deleted from the Inventory
  13573. WFIFOHEAD(fd,packet_len(0x299));
  13574. WFIFOW(fd,0) = 0x299;
  13575. WFIFOW(fd,2) = index+2;
  13576. WFIFOW(fd,4) = nameid;
  13577. WFIFOSET(fd,packet_len(0x299));
  13578. }
  13579. /// Book Reading (ZC_READ_BOOK).
  13580. /// 0294 <book id>.L <page>.L
  13581. void clif_readbook(int fd, int book_id, int page)
  13582. {
  13583. WFIFOHEAD(fd,packet_len(0x294));
  13584. WFIFOW(fd,0) = 0x294;
  13585. WFIFOL(fd,2) = book_id;
  13586. WFIFOL(fd,6) = page;
  13587. WFIFOSET(fd,packet_len(0x294));
  13588. }
  13589. /// Battlegrounds
  13590. ///
  13591. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13592. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13593. void clif_bg_hp(struct map_session_data *sd)
  13594. {
  13595. unsigned char buf[34];
  13596. const int cmd = 0x2e0;
  13597. nullpo_retv(sd);
  13598. WBUFW(buf,0) = cmd;
  13599. WBUFL(buf,2) = sd->status.account_id;
  13600. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13601. if( sd->battle_status.max_hp > INT16_MAX )
  13602. { // To correctly display the %hp bar. [Skotlex]
  13603. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13604. WBUFW(buf,32) = 100;
  13605. }
  13606. else
  13607. {
  13608. WBUFW(buf,30) = sd->battle_status.hp;
  13609. WBUFW(buf,32) = sd->battle_status.max_hp;
  13610. }
  13611. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13612. }
  13613. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13614. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13615. void clif_bg_xy(struct map_session_data *sd)
  13616. {
  13617. unsigned char buf[36];
  13618. nullpo_retv(sd);
  13619. WBUFW(buf,0)=0x2df;
  13620. WBUFL(buf,2)=sd->status.account_id;
  13621. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13622. WBUFW(buf,30)=sd->status.class_;
  13623. WBUFW(buf,32)=sd->bl.x;
  13624. WBUFW(buf,34)=sd->bl.y;
  13625. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13626. }
  13627. void clif_bg_xy_remove(struct map_session_data *sd)
  13628. {
  13629. unsigned char buf[36];
  13630. nullpo_retv(sd);
  13631. WBUFW(buf,0)=0x2df;
  13632. WBUFL(buf,2)=sd->status.account_id;
  13633. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13634. WBUFW(buf,30)=0;
  13635. WBUFW(buf,32)=-1;
  13636. WBUFW(buf,34)=-1;
  13637. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13638. }
  13639. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13640. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13641. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13642. {
  13643. struct map_session_data *sd;
  13644. unsigned char *buf;
  13645. if( (sd = bg_getavailablesd(bg)) == NULL )
  13646. return;
  13647. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13648. WBUFW(buf,0) = 0x2dc;
  13649. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13650. WBUFL(buf,4) = src_id;
  13651. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13652. memcpy(WBUFP(buf,32), mes, len);
  13653. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13654. if( buf )
  13655. aFree(buf);
  13656. }
  13657. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13658. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13659. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13660. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13661. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13662. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13663. char *name, *message;
  13664. int namelen, messagelen;
  13665. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13666. return;
  13667. if( is_atcommand(fd, sd, message, 1) )
  13668. return;
  13669. if (sd->sc.cant.chat)
  13670. return; //no "chatting" while muted.
  13671. if( battle_config.min_chat_delay ) {
  13672. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13673. return;
  13674. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13675. }
  13676. if (battle_config.idletime_option&IDLE_CHAT)
  13677. sd->idletime = last_tick;
  13678. bg_send_message(sd, text, textlen);
  13679. }
  13680. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13681. /// 02de <camp A points>.W <camp B points>.W
  13682. void clif_bg_updatescore(int16 m)
  13683. {
  13684. struct block_list bl;
  13685. unsigned char buf[6];
  13686. bl.id = 0;
  13687. bl.type = BL_NUL;
  13688. bl.m = m;
  13689. WBUFW(buf,0) = 0x2de;
  13690. WBUFW(buf,2) = map[m].bgscore_lion;
  13691. WBUFW(buf,4) = map[m].bgscore_eagle;
  13692. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13693. }
  13694. void clif_bg_updatescore_single(struct map_session_data *sd)
  13695. {
  13696. int fd;
  13697. nullpo_retv(sd);
  13698. fd = sd->fd;
  13699. WFIFOHEAD(fd,packet_len(0x2de));
  13700. WFIFOW(fd,0) = 0x2de;
  13701. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13702. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13703. WFIFOSET(fd,packet_len(0x2de));
  13704. }
  13705. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13706. /// 02dd <account id>.L <name>.24B <camp>.W
  13707. void clif_sendbgemblem_area(struct map_session_data *sd)
  13708. {
  13709. unsigned char buf[33];
  13710. nullpo_retv(sd);
  13711. WBUFW(buf, 0) = 0x2dd;
  13712. WBUFL(buf,2) = sd->bl.id;
  13713. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13714. WBUFW(buf,30) = sd->bg_id;
  13715. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13716. }
  13717. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13718. {
  13719. nullpo_retv(sd);
  13720. WFIFOHEAD(fd,32);
  13721. WFIFOW(fd,0) = 0x2dd;
  13722. WFIFOL(fd,2) = sd->bl.id;
  13723. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13724. WFIFOW(fd,30) = sd->bg_id;
  13725. WFIFOSET(fd,packet_len(0x2dd));
  13726. }
  13727. /// Custom Fonts (ZC_NOTIFY_FONT).
  13728. /// 02ef <account_id>.L <font id>.W
  13729. void clif_font(struct map_session_data *sd)
  13730. {
  13731. #if PACKETVER >= 20080102
  13732. unsigned char buf[8];
  13733. nullpo_retv(sd);
  13734. WBUFW(buf,0) = 0x2ef;
  13735. WBUFL(buf,2) = sd->bl.id;
  13736. WBUFW(buf,6) = sd->status.font;
  13737. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13738. #endif
  13739. }
  13740. /*==========================================
  13741. * Notifies party members of instance change
  13742. *------------------------------------------*/
  13743. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13744. {
  13745. #if PACKETVER >= 20071128
  13746. unsigned char buf[65];
  13747. if(!sd) return;
  13748. WBUFW(buf,0) = 0x2cb;
  13749. memcpy( WBUFP(buf,2), name, 62 );
  13750. WBUFW(buf,63) = num;
  13751. if(flag) // A timer has changed or been added
  13752. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13753. else // No notification
  13754. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13755. #endif
  13756. return;
  13757. }
  13758. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13759. {
  13760. #if PACKETVER >= 20071128
  13761. unsigned char buf[4];
  13762. if(!sd) return;
  13763. WBUFW(buf,0) = 0x2cc;
  13764. WBUFW(buf,2) = num;
  13765. if(flag) // A timer has changed or been added
  13766. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13767. else // No notification
  13768. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13769. #endif
  13770. return;
  13771. }
  13772. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13773. {
  13774. #if PACKETVER >= 20071128
  13775. unsigned char buf[71];
  13776. if(!sd) return; //party_getavailablesd can return NULL
  13777. WBUFW(buf,0) = 0x2cd;
  13778. memcpy( WBUFP(buf,2), name, 62 );
  13779. WBUFL(buf,63) = limit1;
  13780. WBUFL(buf,67) = limit2;
  13781. if(flag) // A timer has changed or been added
  13782. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13783. else // No notification
  13784. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13785. #endif
  13786. return;
  13787. }
  13788. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13789. {
  13790. #if PACKETVER >= 20071128
  13791. unsigned char buf[10];
  13792. if(!sd) return;
  13793. WBUFW(buf,0) = 0x2ce;
  13794. WBUFL(buf,2) = type;
  13795. WBUFL(buf,6) = limit;
  13796. if(flag) // A timer has changed or been added
  13797. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13798. else // No notification
  13799. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13800. #endif
  13801. return;
  13802. }
  13803. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13804. /// 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
  13805. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13806. {
  13807. #if PACKETVER >= 20071002
  13808. unsigned char buf[22];
  13809. struct item_data* id = itemdb_search(item_data->nameid);
  13810. WBUFW(buf,0) = 0x2b8;
  13811. WBUFL(buf,2) = sd->status.account_id;
  13812. WBUFW(buf,6) = item_data->nameid;
  13813. WBUFB(buf,8) = item_data->identify;
  13814. WBUFB(buf,9) = item_data->attribute;
  13815. WBUFB(buf,10) = item_data->refine;
  13816. clif_addcards(WBUFP(buf,11), item_data);
  13817. WBUFW(buf,19) = id->equip; // equip location
  13818. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13819. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13820. #endif
  13821. }
  13822. /// Display gained exp (ZC_NOTIFY_EXP).
  13823. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13824. /// var id:
  13825. /// SP_BASEEXP, SP_JOBEXP
  13826. /// exp type:
  13827. /// 0 = normal exp gain/loss
  13828. /// 1 = quest exp gain/loss
  13829. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13830. {
  13831. int fd;
  13832. nullpo_retv(sd);
  13833. fd = sd->fd;
  13834. WFIFOHEAD(fd, packet_len(0x7f6));
  13835. WFIFOW(fd,0) = 0x7f6;
  13836. WFIFOL(fd,2) = sd->bl.id;
  13837. WFIFOL(fd,6) = exp;
  13838. WFIFOW(fd,10) = type;
  13839. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13840. WFIFOSET(fd,packet_len(0x7f6));
  13841. }
  13842. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13843. /// type:
  13844. /// 0 = Displays 'value' for 5 seconds.
  13845. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13846. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13847. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13848. /// value:
  13849. /// 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).
  13850. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13851. {
  13852. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13853. WFIFOW(sd->fd,0) = 0x1b1;
  13854. WFIFOB(sd->fd,2) = type;
  13855. WFIFOL(sd->fd,3) = value;
  13856. WFIFOSET(sd->fd, packet_len(0x1b1));
  13857. }
  13858. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13859. /// 021d <state>.L
  13860. /// state:
  13861. /// 0 = Full effects
  13862. /// 1 = Reduced effects
  13863. ///
  13864. /// NOTE: The state is used on Aegis for sending skill unit packet
  13865. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13866. /// whenever possible. Due to the way the decision check is
  13867. /// constructed, this state tracking was rendered useless,
  13868. /// as the only skill unit, that is sent with 0x1c9 is
  13869. /// Graffiti.
  13870. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13871. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13872. sd->state.lesseffect = ( isLess != 0 );
  13873. }
  13874. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  13875. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  13876. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  13877. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13878. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13879. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13880. int type = RFIFOL(fd,info->pos[1]);
  13881. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13882. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13883. if( sd->state.trading || sd->npc_shopid )
  13884. return;
  13885. if( flag == 0 || n == 0) {
  13886. clif_menuskill_clear(sd);
  13887. return; // Canceled by player.
  13888. }
  13889. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13890. clif_menuskill_clear(sd);
  13891. return; // Prevent hacking.
  13892. }
  13893. switch( type ) {
  13894. case 0: // Change Material
  13895. skill_changematerial(sd,n,item_list);
  13896. break;
  13897. case 1: // Level 1: Pure to Rough
  13898. case 2: // Level 2: Rough to Pure
  13899. skill_elementalanalysis(sd,n,type,item_list);
  13900. break;
  13901. }
  13902. clif_menuskill_clear(sd);
  13903. return;
  13904. }
  13905. /*==========================================
  13906. * Elemental System
  13907. *==========================================*/
  13908. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13909. struct elemental_data *ed;
  13910. struct status_data *status;
  13911. int fd;
  13912. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  13913. return;
  13914. fd = sd->fd;
  13915. status = &ed->battle_status;
  13916. WFIFOHEAD(fd,8);
  13917. WFIFOW(fd,0) = 0x81e;
  13918. WFIFOW(fd,2) = type;
  13919. switch( type ) {
  13920. case SP_HP:
  13921. WFIFOL(fd,4) = status->hp;
  13922. break;
  13923. case SP_MAXHP:
  13924. WFIFOL(fd,4) = status->max_hp;
  13925. break;
  13926. case SP_SP:
  13927. WFIFOL(fd,4) = status->sp;
  13928. break;
  13929. case SP_MAXSP:
  13930. WFIFOL(fd,4) = status->max_sp;
  13931. break;
  13932. }
  13933. WFIFOSET(fd,8);
  13934. }
  13935. void clif_elemental_info(struct map_session_data *sd) {
  13936. int fd;
  13937. struct elemental_data *ed;
  13938. struct status_data *status;
  13939. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  13940. return;
  13941. fd = sd->fd;
  13942. status = &ed->battle_status;
  13943. WFIFOHEAD(fd,22);
  13944. WFIFOW(fd, 0) = 0x81d;
  13945. WFIFOL(fd, 2) = ed->bl.id;
  13946. WFIFOL(fd, 6) = status->hp;
  13947. WFIFOL(fd,10) = status->max_hp;
  13948. WFIFOL(fd,14) = status->sp;
  13949. WFIFOL(fd,18) = status->max_sp;
  13950. WFIFOSET(fd,22);
  13951. }
  13952. /// Buying Store System
  13953. ///
  13954. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13955. /// 0810 <slots>.B
  13956. void clif_buyingstore_open(struct map_session_data* sd)
  13957. {
  13958. int fd = sd->fd;
  13959. WFIFOHEAD(fd,packet_len(0x810));
  13960. WFIFOW(fd,0) = 0x810;
  13961. WFIFOB(fd,2) = sd->buyingstore.slots;
  13962. WFIFOSET(fd,packet_len(0x810));
  13963. }
  13964. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13965. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13966. /// result:
  13967. /// 0 = cancel
  13968. /// 1 = open
  13969. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13970. {
  13971. const unsigned int blocksize = 8;
  13972. uint8* itemlist;
  13973. char storename[MESSAGE_SIZE];
  13974. unsigned char result;
  13975. int zenylimit;
  13976. unsigned int count, packet_len;
  13977. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13978. packet_len = RFIFOW(fd,info->pos[0]);
  13979. // TODO: Make this check global for all variable length packets.
  13980. if( packet_len < 89 )
  13981. {// minimum packet length
  13982. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13983. return;
  13984. }
  13985. zenylimit = RFIFOL(fd,info->pos[1]);
  13986. result = RFIFOL(fd,info->pos[2]);
  13987. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13988. itemlist = RFIFOP(fd,info->pos[4]);
  13989. // so that buyingstore_create knows, how many elements it has access to
  13990. packet_len-= info->pos[4];
  13991. if( packet_len%blocksize )
  13992. {
  13993. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13994. return;
  13995. }
  13996. count = packet_len/blocksize;
  13997. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  13998. }
  13999. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14000. /// 0812 <result>.W <total weight>.L
  14001. /// result:
  14002. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14003. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14004. /// 8 = "No sale (purchase) information available." (0x705)
  14005. /// ? = nothing
  14006. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14007. {
  14008. int fd = sd->fd;
  14009. WFIFOHEAD(fd,packet_len(0x812));
  14010. WFIFOW(fd,0) = 0x812;
  14011. WFIFOW(fd,2) = result;
  14012. WFIFOL(fd,4) = weight;
  14013. WFIFOSET(fd,packet_len(0x812));
  14014. }
  14015. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14016. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14017. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14018. {
  14019. int fd = sd->fd;
  14020. unsigned int i;
  14021. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14022. WFIFOW(fd,0) = 0x813;
  14023. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14024. WFIFOL(fd,4) = sd->bl.id;
  14025. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14026. for( i = 0; i < sd->buyingstore.slots; i++ )
  14027. {
  14028. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14029. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14030. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14031. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14032. }
  14033. WFIFOSET(fd,WFIFOW(fd,2));
  14034. }
  14035. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14036. /// 0814 <account id>.L <store name>.80B
  14037. void clif_buyingstore_entry(struct map_session_data* sd)
  14038. {
  14039. uint8 buf[86];
  14040. WBUFW(buf,0) = 0x814;
  14041. WBUFL(buf,2) = sd->bl.id;
  14042. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14043. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14044. }
  14045. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14046. {
  14047. int fd = sd->fd;
  14048. WFIFOHEAD(fd,packet_len(0x814));
  14049. WFIFOW(fd,0) = 0x814;
  14050. WFIFOL(fd,2) = pl_sd->bl.id;
  14051. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14052. WFIFOSET(fd,packet_len(0x814));
  14053. }
  14054. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14055. /// 0815
  14056. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14057. {
  14058. buyingstore_close(sd);
  14059. }
  14060. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14061. /// 0816 <account id>.L
  14062. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14063. {
  14064. uint8 buf[6];
  14065. WBUFW(buf,0) = 0x816;
  14066. WBUFL(buf,2) = sd->bl.id;
  14067. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14068. }
  14069. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14070. {
  14071. int fd = sd->fd;
  14072. WFIFOHEAD(fd,packet_len(0x816));
  14073. WFIFOW(fd,0) = 0x816;
  14074. WFIFOL(fd,2) = pl_sd->bl.id;
  14075. WFIFOSET(fd,packet_len(0x816));
  14076. }
  14077. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14078. /// 0817 <account id>.L
  14079. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14080. {
  14081. uint32 account_id;
  14082. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14083. buyingstore_open(sd, account_id);
  14084. }
  14085. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14086. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14087. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14088. {
  14089. int fd = sd->fd;
  14090. unsigned int i;
  14091. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14092. WFIFOW(fd,0) = 0x818;
  14093. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14094. WFIFOL(fd,4) = pl_sd->bl.id;
  14095. WFIFOL(fd,8) = pl_sd->buyer_id;
  14096. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14097. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14098. {
  14099. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14100. 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.
  14101. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14102. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14103. }
  14104. WFIFOSET(fd,WFIFOW(fd,2));
  14105. }
  14106. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14107. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14108. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14109. {
  14110. const unsigned int blocksize = 6;
  14111. uint8* itemlist;
  14112. uint32 account_id;
  14113. unsigned int count, packet_len, buyer_id;
  14114. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14115. packet_len = RFIFOW(fd,info->pos[0]);
  14116. if( packet_len < 12 )
  14117. {// minimum packet length
  14118. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14119. return;
  14120. }
  14121. account_id = RFIFOL(fd,info->pos[1]);
  14122. buyer_id = RFIFOL(fd,info->pos[2]);
  14123. itemlist = RFIFOP(fd,info->pos[3]);
  14124. // so that buyingstore_trade knows, how many elements it has access to
  14125. packet_len-= info->pos[3];
  14126. if( packet_len%blocksize )
  14127. {
  14128. 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);
  14129. return;
  14130. }
  14131. count = packet_len/blocksize;
  14132. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14133. }
  14134. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14135. /// 081a <result>.W
  14136. /// result:
  14137. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14138. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14139. /// ? = nothing
  14140. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14141. {
  14142. int fd = sd->fd;
  14143. WFIFOHEAD(fd,packet_len(0x81a));
  14144. WFIFOW(fd,0) = 0x81a;
  14145. WFIFOW(fd,2) = result;
  14146. WFIFOSET(fd,packet_len(0x81a));
  14147. }
  14148. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  14149. /// 081b <name id>.W <amount>.W <limit zeny>.L
  14150. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  14151. {
  14152. int fd = sd->fd;
  14153. WFIFOHEAD(fd,packet_len(0x81b));
  14154. WFIFOW(fd,0) = 0x81b;
  14155. WFIFOW(fd,2) = nameid;
  14156. WFIFOW(fd,4) = amount; // amount of nameid received
  14157. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  14158. WFIFOSET(fd,packet_len(0x81b));
  14159. }
  14160. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14161. /// 081c <index>.W <amount>.W <price>.L
  14162. /// message:
  14163. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14164. ///
  14165. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14166. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14167. {
  14168. int fd = sd->fd;
  14169. WFIFOHEAD(fd,packet_len(0x81c));
  14170. WFIFOW(fd,0) = 0x81c;
  14171. WFIFOW(fd,2) = index+2;
  14172. WFIFOW(fd,4) = amount;
  14173. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14174. WFIFOSET(fd,packet_len(0x81c));
  14175. }
  14176. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14177. /// 0824 <result>.W <name id>.W
  14178. /// result:
  14179. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14180. /// 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)
  14181. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14182. /// ? = nothing
  14183. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14184. {
  14185. int fd = sd->fd;
  14186. WFIFOHEAD(fd,packet_len(0x824));
  14187. WFIFOW(fd,0) = 0x824;
  14188. WFIFOW(fd,2) = result;
  14189. WFIFOW(fd,4) = nameid;
  14190. WFIFOSET(fd,packet_len(0x824));
  14191. }
  14192. /// Search Store Info System
  14193. ///
  14194. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14195. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14196. /// type:
  14197. /// 0 = Vending
  14198. /// 1 = Buying Store
  14199. ///
  14200. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14201. /// amount of card slots. If the client does not know about the item it
  14202. /// cannot be searched.
  14203. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14204. {
  14205. const unsigned int blocksize = 2;
  14206. const uint8* itemlist;
  14207. const uint8* cardlist;
  14208. unsigned char type;
  14209. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14210. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14211. packet_len = RFIFOW(fd,info->pos[0]);
  14212. if( packet_len < 15 )
  14213. {// minimum packet length
  14214. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14215. return;
  14216. }
  14217. type = RFIFOB(fd,info->pos[1]);
  14218. max_price = RFIFOL(fd,info->pos[2]);
  14219. min_price = RFIFOL(fd,info->pos[3]);
  14220. item_count = RFIFOB(fd,info->pos[4]);
  14221. card_count = RFIFOB(fd,info->pos[5]);
  14222. itemlist = RFIFOP(fd,info->pos[6]);
  14223. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14224. // check, if there is enough data for the claimed count of items
  14225. packet_len-= info->pos[6];
  14226. if( packet_len%blocksize )
  14227. {
  14228. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14229. return;
  14230. }
  14231. count = packet_len/blocksize;
  14232. if( count < item_count+card_count )
  14233. {
  14234. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14235. return;
  14236. }
  14237. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14238. }
  14239. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14240. /// 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 }*
  14241. /// is first page:
  14242. /// 0 = appends to existing results
  14243. /// 1 = clears previous results before displaying this result set
  14244. /// is next page:
  14245. /// 0 = no "next" label
  14246. /// 1 = "next" label to retrieve more results
  14247. void clif_search_store_info_ack(struct map_session_data* sd)
  14248. {
  14249. const unsigned int blocksize = MESSAGE_SIZE+26;
  14250. int fd = sd->fd;
  14251. unsigned int i, start, end;
  14252. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14253. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14254. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14255. WFIFOW(fd,0) = 0x836;
  14256. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14257. WFIFOB(fd,4) = !sd->searchstore.pages;
  14258. WFIFOB(fd,5) = searchstore_querynext(sd);
  14259. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14260. for( i = start; i < end; i++ ) {
  14261. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14262. struct item it;
  14263. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14264. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14265. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14266. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14267. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14268. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14269. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14270. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14271. // make-up an item for clif_addcards
  14272. memset(&it, 0, sizeof(it));
  14273. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14274. it.nameid = ssitem->nameid;
  14275. it.amount = ssitem->amount;
  14276. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14277. }
  14278. WFIFOSET(fd,WFIFOW(fd,2));
  14279. }
  14280. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14281. /// 0837 <reason>.B
  14282. /// reason:
  14283. /// 0 = "No matching stores were found." (0x70b)
  14284. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14285. /// 2 = "You cannot search anymore." (0x706)
  14286. /// 3 = "You cannot search yet." (0x708)
  14287. /// 4 = "No sale (purchase) information available." (0x705)
  14288. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14289. {
  14290. int fd = sd->fd;
  14291. WFIFOHEAD(fd,packet_len(0x837));
  14292. WFIFOW(fd,0) = 0x837;
  14293. WFIFOB(fd,2) = reason;
  14294. WFIFOSET(fd,packet_len(0x837));
  14295. }
  14296. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14297. /// 0838
  14298. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14299. {
  14300. searchstore_next(sd);
  14301. }
  14302. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14303. /// 083a <type>.W <remaining uses>.B
  14304. /// type:
  14305. /// 0 = Search Stores
  14306. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14307. void clif_open_search_store_info(struct map_session_data* sd)
  14308. {
  14309. int fd = sd->fd;
  14310. WFIFOHEAD(fd,packet_len(0x83a));
  14311. WFIFOW(fd,0) = 0x83a;
  14312. WFIFOW(fd,2) = sd->searchstore.effect;
  14313. #if PACKETVER > 20100701
  14314. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14315. #endif
  14316. WFIFOSET(fd,packet_len(0x83a));
  14317. }
  14318. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14319. /// 083b
  14320. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14321. {
  14322. searchstore_close(sd);
  14323. }
  14324. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14325. /// 083c <account id>.L <store id>.L <nameid>.W
  14326. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14327. {
  14328. unsigned short nameid;
  14329. uint32 account_id, store_id;
  14330. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14331. account_id = RFIFOL(fd,info->pos[0]);
  14332. store_id = RFIFOL(fd,info->pos[1]);
  14333. nameid = RFIFOW(fd,info->pos[2]);
  14334. searchstore_click(sd, account_id, store_id, nameid);
  14335. }
  14336. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14337. /// 083d <xPos>.W <yPos>.W
  14338. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14339. {
  14340. int fd = sd->fd;
  14341. WFIFOHEAD(fd,packet_len(0x83d));
  14342. WFIFOW(fd,0) = 0x83d;
  14343. WFIFOW(fd,2) = x;
  14344. WFIFOW(fd,4) = y;
  14345. WFIFOSET(fd,packet_len(0x83d));
  14346. }
  14347. /// Parse function for packet debugging.
  14348. void clif_parse_debug(int fd,struct map_session_data *sd)
  14349. {
  14350. int cmd, packet_len;
  14351. // clif_parse ensures, that there is at least 2 bytes of data
  14352. cmd = RFIFOW(fd,0);
  14353. if( sd ) {
  14354. packet_len = packet_db[sd->packet_ver][cmd].len;
  14355. if( packet_len == 0 )
  14356. {// unknown
  14357. packet_len = RFIFOREST(fd);
  14358. }
  14359. else if( packet_len == -1 )
  14360. {// variable length
  14361. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14362. }
  14363. 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);
  14364. }
  14365. else
  14366. {
  14367. packet_len = RFIFOREST(fd);
  14368. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14369. }
  14370. ShowDump(RFIFOP(fd,0), packet_len);
  14371. }
  14372. /*==========================================
  14373. * Server tells client to display a window similar to Magnifier (item) one
  14374. * Server populates the window with avilable elemental converter options according to player's inventory
  14375. *------------------------------------------*/
  14376. int clif_elementalconverter_list(struct map_session_data *sd) {
  14377. int i,c,view,fd;
  14378. nullpo_ret(sd);
  14379. /// Main client packet processing function
  14380. fd=sd->fd;
  14381. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14382. WFIFOW(fd, 0)=0x1ad;
  14383. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14384. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14385. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14386. WFIFOW(fd,c*2+ 4)= view;
  14387. else
  14388. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14389. c++;
  14390. }
  14391. }
  14392. WFIFOW(fd,2) = c*2+4;
  14393. WFIFOSET(fd, WFIFOW(fd,2));
  14394. if (c > 0) {
  14395. sd->menuskill_id = SA_CREATECON;
  14396. sd->menuskill_val = c;
  14397. }
  14398. return 0;
  14399. }
  14400. /**
  14401. * Rune Knight
  14402. **/
  14403. void clif_millenniumshield(struct block_list *bl, short shields) {
  14404. #if PACKETVER >= 20081217
  14405. unsigned char buf[10];
  14406. WBUFW(buf,0) = 0x440;
  14407. WBUFL(buf,2) = bl->id;
  14408. WBUFW(buf,6) = shields;
  14409. WBUFW(buf,8) = 0;
  14410. clif_send(buf,packet_len(0x440),bl,AREA);
  14411. #endif
  14412. }
  14413. /**
  14414. * Warlock
  14415. **/
  14416. /*==========================================
  14417. * Spellbook list [LimitLine/3CeAM]
  14418. *------------------------------------------*/
  14419. int clif_spellbook_list(struct map_session_data *sd)
  14420. {
  14421. int i, c;
  14422. int fd;
  14423. nullpo_ret(sd);
  14424. fd = sd->fd;
  14425. WFIFOHEAD(fd, 8 * 8 + 8);
  14426. WFIFOW(fd,0) = 0x1ad;
  14427. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14428. {
  14429. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14430. {
  14431. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14432. c++;
  14433. }
  14434. }
  14435. if( c > 0 )
  14436. {
  14437. WFIFOW(fd,2) = c * 2 + 4;
  14438. WFIFOSET(fd, WFIFOW(fd, 2));
  14439. sd->menuskill_id = WL_READING_SB;
  14440. sd->menuskill_val = c;
  14441. }
  14442. else{
  14443. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14444. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14445. }
  14446. return 1;
  14447. }
  14448. /**
  14449. * Mechanic
  14450. **/
  14451. /*==========================================
  14452. * Magic Decoy Material List
  14453. *------------------------------------------*/
  14454. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14455. int i, c;
  14456. int fd;
  14457. nullpo_ret(sd);
  14458. fd = sd->fd;
  14459. WFIFOHEAD(fd, 8 * 8 + 8);
  14460. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14461. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14462. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14463. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14464. c ++;
  14465. }
  14466. }
  14467. if( c > 0 ) {
  14468. sd->menuskill_id = NC_MAGICDECOY;
  14469. sd->menuskill_val = skill_lv;
  14470. sd->sc.comet_x = x;
  14471. sd->sc.comet_y = y;
  14472. WFIFOW(fd,2) = c * 2 + 4;
  14473. WFIFOSET(fd, WFIFOW(fd, 2));
  14474. } else {
  14475. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14476. return 0;
  14477. }
  14478. return 1;
  14479. }
  14480. /*==========================================
  14481. * Guillotine Cross Poisons List
  14482. *------------------------------------------*/
  14483. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14484. int i, c;
  14485. int fd;
  14486. nullpo_ret(sd);
  14487. fd = sd->fd;
  14488. WFIFOHEAD(fd, 8 * 8 + 8);
  14489. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14490. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14491. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14492. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14493. c ++;
  14494. }
  14495. }
  14496. if( c > 0 ) {
  14497. sd->menuskill_id = GC_POISONINGWEAPON;
  14498. sd->menuskill_val = skill_lv;
  14499. WFIFOW(fd,2) = c * 2 + 4;
  14500. WFIFOSET(fd, WFIFOW(fd, 2));
  14501. } else {
  14502. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14503. return 0;
  14504. }
  14505. return 1;
  14506. }
  14507. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14508. int fd, i, c;
  14509. nullpo_ret(sd);
  14510. fd = sd->fd;
  14511. if( !fd ) return 0;
  14512. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14513. return 0;
  14514. WFIFOHEAD(fd, 2 * 6 + 4);
  14515. WFIFOW(fd,0) = 0x442;
  14516. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14517. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14518. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14519. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14520. {
  14521. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14522. c++;
  14523. }
  14524. if( c > 0 ) {
  14525. WFIFOW(fd,2) = 8 + c * 2;
  14526. WFIFOL(fd,4) = c;
  14527. WFIFOSET(fd,WFIFOW(fd,2));
  14528. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14529. sd->menuskill_val = c;
  14530. } else {
  14531. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14532. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14533. }
  14534. return 1;
  14535. }
  14536. /*===========================================
  14537. * Skill list for Four Elemental Analysis
  14538. * and Change Material skills.
  14539. *------------------------------------------*/
  14540. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14541. {
  14542. #if PACKETVER >= 20090922
  14543. int fd;
  14544. nullpo_ret(sd);
  14545. sd->menuskill_id = skill_id; // To prevent hacking.
  14546. sd->menuskill_val = skill_lv;
  14547. if( skill_id == GN_CHANGEMATERIAL )
  14548. skill_lv = 0; // Changematerial
  14549. fd = sd->fd;
  14550. WFIFOHEAD(fd,packet_len(0x7e3));
  14551. WFIFOW(fd,0) = 0x7e3;
  14552. WFIFOL(fd,2) = skill_lv;
  14553. WFIFOL(fd,4) = 0;
  14554. WFIFOSET(fd,packet_len(0x7e3));
  14555. #endif
  14556. return 1;
  14557. }
  14558. /*==========================================
  14559. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14560. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14561. * RFIFOL(fd,2) - type (currently not used)
  14562. *------------------------------------------*/
  14563. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14564. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14565. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14566. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14567. return;
  14568. if( pc_istrading(sd) ) {
  14569. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14570. clif_menuskill_clear(sd);
  14571. return;
  14572. }
  14573. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14574. clif_menuskill_clear(sd);
  14575. }
  14576. /*==========================================
  14577. * Kagerou/Oboro amulet spirit
  14578. *------------------------------------------*/
  14579. void clif_spiritcharm(struct map_session_data *sd)
  14580. {
  14581. unsigned char buf[10];
  14582. nullpo_retv(sd);
  14583. WBUFW(buf,0)=0x08cf;
  14584. WBUFL(buf,2)=sd->bl.id;
  14585. WBUFW(buf,6)=sd->spiritcharm_type;
  14586. WBUFW(buf,8)=sd->spiritcharm;
  14587. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14588. }
  14589. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14590. /// 0907 <index>.W
  14591. ///
  14592. /// R 0908 <index>.w <type>.b
  14593. /// type:
  14594. /// 0 = move item to personal tab
  14595. /// 1 = move item to normal tab
  14596. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14597. #if PACKETVER >= 20111122
  14598. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14599. int index = RFIFOW(fd,info->pos[0])-2;
  14600. int type = RFIFOB(fd, info->pos[1]);
  14601. /* can't move while dead. */
  14602. if(pc_isdead(sd)) {
  14603. return;
  14604. }
  14605. if (index < 0 || index >= MAX_INVENTORY)
  14606. return;
  14607. if ( sd->status.inventory[index].favorite && type == 1 )
  14608. sd->status.inventory[index].favorite = 0;
  14609. else if( type == 0 )
  14610. sd->status.inventory[index].favorite = 1;
  14611. else
  14612. return;/* nothing to do. */
  14613. clif_favorite_item(sd, index);
  14614. #endif
  14615. }
  14616. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14617. /// 0900 <index>.W <favorite>.B
  14618. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14619. int fd = sd->fd;
  14620. WFIFOHEAD(fd,packet_len(0x908));
  14621. WFIFOW(fd,0) = 0x908;
  14622. WFIFOW(fd,2) = index+2;
  14623. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14624. WFIFOSET(fd,packet_len(0x908));
  14625. }
  14626. void clif_snap( struct block_list *bl, short x, short y ) {
  14627. unsigned char buf[10];
  14628. WBUFW(buf,0) = 0x8d2;
  14629. WBUFL(buf,2) = bl->id;
  14630. WBUFW(buf,6) = x;
  14631. WBUFW(buf,8) = y;
  14632. if( disguised(bl) )
  14633. {
  14634. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14635. WBUFL(buf,2) = -bl->id;
  14636. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14637. } else
  14638. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14639. }
  14640. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14641. #if PACKETVER >= 20120404
  14642. WFIFOHEAD(fd,packet_len(0x977));
  14643. WFIFOW(fd,0) = 0x977;
  14644. WFIFOL(fd,2) = md->bl.id;
  14645. WFIFOL(fd,6) = md->status.hp;
  14646. WFIFOL(fd,10) = md->status.max_hp;
  14647. WFIFOSET(fd,packet_len(0x977));
  14648. #endif
  14649. }
  14650. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14651. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14652. return;
  14653. }
  14654. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14655. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14656. WFIFOW(sd->fd,0) = 0x2c9;
  14657. WFIFOB(sd->fd,2) = flag;
  14658. WFIFOSET(sd->fd, packet_len(0x2c9));
  14659. }
  14660. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14661. /// 0979 <world name>.24B <char name>.24B
  14662. void clif_ackworldinfo(struct map_session_data* sd) {
  14663. int fd;
  14664. nullpo_retv(sd);
  14665. fd = sd->fd;
  14666. WFIFOHEAD(fd,packet_len(0x979));
  14667. WFIFOW(fd,0)=0x979;
  14668. //AID -> world name ?
  14669. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14670. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14671. WFIFOSET(fd,packet_len(0x979));
  14672. }
  14673. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14674. /// 0978 <AID>.L
  14675. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14676. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14677. if(sd) clif_ackworldinfo(sd);
  14678. }
  14679. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14680. /// 0447
  14681. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14682. //if(sd)
  14683. ;
  14684. }
  14685. /// req world info (CZ_CLIENT_VERSION)
  14686. /// 044A <version>.L
  14687. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14688. //if(sd)
  14689. ;
  14690. }
  14691. /// Ranking list
  14692. /// ranking pointlist { <name>.24B <point>.L }*10
  14693. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14694. struct fame_list* list;
  14695. int skip = 0;
  14696. switch(rankingtype+1) { //to keep the same case as char.c
  14697. case 1: list = smith_fame_list; break;
  14698. case 2: list = chemist_fame_list; break;
  14699. case 3: list = taekwon_fame_list; break;
  14700. default: skip=1; break;
  14701. }
  14702. if(!skip) {
  14703. int i;
  14704. //Packet size limits this list to 10 elements. [Skotlex]
  14705. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14706. if (list[i].id > 0) {
  14707. const char* name;
  14708. if (strcmp(list[i].name, "-") == 0 &&
  14709. (name = map_charid2nick(list[i].id)) != NULL)
  14710. {
  14711. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14712. } else {
  14713. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14714. }
  14715. } else {
  14716. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14717. }
  14718. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14719. }
  14720. for(;i < 10; i++) { //In case the MAX is less than 10.
  14721. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14722. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14723. }
  14724. }
  14725. }
  14726. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14727. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14728. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14729. int mypoint = 0;
  14730. WBUFW(buf,0) = 0x97d;
  14731. WBUFW(buf,2) = rankingType;
  14732. clif_sub_ranklist(buf,4,sd,rankingType);
  14733. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14734. case MAPID_BLACKSMITH:
  14735. case MAPID_ALCHEMIST:
  14736. case MAPID_TAEKWON:
  14737. mypoint = sd->status.fame;
  14738. }
  14739. WBUFL(buf,284) = mypoint; //mypoint
  14740. clif_send(buf, 288, &sd->bl, SELF);
  14741. }
  14742. /*
  14743. * 097c <type> (CZ_REQ_RANKING)
  14744. * type
  14745. * 0: /blacksmith
  14746. * 1: /alchemist
  14747. * 2: /taekwon
  14748. * 3: /pk
  14749. * */
  14750. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14751. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14752. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14753. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14754. }
  14755. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14756. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14757. #if PACKETVER < 20130710
  14758. switch(rankingtype){
  14759. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14760. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14761. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14762. }
  14763. #else
  14764. int fd=sd->fd;
  14765. WFIFOHEAD(fd,14);
  14766. WFIFOW(fd,0) = 0x97e;
  14767. WFIFOW(fd,2) = rankingtype;
  14768. WFIFOL(fd,4) = point;
  14769. WFIFOL(fd,8) = sd->status.fame;
  14770. WFIFOSET(fd,12);
  14771. #endif
  14772. }
  14773. /**
  14774. * Transmit personal information to player. (rates)
  14775. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14776. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14777. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14778. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14779. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14780. * FIXME!
  14781. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14782. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14783. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14784. */
  14785. #ifdef VIP_ENABLE
  14786. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14787. if (sd) {
  14788. struct s_packet_db* info;
  14789. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14790. int cmd = 0, fd, i = 0;
  14791. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14792. int details_bexp[PINFO_MAX];
  14793. int details_drop[PINFO_MAX];
  14794. int details_penalty[PINFO_MAX];
  14795. int penalty_const;
  14796. /**
  14797. * Set for EXP
  14798. */
  14799. //0:PCRoom
  14800. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14801. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14802. details_bexp[0] = 0;
  14803. else {
  14804. if (details_bexp[0] < 100) {
  14805. details_bexp[0] = 100 - details_bexp[0];
  14806. details_bexp[0] = 0 - details_bexp[0];
  14807. }
  14808. else
  14809. details_bexp[0] = details_bexp[0] - 100;
  14810. }
  14811. //1:Premium
  14812. if (pc_isvip(sd)) {
  14813. details_bexp[1] = battle_config.vip_base_exp_increase;
  14814. if (details_bexp[1] < 0)
  14815. details_bexp[1] = 0 - details_bexp[1];
  14816. }
  14817. else
  14818. details_bexp[1] = 0;
  14819. //2:Server
  14820. details_bexp[2] = battle_config.base_exp_rate;
  14821. if (details_bexp[2] == 100)
  14822. details_bexp[2] = 0;
  14823. else {
  14824. if (details_bexp[2] < 100) {
  14825. details_bexp[2] = 100 - details_bexp[2];
  14826. details_bexp[2] = 0 - details_bexp[2];
  14827. }
  14828. else
  14829. details_bexp[2] = details_bexp[2] - 100;
  14830. }
  14831. //3:TPLUS
  14832. details_bexp[3] = 0;
  14833. /* End - EXP set*/
  14834. /**
  14835. * Set for Drop rate
  14836. */
  14837. //0:PCRoom
  14838. details_drop[0] = 0;
  14839. //1:Premium
  14840. details_drop[1] = battle_config.vip_drop_increase;
  14841. if (pc_isvip(sd)) {
  14842. if (details_drop[1] < 0)
  14843. details_drop[1] = 0 - details_drop[1];
  14844. }
  14845. else
  14846. details_drop[1] = 0;
  14847. //2:Server
  14848. details_drop[2] = battle_config.item_rate_common;
  14849. if (details_drop[2] == 100)
  14850. details_drop[2] = 0;
  14851. else {
  14852. if (details_drop[2] < 100) {
  14853. details_drop[2] = 100 - details_drop[2];
  14854. details_drop[2] = 0 - details_drop[2];
  14855. }
  14856. else
  14857. details_drop[2] = details_drop[2] - 100;
  14858. }
  14859. //3:TPLUS
  14860. details_drop[3] = 0;
  14861. /* End - Drop set*/
  14862. /**
  14863. * Set for Penalty rate
  14864. */
  14865. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14866. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14867. //0:PCRoom
  14868. details_penalty[0] = 0;
  14869. //1:Premium
  14870. if (pc_isvip(sd)) {
  14871. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14872. if (details_penalty[1] == 100)
  14873. details_penalty[1] = 0;
  14874. else {
  14875. if (details_penalty[1] < 100) {
  14876. details_penalty[1] = 100 - details_penalty[1];
  14877. details_penalty[1] = 0 - details_penalty[1];
  14878. }
  14879. else
  14880. details_penalty[1] = details_penalty[1] - 100;
  14881. }
  14882. }
  14883. else
  14884. details_penalty[1] = 0;
  14885. //2:Server
  14886. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14887. if (details_penalty[2] == 100)
  14888. details_penalty[2] = 0;
  14889. else {
  14890. if (details_penalty[2] < 100) {
  14891. details_penalty[2] = 100 - details_penalty[2];
  14892. details_penalty[2] = 0 - details_penalty[2];
  14893. }
  14894. else
  14895. details_penalty[2] = details_penalty[2] - 100;
  14896. }
  14897. //3:TPLUS
  14898. details_penalty[3] = 0;
  14899. /* End - Penalty set*/
  14900. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14901. info = &packet_db[sd->packet_ver][cmd];
  14902. len = info->len; //this is the base len without details
  14903. if(!len) return; //version as packet disable
  14904. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14905. szdetails = 7;
  14906. factor = 1;
  14907. }
  14908. else if (cmd == 0x097b) {
  14909. tot_baseexp *= factor;
  14910. tot_drop *= factor;
  14911. tot_penalty *= factor;
  14912. }
  14913. fd = sd->fd;
  14914. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14915. WFIFOW(fd,0) = cmd;
  14916. for (i = 0; i < maxinfotype; i++) {
  14917. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14918. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14919. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14920. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14921. tot_baseexp += details_bexp[i]*factor;
  14922. tot_drop += details_penalty[i]*factor;
  14923. tot_penalty += details_drop[i]*factor;
  14924. len += szdetails;
  14925. }
  14926. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14927. if (cmd == 0x08cb) { //0x08cb version
  14928. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14929. WFIFOW(fd,info->pos[2]) = tot_drop;
  14930. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14931. }
  14932. else { //2013-08-07aRagexe uses 0x097b
  14933. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14934. WFIFOL(fd,info->pos[2]) = tot_drop;
  14935. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14936. }
  14937. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14938. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14939. WFIFOSET(fd,len);
  14940. }
  14941. }
  14942. #endif
  14943. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14944. char cmd[30];
  14945. int t_aid = RFIFOL(fd,2);
  14946. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14947. is_atcommand(fd, sd, cmd, 1);
  14948. }
  14949. /**
  14950. * Marks Crimson Marker target on mini-map to the caster
  14951. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  14952. * @param fd
  14953. * @param bl Crimson Marker target
  14954. **/
  14955. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  14956. struct s_packet_db* info;
  14957. int cmd = 0;
  14958. int16 len;
  14959. unsigned char buf[11];
  14960. nullpo_retv(sd);
  14961. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  14962. if (!cmd)
  14963. cmd = 0x09C1; //default
  14964. info = &packet_db[sd->packet_ver][cmd];
  14965. if (!(len = info->len))
  14966. return;
  14967. WBUFW(buf, 0) = cmd;
  14968. WBUFL(buf, info->pos[0]) = bl->id;
  14969. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  14970. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  14971. clif_send(buf, len, &sd->bl, SELF);
  14972. }
  14973. /**
  14974. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  14975. **/
  14976. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  14977. struct s_packet_db *info = NULL;
  14978. int cmd = 0;
  14979. nullpo_retv(sd);
  14980. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  14981. info = &packet_db[sd->packet_ver][cmd];
  14982. if (!cmd || !info->len)
  14983. return;
  14984. WFIFOHEAD(sd->fd, info->len);
  14985. WFIFOW(sd->fd, 0) = cmd;
  14986. WFIFOW(sd->fd, info->pos[0]) = n+2;
  14987. WFIFOSET(sd->fd, info->len);
  14988. }
  14989. /// [Ind/Hercules]
  14990. void clif_showscript(struct block_list* bl, const char* message) {
  14991. char buf[256];
  14992. size_t len;
  14993. nullpo_retv(bl);
  14994. if(!message)
  14995. return;
  14996. len = strlen(message)+1;
  14997. if( len > sizeof(buf)-8 ) {
  14998. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  14999. len = sizeof(buf)-8;
  15000. }
  15001. WBUFW(buf,0) = 0x8b3;
  15002. WBUFW(buf,2) = (len+8);
  15003. WBUFL(buf,4) = bl->id;
  15004. safestrncpy((char *) WBUFP(buf,8), message, len);
  15005. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  15006. }
  15007. /// [Ind/Hercules]
  15008. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15009. unsigned char buf[10];
  15010. nullpo_retv(sd);
  15011. WBUFW(buf,0) = 0x7fc;
  15012. WBUFL(buf,2) = prev_leader_aid;
  15013. WBUFL(buf,6) = new_leader_aid;
  15014. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  15015. }
  15016. /**
  15017. * Decrypt packet identifier for player
  15018. * @param fd
  15019. * @param sd
  15020. * @param packet_ver
  15021. * Orig author [Ind/Hercules]
  15022. **/
  15023. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15024. #ifndef PACKET_OBFUSCATION
  15025. return RFIFOW(fd, 0);
  15026. #else
  15027. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15028. if (sd)
  15029. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15030. else
  15031. 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.
  15032. return cmd; // Return the decrypted packet ID.
  15033. #endif
  15034. }
  15035. #ifdef DUMP_UNKNOWN_PACKET
  15036. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15037. {
  15038. const char* packet_txt = "save/packet.txt";
  15039. FILE* fp;
  15040. time_t time_server;
  15041. struct tm *datetime;
  15042. char datestr[512];
  15043. time(&time_server); // get time in seconds since 1/1/1970
  15044. datetime = localtime(&time_server); // convert seconds in structure
  15045. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15046. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15047. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15048. if( sd ) {
  15049. 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);
  15050. } else {
  15051. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15052. }
  15053. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15054. fprintf(fp, "\n");
  15055. fclose(fp);
  15056. } else {
  15057. ShowError("Failed to write '%s'.\n", packet_txt);
  15058. // Dump on console instead
  15059. if( sd ) {
  15060. 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);
  15061. } else {
  15062. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15063. }
  15064. ShowDump(RFIFOP(fd,0), packet_len);
  15065. }
  15066. }
  15067. #endif
  15068. /// Roulette System
  15069. /// Author: Yommy
  15070. /**
  15071. * Opens Roulette window
  15072. * @param fd
  15073. * @param sd
  15074. */
  15075. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15076. {
  15077. nullpo_retv(sd);
  15078. if (!battle_config.feature_roulette) {
  15079. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15080. return;
  15081. }
  15082. WFIFOHEAD(fd,packet_len(0xa1a));
  15083. WFIFOW(fd,0) = 0xa1a;
  15084. WFIFOB(fd,2) = 0; // result
  15085. WFIFOL(fd,3) = 0; // serial
  15086. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15087. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15088. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15089. WFIFOL(fd,11) = sd->roulette_point.gold;
  15090. WFIFOL(fd,15) = sd->roulette_point.silver;
  15091. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15092. WFIFOSET(fd,packet_len(0xa1a));
  15093. }
  15094. /**
  15095. * Generates information to be displayed
  15096. * @param fd
  15097. * @param sd
  15098. */
  15099. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15100. {
  15101. unsigned short i, j, count = 0;
  15102. int len = 8 + (42 * 8);
  15103. nullpo_retv(sd);
  15104. if (!battle_config.feature_roulette) {
  15105. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15106. return;
  15107. }
  15108. WFIFOHEAD(fd,len);
  15109. WFIFOW(fd,0) = 0xa1c;
  15110. WFIFOW(fd,2) = len;
  15111. WFIFOL(fd,4) = 1; // serial
  15112. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15113. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15114. WFIFOW(fd,8 * count + 8) = i;
  15115. WFIFOW(fd,8 * count + 10) = j;
  15116. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15117. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15118. count++;
  15119. }
  15120. }
  15121. WFIFOSET(fd,len);
  15122. return;
  15123. }
  15124. /**
  15125. * Closes Roulette window
  15126. * @param fd
  15127. * @param sd
  15128. */
  15129. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15130. {
  15131. nullpo_retv(sd);
  15132. if (!battle_config.feature_roulette) {
  15133. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15134. return;
  15135. }
  15136. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15137. return;
  15138. }
  15139. /**
  15140. *
  15141. **/
  15142. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15143. #if PACKETVER >= 20141016
  15144. uint16 cmd = 0xa22;
  15145. unsigned char buf[5];
  15146. nullpo_retv(sd);
  15147. if (packet_db[sd->packet_ver][cmd].len == 0)
  15148. return;
  15149. WBUFW(buf,0) = cmd;
  15150. WBUFB(buf,2) = type;
  15151. WBUFW(buf,3) = 0; //! TODO: Additional item
  15152. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15153. #endif
  15154. }
  15155. /**
  15156. * Claim roulette reward
  15157. * @param sd Player
  15158. * @return 0:Success
  15159. **/
  15160. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15161. struct item it;
  15162. uint8 res = 1;
  15163. nullpo_retr(1, sd);
  15164. if (sd->roulette.prizeIdx < 0)
  15165. return RECV_ITEM_FAILED;
  15166. memset(&it, 0, sizeof(it));
  15167. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15168. it.identify = 1;
  15169. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15170. ; // onSuccess
  15171. }
  15172. sd->roulette.claimPrize = false;
  15173. sd->roulette.prizeStage = 0;
  15174. sd->roulette.prizeIdx = -1;
  15175. sd->roulette.stage = 0;
  15176. return res;
  15177. }
  15178. /**
  15179. * Process the stage and attempt to give a prize
  15180. * @param fd
  15181. * @param sd
  15182. */
  15183. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15184. {
  15185. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15186. short stage = sd->roulette.stage;
  15187. nullpo_retv(sd);
  15188. if (!battle_config.feature_roulette) {
  15189. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15190. return;
  15191. }
  15192. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15193. stage = sd->roulette.stage = 0;
  15194. if (!stage) {
  15195. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15196. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15197. }
  15198. if (result == GENERATE_ROULETTE_SUCCESS) {
  15199. if (!stage) {
  15200. if (sd->roulette_point.bronze > 0) {
  15201. sd->roulette_point.bronze -= 1;
  15202. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15203. } else if (sd->roulette_point.silver > 9) {
  15204. sd->roulette_point.silver -= 10;
  15205. stage = sd->roulette.stage = 2;
  15206. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15207. } else if (sd->roulette_point.gold > 9) {
  15208. sd->roulette_point.gold -= 10;
  15209. stage = sd->roulette.stage = 4;
  15210. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15211. }
  15212. }
  15213. sd->roulette.prizeStage = stage;
  15214. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15215. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15216. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15217. clif_roulette_getitem(sd);
  15218. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15219. return;
  15220. }
  15221. else {
  15222. sd->roulette.claimPrize = true;
  15223. sd->roulette.stage++;
  15224. }
  15225. }
  15226. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15227. }
  15228. /**
  15229. * Request to cash in prize
  15230. * @param fd
  15231. * @param sd
  15232. */
  15233. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15234. {
  15235. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15236. nullpo_retv(sd);
  15237. if (!battle_config.feature_roulette) {
  15238. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15239. return;
  15240. }
  15241. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15242. switch (clif_roulette_getitem(sd)) {
  15243. case 0:
  15244. type = RECV_ITEM_SUCCESS;
  15245. break;
  15246. case 1:
  15247. case 4:
  15248. case 5:
  15249. type = RECV_ITEM_OVERCOUNT;
  15250. break;
  15251. case 2:
  15252. type = RECV_ITEM_OVERWEIGHT;
  15253. break;
  15254. case 7:
  15255. default:
  15256. type = RECV_ITEM_FAILED;
  15257. break;
  15258. }
  15259. }
  15260. clif_roulette_recvitem_ack(sd,type);
  15261. return;
  15262. }
  15263. /**
  15264. * Update Roulette window with current stats
  15265. * @param sd
  15266. * @param result
  15267. * @param stage
  15268. * @param prizeIdx
  15269. * @param bonusItemID
  15270. */
  15271. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15272. {
  15273. int fd = sd->fd;
  15274. nullpo_retv(sd);
  15275. WFIFOHEAD(fd,packet_len(0xa20));
  15276. WFIFOW(fd,0) = 0xa20;
  15277. WFIFOB(fd,2) = result;
  15278. WFIFOW(fd,3) = stage;
  15279. WFIFOW(fd,5) = prizeIdx;
  15280. WFIFOW(fd,7) = bonusItemID;
  15281. WFIFOL(fd,9) = sd->roulette_point.gold;
  15282. WFIFOL(fd,13) = sd->roulette_point.silver;
  15283. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15284. WFIFOSET(fd,packet_len(0xa20));
  15285. }
  15286. /// MERGE ITEM
  15287. /**
  15288. * Acknowledge the client about item merger result
  15289. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15290. * @param fd
  15291. * @param sd
  15292. **/
  15293. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15294. unsigned char buf[9];
  15295. struct s_packet_db *info = NULL;
  15296. short cmd = 0;
  15297. nullpo_retv(sd);
  15298. if (!clif_session_isValid(sd))
  15299. return;
  15300. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15301. return;
  15302. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15303. return;
  15304. WBUFW(buf, 0) = cmd;
  15305. WBUFW(buf, info->pos[0]) = index;
  15306. WBUFW(buf, info->pos[1]) = count;
  15307. WBUFB(buf, info->pos[2]) = type;
  15308. clif_send(buf, info->len, &sd->bl, SELF);
  15309. }
  15310. /**
  15311. * Check if item has the pair to be merged
  15312. * @param sd
  15313. * @param it Item
  15314. * @return True if has pair, False if not
  15315. **/
  15316. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15317. struct item *it_;
  15318. unsigned short i;
  15319. nullpo_retr(false, sd);
  15320. 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);
  15321. if (i < MAX_INVENTORY)
  15322. return true;
  15323. return false;
  15324. }
  15325. /**
  15326. * Check if item can be merged
  15327. * @param id Item Data
  15328. * @param it Item
  15329. * @return True if can be merged, False if not
  15330. **/
  15331. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15332. if (!id || !it)
  15333. return false;
  15334. if (id->type == IT_CASH)
  15335. return false;
  15336. if (!itemdb_isstackable2(id))
  15337. return false;
  15338. if (itemdb_isspecial(it->card[0]))
  15339. return false;
  15340. if (!it->unique_id)
  15341. return false;
  15342. return true;
  15343. }
  15344. /**
  15345. * Open available item to be merged.
  15346. * Only show 1 item in 1 process.
  15347. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15348. * @param sd
  15349. **/
  15350. void clif_merge_item_open(struct map_session_data *sd) {
  15351. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15352. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15353. int len = 0;
  15354. struct s_packet_db *info = NULL;
  15355. struct item *it;
  15356. nullpo_retv(sd);
  15357. if (!clif_session_isValid(sd))
  15358. return;
  15359. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15360. return;
  15361. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15362. return;
  15363. // Get entries
  15364. for (i = 0; i < MAX_INVENTORY; i++) {
  15365. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15366. continue;
  15367. if (clif_merge_item_has_pair(sd, it))
  15368. indexes[n++] = i;
  15369. }
  15370. if (n < 2) { // No item need to be merged
  15371. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15372. return;
  15373. }
  15374. WBUFW(buf, 0) = cmd;
  15375. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15376. for (i = 0; i < n; i++) {
  15377. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15378. }
  15379. clif_send(buf, len, &sd->bl, SELF);
  15380. }
  15381. /**
  15382. * Process item merger
  15383. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15384. * @param fd
  15385. * @param sd
  15386. **/
  15387. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15388. struct s_packet_db *info = NULL;
  15389. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15390. unsigned int count = 0;
  15391. struct item_data *id = NULL;
  15392. nullpo_retv(sd);
  15393. if (!clif_session_isValid(sd))
  15394. return;
  15395. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15396. return;
  15397. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15398. if (n < 2) { // No item need to be merged
  15399. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15400. return;
  15401. }
  15402. for (i = 0, j = 0; i < n; i++) {
  15403. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15404. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15405. continue;
  15406. indexes[j] = idx;
  15407. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15408. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15409. return;
  15410. }
  15411. count += sd->status.inventory[idx].amount;
  15412. j++;
  15413. }
  15414. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15415. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15416. return;
  15417. }
  15418. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15419. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15420. return;
  15421. }
  15422. // Merrrrge!!!!
  15423. for (i = 1; i < n; i++) {
  15424. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15425. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15426. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15427. sd->inventory_data[idx] = NULL;
  15428. clif_delitem(sd, idx, amt, 0);
  15429. }
  15430. sd->status.inventory[indexes[0]].amount = count;
  15431. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15432. }
  15433. /**
  15434. * Cancel item merge
  15435. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15436. * @param fd
  15437. * @param sd
  15438. **/
  15439. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15440. return; // Nothing todo yet
  15441. }
  15442. /**
  15443. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15444. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15445. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15446. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15447. **/
  15448. 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) {
  15449. unsigned char buf[9 + NAME_LENGTH * 2];
  15450. unsigned short cmd = 0;
  15451. struct s_packet_db *info = NULL;
  15452. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15453. return;
  15454. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15455. return;
  15456. WBUFW(buf, 0) = 0x7fd;
  15457. WBUFB(buf, 4) = type;
  15458. WBUFW(buf, 5) = nameid;
  15459. WBUFB(buf, 7) = NAME_LENGTH;
  15460. safestrncpy((char *)WBUFP(buf, 8), char_name, NAME_LENGTH);
  15461. switch (type) {
  15462. case ITEMOBTAIN_TYPE_BOXITEM:
  15463. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15464. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15465. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15466. break;
  15467. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15468. {
  15469. struct mob_db *db = mob_db(container);
  15470. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15471. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15472. safestrncpy((char *)WBUFP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15473. }
  15474. break;
  15475. case ITEMOBTAIN_TYPE_NPC:
  15476. default:
  15477. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15478. break;
  15479. }
  15480. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15481. }
  15482. /*==========================================
  15483. * Main client packet processing function
  15484. *------------------------------------------*/
  15485. static int clif_parse(int fd)
  15486. {
  15487. int cmd, packet_ver, packet_len, err;
  15488. TBL_PC* sd;
  15489. int pnum;
  15490. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15491. // Note: "click masters" can do 80+ clicks in 10 seconds
  15492. 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]
  15493. { // begin main client packet processing loop
  15494. sd = (TBL_PC *)session[fd]->session_data;
  15495. if (session[fd]->flag.eof) {
  15496. if (sd) {
  15497. if (sd->state.autotrade) {
  15498. //Disassociate character from the socket connection.
  15499. session[fd]->session_data = NULL;
  15500. sd->fd = 0;
  15501. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15502. } else
  15503. if (sd->state.active) {
  15504. // Player logout display [Valaris]
  15505. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15506. clif_quitsave(fd, sd);
  15507. } else {
  15508. //Unusual logout (during log on/off/map-changer procedure)
  15509. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15510. map_quit(sd);
  15511. }
  15512. } else {
  15513. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15514. }
  15515. do_close(fd);
  15516. return 0;
  15517. }
  15518. if (RFIFOREST(fd) < 2)
  15519. return 0;
  15520. cmd = clif_parse_cmd(fd, sd);
  15521. // identify client's packet version
  15522. if (sd) {
  15523. packet_ver = sd->packet_ver;
  15524. } else {
  15525. // check authentification packet to know packet version
  15526. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15527. if( err ) {// failed to identify packet version
  15528. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15529. err == 1 ? "" :
  15530. err == 2 ? ", possibly for having an invalid account_id" :
  15531. err == 3 ? ", possibly for having an invalid char_id." :
  15532. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15533. err == 4 ? ", possibly for having an invalid login_id1." :
  15534. err == 5 ? ", possibly for having an invalid client_tick." :
  15535. */
  15536. err == 6 ? ", possibly for having an invalid sex." :
  15537. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15538. WFIFOHEAD(fd,packet_len(0x6a));
  15539. WFIFOW(fd,0) = 0x6a;
  15540. WFIFOB(fd,2) = 3; // Rejected from Server
  15541. WFIFOSET(fd,packet_len(0x6a));
  15542. #ifdef DUMP_INVALID_PACKET
  15543. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15544. #endif
  15545. RFIFOSKIP(fd, RFIFOREST(fd));
  15546. set_eof(fd);
  15547. return 0;
  15548. }
  15549. }
  15550. // filter out invalid / unsupported packets
  15551. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15552. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15553. #ifdef DUMP_INVALID_PACKET
  15554. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15555. #endif
  15556. set_eof(fd);
  15557. return 0;
  15558. }
  15559. // determine real packet length
  15560. packet_len = packet_db[packet_ver][cmd].len;
  15561. if (packet_len == -1) { // variable-length packet
  15562. if (RFIFOREST(fd) < 4)
  15563. return 0;
  15564. packet_len = RFIFOW(fd,2);
  15565. if (packet_len < 4 || packet_len > 32768) {
  15566. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15567. #ifdef DUMP_INVALID_PACKET
  15568. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15569. #endif
  15570. set_eof(fd);
  15571. return 0;
  15572. }
  15573. }
  15574. if ((int)RFIFOREST(fd) < packet_len)
  15575. return 0; // not enough data received to form the packet
  15576. #ifdef PACKET_OBFUSCATION
  15577. RFIFOW(fd, 0) = cmd;
  15578. if (sd)
  15579. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15580. #endif
  15581. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15582. packet_db[packet_ver][cmd].func(fd, sd);
  15583. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15584. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15585. ; //Only valid packet when there is no session
  15586. else
  15587. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15588. ; //Only valid packet when player is not on a map
  15589. else
  15590. packet_db[packet_ver][cmd].func(fd, sd);
  15591. }
  15592. #ifdef DUMP_UNKNOWN_PACKET
  15593. else DumpUnknown(fd,sd,cmd,packet_len);
  15594. #endif
  15595. RFIFOSKIP(fd, packet_len);
  15596. }; // main loop end
  15597. return 0;
  15598. }
  15599. /*==========================================
  15600. * Reads packet_db.txt and setups its array reference
  15601. *------------------------------------------*/
  15602. void packetdb_readdb(bool reload)
  15603. {
  15604. char line[1024];
  15605. int cmd,i,j;
  15606. int max_cmd=-1;
  15607. bool skip_ver = false;
  15608. int warned = 0;
  15609. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15610. #ifdef PACKET_OBFUSCATION
  15611. bool key_defined = false;
  15612. int last_key_defined = -1;
  15613. #endif
  15614. int packet_len_table[MAX_PACKET_DB] = {
  15615. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15619. //#0x0040
  15620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15622. #if PACKETVER <= 20081217
  15623. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  15624. #else
  15625. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  15626. #endif
  15627. #if PACKETVER < 2
  15628. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  15629. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  15630. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  15631. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  15632. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  15633. #else
  15634. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  15635. #endif
  15636. //#0x0080
  15637. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  15638. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  15639. #if PACKETVER <= 20100622
  15640. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  15641. #else
  15642. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  15643. #endif
  15644. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  15645. //#0x00C0
  15646. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  15647. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  15648. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  15649. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  15650. //#0x0100
  15651. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  15652. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  15653. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  15654. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  15655. //#0x0140
  15656. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  15657. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  15658. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  15659. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  15660. //#0x0180
  15661. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  15662. #if PACKETVER < 1
  15663. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15664. #else // 196 comodo icon status display for later
  15665. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15666. #endif
  15667. #if PACKETVER < 20081126
  15668. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15669. #else // 0x1a2 changed (35->37)
  15670. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15671. #endif
  15672. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  15673. //#0x01C0, Set 0x1d5=-1
  15674. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  15675. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  15676. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  15677. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  15678. //#0x0200
  15679. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  15680. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  15681. #if PACKETVER < 20071106
  15682. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  15683. #else // 0x22c changed
  15684. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  15685. #endif
  15686. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  15687. //#0x0240
  15688. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  15689. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  15690. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15691. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15692. //#0x0280
  15693. #if PACKETVER < 20070711
  15694. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  15695. #else
  15696. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  15697. #endif
  15698. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  15699. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15700. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  15701. //#0x02C0
  15702. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  15703. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  15704. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  15705. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15706. //#0x0300
  15707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15711. //#0x0340
  15712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15716. //#0x0380
  15717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15721. //#0x03C0
  15722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15726. //#0x0400
  15727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  15731. //#0x0440
  15732. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  15733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15736. //#0x0480
  15737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15741. //#0x04C0
  15742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15746. //#0x0500
  15747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15751. //#0x0540
  15752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15756. //#0x0580
  15757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15761. //#0x05C0
  15762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15766. //#0x0600
  15767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15771. //#0x0640
  15772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15776. //#0x0680
  15777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15781. //#0x06C0
  15782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15786. //#0x0700
  15787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15791. //#0x0740
  15792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15796. //#0x0780
  15797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15801. //#0x07C0
  15802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15803. #if PACKETVER < 20090617
  15804. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15805. #else // 0x7d9 changed
  15806. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15807. #endif
  15808. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15809. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  15810. //#0x0800
  15811. #if PACKETVER < 20091229
  15812. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15813. #else // for Party booking ( PACKETVER >= 20091229 )
  15814. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15815. #endif
  15816. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15817. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15818. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15819. //#0x0840
  15820. #if PACKETVER < 20130000
  15821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15822. #else
  15823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15824. #endif
  15825. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  15826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15828. //#0x0880
  15829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15832. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15833. //#0x08C0
  15834. 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10,
  15835. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15838. //#0x0900
  15839. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15843. //#0x0940
  15844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  15847. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15848. //#0x0980
  15849. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15850. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  15851. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15852. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15853. //#0x09C0
  15854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  15855. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, 0, 0, 0, 0, 7,
  15856. 0, 0, 0, 0, 0, 0, 0, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  15857. 0, 11, 12, 11, 0, 0, 0, 0, 0,143, 0, 0, 0, 0, 0, 0,
  15858. //#0x0a00
  15859. #if PACKETVER >= 20141022
  15860. 269, 3, 0, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 0, 0,
  15861. #else
  15862. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 0, 0,
  15863. #endif
  15864. 0, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  15865. 21, 3, 5, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15867. };
  15868. struct {
  15869. void (*func)(int, struct map_session_data *);
  15870. char *name;
  15871. } clif_parse_func[]={
  15872. {clif_parse_WantToConnection,"wanttoconnection"},
  15873. {clif_parse_LoadEndAck,"loadendack"},
  15874. {clif_parse_TickSend,"ticksend"},
  15875. {clif_parse_WalkToXY,"walktoxy"},
  15876. {clif_parse_QuitGame,"quitgame"},
  15877. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15878. {clif_parse_GlobalMessage,"globalmessage"},
  15879. {clif_parse_MapMove,"mapmove"},
  15880. {clif_parse_ChangeDir,"changedir"},
  15881. {clif_parse_Emotion,"emotion"},
  15882. {clif_parse_HowManyConnections,"howmanyconnections"},
  15883. {clif_parse_ActionRequest,"actionrequest"},
  15884. {clif_parse_Restart,"restart"},
  15885. {clif_parse_WisMessage,"wis"},
  15886. {clif_parse_Broadcast,"broadcast"},
  15887. {clif_parse_TakeItem,"takeitem"},
  15888. {clif_parse_DropItem,"dropitem"},
  15889. {clif_parse_UseItem,"useitem"},
  15890. {clif_parse_EquipItem,"equipitem"},
  15891. {clif_parse_UnequipItem,"unequipitem"},
  15892. {clif_parse_NpcClicked,"npcclicked"},
  15893. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15894. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15895. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15896. {clif_parse_CreateChatRoom,"createchatroom"},
  15897. {clif_parse_ChatAddMember,"chataddmember"},
  15898. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15899. {clif_parse_ChangeChatOwner,"changechatowner"},
  15900. {clif_parse_KickFromChat,"kickfromchat"},
  15901. {clif_parse_ChatLeave,"chatleave"},
  15902. {clif_parse_TradeRequest,"traderequest"},
  15903. {clif_parse_TradeAck,"tradeack"},
  15904. {clif_parse_TradeAddItem,"tradeadditem"},
  15905. {clif_parse_TradeOk,"tradeok"},
  15906. {clif_parse_TradeCancel,"tradecancel"},
  15907. {clif_parse_TradeCommit,"tradecommit"},
  15908. {clif_parse_StopAttack,"stopattack"},
  15909. {clif_parse_PutItemToCart,"putitemtocart"},
  15910. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15911. {clif_parse_RemoveOption,"removeoption"},
  15912. {clif_parse_ChangeCart,"changecart"},
  15913. {clif_parse_StatusUp,"statusup"},
  15914. {clif_parse_SkillUp,"skillup"},
  15915. {clif_parse_UseSkillToId,"useskilltoid"},
  15916. {clif_parse_UseSkillToPos,"useskilltopos"},
  15917. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15918. {clif_parse_UseSkillMap,"useskillmap"},
  15919. {clif_parse_RequestMemo,"requestmemo"},
  15920. {clif_parse_ProduceMix,"producemix"},
  15921. {clif_parse_Cooking,"cooking"},
  15922. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15923. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15924. {clif_parse_NpcAmountInput,"npcamountinput"},
  15925. {clif_parse_NpcStringInput,"npcstringinput"},
  15926. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15927. {clif_parse_ItemIdentify,"itemidentify"},
  15928. {clif_parse_SelectArrow,"selectarrow"},
  15929. {clif_parse_AutoSpell,"autospell"},
  15930. {clif_parse_UseCard,"usecard"},
  15931. {clif_parse_InsertCard,"insertcard"},
  15932. {clif_parse_RepairItem,"repairitem"},
  15933. {clif_parse_WeaponRefine,"weaponrefine"},
  15934. {clif_parse_SolveCharName,"solvecharname"},
  15935. {clif_parse_ResetChar,"resetchar"},
  15936. {clif_parse_LocalBroadcast,"localbroadcast"},
  15937. {clif_parse_MoveToKafra,"movetokafra"},
  15938. {clif_parse_MoveFromKafra,"movefromkafra"},
  15939. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15940. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15941. {clif_parse_CloseKafra,"closekafra"},
  15942. {clif_parse_CreateParty,"createparty"},
  15943. {clif_parse_CreateParty2,"createparty2"},
  15944. {clif_parse_PartyInvite,"partyinvite"},
  15945. {clif_parse_PartyInvite2,"partyinvite2"},
  15946. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15947. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15948. {clif_parse_LeaveParty,"leaveparty"},
  15949. {clif_parse_RemovePartyMember,"removepartymember"},
  15950. {clif_parse_PartyChangeOption,"partychangeoption"},
  15951. {clif_parse_PartyMessage,"partymessage"},
  15952. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15953. {clif_parse_CloseVending,"closevending"},
  15954. {clif_parse_VendingListReq,"vendinglistreq"},
  15955. {clif_parse_PurchaseReq,"purchasereq"},
  15956. {clif_parse_PurchaseReq2,"purchasereq2"},
  15957. {clif_parse_OpenVending,"openvending"},
  15958. {clif_parse_CreateGuild,"createguild"},
  15959. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15960. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15961. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15962. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15963. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15964. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15965. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15966. {clif_parse_GuildInvite,"guildinvite"},
  15967. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15968. {clif_parse_GuildLeave,"guildleave"},
  15969. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15970. {clif_parse_GuildMessage,"guildmessage"},
  15971. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15972. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15973. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15974. {clif_parse_GuildOpposition,"guildopposition"},
  15975. {clif_parse_GuildBreak,"guildbreak"},
  15976. {clif_parse_PetMenu,"petmenu"},
  15977. {clif_parse_CatchPet,"catchpet"},
  15978. {clif_parse_SelectEgg,"selectegg"},
  15979. {clif_parse_SendEmotion,"sendemotion"},
  15980. {clif_parse_ChangePetName,"changepetname"},
  15981. {clif_parse_GMKick,"gmkick"},
  15982. {clif_parse_GMHide,"gmhide"},
  15983. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15984. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15985. {clif_parse_GMKickAll,"killall"},
  15986. {clif_parse_GMRecall,"recall"},
  15987. {clif_parse_GMRecall,"summon"},
  15988. {clif_parse_GM_Item_Monster,"itemmonster"},
  15989. {clif_parse_GMShift,"remove"},
  15990. {clif_parse_GMShift,"shift"},
  15991. {clif_parse_GMChangeMapType,"changemaptype"},
  15992. {clif_parse_GMRc,"rc"},
  15993. {clif_parse_GMRecall2,"recall2"},
  15994. {clif_parse_GMRemove2,"remove2"},
  15995. {clif_parse_GMFullStrip,"gmfullstrip"},
  15996. {clif_parse_NoviceDoriDori,"sndoridori"},
  15997. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15998. {clif_parse_PMIgnore,"wisexin"},
  15999. {clif_parse_PMIgnoreList,"wisexlist"},
  16000. {clif_parse_PMIgnoreAll,"wisall"},
  16001. {clif_parse_FriendsListAdd,"friendslistadd"},
  16002. {clif_parse_FriendsListRemove,"friendslistremove"},
  16003. {clif_parse_FriendsListReply,"friendslistreply"},
  16004. {clif_parse_Blacksmith,"blacksmith"},
  16005. {clif_parse_Alchemist,"alchemist"},
  16006. {clif_parse_Taekwon,"taekwon"},
  16007. {clif_parse_RankingPk,"rankingpk"},
  16008. {clif_parse_FeelSaveOk,"feelsaveok"},
  16009. {clif_parse_debug,"debug"},
  16010. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16011. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16012. {clif_parse_HomMoveTo,"hommoveto"},
  16013. {clif_parse_HomAttack,"homattack"},
  16014. {clif_parse_HomMenu,"hommenu"},
  16015. {clif_parse_StoragePassword,"storagepassword"},
  16016. {clif_parse_Hotkey,"hotkey"},
  16017. {clif_parse_AutoRevive,"autorevive"},
  16018. {clif_parse_Check,"check"},
  16019. {clif_parse_Adopt_request,"adoptrequest"},
  16020. {clif_parse_Adopt_reply,"adoptreply"},
  16021. // MAIL SYSTEM
  16022. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16023. {clif_parse_Mail_read,"mailread"},
  16024. {clif_parse_Mail_getattach,"mailgetattach"},
  16025. {clif_parse_Mail_delete,"maildelete"},
  16026. {clif_parse_Mail_return,"mailreturn"},
  16027. {clif_parse_Mail_setattach,"mailsetattach"},
  16028. {clif_parse_Mail_winopen,"mailwinopen"},
  16029. {clif_parse_Mail_send,"mailsend"},
  16030. // AUCTION SYSTEM
  16031. {clif_parse_Auction_search,"auctionsearch"},
  16032. {clif_parse_Auction_buysell,"auctionbuysell"},
  16033. {clif_parse_Auction_setitem,"auctionsetitem"},
  16034. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16035. {clif_parse_Auction_register,"auctionregister"},
  16036. {clif_parse_Auction_cancel,"auctioncancel"},
  16037. {clif_parse_Auction_close,"auctionclose"},
  16038. {clif_parse_Auction_bid,"auctionbid"},
  16039. // Quest Log System
  16040. {clif_parse_questStateAck,"queststate"},
  16041. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16042. {clif_parse_EquipTick,"equiptickbox"},
  16043. {clif_parse_BattleChat,"battlechat"},
  16044. {clif_parse_mercenary_action,"mermenu"},
  16045. {clif_parse_progressbar,"progressbar"},
  16046. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16047. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16048. #if PACKETVER >= 20091229
  16049. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16050. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16051. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16052. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16053. #endif
  16054. {clif_parse_BankCheck,"bankcheck"},
  16055. {clif_parse_BankDeposit,"bankdeposit"},
  16056. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16057. {clif_parse_BankOpen,"bankopen"},
  16058. {clif_parse_BankClose,"bankclose"},
  16059. {clif_parse_PVPInfo,"pvpinfo"},
  16060. {clif_parse_LessEffect,"lesseffect"},
  16061. // Buying Store
  16062. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16063. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16064. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16065. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16066. // Store Search
  16067. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16068. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16069. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16070. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16071. // Cashshop
  16072. { clif_parse_cashshop_open_request, "cashshopopen" },
  16073. { clif_parse_cashshop_close, "cashshopclose" },
  16074. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16075. { clif_parse_cashshop_buy, "cashshopbuy" },
  16076. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16077. /* */
  16078. { clif_parse_MoveItem , "moveitem" },
  16079. { clif_parse_PartyTick, "partytick" },
  16080. { clif_parse_dull, "dull" },
  16081. { clif_parse_GuildInvite2 , "guildinvite2" },
  16082. { clif_parse_reqworldinfo, "reqworldinfo"},
  16083. { clif_parse_client_version, "clientversion"},
  16084. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16085. { clif_parse_ranklist, "ranklist"},
  16086. // Market NPC
  16087. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16088. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16089. // Roulette
  16090. { clif_parse_RouletteOpen, "rouletteopen" },
  16091. { clif_parse_RouletteInfo, "rouletteinfo" },
  16092. { clif_parse_RouletteClose, "rouletteclose" },
  16093. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16094. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16095. // Merge Item
  16096. { clif_parse_merge_item_req, "mergeitem_req"},
  16097. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16098. // HotkeyRowShift
  16099. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16100. {NULL,NULL}
  16101. };
  16102. struct {
  16103. char *name; //function name
  16104. int funcidx; //
  16105. } clif_ack_func[]={ //hash
  16106. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16107. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16108. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16109. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16110. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16111. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16112. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16113. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16114. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16115. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16116. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16117. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16118. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16119. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16120. };
  16121. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16122. int f;
  16123. memset(packet_db,0,sizeof(packet_db));
  16124. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16125. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16126. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16127. packet_len(i) = packet_len_table[i];
  16128. clif_config.packet_db_ver = MAX_PACKET_VER;
  16129. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16130. FILE *fp;
  16131. int ln = 0;
  16132. int entries = 0;
  16133. char *str[64], *p, *str2[64], *p2;
  16134. sprintf(line, "%s/%s", db_path, filename[f]);
  16135. if( (fp = fopen(line,"r")) == NULL ) {
  16136. if (f == 0) {
  16137. ShowFatalError("Can't read %s\n", line);
  16138. exit(EXIT_FAILURE);
  16139. }
  16140. return;
  16141. }
  16142. while( fgets(line, sizeof(line), fp) ) {
  16143. char w1[256],w2[256];
  16144. ln++;
  16145. if(line[0]=='/' && line[1]=='/')
  16146. continue;
  16147. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16148. if (strcmpi(w1,"packet_ver") == 0) {
  16149. int prev_ver = packet_ver;
  16150. skip_ver = false;
  16151. packet_ver = atoi(w2);
  16152. if ( packet_ver > MAX_PACKET_VER )
  16153. { //Check to avoid overflowing. [Skotlex]
  16154. if( (warned&1) == 0 )
  16155. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16156. warned &= 1;
  16157. skip_ver = true;
  16158. }
  16159. else if( packet_ver < 0 )
  16160. {
  16161. if( (warned&2) == 0 )
  16162. ShowWarning("Negative packet versions are not supported.\n");
  16163. warned &= 2;
  16164. skip_ver = true;
  16165. }
  16166. else if( packet_ver == SERVER )
  16167. {
  16168. if( (warned&4) == 0 )
  16169. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16170. warned &= 4;
  16171. skip_ver = true;
  16172. }
  16173. if( skip_ver )
  16174. {
  16175. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16176. packet_ver = prev_ver;
  16177. continue;
  16178. }
  16179. // copy from previous version into new version and continue
  16180. // - indicating all following packets should be read into the newer version
  16181. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16182. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16183. continue;
  16184. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16185. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16186. clif_config.packet_db_ver = MAX_PACKET_VER;
  16187. else // to manually set the packet DB version
  16188. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16189. continue;
  16190. }
  16191. #ifdef PACKET_OBFUSCATION
  16192. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16193. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16194. trim(w2);
  16195. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16196. if (!packet_keys[packet_ver])
  16197. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16198. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16199. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16200. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16201. last_key_defined = packet_ver;
  16202. if (battle_config.etc_log)
  16203. 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]);
  16204. }
  16205. continue;
  16206. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16207. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16208. trim(w2);
  16209. if (strcmpi(w2,"default") == 0)
  16210. continue;
  16211. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16212. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16213. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16214. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16215. key_defined = true;
  16216. if (battle_config.etc_log)
  16217. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16218. }
  16219. continue;
  16220. }
  16221. #endif
  16222. }
  16223. if( skip_ver )
  16224. continue; // Skipping current packet version
  16225. memset(str,0,sizeof(str));
  16226. for (j = 0, p = line; j < 4 && p; ++j) {
  16227. str[j] = p;
  16228. p = strchr(p,',');
  16229. if (p)
  16230. *p++=0;
  16231. }
  16232. if (str[0] == NULL)
  16233. continue;
  16234. cmd = strtol(str[0],(char **)NULL,0);
  16235. if(max_cmd < cmd)
  16236. max_cmd = cmd;
  16237. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16238. continue;
  16239. if(str[1]==NULL){
  16240. ShowError("packet_db: packet len error\n");
  16241. continue;
  16242. }
  16243. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16244. if(str[2]==NULL){
  16245. packet_db[packet_ver][cmd].func = NULL;
  16246. ln++;
  16247. continue;
  16248. }
  16249. // look up processing function by name
  16250. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16251. if( j < ARRAYLENGTH(clif_parse_func) )
  16252. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16253. else { //search if it's a mapped ack func
  16254. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16255. if( j < ARRAYLENGTH(clif_ack_func)) {
  16256. int fidx = clif_ack_func[j].funcidx;
  16257. packet_db_ack[packet_ver][fidx] = cmd;
  16258. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16259. }
  16260. }
  16261. // set the identifying cmd for the packet_db version
  16262. if (strcmp(str[2],"wanttoconnection")==0)
  16263. clif_config.connect_cmd[packet_ver] = cmd;
  16264. if(str[3]==NULL){
  16265. ShowError("packet_db: packet error\n");
  16266. exit(EXIT_FAILURE);
  16267. }
  16268. for(j = 0, p2 = str[3]; p2; j++){
  16269. short k;
  16270. str2[j] = p2;
  16271. p2 = strchr(p2,':');
  16272. if(p2)
  16273. *p2++=0;
  16274. k = atoi(str2[j]);
  16275. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16276. if( j >= MAX_PACKET_POS )
  16277. {
  16278. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16279. break;
  16280. }
  16281. packet_db[packet_ver][cmd].pos[j] = k;
  16282. }
  16283. entries++;
  16284. }
  16285. fclose(fp);
  16286. if(max_cmd > MAX_PACKET_DB) {
  16287. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16288. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16289. }
  16290. //Locate the nearest version that we still support. [Skotlex]
  16291. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16292. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16293. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16294. }
  16295. sprintf(line, "%s/%s", db_path,filename[f]);
  16296. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16297. }
  16298. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16299. #ifdef PACKET_OBFUSCATION
  16300. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16301. int use_key = last_key_defined;
  16302. if (last_key_defined == -1)
  16303. ShowError("Can't find packet obfuscation keys!\n");
  16304. else {
  16305. if (packet_keys[clif_config.packet_db_ver])
  16306. use_key = clif_config.packet_db_ver;
  16307. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16308. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16309. }
  16310. }
  16311. 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]);
  16312. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16313. if (packet_keys[i]) {
  16314. aFree(packet_keys[i]);
  16315. packet_keys[i] = NULL;
  16316. }
  16317. }
  16318. #endif
  16319. }
  16320. /*==========================================
  16321. *
  16322. *------------------------------------------*/
  16323. void do_init_clif(void) {
  16324. const char* colors[COLOR_MAX] = {
  16325. "0x00FF00",
  16326. "0xFF0000",
  16327. "0xFFFFFF",
  16328. "0xFFFF00",
  16329. };
  16330. int i;
  16331. /**
  16332. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16333. **/
  16334. for(i = 0; i < COLOR_MAX; i++) {
  16335. color_table[i] = strtoul(colors[i],NULL,0);
  16336. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16337. }
  16338. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16339. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16340. #ifdef PACKET_OBFUSCATION
  16341. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16342. #endif
  16343. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16344. packetdb_readdb(false);
  16345. set_defaultparse(clif_parse);
  16346. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16347. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16348. exit(EXIT_FAILURE);
  16349. }
  16350. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16351. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16352. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16353. }
  16354. void do_final_clif(void) {
  16355. ers_destroy(delay_clearunit_ers);
  16356. }