clif.c 541 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943
  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)=min(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. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1354. hd = sd->hd;
  1355. if ( !hd )
  1356. return 0 ;
  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 cmd = RFIFOW(fd,0), 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. #if PACKETVER == 20141022
  5047. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5048. /** so we redirect to ZC_NPC_CHAT **/
  5049. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5050. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5051. unsigned short len = strnlen(mes, CHAT_SIZE_MAX);
  5052. if (len > 0) {
  5053. WFIFOHEAD(fd, 13 + len);
  5054. WFIFOW(fd, 0) = 0x2C1;
  5055. WFIFOW(fd, 2) = 13 + len;
  5056. WFIFOL(fd, 4) = 0;
  5057. WFIFOL(fd, 8) = color;
  5058. safestrncpy((char*)WFIFOP(fd, 12), mes, len+1);
  5059. WFIFOSET(fd, WFIFOW(fd, 2));
  5060. }
  5061. #else
  5062. char *message, *line;
  5063. message = aStrdup(mes);
  5064. line = strtok(message, "\n");
  5065. while(line != NULL) {
  5066. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5067. int len = strnlen(line, 255);
  5068. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5069. WFIFOHEAD(fd, 5 + len);
  5070. WFIFOW(fd,0) = 0x8e;
  5071. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5072. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5073. WFIFOSET(fd, 5 + len);
  5074. }
  5075. line = strtok(NULL, "\n");
  5076. }
  5077. aFree(message);
  5078. #endif
  5079. }
  5080. }
  5081. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5082. /// 009a <packet len>.W <message>.?B
  5083. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5084. {
  5085. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5086. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5087. WBUFW(buf,0) = 0x9a;
  5088. WBUFW(buf,2) = 4 + lp + len;
  5089. if (type&BC_BLUE)
  5090. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5091. else if (type&BC_WOE)
  5092. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5093. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5094. clif_send(buf, WBUFW(buf,2), bl, target);
  5095. if (buf)
  5096. aFree(buf);
  5097. }
  5098. /*==========================================
  5099. * Displays a message on a 'bl' to all it's nearby clients
  5100. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5101. *------------------------------------------*/
  5102. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5103. char buf[100];
  5104. int len;
  5105. nullpo_retv(bl);
  5106. if(!message)
  5107. return;
  5108. len = strlen(message)+1;
  5109. if( len > sizeof(buf)-8 ) {
  5110. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5111. len = sizeof(buf)-8;
  5112. }
  5113. WBUFW(buf,0)=0x8d;
  5114. WBUFW(buf,2)=len+8;
  5115. WBUFL(buf,4)=bl->id;
  5116. safestrncpy((char *) WBUFP(buf,8),message,len);
  5117. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5118. }
  5119. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5120. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5121. 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)
  5122. {
  5123. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5124. WBUFW(buf,0) = 0x1c3;
  5125. WBUFW(buf,2) = len + 16;
  5126. WBUFL(buf,4) = fontColor;
  5127. WBUFW(buf,8) = fontType;
  5128. WBUFW(buf,10) = fontSize;
  5129. WBUFW(buf,12) = fontAlign;
  5130. WBUFW(buf,14) = fontY;
  5131. memcpy(WBUFP(buf,16), mes, len);
  5132. clif_send(buf, WBUFW(buf,2), bl, target);
  5133. if (buf)
  5134. aFree(buf);
  5135. }
  5136. /*
  5137. * Display *msg from *sd to all *users in channel
  5138. */
  5139. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5140. DBIterator *iter;
  5141. struct map_session_data *user;
  5142. unsigned short msg_len = strlen(msg) + 1;
  5143. WFIFOHEAD(sd->fd,msg_len + 12);
  5144. WFIFOW(sd->fd,0) = 0x2C1;
  5145. WFIFOW(sd->fd,2) = msg_len + 12;
  5146. WFIFOL(sd->fd,4) = 0;
  5147. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5148. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5149. iter = db_iterator(channel->users);
  5150. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  5151. if( user->fd == sd->fd )
  5152. continue;
  5153. WFIFOHEAD(user->fd,msg_len + 12);
  5154. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5155. WFIFOSET(user->fd, msg_len + 12);
  5156. }
  5157. dbi_destroy(iter);
  5158. WFIFOSET(sd->fd, msg_len + 12);
  5159. }
  5160. /// Displays heal effect (ZC_RECOVERY).
  5161. /// 013d <var id>.W <amount>.W
  5162. /// var id:
  5163. /// 5 = HP (SP_HP)
  5164. /// 7 = SP (SP_SP)
  5165. /// ? = ignored
  5166. void clif_heal(int fd,int type,int val)
  5167. {
  5168. WFIFOHEAD(fd,packet_len(0x13d));
  5169. WFIFOW(fd,0)=0x13d;
  5170. WFIFOW(fd,2)=type;
  5171. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  5172. WFIFOSET(fd,packet_len(0x13d));
  5173. }
  5174. /// Displays resurrection effect (ZC_RESURRECTION).
  5175. /// 0148 <id>.L <type>.W
  5176. /// type:
  5177. /// ignored
  5178. void clif_resurrection(struct block_list *bl,int type)
  5179. {
  5180. unsigned char buf[16];
  5181. nullpo_retv(bl);
  5182. WBUFW(buf,0)=0x148;
  5183. WBUFL(buf,2)=bl->id;
  5184. WBUFW(buf,6)=0;
  5185. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5186. if (disguised(bl))
  5187. clif_spawn(bl);
  5188. }
  5189. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5190. /// 0199 <type>.W
  5191. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5192. {
  5193. int fd;
  5194. nullpo_retv(sd);
  5195. fd=sd->fd;
  5196. WFIFOHEAD(fd,packet_len(0x199));
  5197. WFIFOW(fd,0)=0x199;
  5198. WFIFOW(fd,2)=property;
  5199. WFIFOSET(fd,packet_len(0x199));
  5200. }
  5201. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5202. #if PACKETVER >= 20121010
  5203. unsigned char buf[8];
  5204. unsigned int NotifyProperty =
  5205. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5206. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5207. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5208. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5209. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5210. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5211. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5212. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5213. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5214. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5215. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5216. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5217. WBUFW(buf,0)=0x99b;
  5218. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5219. WBUFL(buf,4)=NotifyProperty;
  5220. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5221. clif_send(buf,packet_len(0x99b),bl,t);
  5222. #endif
  5223. }
  5224. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5225. /// 01d6 <type>.W
  5226. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5227. {
  5228. int fd;
  5229. nullpo_retv(sd);
  5230. fd=sd->fd;
  5231. WFIFOHEAD(fd,packet_len(0x1D6));
  5232. WFIFOW(fd,0)=0x1D6;
  5233. WFIFOW(fd,2)=type;
  5234. WFIFOSET(fd,packet_len(0x1D6));
  5235. }
  5236. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5237. /// 019a <id>.L <ranking>.L <total>.L
  5238. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5239. {
  5240. if(type == 2) {
  5241. int fd = sd->fd;
  5242. WFIFOHEAD(fd,packet_len(0x19a));
  5243. WFIFOW(fd,0) = 0x19a;
  5244. WFIFOL(fd,2) = sd->bl.id;
  5245. WFIFOL(fd,6) = pvprank;
  5246. WFIFOL(fd,10) = pvpnum;
  5247. WFIFOSET(fd,packet_len(0x19a));
  5248. } else {
  5249. unsigned char buf[32];
  5250. WBUFW(buf,0) = 0x19a;
  5251. WBUFL(buf,2) = sd->bl.id;
  5252. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5253. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5254. else
  5255. WBUFL(buf,6) = pvprank;
  5256. WBUFL(buf,10) = pvpnum;
  5257. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5258. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5259. else if(!type)
  5260. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5261. else
  5262. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5263. }
  5264. }
  5265. /*==========================================
  5266. *
  5267. *------------------------------------------*/
  5268. void clif_map_property_mapall(int map_idx, enum map_property property)
  5269. {
  5270. struct block_list bl;
  5271. unsigned char buf[16];
  5272. bl.id = 0;
  5273. bl.type = BL_NUL;
  5274. bl.m = map_idx;
  5275. WBUFW(buf,0)=0x199;
  5276. WBUFW(buf,2)=property;
  5277. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5278. }
  5279. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5280. /// 0188 <result>.W <index>.W <refine>.W
  5281. /// result:
  5282. /// 0 = success
  5283. /// 1 = failure
  5284. /// 2 = downgrade
  5285. void clif_refine(int fd, int fail, int index, int val)
  5286. {
  5287. WFIFOHEAD(fd,packet_len(0x188));
  5288. WFIFOW(fd,0)=0x188;
  5289. WFIFOW(fd,2)=fail;
  5290. WFIFOW(fd,4)=index+2;
  5291. WFIFOW(fd,6)=val;
  5292. WFIFOSET(fd,packet_len(0x188));
  5293. }
  5294. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5295. /// 0223 <result>.L <nameid>.W
  5296. /// result:
  5297. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5298. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5299. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5300. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5301. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5302. {
  5303. WFIFOHEAD(fd,packet_len(0x223));
  5304. WFIFOW(fd,0)=0x223;
  5305. WFIFOL(fd,2)=result;
  5306. WFIFOW(fd,6)=item_id;
  5307. WFIFOSET(fd,packet_len(0x223));
  5308. }
  5309. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5310. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5311. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5312. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5313. {
  5314. #if PACKETVER < 20091104
  5315. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5316. WFIFOW(fd,0) = 0x97;
  5317. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5318. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5319. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5320. WFIFOSET(fd,WFIFOW(fd,2));
  5321. #else
  5322. struct map_session_data *ssd = map_nick2sd(nick);
  5323. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5324. WFIFOW(fd,0) = 0x97;
  5325. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5326. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5327. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5328. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5329. WFIFOSET(fd,WFIFOW(fd,2));
  5330. #endif
  5331. }
  5332. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5333. /// 0098 <result>.B
  5334. /// result:
  5335. /// 0 = success to send wisper
  5336. /// 1 = target character is not loged in
  5337. /// 2 = ignored by target
  5338. /// 3 = everyone ignored by target
  5339. void clif_wis_end(int fd, int result)
  5340. {
  5341. struct map_session_data *sd = (session_isValid(fd) ? session[fd]->session_data : NULL);
  5342. if (!sd)
  5343. return;
  5344. #if PACKETVER >= 20131223
  5345. WFIFOHEAD(fd,packet_len(0x9df));
  5346. WFIFOW(fd,0) = 0x9df;
  5347. WFIFOB(fd,2) = (char)result;
  5348. WFIFOL(fd,3) = 0;
  5349. WFIFOSET(fd,packet_len(0x9df));
  5350. #else
  5351. WFIFOHEAD(fd,packet_len(0x98));
  5352. WFIFOW(fd,0) = 0x98;
  5353. WFIFOB(fd,2) = (char)result;
  5354. WFIFOSET(fd,packet_len(0x98));
  5355. #endif
  5356. }
  5357. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5358. /// 0194 <char id>.L <name>.24B
  5359. void clif_solved_charname(int fd, int charid, const char* name)
  5360. {
  5361. WFIFOHEAD(fd,packet_len(0x194));
  5362. WFIFOW(fd,0)=0x194;
  5363. WFIFOL(fd,2)=charid;
  5364. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5365. WFIFOSET(fd,packet_len(0x194));
  5366. }
  5367. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5368. /// 017b <packet len>.W { <name id>.W }*
  5369. void clif_use_card(struct map_session_data *sd,int idx)
  5370. {
  5371. int i,c,ep;
  5372. int fd=sd->fd;
  5373. nullpo_retv(sd);
  5374. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5375. return;
  5376. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5377. return; //Avoid parsing invalid item indexes (no card/no item)
  5378. ep=sd->inventory_data[idx]->equip;
  5379. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5380. WFIFOW(fd,0)=0x17b;
  5381. for(i=c=0;i<MAX_INVENTORY;i++){
  5382. int j;
  5383. if(sd->inventory_data[i] == NULL)
  5384. continue;
  5385. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5386. continue;
  5387. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5388. continue;
  5389. if(sd->status.inventory[i].identify==0 ) //Not identified
  5390. continue;
  5391. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5392. continue;
  5393. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5394. continue;
  5395. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5396. if( j == sd->inventory_data[i]->slot ) // No room
  5397. continue;
  5398. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5399. continue;
  5400. WFIFOW(fd,4+c*2)=i+2;
  5401. c++;
  5402. }
  5403. if( !c ) return; // no item is available for card insertion
  5404. WFIFOW(fd,2)=4+c*2;
  5405. WFIFOSET(fd,WFIFOW(fd,2));
  5406. }
  5407. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5408. /// 017d <equip index>.W <card index>.W <result>.B
  5409. /// result:
  5410. /// 0 = success
  5411. /// 1 = failure
  5412. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5413. {
  5414. int fd;
  5415. nullpo_retv(sd);
  5416. fd=sd->fd;
  5417. WFIFOHEAD(fd,packet_len(0x17d));
  5418. WFIFOW(fd,0)=0x17d;
  5419. WFIFOW(fd,2)=idx_equip+2;
  5420. WFIFOW(fd,4)=idx_card+2;
  5421. WFIFOB(fd,6)=flag;
  5422. WFIFOSET(fd,packet_len(0x17d));
  5423. }
  5424. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5425. /// 0177 <packet len>.W { <name id>.W }*
  5426. void clif_item_identify_list(struct map_session_data *sd)
  5427. {
  5428. int i,c;
  5429. int fd;
  5430. nullpo_retv(sd);
  5431. fd=sd->fd;
  5432. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5433. WFIFOW(fd,0)=0x177;
  5434. for(i=c=0;i<MAX_INVENTORY;i++){
  5435. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5436. WFIFOW(fd,c*2+4)=i+2;
  5437. c++;
  5438. }
  5439. }
  5440. if(c > 0) {
  5441. WFIFOW(fd,2)=c*2+4;
  5442. WFIFOSET(fd,WFIFOW(fd,2));
  5443. sd->menuskill_id = MC_IDENTIFY;
  5444. sd->menuskill_val = c;
  5445. }
  5446. }
  5447. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5448. /// 0179 <index>.W <result>.B
  5449. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5450. {
  5451. int fd;
  5452. nullpo_retv(sd);
  5453. fd=sd->fd;
  5454. WFIFOHEAD(fd,packet_len(0x179));
  5455. WFIFOW(fd, 0)=0x179;
  5456. WFIFOW(fd, 2)=idx+2;
  5457. WFIFOB(fd, 4)=flag;
  5458. WFIFOSET(fd,packet_len(0x179));
  5459. }
  5460. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5461. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5462. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5463. {
  5464. int i,c;
  5465. int fd;
  5466. nullpo_retv(sd);
  5467. nullpo_retv(dstsd);
  5468. fd=sd->fd;
  5469. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5470. WFIFOW(fd,0)=0x1fc;
  5471. for(i=c=0;i<MAX_INVENTORY;i++){
  5472. unsigned short nameid;
  5473. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5474. WFIFOW(fd,c*13+4) = i;
  5475. WFIFOW(fd,c*13+6) = nameid;
  5476. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5477. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5478. c++;
  5479. }
  5480. }
  5481. if(c > 0) {
  5482. WFIFOW(fd,2)=c*13+4;
  5483. WFIFOSET(fd,WFIFOW(fd,2));
  5484. sd->menuskill_id = BS_REPAIRWEAPON;
  5485. sd->menuskill_val = dstsd->bl.id;
  5486. sd->menuskill_val2 = lv;
  5487. }else
  5488. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5489. }
  5490. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5491. /// 01fe <index>.W <result>.B
  5492. /// index:
  5493. /// ignored (inventory index)
  5494. /// result:
  5495. /// 0 = Item repair success.
  5496. /// 1 = Item repair failure.
  5497. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5498. {
  5499. int fd;
  5500. nullpo_retv(sd);
  5501. fd = sd->fd;
  5502. WFIFOHEAD(fd,packet_len(0x1fe));
  5503. WFIFOW(fd, 0)=0x1fe;
  5504. WFIFOW(fd, 2)=idx+2;
  5505. WFIFOB(fd, 4)=flag;
  5506. WFIFOSET(fd,packet_len(0x1fe));
  5507. }
  5508. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5509. /// 02bb <equip location>.W <account id>.L
  5510. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5511. {
  5512. int fd = sd->fd;
  5513. WFIFOHEAD(fd,packet_len(0x2bb));
  5514. WFIFOW(fd,0) = 0x2bb;
  5515. WFIFOW(fd,2) = position;
  5516. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5517. WFIFOSET(fd,packet_len(0x2bb));
  5518. }
  5519. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5520. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5521. void clif_item_refine_list(struct map_session_data *sd)
  5522. {
  5523. int i,c;
  5524. int fd;
  5525. uint16 skill_lv;
  5526. int refine_item[5];
  5527. nullpo_retv(sd);
  5528. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5529. fd=sd->fd;
  5530. refine_item[0] = -1;
  5531. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5532. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5533. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5534. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5535. WFIFOW(fd,0)=0x221;
  5536. for(i=c=0;i<MAX_INVENTORY;i++){
  5537. unsigned char wlv;
  5538. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5539. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5540. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5541. WFIFOW(fd,c*13+ 4)=i+2;
  5542. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5543. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5544. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5545. c++;
  5546. }
  5547. }
  5548. WFIFOW(fd,2)=c*13+4;
  5549. WFIFOSET(fd,WFIFOW(fd,2));
  5550. if (c > 0) {
  5551. sd->menuskill_id = WS_WEAPONREFINE;
  5552. sd->menuskill_val = skill_lv;
  5553. }
  5554. }
  5555. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5556. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5557. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5558. {
  5559. int fd;
  5560. nullpo_retv(sd);
  5561. fd=sd->fd;
  5562. WFIFOHEAD(fd,packet_len(0x147));
  5563. WFIFOW(fd, 0)=0x147;
  5564. WFIFOW(fd, 2)=skill_id;
  5565. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5566. WFIFOW(fd, 6)=0;
  5567. WFIFOW(fd, 8)=skill_lv;
  5568. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5569. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5570. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5571. WFIFOB(fd,38)=0;
  5572. WFIFOSET(fd,packet_len(0x147));
  5573. }
  5574. /// Adds an item to character's cart.
  5575. /// 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)
  5576. /// 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)
  5577. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5578. {
  5579. int view,fd;
  5580. unsigned char *buf;
  5581. nullpo_retv(sd);
  5582. fd=sd->fd;
  5583. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5584. return;
  5585. #if PACKETVER < 5
  5586. WFIFOHEAD(fd,packet_len(0x124));
  5587. buf=WFIFOP(fd,0);
  5588. WBUFW(buf,0)=0x124;
  5589. WBUFW(buf,2)=n+2;
  5590. WBUFL(buf,4)=amount;
  5591. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5592. WBUFW(buf,8)=view;
  5593. else
  5594. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5595. WBUFB(buf,10)=sd->status.cart[n].identify;
  5596. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5597. WBUFB(buf,12)=sd->status.cart[n].refine;
  5598. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5599. WFIFOSET(fd,packet_len(0x124));
  5600. #else
  5601. WFIFOHEAD(fd,packet_len(0x1c5));
  5602. buf=WFIFOP(fd,0);
  5603. WBUFW(buf,0)=0x1c5;
  5604. WBUFW(buf,2)=n+2;
  5605. WBUFL(buf,4)=amount;
  5606. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5607. WBUFW(buf,8)=view;
  5608. else
  5609. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5610. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5611. WBUFB(buf,11)=sd->status.cart[n].identify;
  5612. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5613. WBUFB(buf,13)=sd->status.cart[n].refine;
  5614. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5615. WFIFOSET(fd,packet_len(0x1c5));
  5616. #endif
  5617. }
  5618. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5619. /* Acknowledge an item have been added to cart
  5620. * 012c <result>B
  5621. * result :
  5622. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5623. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5624. */
  5625. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5626. {
  5627. int fd;
  5628. unsigned char *buf;
  5629. nullpo_retv(sd);
  5630. fd = sd->fd;
  5631. buf = WFIFOP(fd,0);
  5632. WBUFW(buf,0) = 0x12c;
  5633. WBUFB(buf,2) = flag;
  5634. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5635. }
  5636. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5637. void clif_bank_open(struct map_session_data *sd){
  5638. int fd;
  5639. nullpo_retv(sd);
  5640. fd = sd->fd;
  5641. WFIFOHEAD(fd,4);
  5642. WFIFOW(fd,0) = 0x09b7;
  5643. WFIFOW(fd,2) = 0;
  5644. WFIFOSET(fd,4);
  5645. }
  5646. /*
  5647. * Request to Open the banking system
  5648. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5649. */
  5650. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5651. //TODO check if preventing trade or stuff like that
  5652. //also mark something in case char ain't available for saving, should we check now ?
  5653. nullpo_retv(sd);
  5654. if( !battle_config.feature_banking ) {
  5655. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5656. return;
  5657. }
  5658. else {
  5659. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5660. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5661. if(sd->status.account_id == aid){
  5662. sd->state.banking = 1;
  5663. //request save ?
  5664. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5665. //on succes open bank ?
  5666. clif_bank_open(sd);
  5667. }
  5668. }
  5669. }
  5670. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5671. void clif_bank_close(struct map_session_data *sd){
  5672. int fd;
  5673. nullpo_retv(sd);
  5674. fd = sd->fd;
  5675. WFIFOHEAD(fd,4);
  5676. WFIFOW(fd,0) = 0x09B9;
  5677. WFIFOW(fd,2) = 0;
  5678. WFIFOSET(fd,4);
  5679. }
  5680. /*
  5681. * Request to close the banking system
  5682. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5683. */
  5684. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5685. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5686. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5687. nullpo_retv(sd);
  5688. if( !battle_config.feature_banking ) {
  5689. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5690. //still allow to go trough to not stuck player if we have disable it while they was in
  5691. }
  5692. if(sd->status.account_id == aid){
  5693. sd->state.banking = 0;
  5694. clif_bank_close(sd);
  5695. }
  5696. }
  5697. /*
  5698. * Display how much we got in bank (I suppose)
  5699. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5700. */
  5701. void clif_Bank_Check(struct map_session_data* sd) {
  5702. unsigned char buf[13];
  5703. struct s_packet_db* info;
  5704. int16 len;
  5705. int cmd = 0;
  5706. nullpo_retv(sd);
  5707. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5708. if(!cmd) cmd = 0x09A6; //default
  5709. info = &packet_db[sd->packet_ver][cmd];
  5710. len = info->len;
  5711. if(!len) return; //version as packet disable
  5712. // sd->state.banking = 1; //mark opening and closing
  5713. WBUFW(buf,0) = cmd;
  5714. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5715. WBUFW(buf,info->pos[1]) = 0; //reason
  5716. clif_send(buf,len,&sd->bl,SELF);
  5717. }
  5718. /*
  5719. * Requesting the data in bank
  5720. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5721. */
  5722. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5723. nullpo_retv(sd);
  5724. if( !battle_config.feature_banking ) {
  5725. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5726. return;
  5727. }
  5728. else {
  5729. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5730. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5731. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5732. clif_Bank_Check(sd);
  5733. }
  5734. }
  5735. /*
  5736. * Acknowledge of deposit some money in bank
  5737. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5738. */
  5739. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5740. unsigned char buf[17];
  5741. struct s_packet_db* info;
  5742. int16 len;
  5743. int cmd =0;
  5744. nullpo_retv(sd);
  5745. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5746. if(!cmd) cmd = 0x09A8;
  5747. info = &packet_db[sd->packet_ver][cmd];
  5748. len = info->len;
  5749. if(!len) return; //version as packet disable
  5750. WBUFW(buf,0) = cmd;
  5751. WBUFW(buf,info->pos[0]) = (short)reason;
  5752. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5753. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5754. clif_send(buf,len,&sd->bl,SELF);
  5755. }
  5756. /*
  5757. * Request saving some money in bank
  5758. * @author : original [Yommy/Hercules]
  5759. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5760. */
  5761. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5762. nullpo_retv(sd);
  5763. if( !battle_config.feature_banking ) {
  5764. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5765. return;
  5766. }
  5767. else {
  5768. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5769. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5770. int money = RFIFOL(fd,info->pos[1]);
  5771. if(sd->status.account_id == aid){
  5772. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5773. clif_bank_deposit(sd,reason);
  5774. }
  5775. }
  5776. }
  5777. /*
  5778. * Acknowledge of withdrawing some money from bank
  5779. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5780. */
  5781. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5782. unsigned char buf[17];
  5783. struct s_packet_db* info;
  5784. int16 len;
  5785. int cmd;
  5786. nullpo_retv(sd);
  5787. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5788. if(!cmd) cmd = 0x09AA;
  5789. info = &packet_db[sd->packet_ver][cmd];
  5790. len = info->len;
  5791. if(!len) return; //version as packet disable
  5792. WBUFW(buf,0) = cmd;
  5793. WBUFW(buf,info->pos[0]) = (short)reason;
  5794. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5795. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5796. clif_send(buf,len,&sd->bl,SELF);
  5797. }
  5798. /*
  5799. * Request Withdrawing some money from bank
  5800. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5801. */
  5802. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5803. nullpo_retv(sd);
  5804. if( !battle_config.feature_banking ) {
  5805. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5806. return;
  5807. }
  5808. else {
  5809. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5810. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5811. int money = RFIFOL(fd,info->pos[1]);
  5812. if(sd->status.account_id == aid){
  5813. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5814. clif_bank_withdraw(sd,reason);
  5815. }
  5816. }
  5817. }
  5818. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5819. /// 0125 <index>.W <amount>.L
  5820. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5821. {
  5822. int fd;
  5823. nullpo_retv(sd);
  5824. fd=sd->fd;
  5825. WFIFOHEAD(fd,packet_len(0x125));
  5826. WFIFOW(fd,0)=0x125;
  5827. WFIFOW(fd,2)=n+2;
  5828. WFIFOL(fd,4)=amount;
  5829. WFIFOSET(fd,packet_len(0x125));
  5830. }
  5831. /// Opens the shop creation menu (ZC_OPENSTORE).
  5832. /// 012d <num>.W
  5833. /// num:
  5834. /// number of allowed item slots
  5835. void clif_openvendingreq(struct map_session_data* sd, int num)
  5836. {
  5837. int fd;
  5838. nullpo_retv(sd);
  5839. fd = sd->fd;
  5840. WFIFOHEAD(fd,packet_len(0x12d));
  5841. WFIFOW(fd,0) = 0x12d;
  5842. WFIFOW(fd,2) = num;
  5843. WFIFOSET(fd,packet_len(0x12d));
  5844. }
  5845. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5846. /// 0131 <owner id>.L <message>.80B
  5847. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5848. {
  5849. unsigned char buf[128];
  5850. nullpo_retv(bl);
  5851. WBUFW(buf,0) = 0x131;
  5852. WBUFL(buf,2) = bl->id;
  5853. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5854. if( fd ) {
  5855. WFIFOHEAD(fd,packet_len(0x131));
  5856. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5857. WFIFOSET(fd,packet_len(0x131));
  5858. } else {
  5859. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5860. }
  5861. }
  5862. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5863. /// 0132 <owner id>.L
  5864. void clif_closevendingboard(struct block_list* bl, int fd)
  5865. {
  5866. unsigned char buf[16];
  5867. nullpo_retv(bl);
  5868. WBUFW(buf,0) = 0x132;
  5869. WBUFL(buf,2) = bl->id;
  5870. if( fd ) {
  5871. WFIFOHEAD(fd,packet_len(0x132));
  5872. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5873. WFIFOSET(fd,packet_len(0x132));
  5874. } else {
  5875. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5876. }
  5877. }
  5878. /// Sends a list of items in a shop.
  5879. /// 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)
  5880. /// 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)
  5881. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5882. {
  5883. int i,fd;
  5884. int count;
  5885. struct map_session_data* vsd;
  5886. #if PACKETVER < 20100105
  5887. const int cmd = 0x133;
  5888. const int offset = 8;
  5889. #else
  5890. const int cmd = 0x800;
  5891. const int offset = 12;
  5892. #endif
  5893. nullpo_retv(sd);
  5894. nullpo_retv(vending);
  5895. nullpo_retv(vsd=map_id2sd(id));
  5896. fd = sd->fd;
  5897. count = vsd->vend_num;
  5898. WFIFOHEAD(fd, offset+count*22);
  5899. WFIFOW(fd,0) = cmd;
  5900. WFIFOW(fd,2) = offset+count*22;
  5901. WFIFOL(fd,4) = id;
  5902. #if PACKETVER >= 20100105
  5903. WFIFOL(fd,8) = vsd->vender_id;
  5904. #endif
  5905. for( i = 0; i < count; i++ )
  5906. {
  5907. int index = vending[i].index;
  5908. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5909. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5910. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5911. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5912. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5913. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5914. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5915. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5916. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5917. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5918. }
  5919. WFIFOSET(fd,WFIFOW(fd,2));
  5920. }
  5921. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5922. /// 0135 <index>.W <amount>.W <result>.B
  5923. /// result:
  5924. /// 0 = success
  5925. /// 1 = not enough zeny
  5926. /// 2 = overweight
  5927. /// 4 = out of stock
  5928. /// 5 = "cannot use an npc shop while in a trade"
  5929. /// 6 = Because the store information was incorrect the item was not purchased.
  5930. /// 7 = No sales information.
  5931. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5932. {
  5933. int fd;
  5934. nullpo_retv(sd);
  5935. fd = sd->fd;
  5936. WFIFOHEAD(fd,packet_len(0x135));
  5937. WFIFOW(fd,0) = 0x135;
  5938. WFIFOW(fd,2) = index+2;
  5939. WFIFOW(fd,4) = amount;
  5940. WFIFOB(fd,6) = fail;
  5941. WFIFOSET(fd,packet_len(0x135));
  5942. }
  5943. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5944. /// 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 }*
  5945. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5946. {
  5947. int i,fd;
  5948. int count;
  5949. nullpo_retv(sd);
  5950. fd = sd->fd;
  5951. count = sd->vend_num;
  5952. WFIFOHEAD(fd, 8+count*22);
  5953. WFIFOW(fd,0) = 0x136;
  5954. WFIFOW(fd,2) = 8+count*22;
  5955. WFIFOL(fd,4) = id;
  5956. for( i = 0; i < count; i++ ) {
  5957. int index = vending[i].index;
  5958. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5959. WFIFOL(fd, 8+i*22) = vending[i].value;
  5960. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5961. WFIFOW(fd,14+i*22) = vending[i].amount;
  5962. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5963. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5964. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5965. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5966. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5967. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5968. }
  5969. WFIFOSET(fd,WFIFOW(fd,2));
  5970. #if PACKETVER >= 20141022
  5971. // Should go elsewhere perhaps? It has to be bundled with this however.
  5972. WFIFOHEAD(fd, 3);
  5973. WFIFOW(fd, 0) = 0xa28;
  5974. WFIFOB(fd, 2) = 0; // 1 is failure. Our current responses to failure are working so not yet implemented.
  5975. WFIFOSET(fd, 3);
  5976. #endif
  5977. }
  5978. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5979. /// 0137 <index>.W <amount>.W
  5980. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5981. {
  5982. int fd;
  5983. nullpo_retv(sd);
  5984. fd = sd->fd;
  5985. WFIFOHEAD(fd,packet_len(0x137));
  5986. WFIFOW(fd,0) = 0x137;
  5987. WFIFOW(fd,2) = index+2;
  5988. WFIFOW(fd,4) = amount;
  5989. WFIFOSET(fd,packet_len(0x137));
  5990. }
  5991. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5992. /// 00fa <result>.B
  5993. /// result:
  5994. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5995. /// 1 = MsgStringTable[78]="party name already exists"
  5996. /// 2 = MsgStringTable[79]="already in a party"
  5997. /// 3 = cannot organize parties on this map
  5998. /// ? = nothing
  5999. void clif_party_created(struct map_session_data *sd,int result)
  6000. {
  6001. int fd;
  6002. nullpo_retv(sd);
  6003. fd=sd->fd;
  6004. WFIFOHEAD(fd,packet_len(0xfa));
  6005. WFIFOW(fd,0)=0xfa;
  6006. WFIFOB(fd,2)=result;
  6007. WFIFOSET(fd,packet_len(0xfa));
  6008. }
  6009. /// Adds new member to a party.
  6010. /// 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)
  6011. /// 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)
  6012. /// role:
  6013. /// 0 = leader
  6014. /// 1 = normal
  6015. /// state:
  6016. /// 0 = connected
  6017. /// 1 = disconnected
  6018. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6019. {
  6020. unsigned char buf[81];
  6021. int i;
  6022. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6023. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6024. } else {
  6025. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6026. }
  6027. if (i >= MAX_PARTY) return; //Should never happen...
  6028. sd = p->data[i].sd;
  6029. WBUFW(buf, 0) = 0x1e9;
  6030. WBUFL(buf, 2) = sd->status.account_id;
  6031. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6032. WBUFW(buf,10) = sd->bl.x;
  6033. WBUFW(buf,12) = sd->bl.y;
  6034. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6035. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6036. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6037. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6038. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6039. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6040. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6041. }
  6042. /// Sends party information (ZC_GROUP_LIST).
  6043. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6044. /// role:
  6045. /// 0 = leader
  6046. /// 1 = normal
  6047. /// state:
  6048. /// 0 = connected
  6049. /// 1 = disconnected
  6050. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6051. {
  6052. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6053. struct map_session_data* party_sd = NULL;
  6054. int i, c;
  6055. nullpo_retv(p);
  6056. WBUFW(buf,0) = 0xfb;
  6057. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6058. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6059. {
  6060. struct party_member* m = &p->party.member[i];
  6061. if(!m->account_id) continue;
  6062. if(party_sd == NULL) party_sd = p->data[i].sd;
  6063. WBUFL(buf,28+c*46) = m->account_id;
  6064. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6065. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6066. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6067. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6068. c++;
  6069. }
  6070. WBUFW(buf,2) = 28+c*46;
  6071. if(sd) { // send only to self
  6072. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6073. } else if (party_sd) { // send to whole party
  6074. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6075. }
  6076. }
  6077. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6078. /// 02c9 <flag>.B
  6079. /// flag:
  6080. /// 0 = allow party invites
  6081. /// 1 = auto-deny party invites
  6082. void clif_partyinvitationstate(struct map_session_data* sd)
  6083. {
  6084. int fd;
  6085. nullpo_retv(sd);
  6086. fd = sd->fd;
  6087. WFIFOHEAD(fd, packet_len(0x2c9));
  6088. WFIFOW(fd, 0) = 0x2c9;
  6089. WFIFOB(fd, 2) = 0; // not implemented
  6090. WFIFOSET(fd, packet_len(0x2c9));
  6091. }
  6092. /// Party invitation request.
  6093. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6094. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6095. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6096. {
  6097. #if PACKETVER < 20070821
  6098. const int cmd = 0xfe;
  6099. #else
  6100. const int cmd = 0x2c6;
  6101. #endif
  6102. int fd;
  6103. struct party_data *p;
  6104. nullpo_retv(sd);
  6105. nullpo_retv(tsd);
  6106. fd=tsd->fd;
  6107. if( (p=party_search(sd->status.party_id))==NULL )
  6108. return;
  6109. WFIFOHEAD(fd,packet_len(cmd));
  6110. WFIFOW(fd,0)=cmd;
  6111. WFIFOL(fd,2)=sd->status.party_id;
  6112. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6113. WFIFOSET(fd,packet_len(cmd));
  6114. }
  6115. /// Party invite result.
  6116. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6117. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6118. /// result=0 : char is already in a party -> MsgStringTable[80]
  6119. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6120. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6121. /// result=3 : party is full -> MsgStringTable[83]
  6122. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6123. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6124. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6125. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  6126. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  6127. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  6128. {
  6129. int fd;
  6130. nullpo_retv(sd);
  6131. fd=sd->fd;
  6132. #if PACKETVER < 20070904
  6133. if( result == 7 ) {
  6134. clif_displaymessage(fd, msg_txt(sd,3));
  6135. return;
  6136. }
  6137. #endif
  6138. #if PACKETVER < 20070821
  6139. WFIFOHEAD(fd,packet_len(0xfd));
  6140. WFIFOW(fd,0) = 0xfd;
  6141. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6142. WFIFOB(fd,26) = result;
  6143. WFIFOSET(fd,packet_len(0xfd));
  6144. #else
  6145. WFIFOHEAD(fd,packet_len(0x2c5));
  6146. WFIFOW(fd,0) = 0x2c5;
  6147. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6148. WFIFOL(fd,26) = result;
  6149. WFIFOSET(fd,packet_len(0x2c5));
  6150. #endif
  6151. }
  6152. /// Updates party settings.
  6153. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6154. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6155. /// exp option:
  6156. /// 0 = exp sharing disabled
  6157. /// 1 = exp sharing enabled
  6158. /// 2 = cannot change exp sharing
  6159. ///
  6160. /// flag:
  6161. /// 0 = send to party
  6162. /// 1 = send to sd
  6163. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6164. {
  6165. unsigned char buf[16];
  6166. #if PACKETVER < 20090603
  6167. const int cmd = 0x101;
  6168. #else
  6169. const int cmd = 0x7d8;
  6170. #endif
  6171. nullpo_retv(p);
  6172. if(!sd && flag==0){
  6173. int i;
  6174. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6175. if (i < MAX_PARTY)
  6176. sd = p->data[i].sd;
  6177. }
  6178. if(!sd) return;
  6179. WBUFW(buf,0)=cmd;
  6180. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6181. #if PACKETVER >= 20090603
  6182. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6183. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6184. #endif
  6185. if(flag==0)
  6186. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6187. else
  6188. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6189. }
  6190. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6191. /// result:
  6192. /// 0 = leave
  6193. /// 1 = expel
  6194. /// 2 = cannot leave party on this map
  6195. /// 3 = cannot expel from party on this map
  6196. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6197. {
  6198. unsigned char buf[64];
  6199. nullpo_retv(p);
  6200. if(!sd && (flag&0xf0)==0)
  6201. {
  6202. int i;
  6203. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6204. if (i < MAX_PARTY)
  6205. sd = p->data[i].sd;
  6206. }
  6207. if(!sd) return;
  6208. WBUFW(buf,0)=0x105;
  6209. WBUFL(buf,2)=account_id;
  6210. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6211. WBUFB(buf,30)=flag&0x0f;
  6212. if((flag&0xf0)==0)
  6213. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6214. else
  6215. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6216. }
  6217. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6218. /// 0109 <packet len>.W <account id>.L <message>.?B
  6219. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6220. {
  6221. struct map_session_data *sd;
  6222. int i;
  6223. nullpo_retv(p);
  6224. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6225. if(i < MAX_PARTY){
  6226. unsigned char buf[1024];
  6227. if( len > sizeof(buf)-8 )
  6228. {
  6229. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6230. len = sizeof(buf)-8;
  6231. }
  6232. sd = p->data[i].sd;
  6233. WBUFW(buf,0)=0x109;
  6234. WBUFW(buf,2)=len+8;
  6235. WBUFL(buf,4)=account_id;
  6236. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6237. clif_send(buf,len+8,&sd->bl,PARTY);
  6238. }
  6239. }
  6240. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6241. /// 0107 <account id>.L <x>.W <y>.W
  6242. void clif_party_xy(struct map_session_data *sd)
  6243. {
  6244. unsigned char buf[16];
  6245. nullpo_retv(sd);
  6246. WBUFW(buf,0)=0x107;
  6247. WBUFL(buf,2)=sd->status.account_id;
  6248. WBUFW(buf,6)=sd->bl.x;
  6249. WBUFW(buf,8)=sd->bl.y;
  6250. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6251. }
  6252. /*==========================================
  6253. * Sends x/y dot to a single fd. [Skotlex]
  6254. *------------------------------------------*/
  6255. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6256. {
  6257. WFIFOHEAD(fd,packet_len(0x107));
  6258. WFIFOW(fd,0)=0x107;
  6259. WFIFOL(fd,2)=sd->status.account_id;
  6260. WFIFOW(fd,6)=sd->bl.x;
  6261. WFIFOW(fd,8)=sd->bl.y;
  6262. WFIFOSET(fd,packet_len(0x107));
  6263. }
  6264. /// Updates HP bar of a party member.
  6265. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6266. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6267. void clif_party_hp(struct map_session_data *sd)
  6268. {
  6269. unsigned char buf[16];
  6270. #if PACKETVER < 20100126
  6271. const int cmd = 0x106;
  6272. #else
  6273. const int cmd = 0x80e;
  6274. #endif
  6275. nullpo_retv(sd);
  6276. WBUFW(buf,0)=cmd;
  6277. WBUFL(buf,2)=sd->status.account_id;
  6278. #if PACKETVER < 20100126
  6279. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6280. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6281. WBUFW(buf,8) = 100;
  6282. } else {
  6283. WBUFW(buf,6) = sd->battle_status.hp;
  6284. WBUFW(buf,8) = sd->battle_status.max_hp;
  6285. }
  6286. #else
  6287. WBUFL(buf,6) = sd->battle_status.hp;
  6288. WBUFL(buf,10) = sd->battle_status.max_hp;
  6289. #endif
  6290. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6291. }
  6292. /*==========================================
  6293. * Sends HP bar to a single fd. [Skotlex]
  6294. *------------------------------------------*/
  6295. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6296. {
  6297. #if PACKETVER < 20100126
  6298. const int cmd = 0x106;
  6299. #else
  6300. const int cmd = 0x80e;
  6301. #endif
  6302. WFIFOHEAD(fd,packet_len(cmd));
  6303. WFIFOW(fd,0) = cmd;
  6304. WFIFOL(fd,2) = id;
  6305. #if PACKETVER < 20100126
  6306. if( maxhp > INT16_MAX )
  6307. {// To correctly display the %hp bar. [Skotlex]
  6308. WFIFOW(fd,6) = hp/(maxhp/100);
  6309. WFIFOW(fd,8) = 100;
  6310. } else {
  6311. WFIFOW(fd,6) = hp;
  6312. WFIFOW(fd,8) = maxhp;
  6313. }
  6314. #else
  6315. WFIFOL(fd,6) = hp;
  6316. WFIFOL(fd,10) = maxhp;
  6317. #endif
  6318. WFIFOSET(fd, packet_len(cmd));
  6319. }
  6320. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6321. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6322. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6323. {
  6324. int fd;
  6325. nullpo_retv(sd);
  6326. nullpo_retv(bl);
  6327. fd=sd->fd;
  6328. WFIFOHEAD(fd,packet_len(0x139));
  6329. WFIFOW(fd, 0)=0x139;
  6330. WFIFOL(fd, 2)=bl->id;
  6331. WFIFOW(fd, 6)=bl->x;
  6332. WFIFOW(fd, 8)=bl->y;
  6333. WFIFOW(fd,10)=sd->bl.x;
  6334. WFIFOW(fd,12)=sd->bl.y;
  6335. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6336. WFIFOSET(fd,packet_len(0x139));
  6337. }
  6338. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6339. /// 018f <result>.W <name id>.W
  6340. /// result:
  6341. /// 0 = success
  6342. /// 1 = failure
  6343. /// 2 = success (alchemist)
  6344. /// 3 = failure (alchemist)
  6345. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6346. {
  6347. int view,fd;
  6348. nullpo_retv(sd);
  6349. fd = sd->fd;
  6350. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6351. WFIFOHEAD(fd,packet_len(0x18f));
  6352. WFIFOW(fd, 0)=0x18f;
  6353. WFIFOW(fd, 2)=flag;
  6354. if((view = itemdb_viewid(nameid)) > 0)
  6355. WFIFOW(fd, 4)=view;
  6356. else
  6357. WFIFOW(fd, 4)=nameid;
  6358. WFIFOSET(fd,packet_len(0x18f));
  6359. }
  6360. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6361. /// 019e
  6362. void clif_catch_process(struct map_session_data *sd)
  6363. {
  6364. int fd;
  6365. nullpo_retv(sd);
  6366. fd=sd->fd;
  6367. WFIFOHEAD(fd,packet_len(0x19e));
  6368. WFIFOW(fd,0)=0x19e;
  6369. WFIFOSET(fd,packet_len(0x19e));
  6370. }
  6371. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6372. /// 01a0 <result>.B
  6373. /// 0 = failure
  6374. /// 1 = success
  6375. void clif_pet_roulette(struct map_session_data *sd,int data)
  6376. {
  6377. int fd;
  6378. nullpo_retv(sd);
  6379. fd=sd->fd;
  6380. WFIFOHEAD(fd,packet_len(0x1a0));
  6381. WFIFOW(fd,0)=0x1a0;
  6382. WFIFOB(fd,2)=data;
  6383. WFIFOSET(fd,packet_len(0x1a0));
  6384. }
  6385. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6386. /// 01a6 <packet len>.W { <index>.W }*
  6387. void clif_sendegg(struct map_session_data *sd)
  6388. {
  6389. int i,n=0,fd;
  6390. nullpo_retv(sd);
  6391. fd=sd->fd;
  6392. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6393. clif_displaymessage(fd, msg_txt(sd,666));
  6394. return;
  6395. }
  6396. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6397. WFIFOW(fd,0)=0x1a6;
  6398. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6399. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6400. sd->inventory_data[i]->type!=IT_PETEGG ||
  6401. sd->status.inventory[i].amount<=0)
  6402. continue;
  6403. WFIFOW(fd,n*2+4)=i+2;
  6404. n++;
  6405. }
  6406. WFIFOW(fd,2)=4+n*2;
  6407. WFIFOSET(fd,WFIFOW(fd,2));
  6408. sd->menuskill_id = SA_TAMINGMONSTER;
  6409. sd->menuskill_val = -1;
  6410. }
  6411. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6412. /// 01a4 <type>.B <id>.L <data>.L
  6413. /// type:
  6414. /// 0 = pre-init (data = 0)
  6415. /// 1 = intimacy (data = 0~4)
  6416. /// 2 = hunger (data = 0~4)
  6417. /// 3 = accessory
  6418. /// 4 = performance (data = 1~3: normal, 4: special)
  6419. /// 5 = hairstyle
  6420. ///
  6421. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6422. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6423. {
  6424. uint8 buf[16];
  6425. nullpo_retv(pd);
  6426. WBUFW(buf,0) = 0x1a4;
  6427. WBUFB(buf,2) = type;
  6428. WBUFL(buf,3) = pd->bl.id;
  6429. WBUFL(buf,7) = param;
  6430. if (sd)
  6431. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6432. else
  6433. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6434. }
  6435. /// Pet's base data (ZC_PROPERTY_PET).
  6436. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6437. void clif_send_petstatus(struct map_session_data *sd)
  6438. {
  6439. int fd;
  6440. struct s_pet *pet;
  6441. nullpo_retv(sd);
  6442. nullpo_retv(sd->pd);
  6443. fd=sd->fd;
  6444. pet = &sd->pd->pet;
  6445. WFIFOHEAD(fd,packet_len(0x1a2));
  6446. WFIFOW(fd,0)=0x1a2;
  6447. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6448. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6449. WFIFOW(fd,27)=pet->level;
  6450. WFIFOW(fd,29)=pet->hungry;
  6451. WFIFOW(fd,31)=pet->intimate;
  6452. WFIFOW(fd,33)=pet->equip;
  6453. #if PACKETVER >= 20081126
  6454. WFIFOW(fd,35)=pet->class_;
  6455. #endif
  6456. WFIFOSET(fd,packet_len(0x1a2));
  6457. }
  6458. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6459. /// 01aa <id>.L <data>.L
  6460. /// data:
  6461. /// @see CZ_PET_ACT.
  6462. void clif_pet_emotion(struct pet_data *pd,int param)
  6463. {
  6464. unsigned char buf[16];
  6465. nullpo_retv(pd);
  6466. memset(buf,0,packet_len(0x1aa));
  6467. WBUFW(buf,0)=0x1aa;
  6468. WBUFL(buf,2)=pd->bl.id;
  6469. if(param >= 100 && pd->petDB->talk_convert_class) {
  6470. if(pd->petDB->talk_convert_class < 0)
  6471. return;
  6472. else if(pd->petDB->talk_convert_class > 0) {
  6473. // replace mob_id component of talk/act data
  6474. param -= (pd->pet.class_ - 100)*100;
  6475. param += (pd->petDB->talk_convert_class - 100)*100;
  6476. }
  6477. }
  6478. WBUFL(buf,6)=param;
  6479. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6480. }
  6481. /// Result of request to feed a pet (ZC_FEED_PET).
  6482. /// 01a3 <result>.B <name id>.W
  6483. /// result:
  6484. /// 0 = failure
  6485. /// 1 = success
  6486. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6487. {
  6488. int fd;
  6489. nullpo_retv(sd);
  6490. fd=sd->fd;
  6491. WFIFOHEAD(fd,packet_len(0x1a3));
  6492. WFIFOW(fd,0)=0x1a3;
  6493. WFIFOB(fd,2)=fail;
  6494. WFIFOW(fd,3)=foodid;
  6495. WFIFOSET(fd,packet_len(0x1a3));
  6496. }
  6497. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6498. /// 01cd { <skill id>.L }*7
  6499. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6500. {
  6501. int fd;
  6502. nullpo_retv(sd);
  6503. fd=sd->fd;
  6504. WFIFOHEAD(fd,packet_len(0x1cd));
  6505. WFIFOW(fd, 0)=0x1cd;
  6506. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6507. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6508. else
  6509. WFIFOL(fd,2)= 0x00000000;
  6510. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6511. WFIFOL(fd,6)= MG_COLDBOLT;
  6512. else
  6513. WFIFOL(fd,6)= 0x00000000;
  6514. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6515. WFIFOL(fd,10)= MG_FIREBOLT;
  6516. else
  6517. WFIFOL(fd,10)= 0x00000000;
  6518. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6519. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6520. else
  6521. WFIFOL(fd,14)= 0x00000000;
  6522. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6523. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6524. else
  6525. WFIFOL(fd,18)= 0x00000000;
  6526. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6527. WFIFOL(fd,22)= MG_FIREBALL;
  6528. else
  6529. WFIFOL(fd,22)= 0x00000000;
  6530. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6531. WFIFOL(fd,26)= MG_FROSTDIVER;
  6532. else
  6533. WFIFOL(fd,26)= 0x00000000;
  6534. WFIFOSET(fd,packet_len(0x1cd));
  6535. sd->menuskill_id = SA_AUTOSPELL;
  6536. sd->menuskill_val = skill_lv;
  6537. }
  6538. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6539. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6540. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6541. {
  6542. unsigned char buf[56];
  6543. nullpo_retv(src);
  6544. memset(buf,0,packet_len(0x1cf));
  6545. WBUFW(buf,0) = 0x1cf;
  6546. WBUFL(buf,2) = src->id;
  6547. if( src->type == BL_MER )
  6548. {
  6549. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6550. if( md && md->master && md->devotion_flag )
  6551. WBUFL(buf,6) = md->master->bl.id;
  6552. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6553. }
  6554. else
  6555. {
  6556. int i;
  6557. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6558. if( sd == NULL )
  6559. return;
  6560. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6561. WBUFL(buf,6+4*i) = sd->devotion[i];
  6562. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6563. }
  6564. if( tsd )
  6565. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6566. else
  6567. clif_send(buf, packet_len(0x1cf), src, AREA);
  6568. }
  6569. /*==========================================
  6570. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6571. * Notifies clients in an area of an object's spirits.
  6572. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6573. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6574. *------------------------------------------*/
  6575. void clif_spiritball(struct block_list *bl) {
  6576. unsigned char buf[16];
  6577. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6578. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6579. nullpo_retv(bl);
  6580. WBUFW(buf, 0) = 0x1d0;
  6581. WBUFL(buf, 2) = bl->id;
  6582. WBUFW(buf, 6) = 0; //init to 0
  6583. switch(bl->type){
  6584. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6585. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6586. }
  6587. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6588. }
  6589. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6590. /// 01d2 <account id>.L <delay>.L
  6591. void clif_combo_delay(struct block_list *bl,int wait)
  6592. {
  6593. unsigned char buf[32];
  6594. nullpo_retv(bl);
  6595. WBUFW(buf,0)=0x1d2;
  6596. WBUFL(buf,2)=bl->id;
  6597. WBUFL(buf,6)=wait;
  6598. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6599. }
  6600. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6601. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6602. /// flag:
  6603. /// 0 = inactive
  6604. /// 1 = active
  6605. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6606. {
  6607. unsigned char buf[32];
  6608. nullpo_retv(src);
  6609. WBUFW(buf,0)=0x1d1;
  6610. WBUFL(buf,2)=src->id;
  6611. WBUFL(buf,6)=dst_id;
  6612. WBUFL(buf,10)=active;
  6613. clif_send(buf,packet_len(0x1d1),src,AREA);
  6614. }
  6615. /// MVP effect (ZC_MVP).
  6616. /// 010c <account id>.L
  6617. void clif_mvp_effect(struct map_session_data *sd)
  6618. {
  6619. unsigned char buf[16];
  6620. nullpo_retv(sd);
  6621. WBUFW(buf,0)=0x10c;
  6622. WBUFL(buf,2)=sd->bl.id;
  6623. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6624. }
  6625. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6626. /// 010a <name id>.W
  6627. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6628. {
  6629. int view,fd;
  6630. nullpo_retv(sd);
  6631. fd=sd->fd;
  6632. WFIFOHEAD(fd,packet_len(0x10a));
  6633. WFIFOW(fd,0)=0x10a;
  6634. if((view = itemdb_viewid(nameid)) > 0)
  6635. WFIFOW(fd,2)=view;
  6636. else
  6637. WFIFOW(fd,2)=nameid;
  6638. WFIFOSET(fd,packet_len(0x10a));
  6639. }
  6640. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6641. /// 010b <exp>.L
  6642. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6643. {
  6644. int fd;
  6645. nullpo_retv(sd);
  6646. fd=sd->fd;
  6647. WFIFOHEAD(fd,packet_len(0x10b));
  6648. WFIFOW(fd,0)=0x10b;
  6649. WFIFOL(fd,2)=min(exp,UINT32_MAX);
  6650. WFIFOSET(fd,packet_len(0x10b));
  6651. }
  6652. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6653. /// 010d
  6654. ///
  6655. /// "You are the MVP, but cannot obtain the reward because
  6656. /// you are overweight."
  6657. void clif_mvp_noitem(struct map_session_data* sd)
  6658. {
  6659. int fd = sd->fd;
  6660. WFIFOHEAD(fd,packet_len(0x10d));
  6661. WFIFOW(fd,0) = 0x10d;
  6662. WFIFOSET(fd,packet_len(0x10d));
  6663. }
  6664. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6665. /// 0167 <result>.B
  6666. /// result:
  6667. /// 0 = "Guild has been created."
  6668. /// 1 = "You are already in a Guild."
  6669. /// 2 = "That Guild Name already exists."
  6670. /// 3 = "You need the neccessary item to create a Guild."
  6671. void clif_guild_created(struct map_session_data *sd,int flag)
  6672. {
  6673. int fd;
  6674. nullpo_retv(sd);
  6675. fd=sd->fd;
  6676. WFIFOHEAD(fd,packet_len(0x167));
  6677. WFIFOW(fd,0)=0x167;
  6678. WFIFOB(fd,2)=flag;
  6679. WFIFOSET(fd,packet_len(0x167));
  6680. }
  6681. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6682. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6683. /// mode:
  6684. /// &0x01 = allow invite
  6685. /// &0x10 = allow expel
  6686. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6687. {
  6688. int ps,fd;
  6689. nullpo_retv(sd);
  6690. nullpo_retv(g);
  6691. fd=sd->fd;
  6692. ps=guild_getposition(g,sd);
  6693. WFIFOHEAD(fd,packet_len(0x16c));
  6694. WFIFOW(fd,0)=0x16c;
  6695. WFIFOL(fd,2)=g->guild_id;
  6696. WFIFOL(fd,6)=g->emblem_id;
  6697. WFIFOL(fd,10)=g->position[ps].mode;
  6698. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6699. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6700. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6701. WFIFOSET(fd,packet_len(0x16c));
  6702. }
  6703. /// Guild member login notice.
  6704. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6705. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6706. /// status:
  6707. /// 0 = offline
  6708. /// 1 = online
  6709. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6710. {
  6711. unsigned char buf[64];
  6712. struct map_session_data* sd;
  6713. nullpo_retv(g);
  6714. WBUFW(buf, 0)=0x1f2;
  6715. WBUFL(buf, 2)=g->member[idx].account_id;
  6716. WBUFL(buf, 6)=g->member[idx].char_id;
  6717. WBUFL(buf,10)=flag;
  6718. if( ( sd = g->member[idx].sd ) != NULL )
  6719. {
  6720. WBUFW(buf,14) = sd->status.sex;
  6721. WBUFW(buf,16) = sd->status.hair;
  6722. WBUFW(buf,18) = sd->status.hair_color;
  6723. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6724. }
  6725. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6726. {
  6727. WBUFW(buf,14) = 0;
  6728. WBUFW(buf,16) = 0;
  6729. WBUFW(buf,18) = 0;
  6730. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6731. }
  6732. }
  6733. // Function `clif_guild_memberlogin_notice` sends info about
  6734. // logins and logouts of a guild member to the rest members.
  6735. // But at the 1st time (after a player login or map changing)
  6736. // the client won't show the message.
  6737. // So I suggest use this function for sending "first-time-info"
  6738. // to some player on entering the game or changing location.
  6739. // At next time the client would always show the message.
  6740. // The function sends all the statuses in the single packet
  6741. // to economize traffic. [LuzZza]
  6742. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6743. {
  6744. struct guild *g;
  6745. unsigned char buf[14*128];
  6746. int i, count=0, p_len;
  6747. nullpo_retv(sd);
  6748. p_len = packet_len(0x16d);
  6749. if(!(g = sd->guild))
  6750. return;
  6751. for(i=0; i<g->max_member; i++) {
  6752. if(g->member[i].account_id > 0 &&
  6753. g->member[i].account_id != sd->status.account_id) {
  6754. WBUFW(buf,count*p_len) = 0x16d;
  6755. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6756. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6757. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6758. count++;
  6759. }
  6760. }
  6761. clif_send(buf, p_len*count, &sd->bl, SELF);
  6762. }
  6763. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6764. /// 014e <menu flag>.L
  6765. /// menu flag:
  6766. /// 0x00 = Basic Info (always on)
  6767. /// &0x01 = Member manager
  6768. /// &0x02 = Positions
  6769. /// &0x04 = Skills
  6770. /// &0x10 = Expulsion list
  6771. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6772. /// &0x80 = Notice
  6773. void clif_guild_masterormember(struct map_session_data *sd)
  6774. {
  6775. int fd;
  6776. nullpo_retv(sd);
  6777. fd=sd->fd;
  6778. WFIFOHEAD(fd,packet_len(0x14e));
  6779. WFIFOW(fd,0) = 0x14e;
  6780. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6781. WFIFOSET(fd,packet_len(0x14e));
  6782. }
  6783. /// Guild basic information (Territories [Valaris])
  6784. /// 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)
  6785. /// 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)
  6786. void clif_guild_basicinfo(struct map_session_data *sd) {
  6787. int fd;
  6788. struct guild *g;
  6789. nullpo_retv(sd);
  6790. fd = sd->fd;
  6791. if( (g = sd->guild) == NULL )
  6792. return;
  6793. WFIFOHEAD(fd,packet_len(0x1b6));
  6794. WFIFOW(fd, 0)=0x1b6;//0x150;
  6795. WFIFOL(fd, 2)=g->guild_id;
  6796. WFIFOL(fd, 6)=g->guild_lv;
  6797. WFIFOL(fd,10)=g->connect_member;
  6798. WFIFOL(fd,14)=g->max_member;
  6799. WFIFOL(fd,18)=g->average_lv;
  6800. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6801. WFIFOL(fd,26)=g->next_exp;
  6802. WFIFOL(fd,30)=0; // Tax Points
  6803. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6804. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6805. WFIFOL(fd,42)=g->emblem_id;
  6806. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6807. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6808. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6809. WFIFOL(fd,110) = 0; // zeny
  6810. WFIFOSET(fd,packet_len(0x1b6));
  6811. }
  6812. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6813. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6814. void clif_guild_allianceinfo(struct map_session_data *sd)
  6815. {
  6816. int fd,i,c;
  6817. struct guild *g;
  6818. nullpo_retv(sd);
  6819. if( (g = sd->guild) == NULL )
  6820. return;
  6821. fd = sd->fd;
  6822. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6823. WFIFOW(fd, 0)=0x14c;
  6824. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6825. struct guild_alliance *a=&g->alliance[i];
  6826. if(a->guild_id>0){
  6827. WFIFOL(fd,c*32+4)=a->opposition;
  6828. WFIFOL(fd,c*32+8)=a->guild_id;
  6829. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6830. c++;
  6831. }
  6832. }
  6833. WFIFOW(fd, 2)=c*32+4;
  6834. WFIFOSET(fd,WFIFOW(fd,2));
  6835. }
  6836. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6837. /// 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 }*
  6838. /// state:
  6839. /// 0 = offline
  6840. /// 1 = online
  6841. /// memo:
  6842. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6843. void clif_guild_memberlist(struct map_session_data *sd)
  6844. {
  6845. int fd;
  6846. int i,c;
  6847. struct guild *g;
  6848. nullpo_retv(sd);
  6849. if( (fd = sd->fd) == 0 )
  6850. return;
  6851. if( (g = sd->guild) == NULL )
  6852. return;
  6853. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6854. WFIFOW(fd, 0)=0x154;
  6855. for(i=0,c=0;i<g->max_member;i++){
  6856. struct guild_member *m=&g->member[i];
  6857. if(m->account_id==0)
  6858. continue;
  6859. WFIFOL(fd,c*104+ 4)=m->account_id;
  6860. WFIFOL(fd,c*104+ 8)=m->char_id;
  6861. WFIFOW(fd,c*104+12)=m->hair;
  6862. WFIFOW(fd,c*104+14)=m->hair_color;
  6863. WFIFOW(fd,c*104+16)=m->gender;
  6864. WFIFOW(fd,c*104+18)=m->class_;
  6865. WFIFOW(fd,c*104+20)=m->lv;
  6866. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6867. WFIFOL(fd,c*104+26)=m->online;
  6868. WFIFOL(fd,c*104+30)=m->position;
  6869. 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.
  6870. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6871. c++;
  6872. }
  6873. WFIFOW(fd, 2)=c*104+4;
  6874. WFIFOSET(fd,WFIFOW(fd,2));
  6875. }
  6876. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6877. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6878. void clif_guild_positionnamelist(struct map_session_data *sd)
  6879. {
  6880. int i,fd;
  6881. struct guild *g;
  6882. nullpo_retv(sd);
  6883. if( (g = sd->guild) == NULL )
  6884. return;
  6885. fd = sd->fd;
  6886. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6887. WFIFOW(fd, 0)=0x166;
  6888. for(i=0;i<MAX_GUILDPOSITION;i++){
  6889. WFIFOL(fd,i*28+4)=i;
  6890. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6891. }
  6892. WFIFOW(fd,2)=i*28+4;
  6893. WFIFOSET(fd,WFIFOW(fd,2));
  6894. }
  6895. /// Guild position information (ZC_POSITION_INFO).
  6896. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6897. /// mode:
  6898. /// &0x01 = allow invite
  6899. /// &0x10 = allow expel
  6900. /// ranking:
  6901. /// TODO
  6902. void clif_guild_positioninfolist(struct map_session_data *sd)
  6903. {
  6904. int i,fd;
  6905. struct guild *g;
  6906. nullpo_retv(sd);
  6907. if( (g = sd->guild) == NULL )
  6908. return;
  6909. fd = sd->fd;
  6910. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6911. WFIFOW(fd, 0)=0x160;
  6912. for(i=0;i<MAX_GUILDPOSITION;i++){
  6913. struct guild_position *p=&g->position[i];
  6914. WFIFOL(fd,i*16+ 4)=i;
  6915. WFIFOL(fd,i*16+ 8)=p->mode;
  6916. WFIFOL(fd,i*16+12)=i;
  6917. WFIFOL(fd,i*16+16)=p->exp_mode;
  6918. }
  6919. WFIFOW(fd, 2)=i*16+4;
  6920. WFIFOSET(fd,WFIFOW(fd,2));
  6921. }
  6922. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6923. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6924. /// mode:
  6925. /// &0x01 = allow invite
  6926. /// &0x10 = allow expel
  6927. /// ranking:
  6928. /// TODO
  6929. void clif_guild_positionchanged(struct guild *g,int idx)
  6930. {
  6931. // FIXME: This packet is intended to update the clients after a
  6932. // commit of position info changes, not sending one packet per
  6933. // position.
  6934. struct map_session_data *sd;
  6935. unsigned char buf[128];
  6936. nullpo_retv(g);
  6937. WBUFW(buf, 0)=0x174;
  6938. WBUFW(buf, 2)=44; // packet len
  6939. // GUILD_REG_POSITION_INFO{
  6940. WBUFL(buf, 4)=idx;
  6941. WBUFL(buf, 8)=g->position[idx].mode;
  6942. WBUFL(buf,12)=idx;
  6943. WBUFL(buf,16)=g->position[idx].exp_mode;
  6944. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6945. // }*
  6946. if( (sd=guild_getavailablesd(g))!=NULL )
  6947. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6948. }
  6949. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6950. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6951. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6952. {
  6953. // FIXME: This packet is intended to update the clients after a
  6954. // commit of member position assignment changes, not sending one
  6955. // packet per position.
  6956. struct map_session_data *sd;
  6957. unsigned char buf[64];
  6958. nullpo_retv(g);
  6959. WBUFW(buf, 0)=0x156;
  6960. WBUFW(buf, 2)=16; // packet len
  6961. // MEMBER_POSITION_INFO{
  6962. WBUFL(buf, 4)=g->member[idx].account_id;
  6963. WBUFL(buf, 8)=g->member[idx].char_id;
  6964. WBUFL(buf,12)=g->member[idx].position;
  6965. // }*
  6966. if( (sd=guild_getavailablesd(g))!=NULL )
  6967. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6968. }
  6969. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6970. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6971. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6972. {
  6973. int fd;
  6974. nullpo_retv(sd);
  6975. nullpo_retv(g);
  6976. fd = sd->fd;
  6977. if( g->emblem_len <= 0 )
  6978. return;
  6979. WFIFOHEAD(fd,g->emblem_len+12);
  6980. WFIFOW(fd,0)=0x152;
  6981. WFIFOW(fd,2)=g->emblem_len+12;
  6982. WFIFOL(fd,4)=g->guild_id;
  6983. WFIFOL(fd,8)=g->emblem_id;
  6984. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6985. WFIFOSET(fd,WFIFOW(fd,2));
  6986. }
  6987. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6988. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6989. void clif_guild_emblem_area(struct block_list* bl)
  6990. {
  6991. uint8 buf[12];
  6992. nullpo_retv(bl);
  6993. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6994. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6995. WBUFW(buf,0) = 0x1b4;
  6996. WBUFL(buf,2) = bl->id;
  6997. WBUFL(buf,6) = status_get_guild_id(bl);
  6998. WBUFW(buf,10) = status_get_emblem_id(bl);
  6999. clif_send(buf, 12, bl, AREA_WOS);
  7000. }
  7001. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7002. /// 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 }*
  7003. void clif_guild_skillinfo(struct map_session_data* sd)
  7004. {
  7005. int fd;
  7006. struct guild* g;
  7007. int i,c;
  7008. nullpo_retv(sd);
  7009. if( (g = sd->guild) == NULL )
  7010. return;
  7011. fd = sd->fd;
  7012. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7013. WFIFOW(fd,0) = 0x0162;
  7014. WFIFOW(fd,4) = g->skill_point;
  7015. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7016. {
  7017. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7018. {
  7019. int id = g->skill[i].id;
  7020. int p = 6 + c*37;
  7021. WFIFOW(fd,p+0) = id;
  7022. WFIFOL(fd,p+2) = skill_get_inf(id);
  7023. WFIFOW(fd,p+6) = g->skill[i].lv;
  7024. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7025. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7026. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7027. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7028. c++;
  7029. }
  7030. }
  7031. WFIFOW(fd,2) = 6 + c*37;
  7032. WFIFOSET(fd,WFIFOW(fd,2));
  7033. }
  7034. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7035. /// 016f <subject>.60B <notice>.120B
  7036. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  7037. {
  7038. int fd;
  7039. nullpo_retv(sd);
  7040. nullpo_retv(g);
  7041. fd = sd->fd;
  7042. if ( !session_isActive(fd) )
  7043. return;
  7044. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7045. return;
  7046. WFIFOHEAD(fd,packet_len(0x16f));
  7047. WFIFOW(fd,0) = 0x16f;
  7048. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7049. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7050. WFIFOSET(fd,packet_len(0x16f));
  7051. }
  7052. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7053. /// 016a <guild id>.L <guild name>.24B
  7054. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7055. {
  7056. int fd;
  7057. nullpo_retv(sd);
  7058. nullpo_retv(g);
  7059. fd=sd->fd;
  7060. WFIFOHEAD(fd,packet_len(0x16a));
  7061. WFIFOW(fd,0)=0x16a;
  7062. WFIFOL(fd,2)=g->guild_id;
  7063. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  7064. WFIFOSET(fd,packet_len(0x16a));
  7065. }
  7066. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7067. /// 0169 <answer>.B
  7068. /// answer:
  7069. /// 0 = Already in guild.
  7070. /// 1 = Offer rejected.
  7071. /// 2 = Offer accepted.
  7072. /// 3 = Guild full.
  7073. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7074. {
  7075. int fd;
  7076. nullpo_retv(sd);
  7077. fd=sd->fd;
  7078. WFIFOHEAD(fd,packet_len(0x169));
  7079. WFIFOW(fd,0)=0x169;
  7080. WFIFOB(fd,2)=flag;
  7081. WFIFOSET(fd,packet_len(0x169));
  7082. }
  7083. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7084. /// 015a <char name>.24B <reason>.40B
  7085. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7086. {
  7087. unsigned char buf[128];
  7088. nullpo_retv(sd);
  7089. WBUFW(buf, 0)=0x15a;
  7090. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  7091. memcpy(WBUFP(buf,26),mes,40);
  7092. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7093. }
  7094. /// Notifies clients of a guild of an expelled member.
  7095. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7096. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7097. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7098. {
  7099. unsigned char buf[128];
  7100. #if PACKETVER < 20100803
  7101. const unsigned short cmd = 0x15c;
  7102. #else
  7103. const unsigned short cmd = 0x839;
  7104. #endif
  7105. nullpo_retv(sd);
  7106. WBUFW(buf,0) = cmd;
  7107. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7108. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7109. #if PACKETVER < 20100803
  7110. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7111. #endif
  7112. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7113. }
  7114. /// Guild expulsion list (ZC_BAN_LIST).
  7115. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7116. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7117. void clif_guild_expulsionlist(struct map_session_data* sd)
  7118. {
  7119. #if PACKETVER < 20100803
  7120. const int offset = NAME_LENGTH*2+40;
  7121. #else
  7122. const int offset = NAME_LENGTH+40;
  7123. #endif
  7124. int fd, i, c = 0;
  7125. struct guild* g;
  7126. nullpo_retv(sd);
  7127. if( (g = sd->guild) == NULL )
  7128. return;
  7129. fd = sd->fd;
  7130. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7131. WFIFOW(fd,0) = 0x163;
  7132. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7133. {
  7134. struct guild_expulsion* e = &g->expulsion[i];
  7135. if( e->account_id > 0 )
  7136. {
  7137. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7138. #if PACKETVER < 20100803
  7139. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7140. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7141. #else
  7142. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7143. #endif
  7144. c++;
  7145. }
  7146. }
  7147. WFIFOW(fd,2) = 4 + c*offset;
  7148. WFIFOSET(fd,WFIFOW(fd,2));
  7149. }
  7150. /// Guild chat message (ZC_GUILD_CHAT).
  7151. /// 017f <packet len>.W <message>.?B
  7152. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7153. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7154. struct map_session_data *sd;
  7155. uint8 buf[256];
  7156. if( len == 0 )
  7157. {
  7158. return;
  7159. }
  7160. else if( len > sizeof(buf)-5 )
  7161. {
  7162. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7163. len = sizeof(buf)-5;
  7164. }
  7165. WBUFW(buf, 0) = 0x17f;
  7166. WBUFW(buf, 2) = len + 5;
  7167. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7168. if ((sd = guild_getavailablesd(g)) != NULL)
  7169. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7170. }
  7171. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7172. /// 0171 <inviter account id>.L <guild name>.24B
  7173. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7174. {
  7175. int fd;
  7176. nullpo_retv(sd);
  7177. fd=sd->fd;
  7178. WFIFOHEAD(fd,packet_len(0x171));
  7179. WFIFOW(fd,0)=0x171;
  7180. WFIFOL(fd,2)=account_id;
  7181. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7182. WFIFOSET(fd,packet_len(0x171));
  7183. }
  7184. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7185. /// 0173 <answer>.B
  7186. /// answer:
  7187. /// 0 = Already allied.
  7188. /// 1 = You rejected the offer.
  7189. /// 2 = You accepted the offer.
  7190. /// 3 = They have too any alliances.
  7191. /// 4 = You have too many alliances.
  7192. /// 5 = Alliances are disabled.
  7193. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7194. {
  7195. int fd;
  7196. nullpo_retv(sd);
  7197. fd=sd->fd;
  7198. WFIFOHEAD(fd,packet_len(0x173));
  7199. WFIFOW(fd,0)=0x173;
  7200. WFIFOL(fd,2)=flag;
  7201. WFIFOSET(fd,packet_len(0x173));
  7202. }
  7203. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7204. /// 0184 <other guild id>.L <relation>.L
  7205. /// relation:
  7206. /// 0 = Ally
  7207. /// 1 = Enemy
  7208. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7209. {
  7210. int fd;
  7211. nullpo_retv(sd);
  7212. fd = sd->fd;
  7213. if (fd <= 0)
  7214. return;
  7215. WFIFOHEAD(fd,packet_len(0x184));
  7216. WFIFOW(fd,0)=0x184;
  7217. WFIFOL(fd,2)=guild_id;
  7218. WFIFOL(fd,6)=flag;
  7219. WFIFOSET(fd,packet_len(0x184));
  7220. }
  7221. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7222. /// 0181 <result>.B
  7223. /// result:
  7224. /// 0 = Antagonist has been set.
  7225. /// 1 = Guild has too many Antagonists.
  7226. /// 2 = Already set as an Antagonist.
  7227. /// 3 = Antagonists are disabled.
  7228. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7229. {
  7230. int fd;
  7231. nullpo_retv(sd);
  7232. fd=sd->fd;
  7233. WFIFOHEAD(fd,packet_len(0x181));
  7234. WFIFOW(fd,0)=0x181;
  7235. WFIFOB(fd,2)=flag;
  7236. WFIFOSET(fd,packet_len(0x181));
  7237. }
  7238. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7239. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7240. /*
  7241. void clif_guild_allianceadded(struct guild *g,int idx)
  7242. {
  7243. unsigned char buf[64];
  7244. WBUFW(buf,0)=0x185;
  7245. WBUFL(buf,2)=g->alliance[idx].opposition;
  7246. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7247. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7248. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7249. }
  7250. */
  7251. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7252. /// 015e <reason>.L
  7253. /// 0 = success
  7254. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7255. /// 2 = there are still members in the guild
  7256. void clif_guild_broken(struct map_session_data *sd,int flag)
  7257. {
  7258. int fd;
  7259. nullpo_retv(sd);
  7260. fd=sd->fd;
  7261. WFIFOHEAD(fd,packet_len(0x15e));
  7262. WFIFOW(fd,0)=0x15e;
  7263. WFIFOL(fd,2)=flag;
  7264. WFIFOSET(fd,packet_len(0x15e));
  7265. }
  7266. /// Displays emotion on an object (ZC_EMOTION).
  7267. /// 00c0 <id>.L <type>.B
  7268. /// type:
  7269. /// enum emotion_type
  7270. void clif_emotion(struct block_list *bl,int type)
  7271. {
  7272. unsigned char buf[8];
  7273. nullpo_retv(bl);
  7274. WBUFW(buf,0)=0xc0;
  7275. WBUFL(buf,2)=bl->id;
  7276. WBUFB(buf,6)=type;
  7277. clif_send(buf,packet_len(0xc0),bl,AREA);
  7278. }
  7279. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7280. /// 0191 <id>.L <contents>.80B
  7281. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7282. {
  7283. unsigned char buf[MESSAGE_SIZE+6];
  7284. nullpo_retv(bl);
  7285. WBUFW(buf,0) = 0x191;
  7286. WBUFL(buf,2) = bl->id;
  7287. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7288. clif_send(buf,packet_len(0x191),bl,AREA);
  7289. }
  7290. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7291. /// 01ea <id>.L
  7292. void clif_wedding_effect(struct block_list *bl)
  7293. {
  7294. unsigned char buf[6];
  7295. nullpo_retv(bl);
  7296. WBUFW(buf,0) = 0x1ea;
  7297. WBUFL(buf,2) = bl->id;
  7298. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7299. }
  7300. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7301. /// 01e6 <partner name>.24B
  7302. void clif_callpartner(struct map_session_data *sd)
  7303. {
  7304. unsigned char buf[26];
  7305. nullpo_retv(sd);
  7306. WBUFW(buf,0) = 0x1e6;
  7307. if( sd->status.partner_id ) {
  7308. const char *p = map_charid2nick(sd->status.partner_id);
  7309. struct map_session_data *p_sd = pc_get_partner(sd);
  7310. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7311. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7312. else
  7313. WBUFB(buf,2) = 0;
  7314. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7315. WBUFB(buf,2) = 0;
  7316. }
  7317. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7318. }
  7319. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7320. /// 01e4
  7321. /// This packet while still implemented by the client is no longer being officially used.
  7322. /*
  7323. void clif_marriage_process(struct map_session_data *sd)
  7324. {
  7325. int fd;
  7326. nullpo_retv(sd);
  7327. fd=sd->fd;
  7328. WFIFOHEAD(fd,packet_len(0x1e4));
  7329. WFIFOW(fd,0)=0x1e4;
  7330. WFIFOSET(fd,packet_len(0x1e4));
  7331. }
  7332. */
  7333. /// Notice of divorce (ZC_DIVORCE).
  7334. /// 0205 <partner name>.24B
  7335. void clif_divorced(struct map_session_data* sd, const char* name)
  7336. {
  7337. int fd;
  7338. nullpo_retv(sd);
  7339. fd=sd->fd;
  7340. WFIFOHEAD(fd,packet_len(0x205));
  7341. WFIFOW(fd,0)=0x205;
  7342. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7343. WFIFOSET(fd, packet_len(0x205));
  7344. }
  7345. /// Marriage proposal (ZC_REQ_COUPLE).
  7346. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7347. /// This packet while still implemented by the client is no longer being officially used.
  7348. /*
  7349. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7350. {
  7351. nullpo_retv(sd);
  7352. WFIFOHEAD(fd,packet_len(0x1e2));
  7353. WFIFOW(fd,0) = 0x1e2;
  7354. WFIFOL(fd,2) = ssd->status.account_id;
  7355. WFIFOL(fd,6) = ssd->status.char_id;
  7356. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7357. WFIFOSET(fd, packet_len(0x1e2));
  7358. }
  7359. */
  7360. /*==========================================
  7361. *
  7362. *------------------------------------------*/
  7363. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7364. {
  7365. clif_disp_message(&sd->bl, mes, len, SELF);
  7366. }
  7367. /*==========================================
  7368. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7369. *------------------------------------------*/
  7370. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7371. {
  7372. unsigned char buf[256];
  7373. if( len == 0 ) {
  7374. return;
  7375. } else if( len > sizeof(buf)-5 ) {
  7376. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7377. len = sizeof(buf)-5;
  7378. }
  7379. WBUFW(buf, 0) = 0x17f;
  7380. WBUFW(buf, 2) = len + 5;
  7381. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7382. clif_send(buf, WBUFW(buf,2), src, target);
  7383. }
  7384. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7385. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7386. /// 00cd <result>.B
  7387. /// result:
  7388. /// 0 = failure
  7389. /// 1 = success
  7390. void clif_GM_kickack(struct map_session_data *sd, int id)
  7391. {
  7392. int fd;
  7393. nullpo_retv(sd);
  7394. fd = sd->fd;
  7395. WFIFOHEAD(fd,packet_len(0xcd));
  7396. WFIFOW(fd,0) = 0xcd;
  7397. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7398. WFIFOSET(fd, packet_len(0xcd));
  7399. }
  7400. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7401. {
  7402. int fd = tsd->fd;
  7403. if( fd > 0 )
  7404. clif_authfail_fd(fd, 15);
  7405. else {
  7406. // Close vending/buyingstore
  7407. if (sd) {
  7408. if (tsd->state.vending)
  7409. vending_closevending(tsd);
  7410. else if (tsd->state.buyingstore)
  7411. buyingstore_close(tsd);
  7412. }
  7413. map_quit(tsd);
  7414. }
  7415. if( sd )
  7416. clif_GM_kickack(sd,tsd->status.account_id);
  7417. }
  7418. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7419. /// 014a <result>.L
  7420. /// result:
  7421. /// 0 = "A manner point has been successfully aligned."
  7422. /// 1 = MP_FAILURE_EXHAUST
  7423. /// 2 = MP_FAILURE_ALREADY_GIVING
  7424. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7425. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7426. /// 5 = "You got a good point from %s."
  7427. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7428. {
  7429. int fd;
  7430. nullpo_retv(sd);
  7431. fd = sd->fd;
  7432. WFIFOHEAD(fd,packet_len(0x14a));
  7433. WFIFOW(fd,0) = 0x14a;
  7434. WFIFOL(fd,2) = type;
  7435. WFIFOSET(fd, packet_len(0x14a));
  7436. }
  7437. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7438. /// 014b <type>.B <GM name>.24B
  7439. /// type:
  7440. /// 0 = positive (unmute)
  7441. /// 1 = negative (mute)
  7442. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7443. {
  7444. int fd;
  7445. nullpo_retv(sd);
  7446. nullpo_retv(tsd);
  7447. fd = tsd->fd;
  7448. WFIFOHEAD(fd,packet_len(0x14b));
  7449. WFIFOW(fd,0) = 0x14b;
  7450. WFIFOB(fd,2) = type;
  7451. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7452. WFIFOSET(fd, packet_len(0x14b));
  7453. }
  7454. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7455. /// 00d1 <type>.B <result>.B
  7456. /// type:
  7457. /// 0 = /ex (deny)
  7458. /// 1 = /in (allow)
  7459. /// result:
  7460. /// 0 = success
  7461. /// 1 = failure
  7462. /// 2 = too many blocks
  7463. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7464. {
  7465. int fd;
  7466. nullpo_retv(sd);
  7467. fd=sd->fd;
  7468. WFIFOHEAD(fd,packet_len(0xd1));
  7469. WFIFOW(fd,0)=0xd1;
  7470. WFIFOB(fd,2)=type;
  7471. WFIFOB(fd,3)=flag;
  7472. WFIFOSET(fd,packet_len(0xd1));
  7473. }
  7474. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7475. /// 00d2 <type>.B <result>.B
  7476. /// type:
  7477. /// 0 = /exall (deny)
  7478. /// 1 = /inall (allow)
  7479. /// result:
  7480. /// 0 = success
  7481. /// 1 = failure
  7482. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7483. {
  7484. int fd;
  7485. nullpo_retv(sd);
  7486. fd=sd->fd;
  7487. WFIFOHEAD(fd,packet_len(0xd2));
  7488. WFIFOW(fd,0)=0xd2;
  7489. WFIFOB(fd,2)=type;
  7490. WFIFOB(fd,3)=flag;
  7491. WFIFOSET(fd,packet_len(0xd2));
  7492. }
  7493. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7494. /// 07fe <bgm>.24B
  7495. void clif_playBGM(struct map_session_data* sd, const char* name)
  7496. {
  7497. int fd;
  7498. nullpo_retv(sd);
  7499. fd = sd->fd;
  7500. WFIFOHEAD(fd,packet_len(0x7fe));
  7501. WFIFOW(fd,0) = 0x7fe;
  7502. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7503. WFIFOSET(fd,packet_len(0x7fe));
  7504. }
  7505. /// Plays/stops a wave sound (ZC_SOUND).
  7506. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7507. /// file name:
  7508. /// relative to data\wav
  7509. /// act:
  7510. /// 0 = play (once)
  7511. /// 1 = play (repeat, does not work)
  7512. /// 2 = stops all sound instances of file name (does not work)
  7513. /// term:
  7514. /// unknown purpose, only relevant to act = 1
  7515. /// npc id:
  7516. /// The accustic direction of the sound is determined by the
  7517. /// relative position of the NPC to the player (3D sound).
  7518. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7519. {
  7520. int fd;
  7521. nullpo_retv(sd);
  7522. nullpo_retv(bl);
  7523. fd = sd->fd;
  7524. WFIFOHEAD(fd,packet_len(0x1d3));
  7525. WFIFOW(fd,0) = 0x1d3;
  7526. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7527. WFIFOB(fd,26) = type;
  7528. WFIFOL(fd,27) = 0;
  7529. WFIFOL(fd,31) = bl->id;
  7530. WFIFOSET(fd,packet_len(0x1d3));
  7531. }
  7532. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7533. {
  7534. unsigned char buf[40];
  7535. nullpo_retv(bl);
  7536. WBUFW(buf,0) = 0x1d3;
  7537. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7538. WBUFB(buf,26) = type;
  7539. WBUFL(buf,27) = 0;
  7540. WBUFL(buf,31) = bl->id;
  7541. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7542. }
  7543. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7544. /// 01f3 <id>.L <effect id>.L
  7545. /// effect id:
  7546. /// @see doc/effect_list.txt
  7547. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7548. {
  7549. unsigned char buf[24];
  7550. nullpo_retv(bl);
  7551. memset(buf, 0, packet_len(0x1f3));
  7552. WBUFW(buf,0) = 0x1f3;
  7553. WBUFL(buf,2) = bl->id;
  7554. WBUFL(buf,6) = type;
  7555. clif_send(buf, packet_len(0x1f3), bl, target);
  7556. if (disguised(bl)) {
  7557. WBUFL(buf,2) = -bl->id;
  7558. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7559. }
  7560. }
  7561. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7562. {
  7563. WFIFOHEAD(fd,10);
  7564. WFIFOW(fd,0) = 0x1f3;
  7565. WFIFOL(fd,2) = bl->id;
  7566. WFIFOL(fd,6) = type;
  7567. WFIFOSET(fd,10);
  7568. }
  7569. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7570. /// 0284 <id>.L <effect id>.L <num data>.L
  7571. /// effect id:
  7572. /// @see doc/effect_list.txt
  7573. /// num data:
  7574. /// effect-dependent value
  7575. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7576. {
  7577. uint8 buf[14];
  7578. WBUFW(buf,0) = 0x284;
  7579. WBUFL(buf,2) = bl->id;
  7580. WBUFL(buf,6) = effect_id;
  7581. WBUFL(buf,10) = num;
  7582. clif_send(buf, packet_len(0x284), bl, target);
  7583. if( disguised(bl) )
  7584. {
  7585. WBUFL(buf,2) = -bl->id;
  7586. clif_send(buf, packet_len(0x284), bl, SELF);
  7587. }
  7588. }
  7589. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7590. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7591. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7592. unsigned short msg_len = strlen(msg) + 1;
  7593. WFIFOHEAD(fd,msg_len + 12);
  7594. WFIFOW(fd,0) = 0x2C1;
  7595. WFIFOW(fd,2) = msg_len + 12;
  7596. WFIFOL(fd,4) = 0;
  7597. WFIFOL(fd,8) = color; //either color_table or channel_table
  7598. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7599. WFIFOSET(fd, msg_len + 12);
  7600. return 0;
  7601. }
  7602. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7603. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7604. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7605. unsigned short msg_len = strlen(msg) + 1;
  7606. uint8 buf[256];
  7607. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7608. nullpo_retv(bl);
  7609. if( msg_len > sizeof(buf)-12 ) {
  7610. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7611. msg_len = sizeof(buf)-12;
  7612. }
  7613. WBUFW(buf,0) = 0x2C1;
  7614. WBUFW(buf,2) = msg_len + 12;
  7615. WBUFL(buf,4) = bl->id;
  7616. WBUFL(buf,8) = color;
  7617. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7618. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7619. }
  7620. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7621. {
  7622. int fd;
  7623. unsigned short msg_len = strlen(msg) + 1;
  7624. nullpo_retv(sd);
  7625. if(msg_len > 0) {
  7626. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7627. fd = sd->fd;
  7628. WFIFOHEAD(fd, msg_len+12);
  7629. WFIFOW(fd,0) = 0x2C1;
  7630. WFIFOW(fd,2) = msg_len+12;
  7631. WFIFOL(fd,4) = 0;
  7632. WFIFOL(fd,8) = color;
  7633. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7634. WFIFOSET(fd, WFIFOW(fd,2));
  7635. }
  7636. }
  7637. /**
  7638. * Notifies the client that the storage window is still open
  7639. *
  7640. * Should only be used in cases where the client closed the
  7641. * storage window without server's consent
  7642. */
  7643. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7644. // Notify the client that the storage is open
  7645. if( sd->state.storage_flag == 1 ) {
  7646. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7647. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7648. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7649. }
  7650. // Notify the client that the gstorage is open otherwise it will
  7651. // remain locked forever and nobody will be able to access it
  7652. if( sd->state.storage_flag == 2 ) {
  7653. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7654. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7655. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7656. else {
  7657. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7658. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7659. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7660. }
  7661. }
  7662. }
  7663. // refresh the client's screen, getting rid of any effects
  7664. void clif_refresh(struct map_session_data *sd)
  7665. {
  7666. nullpo_retv(sd);
  7667. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7668. clif_inventorylist(sd);
  7669. if(pc_iscarton(sd)) {
  7670. clif_cartlist(sd);
  7671. clif_updatestatus(sd,SP_CARTINFO);
  7672. }
  7673. clif_updatestatus(sd,SP_WEIGHT);
  7674. clif_updatestatus(sd,SP_MAXWEIGHT);
  7675. clif_updatestatus(sd,SP_STR);
  7676. clif_updatestatus(sd,SP_AGI);
  7677. clif_updatestatus(sd,SP_VIT);
  7678. clif_updatestatus(sd,SP_INT);
  7679. clif_updatestatus(sd,SP_DEX);
  7680. clif_updatestatus(sd,SP_LUK);
  7681. if (sd->spiritball)
  7682. clif_spiritball_single(sd->fd, sd);
  7683. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7684. clif_spiritcharm_single(sd->fd, sd);
  7685. if (sd->vd.cloth_color)
  7686. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7687. if(hom_is_active(sd->hd))
  7688. clif_send_homdata(sd,SP_ACK,0);
  7689. if( sd->md ) {
  7690. clif_mercenary_info(sd);
  7691. clif_mercenary_skillblock(sd);
  7692. }
  7693. if( sd->ed )
  7694. clif_elemental_info(sd);
  7695. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7696. clif_weather_check(sd);
  7697. if( sd->chatID )
  7698. chat_leavechat(sd,0);
  7699. if( sd->state.vending )
  7700. clif_openvending(sd, sd->bl.id, sd->vending);
  7701. if( pc_issit(sd) )
  7702. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7703. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7704. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7705. else
  7706. clif_changed_dir(&sd->bl, SELF);
  7707. // unlike vending, resuming buyingstore crashes the client.
  7708. buyingstore_close(sd);
  7709. mail_clear(sd);
  7710. if( disguised(&sd->bl) ) {/* refresh-da */
  7711. short disguise = sd->disguise;
  7712. pc_disguise(sd, 0);
  7713. pc_disguise(sd, disguise);
  7714. }
  7715. clif_refresh_storagewindow(sd);
  7716. }
  7717. /// Updates the object's (bl) name on client.
  7718. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7719. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7720. void clif_charnameack (int fd, struct block_list *bl)
  7721. {
  7722. unsigned char buf[103];
  7723. int cmd = 0x95;
  7724. nullpo_retv(bl);
  7725. WBUFW(buf,0) = cmd;
  7726. WBUFL(buf,2) = bl->id;
  7727. switch( bl->type )
  7728. {
  7729. case BL_PC:
  7730. {
  7731. struct map_session_data *ssd = (struct map_session_data *)bl;
  7732. struct party_data *p = NULL;
  7733. struct guild *g = NULL;
  7734. int ps = -1;
  7735. //Requesting your own "shadow" name. [Skotlex]
  7736. if (ssd->fd == fd && ssd->disguise)
  7737. WBUFL(buf,2) = -bl->id;
  7738. if( ssd->fakename[0] ) {
  7739. WBUFW(buf, 0) = cmd = 0x195;
  7740. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7741. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7742. break;
  7743. }
  7744. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7745. if( ssd->status.party_id ) {
  7746. p = party_search(ssd->status.party_id);
  7747. }
  7748. if( ssd->status.guild_id ) {
  7749. if( ( g = ssd->guild ) != NULL ) {
  7750. int i;
  7751. 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);
  7752. if( i < g->max_member ) ps = g->member[i].position;
  7753. }
  7754. }
  7755. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7756. p = NULL;
  7757. }
  7758. if (p == NULL && g == NULL)
  7759. break;
  7760. WBUFW(buf, 0) = cmd = 0x195;
  7761. if (p)
  7762. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7763. else
  7764. WBUFB(buf,30) = 0;
  7765. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7766. {
  7767. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7768. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7769. } else { //Assume no guild.
  7770. WBUFB(buf,54) = 0;
  7771. WBUFB(buf,78) = 0;
  7772. }
  7773. }
  7774. break;
  7775. //[blackhole89]
  7776. case BL_HOM:
  7777. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7778. break;
  7779. case BL_MER:
  7780. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7781. break;
  7782. case BL_PET:
  7783. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7784. break;
  7785. case BL_NPC:
  7786. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7787. break;
  7788. case BL_MOB:
  7789. {
  7790. struct mob_data *md = (struct mob_data *)bl;
  7791. nullpo_retv(md);
  7792. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7793. if( md->guardian_data && md->guardian_data->guild_id )
  7794. {
  7795. WBUFW(buf, 0) = cmd = 0x195;
  7796. WBUFB(buf,30) = 0;
  7797. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7798. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7799. }
  7800. else if( battle_config.show_mob_info )
  7801. {
  7802. char mobhp[50], *str_p = mobhp;
  7803. WBUFW(buf, 0) = cmd = 0x195;
  7804. if( battle_config.show_mob_info&4 )
  7805. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7806. if( battle_config.show_mob_info&1 )
  7807. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7808. if( battle_config.show_mob_info&2 )
  7809. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7810. //Even thought mobhp ain't a name, we send it as one so the client
  7811. //can parse it. [Skotlex]
  7812. if( str_p != mobhp )
  7813. {
  7814. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7815. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7816. WBUFB(buf,54) = 0;
  7817. WBUFB(buf,78) = 0;
  7818. }
  7819. }
  7820. }
  7821. break;
  7822. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7823. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7824. // break;
  7825. return;
  7826. case BL_ELEM:
  7827. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7828. break;
  7829. default:
  7830. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7831. return;
  7832. }
  7833. // if no receipient specified just update nearby clients
  7834. if (fd == 0)
  7835. clif_send(buf, packet_len(cmd), bl, AREA);
  7836. else {
  7837. WFIFOHEAD(fd, packet_len(cmd));
  7838. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7839. WFIFOSET(fd, packet_len(cmd));
  7840. }
  7841. }
  7842. //Used to update when a char leaves a party/guild. [Skotlex]
  7843. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7844. void clif_charnameupdate (struct map_session_data *ssd)
  7845. {
  7846. unsigned char buf[103];
  7847. int cmd = 0x195, ps = -1;
  7848. struct party_data *p = NULL;
  7849. struct guild *g = NULL;
  7850. nullpo_retv(ssd);
  7851. if( ssd->fakename[0] )
  7852. return; //No need to update as the party/guild was not displayed anyway.
  7853. WBUFW(buf,0) = cmd;
  7854. WBUFL(buf,2) = ssd->bl.id;
  7855. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7856. if (!battle_config.display_party_name) {
  7857. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7858. p = party_search(ssd->status.party_id);
  7859. }else{
  7860. if (ssd->status.party_id > 0)
  7861. p = party_search(ssd->status.party_id);
  7862. }
  7863. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7864. {
  7865. int i;
  7866. 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);
  7867. if( i < g->max_member ) ps = g->member[i].position;
  7868. }
  7869. if( p )
  7870. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7871. else
  7872. WBUFB(buf,30) = 0;
  7873. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7874. {
  7875. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7876. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7877. }
  7878. else
  7879. {
  7880. WBUFB(buf,54) = 0;
  7881. WBUFB(buf,78) = 0;
  7882. }
  7883. // Update nearby clients
  7884. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7885. }
  7886. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7887. /// 01ff <id>.L <x>.W <y>.W
  7888. ///
  7889. /// Visually moves(instant) a character to x,y. The char moves even
  7890. /// when the target cell isn't walkable. If the char is sitting it
  7891. /// stays that way.
  7892. void clif_slide(struct block_list *bl, int x, int y)
  7893. {
  7894. unsigned char buf[10];
  7895. nullpo_retv(bl);
  7896. WBUFW(buf, 0) = 0x01ff;
  7897. WBUFL(buf, 2) = bl->id;
  7898. WBUFW(buf, 6) = x;
  7899. WBUFW(buf, 8) = y;
  7900. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7901. if( disguised(bl) )
  7902. {
  7903. WBUFL(buf,2) = -bl->id;
  7904. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7905. }
  7906. }
  7907. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7908. /// 008d <packet len>.W <id>.L <message>.?B
  7909. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7910. {
  7911. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7912. int len_mes = strlen(mes)+1; //Account for \0
  7913. if (len_mes > sizeof(buf)-8) {
  7914. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7915. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7916. }
  7917. // send message to others
  7918. WBUFW(buf,0) = 0x8d;
  7919. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7920. WBUFL(buf,4) = bl->id;
  7921. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7922. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7923. // send back message to the speaker
  7924. if( bl->type == BL_PC ) {
  7925. WBUFW(buf,0) = 0x8e;
  7926. WBUFW(buf, 2) = len_mes + 4;
  7927. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7928. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7929. }
  7930. }
  7931. /*==========================
  7932. * Minimap fix [Kevin]
  7933. * Remove dot from minimap
  7934. *--------------------------*/
  7935. void clif_party_xy_remove(struct map_session_data *sd)
  7936. {
  7937. unsigned char buf[16];
  7938. nullpo_retv(sd);
  7939. WBUFW(buf,0)=0x107;
  7940. WBUFL(buf,2)=sd->status.account_id;
  7941. WBUFW(buf,6)=-1;
  7942. WBUFW(buf,8)=-1;
  7943. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7944. }
  7945. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7946. /// 0215 <msg id>.L
  7947. /// msg id:
  7948. /// 0x15 = End all negative status (PA_GOSPEL)
  7949. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7950. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7951. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7952. /// 0x19 = All stats +20 (PA_GOSPEL)
  7953. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7954. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7955. /// 0x1e = DEF +25% (PA_GOSPEL)
  7956. /// 0x1f = ATK +100% (PA_GOSPEL)
  7957. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7958. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7959. /// ? = nothing
  7960. void clif_gospel_info(struct map_session_data *sd, int type)
  7961. {
  7962. int fd=sd->fd;
  7963. WFIFOHEAD(fd,packet_len(0x215));
  7964. WFIFOW(fd,0)=0x215;
  7965. WFIFOL(fd,2)=type;
  7966. WFIFOSET(fd, packet_len(0x215));
  7967. }
  7968. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7969. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7970. /// result:
  7971. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7972. /// star:
  7973. /// 0 = Place of the Sun
  7974. /// 1 = Place of the Moon
  7975. /// 2 = Place of the Stars
  7976. /// 1 = Star Gladiator %s's %s: <mapname>
  7977. /// star:
  7978. /// 0 = Place of the Sun
  7979. /// 1 = Place of the Moon
  7980. /// 2 = Place of the Stars
  7981. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7982. /// star:
  7983. /// 0 = Target of the Sun
  7984. /// 1 = Target of the Moon
  7985. /// 2 = Target of the Stars
  7986. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7987. /// star:
  7988. /// 0 = Monster of the Sun
  7989. /// 1 = Monster of the Moon
  7990. /// 2 = Monster of the Stars
  7991. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7992. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7993. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7994. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7995. /// 40 = Target HP : <monster_id used as HP>
  7996. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7997. {
  7998. int fd = sd->fd;
  7999. WFIFOHEAD(fd,packet_len(0x20e));
  8000. WFIFOW(fd,0) = 0x20e;
  8001. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8002. WFIFOL(fd,26) = monster_id;
  8003. WFIFOB(fd,30) = star;
  8004. WFIFOB(fd,31) = result;
  8005. WFIFOSET(fd,packet_len(0x20e));
  8006. }
  8007. /*==========================================
  8008. * Info about Star Glaldiator save map [Komurka]
  8009. * type: 1: Information, 0: Map registered
  8010. *------------------------------------------*/
  8011. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8012. {
  8013. char mapname[MAP_NAME_LENGTH_EXT];
  8014. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8015. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8016. }
  8017. /*==========================================
  8018. * Info about Star Glaldiator hate mob [Komurka]
  8019. * type: 1: Register mob, 0: Information.
  8020. *------------------------------------------*/
  8021. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8022. {
  8023. if( pcdb_checkid(class_) ) {
  8024. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8025. } else if( mobdb_checkid(class_) ) {
  8026. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8027. } else {
  8028. 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);
  8029. }
  8030. }
  8031. /*==========================================
  8032. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8033. *------------------------------------------*/
  8034. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8035. {
  8036. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8037. }
  8038. /*==========================================
  8039. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8040. *------------------------------------------*/
  8041. void clif_feel_hate_reset(struct map_session_data *sd)
  8042. {
  8043. clif_starskill(sd, "", 0, 0, 30);
  8044. }
  8045. /// Equip window (un)tick ack (ZC_CONFIG).
  8046. /// 02d9 <type>.L <value>.L
  8047. /// type:
  8048. /// 0 = open equip window
  8049. /// value:
  8050. /// 0 = disabled
  8051. /// 1 = enabled
  8052. void clif_equiptickack(struct map_session_data* sd, int flag)
  8053. {
  8054. int fd;
  8055. nullpo_retv(sd);
  8056. fd = sd->fd;
  8057. WFIFOHEAD(fd, packet_len(0x2d9));
  8058. WFIFOW(fd, 0) = 0x2d9;
  8059. WFIFOL(fd, 2) = 0;
  8060. WFIFOL(fd, 6) = flag;
  8061. WFIFOSET(fd, packet_len(0x2d9));
  8062. }
  8063. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8064. /// 02da <open equip window>.B
  8065. /// open equip window:
  8066. /// 0 = disabled
  8067. /// 1 = enabled
  8068. void clif_equipcheckbox(struct map_session_data* sd)
  8069. {
  8070. int fd;
  8071. nullpo_retv(sd);
  8072. fd = sd->fd;
  8073. WFIFOHEAD(fd, packet_len(0x2da));
  8074. WFIFOW(fd, 0) = 0x2da;
  8075. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8076. WFIFOSET(fd, packet_len(0x2da));
  8077. }
  8078. /// Sends info about a player's equipped items.
  8079. /// 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)
  8080. /// 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)
  8081. /// 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)
  8082. /// 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)
  8083. /// 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)
  8084. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8085. {
  8086. uint8* buf;
  8087. int i, n, fd, offset = 0;
  8088. #if PACKETVER < 20100629
  8089. const int s = 26;
  8090. #elif PACKETVER < 20120925
  8091. const int s = 28;
  8092. #else
  8093. const int s = 31;
  8094. #endif
  8095. nullpo_retv(sd);
  8096. nullpo_retv(tsd);
  8097. fd = sd->fd;
  8098. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8099. buf = WFIFOP(fd,0);
  8100. #if PACKETVER < 20101124
  8101. WBUFW(buf, 0) = 0x2d7;
  8102. #elif PACKETVER < 20120925
  8103. WBUFW(buf, 0) = 0x859;
  8104. #else
  8105. WBUFW(buf, 0) = 0x997;
  8106. #endif
  8107. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8108. WBUFW(buf,28) = tsd->status.class_;
  8109. WBUFW(buf,30) = tsd->vd.hair_style;
  8110. WBUFW(buf,32) = tsd->vd.head_bottom;
  8111. WBUFW(buf,34) = tsd->vd.head_mid;
  8112. WBUFW(buf,36) = tsd->vd.head_top;
  8113. #if PACKETVER >= 20110111
  8114. WBUFW(buf,38) = tsd->vd.robe;
  8115. offset+= 2;
  8116. buf = WBUFP(buf,2);
  8117. #endif
  8118. WBUFW(buf,38) = tsd->vd.hair_color;
  8119. WBUFW(buf,40) = tsd->vd.cloth_color;
  8120. WBUFB(buf,42) = tsd->vd.sex;
  8121. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8122. {
  8123. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8124. continue;
  8125. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8126. continue;
  8127. // Add item info : refine, identify flag, element, etc.
  8128. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8129. n++;
  8130. }
  8131. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8132. WFIFOSET(fd, WFIFOW(fd, 2));
  8133. }
  8134. /// Display msgstringtable.txt string (ZC_MSG).
  8135. /// 0291 <message>.W
  8136. void clif_msg(struct map_session_data* sd, unsigned short id)
  8137. {
  8138. int fd;
  8139. nullpo_retv(sd);
  8140. fd = sd->fd;
  8141. WFIFOHEAD(fd, packet_len(0x291));
  8142. WFIFOW(fd, 0) = 0x291;
  8143. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8144. WFIFOSET(fd, packet_len(0x291));
  8145. }
  8146. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8147. /// 0x7e2 <message>.W <value>.L
  8148. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8149. {
  8150. int fd = sd->fd;
  8151. WFIFOHEAD(fd, packet_len(0x7e2));
  8152. WFIFOW(fd,0) = 0x7e2;
  8153. WFIFOW(fd,2) = id;
  8154. WFIFOL(fd,4) = value;
  8155. WFIFOSET(fd, packet_len(0x7e2));
  8156. }
  8157. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8158. /// 07e6 <skill id>.W <msg id>.L
  8159. ///
  8160. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8161. /// "[SkillName] Message"
  8162. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8163. {
  8164. int fd = sd->fd;
  8165. WFIFOHEAD(fd, packet_len(0x7e6));
  8166. WFIFOW(fd,0) = 0x7e6;
  8167. WFIFOW(fd,2) = skill_id;
  8168. WFIFOL(fd,4) = msg_id;
  8169. WFIFOSET(fd, packet_len(0x7e6));
  8170. }
  8171. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8172. /// Returns true if the packet was parsed successfully.
  8173. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8174. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8175. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  8176. {
  8177. char *text, *name, *message;
  8178. unsigned int packetlen, textlen, namelen, messagelen;
  8179. int fd = sd->fd;
  8180. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8181. *name_ = NULL;
  8182. *namelen_ = 0;
  8183. *message_ = NULL;
  8184. *messagelen_ = 0;
  8185. packetlen = RFIFOW(fd,info->pos[0]);
  8186. // basic structure checks
  8187. if( packetlen < 4 + 1 )
  8188. { // 4-byte header and at least an empty string is expected
  8189. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8190. return false;
  8191. }
  8192. text = (char*)RFIFOP(fd,info->pos[1]);
  8193. textlen = packetlen - 4;
  8194. // process <name> part of the packet
  8195. if( format == 0 )
  8196. {// name and message are separated by ' : '
  8197. // validate name
  8198. name = text;
  8199. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8200. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8201. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8202. {
  8203. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8204. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8205. set_eof(fd); // Just kick them out to correct it.
  8206. return false;
  8207. }
  8208. message = name + namelen + 3;
  8209. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8210. }
  8211. else
  8212. {// name has fixed width
  8213. if( textlen < NAME_LENGTH + 1 )
  8214. {
  8215. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8216. return false;
  8217. }
  8218. // validate name
  8219. name = text;
  8220. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8221. if( name[namelen] != '\0' )
  8222. { // only restriction is that the name must be zero-terminated
  8223. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8224. return false;
  8225. }
  8226. message = name + NAME_LENGTH;
  8227. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8228. }
  8229. if( messagelen != strnlen(message, messagelen)+1 )
  8230. { // the declared length must match real length
  8231. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8232. return false;
  8233. }
  8234. // verify <message> part of the packet
  8235. if( message[messagelen-1] != '\0' )
  8236. { // message must be zero-terminated
  8237. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8238. return false;
  8239. }
  8240. if( messagelen > CHAT_SIZE_MAX-1 )
  8241. { // messages mustn't be too long
  8242. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8243. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8244. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8245. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8246. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8247. return false;
  8248. }
  8249. *name_ = name;
  8250. *namelen_ = namelen;
  8251. *message_ = message;
  8252. *messagelen_ = messagelen;
  8253. return true;
  8254. }
  8255. // ---------------------
  8256. // clif_guess_PacketVer
  8257. // ---------------------
  8258. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8259. // error codes:
  8260. // 0 - Success
  8261. // 1 - Unknown packet_ver
  8262. // 2 - Invalid account_id
  8263. // 3 - Invalid char_id
  8264. // 4 - Invalid login_id1 (reserved)
  8265. // 5 - Invalid client_tick (reserved)
  8266. // 6 - Invalid sex
  8267. // Only the first 'invalid' error that appears is used.
  8268. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8269. {
  8270. static int err = 1;
  8271. static int packet_ver = -1;
  8272. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8273. unsigned short cmd;
  8274. if (get_previous)
  8275. {//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]
  8276. if( error )
  8277. *error = err;
  8278. return packet_ver;
  8279. }
  8280. //By default, start searching on the default one.
  8281. err = 1;
  8282. packet_ver = clif_config.packet_db_ver;
  8283. cmd = clif_parse_cmd(fd, NULL);
  8284. packet_len = RFIFOREST(fd);
  8285. #define SET_ERROR(n) \
  8286. if( err == 1 )\
  8287. err = n;\
  8288. //define SET_ERROR
  8289. // FIXME: If the packet is not received at once, this will FAIL.
  8290. // Figure out, when it happens, that only part of the packet is
  8291. // received, or fix the function to be able to deal with that
  8292. // case.
  8293. #define CHECK_PACKET_VER() \
  8294. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8295. ;/* not wanttoconnection or wrong length */\
  8296. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8297. { SET_ERROR(2); }/* invalid account_id */\
  8298. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8299. { SET_ERROR(3); }/* invalid char_id */\
  8300. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8301. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8302. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8303. { SET_ERROR(6); }/* invalid sex */\
  8304. else\
  8305. {\
  8306. err = 0;\
  8307. if( error )\
  8308. *error = 0;\
  8309. return packet_ver;\
  8310. }\
  8311. //define CHECK_PACKET_VER
  8312. CHECK_PACKET_VER();//Default packet version found.
  8313. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8314. CHECK_PACKET_VER();
  8315. }
  8316. if( error )
  8317. *error = err;
  8318. packet_ver = -1;
  8319. return -1;
  8320. #undef SET_ERROR
  8321. #undef CHECK_PACKET_VER
  8322. }
  8323. // ------------
  8324. // clif_parse_*
  8325. // ------------
  8326. // Parses incoming (player) connection
  8327. /// Request to connect to map-server.
  8328. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8329. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8330. /// There are various variants of this packet, some of them have padding between fields.
  8331. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8332. {
  8333. struct block_list* bl;
  8334. struct auth_node* node;
  8335. int cmd, account_id, char_id, login_id1, sex;
  8336. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8337. 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])
  8338. if (sd) {
  8339. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8340. return;
  8341. }
  8342. // Only valid packet version get here
  8343. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8344. cmd = RFIFOW(fd,0);
  8345. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8346. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8347. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8348. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8349. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8350. if( packet_ver < 5 || // reject really old client versions
  8351. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8352. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8353. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8354. {// packet version rejected
  8355. 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));
  8356. WFIFOHEAD(fd,packet_len(0x6a));
  8357. WFIFOW(fd,0) = 0x6a;
  8358. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8359. WFIFOSET(fd,packet_len(0x6a));
  8360. set_eof(fd);
  8361. return;
  8362. }
  8363. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8364. clif_authfail_fd(fd,1);// server closed
  8365. return;
  8366. }
  8367. //Check for double login.
  8368. bl = map_id2bl(account_id);
  8369. if(bl && bl->type != BL_PC) {
  8370. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8371. WFIFOHEAD(fd,packet_len(0x6a));
  8372. WFIFOW(fd,0) = 0x6a;
  8373. WFIFOB(fd,2) = 3; // Rejected by server
  8374. WFIFOSET(fd,packet_len(0x6a));
  8375. set_eof(fd);
  8376. return;
  8377. }
  8378. if (bl ||
  8379. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8380. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8381. {
  8382. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8383. return;
  8384. }
  8385. CREATE(sd, TBL_PC, 1);
  8386. sd->fd = fd;
  8387. sd->packet_ver = packet_ver;
  8388. #ifdef PACKET_OBFUSCATION
  8389. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8390. #endif
  8391. session[fd]->session_data = sd;
  8392. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8393. #if PACKETVER < 20070521
  8394. WFIFOHEAD(fd,4);
  8395. WFIFOL(fd,0) = sd->bl.id;
  8396. WFIFOSET(fd,4);
  8397. #else
  8398. WFIFOHEAD(fd,packet_len(0x283));
  8399. WFIFOW(fd,0) = 0x283;
  8400. WFIFOL(fd,2) = sd->bl.id;
  8401. WFIFOSET(fd,packet_len(0x283));
  8402. #endif
  8403. chrif_authreq(sd,false);
  8404. }
  8405. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8406. /// 007d
  8407. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8408. {
  8409. int i;
  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. map_addblock(&sd->ed->bl);
  8530. clif_spawn(&sd->ed->bl);
  8531. clif_elemental_info(sd);
  8532. clif_elemental_updatestatus(sd,SP_HP);
  8533. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8534. clif_elemental_updatestatus(sd,SP_SP);
  8535. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8536. }
  8537. if(sd->state.connect_new) {
  8538. int lv;
  8539. guild_notice = true;
  8540. sd->state.connect_new = 0;
  8541. clif_skillinfoblock(sd);
  8542. clif_hotkeys_send(sd);
  8543. clif_updatestatus(sd,SP_BASEEXP);
  8544. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8545. clif_updatestatus(sd,SP_JOBEXP);
  8546. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8547. clif_updatestatus(sd,SP_SKILLPOINT);
  8548. clif_initialstatus(sd);
  8549. if (sd->sc.option&OPTION_FALCON)
  8550. clif_status_load(&sd->bl, SI_FALCON, 1);
  8551. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8552. clif_status_load(&sd->bl, SI_RIDING, 1);
  8553. else if (sd->sc.option&OPTION_WUGRIDER)
  8554. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8555. else if (sd->sc.data[SC_ALL_RIDING])
  8556. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8557. if(sd->status.manner < 0)
  8558. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8559. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8560. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8561. if(sd->bl.m == sd->feel_map[0].m
  8562. || sd->bl.m == sd->feel_map[1].m
  8563. || sd->bl.m == sd->feel_map[2].m)
  8564. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8565. }
  8566. if(sd->pd && sd->pd->pet.intimate > 900)
  8567. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8568. if(hom_is_active(sd->hd))
  8569. hom_init_timers(sd->hd);
  8570. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8571. sd->state.night = 1;
  8572. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8573. }
  8574. // Notify everyone that this char logged in [Skotlex].
  8575. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8576. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8577. //Login Event
  8578. npc_script_event(sd, NPCE_LOGIN);
  8579. }
  8580. } else {
  8581. //For some reason the client "loses" these on warp/map-change.
  8582. clif_updatestatus(sd,SP_STR);
  8583. clif_updatestatus(sd,SP_AGI);
  8584. clif_updatestatus(sd,SP_VIT);
  8585. clif_updatestatus(sd,SP_INT);
  8586. clif_updatestatus(sd,SP_DEX);
  8587. clif_updatestatus(sd,SP_LUK);
  8588. // abort currently running script
  8589. sd->state.using_fake_npc = 0;
  8590. sd->state.menu_or_input = 0;
  8591. sd->npc_menu = 0;
  8592. if(sd->npc_id)
  8593. npc_event_dequeue(sd);
  8594. }
  8595. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8596. #if PACKETVER >= 20070918
  8597. clif_partyinvitationstate(sd);
  8598. clif_equipcheckbox(sd);
  8599. #endif
  8600. #ifdef VIP_ENABLE
  8601. if (!sd->disableshowrate) {
  8602. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8603. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8604. }
  8605. #endif
  8606. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8607. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8608. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8609. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8610. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8611. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8612. { //Display night.
  8613. if( !sd->state.night )
  8614. {
  8615. sd->state.night = 1;
  8616. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8617. }
  8618. }
  8619. else if( sd->state.night )
  8620. { //Clear night display.
  8621. sd->state.night = 0;
  8622. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8623. }
  8624. if( map[sd->bl.m].flag.battleground )
  8625. {
  8626. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8627. if( map[sd->bl.m].flag.battleground == 2 )
  8628. clif_bg_updatescore_single(sd);
  8629. }
  8630. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8631. {
  8632. char output[128];
  8633. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8634. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8635. }
  8636. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8637. map[sd->bl.m].hpmeter_visible++;
  8638. sd->state.hpmeter_visible = 1;
  8639. }
  8640. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8641. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8642. sd->state.changemap = false;
  8643. // Instances do not need their own channels
  8644. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8645. channel_mjoin(sd); //join new map
  8646. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8647. clif_guild_notice(sd, sd->guild); // Displays at end
  8648. mail_clear(sd);
  8649. clif_maptypeproperty2(&sd->bl,SELF);
  8650. /* Guild Aura Init */
  8651. if( sd->state.gmaster_flag ) {
  8652. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8653. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8654. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8655. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8656. }
  8657. if( sd->state.vending ) { /* show we have a vending */
  8658. clif_openvending(sd,sd->bl.id,sd->vending);
  8659. clif_showvendingboard(&sd->bl,sd->message,0);
  8660. }
  8661. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8662. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8663. npc_script_event(sd, NPCE_LOADMAP);
  8664. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8665. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8666. if (sd->sc.opt2) //Client loses these on warp.
  8667. clif_changeoption(&sd->bl);
  8668. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8669. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8670. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8671. }
  8672. clif_weather_check(sd);
  8673. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8674. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8675. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8676. else
  8677. sd->areanpc_id = 0;
  8678. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8679. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8680. pc_setdead(sd);
  8681. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8682. if(pc_isdead(sd))
  8683. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8684. else {
  8685. skill_usave_trigger(sd);
  8686. if (battle_config.spawn_direction)
  8687. clif_changed_dir(&sd->bl, SELF);
  8688. }
  8689. // Trigger skill effects if you appear standing on them
  8690. if(!battle_config.pc_invincible_time)
  8691. skill_unit_move(&sd->bl,gettick(),1);
  8692. // NPC Quest / Event Icon Check [Kisuka]
  8693. #if PACKETVER >= 20090218
  8694. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8695. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8696. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8697. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8698. if( sd->class_ == qi->job )
  8699. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8700. } else {
  8701. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8702. }
  8703. }
  8704. }
  8705. #endif
  8706. }
  8707. /// Server's tick (ZC_NOTIFY_TIME).
  8708. /// 007f <time>.L
  8709. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8710. {
  8711. int fd = sd->fd;
  8712. WFIFOHEAD(fd,packet_len(0x7f));
  8713. WFIFOW(fd,0) = 0x7f;
  8714. WFIFOL(fd,2) = time;
  8715. WFIFOSET(fd,packet_len(0x7f));
  8716. }
  8717. /// Request for server's tick.
  8718. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8719. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8720. /// There are various variants of this packet, some of them have padding between fields.
  8721. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8722. {
  8723. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8724. clif_notify_time(sd, gettick());
  8725. }
  8726. /// Sends hotkey bar.
  8727. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8728. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8729. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8730. void clif_hotkeys_send(struct map_session_data *sd) {
  8731. #ifdef HOTKEY_SAVING
  8732. const int fd = sd->fd;
  8733. int i;
  8734. int offset = 2;
  8735. #if PACKETVER < 20090603
  8736. const int cmd = 0x2b9;
  8737. #elif PACKETVER < 20141022
  8738. const int cmd = 0x7d9;
  8739. #else
  8740. const int cmd = 0xa00;
  8741. offset = 3;
  8742. #endif
  8743. if (!fd) return;
  8744. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8745. WFIFOW(fd, 0) = cmd;
  8746. for(i = 0; i < MAX_HOTKEYS; i++) {
  8747. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8748. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8749. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8750. }
  8751. WFIFOSET(fd, packet_len(cmd));
  8752. #endif
  8753. }
  8754. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8755. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8756. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8757. #ifdef HOTKEY_SAVING
  8758. unsigned short idx;
  8759. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8760. idx = RFIFOW(fd, info->pos[0]);
  8761. if (idx >= MAX_HOTKEYS) return;
  8762. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8763. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8764. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8765. #endif
  8766. }
  8767. /// Displays cast-like progress bar (ZC_PROGRESS).
  8768. /// 02f0 <color>.L <time>.L
  8769. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8770. {
  8771. int fd = sd->fd;
  8772. WFIFOHEAD(fd,packet_len(0x2f0));
  8773. WFIFOW(fd,0) = 0x2f0;
  8774. WFIFOL(fd,2) = color;
  8775. WFIFOL(fd,6) = second;
  8776. WFIFOSET(fd,packet_len(0x2f0));
  8777. }
  8778. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8779. /// 02f2
  8780. void clif_progressbar_abort(struct map_session_data * sd)
  8781. {
  8782. int fd = sd->fd;
  8783. WFIFOHEAD(fd,packet_len(0x2f2));
  8784. WFIFOW(fd,0) = 0x2f2;
  8785. WFIFOSET(fd,packet_len(0x2f2));
  8786. }
  8787. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8788. /// 02f1
  8789. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8790. {
  8791. int npc_id = sd->progressbar.npc_id;
  8792. if( gettick() < sd->progressbar.timeout && sd->st )
  8793. sd->st->state = END;
  8794. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8795. npc_scriptcont(sd, npc_id, false);
  8796. }
  8797. /// Request to walk to a certain position on the current map.
  8798. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8799. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8800. /// There are various variants of this packet, some of them have padding between fields.
  8801. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8802. {
  8803. short x, y;
  8804. if (pc_isdead(sd)) {
  8805. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8806. return;
  8807. }
  8808. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8809. ; //You CAN walk on this OPT1 value.
  8810. else if( sd->progressbar.npc_id )
  8811. clif_progressbar_abort(sd);
  8812. else if (pc_cant_act(sd))
  8813. return;
  8814. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8815. return;
  8816. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8817. //A move command one cell west is only valid if the target cell is free
  8818. if(battle_config.official_cell_stack_limit > 0
  8819. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  8820. return;
  8821. // Cloaking wall check is actually updated when you click to process next movement
  8822. // not when you move each cell. This is official behaviour.
  8823. if (sd->sc.data[SC_CLOAKING])
  8824. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8825. pc_delinvincibletimer(sd);
  8826. //Set last idle time... [Skotlex]
  8827. if (battle_config.idletime_option&IDLE_WALK)
  8828. sd->idletime = last_tick;
  8829. unit_walktoxy(&sd->bl, x, y, 4);
  8830. }
  8831. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8832. /// 018b <result>.W
  8833. /// result:
  8834. /// 0 = disconnect (quit)
  8835. /// 1 = cannot disconnect (wait 10 seconds)
  8836. /// ? = ignored
  8837. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8838. {
  8839. int fd = sd->fd;
  8840. WFIFOHEAD(fd,packet_len(0x18b));
  8841. WFIFOW(fd,0) = 0x18b;
  8842. WFIFOW(fd,2) = result;
  8843. WFIFOSET(fd,packet_len(0x18b));
  8844. }
  8845. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8846. /// 018a <type>.W
  8847. /// type:
  8848. /// 0 = quit
  8849. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8850. {
  8851. /* Rovert's prevent logout option fixed [Valaris] */
  8852. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8853. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8854. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8855. {
  8856. set_eof(fd);
  8857. pc_damage_log_clear(sd,0);
  8858. clif_disconnect_ack(sd, 0);
  8859. } else {
  8860. clif_disconnect_ack(sd, 1);
  8861. }
  8862. }
  8863. /// Requesting unit's name.
  8864. /// 0094 <id>.L (CZ_REQNAME)
  8865. /// 0368 <id>.L (CZ_REQNAME2)
  8866. /// There are various variants of this packet, some of them have padding between fields.
  8867. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8868. {
  8869. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8870. struct block_list* bl;
  8871. //struct status_change *sc;
  8872. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8873. id = sd->bl.id;
  8874. bl = map_id2bl(id);
  8875. if( bl == NULL )
  8876. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8877. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8878. return; // Block namerequests past view range
  8879. // 'see people in GM hide' cheat detection
  8880. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8881. sc = status_get_sc(bl);
  8882. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8883. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8884. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8885. ) {
  8886. char gm_msg[256];
  8887. 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);
  8888. ShowWarning(gm_msg);
  8889. // information is sent to all online GMs
  8890. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8891. return;
  8892. }
  8893. */
  8894. clif_charnameack(fd, bl);
  8895. }
  8896. /// Validates and processes global messages
  8897. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8898. /// There are various variants of this packet.
  8899. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8900. {
  8901. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8902. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8903. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8904. char *name, *message, *fakename = NULL;
  8905. int namelen, messagelen;
  8906. bool is_fake;
  8907. // validate packet and retrieve name and message
  8908. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8909. return;
  8910. if( is_atcommand(fd, sd, message, 1) )
  8911. return;
  8912. if (sd->sc.cant.chat)
  8913. return; //no "chatting" while muted.
  8914. if( battle_config.min_chat_delay ) { //[Skotlex]
  8915. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8916. return;
  8917. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8918. }
  8919. if (battle_config.idletime_option&IDLE_CHAT)
  8920. sd->idletime = last_tick;
  8921. if( sd->gcbind ) {
  8922. channel_send(sd->gcbind,sd,message);
  8923. return;
  8924. }
  8925. /**
  8926. * Fake Name Design by FatalEror (bug report #9)
  8927. **/
  8928. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8929. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8930. strcpy(fakename, sd->fakename);
  8931. strcat(fakename, " : ");
  8932. strcat(fakename, message);
  8933. textlen = strlen(fakename) + 1;
  8934. }
  8935. // send message to others (using the send buffer for temp. storage)
  8936. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8937. // send back message to the speaker
  8938. if( is_fake ) {
  8939. WFIFOW(fd,0) = 0x8e;
  8940. WFIFOW(fd,2) = textlen + 4;
  8941. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8942. aFree(fakename);
  8943. } else {
  8944. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8945. WFIFOW(fd,0) = 0x8e;
  8946. }
  8947. WFIFOSET(fd, WFIFOW(fd,2));
  8948. #ifdef PCRE_SUPPORT
  8949. // trigger listening npcs
  8950. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8951. #endif
  8952. // Chat logging type 'O' / Global Chat
  8953. 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);
  8954. }
  8955. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8956. /// Request to warp to a map on given coordinates.
  8957. /// 0140 <map name>.16B <x>.W <y>.W
  8958. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8959. {
  8960. char command[MAP_NAME_LENGTH_EXT+25];
  8961. char* map_name;
  8962. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8963. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8964. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8965. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8966. RFIFOW(fd,info->pos[1]), //x
  8967. RFIFOW(fd,info->pos[2])); //y
  8968. is_atcommand(fd, sd, command, 1);
  8969. }
  8970. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8971. /// 009c <id>.L <head dir>.W <dir>.B
  8972. /// head dir:
  8973. /// 0 = straight
  8974. /// 1 = turned CW
  8975. /// 2 = turned CCW
  8976. /// dir:
  8977. /// 0 = north
  8978. /// 1 = northwest
  8979. /// 2 = west
  8980. /// 3 = southwest
  8981. /// 4 = south
  8982. /// 5 = southeast
  8983. /// 6 = east
  8984. /// 7 = northeast
  8985. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8986. {
  8987. unsigned char buf[64];
  8988. WBUFW(buf,0) = 0x9c;
  8989. WBUFL(buf,2) = bl->id;
  8990. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8991. WBUFB(buf,8) = unit_getdir(bl);
  8992. clif_send(buf, packet_len(0x9c), bl, target);
  8993. if (disguised(bl)) {
  8994. WBUFL(buf,2) = -bl->id;
  8995. WBUFW(buf,6) = 0;
  8996. clif_send(buf, packet_len(0x9c), bl, SELF);
  8997. }
  8998. }
  8999. /// Request to change own body and head direction.
  9000. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9001. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9002. /// There are various variants of this packet, some of them have padding between fields.
  9003. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9004. {
  9005. unsigned char headdir, dir;
  9006. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9007. headdir = RFIFOB(fd,info->pos[0]);
  9008. dir = RFIFOB(fd,info->pos[1]);
  9009. pc_setdir(sd, dir, headdir);
  9010. clif_changed_dir(&sd->bl, AREA_WOS);
  9011. }
  9012. /// Request to show an emotion (CZ_REQ_EMOTION).
  9013. /// 00bf <type>.B
  9014. /// type:
  9015. /// @see enum emotion_type
  9016. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9017. {
  9018. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9019. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  9020. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9021. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9022. return;
  9023. }
  9024. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9025. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9026. sd->emotionlasttime = time(NULL);
  9027. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9028. return;
  9029. }
  9030. sd->emotionlasttime = time(NULL);
  9031. if (battle_config.idletime_option&IDLE_EMOTION)
  9032. sd->idletime = last_tick;
  9033. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9034. emoticon = rnd()%6+E_DICE1;
  9035. }
  9036. clif_emotion(&sd->bl, emoticon);
  9037. } else
  9038. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9039. }
  9040. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9041. /// 00c2 <count>.L
  9042. void clif_user_count(struct map_session_data* sd, int count)
  9043. {
  9044. int fd = sd->fd;
  9045. WFIFOHEAD(fd,packet_len(0xc2));
  9046. WFIFOW(fd,0) = 0xc2;
  9047. WFIFOL(fd,2) = count;
  9048. WFIFOSET(fd,packet_len(0xc2));
  9049. }
  9050. /// /w /who (CZ_REQ_USER_COUNT).
  9051. /// Request to display amount of currently connected players.
  9052. /// 00c1
  9053. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9054. {
  9055. clif_user_count(sd, map_getusers());
  9056. }
  9057. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9058. {
  9059. if (pc_isdead(sd)) {
  9060. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9061. return;
  9062. }
  9063. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9064. // (not all are included in pc_can_attack)
  9065. if (sd->sc.count &&
  9066. (sd->sc.data[SC_TRICKDEAD] ||
  9067. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9068. sd->sc.data[SC_BLADESTOP] ||
  9069. sd->sc.data[SC__MANHOLE] ))
  9070. return;
  9071. if(action_type != 0x00 && action_type != 0x07)
  9072. pc_stop_walking(sd, 1);
  9073. pc_stop_attack(sd);
  9074. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9075. target_id = sd->bl.id;
  9076. switch(action_type)
  9077. {
  9078. case 0x00: // once attack
  9079. case 0x07: // continuous attack
  9080. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9081. return;
  9082. if( sd->sc.option&OPTION_COSTUME )
  9083. return;
  9084. if( sd->sc.option&OPTION_COSTUME )
  9085. return;
  9086. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9087. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9088. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9089. return;
  9090. }
  9091. }
  9092. pc_delinvincibletimer(sd);
  9093. if (battle_config.idletime_option&IDLE_ATTACK)
  9094. sd->idletime = last_tick;
  9095. unit_attack(&sd->bl, target_id, action_type != 0);
  9096. break;
  9097. case 0x02: // sitdown
  9098. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  9099. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9100. break;
  9101. }
  9102. if(pc_issit(sd)) {
  9103. //Bugged client? Just refresh them.
  9104. clif_sitting(&sd->bl);
  9105. return;
  9106. }
  9107. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  9108. break;
  9109. if (sd->sc.count && (
  9110. sd->sc.data[SC_DANCING] ||
  9111. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9112. )) //No sitting during these states either.
  9113. break;
  9114. if (battle_config.idletime_option&IDLE_SIT)
  9115. sd->idletime = last_tick;
  9116. pc_setsit(sd);
  9117. skill_sit(sd, 1);
  9118. clif_sitting(&sd->bl);
  9119. break;
  9120. case 0x03: // standup
  9121. if (!pc_issit(sd)) {
  9122. //Bugged client? Just refresh them.
  9123. clif_standing(&sd->bl);
  9124. return;
  9125. }
  9126. if (pc_setstand(sd, false)) {
  9127. if (battle_config.idletime_option&IDLE_SIT)
  9128. sd->idletime = last_tick;
  9129. skill_sit(sd, 0);
  9130. clif_standing(&sd->bl);
  9131. }
  9132. break;
  9133. }
  9134. }
  9135. /// Request for an action.
  9136. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9137. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9138. /// action:
  9139. /// 0 = attack
  9140. /// 1 = pick up item
  9141. /// 2 = sit down
  9142. /// 3 = stand up
  9143. /// 7 = continous attack
  9144. /// 12 = (touch skill?)
  9145. /// There are various variants of this packet, some of them have padding between fields.
  9146. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9147. {
  9148. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9149. clif_parse_ActionRequest_sub(sd,
  9150. RFIFOB(fd,info->pos[1]),
  9151. RFIFOL(fd,info->pos[0]),
  9152. gettick()
  9153. );
  9154. }
  9155. /// Response to the death/system menu (CZ_RESTART).
  9156. /// 00b2 <type>.B
  9157. /// type:
  9158. /// 0 = restart (respawn)
  9159. /// 1 = char-select (disconnect)
  9160. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9161. {
  9162. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9163. case 0x00:
  9164. pc_respawn(sd,CLR_OUTSIGHT);
  9165. break;
  9166. case 0x01:
  9167. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9168. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9169. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9170. { //Send to char-server for character selection.
  9171. pc_damage_log_clear(sd,0);
  9172. chrif_charselectreq(sd, session[fd]->client_addr);
  9173. } else {
  9174. clif_disconnect_ack(sd, 1);
  9175. }
  9176. break;
  9177. }
  9178. }
  9179. /// Validates and processes whispered messages (CZ_WHISPER).
  9180. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9181. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9182. {
  9183. struct map_session_data* dstsd;
  9184. int i;
  9185. char *target, *message;
  9186. int namelen, messagelen;
  9187. // validate packet and retrieve name and message
  9188. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9189. return;
  9190. if ( is_atcommand(fd, sd, message, 1) )
  9191. return;
  9192. if (sd->sc.cant.chat)
  9193. return; //no "chatting" while muted.
  9194. if (battle_config.min_chat_delay) { //[Skotlex]
  9195. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9196. return;
  9197. }
  9198. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9199. }
  9200. if (battle_config.idletime_option&IDLE_CHAT)
  9201. sd->idletime = last_tick;
  9202. // Chat logging type 'W' / Whisper
  9203. 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);
  9204. //-------------------------------------------------------//
  9205. // Lordalfa - Paperboy - To whisper NPC commands //
  9206. //-------------------------------------------------------//
  9207. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9208. {
  9209. char* str = target+4; //Skip the NPC: string part.
  9210. struct npc_data* npc;
  9211. if ((npc = npc_name2id(str))) {
  9212. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9213. char *split;
  9214. char output[256];
  9215. str = message;
  9216. // skip codepage indicator, if detected
  9217. if( str[0] == '|' && strlen(str) >= 4 )
  9218. str += 3;
  9219. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9220. split = strchr(str,'#');
  9221. if( split == NULL ) { // use the remaining string
  9222. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9223. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9224. split_data[i][0] = '\0';
  9225. break;
  9226. }
  9227. *split = '\0';
  9228. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9229. str = split+1;
  9230. }
  9231. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9232. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9233. set_var(sd,output,(char *) split_data[i]);
  9234. }
  9235. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9236. npc_event(sd,output,0); // Calls the NPC label
  9237. return;
  9238. }
  9239. } else if( target[0] == '#' ) {
  9240. struct Channel *channel = NULL;
  9241. char* chname = target;
  9242. channel = channel_name2channel(chname,sd,3);
  9243. if(channel){
  9244. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9245. channel_send(channel,sd,message);
  9246. }
  9247. else if( channel->pass[0] == '\0') { //no pass needed
  9248. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9249. }
  9250. else {
  9251. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9252. }
  9253. return;
  9254. }
  9255. }
  9256. // searching destination character
  9257. dstsd = map_nick2sd(target);
  9258. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9259. // player is not on this map-server
  9260. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9261. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9262. // and if we ask for 'Test', we must not contact 'test' player
  9263. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9264. intif_wis_message(sd, target, message, messagelen);
  9265. return;
  9266. }
  9267. // if player ignores everyone
  9268. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9269. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9270. clif_wis_end(fd, 1); // 1: target character is not logged in
  9271. else
  9272. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9273. return;
  9274. }
  9275. // if player is autotrading
  9276. if (dstsd->state.autotrade == 1) {
  9277. char output[256];
  9278. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9279. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9280. return;
  9281. }
  9282. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9283. // if player ignores the source character
  9284. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9285. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9286. clif_wis_end(fd, 2); // 2: ignored by target
  9287. return;
  9288. }
  9289. }
  9290. // notify sender of success
  9291. clif_wis_end(fd, 0); // 0: success to send wisper
  9292. // Normal message
  9293. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9294. }
  9295. /// /b /nb (CZ_BROADCAST).
  9296. /// Request to broadcast a message on whole server.
  9297. /// 0099 <packet len>.W <text>.?B 00
  9298. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9299. char command[CHAT_SIZE_MAX+11];
  9300. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9301. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9302. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9303. // as the length varies depending on the command used, just block unreasonably long strings
  9304. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9305. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9306. is_atcommand(fd, sd, command, 1);
  9307. }
  9308. /// Request to pick up an item.
  9309. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9310. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9311. /// There are various variants of this packet, some of them have padding between fields.
  9312. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9313. {
  9314. struct flooritem_data *fitem;
  9315. int map_object_id;
  9316. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9317. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9318. do {
  9319. if (pc_isdead(sd)) {
  9320. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9321. break;
  9322. }
  9323. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9324. break;
  9325. if (pc_cant_act(sd))
  9326. break;
  9327. if (!pc_takeitem(sd, fitem))
  9328. break;
  9329. return;
  9330. } while (0);
  9331. // Client REQUIRES a fail packet or you can no longer pick items.
  9332. clif_additem(sd,0,0,6);
  9333. }
  9334. /// Request to drop an item.
  9335. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9336. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9337. /// There are various variants of this packet, some of them have padding between fields.
  9338. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9339. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9340. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9341. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9342. for(;;) {
  9343. if (pc_isdead(sd))
  9344. break;
  9345. if (pc_cant_act2(sd) || sd->npc_id)
  9346. break;
  9347. if (sd->sc.count && (
  9348. sd->sc.data[SC_AUTOCOUNTER] ||
  9349. sd->sc.data[SC_BLADESTOP] ||
  9350. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9351. ))
  9352. break;
  9353. if (!pc_dropitem(sd, item_index, item_amount))
  9354. break;
  9355. if (battle_config.idletime_option&IDLE_DROPITEM)
  9356. sd->idletime = last_tick;
  9357. return;
  9358. }
  9359. //Because the client does not like being ignored.
  9360. clif_dropitem(sd, item_index,0);
  9361. }
  9362. /// Request to use an item.
  9363. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9364. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9365. /// There are various variants of this packet, some of them have padding between fields.
  9366. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9367. {
  9368. int n;
  9369. if (pc_isdead(sd)) {
  9370. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9371. return;
  9372. }
  9373. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9374. return;
  9375. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9376. if (battle_config.idletime_option&IDLE_USEITEM)
  9377. sd->idletime = last_tick;
  9378. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9379. if(n <0 || n >= MAX_INVENTORY)
  9380. return;
  9381. if (!pc_useitem(sd,n))
  9382. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9383. }
  9384. /// Request to equip an item
  9385. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9386. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9387. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9388. {
  9389. int index;
  9390. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9391. if(pc_isdead(sd)) {
  9392. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9393. return;
  9394. }
  9395. index = RFIFOW(fd,info->pos[0])-2;
  9396. if (index < 0 || index >= MAX_INVENTORY)
  9397. return; //Out of bounds check.
  9398. if(sd->npc_id && !sd->npc_item_flag) {
  9399. return;
  9400. } else if (sd->state.storage_flag || sd->sc.opt1)
  9401. ; //You can equip/unequip stuff while storage is open/under status changes
  9402. else if (pc_cant_act2(sd))
  9403. return;
  9404. if(!sd->status.inventory[index].identify) {
  9405. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9406. return;
  9407. }
  9408. if(!sd->inventory_data[index])
  9409. return;
  9410. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9411. pet_equipitem(sd,index);
  9412. return;
  9413. }
  9414. if (battle_config.idletime_option&IDLE_USEITEM)
  9415. sd->idletime = last_tick;
  9416. //Client doesn't send the position for ammo.
  9417. if(sd->inventory_data[index]->type == IT_AMMO)
  9418. pc_equipitem(sd,index,EQP_AMMO);
  9419. else {
  9420. int req_pos;
  9421. #if PACKETVER >= 20120925
  9422. req_pos = RFIFOL(fd,info->pos[1]);
  9423. #else
  9424. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9425. #endif
  9426. pc_equipitem(sd,index,req_pos);
  9427. }
  9428. }
  9429. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9430. /// 00ab <index>.W
  9431. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9432. {
  9433. int index;
  9434. if(pc_isdead(sd)) {
  9435. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9436. return;
  9437. }
  9438. if (sd->npc_id && !sd->npc_item_flag) {
  9439. return;
  9440. } else if (sd->state.storage_flag || sd->sc.opt1)
  9441. ; //You can equip/unequip stuff while storage is open/under status changes
  9442. else if (pc_cant_act2(sd))
  9443. return;
  9444. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9445. if (battle_config.idletime_option&IDLE_USEITEM)
  9446. sd->idletime = last_tick;
  9447. pc_unequipitem(sd,index,1);
  9448. }
  9449. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9450. /// 0090 <id>.L <type>.B
  9451. /// type:
  9452. /// 1 = click
  9453. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9454. {
  9455. struct block_list *bl;
  9456. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9457. if(pc_isdead(sd)) {
  9458. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9459. return;
  9460. }
  9461. if (pc_cant_act2(sd) || sd->npc_id)
  9462. return;
  9463. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9464. //type = RFIFOB(fd,info->pos[1]);
  9465. if (!bl) return;
  9466. switch (bl->type) {
  9467. case BL_MOB:
  9468. case BL_PC:
  9469. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9470. break;
  9471. case BL_NPC:
  9472. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9473. npc_click(sd,(TBL_NPC*)bl);
  9474. break;
  9475. }
  9476. }
  9477. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9478. /// 00c5 <id>.L <type>.B
  9479. /// type:
  9480. /// 0 = buy
  9481. /// 1 = sell
  9482. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9483. {
  9484. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9485. if (sd->state.trading)
  9486. return;
  9487. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9488. }
  9489. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9490. /// 00ca <result>.B
  9491. /// result:
  9492. /// 0 = "The deal has successfully completed."
  9493. /// 1 = "You do not have enough zeny."
  9494. /// 2 = "You are over your Weight Limit."
  9495. /// 3 = "Out of the maximum capacity, you have too many items."
  9496. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9497. {
  9498. int fd = sd->fd;
  9499. WFIFOHEAD(fd,packet_len(0xca));
  9500. WFIFOW(fd,0) = 0xca;
  9501. WFIFOB(fd,2) = result;
  9502. WFIFOSET(fd,packet_len(0xca));
  9503. }
  9504. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9505. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9506. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9507. {
  9508. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9509. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9510. int result;
  9511. if( sd->state.trading || !sd->npc_shopid )
  9512. result = 1;
  9513. else
  9514. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9515. sd->npc_shopid = 0; //Clear shop data.
  9516. clif_npc_buy_result(sd, result);
  9517. }
  9518. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9519. /// 00cb <result>.B
  9520. /// result:
  9521. /// 0 = "The deal has successfully completed."
  9522. /// 1 = "The deal has failed."
  9523. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9524. {
  9525. int fd = sd->fd;
  9526. WFIFOHEAD(fd,packet_len(0xcb));
  9527. WFIFOW(fd,0) = 0xcb;
  9528. WFIFOB(fd,2) = result;
  9529. WFIFOSET(fd,packet_len(0xcb));
  9530. }
  9531. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9532. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9533. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9534. {
  9535. int fail=0,n;
  9536. unsigned short *item_list;
  9537. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9538. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9539. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9540. if (sd->state.trading || !sd->npc_shopid)
  9541. fail = 1;
  9542. else
  9543. fail = npc_selllist(sd,n,item_list);
  9544. sd->npc_shopid = 0; //Clear shop data.
  9545. clif_npc_sell_result(sd, fail);
  9546. }
  9547. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9548. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9549. /// type:
  9550. /// 0 = private
  9551. /// 1 = public
  9552. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9553. {
  9554. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9555. int len = RFIFOW(fd,info->pos[0])-15;
  9556. int limit = RFIFOW(fd,info->pos[1]);
  9557. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9558. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9559. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9560. char s_password[CHATROOM_PASS_SIZE];
  9561. char s_title[CHATROOM_TITLE_SIZE];
  9562. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9563. return;
  9564. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9565. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9566. return;
  9567. }
  9568. if( npc_isnear(&sd->bl) ) {
  9569. // uncomment to send msg_txt.
  9570. //char output[150];
  9571. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9572. //clif_displaymessage(sd->fd, output);
  9573. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9574. return;
  9575. }
  9576. if( len <= 0 )
  9577. return; // invalid input
  9578. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9579. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9580. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9581. }
  9582. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9583. /// 00d9 <chat ID>.L <passwd>.8B
  9584. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9585. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9586. int chatid = RFIFOL(fd,info->pos[0]);
  9587. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9588. chat_joinchat(sd,chatid,password);
  9589. }
  9590. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9591. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9592. /// type:
  9593. /// 0 = private
  9594. /// 1 = public
  9595. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9596. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9597. int len = RFIFOW(fd,info->pos[0])-15;
  9598. int limit = RFIFOW(fd,info->pos[1]);
  9599. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9600. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9601. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9602. char s_password[CHATROOM_PASS_SIZE];
  9603. char s_title[CHATROOM_TITLE_SIZE];
  9604. if( len <= 0 )
  9605. return; // invalid input
  9606. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9607. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9608. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9609. }
  9610. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9611. /// 00e0 <role>.L <nick>.24B
  9612. /// role:
  9613. /// 0 = owner
  9614. /// 1 = normal
  9615. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9616. {
  9617. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9618. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9619. }
  9620. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9621. /// 00e2 <name>.24B
  9622. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9623. {
  9624. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9625. }
  9626. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9627. /// 00e3
  9628. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9629. {
  9630. chat_leavechat(sd,0);
  9631. }
  9632. //Handles notifying asker and rejecter of what has just ocurred.
  9633. //Type is used to determine the correct msg_txt to use:
  9634. //0:
  9635. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9636. {
  9637. const char* msg;
  9638. char output[256];
  9639. // Your request has been rejected by autoreject option.
  9640. msg = msg_txt(sd,392);
  9641. clif_disp_onlyself(sd, msg, strlen(msg));
  9642. //Notice that a request was rejected.
  9643. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9644. clif_disp_onlyself(tsd, output, strlen(output));
  9645. }
  9646. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9647. /// 00e4 <account id>.L
  9648. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9649. {
  9650. struct map_session_data *t_sd;
  9651. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9652. if(!sd->chatID && pc_cant_act(sd))
  9653. return; //You can trade while in a chatroom.
  9654. // @noask [LuzZza]
  9655. if(t_sd && t_sd->state.noask) {
  9656. clif_noask_sub(sd, t_sd, 0);
  9657. return;
  9658. }
  9659. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9660. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9661. return;
  9662. }
  9663. trade_traderequest(sd,t_sd);
  9664. }
  9665. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9666. /// 00e6 <result>.B
  9667. /// result:
  9668. /// 3 = accepted
  9669. /// 4 = rejected
  9670. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9671. {
  9672. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9673. }
  9674. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9675. /// 00e8 <index>.W <amount>.L
  9676. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9677. {
  9678. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9679. short index = RFIFOW(fd,info->pos[0]);
  9680. int amount = RFIFOL(fd,info->pos[1]);
  9681. if( index == 0 )
  9682. trade_tradeaddzeny(sd, amount);
  9683. else
  9684. trade_tradeadditem(sd, index, (short)amount);
  9685. }
  9686. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9687. /// 00eb
  9688. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9689. {
  9690. trade_tradeok(sd);
  9691. }
  9692. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9693. /// 00ed
  9694. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9695. {
  9696. trade_tradecancel(sd);
  9697. }
  9698. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9699. /// 00ef
  9700. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9701. {
  9702. trade_tradecommit(sd);
  9703. }
  9704. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9705. /// 0118
  9706. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9707. {
  9708. pc_stop_attack(sd);
  9709. }
  9710. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9711. /// 0126 <index>.W <amount>.L
  9712. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9713. {
  9714. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9715. if (pc_istrading(sd))
  9716. return;
  9717. if (!pc_iscarton(sd))
  9718. return;
  9719. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9720. }
  9721. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9722. /// 0127 <index>.W <amount>.L
  9723. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9724. {
  9725. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9726. if (!pc_iscarton(sd))
  9727. return;
  9728. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9729. }
  9730. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9731. /// 012a
  9732. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9733. {
  9734. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9735. #ifdef NEW_CARTS
  9736. && sd->sc.data[SC_PUSH_CART] )
  9737. pc_setcart(sd,0);
  9738. #else
  9739. )
  9740. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9741. #endif
  9742. else // priority to remove this option before we can clear cart
  9743. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9744. }
  9745. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9746. /// 01af <num>.W
  9747. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9748. {// TODO: State tracking?
  9749. int type;
  9750. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9751. return;
  9752. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9753. #ifdef NEW_CARTS
  9754. if( (type == 9 && sd->status.base_level > 131) ||
  9755. (type == 8 && sd->status.base_level > 121) ||
  9756. (type == 7 && sd->status.base_level > 111) ||
  9757. (type == 6 && sd->status.base_level > 101) ||
  9758. (type == 5 && sd->status.base_level > 90) ||
  9759. (type == 4 && sd->status.base_level > 80) ||
  9760. (type == 3 && sd->status.base_level > 65) ||
  9761. (type == 2 && sd->status.base_level > 40) ||
  9762. (type == 1))
  9763. #else
  9764. if( (type == 5 && sd->status.base_level > 90) ||
  9765. (type == 4 && sd->status.base_level > 80) ||
  9766. (type == 3 && sd->status.base_level > 65) ||
  9767. (type == 2 && sd->status.base_level > 40) ||
  9768. (type == 1))
  9769. #endif
  9770. pc_setcart(sd,type);
  9771. }
  9772. /// Request to increase status (CZ_STATUS_CHANGE).
  9773. /// 00bb <status id>.W <amount>.B
  9774. /// status id:
  9775. /// SP_STR ~ SP_LUK
  9776. /// amount:
  9777. /// Old clients always send 1 for this, even when using /str+ and the like.
  9778. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9779. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9780. {
  9781. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9782. if( increase_amount < 0 ) {
  9783. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9784. fd, increase_amount);
  9785. }
  9786. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9787. }
  9788. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9789. /// 0112 <skill id>.W
  9790. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9791. {
  9792. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9793. }
  9794. 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)
  9795. {
  9796. int lv;
  9797. if( !hd )
  9798. return;
  9799. if( skill_isNotOk_hom(skill_id, hd) ) {
  9800. clif_emotion(&hd->bl, E_DOTS);
  9801. return;
  9802. }
  9803. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9804. target_id = hd->bl.id;
  9805. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9806. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9807. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9808. clif_emotion(&hd->bl, E_DOTS);
  9809. if (hd->master)
  9810. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9811. return;
  9812. }
  9813. lv = hom_checkskill(hd, skill_id);
  9814. if( skill_lv > lv )
  9815. skill_lv = lv;
  9816. if( skill_lv )
  9817. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9818. }
  9819. 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)
  9820. {
  9821. int lv;
  9822. if( !hd )
  9823. return;
  9824. if( skill_isNotOk_hom(skill_id, hd) ) {
  9825. clif_emotion(&hd->bl, E_DOTS);
  9826. return;
  9827. }
  9828. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9829. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9830. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9831. clif_emotion(&hd->bl, E_DOTS);
  9832. if (hd->master)
  9833. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9834. return;
  9835. }
  9836. if( hd->sc.data[SC_BASILICA] )
  9837. return;
  9838. lv = hom_checkskill(hd, skill_id);
  9839. if( skill_lv > lv )
  9840. skill_lv = lv;
  9841. if( skill_lv )
  9842. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9843. }
  9844. 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)
  9845. {
  9846. int lv;
  9847. if( !md )
  9848. return;
  9849. if( skill_isNotOk_mercenary(skill_id, md) )
  9850. return;
  9851. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9852. target_id = md->bl.id;
  9853. if( md->ud.skilltimer != INVALID_TIMER )
  9854. {
  9855. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9856. }
  9857. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9858. return;
  9859. lv = mercenary_checkskill(md, skill_id);
  9860. if( skill_lv > lv )
  9861. skill_lv = lv;
  9862. if( skill_lv )
  9863. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9864. }
  9865. 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)
  9866. {
  9867. int lv;
  9868. if( !md )
  9869. return;
  9870. if( skill_isNotOk_mercenary(skill_id, md) )
  9871. return;
  9872. if( md->ud.skilltimer != INVALID_TIMER )
  9873. return;
  9874. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9875. {
  9876. if (md->master)
  9877. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9878. return;
  9879. }
  9880. if( md->sc.data[SC_BASILICA] )
  9881. return;
  9882. lv = mercenary_checkskill(md, skill_id);
  9883. if( skill_lv > lv )
  9884. skill_lv = lv;
  9885. if( skill_lv )
  9886. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9887. }
  9888. /// Request to use a targeted skill.
  9889. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9890. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9891. /// There are various variants of this packet, some of them have padding between fields.
  9892. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9893. {
  9894. uint16 skill_id, skill_lv;
  9895. int tmp, target_id;
  9896. unsigned int tick = gettick();
  9897. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9898. skill_lv = RFIFOW(fd,info->pos[0]);
  9899. skill_id = RFIFOW(fd,info->pos[1]);
  9900. target_id = RFIFOL(fd,info->pos[2]);
  9901. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9902. tmp = skill_get_inf(skill_id);
  9903. if (tmp&INF_GROUND_SKILL || !tmp)
  9904. return; //Using a ground/passive skill on a target? WRONG.
  9905. if( SKILL_CHK_HOMUN(skill_id) ) {
  9906. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9907. return;
  9908. }
  9909. if( SKILL_CHK_MERC(skill_id) ) {
  9910. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9911. return;
  9912. }
  9913. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9914. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  9915. sd->idletime = last_tick;
  9916. if( sd->npc_id ){
  9917. #ifdef RENEWAL
  9918. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9919. return;
  9920. #else
  9921. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9922. return;
  9923. #endif
  9924. }
  9925. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9926. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9927. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9928. return;
  9929. if( pc_issit(sd) )
  9930. return;
  9931. if( skill_isNotOk(skill_id, sd) )
  9932. return;
  9933. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9934. target_id = sd->bl.id; // never trust the client
  9935. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9936. target_id = sd->bl.id;
  9937. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9938. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9939. return;
  9940. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9941. if( sd->skillitem != skill_id ) {
  9942. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9943. return;
  9944. }
  9945. }
  9946. if( sd->sc.option&OPTION_COSTUME )
  9947. return;
  9948. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9949. return; // On basilica only caster can use Basilica again to stop it.
  9950. if( sd->menuskill_id ) {
  9951. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9952. clif_menuskill_clear(sd); //Cancel pet capture.
  9953. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9954. return; //Can't use skills while a menu is open.
  9955. }
  9956. if( sd->skillitem == skill_id ) {
  9957. if( skill_lv != sd->skillitemlv )
  9958. skill_lv = sd->skillitemlv;
  9959. if( !(tmp&INF_SELF_SKILL) )
  9960. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9961. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9962. return;
  9963. }
  9964. sd->skillitem = sd->skillitemlv = 0;
  9965. if( SKILL_CHK_GUILD(skill_id) ) {
  9966. if( sd->state.gmaster_flag )
  9967. skill_lv = guild_checkskill(sd->guild, skill_id);
  9968. else
  9969. skill_lv = 0;
  9970. } else {
  9971. tmp = pc_checkskill(sd, skill_id);
  9972. if( skill_lv > tmp )
  9973. skill_lv = tmp;
  9974. }
  9975. pc_delinvincibletimer(sd);
  9976. if( skill_lv )
  9977. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9978. }
  9979. /*==========================================
  9980. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9981. *------------------------------------------*/
  9982. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9983. {
  9984. unsigned int tick = gettick();
  9985. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9986. return; //Using a target skill on the ground? WRONG.
  9987. if( SKILL_CHK_HOMUN(skill_id) ) {
  9988. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9989. return;
  9990. }
  9991. if( SKILL_CHK_MERC(skill_id) ) {
  9992. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9993. return;
  9994. }
  9995. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9996. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  9997. sd->idletime = last_tick;
  9998. if( skill_isNotOk(skill_id, sd) )
  9999. return;
  10000. if( skillmoreinfo != -1 ) {
  10001. if( pc_issit(sd) ) {
  10002. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10003. return;
  10004. }
  10005. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10006. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10007. }
  10008. if( sd->ud.skilltimer != INVALID_TIMER )
  10009. return;
  10010. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10011. if( sd->skillitem != skill_id ) {
  10012. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10013. return;
  10014. }
  10015. }
  10016. if( sd->sc.option&OPTION_COSTUME )
  10017. return;
  10018. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10019. return; // On basilica only caster can use Basilica again to stop it.
  10020. if( sd->menuskill_id ) {
  10021. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10022. clif_menuskill_clear(sd); //Cancel pet capture.
  10023. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10024. return; //Can't use skills while a menu is open.
  10025. }
  10026. pc_delinvincibletimer(sd);
  10027. if( sd->skillitem == skill_id ) {
  10028. if( skill_lv != sd->skillitemlv )
  10029. skill_lv = sd->skillitemlv;
  10030. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10031. } else {
  10032. int lv;
  10033. sd->skillitem = sd->skillitemlv = 0;
  10034. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10035. if( skill_lv > lv )
  10036. skill_lv = lv;
  10037. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10038. }
  10039. }
  10040. }
  10041. /// Request to use a ground skill.
  10042. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10043. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10044. /// There are various variants of this packet, some of them have padding between fields.
  10045. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10046. {
  10047. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10048. if (pc_cant_act(sd))
  10049. return;
  10050. if (pc_issit(sd))
  10051. return;
  10052. clif_parse_UseSkillToPosSub(fd, sd,
  10053. RFIFOW(fd,info->pos[0]), //skill lv
  10054. RFIFOW(fd,info->pos[1]), //skill num
  10055. RFIFOW(fd,info->pos[2]), //pos x
  10056. RFIFOW(fd,info->pos[3]), //pos y
  10057. -1 //Skill more info.
  10058. );
  10059. }
  10060. /// Request to use a ground skill with text.
  10061. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10062. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10063. /// There are various variants of this packet, some of them have padding between fields.
  10064. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10065. {
  10066. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10067. if (pc_cant_act(sd))
  10068. return;
  10069. if (pc_issit(sd))
  10070. return;
  10071. clif_parse_UseSkillToPosSub(fd, sd,
  10072. RFIFOW(fd,info->pos[0]), //Skill lv
  10073. RFIFOW(fd,info->pos[1]), //Skill num
  10074. RFIFOW(fd,info->pos[2]), //pos x
  10075. RFIFOW(fd,info->pos[3]), //pos y
  10076. info->pos[4] //skill more info
  10077. );
  10078. }
  10079. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10080. /// 011b <skill id>.W <map name>.16B
  10081. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10082. {
  10083. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10084. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10085. char map_name[MAP_NAME_LENGTH];
  10086. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10087. if(skill_id != sd->menuskill_id)
  10088. return;
  10089. //It is possible to use teleport with the storage window open bugreport:8027
  10090. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10091. clif_menuskill_clear(sd);
  10092. return;
  10093. }
  10094. pc_delinvincibletimer(sd);
  10095. skill_castend_map(sd,skill_id,map_name);
  10096. }
  10097. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10098. /// 011d
  10099. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10100. {
  10101. if (!pc_isdead(sd))
  10102. pc_memo(sd,-1);
  10103. }
  10104. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10105. /// 018e <name id>.W { <material id>.W }*3
  10106. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10107. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10108. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10109. int slot1 = RFIFOW(fd,info->pos[1]);
  10110. int slot2 = RFIFOW(fd,info->pos[2]);
  10111. int slot3 = RFIFOW(fd,info->pos[3]);
  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( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  10128. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 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. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10146. return;
  10147. if (pc_istrading(sd)) {
  10148. //Make it fail to avoid shop exploits where you sell something different than you see.
  10149. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10150. clif_menuskill_clear(sd);
  10151. return;
  10152. }
  10153. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  10154. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  10155. clif_menuskill_clear(sd);
  10156. }
  10157. /// Answer to repair weapon item selection dialog
  10158. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10159. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10160. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10161. {
  10162. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10163. return;
  10164. if (pc_istrading(sd)) {
  10165. //Make it fail to avoid shop exploits where you sell something different than you see.
  10166. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10167. clif_menuskill_clear(sd);
  10168. return;
  10169. }
  10170. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10171. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10172. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10173. //for(i = 0; i<MAX_SLOTS; i++)
  10174. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10175. clif_menuskill_clear(sd);
  10176. }
  10177. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10178. /// 0222 <index>.L
  10179. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10180. {
  10181. int idx;
  10182. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10183. return;
  10184. if (pc_istrading(sd)) {
  10185. //Make it fail to avoid shop exploits where you sell something different than you see.
  10186. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10187. clif_menuskill_clear(sd);
  10188. return;
  10189. }
  10190. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10191. skill_weaponrefine(sd, idx-2);
  10192. clif_menuskill_clear(sd);
  10193. }
  10194. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10195. /// 00b8 <npc id>.L <choice>.B
  10196. /// choice:
  10197. /// 1~254 = menu item
  10198. /// 255 = cancel
  10199. /// NOTE: If there were more than 254 items in the list, choice
  10200. /// overflows to choice%256.
  10201. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10202. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10203. int npc_id = RFIFOL(fd,info->pos[0]);
  10204. uint8 select = RFIFOB(fd,info->pos[1]);
  10205. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10206. #ifdef SECURE_NPCTIMEOUT
  10207. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10208. #endif
  10209. TBL_NPC* nd = map_id2nd(npc_id);
  10210. 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);
  10211. clif_GM_kick(NULL,sd);
  10212. #ifdef SECURE_NPCTIMEOUT
  10213. }
  10214. #endif
  10215. return;
  10216. }
  10217. sd->npc_menu = select;
  10218. npc_scriptcont(sd,npc_id, false);
  10219. }
  10220. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10221. /// 00b9 <npc id>.L
  10222. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10223. {
  10224. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10225. }
  10226. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10227. /// 0143 <npc id>.L <value>.L
  10228. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10229. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10230. int npcid = RFIFOL(fd,info->pos[0]);
  10231. int amount = (int)RFIFOL(fd,info->pos[1]);
  10232. sd->npc_amount = amount;
  10233. npc_scriptcont(sd, npcid, false);
  10234. }
  10235. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10236. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10237. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10238. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10239. int message_len = RFIFOW(fd,info->pos[0])-8;
  10240. int npcid = RFIFOL(fd,info->pos[1]);
  10241. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10242. if( message_len <= 0 )
  10243. return; // invalid input
  10244. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10245. npc_scriptcont(sd, npcid, false);
  10246. }
  10247. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10248. /// 0146 <npc id>.L
  10249. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10250. {
  10251. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10252. return;
  10253. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10254. }
  10255. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10256. /// 0178 <index>.W
  10257. /// index:
  10258. /// -1 = cancel
  10259. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10260. {
  10261. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10262. if (sd->menuskill_id != MC_IDENTIFY)
  10263. return;
  10264. if( idx == -1 ) {// cancel pressed
  10265. clif_menuskill_clear(sd);
  10266. return;
  10267. }
  10268. skill_identify(sd,idx-2);
  10269. clif_menuskill_clear(sd);
  10270. }
  10271. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10272. /// 01ae <name id>.W
  10273. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10274. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10275. if (pc_istrading(sd)) {
  10276. //Make it fail to avoid shop exploits where you sell something different than you see.
  10277. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10278. clif_menuskill_clear(sd);
  10279. return;
  10280. }
  10281. switch (sd->menuskill_id) {
  10282. case AC_MAKINGARROW:
  10283. skill_arrow_create(sd,nameid);
  10284. break;
  10285. case SA_CREATECON:
  10286. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  10287. break;
  10288. case WL_READING_SB:
  10289. skill_spellbook(sd,nameid);
  10290. break;
  10291. case GC_POISONINGWEAPON:
  10292. skill_poisoningweapon(sd,nameid);
  10293. break;
  10294. case NC_MAGICDECOY:
  10295. skill_magicdecoy(sd,nameid);
  10296. break;
  10297. }
  10298. clif_menuskill_clear(sd);
  10299. }
  10300. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10301. /// 01ce <skill id>.L
  10302. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10303. {
  10304. if (sd->menuskill_id != SA_AUTOSPELL)
  10305. return;
  10306. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10307. clif_menuskill_clear(sd);
  10308. }
  10309. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10310. /// 017a <card index>.W
  10311. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10312. {
  10313. if (sd->state.trading != 0)
  10314. return;
  10315. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10316. }
  10317. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10318. /// 017c <card index>.W <equip index>.W
  10319. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10320. {
  10321. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10322. if (sd->state.trading != 0)
  10323. return;
  10324. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10325. }
  10326. /// Request of character's name by char ID.
  10327. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10328. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10329. /// There are various variants of this packet, some of them have padding between fields.
  10330. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10331. {
  10332. int charid;
  10333. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10334. map_reqnickdb(sd, charid);
  10335. }
  10336. /// /resetskill /resetstate (CZ_RESET).
  10337. /// Request to reset stats or skills.
  10338. /// 0197 <type>.W
  10339. /// type:
  10340. /// 0 = state
  10341. /// 1 = skill
  10342. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10343. char cmd[15];
  10344. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10345. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10346. else
  10347. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10348. is_atcommand(fd, sd, cmd, 1);
  10349. }
  10350. /// /lb /nlb (CZ_LOCALBROADCAST).
  10351. /// Request to broadcast a message on current map.
  10352. /// 019c <packet len>.W <text>.?B
  10353. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10354. {
  10355. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10356. char command[CHAT_SIZE_MAX+16];
  10357. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10358. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10359. // as the length varies depending on the command used, just block unreasonably long strings
  10360. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10361. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10362. is_atcommand(fd, sd, command, 1);
  10363. }
  10364. /// Request to move an item from inventory to storage.
  10365. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10366. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10367. /// There are various variants of this packet, some of them have padding between fields.
  10368. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10369. {
  10370. int item_index, item_amount;
  10371. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10372. if (pc_istrading(sd))
  10373. return;
  10374. item_index = RFIFOW(fd,info->pos[0])-2;
  10375. item_amount = RFIFOL(fd,info->pos[1]);
  10376. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10377. return;
  10378. if (sd->state.storage_flag == 1)
  10379. storage_storageadd(sd, item_index, item_amount);
  10380. else
  10381. if (sd->state.storage_flag == 2)
  10382. gstorage_storageadd(sd, item_index, item_amount);
  10383. }
  10384. /// Request to move an item from storage to inventory.
  10385. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10386. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10387. /// There are various variants of this packet, some of them have padding between fields.
  10388. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10389. {
  10390. int item_index, item_amount;
  10391. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10392. item_index = RFIFOW(fd,info->pos[0])-1;
  10393. item_amount = RFIFOL(fd,info->pos[1]);
  10394. if (sd->state.storage_flag == 1)
  10395. storage_storageget(sd, item_index, item_amount);
  10396. else if(sd->state.storage_flag == 2)
  10397. gstorage_storageget(sd, item_index, item_amount);
  10398. }
  10399. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10400. /// 0129 <index>.W <amount>.L
  10401. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10402. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10403. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10404. int amount = RFIFOL(fd,info->pos[1]);
  10405. if( sd->state.vending )
  10406. return;
  10407. if (!pc_iscarton(sd))
  10408. return;
  10409. if (sd->state.storage_flag == 1)
  10410. storage_storageaddfromcart(sd, idx, amount);
  10411. else if (sd->state.storage_flag == 2)
  10412. gstorage_storageaddfromcart(sd, idx, amount);
  10413. }
  10414. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10415. /// 0128 <index>.W <amount>.L
  10416. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10417. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10418. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10419. int amount = RFIFOL(fd,info->pos[1]);
  10420. if( sd->state.vending )
  10421. return;
  10422. if (!pc_iscarton(sd))
  10423. return;
  10424. if (sd->state.storage_flag == 1)
  10425. storage_storagegettocart(sd, idx, amount);
  10426. else
  10427. if (sd->state.storage_flag == 2)
  10428. gstorage_storagegettocart(sd, idx, amount);
  10429. }
  10430. /// Request to close storage (CZ_CLOSE_STORE).
  10431. /// 00f7
  10432. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10433. {
  10434. if( sd->state.storage_flag == 1 )
  10435. storage_storageclose(sd);
  10436. else
  10437. if( sd->state.storage_flag == 2 )
  10438. gstorage_storageclose(sd);
  10439. }
  10440. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10441. /// 023a <info>.W
  10442. /// info:
  10443. /// 0 = password has not been set yet
  10444. /// 1 = storage is password-protected
  10445. /// 8 = too many wrong passwords
  10446. /// ? = ignored
  10447. /// NOTE: This packet is only available on certain non-kRO clients.
  10448. void clif_storagepassword(struct map_session_data* sd, short info)
  10449. {
  10450. int fd = sd->fd;
  10451. WFIFOHEAD(fd,packet_len(0x23a));
  10452. WFIFOW(fd,0) = 0x23a;
  10453. WFIFOW(fd,2) = info;
  10454. WFIFOSET(fd,packet_len(0x23a));
  10455. }
  10456. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10457. /// 023b <type>.W <password>.16B <new password>.16B
  10458. /// type:
  10459. /// 2 = change password
  10460. /// 3 = check password
  10461. /// NOTE: This packet is only available on certain non-kRO clients.
  10462. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10463. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10464. // int type = RFIFOW(fd,info->pos[0]);
  10465. // char* password = RFIFOP(fd,info->pos[1]);
  10466. // char* new_password = RFIFOP(fd,info->pos[2]);
  10467. // storage_changepass(sd,password,new_password);
  10468. }
  10469. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10470. /// 023c <result>.W <error count>.W
  10471. /// result:
  10472. /// 4 = password change success
  10473. /// 5 = password change failure
  10474. /// 6 = password check success
  10475. /// 7 = password check failure
  10476. /// 8 = too many wrong passwords
  10477. /// ? = ignored
  10478. /// NOTE: This packet is only available on certain non-kRO clients.
  10479. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10480. {
  10481. int fd = sd->fd;
  10482. WFIFOHEAD(fd,packet_len(0x23c));
  10483. WFIFOW(fd,0) = 0x23c;
  10484. WFIFOW(fd,2) = result;
  10485. WFIFOW(fd,4) = error_count;
  10486. WFIFOSET(fd,packet_len(0x23c));
  10487. }
  10488. /// Party creation request
  10489. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10490. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10491. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10492. name[NAME_LENGTH-1] = '\0';
  10493. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10494. clif_displaymessage(fd, msg_txt(sd,227));
  10495. return;
  10496. }
  10497. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10498. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10499. return;
  10500. }
  10501. party_create(sd,name,0,0);
  10502. }
  10503. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10504. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10505. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10506. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10507. int item1 = RFIFOB(fd,info->pos[1]);
  10508. int item2 = RFIFOB(fd,info->pos[2]);
  10509. name[NAME_LENGTH-1] = '\0';
  10510. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10511. clif_displaymessage(fd, msg_txt(sd,227));
  10512. return;
  10513. }
  10514. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10515. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10516. return;
  10517. }
  10518. party_create(sd,name,item1,item2);
  10519. }
  10520. /// Party invitation request
  10521. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10522. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10523. {
  10524. struct map_session_data *t_sd;
  10525. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10526. clif_displaymessage(fd, msg_txt(sd,227));
  10527. return;
  10528. }
  10529. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10530. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10531. clif_noask_sub(sd, t_sd, 1);
  10532. return;
  10533. }
  10534. party_invite(sd, t_sd);
  10535. }
  10536. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10537. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10538. struct map_session_data *t_sd;
  10539. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10540. name[NAME_LENGTH-1] = '\0';
  10541. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10542. clif_displaymessage(fd, msg_txt(sd,227));
  10543. return;
  10544. }
  10545. t_sd = map_nick2sd(name);
  10546. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10547. clif_noask_sub(sd, t_sd, 1);
  10548. return;
  10549. }
  10550. party_invite(sd, t_sd);
  10551. }
  10552. /// Party invitation reply
  10553. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10554. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10555. /// flag:
  10556. /// 0 = reject
  10557. /// 1 = accept
  10558. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10559. {
  10560. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10561. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10562. RFIFOL(fd,info->pos[1]));
  10563. }
  10564. //(CZ_PARTY_JOIN_REQ_ACK)
  10565. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10566. {
  10567. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10568. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10569. RFIFOB(fd,info->pos[1]));
  10570. }
  10571. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10572. /// 0100
  10573. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10574. {
  10575. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10576. clif_displaymessage(fd, msg_txt(sd,227));
  10577. return;
  10578. }
  10579. party_leave(sd);
  10580. }
  10581. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10582. /// 0103 <account id>.L <char name>.24B
  10583. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10584. {
  10585. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10586. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10587. clif_displaymessage(fd, msg_txt(sd,227));
  10588. return;
  10589. }
  10590. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10591. (char*)RFIFOP(fd,info->pos[1]));
  10592. }
  10593. /// Request to change party options.
  10594. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10595. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10596. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10597. {
  10598. struct party_data *p;
  10599. int i,expflag;
  10600. int cmd = RFIFOW(fd,0);
  10601. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10602. if( !sd->status.party_id )
  10603. return;
  10604. p = party_search(sd->status.party_id);
  10605. if( p == NULL )
  10606. return;
  10607. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10608. if( i == MAX_PARTY )
  10609. return; //Shouldn't happen
  10610. if( !p->party.member[i].leader )
  10611. return;
  10612. expflag = RFIFOL(fd,info->pos[0]);
  10613. if(cmd == 0x0102){ //Client can't change the item-field
  10614. party_changeoption(sd, expflag, p->party.item);
  10615. }
  10616. else {
  10617. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10618. party_changeoption(sd, expflag, itemflag);
  10619. }
  10620. }
  10621. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10622. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10623. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10624. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10625. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10626. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10627. char *name, *message;
  10628. int namelen, messagelen;
  10629. // validate packet and retrieve name and message
  10630. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10631. return;
  10632. if( is_atcommand(fd, sd, message, 1) )
  10633. return;
  10634. if (sd->sc.cant.chat)
  10635. return; //no "chatting" while muted.
  10636. if( battle_config.min_chat_delay )
  10637. { //[Skotlex]
  10638. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10639. return;
  10640. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10641. }
  10642. if (battle_config.idletime_option&IDLE_CHAT)
  10643. sd->idletime = last_tick;
  10644. party_send_message(sd, text, textlen);
  10645. }
  10646. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10647. /// 07da <account id>.L
  10648. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10649. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10650. }
  10651. /// Party Booking in KRO [Spiria]
  10652. ///
  10653. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10654. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10655. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10656. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10657. short level = RFIFOW(fd,info->pos[0]);
  10658. short mapid = RFIFOW(fd,info->pos[1]);
  10659. int idxpbj = info->pos[2];
  10660. short job[PARTY_BOOKING_JOBS];
  10661. int i;
  10662. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10663. job[i] = RFIFOB(fd,idxpbj+i*2);
  10664. party_booking_register(sd, level, mapid, job);
  10665. }
  10666. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10667. /// 0803 <result>.W
  10668. /// result:
  10669. /// 0 = success
  10670. /// 1 = failure
  10671. /// 2 = already registered
  10672. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10673. {
  10674. int fd = sd->fd;
  10675. WFIFOHEAD(fd,packet_len(0x803));
  10676. WFIFOW(fd,0) = 0x803;
  10677. WFIFOW(fd,2) = flag;
  10678. WFIFOSET(fd,packet_len(0x803));
  10679. }
  10680. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10681. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10682. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10683. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10684. short level = RFIFOW(fd,info->pos[0]);
  10685. short mapid = RFIFOW(fd,info->pos[1]);
  10686. short job = RFIFOW(fd,info->pos[2]);
  10687. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10688. short resultcount = RFIFOW(fd,info->pos[4]);
  10689. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10690. }
  10691. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10692. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10693. /// more results:
  10694. /// 0 = no
  10695. /// 1 = yes
  10696. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10697. {
  10698. int i, j;
  10699. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10700. struct party_booking_ad_info *pb_ad;
  10701. WFIFOHEAD(fd,size*count + 5);
  10702. WFIFOW(fd,0) = 0x805;
  10703. WFIFOW(fd,2) = size*count + 5;
  10704. WFIFOB(fd,4) = more_result;
  10705. for(i=0; i<count; i++)
  10706. {
  10707. pb_ad = results[i];
  10708. WFIFOL(fd,i*size+5) = pb_ad->index;
  10709. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10710. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10711. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10712. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10713. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10714. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10715. }
  10716. WFIFOSET(fd,WFIFOW(fd,2));
  10717. }
  10718. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10719. /// 0806
  10720. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10721. {
  10722. if(party_booking_delete(sd))
  10723. clif_PartyBookingDeleteAck(sd, 0);
  10724. }
  10725. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10726. /// 0807 <result>.W
  10727. /// result:
  10728. /// 0 = success
  10729. /// 1 = success (auto-removed expired ad)
  10730. /// 2 = failure
  10731. /// 3 = nothing registered
  10732. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10733. {
  10734. int fd = sd->fd;
  10735. WFIFOHEAD(fd,packet_len(0x807));
  10736. WFIFOW(fd,0) = 0x807;
  10737. WFIFOW(fd,2) = flag;
  10738. WFIFOSET(fd,packet_len(0x807));
  10739. }
  10740. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10741. /// 0808 { <job>.W }*6
  10742. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10743. {
  10744. short job[PARTY_BOOKING_JOBS];
  10745. int i;
  10746. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10747. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10748. job[i] = RFIFOW(fd,idxpbu+i*2);
  10749. party_booking_update(sd, job);
  10750. }
  10751. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10752. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10753. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10754. {
  10755. int i;
  10756. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10757. if(pb_ad == NULL) return;
  10758. WBUFW(buf,0) = 0x809;
  10759. WBUFL(buf,2) = pb_ad->index;
  10760. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10761. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10762. WBUFW(buf,34) = pb_ad->p_detail.level;
  10763. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10764. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10765. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10766. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10767. }
  10768. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10769. /// 080a <index>.L { <job>.W }*6
  10770. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10771. {
  10772. int i;
  10773. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10774. if(pb_ad == NULL) return;
  10775. WBUFW(buf,0) = 0x80a;
  10776. WBUFL(buf,2) = pb_ad->index;
  10777. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10778. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10779. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10780. }
  10781. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10782. /// 080b <index>.L
  10783. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10784. {
  10785. uint8 buf[6];
  10786. WBUFW(buf,0) = 0x80b;
  10787. WBUFL(buf,2) = index;
  10788. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10789. }
  10790. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10791. /// 012e
  10792. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10793. {
  10794. vending_closevending(sd);
  10795. }
  10796. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10797. /// 0130 <account id>.L
  10798. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10799. {
  10800. if( sd->npc_id ) {// using an NPC
  10801. return;
  10802. }
  10803. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10804. }
  10805. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10806. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10807. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10808. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10809. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10810. int id = (int)RFIFOL(fd,info->pos[1]);
  10811. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10812. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10813. // whether it fails or not, the buy window is closed
  10814. sd->vended_id = 0;
  10815. }
  10816. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10817. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10818. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10819. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10820. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10821. int aid = (int)RFIFOL(fd,info->pos[1]);
  10822. int uid = (int)RFIFOL(fd,info->pos[2]);
  10823. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10824. vending_purchasereq(sd, aid, uid, data, len/4);
  10825. // whether it fails or not, the buy window is closed
  10826. sd->vended_id = 0;
  10827. }
  10828. /// Confirm or cancel the shop preparation window.
  10829. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10830. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10831. /// result:
  10832. /// 0 = canceled
  10833. /// 1 = open
  10834. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10835. int cmd = RFIFOW(fd,0);
  10836. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10837. short len = (short)RFIFOW(fd,info->pos[0]);
  10838. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10839. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10840. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10841. len -= 84;
  10842. }
  10843. else { //(CZ_REQ_OPENSTORE2)
  10844. bool flag;
  10845. len -= 85;
  10846. flag = (bool)RFIFOB(fd,info->pos[2]);
  10847. if( !flag )
  10848. sd->state.prevend = 0;
  10849. }
  10850. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10851. return;
  10852. if( map[sd->bl.m].flag.novending ) {
  10853. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10854. return;
  10855. }
  10856. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10857. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10858. return;
  10859. }
  10860. if( message[0] == '\0' ) // invalid input
  10861. return;
  10862. vending_openvending(sd, message, data, len/8, NULL);
  10863. }
  10864. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10865. /// 0165 <char id>.L <guild name>.24B
  10866. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10867. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10868. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10869. name[NAME_LENGTH-1] = '\0';
  10870. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10871. clif_displaymessage(fd, msg_txt(sd,228));
  10872. return;
  10873. }
  10874. guild_create(sd, name);
  10875. }
  10876. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10877. /// 014d
  10878. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10879. {
  10880. clif_guild_masterormember(sd);
  10881. }
  10882. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10883. /// 014f <type>.L
  10884. /// type:
  10885. /// 0 = basic info
  10886. /// 1 = member manager
  10887. /// 2 = positions
  10888. /// 3 = skills
  10889. /// 4 = expulsion list
  10890. /// 5 = unknown (GM_ALLGUILDLIST)
  10891. /// 6 = notice
  10892. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10893. {
  10894. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10895. if( !sd->status.guild_id && !sd->bg_id )
  10896. return;
  10897. switch( type )
  10898. {
  10899. case 0: // Basic Information Guild, hostile alliance information
  10900. clif_guild_basicinfo(sd);
  10901. clif_guild_allianceinfo(sd);
  10902. break;
  10903. case 1: // Members list, list job title
  10904. clif_guild_positionnamelist(sd);
  10905. clif_guild_memberlist(sd);
  10906. break;
  10907. case 2: // List job title, title information list
  10908. clif_guild_positionnamelist(sd);
  10909. clif_guild_positioninfolist(sd);
  10910. break;
  10911. case 3: // Skill list
  10912. clif_guild_skillinfo(sd);
  10913. break;
  10914. case 4: // Expulsion list
  10915. clif_guild_expulsionlist(sd);
  10916. break;
  10917. default:
  10918. ShowError("clif: guild request info: unknown type %d\n", type);
  10919. break;
  10920. }
  10921. }
  10922. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10923. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10924. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10925. {
  10926. int i;
  10927. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10928. int len = RFIFOW(fd,info->pos[0]);
  10929. int idxgpos = info->pos[1];
  10930. if(!sd->state.gmaster_flag)
  10931. return;
  10932. for(i = idxgpos; i < len; i += 40 ){
  10933. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10934. }
  10935. }
  10936. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10937. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10938. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10939. {
  10940. int i;
  10941. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10942. int len = RFIFOW(fd,info->pos[0]);
  10943. int idxgpos = info->pos[1];
  10944. if(!sd->state.gmaster_flag)
  10945. return;
  10946. for(i=idxgpos;i<len;i+=12){
  10947. guild_change_memberposition(sd->status.guild_id,
  10948. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10949. }
  10950. }
  10951. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10952. /// 0151 <guild id>.L
  10953. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10954. {
  10955. struct guild* g;
  10956. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10957. if( (g = guild_search(guild_id)) != NULL )
  10958. clif_guild_emblem(sd,g);
  10959. }
  10960. /// Validates data of a guild emblem (compressed bitmap)
  10961. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10962. {
  10963. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10964. unsigned long buf_len = sizeof(buf);
  10965. int offset = 0;
  10966. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10967. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10968. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10969. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10970. ))
  10971. return -1;
  10972. if(battle_config.emblem_transparency_limit != 100) {
  10973. int i, transcount = 1, tmp[3];
  10974. for(i = offset; i < buf_len-1; i++) {
  10975. int j = i%3;
  10976. tmp[j] = RBUFL(buf,i);
  10977. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10978. transcount++;
  10979. }
  10980. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10981. return -2;
  10982. }
  10983. return 0;
  10984. }
  10985. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10986. /// 0153 <packet len>.W <emblem data>.?B
  10987. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10988. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10989. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10990. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10991. int emb_val=0;
  10992. if( !emblem_len || !sd->state.gmaster_flag )
  10993. return;
  10994. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10995. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10996. return;
  10997. }
  10998. emb_val = clif_validate_emblem(emblem, emblem_len);
  10999. if(emb_val ==-1 ){
  11000. 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);
  11001. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11002. return;
  11003. } else if(emb_val == -2){
  11004. char output[128];
  11005. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11006. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11007. return;
  11008. }
  11009. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11010. }
  11011. /// Guild notice update request (CZ_GUILD_NOTICE).
  11012. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11013. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11014. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11015. int guild_id = RFIFOL(fd,info->pos[0]);
  11016. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11017. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11018. if(!sd->state.gmaster_flag)
  11019. return;
  11020. // compensate for some client defects when using multilanguage mode
  11021. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11022. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11023. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11024. guild_change_notice(sd, guild_id, msg1, msg2);
  11025. }
  11026. // Helper function for guild invite functions
  11027. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11028. {
  11029. if (t_sd == NULL) // not online or does not exist
  11030. return 1;
  11031. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11032. clif_displaymessage(fd, msg_txt(sd,228));
  11033. return 1;
  11034. }
  11035. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11036. clif_noask_sub(sd, t_sd, 2);
  11037. return 1;
  11038. }
  11039. guild_invite(sd, t_sd);
  11040. return 0;
  11041. }
  11042. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11043. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11044. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11045. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11046. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11047. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11048. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11049. if (clif_sub_guild_invite(fd, sd, t_sd))
  11050. return;
  11051. }
  11052. /// Guild invite request (/guildinvite)
  11053. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11054. void
  11055. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11056. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11057. if (clif_sub_guild_invite(fd, sd, t_sd))
  11058. return;
  11059. }
  11060. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11061. /// 016b <guild id>.L <answer>.L
  11062. /// answer:
  11063. /// 0 = refuse
  11064. /// 1 = accept
  11065. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11066. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11067. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11068. RFIFOL(fd,info->pos[1]));
  11069. }
  11070. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11071. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11072. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11073. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11074. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11075. clif_displaymessage(fd, msg_txt(sd,228));
  11076. return;
  11077. }
  11078. if( sd->bg_id ) {
  11079. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11080. return;
  11081. }
  11082. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11083. RFIFOL(fd,info->pos[1]),
  11084. RFIFOL(fd,info->pos[2]),
  11085. (char*)RFIFOP(fd,info->pos[3]));
  11086. }
  11087. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11088. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11089. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11090. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11091. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11092. { // Guild locked.
  11093. clif_displaymessage(fd, msg_txt(sd,228));
  11094. return;
  11095. }
  11096. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11097. RFIFOL(fd,info->pos[1]),
  11098. RFIFOL(fd,info->pos[2]),
  11099. (char*)RFIFOP(fd,info->pos[3]));
  11100. }
  11101. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11102. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11103. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11104. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11105. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  11106. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  11107. char *name, *message;
  11108. int namelen, messagelen;
  11109. // validate packet and retrieve name and message
  11110. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11111. return;
  11112. if( is_atcommand(fd, sd, message, 1) )
  11113. return;
  11114. if (sd->sc.cant.chat)
  11115. return; //no "chatting" while muted.
  11116. if( battle_config.min_chat_delay )
  11117. { //[Skotlex]
  11118. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  11119. return;
  11120. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11121. }
  11122. if (battle_config.idletime_option&IDLE_CHAT)
  11123. sd->idletime = last_tick;
  11124. if( sd->bg_id )
  11125. bg_send_message(sd, text, textlen);
  11126. else
  11127. guild_send_message(sd, text, textlen);
  11128. }
  11129. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11130. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11131. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11132. {
  11133. struct map_session_data *t_sd;
  11134. if(!sd->state.gmaster_flag)
  11135. return;
  11136. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11137. clif_displaymessage(fd, msg_txt(sd,228));
  11138. return;
  11139. }
  11140. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11141. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11142. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11143. // @noask [LuzZza]
  11144. if(t_sd && t_sd->state.noask) {
  11145. clif_noask_sub(sd, t_sd, 3);
  11146. return;
  11147. }
  11148. guild_reqalliance(sd,t_sd);
  11149. }
  11150. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11151. /// 0172 <inviter account id>.L <answer>.L
  11152. /// answer:
  11153. /// 0 = refuse
  11154. /// 1 = accept
  11155. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11156. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11157. guild_reply_reqalliance(sd,
  11158. RFIFOL(fd,info->pos[0]),
  11159. RFIFOL(fd,info->pos[1]));
  11160. }
  11161. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11162. /// 0183 <opponent guild id>.L <relation>.L
  11163. /// relation:
  11164. /// 0 = Ally
  11165. /// 1 = Enemy
  11166. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11167. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11168. if(!sd->state.gmaster_flag)
  11169. return;
  11170. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11171. clif_displaymessage(fd, msg_txt(sd,228));
  11172. return;
  11173. }
  11174. guild_delalliance(sd,
  11175. RFIFOL(fd,info->pos[0]),
  11176. RFIFOL(fd,info->pos[1]));
  11177. }
  11178. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11179. /// 0180 <account id>.L
  11180. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11181. {
  11182. struct map_session_data *t_sd;
  11183. if(!sd->state.gmaster_flag)
  11184. return;
  11185. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11186. clif_displaymessage(fd, msg_txt(sd,228));
  11187. return;
  11188. }
  11189. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11190. // @noask [LuzZza]
  11191. if(t_sd && t_sd->state.noask) {
  11192. clif_noask_sub(sd, t_sd, 4);
  11193. return;
  11194. }
  11195. guild_opposition(sd,t_sd);
  11196. }
  11197. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11198. /// 015d <key>.40B
  11199. /// key:
  11200. /// now guild name; might have been (intended) email, since the
  11201. /// field name and size is same as the one in CH_DELETE_CHAR.
  11202. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11203. {
  11204. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11205. clif_displaymessage(fd, msg_txt(sd,228));
  11206. return;
  11207. }
  11208. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11209. }
  11210. /// Pet
  11211. ///
  11212. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11213. /// 01a1 <type>.B
  11214. /// type:
  11215. /// 0 = pet information
  11216. /// 1 = feed
  11217. /// 2 = performance
  11218. /// 3 = return to egg
  11219. /// 4 = unequip accessory
  11220. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11221. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11222. }
  11223. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11224. /// 019f <id>.L
  11225. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11226. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11227. }
  11228. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11229. /// 01a7 <index>.W
  11230. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11231. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11232. return;
  11233. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11234. clif_menuskill_clear(sd);
  11235. }
  11236. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11237. /// 01a9 <data>.L
  11238. /// data:
  11239. /// is either emotion (@see enum emotion_type) or a compound value
  11240. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11241. /// entry (given in parentheses) in data\pettalktable.xml
  11242. /// act id:
  11243. /// 0 = feeding
  11244. /// 1 = hunting
  11245. /// 2 = danger
  11246. /// 3 = dead
  11247. /// 4 = normal (stand)
  11248. /// 5 = special performance (perfor_s)
  11249. /// 6 = level up (levelup)
  11250. /// 7 = performance 1 (perfor_1)
  11251. /// 8 = performance 2 (perfor_2)
  11252. /// 9 = performance 3 (perfor_3)
  11253. /// 10 = log-in greeting (connect)
  11254. /// hungry value:
  11255. /// 0 = very hungry (hungry)
  11256. /// 1 = hungry (bit_hungry)
  11257. /// 2 = satisfied (noting)
  11258. /// 3 = stuffed (full)
  11259. /// 4 = full (so_full)
  11260. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11261. {
  11262. if(sd->pd)
  11263. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11264. }
  11265. /// Request to change pet's name (CZ_RENAME_PET).
  11266. /// 01a5 <name>.24B
  11267. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11268. {
  11269. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11270. }
  11271. /// /kill (CZ_DISCONNECT_CHARACTER).
  11272. /// Request to disconnect a character.
  11273. /// 00cc <account id>.L
  11274. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11275. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11276. {
  11277. struct block_list *target;
  11278. int tid;
  11279. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11280. target = map_id2bl(tid);
  11281. if (!target) {
  11282. clif_GM_kickack(sd, 0);
  11283. return;
  11284. }
  11285. switch (target->type) {
  11286. case BL_PC:
  11287. {
  11288. char command[NAME_LENGTH+6];
  11289. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11290. is_atcommand(fd, sd, command, 1);
  11291. }
  11292. break;
  11293. /**
  11294. * This one does not invoke any atcommand, so we need to check for permissions.
  11295. */
  11296. case BL_MOB:
  11297. {
  11298. char command[100];
  11299. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11300. clif_GM_kickack(sd, 0);
  11301. return;
  11302. }
  11303. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11304. log_atcommand(sd, command);
  11305. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11306. }
  11307. break;
  11308. case BL_NPC:
  11309. {
  11310. struct npc_data* nd = (struct npc_data *)target;
  11311. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11312. npc_unload_duplicates(nd);
  11313. npc_unload(nd,true);
  11314. npc_read_event_script();
  11315. }
  11316. }
  11317. break;
  11318. default:
  11319. clif_GM_kickack(sd, 0);
  11320. }
  11321. }
  11322. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11323. /// Request to disconnect all characters.
  11324. /// 00ce
  11325. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11326. char cmd[15];
  11327. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11328. is_atcommand(fd, sd, cmd, 1);
  11329. }
  11330. /// /remove (CZ_REMOVE_AID).
  11331. /// Request to warp to a character with given login ID.
  11332. /// 01ba <account name>.24B
  11333. /// /shift (CZ_SHIFT).
  11334. /// Request to warp to a character with given name.
  11335. /// 01bb <char name>.24B
  11336. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11337. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11338. char *player_name;
  11339. char command[NAME_LENGTH+8];
  11340. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11341. player_name[NAME_LENGTH-1] = '\0';
  11342. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11343. is_atcommand(fd, sd, command, 1);
  11344. }
  11345. /// /remove (CZ_REMOVE_AID_SSO).
  11346. /// Request to warp to a character with given account ID.
  11347. /// 0843 <account id>.L
  11348. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11349. {
  11350. uint32 account_id;
  11351. struct map_session_data* pl_sd;
  11352. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11353. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11354. char command[NAME_LENGTH+8];
  11355. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11356. is_atcommand(fd, sd, command, 1);
  11357. }
  11358. }
  11359. /// /recall (CZ_RECALL).
  11360. /// Request to summon a player with given login ID to own position.
  11361. /// 01bc <account name>.24B
  11362. /// /summon (CZ_RECALL_GID).
  11363. /// Request to summon a player with given name to own position.
  11364. /// 01bd <char name>.24B
  11365. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11366. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11367. char *player_name;
  11368. char command [NAME_LENGTH+8];
  11369. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11370. player_name[NAME_LENGTH-1] = '\0';
  11371. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11372. is_atcommand(fd, sd, command, 1);
  11373. }
  11374. /// /recall (CZ_RECALL_SSO).
  11375. /// Request to summon a player with given account ID to own position.
  11376. /// 0842 <account id>.L
  11377. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11378. {
  11379. uint32 account_id;
  11380. struct map_session_data* pl_sd;
  11381. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11382. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11383. char command[NAME_LENGTH+8];
  11384. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11385. is_atcommand(fd, sd, command, 1);
  11386. }
  11387. }
  11388. /// /item /monster (CZ_ITEM_CREATE).
  11389. /// Request to execute GM commands.
  11390. /// Usage:
  11391. /// /item n - summon n monster or acquire n item/s
  11392. /// /item money - grants 2147483647 zenies
  11393. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11394. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11395. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11396. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11397. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11398. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11399. /// 013f <item/mob name>.24B
  11400. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11401. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11402. {
  11403. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11404. int mob_id = 0;
  11405. struct item_data *id = NULL;
  11406. struct mob_db *mob = NULL;
  11407. StringBuf command;
  11408. char *str;
  11409. //#if PACKETVER >= 20131218
  11410. // char str[100];
  11411. //#else
  11412. // char str[24];
  11413. //#endif
  11414. str = (char*)RFIFOP(fd,info->pos[0]);
  11415. if (!str || str[0] == '\0')
  11416. return;
  11417. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11418. return;
  11419. trim(str);
  11420. // Zeny
  11421. if( strcmpi(str, "money") == 0 ) {
  11422. StringBuf_Init(&command);
  11423. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11424. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11425. StringBuf_Destroy(&command);
  11426. return;
  11427. }
  11428. // Item
  11429. if( (id = itemdb_searchname(str)) ) {
  11430. StringBuf_Init(&command);
  11431. if( !itemdb_isstackable2(id) ) //Nonstackable
  11432. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11433. else {
  11434. #ifdef ENABLE_ITEM_GUID
  11435. if (id->flag.guid)
  11436. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11437. else
  11438. #endif
  11439. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11440. }
  11441. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11442. StringBuf_Destroy(&command);
  11443. return;
  11444. }
  11445. // Monster
  11446. if ((mob_id = mobdb_searchname(str)) == 0)
  11447. mob_id = mobdb_checkid(atoi(str));
  11448. if( (mob = mob_db(mob_id)) ) {
  11449. StringBuf_Init(&command);
  11450. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11451. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11452. StringBuf_Destroy(&command);
  11453. return;
  11454. }
  11455. }
  11456. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11457. /// 019d <effect state>.L
  11458. /// effect state:
  11459. /// TODO: Any OPTION_* ?
  11460. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11461. char cmd[6];
  11462. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11463. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11464. is_atcommand(fd, sd, cmd, 1);
  11465. }
  11466. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11467. /// 0149 <account id>.L <type>.B <value>.W
  11468. /// type:
  11469. /// 0 = positive points
  11470. /// 1 = negative points
  11471. /// 2 = self mute (+10 minutes)
  11472. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11473. {
  11474. int id, type, value;
  11475. struct map_session_data *dstsd;
  11476. char command[NAME_LENGTH+15];
  11477. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11478. id = RFIFOL(fd,info->pos[0]);
  11479. type = RFIFOB(fd,info->pos[1]);
  11480. value = RFIFOW(fd,info->pos[2]);
  11481. if( type == 0 )
  11482. value = -value;
  11483. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11484. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11485. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11486. return;
  11487. dstsd = map_id2sd(id);
  11488. if( dstsd == NULL )
  11489. return;
  11490. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11491. is_atcommand(fd, sd, command, 1);
  11492. }
  11493. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11494. /// GM adjustment of a player's manner value by -60.
  11495. /// 0212 <char name>.24B
  11496. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11497. {
  11498. char command[NAME_LENGTH+15];
  11499. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11500. name[NAME_LENGTH-1] = '\0';
  11501. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11502. is_atcommand(fd, sd, command, 1);
  11503. }
  11504. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11505. /// 01e0 <account id>.L <account name>.24B
  11506. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11507. {
  11508. WFIFOHEAD(fd,packet_len(0x1e0));
  11509. WFIFOW(fd,0) = 0x1e0;
  11510. WFIFOL(fd,2) = account_id;
  11511. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11512. WFIFOSET(fd,packet_len(0x1e0));
  11513. }
  11514. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11515. /// 01df <account id>.L
  11516. //! TODO: Figure out how does this actually work
  11517. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11518. {
  11519. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11520. /*
  11521. char query[30];
  11522. safesnprintf(query,sizeof(query),"%d", account_id);
  11523. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11524. */
  11525. clif_account_name(fd, account_id, "");
  11526. }
  11527. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11528. /// GM single cell type change request.
  11529. /// 0198 <x>.W <y>.W <type>.W
  11530. /// type:
  11531. /// 0 = not walkable
  11532. /// 1 = walkable
  11533. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11534. {
  11535. int x,y,type;
  11536. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11537. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11538. return;
  11539. x = RFIFOW(fd,info->pos[0]);
  11540. y = RFIFOW(fd,info->pos[1]);
  11541. type = RFIFOW(fd,info->pos[2]);
  11542. map_setgatcell(sd->bl.m,x,y,type);
  11543. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11544. //FIXME: once players leave the map, the client 'forgets' this information.
  11545. }
  11546. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11547. /// Request to allow/deny whispers from a nick.
  11548. /// 00cf <nick>.24B <type>.B
  11549. /// type:
  11550. /// 0 = (/ex nick) deny speech from nick
  11551. /// 1 = (/in nick) allow speech from nick
  11552. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11553. {
  11554. char* nick;
  11555. uint8 type;
  11556. int i;
  11557. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11558. nick = (char*)RFIFOP(fd,info->pos[0]);
  11559. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11560. type = RFIFOB(fd,info->pos[1]);
  11561. if( type == 0 ) { // Add name to ignore list (block)
  11562. if (strcmp(wisp_server_name, nick) == 0) {
  11563. clif_wisexin(sd, type, 1); // fail
  11564. return;
  11565. }
  11566. // try to find a free spot, while checking for duplicates at the same time
  11567. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11568. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11569. clif_wisexin(sd, type, 2); // too many blocks
  11570. return;
  11571. }
  11572. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11573. clif_wisexin(sd, type, 0); // Aegis reports success.
  11574. return;
  11575. }
  11576. //Insert in position i
  11577. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11578. } else { // Remove name from ignore list (unblock)
  11579. // find entry
  11580. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11581. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11582. clif_wisexin(sd, type, 1); // fail
  11583. return;
  11584. }
  11585. // move everything one place down to overwrite removed entry
  11586. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11587. // wipe last entry
  11588. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11589. }
  11590. clif_wisexin(sd, type, 0); // success
  11591. }
  11592. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11593. /// Request to allow/deny all whispers.
  11594. /// 00d0 <type>.B
  11595. /// type:
  11596. /// 0 = (/exall) deny all speech
  11597. /// 1 = (/inall) allow all speech
  11598. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11599. {
  11600. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11601. if( type == 0 ) {// Deny all
  11602. if( sd->state.ignoreAll ) {
  11603. flag = 1; // fail
  11604. } else {
  11605. sd->state.ignoreAll = 1;
  11606. flag = 0; // success
  11607. }
  11608. } else {//Unblock everyone
  11609. if( sd->state.ignoreAll ) {
  11610. sd->state.ignoreAll = 0;
  11611. flag = 0; // success
  11612. } else {
  11613. if (sd->ignore[0].name[0] != '\0')
  11614. { //Wipe the ignore list.
  11615. memset(sd->ignore, 0, sizeof(sd->ignore));
  11616. flag = 0; // success
  11617. } else {
  11618. flag = 1; // fail
  11619. }
  11620. }
  11621. }
  11622. clif_wisall(sd, type, flag);
  11623. }
  11624. /// Whisper ignore list (ZC_WHISPER_LIST).
  11625. /// 00d4 <packet len>.W { <char name>.24B }*
  11626. void clif_PMIgnoreList(struct map_session_data* sd)
  11627. {
  11628. int i, fd = sd->fd;
  11629. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11630. WFIFOW(fd,0) = 0xd4;
  11631. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11632. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11633. }
  11634. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11635. WFIFOSET(fd,WFIFOW(fd,2));
  11636. }
  11637. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11638. /// 00d3
  11639. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11640. {
  11641. clif_PMIgnoreList(sd);
  11642. }
  11643. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11644. /// 01e7
  11645. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11646. {
  11647. if (sd->state.doridori) return;
  11648. switch (sd->class_&MAPID_UPPERMASK) {
  11649. case MAPID_SOUL_LINKER:
  11650. case MAPID_STAR_GLADIATOR:
  11651. case MAPID_TAEKWON:
  11652. if (!sd->state.rest)
  11653. break;
  11654. case MAPID_SUPER_NOVICE:
  11655. case MAPID_SUPER_BABY:
  11656. case MAPID_SUPER_NOVICE_E:
  11657. case MAPID_SUPER_BABY_E:
  11658. sd->state.doridori=1;
  11659. break;
  11660. }
  11661. }
  11662. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11663. /// 01ed
  11664. /// Note: This packet is caused by 7 lines of any text, followed by
  11665. /// the prayer and an another line of any text. The prayer is
  11666. /// defined by lines 790~793 in data\msgstringtable.txt
  11667. /// "Dear angel, can you hear my voice?"
  11668. /// "I am" (space separated player name) "Super Novice~"
  11669. /// "Help me out~ Please~ T_T"
  11670. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11671. {
  11672. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11673. unsigned int next = pc_nextbaseexp(sd);
  11674. if( next == 0 ) next = pc_thisbaseexp(sd);
  11675. if( next ) {
  11676. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11677. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11678. 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]
  11679. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11680. }
  11681. }
  11682. }
  11683. }
  11684. /// Friends List
  11685. ///
  11686. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11687. /// 0206 <account id>.L <char id>.L <state>.B
  11688. /// state:
  11689. /// 0 = online
  11690. /// 1 = offline
  11691. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11692. {
  11693. int i, fd = sd->fd;
  11694. //Seek friend.
  11695. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11696. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11697. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11698. return; //Not found
  11699. WFIFOHEAD(fd,packet_len(0x206));
  11700. WFIFOW(fd, 0) = 0x206;
  11701. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11702. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11703. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11704. WFIFOSET(fd, packet_len(0x206));
  11705. }
  11706. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11707. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11708. {
  11709. uint32 account_id, char_id, online;
  11710. account_id = va_arg(ap, int);
  11711. char_id = va_arg(ap, int);
  11712. online = va_arg(ap, int);
  11713. clif_friendslist_toggle(sd, account_id, char_id, online);
  11714. return 0;
  11715. }
  11716. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11717. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11718. void clif_friendslist_send(struct map_session_data *sd)
  11719. {
  11720. int i = 0, n, fd = sd->fd;
  11721. // Send friends list
  11722. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11723. WFIFOW(fd, 0) = 0x201;
  11724. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11725. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11726. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11727. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11728. }
  11729. if (i) {
  11730. WFIFOW(fd,2) = 4 + 32 * i;
  11731. WFIFOSET(fd, WFIFOW(fd,2));
  11732. }
  11733. for (n = 0; n < i; n++) { //Sending the online players
  11734. if (map_charid2sd(sd->status.friends[n].char_id))
  11735. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11736. }
  11737. }
  11738. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11739. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11740. /// result:
  11741. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11742. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11743. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11744. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11745. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11746. {
  11747. int fd;
  11748. nullpo_retv(sd);
  11749. fd = sd->fd;
  11750. WFIFOHEAD(fd,packet_len(0x209));
  11751. WFIFOW(fd,0) = 0x209;
  11752. WFIFOW(fd,2) = type;
  11753. if (f_sd) {
  11754. WFIFOL(fd,4) = f_sd->status.account_id;
  11755. WFIFOL(fd,8) = f_sd->status.char_id;
  11756. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11757. }
  11758. WFIFOSET(fd, packet_len(0x209));
  11759. }
  11760. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11761. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11762. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  11763. {
  11764. int fd = sd->fd;
  11765. WFIFOHEAD(fd,packet_len(0x207));
  11766. WFIFOW(fd,0) = 0x207;
  11767. WFIFOL(fd,2) = account_id;
  11768. WFIFOL(fd,6) = char_id;
  11769. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11770. WFIFOSET(fd,packet_len(0x207));
  11771. }
  11772. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11773. /// 0202 <name>.24B
  11774. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11775. {
  11776. struct map_session_data *f_sd;
  11777. int i;
  11778. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11779. // ensure that the request player's friend list is not full
  11780. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11781. if( i == MAX_FRIENDS ) {
  11782. clif_friendslist_reqack(sd, f_sd, 2);
  11783. return;
  11784. }
  11785. // Friend doesn't exist (no player with this name)
  11786. if (f_sd == NULL) {
  11787. clif_displaymessage(fd, msg_txt(sd,3));
  11788. return;
  11789. }
  11790. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11791. return;
  11792. }
  11793. // @noask [LuzZza]
  11794. if(f_sd->state.noask) {
  11795. clif_noask_sub(sd, f_sd, 5);
  11796. return;
  11797. }
  11798. // Friend already exists
  11799. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11800. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11801. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11802. return;
  11803. }
  11804. }
  11805. f_sd->friend_req = sd->status.char_id;
  11806. sd->friend_req = f_sd->status.char_id;
  11807. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11808. }
  11809. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11810. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11811. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11812. /// reply:
  11813. /// 0 = rejected
  11814. /// 1 = accepted
  11815. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11816. {
  11817. struct map_session_data *f_sd;
  11818. uint32 account_id;
  11819. char reply;
  11820. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11821. account_id = RFIFOL(fd,info->pos[0]);
  11822. //char_id = RFIFOL(fd,info->pos[1]);
  11823. if(sd->packet_ver < 6)
  11824. reply = RFIFOB(fd,info->pos[2]);
  11825. else
  11826. reply = RFIFOL(fd,info->pos[2]);
  11827. if( sd->bl.id == account_id ) {// adding oneself as friend
  11828. return;
  11829. }
  11830. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11831. if (f_sd == NULL)
  11832. return;
  11833. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11834. clif_friendslist_reqack(f_sd, sd, 1);
  11835. else {
  11836. int i;
  11837. // Find an empty slot
  11838. for (i = 0; i < MAX_FRIENDS; i++)
  11839. if (f_sd->status.friends[i].char_id == 0)
  11840. break;
  11841. if (i == MAX_FRIENDS) {
  11842. clif_friendslist_reqack(f_sd, sd, 2);
  11843. return;
  11844. }
  11845. f_sd->status.friends[i].account_id = sd->status.account_id;
  11846. f_sd->status.friends[i].char_id = sd->status.char_id;
  11847. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11848. clif_friendslist_reqack(f_sd, sd, 0);
  11849. if (battle_config.friend_auto_add) {
  11850. // Also add f_sd to sd's friendlist.
  11851. for (i = 0; i < MAX_FRIENDS; i++) {
  11852. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11853. return; //No need to add anything.
  11854. if (sd->status.friends[i].char_id == 0)
  11855. break;
  11856. }
  11857. if (i == MAX_FRIENDS) {
  11858. clif_friendslist_reqack(sd, f_sd, 2);
  11859. return;
  11860. }
  11861. sd->status.friends[i].account_id = f_sd->status.account_id;
  11862. sd->status.friends[i].char_id = f_sd->status.char_id;
  11863. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11864. clif_friendslist_reqack(sd, f_sd, 0);
  11865. }
  11866. }
  11867. }
  11868. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11869. /// 0203 <account id>.L <char id>.L
  11870. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11871. {
  11872. struct map_session_data *f_sd = NULL;
  11873. uint32 account_id, char_id;
  11874. int i, j;
  11875. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11876. account_id = RFIFOL(fd,info->pos[0]);
  11877. char_id = RFIFOL(fd,info->pos[1]);
  11878. // Search friend
  11879. for (i = 0; i < MAX_FRIENDS &&
  11880. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11881. if (i == MAX_FRIENDS) {
  11882. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11883. return;
  11884. }
  11885. //remove from friend's list first
  11886. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11887. for (i = 0; i < MAX_FRIENDS &&
  11888. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11889. if (i != MAX_FRIENDS) {
  11890. // move all chars up
  11891. for(j = i + 1; j < MAX_FRIENDS; j++)
  11892. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11893. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11894. //should the guy be notified of some message? we should add it here if so
  11895. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11896. WFIFOW(f_sd->fd,0) = 0x20a;
  11897. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11898. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11899. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11900. }
  11901. } else { //friend not online -- ask char server to delete from his friendlist
  11902. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11903. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11904. return;
  11905. }
  11906. }
  11907. // We can now delete from original requester
  11908. for (i = 0; i < MAX_FRIENDS &&
  11909. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11910. // move all chars up
  11911. for(j = i + 1; j < MAX_FRIENDS; j++)
  11912. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11913. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11914. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11915. WFIFOHEAD(fd,packet_len(0x20a));
  11916. WFIFOW(fd,0) = 0x20a;
  11917. WFIFOL(fd,2) = account_id;
  11918. WFIFOL(fd,6) = char_id;
  11919. WFIFOSET(fd, packet_len(0x20a));
  11920. }
  11921. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11922. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11923. void clif_PVPInfo(struct map_session_data* sd)
  11924. {
  11925. int fd = sd->fd;
  11926. WFIFOHEAD(fd,packet_len(0x210));
  11927. WFIFOW(fd,0) = 0x210;
  11928. WFIFOL(fd,2) = sd->status.char_id;
  11929. WFIFOL(fd,6) = sd->status.account_id;
  11930. WFIFOL(fd,10) = sd->pvp_won; // times won
  11931. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11932. WFIFOL(fd,18) = sd->pvp_point;
  11933. WFIFOSET(fd, packet_len(0x210));
  11934. }
  11935. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11936. /// 020f <char id>.L <account id>.L
  11937. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11938. {
  11939. // TODO: Is there a way to use this on an another player (char/acc id)?
  11940. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11941. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11942. clif_PVPInfo(sd);
  11943. }
  11944. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11945. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11946. void clif_blacksmith(struct map_session_data* sd)
  11947. {
  11948. int i, fd = sd->fd;
  11949. const char* name;
  11950. WFIFOHEAD(fd,packet_len(0x219));
  11951. WFIFOW(fd,0) = 0x219;
  11952. //Packet size limits this list to 10 elements. [Skotlex]
  11953. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11954. if (smith_fame_list[i].id > 0) {
  11955. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11956. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11957. {
  11958. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11959. } else
  11960. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11961. } else
  11962. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11963. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11964. }
  11965. for(;i < 10; i++) { //In case the MAX is less than 10.
  11966. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11967. WFIFOL(fd, 242 + i * 4) = 0;
  11968. }
  11969. WFIFOSET(fd, packet_len(0x219));
  11970. }
  11971. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11972. /// 0217
  11973. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11974. {
  11975. clif_blacksmith(sd);
  11976. }
  11977. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11978. /// 021b <points>.L <total points>.L
  11979. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11980. {
  11981. int fd = sd->fd;
  11982. WFIFOHEAD(fd,packet_len(0x21b));
  11983. WFIFOW(fd,0) = 0x21b;
  11984. WFIFOL(fd,2) = points;
  11985. WFIFOL(fd,6) = sd->status.fame;
  11986. WFIFOSET(fd, packet_len(0x21b));
  11987. }
  11988. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11989. /// 021a { <name>.24B }*10 { <point>.L }*10
  11990. void clif_alchemist(struct map_session_data* sd)
  11991. {
  11992. int i, fd = sd->fd;
  11993. const char* name;
  11994. WFIFOHEAD(fd,packet_len(0x21a));
  11995. WFIFOW(fd,0) = 0x21a;
  11996. //Packet size limits this list to 10 elements. [Skotlex]
  11997. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11998. if (chemist_fame_list[i].id > 0) {
  11999. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  12000. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12001. {
  12002. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12003. } else
  12004. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12005. } else
  12006. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12007. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12008. }
  12009. for(;i < 10; i++) { //In case the MAX is less than 10.
  12010. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12011. WFIFOL(fd, 242 + i * 4) = 0;
  12012. }
  12013. WFIFOSET(fd, packet_len(0x21a));
  12014. }
  12015. /// /alchemist (CZ_ALCHEMIST_RANK).
  12016. /// 0218
  12017. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12018. {
  12019. clif_alchemist(sd);
  12020. }
  12021. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12022. /// 021c <points>.L <total points>.L
  12023. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12024. {
  12025. int fd = sd->fd;
  12026. WFIFOHEAD(fd,packet_len(0x21c));
  12027. WFIFOW(fd,0) = 0x21c;
  12028. WFIFOL(fd,2) = points;
  12029. WFIFOL(fd,6) = sd->status.fame;
  12030. WFIFOSET(fd, packet_len(0x21c));
  12031. }
  12032. /// /taekwon list (ZC_TAEKWON_RANK).
  12033. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12034. void clif_taekwon(struct map_session_data* sd)
  12035. {
  12036. int i, fd = sd->fd;
  12037. const char* name;
  12038. WFIFOHEAD(fd,packet_len(0x226));
  12039. WFIFOW(fd,0) = 0x226;
  12040. //Packet size limits this list to 10 elements. [Skotlex]
  12041. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12042. if (taekwon_fame_list[i].id > 0) {
  12043. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12044. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12045. {
  12046. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12047. } else
  12048. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12049. } else
  12050. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12051. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12052. }
  12053. for(;i < 10; i++) { //In case the MAX is less than 10.
  12054. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12055. WFIFOL(fd, 242 + i * 4) = 0;
  12056. }
  12057. WFIFOSET(fd, packet_len(0x226));
  12058. }
  12059. /// /taekwon (CZ_TAEKWON_RANK).
  12060. /// 0225
  12061. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12062. {
  12063. clif_taekwon(sd);
  12064. }
  12065. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12066. /// 0224 <points>.L <total points>.L
  12067. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12068. {
  12069. int fd = sd->fd;
  12070. WFIFOHEAD(fd,packet_len(0x224));
  12071. WFIFOW(fd,0) = 0x224;
  12072. WFIFOL(fd,2) = points;
  12073. WFIFOL(fd,6) = sd->status.fame;
  12074. WFIFOSET(fd, packet_len(0x224));
  12075. }
  12076. /// /pk list (ZC_KILLER_RANK).
  12077. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12078. void clif_ranking_pk(struct map_session_data* sd)
  12079. {
  12080. int i, fd = sd->fd;
  12081. WFIFOHEAD(fd,packet_len(0x238));
  12082. WFIFOW(fd,0) = 0x238;
  12083. for(i=0;i<10;i++){
  12084. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12085. WFIFOL(fd,i*4+242) = 0;
  12086. }
  12087. WFIFOSET(fd, packet_len(0x238));
  12088. }
  12089. /// /pk (CZ_KILLER_RANK).
  12090. /// 0237
  12091. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12092. {
  12093. clif_ranking_pk(sd);
  12094. }
  12095. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12096. /// 0254 <which>.B
  12097. /// which: (unused atm for security purpose)
  12098. /// 0 = sun
  12099. /// 1 = moon
  12100. /// 2 = star
  12101. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12102. {
  12103. int i;
  12104. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12105. if (sd->menuskill_id != SG_FEEL)
  12106. return;
  12107. i = sd->menuskill_val-1;
  12108. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12109. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12110. sd->feel_map[i].m = sd->bl.m;
  12111. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  12112. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12113. // clif_misceffect2(&sd->bl, 0x1b0);
  12114. // clif_misceffect2(&sd->bl, 0x21f);
  12115. clif_feel_info(sd, i, 0);
  12116. clif_menuskill_clear(sd);
  12117. }
  12118. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12119. /// 0253 <which>.B
  12120. /// which:
  12121. /// 0 = sun
  12122. /// 1 = moon
  12123. /// 2 = star
  12124. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12125. {
  12126. WFIFOHEAD(fd,packet_len(0x253));
  12127. WFIFOW(fd,0)=0x253;
  12128. WFIFOB(fd,2)=TOB(skill_lv-1);
  12129. WFIFOSET(fd, packet_len(0x253));
  12130. sd->menuskill_id = SG_FEEL;
  12131. sd->menuskill_val = skill_lv;
  12132. }
  12133. /// Request to change homunculus' name (CZ_RENAME_MER).
  12134. /// 0231 <name>.24B
  12135. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12136. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12137. }
  12138. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12139. /// 0234 <id>.L
  12140. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12141. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12142. struct block_list *bl = NULL;
  12143. struct unit_data *ud = NULL;
  12144. if( sd->md && sd->md->bl.id == id )
  12145. bl = &sd->md->bl;
  12146. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12147. bl = &sd->hd->bl; // Moving Homunculus
  12148. else
  12149. return;
  12150. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12151. ud = unit_bl2ud(bl);
  12152. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12153. }
  12154. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12155. /// 0232 <id>.L <position data>.3B
  12156. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12157. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12158. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12159. struct block_list *bl = NULL;
  12160. short x, y;
  12161. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12162. if( sd->md && sd->md->bl.id == id )
  12163. bl = &sd->md->bl; // Moving Mercenary
  12164. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12165. bl = &sd->hd->bl; // Moving Homunculus
  12166. else
  12167. return;
  12168. unit_walktoxy(bl, x, y, 4);
  12169. }
  12170. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12171. /// 0233 <id>.L <target id>.L <action>.B
  12172. /// action:
  12173. /// always 0
  12174. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12175. {
  12176. struct block_list *bl = NULL;
  12177. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12178. int id = RFIFOL(fd,info->pos[0]);
  12179. int target_id = RFIFOL(fd,info->pos[1]);
  12180. int action_type = RFIFOB(fd,info->pos[2]);
  12181. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12182. bl = &sd->hd->bl;
  12183. else if( sd->md && sd->md->bl.id == id )
  12184. bl = &sd->md->bl;
  12185. else return;
  12186. unit_stop_attack(bl);
  12187. unit_attack(bl, target_id, action_type != 0);
  12188. }
  12189. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12190. /// 022d <type>.W <command>.B
  12191. /// type:
  12192. /// always 0
  12193. /// command:
  12194. /// 0 = homunculus information
  12195. /// 1 = feed
  12196. /// 2 = delete
  12197. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12198. { //[orn]
  12199. int cmd = RFIFOW(fd,0);
  12200. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12201. if(!hom_is_active(sd->hd))
  12202. return;
  12203. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12204. }
  12205. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12206. /// 0292
  12207. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12208. {
  12209. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12210. uint8 hp = 100, sp = 100;
  12211. if (item_position < 0) {
  12212. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12213. // HP restored
  12214. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12215. sp = 0;
  12216. }
  12217. else
  12218. return;
  12219. }
  12220. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12221. return;
  12222. if (!status_revive(&sd->bl, hp, sp))
  12223. return;
  12224. if (item_position < 0)
  12225. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12226. else
  12227. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12228. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12229. }
  12230. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12231. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12232. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12233. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12234. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12235. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12236. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12237. void clif_check(int fd, struct map_session_data* pl_sd)
  12238. {
  12239. WFIFOHEAD(fd,packet_len(0x214));
  12240. WFIFOW(fd, 0) = 0x214;
  12241. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12242. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12243. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12244. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12245. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12246. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12247. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12248. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12249. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12250. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12251. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12252. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12253. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12254. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12255. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12256. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12257. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12258. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12259. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12260. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12261. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12262. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12263. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12264. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12265. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12266. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12267. WFIFOSET(fd,packet_len(0x214));
  12268. }
  12269. /// /check (CZ_REQ_STATUS_GM).
  12270. /// Request character's status values.
  12271. /// 0213 <char name>.24B
  12272. void clif_parse_Check(int fd, struct map_session_data *sd)
  12273. {
  12274. char charname[NAME_LENGTH];
  12275. struct map_session_data* pl_sd;
  12276. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12277. return;
  12278. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12279. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12280. {
  12281. return;
  12282. }
  12283. clif_check(fd, pl_sd);
  12284. }
  12285. /// MAIL SYSTEM
  12286. /// By Zephyrus
  12287. ///
  12288. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12289. /// 0255 <index>.W <result>.B
  12290. /// result:
  12291. /// 0 = success
  12292. /// 1 = failure
  12293. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12294. {
  12295. WFIFOHEAD(fd,packet_len(0x255));
  12296. WFIFOW(fd,0) = 0x255;
  12297. WFIFOW(fd,2) = index;
  12298. WFIFOB(fd,4) = flag;
  12299. WFIFOSET(fd,packet_len(0x255));
  12300. }
  12301. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12302. /// 0245 <result>.B
  12303. /// result:
  12304. /// 0 = success
  12305. /// 1 = failure
  12306. /// 2 = too many items
  12307. void clif_Mail_getattachment(int fd, uint8 flag)
  12308. {
  12309. WFIFOHEAD(fd,packet_len(0x245));
  12310. WFIFOW(fd,0) = 0x245;
  12311. WFIFOB(fd,2) = flag;
  12312. WFIFOSET(fd,packet_len(0x245));
  12313. }
  12314. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12315. /// 0249 <result>.B
  12316. /// result:
  12317. /// 0 = success
  12318. /// 1 = recipinent does not exist
  12319. void clif_Mail_send(int fd, bool fail)
  12320. {
  12321. WFIFOHEAD(fd,packet_len(0x249));
  12322. WFIFOW(fd,0) = 0x249;
  12323. WFIFOB(fd,2) = fail;
  12324. WFIFOSET(fd,packet_len(0x249));
  12325. }
  12326. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12327. /// 0257 <mail id>.L <result>.W
  12328. /// result:
  12329. /// 0 = success
  12330. /// 1 = failure
  12331. void clif_Mail_delete(int fd, int mail_id, short fail)
  12332. {
  12333. WFIFOHEAD(fd, packet_len(0x257));
  12334. WFIFOW(fd,0) = 0x257;
  12335. WFIFOL(fd,2) = mail_id;
  12336. WFIFOW(fd,6) = fail;
  12337. WFIFOSET(fd, packet_len(0x257));
  12338. }
  12339. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12340. /// 0274 <mail id>.L <result>.W
  12341. /// result:
  12342. /// 0 = success
  12343. /// 1 = failure
  12344. void clif_Mail_return(int fd, int mail_id, short fail)
  12345. {
  12346. WFIFOHEAD(fd,packet_len(0x274));
  12347. WFIFOW(fd,0) = 0x274;
  12348. WFIFOL(fd,2) = mail_id;
  12349. WFIFOW(fd,6) = fail;
  12350. WFIFOSET(fd,packet_len(0x274));
  12351. }
  12352. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12353. /// 024a <mail id>.L <title>.40B <sender>.24B
  12354. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12355. {
  12356. WFIFOHEAD(fd,packet_len(0x24a));
  12357. WFIFOW(fd,0) = 0x24a;
  12358. WFIFOL(fd,2) = mail_id;
  12359. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12360. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12361. WFIFOSET(fd,packet_len(0x24a));
  12362. }
  12363. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12364. /// 0260 <type>.L
  12365. /// type:
  12366. /// 0 = open
  12367. /// 1 = close
  12368. void clif_Mail_window(int fd, int flag)
  12369. {
  12370. WFIFOHEAD(fd,packet_len(0x260));
  12371. WFIFOW(fd,0) = 0x260;
  12372. WFIFOL(fd,2) = flag;
  12373. WFIFOSET(fd,packet_len(0x260));
  12374. }
  12375. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12376. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12377. /// read:
  12378. /// 0 = unread
  12379. /// 1 = read
  12380. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12381. {
  12382. int fd = sd->fd;
  12383. struct mail_data *md = &sd->mail.inbox;
  12384. struct mail_message *msg;
  12385. int len, i, j;
  12386. len = 8 + (73 * md->amount);
  12387. WFIFOHEAD(fd,len);
  12388. WFIFOW(fd,0) = 0x240;
  12389. WFIFOW(fd,2) = len;
  12390. WFIFOL(fd,4) = md->amount;
  12391. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12392. {
  12393. msg = &md->msg[i];
  12394. if (msg->id < 1)
  12395. continue;
  12396. WFIFOL(fd,8+73*j) = msg->id;
  12397. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12398. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12399. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12400. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12401. j++;
  12402. }
  12403. WFIFOSET(fd,len);
  12404. if( md->full ) {// TODO: is this official?
  12405. char output[100];
  12406. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12407. clif_disp_onlyself(sd, output, strlen(output));
  12408. }
  12409. }
  12410. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12411. /// 023f
  12412. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12413. {
  12414. struct mail_data* md = &sd->mail.inbox;
  12415. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12416. intif_Mail_requestinbox(sd->status.char_id, 1);
  12417. else
  12418. clif_Mail_refreshinbox(sd);
  12419. mail_removeitem(sd, 0);
  12420. mail_removezeny(sd, 0);
  12421. }
  12422. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12423. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12424. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12425. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12426. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12427. {
  12428. int i, fd = sd->fd;
  12429. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12430. if( i == MAIL_MAX_INBOX ) {
  12431. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12432. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12433. return;
  12434. } else {
  12435. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12436. struct item *item = &msg->item;
  12437. struct item_data *data;
  12438. int msg_len = strlen(msg->body), len;
  12439. if( msg_len == 0 ) {
  12440. strcpy(msg->body, "(no message)");
  12441. msg_len = strlen(msg->body);
  12442. }
  12443. len = 101 + msg_len;
  12444. WFIFOHEAD(fd,len);
  12445. WFIFOW(fd,0) = 0x242;
  12446. WFIFOW(fd,2) = len;
  12447. WFIFOL(fd,4) = msg->id;
  12448. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12449. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12450. WFIFOL(fd,72) = 0;
  12451. WFIFOL(fd,76) = msg->zeny;
  12452. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12453. WFIFOL(fd,80) = item->amount;
  12454. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12455. WFIFOW(fd,86) = data->type;
  12456. WFIFOB(fd,88) = item->identify;
  12457. WFIFOB(fd,89) = item->attribute;
  12458. WFIFOB(fd,90) = item->refine;
  12459. WFIFOW(fd,91) = item->card[0];
  12460. WFIFOW(fd,93) = item->card[1];
  12461. WFIFOW(fd,95) = item->card[2];
  12462. WFIFOW(fd,97) = item->card[3];
  12463. } else // no item, set all to zero
  12464. memset(WFIFOP(fd,80), 0x00, 19);
  12465. WFIFOB(fd,99) = (unsigned char)msg_len;
  12466. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12467. WFIFOSET(fd,len);
  12468. if (msg->status == MAIL_UNREAD) {
  12469. msg->status = MAIL_READ;
  12470. intif_Mail_read(mail_id);
  12471. clif_parse_Mail_refreshinbox(fd, sd);
  12472. }
  12473. }
  12474. }
  12475. /// Request to open a mail (CZ_MAIL_OPEN).
  12476. /// 0241 <mail id>.L
  12477. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12478. {
  12479. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12480. if( mail_id <= 0 )
  12481. return;
  12482. if( mail_invalid_operation(sd) )
  12483. return;
  12484. clif_Mail_read(sd, mail_id);
  12485. }
  12486. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12487. /// 0244 <mail id>.L
  12488. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12489. {
  12490. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12491. int i;
  12492. bool fail = false;
  12493. if( !chrif_isconnected() )
  12494. return;
  12495. if( mail_id <= 0 )
  12496. return;
  12497. if( mail_invalid_operation(sd) )
  12498. return;
  12499. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12500. if( i == MAIL_MAX_INBOX )
  12501. return;
  12502. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12503. return;
  12504. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12505. clif_Mail_getattachment(fd, 1);
  12506. return;
  12507. }
  12508. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12509. struct item_data *data;
  12510. unsigned int weight;
  12511. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12512. return;
  12513. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12514. case CHKADDITEM_NEW:
  12515. fail = ( pc_inventoryblank(sd) == 0 );
  12516. break;
  12517. case CHKADDITEM_OVERAMOUNT:
  12518. fail = true;
  12519. }
  12520. if( fail ) {
  12521. clif_Mail_getattachment(fd, 1);
  12522. return;
  12523. }
  12524. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12525. if( sd->weight + weight > sd->max_weight ) {
  12526. clif_Mail_getattachment(fd, 2);
  12527. return;
  12528. }
  12529. }
  12530. sd->mail.inbox.msg[i].zeny = 0;
  12531. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12532. clif_Mail_read(sd, mail_id);
  12533. intif_Mail_getattach(sd->status.char_id, mail_id);
  12534. }
  12535. /// Request to delete a mail (CZ_MAIL_DELETE).
  12536. /// 0243 <mail id>.L
  12537. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12538. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12539. int i;
  12540. if( !chrif_isconnected() )
  12541. return;
  12542. if( mail_id <= 0 )
  12543. return;
  12544. if( mail_invalid_operation(sd) )
  12545. return;
  12546. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12547. if (i < MAIL_MAX_INBOX) {
  12548. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12549. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12550. clif_Mail_delete(sd->fd, mail_id, 1);
  12551. return;
  12552. }
  12553. intif_Mail_delete(sd->status.char_id, mail_id);
  12554. }
  12555. }
  12556. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12557. /// 0273 <mail id>.L <receive name>.24B
  12558. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12559. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12560. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12561. int i;
  12562. if( mail_id <= 0 )
  12563. return;
  12564. if( mail_invalid_operation(sd) )
  12565. return;
  12566. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12567. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12568. intif_Mail_return(sd->status.char_id, mail_id);
  12569. else
  12570. clif_Mail_return(sd->fd, mail_id, 1);
  12571. }
  12572. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12573. /// 0247 <index>.W <amount>.L
  12574. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12575. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12576. int idx = RFIFOW(fd,info->pos[0]);
  12577. int amount = RFIFOL(fd,info->pos[1]);
  12578. unsigned char flag;
  12579. if( !chrif_isconnected() )
  12580. return;
  12581. if (idx < 0 || amount < 0)
  12582. return;
  12583. flag = mail_setitem(sd, idx, amount);
  12584. clif_Mail_setattachment(fd,idx,!flag);
  12585. }
  12586. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12587. /// 0246 <type>.W
  12588. /// type:
  12589. /// 0 = reset all
  12590. /// 1 = remove item
  12591. /// 2 = remove zeny
  12592. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12593. {
  12594. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12595. if (type == 0 || type == 1)
  12596. mail_removeitem(sd, 0);
  12597. if (type == 0 || type == 2)
  12598. mail_removezeny(sd, 0);
  12599. }
  12600. /// Request to send mail (CZ_MAIL_SEND).
  12601. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12602. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12603. {
  12604. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12605. if( !chrif_isconnected() )
  12606. return;
  12607. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12608. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12609. return;
  12610. }
  12611. 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]));
  12612. }
  12613. /// AUCTION SYSTEM
  12614. /// By Zephyrus
  12615. ///
  12616. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12617. /// 025f <type>.L
  12618. /// type:
  12619. /// 0 = open
  12620. /// 1 = close
  12621. void clif_Auction_openwindow(struct map_session_data *sd)
  12622. {
  12623. int fd = sd->fd;
  12624. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12625. return;
  12626. if( !battle_config.feature_auction )
  12627. return;
  12628. WFIFOHEAD(fd,packet_len(0x25f));
  12629. WFIFOW(fd,0) = 0x25f;
  12630. WFIFOL(fd,2) = 0;
  12631. WFIFOSET(fd,packet_len(0x25f));
  12632. }
  12633. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12634. /// 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 }*
  12635. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12636. {
  12637. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12638. struct auction_data auction;
  12639. struct item_data *item;
  12640. WFIFOHEAD(fd,12 + (count * 83));
  12641. WFIFOW(fd,0) = 0x252;
  12642. WFIFOW(fd,2) = 12 + (count * 83);
  12643. WFIFOL(fd,4) = pages;
  12644. WFIFOL(fd,8) = count;
  12645. for( i = 0; i < count; i++ ) {
  12646. int k = 12 + (i * 83);
  12647. memcpy(&auction, RBUFP(buf,i * len), len);
  12648. WFIFOL(fd,k) = auction.auction_id;
  12649. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12650. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12651. WFIFOW(fd,28+k) = item->view_id;
  12652. else
  12653. WFIFOW(fd,28+k) = auction.item.nameid;
  12654. WFIFOL(fd,30+k) = auction.type;
  12655. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12656. WFIFOB(fd,36+k) = auction.item.identify;
  12657. WFIFOB(fd,37+k) = auction.item.attribute;
  12658. WFIFOB(fd,38+k) = auction.item.refine;
  12659. WFIFOW(fd,39+k) = auction.item.card[0];
  12660. WFIFOW(fd,41+k) = auction.item.card[1];
  12661. WFIFOW(fd,43+k) = auction.item.card[2];
  12662. WFIFOW(fd,45+k) = auction.item.card[3];
  12663. WFIFOL(fd,47+k) = auction.price;
  12664. WFIFOL(fd,51+k) = auction.buynow;
  12665. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12666. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12667. }
  12668. WFIFOSET(fd,WFIFOW(fd,2));
  12669. }
  12670. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12671. /// 0256 <index>.W <result>.B
  12672. /// result:
  12673. /// 0 = success
  12674. /// 1 = failure
  12675. static void clif_Auction_setitem(int fd, int index, bool fail)
  12676. {
  12677. WFIFOHEAD(fd,packet_len(0x256));
  12678. WFIFOW(fd,0) = 0x256;
  12679. WFIFOW(fd,2) = index;
  12680. WFIFOB(fd,4) = fail;
  12681. WFIFOSET(fd,packet_len(0x256));
  12682. }
  12683. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12684. /// 024b <type>.W
  12685. /// type:
  12686. /// 0 = create (any other action in auction window)
  12687. /// 1 = cancel (cancel pressed on register tab)
  12688. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12689. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12690. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12691. if( sd->auction.amount > 0 )
  12692. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12693. sd->auction.amount = 0;
  12694. }
  12695. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12696. /// 024c <index>.W <count>.L
  12697. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12698. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12699. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12700. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12701. struct item_data *item;
  12702. if( !battle_config.feature_auction )
  12703. return;
  12704. if( sd->auction.amount > 0 )
  12705. sd->auction.amount = 0;
  12706. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12707. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12708. return;
  12709. }
  12710. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12711. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12712. return;
  12713. }
  12714. 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) )
  12715. { // Consumable or pets are not allowed
  12716. clif_Auction_setitem(sd->fd, idx, true);
  12717. return;
  12718. }
  12719. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12720. !sd->status.inventory[idx].identify ||
  12721. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12722. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12723. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12724. ) {
  12725. clif_Auction_setitem(sd->fd, idx, true);
  12726. return;
  12727. }
  12728. sd->auction.index = idx;
  12729. sd->auction.amount = amount;
  12730. clif_Auction_setitem(fd, idx + 2, false);
  12731. }
  12732. /// Result from an auction action (ZC_AUCTION_RESULT).
  12733. /// 0250 <result>.B
  12734. /// result:
  12735. /// 0 = You have failed to bid into the auction
  12736. /// 1 = You have successfully bid in the auction
  12737. /// 2 = The auction has been canceled
  12738. /// 3 = An auction with at least one bidder cannot be canceled
  12739. /// 4 = You cannot register more than 5 items in an auction at a time
  12740. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12741. /// 6 = You have won the auction
  12742. /// 7 = You have failed to win the auction
  12743. /// 8 = You do not have enough Zeny
  12744. /// 9 = You cannot place more than 5 bids at a time
  12745. void clif_Auction_message(int fd, unsigned char flag)
  12746. {
  12747. WFIFOHEAD(fd,packet_len(0x250));
  12748. WFIFOW(fd,0) = 0x250;
  12749. WFIFOB(fd,2) = flag;
  12750. WFIFOSET(fd,packet_len(0x250));
  12751. }
  12752. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12753. /// 025e <result>.W
  12754. /// result:
  12755. /// 0 = You have ended the auction
  12756. /// 1 = You cannot end the auction
  12757. /// 2 = Auction ID is incorrect
  12758. void clif_Auction_close(int fd, unsigned char flag)
  12759. {
  12760. WFIFOHEAD(fd,packet_len(0x25e));
  12761. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12762. WFIFOW(fd,2) = flag;
  12763. WFIFOSET(fd,packet_len(0x25e));
  12764. }
  12765. /// Request to add an auction (CZ_AUCTION_ADD).
  12766. /// 024d <now money>.L <max money>.L <delete hour>.W
  12767. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12768. {
  12769. struct auction_data auction;
  12770. struct item_data *item;
  12771. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12772. if( !battle_config.feature_auction )
  12773. return;
  12774. auction.price = RFIFOL(fd,info->pos[0]);
  12775. auction.buynow = RFIFOL(fd,info->pos[1]);
  12776. auction.hours = RFIFOW(fd,info->pos[2]);
  12777. // Invalid Situations...
  12778. if( sd->auction.amount < 1 ) {
  12779. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12780. return;
  12781. }
  12782. if( auction.price >= auction.buynow ) {
  12783. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12784. return;
  12785. }
  12786. if( auction.hours < 1 || auction.hours > 48 ) {
  12787. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12788. return;
  12789. }
  12790. // Auction checks...
  12791. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12792. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12793. clif_Auction_message(fd, 2); // The auction has been canceled
  12794. return;
  12795. }
  12796. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12797. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12798. return;
  12799. }
  12800. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12801. auction.buynow = battle_config.auction_maximumprice;
  12802. if( auction.price >= auction.buynow )
  12803. auction.price = auction.buynow - 1;
  12804. }
  12805. auction.auction_id = 0;
  12806. auction.seller_id = sd->status.char_id;
  12807. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12808. auction.buyer_id = 0;
  12809. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12810. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12811. {
  12812. clif_Auction_message(fd, 2); // The auction has been canceled
  12813. return;
  12814. }
  12815. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12816. { // Just in case
  12817. clif_Auction_message(fd, 2); // The auction has been canceled
  12818. return;
  12819. }
  12820. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12821. auction.type = item->type;
  12822. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12823. auction.item.amount = 1;
  12824. auction.timestamp = 0;
  12825. if( !intif_Auction_register(&auction) )
  12826. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12827. else
  12828. {
  12829. int zeny = auction.hours*battle_config.auction_feeperhour;
  12830. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12831. sd->auction.amount = 0;
  12832. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12833. }
  12834. }
  12835. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12836. /// 024e <auction id>.L
  12837. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12838. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12839. intif_Auction_cancel(sd->status.char_id, auction_id);
  12840. }
  12841. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12842. /// 025d <auction id>.L
  12843. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12844. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12845. intif_Auction_close(sd->status.char_id, auction_id);
  12846. }
  12847. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12848. /// 024f <auction id>.L <money>.L
  12849. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12850. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12851. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12852. int bid = RFIFOL(fd,info->pos[1]);
  12853. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12854. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12855. return;
  12856. }
  12857. if( bid <= 0 )
  12858. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12859. else if( bid > sd->status.zeny )
  12860. clif_Auction_message(fd, 8); // You do not have enough zeny
  12861. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12862. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12863. else {
  12864. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12865. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12866. }
  12867. }
  12868. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12869. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12870. /// search type:
  12871. /// 0 = armor
  12872. /// 1 = weapon
  12873. /// 2 = card
  12874. /// 3 = misc
  12875. /// 4 = name search
  12876. /// 5 = auction id search
  12877. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12878. char search_text[NAME_LENGTH];
  12879. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12880. short type = RFIFOW(fd,info->pos[0]);
  12881. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12882. int page = RFIFOW(fd,info->pos[3]);
  12883. if( !battle_config.feature_auction )
  12884. return;
  12885. clif_parse_Auction_cancelreg(fd, sd);
  12886. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12887. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12888. }
  12889. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12890. /// 025c <type>.W
  12891. /// type:
  12892. /// 0 = sell (own auctions)
  12893. /// 1 = buy (own bids)
  12894. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12895. {
  12896. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12897. if( !battle_config.feature_auction )
  12898. return;
  12899. clif_parse_Auction_cancelreg(fd, sd);
  12900. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12901. }
  12902. /// CASH/POINT SHOP
  12903. ///
  12904. void clif_cashshop_open( struct map_session_data* sd ){
  12905. WFIFOHEAD( sd->fd, 10 );
  12906. WFIFOW( sd->fd, 0 ) = 0x845;
  12907. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12908. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12909. WFIFOSET( sd->fd, 10 );
  12910. }
  12911. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12912. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12913. clif_cashshop_open( sd );
  12914. }
  12915. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12916. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12917. // No need to do anything here
  12918. }
  12919. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12920. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12921. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12922. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12923. int j;
  12924. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12925. return;
  12926. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12927. WFIFOW(fd, 0) = 0x8c0;
  12928. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12929. WFIFOL(fd, 4) = tab;
  12930. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12931. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12932. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  12933. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  12934. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12935. }
  12936. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12937. }
  12938. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12939. void clif_cashshop_list( int fd ){
  12940. int tab;
  12941. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12942. int length = 8 + cash_shop_items[tab].count * 6;
  12943. int i, offset;
  12944. WFIFOHEAD( fd, length );
  12945. WFIFOW( fd, 0 ) = 0x8ca;
  12946. WFIFOW( fd, 2 ) = length;
  12947. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12948. WFIFOW( fd, 6 ) = tab;
  12949. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12950. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  12951. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  12952. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12953. }
  12954. WFIFOSET( fd, length );
  12955. }
  12956. }
  12957. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12958. if( !sd->status.cashshop_sent ) {
  12959. clif_cashshop_list( fd );
  12960. sd->status.cashshop_sent = true;
  12961. }
  12962. }
  12963. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12964. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12965. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12966. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12967. {
  12968. int fd,i;
  12969. #if PACKETVER < 20070711
  12970. const int offset = 8;
  12971. #else
  12972. const int offset = 12;
  12973. #endif
  12974. nullpo_retv(sd);
  12975. nullpo_retv(nd);
  12976. fd = sd->fd;
  12977. sd->npc_shopid = nd->bl.id;
  12978. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12979. WFIFOW(fd,0) = 0x287;
  12980. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12981. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12982. #if PACKETVER >= 20070711
  12983. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12984. #endif
  12985. for( i = 0; i < nd->u.shop.count; i++ ) {
  12986. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12987. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12988. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12989. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12990. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12991. }
  12992. WFIFOSET(fd,WFIFOW(fd,2));
  12993. }
  12994. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12995. /// 0289 <cash point>.L <error>.W
  12996. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12997. /// error:
  12998. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12999. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13000. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13001. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13002. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13003. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13004. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13005. /// 7 = You can purchase up to 10 items.
  13006. /// 8 = Some items could not be purchased.
  13007. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13008. {
  13009. int fd = sd->fd;
  13010. WFIFOHEAD(fd, packet_len(0x289));
  13011. WFIFOW(fd,0) = 0x289;
  13012. WFIFOL(fd,2) = sd->cashPoints;
  13013. #if PACKETVER < 20070711
  13014. WFIFOW(fd,6) = TOW(error);
  13015. #else
  13016. WFIFOL(fd,6) = sd->kafraPoints;
  13017. WFIFOW(fd,10) = TOW(error);
  13018. #endif
  13019. WFIFOSET(fd, packet_len(0x289));
  13020. }
  13021. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13022. WFIFOHEAD( sd->fd, 16 );
  13023. WFIFOW( sd->fd, 0 ) = 0x849;
  13024. WFIFOL( sd->fd, 2 ) = item_id;
  13025. WFIFOW( sd->fd, 6 ) = result;
  13026. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13027. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13028. WFIFOSET( sd->fd, 16 );
  13029. }
  13030. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13031. /// 0288 <name id>.W <amount>.W
  13032. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13033. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13034. /// 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)
  13035. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  13036. struct s_packet_db* info;
  13037. int cmd = RFIFOW(fd,0);
  13038. nullpo_retv(sd);
  13039. info = &packet_db[sd->packet_ver][cmd];
  13040. if( sd->state.trading || !sd->npc_shopid || !cash_shop_defined) {
  13041. clif_cashshop_ack(sd,1);
  13042. return;
  13043. } else {
  13044. #if PACKETVER < 20101116
  13045. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  13046. short amount = RFIFOW(fd,info->pos[1]);
  13047. int points = RFIFOL(fd,info->pos[2]);
  13048. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13049. #else
  13050. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13051. int len = RFIFOW(fd,info->pos[0]);
  13052. int points = RFIFOL(fd,info->pos[1]);
  13053. int count = RFIFOW(fd,info->pos[2]);
  13054. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13055. if( len < 10 || len != 10 + count * s_itl) {
  13056. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13057. return;
  13058. }
  13059. if(cmd == 0x848) {
  13060. if (cashshop_buylist( sd, points, count, item_list))
  13061. clif_cashshop_ack(sd,0);
  13062. return;
  13063. } else {
  13064. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13065. return;
  13066. }
  13067. #endif
  13068. }
  13069. }
  13070. /// Adoption System
  13071. ///
  13072. /// Adoption message (ZC_BABYMSG).
  13073. /// 0216 <msg>.L
  13074. /// msg:
  13075. /// 0 = "You cannot adopt more than 1 child."
  13076. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13077. /// 2 = "You cannot adopt a married person."
  13078. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13079. {
  13080. int fd = sd->fd;
  13081. WFIFOHEAD(fd,6);
  13082. WFIFOW(fd,0) = 0x216;
  13083. WFIFOL(fd,2) = type;
  13084. WFIFOSET(fd,6);
  13085. }
  13086. /// Adoption confirmation (ZC_REQ_BABY).
  13087. /// 01f6 <account id>.L <char id>.L <name>.B
  13088. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13089. {
  13090. int fd = sd->fd;
  13091. WFIFOHEAD(fd,34);
  13092. WFIFOW(fd,0) = 0x1f6;
  13093. WFIFOL(fd,2) = src->status.account_id;
  13094. WFIFOL(fd,6) = p_id;
  13095. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13096. WFIFOSET(fd,34);
  13097. }
  13098. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13099. /// 01f9 <account id>.L
  13100. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13101. {
  13102. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13103. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13104. if( pc_can_Adopt(sd, p_sd, tsd) )
  13105. {
  13106. tsd->adopt_invite = sd->status.account_id;
  13107. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13108. }
  13109. }
  13110. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13111. /// 01f7 <account id>.L <char id>.L <answer>.L
  13112. /// answer:
  13113. /// 0 = rejected
  13114. /// 1 = accepted
  13115. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13116. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13117. int p1_id = RFIFOL(fd,info->pos[0]);
  13118. int p2_id = RFIFOL(fd,info->pos[1]);
  13119. int result = RFIFOL(fd,info->pos[2]);
  13120. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13121. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13122. int pid = sd->adopt_invite;
  13123. sd->adopt_invite = 0;
  13124. if( p1_sd == NULL || p2_sd == NULL )
  13125. return; // Both players need to be online
  13126. if( pid != p1_sd->status.account_id )
  13127. return; // Incorrect values
  13128. if( result == 0 )
  13129. return; // Rejected
  13130. pc_adoption(p1_sd, p2_sd, sd);
  13131. }
  13132. /// Convex Mirror (ZC_BOSS_INFO).
  13133. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13134. /// infoType:
  13135. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13136. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13137. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13138. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13139. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13140. {
  13141. WFIFOHEAD(fd,70);
  13142. memset(WFIFOP(fd,0),0,70);
  13143. WFIFOW(fd,0) = 0x293;
  13144. if( md != NULL ) {
  13145. if( md->bl.prev != NULL ) { // Boss on This Map
  13146. if( flag ) {
  13147. WFIFOB(fd,2) = 1;
  13148. WFIFOL(fd,3) = md->bl.x;
  13149. WFIFOL(fd,7) = md->bl.y;
  13150. } else
  13151. WFIFOB(fd,2) = 2; // First Time
  13152. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13153. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13154. unsigned int seconds;
  13155. int hours, minutes;
  13156. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13157. hours = seconds / (60 * 60);
  13158. seconds = seconds - (60 * 60 * hours);
  13159. minutes = seconds / 60;
  13160. WFIFOB(fd,2) = 3;
  13161. WFIFOW(fd,11) = hours; // Hours
  13162. WFIFOW(fd,13) = minutes; // Minutes
  13163. }
  13164. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13165. }
  13166. WFIFOSET(fd,70);
  13167. }
  13168. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13169. /// 02d6 <account id>.L
  13170. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13171. {
  13172. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13173. struct map_session_data* tsd = map_id2sd(aid);
  13174. if (!tsd)
  13175. return;
  13176. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13177. clif_viewequip_ack(sd, tsd);
  13178. else
  13179. clif_msg(sd, VIEW_EQUIP_FAIL);
  13180. }
  13181. /// Request to change equip window tick (CZ_CONFIG).
  13182. /// 02d8 <type>.L <flag>.L
  13183. /// type:
  13184. /// 0 = open equip window
  13185. /// flag:
  13186. /// 0 = disabled
  13187. /// 1 = enabled
  13188. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13189. {
  13190. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13191. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13192. sd->status.show_equip = flag;
  13193. clif_equiptickack(sd, flag);
  13194. }
  13195. /// Request to change party invitation tick.
  13196. /// value:
  13197. /// 0 = disabled
  13198. /// 1 = enabled
  13199. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13200. {
  13201. bool flag = RFIFOB(fd,6) ? true : false;
  13202. sd->status.allow_party = flag;
  13203. clif_partytickack(sd, flag);
  13204. }
  13205. /// Questlog System [Kevin] [Inkfish]
  13206. ///
  13207. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13208. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13209. void clif_quest_send_list(struct map_session_data * sd)
  13210. {
  13211. int fd = sd->fd;
  13212. int i;
  13213. int len = sd->avail_quests*5+8;
  13214. WFIFOHEAD(fd,len);
  13215. WFIFOW(fd, 0) = 0x2b1;
  13216. WFIFOW(fd, 2) = len;
  13217. WFIFOL(fd, 4) = sd->avail_quests;
  13218. for( i = 0; i < sd->avail_quests; i++ ) {
  13219. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  13220. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  13221. }
  13222. WFIFOSET(fd, len);
  13223. }
  13224. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13225. /// 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
  13226. void clif_quest_send_mission(struct map_session_data * sd)
  13227. {
  13228. int fd = sd->fd;
  13229. int i, j;
  13230. int len = sd->avail_quests*104+8;
  13231. struct mob_db *mob;
  13232. WFIFOHEAD(fd, len);
  13233. WFIFOW(fd, 0) = 0x2b2;
  13234. WFIFOW(fd, 2) = len;
  13235. WFIFOL(fd, 4) = sd->avail_quests;
  13236. for( i = 0; i < sd->avail_quests; i++ ) {
  13237. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13238. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13239. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13240. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13241. WFIFOW(fd, i*104+20) = qi->num_objectives;
  13242. for( j = 0 ; j < qi->num_objectives; j++ ) {
  13243. WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
  13244. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13245. mob = mob_db(qi->mob[j]);
  13246. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13247. }
  13248. }
  13249. WFIFOSET(fd, len);
  13250. }
  13251. /// Notification about a new quest (ZC_ADD_QUEST).
  13252. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13253. void clif_quest_add(struct map_session_data * sd, struct quest * qd)
  13254. {
  13255. int fd = sd->fd;
  13256. int i;
  13257. struct quest_db *qi = quest_search(qd->quest_id);
  13258. WFIFOHEAD(fd, packet_len(0x2b3));
  13259. WFIFOW(fd, 0) = 0x2b3;
  13260. WFIFOL(fd, 2) = qd->quest_id;
  13261. WFIFOB(fd, 6) = qd->state;
  13262. WFIFOB(fd, 7) = qi->time;
  13263. WFIFOL(fd, 11) = qd->time;
  13264. WFIFOW(fd, 15) = qi->num_objectives;
  13265. for( i = 0; i < qi->num_objectives; i++ ) {
  13266. struct mob_db *mob;
  13267. WFIFOL(fd, i*30+17) = qi->mob[i];
  13268. WFIFOW(fd, i*30+21) = qd->count[i];
  13269. mob = mob_db(qi->mob[i]);
  13270. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13271. }
  13272. WFIFOSET(fd, packet_len(0x2b3));
  13273. }
  13274. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13275. /// 02b4 <quest id>.L
  13276. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  13277. {
  13278. int fd = sd->fd;
  13279. WFIFOHEAD(fd, packet_len(0x2b4));
  13280. WFIFOW(fd, 0) = 0x2b4;
  13281. WFIFOL(fd, 2) = quest_id;
  13282. WFIFOSET(fd, packet_len(0x2b4));
  13283. }
  13284. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13285. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13286. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd)
  13287. {
  13288. int fd = sd->fd;
  13289. int i;
  13290. struct quest_db *qi = quest_search(qd->quest_id);
  13291. int len = qi->num_objectives * 12 + 6;
  13292. WFIFOHEAD(fd, len);
  13293. WFIFOW(fd, 0) = 0x2b5;
  13294. WFIFOW(fd, 2) = len;
  13295. WFIFOW(fd, 4) = qi->num_objectives;
  13296. for( i = 0; i < qi->num_objectives; i++ ) {
  13297. WFIFOL(fd, i*12+6) = qd->quest_id;
  13298. WFIFOL(fd, i*12+10) = qi->mob[i];
  13299. WFIFOW(fd, i*12+14) = qi->count[i];
  13300. WFIFOW(fd, i*12+16) = qd->count[i];
  13301. }
  13302. WFIFOSET(fd, len);
  13303. }
  13304. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13305. /// 02b6 <quest id>.L <active>.B
  13306. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  13307. {
  13308. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13309. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13310. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13311. }
  13312. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13313. /// 02b7 <quest id>.L <active>.B
  13314. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  13315. {
  13316. int fd = sd->fd;
  13317. WFIFOHEAD(fd, packet_len(0x2b7));
  13318. WFIFOW(fd, 0) = 0x2b7;
  13319. WFIFOL(fd, 2) = quest_id;
  13320. WFIFOB(fd, 6) = active;
  13321. WFIFOSET(fd, packet_len(0x2b7));
  13322. }
  13323. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13324. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13325. /// effect:
  13326. /// 0 = none
  13327. /// 1 = exclamation mark icon
  13328. /// 2 = question mark icon
  13329. /// type:
  13330. /// 0 = yellow
  13331. /// 1 = orange
  13332. /// 2 = green
  13333. /// 3 = purple
  13334. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13335. {
  13336. #if PACKETVER >= 20090218
  13337. int fd = sd->fd;
  13338. WFIFOHEAD(fd, packet_len(0x446));
  13339. WFIFOW(fd, 0) = 0x446;
  13340. WFIFOL(fd, 2) = bl->id;
  13341. WFIFOW(fd, 6) = bl->x;
  13342. WFIFOW(fd, 8) = bl->y;
  13343. WFIFOW(fd, 10) = state;
  13344. WFIFOW(fd, 12) = color;
  13345. WFIFOSET(fd, packet_len(0x446));
  13346. #endif
  13347. }
  13348. /// Mercenary System
  13349. ///
  13350. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13351. /// 02a2 <var id>.W <value>.L
  13352. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13353. {
  13354. struct mercenary_data *md;
  13355. struct status_data *status;
  13356. int fd;
  13357. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13358. return;
  13359. fd = sd->fd;
  13360. status = &md->battle_status;
  13361. WFIFOHEAD(fd,packet_len(0x2a2));
  13362. WFIFOW(fd,0) = 0x2a2;
  13363. WFIFOW(fd,2) = type;
  13364. switch( type ) {
  13365. case SP_ATK1:
  13366. {
  13367. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13368. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13369. }
  13370. break;
  13371. case SP_MATK1:
  13372. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13373. break;
  13374. case SP_HIT:
  13375. WFIFOL(fd,4) = status->hit;
  13376. break;
  13377. case SP_CRITICAL:
  13378. WFIFOL(fd,4) = status->cri/10;
  13379. break;
  13380. case SP_DEF1:
  13381. WFIFOL(fd,4) = status->def;
  13382. break;
  13383. case SP_MDEF1:
  13384. WFIFOL(fd,4) = status->mdef;
  13385. break;
  13386. case SP_MERCFLEE:
  13387. WFIFOL(fd,4) = status->flee;
  13388. break;
  13389. case SP_ASPD:
  13390. WFIFOL(fd,4) = status->amotion;
  13391. break;
  13392. case SP_HP:
  13393. WFIFOL(fd,4) = status->hp;
  13394. break;
  13395. case SP_MAXHP:
  13396. WFIFOL(fd,4) = status->max_hp;
  13397. break;
  13398. case SP_SP:
  13399. WFIFOL(fd,4) = status->sp;
  13400. break;
  13401. case SP_MAXSP:
  13402. WFIFOL(fd,4) = status->max_sp;
  13403. break;
  13404. case SP_MERCKILLS:
  13405. WFIFOL(fd,4) = md->mercenary.kill_count;
  13406. break;
  13407. case SP_MERCFAITH:
  13408. WFIFOL(fd,4) = mercenary_get_faith(md);
  13409. break;
  13410. }
  13411. WFIFOSET(fd,packet_len(0x2a2));
  13412. }
  13413. /// Mercenary base status data (ZC_MER_INIT).
  13414. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13415. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13416. /// <calls>.L <kills>.L <atk range>.W
  13417. void clif_mercenary_info(struct map_session_data *sd)
  13418. {
  13419. int fd;
  13420. struct mercenary_data *md;
  13421. struct status_data *status;
  13422. int atk;
  13423. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13424. return;
  13425. fd = sd->fd;
  13426. status = &md->battle_status;
  13427. WFIFOHEAD(fd,packet_len(0x29b));
  13428. WFIFOW(fd,0) = 0x29b;
  13429. WFIFOL(fd,2) = md->bl.id;
  13430. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13431. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13432. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13433. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13434. WFIFOW(fd,10) = status->hit;
  13435. WFIFOW(fd,12) = status->cri/10;
  13436. WFIFOW(fd,14) = status->def;
  13437. WFIFOW(fd,16) = status->mdef;
  13438. WFIFOW(fd,18) = status->flee;
  13439. WFIFOW(fd,20) = status->amotion;
  13440. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13441. WFIFOW(fd,46) = md->db->lv;
  13442. WFIFOL(fd,48) = status->hp;
  13443. WFIFOL(fd,52) = status->max_hp;
  13444. WFIFOL(fd,56) = status->sp;
  13445. WFIFOL(fd,60) = status->max_sp;
  13446. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13447. WFIFOW(fd,68) = mercenary_get_faith(md);
  13448. WFIFOL(fd,70) = mercenary_get_calls(md);
  13449. WFIFOL(fd,74) = md->mercenary.kill_count;
  13450. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13451. WFIFOSET(fd,packet_len(0x29b));
  13452. }
  13453. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13454. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13455. void clif_mercenary_skillblock(struct map_session_data *sd)
  13456. {
  13457. struct mercenary_data *md;
  13458. int fd, i, len = 4;
  13459. if( sd == NULL || (md = sd->md) == NULL )
  13460. return;
  13461. fd = sd->fd;
  13462. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13463. WFIFOW(fd,0) = 0x29d;
  13464. for( i = 0; i < MAX_MERCSKILL; i++ )
  13465. {
  13466. uint16 id;
  13467. short idx = -1;
  13468. if( (id = md->db->skill[i].id) == 0 )
  13469. continue;
  13470. if ((idx = mercenary_skill_get_index(id)) == -1)
  13471. continue;
  13472. WFIFOW(fd,len) = id;
  13473. WFIFOL(fd,len+2) = skill_get_inf(id);
  13474. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13475. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13476. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv);
  13477. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13478. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13479. len += 37;
  13480. }
  13481. WFIFOW(fd,2) = len;
  13482. WFIFOSET(fd,len);
  13483. }
  13484. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13485. /// 029f <command>.B
  13486. /// 1 = mercenary information
  13487. /// 2 = delete
  13488. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13489. {
  13490. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13491. if( sd->md == NULL )
  13492. return;
  13493. if( option == 2 ) mercenary_delete(sd->md, 2);
  13494. }
  13495. /// Mercenary Message
  13496. /// message:
  13497. /// 0 = Mercenary soldier's duty hour is over.
  13498. /// 1 = Your mercenary soldier has been killed.
  13499. /// 2 = Your mercenary soldier has been fired.
  13500. /// 3 = Your mercenary soldier has ran away.
  13501. void clif_mercenary_message(struct map_session_data* sd, int message){
  13502. clif_msg(sd, MERC_MSG_BASE + message);
  13503. }
  13504. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13505. /// 0298 <name id>.W <seconds>.L
  13506. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13507. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13508. WFIFOHEAD(fd,packet_len(0x298));
  13509. WFIFOW(fd,0) = 0x298;
  13510. WFIFOW(fd,2) = nameid;
  13511. WFIFOL(fd,4) = seconds;
  13512. WFIFOSET(fd,packet_len(0x298));
  13513. }
  13514. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13515. /// 0299 <index>.W <name id>.W
  13516. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13517. { // '<ItemName>' item has been deleted from the Inventory
  13518. WFIFOHEAD(fd,packet_len(0x299));
  13519. WFIFOW(fd,0) = 0x299;
  13520. WFIFOW(fd,2) = index+2;
  13521. WFIFOW(fd,4) = nameid;
  13522. WFIFOSET(fd,packet_len(0x299));
  13523. }
  13524. /// Book Reading (ZC_READ_BOOK).
  13525. /// 0294 <book id>.L <page>.L
  13526. void clif_readbook(int fd, int book_id, int page)
  13527. {
  13528. WFIFOHEAD(fd,packet_len(0x294));
  13529. WFIFOW(fd,0) = 0x294;
  13530. WFIFOL(fd,2) = book_id;
  13531. WFIFOL(fd,6) = page;
  13532. WFIFOSET(fd,packet_len(0x294));
  13533. }
  13534. /// Battlegrounds
  13535. ///
  13536. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13537. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13538. void clif_bg_hp(struct map_session_data *sd)
  13539. {
  13540. unsigned char buf[34];
  13541. const int cmd = 0x2e0;
  13542. nullpo_retv(sd);
  13543. WBUFW(buf,0) = cmd;
  13544. WBUFL(buf,2) = sd->status.account_id;
  13545. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13546. if( sd->battle_status.max_hp > INT16_MAX )
  13547. { // To correctly display the %hp bar. [Skotlex]
  13548. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13549. WBUFW(buf,32) = 100;
  13550. }
  13551. else
  13552. {
  13553. WBUFW(buf,30) = sd->battle_status.hp;
  13554. WBUFW(buf,32) = sd->battle_status.max_hp;
  13555. }
  13556. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13557. }
  13558. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13559. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13560. void clif_bg_xy(struct map_session_data *sd)
  13561. {
  13562. unsigned char buf[36];
  13563. nullpo_retv(sd);
  13564. WBUFW(buf,0)=0x2df;
  13565. WBUFL(buf,2)=sd->status.account_id;
  13566. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13567. WBUFW(buf,30)=sd->status.class_;
  13568. WBUFW(buf,32)=sd->bl.x;
  13569. WBUFW(buf,34)=sd->bl.y;
  13570. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13571. }
  13572. void clif_bg_xy_remove(struct map_session_data *sd)
  13573. {
  13574. unsigned char buf[36];
  13575. nullpo_retv(sd);
  13576. WBUFW(buf,0)=0x2df;
  13577. WBUFL(buf,2)=sd->status.account_id;
  13578. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13579. WBUFW(buf,30)=0;
  13580. WBUFW(buf,32)=-1;
  13581. WBUFW(buf,34)=-1;
  13582. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13583. }
  13584. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13585. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13586. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13587. {
  13588. struct map_session_data *sd;
  13589. unsigned char *buf;
  13590. if( (sd = bg_getavailablesd(bg)) == NULL )
  13591. return;
  13592. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13593. WBUFW(buf,0) = 0x2dc;
  13594. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13595. WBUFL(buf,4) = src_id;
  13596. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13597. memcpy(WBUFP(buf,32), mes, len);
  13598. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13599. if( buf )
  13600. aFree(buf);
  13601. }
  13602. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13603. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13604. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13605. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13606. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13607. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13608. char *name, *message;
  13609. int namelen, messagelen;
  13610. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13611. return;
  13612. if( is_atcommand(fd, sd, message, 1) )
  13613. return;
  13614. if (sd->sc.cant.chat)
  13615. return; //no "chatting" while muted.
  13616. if( battle_config.min_chat_delay ) {
  13617. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13618. return;
  13619. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13620. }
  13621. if (battle_config.idletime_option&IDLE_CHAT)
  13622. sd->idletime = last_tick;
  13623. bg_send_message(sd, text, textlen);
  13624. }
  13625. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13626. /// 02de <camp A points>.W <camp B points>.W
  13627. void clif_bg_updatescore(int16 m)
  13628. {
  13629. struct block_list bl;
  13630. unsigned char buf[6];
  13631. bl.id = 0;
  13632. bl.type = BL_NUL;
  13633. bl.m = m;
  13634. WBUFW(buf,0) = 0x2de;
  13635. WBUFW(buf,2) = map[m].bgscore_lion;
  13636. WBUFW(buf,4) = map[m].bgscore_eagle;
  13637. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13638. }
  13639. void clif_bg_updatescore_single(struct map_session_data *sd)
  13640. {
  13641. int fd;
  13642. nullpo_retv(sd);
  13643. fd = sd->fd;
  13644. WFIFOHEAD(fd,packet_len(0x2de));
  13645. WFIFOW(fd,0) = 0x2de;
  13646. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13647. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13648. WFIFOSET(fd,packet_len(0x2de));
  13649. }
  13650. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13651. /// 02dd <account id>.L <name>.24B <camp>.W
  13652. void clif_sendbgemblem_area(struct map_session_data *sd)
  13653. {
  13654. unsigned char buf[33];
  13655. nullpo_retv(sd);
  13656. WBUFW(buf, 0) = 0x2dd;
  13657. WBUFL(buf,2) = sd->bl.id;
  13658. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13659. WBUFW(buf,30) = sd->bg_id;
  13660. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13661. }
  13662. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13663. {
  13664. nullpo_retv(sd);
  13665. WFIFOHEAD(fd,32);
  13666. WFIFOW(fd,0) = 0x2dd;
  13667. WFIFOL(fd,2) = sd->bl.id;
  13668. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13669. WFIFOW(fd,30) = sd->bg_id;
  13670. WFIFOSET(fd,packet_len(0x2dd));
  13671. }
  13672. /// Custom Fonts (ZC_NOTIFY_FONT).
  13673. /// 02ef <account_id>.L <font id>.W
  13674. void clif_font(struct map_session_data *sd)
  13675. {
  13676. #if PACKETVER >= 20080102
  13677. unsigned char buf[8];
  13678. nullpo_retv(sd);
  13679. WBUFW(buf,0) = 0x2ef;
  13680. WBUFL(buf,2) = sd->bl.id;
  13681. WBUFW(buf,6) = sd->status.font;
  13682. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13683. #endif
  13684. }
  13685. /*==========================================
  13686. * Notifies party members of instance change
  13687. *------------------------------------------*/
  13688. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13689. {
  13690. #if PACKETVER >= 20071128
  13691. unsigned char buf[65];
  13692. if(!sd) return;
  13693. WBUFW(buf,0) = 0x2cb;
  13694. memcpy( WBUFP(buf,2), name, 62 );
  13695. WBUFW(buf,63) = num;
  13696. if(flag) // A timer has changed or been added
  13697. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13698. else // No notification
  13699. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13700. #endif
  13701. return;
  13702. }
  13703. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13704. {
  13705. #if PACKETVER >= 20071128
  13706. unsigned char buf[4];
  13707. if(!sd) return;
  13708. WBUFW(buf,0) = 0x2cc;
  13709. WBUFW(buf,2) = num;
  13710. if(flag) // A timer has changed or been added
  13711. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13712. else // No notification
  13713. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13714. #endif
  13715. return;
  13716. }
  13717. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13718. {
  13719. #if PACKETVER >= 20071128
  13720. unsigned char buf[71];
  13721. if(!sd) return; //party_getavailablesd can return NULL
  13722. WBUFW(buf,0) = 0x2cd;
  13723. memcpy( WBUFP(buf,2), name, 62 );
  13724. WBUFL(buf,63) = limit1;
  13725. WBUFL(buf,67) = limit2;
  13726. if(flag) // A timer has changed or been added
  13727. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13728. else // No notification
  13729. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13730. #endif
  13731. return;
  13732. }
  13733. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13734. {
  13735. #if PACKETVER >= 20071128
  13736. unsigned char buf[10];
  13737. if(!sd) return;
  13738. WBUFW(buf,0) = 0x2ce;
  13739. WBUFL(buf,2) = type;
  13740. WBUFL(buf,6) = limit;
  13741. if(flag) // A timer has changed or been added
  13742. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13743. else // No notification
  13744. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13745. #endif
  13746. return;
  13747. }
  13748. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13749. /// 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
  13750. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13751. {
  13752. #if PACKETVER >= 20071002
  13753. unsigned char buf[22];
  13754. struct item_data* id = itemdb_search(item_data->nameid);
  13755. WBUFW(buf,0) = 0x2b8;
  13756. WBUFL(buf,2) = sd->status.account_id;
  13757. WBUFW(buf,6) = item_data->nameid;
  13758. WBUFB(buf,8) = item_data->identify;
  13759. WBUFB(buf,9) = item_data->attribute;
  13760. WBUFB(buf,10) = item_data->refine;
  13761. clif_addcards(WBUFP(buf,11), item_data);
  13762. WBUFW(buf,19) = id->equip; // equip location
  13763. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13764. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13765. #endif
  13766. }
  13767. /// Display gained exp (ZC_NOTIFY_EXP).
  13768. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13769. /// var id:
  13770. /// SP_BASEEXP, SP_JOBEXP
  13771. /// exp type:
  13772. /// 0 = normal exp gain/loss
  13773. /// 1 = quest exp gain/loss
  13774. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13775. {
  13776. int fd;
  13777. nullpo_retv(sd);
  13778. fd = sd->fd;
  13779. WFIFOHEAD(fd, packet_len(0x7f6));
  13780. WFIFOW(fd,0) = 0x7f6;
  13781. WFIFOL(fd,2) = sd->bl.id;
  13782. WFIFOL(fd,6) = exp;
  13783. WFIFOW(fd,10) = type;
  13784. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13785. WFIFOSET(fd,packet_len(0x7f6));
  13786. }
  13787. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13788. /// type:
  13789. /// 0 = Displays 'value' for 5 seconds.
  13790. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13791. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13792. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13793. /// value:
  13794. /// 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).
  13795. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13796. {
  13797. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13798. WFIFOW(sd->fd,0) = 0x1b1;
  13799. WFIFOB(sd->fd,2) = type;
  13800. WFIFOL(sd->fd,3) = value;
  13801. WFIFOSET(sd->fd, packet_len(0x1b1));
  13802. }
  13803. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13804. /// 021d <state>.L
  13805. /// state:
  13806. /// 0 = Full effects
  13807. /// 1 = Reduced effects
  13808. ///
  13809. /// NOTE: The state is used on Aegis for sending skill unit packet
  13810. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13811. /// whenever possible. Due to the way the decision check is
  13812. /// constructed, this state tracking was rendered useless,
  13813. /// as the only skill unit, that is sent with 0x1c9 is
  13814. /// Graffiti.
  13815. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13816. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13817. sd->state.lesseffect = ( isLess != 0 );
  13818. }
  13819. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13820. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13821. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13822. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13823. int type = RFIFOL(fd,info->pos[1]);
  13824. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13825. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13826. if( sd->state.trading || sd->npc_shopid )
  13827. return;
  13828. if( flag == 0 || n == 0) {
  13829. clif_menuskill_clear(sd);
  13830. return; // Canceled by player.
  13831. }
  13832. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13833. clif_menuskill_clear(sd);
  13834. return; // Prevent hacking.
  13835. }
  13836. switch( type ) {
  13837. case 0: // Change Material
  13838. skill_changematerial(sd,n,item_list);
  13839. break;
  13840. case 1: // Level 1: Pure to Rough
  13841. case 2: // Level 2: Rough to Pure
  13842. skill_elementalanalysis(sd,n,type,item_list);
  13843. break;
  13844. }
  13845. clif_menuskill_clear(sd);
  13846. return;
  13847. }
  13848. /*==========================================
  13849. * Elemental System
  13850. *==========================================*/
  13851. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13852. struct elemental_data *ed;
  13853. struct status_data *status;
  13854. int fd;
  13855. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  13856. return;
  13857. fd = sd->fd;
  13858. status = &ed->battle_status;
  13859. WFIFOHEAD(fd,8);
  13860. WFIFOW(fd,0) = 0x81e;
  13861. WFIFOW(fd,2) = type;
  13862. switch( type ) {
  13863. case SP_HP:
  13864. WFIFOL(fd,4) = status->hp;
  13865. break;
  13866. case SP_MAXHP:
  13867. WFIFOL(fd,4) = status->max_hp;
  13868. break;
  13869. case SP_SP:
  13870. WFIFOL(fd,4) = status->sp;
  13871. break;
  13872. case SP_MAXSP:
  13873. WFIFOL(fd,4) = status->max_sp;
  13874. break;
  13875. }
  13876. WFIFOSET(fd,8);
  13877. }
  13878. void clif_elemental_info(struct map_session_data *sd) {
  13879. int fd;
  13880. struct elemental_data *ed;
  13881. struct status_data *status;
  13882. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  13883. return;
  13884. fd = sd->fd;
  13885. status = &ed->battle_status;
  13886. WFIFOHEAD(fd,22);
  13887. WFIFOW(fd, 0) = 0x81d;
  13888. WFIFOL(fd, 2) = ed->bl.id;
  13889. WFIFOL(fd, 6) = status->hp;
  13890. WFIFOL(fd,10) = status->max_hp;
  13891. WFIFOL(fd,14) = status->sp;
  13892. WFIFOL(fd,18) = status->max_sp;
  13893. WFIFOSET(fd,22);
  13894. }
  13895. /// Buying Store System
  13896. ///
  13897. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13898. /// 0810 <slots>.B
  13899. void clif_buyingstore_open(struct map_session_data* sd)
  13900. {
  13901. int fd = sd->fd;
  13902. WFIFOHEAD(fd,packet_len(0x810));
  13903. WFIFOW(fd,0) = 0x810;
  13904. WFIFOB(fd,2) = sd->buyingstore.slots;
  13905. WFIFOSET(fd,packet_len(0x810));
  13906. }
  13907. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13908. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13909. /// result:
  13910. /// 0 = cancel
  13911. /// 1 = open
  13912. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13913. {
  13914. const unsigned int blocksize = 8;
  13915. uint8* itemlist;
  13916. char storename[MESSAGE_SIZE];
  13917. unsigned char result;
  13918. int zenylimit;
  13919. unsigned int count, packet_len;
  13920. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13921. packet_len = RFIFOW(fd,info->pos[0]);
  13922. // TODO: Make this check global for all variable length packets.
  13923. if( packet_len < 89 )
  13924. {// minimum packet length
  13925. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13926. return;
  13927. }
  13928. zenylimit = RFIFOL(fd,info->pos[1]);
  13929. result = RFIFOL(fd,info->pos[2]);
  13930. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13931. itemlist = RFIFOP(fd,info->pos[4]);
  13932. // so that buyingstore_create knows, how many elements it has access to
  13933. packet_len-= info->pos[4];
  13934. if( packet_len%blocksize )
  13935. {
  13936. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13937. return;
  13938. }
  13939. count = packet_len/blocksize;
  13940. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  13941. }
  13942. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13943. /// 0812 <result>.W <total weight>.L
  13944. /// result:
  13945. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13946. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13947. /// 8 = "No sale (purchase) information available." (0x705)
  13948. /// ? = nothing
  13949. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13950. {
  13951. int fd = sd->fd;
  13952. WFIFOHEAD(fd,packet_len(0x812));
  13953. WFIFOW(fd,0) = 0x812;
  13954. WFIFOW(fd,2) = result;
  13955. WFIFOL(fd,4) = weight;
  13956. WFIFOSET(fd,packet_len(0x812));
  13957. }
  13958. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13959. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13960. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13961. {
  13962. int fd = sd->fd;
  13963. unsigned int i;
  13964. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13965. WFIFOW(fd,0) = 0x813;
  13966. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13967. WFIFOL(fd,4) = sd->bl.id;
  13968. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13969. for( i = 0; i < sd->buyingstore.slots; i++ )
  13970. {
  13971. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13972. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13973. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13974. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13975. }
  13976. WFIFOSET(fd,WFIFOW(fd,2));
  13977. }
  13978. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13979. /// 0814 <account id>.L <store name>.80B
  13980. void clif_buyingstore_entry(struct map_session_data* sd)
  13981. {
  13982. uint8 buf[86];
  13983. WBUFW(buf,0) = 0x814;
  13984. WBUFL(buf,2) = sd->bl.id;
  13985. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13986. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13987. }
  13988. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13989. {
  13990. int fd = sd->fd;
  13991. WFIFOHEAD(fd,packet_len(0x814));
  13992. WFIFOW(fd,0) = 0x814;
  13993. WFIFOL(fd,2) = pl_sd->bl.id;
  13994. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13995. WFIFOSET(fd,packet_len(0x814));
  13996. }
  13997. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13998. /// 0815
  13999. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14000. {
  14001. buyingstore_close(sd);
  14002. }
  14003. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14004. /// 0816 <account id>.L
  14005. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14006. {
  14007. uint8 buf[6];
  14008. WBUFW(buf,0) = 0x816;
  14009. WBUFL(buf,2) = sd->bl.id;
  14010. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14011. }
  14012. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14013. {
  14014. int fd = sd->fd;
  14015. WFIFOHEAD(fd,packet_len(0x816));
  14016. WFIFOW(fd,0) = 0x816;
  14017. WFIFOL(fd,2) = pl_sd->bl.id;
  14018. WFIFOSET(fd,packet_len(0x816));
  14019. }
  14020. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14021. /// 0817 <account id>.L
  14022. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14023. {
  14024. uint32 account_id;
  14025. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14026. buyingstore_open(sd, account_id);
  14027. }
  14028. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14029. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14030. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14031. {
  14032. int fd = sd->fd;
  14033. unsigned int i;
  14034. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14035. WFIFOW(fd,0) = 0x818;
  14036. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14037. WFIFOL(fd,4) = pl_sd->bl.id;
  14038. WFIFOL(fd,8) = pl_sd->buyer_id;
  14039. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14040. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14041. {
  14042. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14043. 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.
  14044. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14045. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14046. }
  14047. WFIFOSET(fd,WFIFOW(fd,2));
  14048. }
  14049. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14050. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14051. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14052. {
  14053. const unsigned int blocksize = 6;
  14054. uint8* itemlist;
  14055. uint32 account_id;
  14056. unsigned int count, packet_len, buyer_id;
  14057. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14058. packet_len = RFIFOW(fd,info->pos[0]);
  14059. if( packet_len < 12 )
  14060. {// minimum packet length
  14061. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14062. return;
  14063. }
  14064. account_id = RFIFOL(fd,info->pos[1]);
  14065. buyer_id = RFIFOL(fd,info->pos[2]);
  14066. itemlist = RFIFOP(fd,info->pos[3]);
  14067. // so that buyingstore_trade knows, how many elements it has access to
  14068. packet_len-= info->pos[3];
  14069. if( packet_len%blocksize )
  14070. {
  14071. 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);
  14072. return;
  14073. }
  14074. count = packet_len/blocksize;
  14075. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14076. }
  14077. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14078. /// 081a <result>.W
  14079. /// result:
  14080. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14081. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14082. /// ? = nothing
  14083. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14084. {
  14085. int fd = sd->fd;
  14086. WFIFOHEAD(fd,packet_len(0x81a));
  14087. WFIFOW(fd,0) = 0x81a;
  14088. WFIFOW(fd,2) = result;
  14089. WFIFOSET(fd,packet_len(0x81a));
  14090. }
  14091. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  14092. /// 081b <name id>.W <amount>.W <limit zeny>.L
  14093. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  14094. {
  14095. int fd = sd->fd;
  14096. WFIFOHEAD(fd,packet_len(0x81b));
  14097. WFIFOW(fd,0) = 0x81b;
  14098. WFIFOW(fd,2) = nameid;
  14099. WFIFOW(fd,4) = amount; // amount of nameid received
  14100. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  14101. WFIFOSET(fd,packet_len(0x81b));
  14102. }
  14103. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14104. /// 081c <index>.W <amount>.W <price>.L
  14105. /// message:
  14106. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14107. ///
  14108. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14109. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14110. {
  14111. int fd = sd->fd;
  14112. WFIFOHEAD(fd,packet_len(0x81c));
  14113. WFIFOW(fd,0) = 0x81c;
  14114. WFIFOW(fd,2) = index+2;
  14115. WFIFOW(fd,4) = amount;
  14116. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14117. WFIFOSET(fd,packet_len(0x81c));
  14118. }
  14119. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14120. /// 0824 <result>.W <name id>.W
  14121. /// result:
  14122. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14123. /// 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)
  14124. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14125. /// ? = nothing
  14126. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14127. {
  14128. int fd = sd->fd;
  14129. WFIFOHEAD(fd,packet_len(0x824));
  14130. WFIFOW(fd,0) = 0x824;
  14131. WFIFOW(fd,2) = result;
  14132. WFIFOW(fd,4) = nameid;
  14133. WFIFOSET(fd,packet_len(0x824));
  14134. }
  14135. /// Search Store Info System
  14136. ///
  14137. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14138. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14139. /// type:
  14140. /// 0 = Vending
  14141. /// 1 = Buying Store
  14142. ///
  14143. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14144. /// amount of card slots. If the client does not know about the item it
  14145. /// cannot be searched.
  14146. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14147. {
  14148. const unsigned int blocksize = 2;
  14149. const uint8* itemlist;
  14150. const uint8* cardlist;
  14151. unsigned char type;
  14152. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14153. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14154. packet_len = RFIFOW(fd,info->pos[0]);
  14155. if( packet_len < 15 )
  14156. {// minimum packet length
  14157. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14158. return;
  14159. }
  14160. type = RFIFOB(fd,info->pos[1]);
  14161. max_price = RFIFOL(fd,info->pos[2]);
  14162. min_price = RFIFOL(fd,info->pos[3]);
  14163. item_count = RFIFOB(fd,info->pos[4]);
  14164. card_count = RFIFOB(fd,info->pos[5]);
  14165. itemlist = RFIFOP(fd,info->pos[6]);
  14166. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14167. // check, if there is enough data for the claimed count of items
  14168. packet_len-= info->pos[6];
  14169. if( packet_len%blocksize )
  14170. {
  14171. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14172. return;
  14173. }
  14174. count = packet_len/blocksize;
  14175. if( count < item_count+card_count )
  14176. {
  14177. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14178. return;
  14179. }
  14180. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14181. }
  14182. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14183. /// 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 }*
  14184. /// is first page:
  14185. /// 0 = appends to existing results
  14186. /// 1 = clears previous results before displaying this result set
  14187. /// is next page:
  14188. /// 0 = no "next" label
  14189. /// 1 = "next" label to retrieve more results
  14190. void clif_search_store_info_ack(struct map_session_data* sd)
  14191. {
  14192. const unsigned int blocksize = MESSAGE_SIZE+26;
  14193. int fd = sd->fd;
  14194. unsigned int i, start, end;
  14195. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14196. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14197. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14198. WFIFOW(fd,0) = 0x836;
  14199. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14200. WFIFOB(fd,4) = !sd->searchstore.pages;
  14201. WFIFOB(fd,5) = searchstore_querynext(sd);
  14202. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14203. for( i = start; i < end; i++ ) {
  14204. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14205. struct item it;
  14206. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14207. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14208. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14209. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14210. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14211. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14212. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14213. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14214. // make-up an item for clif_addcards
  14215. memset(&it, 0, sizeof(it));
  14216. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14217. it.nameid = ssitem->nameid;
  14218. it.amount = ssitem->amount;
  14219. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14220. }
  14221. WFIFOSET(fd,WFIFOW(fd,2));
  14222. }
  14223. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14224. /// 0837 <reason>.B
  14225. /// reason:
  14226. /// 0 = "No matching stores were found." (0x70b)
  14227. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14228. /// 2 = "You cannot search anymore." (0x706)
  14229. /// 3 = "You cannot search yet." (0x708)
  14230. /// 4 = "No sale (purchase) information available." (0x705)
  14231. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14232. {
  14233. int fd = sd->fd;
  14234. WFIFOHEAD(fd,packet_len(0x837));
  14235. WFIFOW(fd,0) = 0x837;
  14236. WFIFOB(fd,2) = reason;
  14237. WFIFOSET(fd,packet_len(0x837));
  14238. }
  14239. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14240. /// 0838
  14241. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14242. {
  14243. searchstore_next(sd);
  14244. }
  14245. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14246. /// 083a <type>.W <remaining uses>.B
  14247. /// type:
  14248. /// 0 = Search Stores
  14249. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14250. void clif_open_search_store_info(struct map_session_data* sd)
  14251. {
  14252. int fd = sd->fd;
  14253. WFIFOHEAD(fd,packet_len(0x83a));
  14254. WFIFOW(fd,0) = 0x83a;
  14255. WFIFOW(fd,2) = sd->searchstore.effect;
  14256. #if PACKETVER > 20100701
  14257. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14258. #endif
  14259. WFIFOSET(fd,packet_len(0x83a));
  14260. }
  14261. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14262. /// 083b
  14263. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14264. {
  14265. searchstore_close(sd);
  14266. }
  14267. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14268. /// 083c <account id>.L <store id>.L <nameid>.W
  14269. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14270. {
  14271. unsigned short nameid;
  14272. uint32 account_id, store_id;
  14273. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14274. account_id = RFIFOL(fd,info->pos[0]);
  14275. store_id = RFIFOL(fd,info->pos[1]);
  14276. nameid = RFIFOW(fd,info->pos[2]);
  14277. searchstore_click(sd, account_id, store_id, nameid);
  14278. }
  14279. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14280. /// 083d <xPos>.W <yPos>.W
  14281. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14282. {
  14283. int fd = sd->fd;
  14284. WFIFOHEAD(fd,packet_len(0x83d));
  14285. WFIFOW(fd,0) = 0x83d;
  14286. WFIFOW(fd,2) = x;
  14287. WFIFOW(fd,4) = y;
  14288. WFIFOSET(fd,packet_len(0x83d));
  14289. }
  14290. /// Parse function for packet debugging.
  14291. void clif_parse_debug(int fd,struct map_session_data *sd)
  14292. {
  14293. int cmd, packet_len;
  14294. // clif_parse ensures, that there is at least 2 bytes of data
  14295. cmd = RFIFOW(fd,0);
  14296. if( sd ) {
  14297. packet_len = packet_db[sd->packet_ver][cmd].len;
  14298. if( packet_len == 0 )
  14299. {// unknown
  14300. packet_len = RFIFOREST(fd);
  14301. }
  14302. else if( packet_len == -1 )
  14303. {// variable length
  14304. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14305. }
  14306. 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);
  14307. }
  14308. else
  14309. {
  14310. packet_len = RFIFOREST(fd);
  14311. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14312. }
  14313. ShowDump(RFIFOP(fd,0), packet_len);
  14314. }
  14315. /*==========================================
  14316. * Server tells client to display a window similar to Magnifier (item) one
  14317. * Server populates the window with avilable elemental converter options according to player's inventory
  14318. *------------------------------------------*/
  14319. int clif_elementalconverter_list(struct map_session_data *sd) {
  14320. int i,c,view,fd;
  14321. nullpo_ret(sd);
  14322. /// Main client packet processing function
  14323. fd=sd->fd;
  14324. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14325. WFIFOW(fd, 0)=0x1ad;
  14326. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14327. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14328. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14329. WFIFOW(fd,c*2+ 4)= view;
  14330. else
  14331. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14332. c++;
  14333. }
  14334. }
  14335. WFIFOW(fd,2) = c*2+4;
  14336. WFIFOSET(fd, WFIFOW(fd,2));
  14337. if (c > 0) {
  14338. sd->menuskill_id = SA_CREATECON;
  14339. sd->menuskill_val = c;
  14340. }
  14341. return 0;
  14342. }
  14343. /**
  14344. * Rune Knight
  14345. **/
  14346. void clif_millenniumshield(struct block_list *bl, short shields) {
  14347. #if PACKETVER >= 20081217
  14348. unsigned char buf[10];
  14349. WBUFW(buf,0) = 0x440;
  14350. WBUFL(buf,2) = bl->id;
  14351. WBUFW(buf,6) = shields;
  14352. WBUFW(buf,8) = 0;
  14353. clif_send(buf,packet_len(0x440),bl,AREA);
  14354. #endif
  14355. }
  14356. /**
  14357. * Warlock
  14358. **/
  14359. /*==========================================
  14360. * Spellbook list [LimitLine/3CeAM]
  14361. *------------------------------------------*/
  14362. int clif_spellbook_list(struct map_session_data *sd)
  14363. {
  14364. int i, c;
  14365. int fd;
  14366. nullpo_ret(sd);
  14367. fd = sd->fd;
  14368. WFIFOHEAD(fd, 8 * 8 + 8);
  14369. WFIFOW(fd,0) = 0x1ad;
  14370. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14371. {
  14372. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14373. {
  14374. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14375. c++;
  14376. }
  14377. }
  14378. if( c > 0 )
  14379. {
  14380. WFIFOW(fd,2) = c * 2 + 4;
  14381. WFIFOSET(fd, WFIFOW(fd, 2));
  14382. sd->menuskill_id = WL_READING_SB;
  14383. sd->menuskill_val = c;
  14384. }
  14385. else{
  14386. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14387. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14388. }
  14389. return 1;
  14390. }
  14391. /**
  14392. * Mechanic
  14393. **/
  14394. /*==========================================
  14395. * Magic Decoy Material List
  14396. *------------------------------------------*/
  14397. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14398. int i, c;
  14399. int fd;
  14400. nullpo_ret(sd);
  14401. fd = sd->fd;
  14402. WFIFOHEAD(fd, 8 * 8 + 8);
  14403. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14404. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14405. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14406. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14407. c ++;
  14408. }
  14409. }
  14410. if( c > 0 ) {
  14411. sd->menuskill_id = NC_MAGICDECOY;
  14412. sd->menuskill_val = skill_lv;
  14413. sd->sc.comet_x = x;
  14414. sd->sc.comet_y = y;
  14415. WFIFOW(fd,2) = c * 2 + 4;
  14416. WFIFOSET(fd, WFIFOW(fd, 2));
  14417. } else {
  14418. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14419. return 0;
  14420. }
  14421. return 1;
  14422. }
  14423. /*==========================================
  14424. * Guillotine Cross Poisons List
  14425. *------------------------------------------*/
  14426. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14427. int i, c;
  14428. int fd;
  14429. nullpo_ret(sd);
  14430. fd = sd->fd;
  14431. WFIFOHEAD(fd, 8 * 8 + 8);
  14432. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14433. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14434. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14435. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14436. c ++;
  14437. }
  14438. }
  14439. if( c > 0 ) {
  14440. sd->menuskill_id = GC_POISONINGWEAPON;
  14441. sd->menuskill_val = skill_lv;
  14442. WFIFOW(fd,2) = c * 2 + 4;
  14443. WFIFOSET(fd, WFIFOW(fd, 2));
  14444. } else {
  14445. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14446. return 0;
  14447. }
  14448. return 1;
  14449. }
  14450. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14451. int fd, i, c;
  14452. nullpo_ret(sd);
  14453. fd = sd->fd;
  14454. if( !fd ) return 0;
  14455. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14456. return 0;
  14457. WFIFOHEAD(fd, 2 * 6 + 4);
  14458. WFIFOW(fd,0) = 0x442;
  14459. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14460. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14461. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14462. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14463. {
  14464. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14465. c++;
  14466. }
  14467. if( c > 0 ) {
  14468. WFIFOW(fd,2) = 8 + c * 2;
  14469. WFIFOL(fd,4) = c;
  14470. WFIFOSET(fd,WFIFOW(fd,2));
  14471. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14472. sd->menuskill_val = c;
  14473. } else {
  14474. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14475. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14476. }
  14477. return 1;
  14478. }
  14479. /*===========================================
  14480. * Skill list for Four Elemental Analysis
  14481. * and Change Material skills.
  14482. *------------------------------------------*/
  14483. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14484. {
  14485. #if PACKETVER >= 20090922
  14486. int fd;
  14487. nullpo_ret(sd);
  14488. sd->menuskill_id = skill_id; // To prevent hacking.
  14489. sd->menuskill_val = skill_lv;
  14490. if( skill_id == GN_CHANGEMATERIAL )
  14491. skill_lv = 0; // Changematerial
  14492. fd = sd->fd;
  14493. WFIFOHEAD(fd,packet_len(0x7e3));
  14494. WFIFOW(fd,0) = 0x7e3;
  14495. WFIFOL(fd,2) = skill_lv;
  14496. WFIFOL(fd,4) = 0;
  14497. WFIFOSET(fd,packet_len(0x7e3));
  14498. #endif
  14499. return 1;
  14500. }
  14501. // msgstringtable.txt
  14502. // 0x291 <line>.W
  14503. void clif_msgtable(int fd, int line) {
  14504. WFIFOHEAD(fd, packet_len(0x291));
  14505. WFIFOW(fd, 0) = 0x291;
  14506. WFIFOW(fd, 2) = line;
  14507. WFIFOSET(fd, packet_len(0x291));
  14508. }
  14509. // msgstringtable.txt
  14510. // 0x7e2 <line>.W <value>.L
  14511. void clif_msgtable_num(int fd, int line, int num) {
  14512. #if PACKETVER >= 20090805
  14513. WFIFOHEAD(fd, packet_len(0x7e2));
  14514. WFIFOW(fd, 0) = 0x7e2;
  14515. WFIFOW(fd, 2) = line;
  14516. WFIFOL(fd, 4) = num;
  14517. WFIFOSET(fd, packet_len(0x7e2));
  14518. #endif
  14519. }
  14520. /*==========================================
  14521. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14522. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14523. * RFIFOL(fd,2) - type (currently not used)
  14524. *------------------------------------------*/
  14525. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14526. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14527. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14528. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14529. return;
  14530. if( pc_istrading(sd) ) {
  14531. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14532. clif_menuskill_clear(sd);
  14533. return;
  14534. }
  14535. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14536. clif_menuskill_clear(sd);
  14537. }
  14538. /*==========================================
  14539. * Kagerou/Oboro amulet spirit
  14540. *------------------------------------------*/
  14541. void clif_spiritcharm(struct map_session_data *sd)
  14542. {
  14543. unsigned char buf[10];
  14544. nullpo_retv(sd);
  14545. WBUFW(buf,0)=0x08cf;
  14546. WBUFL(buf,2)=sd->bl.id;
  14547. WBUFW(buf,6)=sd->spiritcharm_type;
  14548. WBUFW(buf,8)=sd->spiritcharm;
  14549. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14550. }
  14551. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14552. /// 0907 <index>.W
  14553. ///
  14554. /// R 0908 <index>.w <type>.b
  14555. /// type:
  14556. /// 0 = move item to personal tab
  14557. /// 1 = move item to normal tab
  14558. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14559. #if PACKETVER >= 20111122
  14560. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14561. int index = RFIFOW(fd,info->pos[0])-2;
  14562. int type = RFIFOB(fd, info->pos[1]);
  14563. /* can't move while dead. */
  14564. if(pc_isdead(sd)) {
  14565. return;
  14566. }
  14567. if (index < 0 || index >= MAX_INVENTORY)
  14568. return;
  14569. if ( sd->status.inventory[index].favorite && type == 1 )
  14570. sd->status.inventory[index].favorite = 0;
  14571. else if( type == 0 )
  14572. sd->status.inventory[index].favorite = 1;
  14573. else
  14574. return;/* nothing to do. */
  14575. clif_favorite_item(sd, index);
  14576. #endif
  14577. }
  14578. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14579. /// 0900 <index>.W <favorite>.B
  14580. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14581. int fd = sd->fd;
  14582. WFIFOHEAD(fd,packet_len(0x908));
  14583. WFIFOW(fd,0) = 0x908;
  14584. WFIFOW(fd,2) = index+2;
  14585. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14586. WFIFOSET(fd,packet_len(0x908));
  14587. }
  14588. void clif_snap( struct block_list *bl, short x, short y ) {
  14589. unsigned char buf[10];
  14590. WBUFW(buf,0) = 0x8d2;
  14591. WBUFL(buf,2) = bl->id;
  14592. WBUFW(buf,6) = x;
  14593. WBUFW(buf,8) = y;
  14594. if( disguised(bl) )
  14595. {
  14596. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14597. WBUFL(buf,2) = -bl->id;
  14598. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14599. } else
  14600. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14601. }
  14602. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14603. #if PACKETVER >= 20120404
  14604. WFIFOHEAD(fd,packet_len(0x977));
  14605. WFIFOW(fd,0) = 0x977;
  14606. WFIFOL(fd,2) = md->bl.id;
  14607. WFIFOL(fd,6) = md->status.hp;
  14608. WFIFOL(fd,10) = md->status.max_hp;
  14609. WFIFOSET(fd,packet_len(0x977));
  14610. #endif
  14611. }
  14612. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14613. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14614. return;
  14615. }
  14616. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14617. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14618. WFIFOW(sd->fd,0) = 0x2c9;
  14619. WFIFOB(sd->fd,2) = flag;
  14620. WFIFOSET(sd->fd, packet_len(0x2c9));
  14621. }
  14622. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14623. /// 0979 <world name>.24B <char name>.24B
  14624. void clif_ackworldinfo(struct map_session_data* sd) {
  14625. int fd;
  14626. nullpo_retv(sd);
  14627. fd = sd->fd;
  14628. WFIFOHEAD(fd,packet_len(0x979));
  14629. WFIFOW(fd,0)=0x979;
  14630. //AID -> world name ?
  14631. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14632. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14633. WFIFOSET(fd,packet_len(0x979));
  14634. }
  14635. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14636. /// 0978 <AID>.L
  14637. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14638. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14639. if(sd) clif_ackworldinfo(sd);
  14640. }
  14641. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14642. /// 0447
  14643. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14644. //if(sd)
  14645. ;
  14646. }
  14647. /// req world info (CZ_CLIENT_VERSION)
  14648. /// 044A <version>.L
  14649. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14650. //if(sd)
  14651. ;
  14652. }
  14653. /// Ranking list
  14654. /// ranking pointlist { <name>.24B <point>.L }*10
  14655. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14656. struct fame_list* list;
  14657. int skip = 0;
  14658. switch(rankingtype+1) { //to keep the same case as char.c
  14659. case 1: list = smith_fame_list; break;
  14660. case 2: list = chemist_fame_list; break;
  14661. case 3: list = taekwon_fame_list; break;
  14662. default: skip=1; break;
  14663. }
  14664. if(!skip) {
  14665. int i;
  14666. //Packet size limits this list to 10 elements. [Skotlex]
  14667. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14668. if (list[i].id > 0) {
  14669. const char* name;
  14670. if (strcmp(list[i].name, "-") == 0 &&
  14671. (name = map_charid2nick(list[i].id)) != NULL)
  14672. {
  14673. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14674. } else {
  14675. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14676. }
  14677. } else {
  14678. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14679. }
  14680. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14681. }
  14682. for(;i < 10; i++) { //In case the MAX is less than 10.
  14683. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14684. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14685. }
  14686. }
  14687. }
  14688. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14689. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14690. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14691. int mypoint = 0;
  14692. WBUFW(buf,0) = 0x97d;
  14693. WBUFW(buf,2) = rankingType;
  14694. clif_sub_ranklist(buf,4,sd,rankingType);
  14695. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14696. case MAPID_BLACKSMITH:
  14697. case MAPID_ALCHEMIST:
  14698. case MAPID_TAEKWON:
  14699. mypoint = sd->status.fame;
  14700. }
  14701. WBUFL(buf,284) = mypoint; //mypoint
  14702. clif_send(buf, 288, &sd->bl, SELF);
  14703. }
  14704. /*
  14705. * 097c <type> (CZ_REQ_RANKING)
  14706. * type
  14707. * 0: /blacksmith
  14708. * 1: /alchemist
  14709. * 2: /taekwon
  14710. * 3: /pk
  14711. * */
  14712. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14713. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14714. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14715. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14716. }
  14717. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14718. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14719. #if PACKETVER < 20130710
  14720. switch(rankingtype){
  14721. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14722. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14723. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14724. }
  14725. #else
  14726. int fd=sd->fd;
  14727. WFIFOHEAD(fd,14);
  14728. WFIFOW(fd,0) = 0x97e;
  14729. WFIFOW(fd,2) = rankingtype;
  14730. WFIFOL(fd,4) = point;
  14731. WFIFOL(fd,8) = sd->status.fame;
  14732. WFIFOSET(fd,12);
  14733. #endif
  14734. }
  14735. /**
  14736. * Transmit personal information to player. (rates)
  14737. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14738. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14739. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14740. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14741. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14742. * FIXME!
  14743. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14744. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14745. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14746. */
  14747. #ifdef VIP_ENABLE
  14748. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14749. if (sd) {
  14750. struct s_packet_db* info;
  14751. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14752. int cmd = 0, fd, i = 0;
  14753. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14754. int details_bexp[PINFO_MAX];
  14755. int details_drop[PINFO_MAX];
  14756. int details_penalty[PINFO_MAX];
  14757. int penalty_const;
  14758. /**
  14759. * Set for EXP
  14760. */
  14761. //0:PCRoom
  14762. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14763. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14764. details_bexp[0] = 0;
  14765. else {
  14766. if (details_bexp[0] < 100) {
  14767. details_bexp[0] = 100 - details_bexp[0];
  14768. details_bexp[0] = 0 - details_bexp[0];
  14769. }
  14770. else
  14771. details_bexp[0] = details_bexp[0] - 100;
  14772. }
  14773. //1:Premium
  14774. if (pc_isvip(sd)) {
  14775. details_bexp[1] = battle_config.vip_base_exp_increase;
  14776. if (details_bexp[1] < 0)
  14777. details_bexp[1] = 0 - details_bexp[1];
  14778. }
  14779. else
  14780. details_bexp[1] = 0;
  14781. //2:Server
  14782. details_bexp[2] = battle_config.base_exp_rate;
  14783. if (details_bexp[2] == 100)
  14784. details_bexp[2] = 0;
  14785. else {
  14786. if (details_bexp[2] < 100) {
  14787. details_bexp[2] = 100 - details_bexp[2];
  14788. details_bexp[2] = 0 - details_bexp[2];
  14789. }
  14790. else
  14791. details_bexp[2] = details_bexp[2] - 100;
  14792. }
  14793. //3:TPLUS
  14794. details_bexp[3] = 0;
  14795. /* End - EXP set*/
  14796. /**
  14797. * Set for Drop rate
  14798. */
  14799. //0:PCRoom
  14800. details_drop[0] = 0;
  14801. //1:Premium
  14802. details_drop[1] = battle_config.vip_drop_increase;
  14803. if (pc_isvip(sd)) {
  14804. if (details_drop[1] < 0)
  14805. details_drop[1] = 0 - details_drop[1];
  14806. }
  14807. else
  14808. details_drop[1] = 0;
  14809. //2:Server
  14810. details_drop[2] = battle_config.item_rate_common;
  14811. if (details_drop[2] == 100)
  14812. details_drop[2] = 0;
  14813. else {
  14814. if (details_drop[2] < 100) {
  14815. details_drop[2] = 100 - details_drop[2];
  14816. details_drop[2] = 0 - details_drop[2];
  14817. }
  14818. else
  14819. details_drop[2] = details_drop[2] - 100;
  14820. }
  14821. //3:TPLUS
  14822. details_drop[3] = 0;
  14823. /* End - Drop set*/
  14824. /**
  14825. * Set for Penalty rate
  14826. */
  14827. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14828. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14829. //0:PCRoom
  14830. details_penalty[0] = 0;
  14831. //1:Premium
  14832. if (pc_isvip(sd)) {
  14833. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14834. if (details_penalty[1] == 100)
  14835. details_penalty[1] = 0;
  14836. else {
  14837. if (details_penalty[1] < 100) {
  14838. details_penalty[1] = 100 - details_penalty[1];
  14839. details_penalty[1] = 0 - details_penalty[1];
  14840. }
  14841. else
  14842. details_penalty[1] = details_penalty[1] - 100;
  14843. }
  14844. }
  14845. else
  14846. details_penalty[1] = 0;
  14847. //2:Server
  14848. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14849. if (details_penalty[2] == 100)
  14850. details_penalty[2] = 0;
  14851. else {
  14852. if (details_penalty[2] < 100) {
  14853. details_penalty[2] = 100 - details_penalty[2];
  14854. details_penalty[2] = 0 - details_penalty[2];
  14855. }
  14856. else
  14857. details_penalty[2] = details_penalty[2] - 100;
  14858. }
  14859. //3:TPLUS
  14860. details_penalty[3] = 0;
  14861. /* End - Penalty set*/
  14862. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14863. info = &packet_db[sd->packet_ver][cmd];
  14864. len = info->len; //this is the base len without details
  14865. if(!len) return; //version as packet disable
  14866. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14867. szdetails = 7;
  14868. factor = 1;
  14869. }
  14870. else if (cmd == 0x097b) {
  14871. tot_baseexp *= factor;
  14872. tot_drop *= factor;
  14873. tot_penalty *= factor;
  14874. }
  14875. fd = sd->fd;
  14876. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14877. WFIFOW(fd,0) = cmd;
  14878. for (i = 0; i < maxinfotype; i++) {
  14879. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14880. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14881. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14882. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14883. tot_baseexp += details_bexp[i]*factor;
  14884. tot_drop += details_penalty[i]*factor;
  14885. tot_penalty += details_drop[i]*factor;
  14886. len += szdetails;
  14887. }
  14888. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14889. if (cmd == 0x08cb) { //0x08cb version
  14890. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14891. WFIFOW(fd,info->pos[2]) = tot_drop;
  14892. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14893. }
  14894. else { //2013-08-07aRagexe uses 0x097b
  14895. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14896. WFIFOL(fd,info->pos[2]) = tot_drop;
  14897. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14898. }
  14899. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14900. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14901. WFIFOSET(fd,len);
  14902. }
  14903. }
  14904. #endif
  14905. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14906. char cmd[30];
  14907. int t_aid = RFIFOL(fd,2);
  14908. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14909. is_atcommand(fd, sd, cmd, 1);
  14910. }
  14911. /**
  14912. * Marks Crimson Marker target on mini-map to the caster
  14913. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  14914. * @param fd
  14915. * @param bl Crimson Marker target
  14916. **/
  14917. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  14918. struct s_packet_db* info;
  14919. int cmd = 0;
  14920. int16 len;
  14921. unsigned char buf[11];
  14922. nullpo_retv(sd);
  14923. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  14924. if (!cmd)
  14925. cmd = 0x09C1; //default
  14926. info = &packet_db[sd->packet_ver][cmd];
  14927. if (!(len = info->len))
  14928. return;
  14929. WBUFW(buf, 0) = cmd;
  14930. WBUFL(buf, info->pos[0]) = bl->id;
  14931. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  14932. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  14933. clif_send(buf, len, &sd->bl, SELF);
  14934. }
  14935. /**
  14936. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  14937. **/
  14938. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  14939. struct s_packet_db *info = NULL;
  14940. int cmd = 0;
  14941. nullpo_retv(sd);
  14942. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  14943. info = &packet_db[sd->packet_ver][cmd];
  14944. if (!cmd || !info->len)
  14945. return;
  14946. WFIFOHEAD(sd->fd, info->len);
  14947. WFIFOW(sd->fd, 0) = cmd;
  14948. WFIFOW(sd->fd, info->pos[0]) = n+2;
  14949. WFIFOSET(sd->fd, info->len);
  14950. }
  14951. /// [Ind/Hercules]
  14952. void clif_showscript(struct block_list* bl, const char* message) {
  14953. char buf[256];
  14954. size_t len;
  14955. nullpo_retv(bl);
  14956. if(!message)
  14957. return;
  14958. len = strlen(message)+1;
  14959. if( len > sizeof(buf)-8 ) {
  14960. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  14961. len = sizeof(buf)-8;
  14962. }
  14963. WBUFW(buf,0) = 0x8b3;
  14964. WBUFW(buf,2) = (len+8);
  14965. WBUFL(buf,4) = bl->id;
  14966. safestrncpy((char *) WBUFP(buf,8), message, len);
  14967. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  14968. }
  14969. /// [Ind/Hercules]
  14970. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  14971. unsigned char buf[10];
  14972. nullpo_retv(sd);
  14973. WBUFW(buf,0) = 0x7fc;
  14974. WBUFL(buf,2) = prev_leader_aid;
  14975. WBUFL(buf,6) = new_leader_aid;
  14976. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  14977. }
  14978. /**
  14979. * Decrypt packet identifier for player
  14980. * @param fd
  14981. * @param sd
  14982. * @param packet_ver
  14983. * Orig author [Ind/Hercules]
  14984. **/
  14985. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  14986. #ifndef PACKET_OBFUSCATION
  14987. return RFIFOW(fd, 0);
  14988. #else
  14989. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  14990. if (sd)
  14991. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  14992. else
  14993. 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.
  14994. return cmd; // Return the decrypted packet ID.
  14995. #endif
  14996. }
  14997. /**
  14998. * !TODO: Special item that obtained, must be broadcasted by this packet
  14999. * 07fd ?? (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15000. */
  15001. //void clif_broadcast_obtain_special_item() {}
  15002. #ifdef DUMP_UNKNOWN_PACKET
  15003. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15004. {
  15005. const char* packet_txt = "save/packet.txt";
  15006. FILE* fp;
  15007. time_t time_server;
  15008. struct tm *datetime;
  15009. char datestr[512];
  15010. time(&time_server); // get time in seconds since 1/1/1970
  15011. datetime = localtime(&time_server); // convert seconds in structure
  15012. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15013. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15014. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15015. if( sd ) {
  15016. 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);
  15017. } else {
  15018. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15019. }
  15020. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15021. fprintf(fp, "\n");
  15022. fclose(fp);
  15023. } else {
  15024. ShowError("Failed to write '%s'.\n", packet_txt);
  15025. // Dump on console instead
  15026. if( sd ) {
  15027. 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);
  15028. } else {
  15029. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15030. }
  15031. ShowDump(RFIFOP(fd,0), packet_len);
  15032. }
  15033. }
  15034. #endif
  15035. /// Roulette System
  15036. /// Author: Yommy
  15037. /**
  15038. * Opens Roulette window
  15039. * @param fd
  15040. * @param sd
  15041. */
  15042. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15043. {
  15044. nullpo_retv(sd);
  15045. if (!battle_config.feature_roulette) {
  15046. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15047. return;
  15048. }
  15049. WFIFOHEAD(fd,packet_len(0xa1a));
  15050. WFIFOW(fd,0) = 0xa1a;
  15051. WFIFOB(fd,2) = 0; // result
  15052. WFIFOL(fd,3) = 0; // serial
  15053. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15054. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15055. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15056. WFIFOL(fd,11) = sd->roulette_point.gold;
  15057. WFIFOL(fd,15) = sd->roulette_point.silver;
  15058. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15059. WFIFOSET(fd,packet_len(0xa1a));
  15060. }
  15061. /**
  15062. * Generates information to be displayed
  15063. * @param fd
  15064. * @param sd
  15065. */
  15066. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15067. {
  15068. unsigned short i, j, count = 0;
  15069. int len = 8 + (42 * 8);
  15070. nullpo_retv(sd);
  15071. if (!battle_config.feature_roulette) {
  15072. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15073. return;
  15074. }
  15075. WFIFOHEAD(fd,len);
  15076. WFIFOW(fd,0) = 0xa1c;
  15077. WFIFOW(fd,2) = len;
  15078. WFIFOL(fd,4) = 1; // serial
  15079. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15080. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15081. WFIFOW(fd,8 * count + 8) = i;
  15082. WFIFOW(fd,8 * count + 10) = j;
  15083. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15084. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15085. count++;
  15086. }
  15087. }
  15088. WFIFOSET(fd,len);
  15089. return;
  15090. }
  15091. /**
  15092. * Closes Roulette window
  15093. * @param fd
  15094. * @param sd
  15095. */
  15096. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15097. {
  15098. nullpo_retv(sd);
  15099. if (!battle_config.feature_roulette) {
  15100. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15101. return;
  15102. }
  15103. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15104. return;
  15105. }
  15106. /**
  15107. *
  15108. **/
  15109. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15110. #if PACKETVER >= 20141016
  15111. uint16 cmd = 0xa22;
  15112. unsigned char buf[5];
  15113. nullpo_retv(sd);
  15114. if (packet_db[sd->packet_ver][cmd].len == 0)
  15115. return;
  15116. WBUFW(buf,0) = cmd;
  15117. WBUFB(buf,2) = type;
  15118. WBUFW(buf,3) = 0; //! TODO: Additional item
  15119. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15120. #endif
  15121. }
  15122. /**
  15123. * Claim roulette reward
  15124. * @param sd Player
  15125. * @return 0:Success
  15126. **/
  15127. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15128. struct item it;
  15129. uint8 res = 1;
  15130. nullpo_retr(1, sd);
  15131. if (sd->roulette.prizeIdx < 0)
  15132. return RECV_ITEM_FAILED;
  15133. memset(&it, 0, sizeof(it));
  15134. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15135. it.identify = 1;
  15136. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15137. ; // onSuccess
  15138. }
  15139. sd->roulette.claimPrize = false;
  15140. sd->roulette.prizeStage = 0;
  15141. sd->roulette.prizeIdx = -1;
  15142. sd->roulette.stage = 0;
  15143. return res;
  15144. }
  15145. /**
  15146. * Process the stage and attempt to give a prize
  15147. * @param fd
  15148. * @param sd
  15149. */
  15150. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15151. {
  15152. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15153. short stage = sd->roulette.stage;
  15154. nullpo_retv(sd);
  15155. if (!battle_config.feature_roulette) {
  15156. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15157. return;
  15158. }
  15159. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15160. stage = sd->roulette.stage = 0;
  15161. if (!stage) {
  15162. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15163. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15164. }
  15165. if (result == GENERATE_ROULETTE_SUCCESS) {
  15166. if (!stage) {
  15167. if (sd->roulette_point.bronze > 0) {
  15168. sd->roulette_point.bronze -= 1;
  15169. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15170. } else if (sd->roulette_point.silver > 9) {
  15171. sd->roulette_point.silver -= 10;
  15172. stage = sd->roulette.stage = 2;
  15173. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15174. } else if (sd->roulette_point.gold > 9) {
  15175. sd->roulette_point.gold -= 10;
  15176. stage = sd->roulette.stage = 4;
  15177. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15178. }
  15179. }
  15180. sd->roulette.prizeStage = stage;
  15181. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15182. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15183. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15184. clif_roulette_getitem(sd);
  15185. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15186. return;
  15187. }
  15188. else {
  15189. sd->roulette.claimPrize = true;
  15190. sd->roulette.stage++;
  15191. }
  15192. }
  15193. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15194. }
  15195. /**
  15196. * Request to cash in prize
  15197. * @param fd
  15198. * @param sd
  15199. */
  15200. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15201. {
  15202. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15203. nullpo_retv(sd);
  15204. if (!battle_config.feature_roulette) {
  15205. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15206. return;
  15207. }
  15208. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15209. switch (clif_roulette_getitem(sd)) {
  15210. case 0:
  15211. type = RECV_ITEM_SUCCESS;
  15212. break;
  15213. case 1:
  15214. case 4:
  15215. case 5:
  15216. type = RECV_ITEM_OVERCOUNT;
  15217. break;
  15218. case 2:
  15219. type = RECV_ITEM_OVERWEIGHT;
  15220. break;
  15221. case 7:
  15222. default:
  15223. type = RECV_ITEM_FAILED;
  15224. break;
  15225. }
  15226. }
  15227. clif_roulette_recvitem_ack(sd,type);
  15228. return;
  15229. }
  15230. /**
  15231. * Update Roulette window with current stats
  15232. * @param sd
  15233. * @param result
  15234. * @param stage
  15235. * @param prizeIdx
  15236. * @param bonusItemID
  15237. */
  15238. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15239. {
  15240. int fd = sd->fd;
  15241. nullpo_retv(sd);
  15242. WFIFOHEAD(fd,packet_len(0xa20));
  15243. WFIFOW(fd,0) = 0xa20;
  15244. WFIFOB(fd,2) = result;
  15245. WFIFOW(fd,3) = stage;
  15246. WFIFOW(fd,5) = prizeIdx;
  15247. WFIFOW(fd,7) = bonusItemID;
  15248. WFIFOL(fd,9) = sd->roulette_point.gold;
  15249. WFIFOL(fd,13) = sd->roulette_point.silver;
  15250. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15251. WFIFOSET(fd,packet_len(0xa20));
  15252. }
  15253. /*==========================================
  15254. * Main client packet processing function
  15255. *------------------------------------------*/
  15256. static int clif_parse(int fd)
  15257. {
  15258. int cmd, packet_ver, packet_len, err;
  15259. TBL_PC* sd;
  15260. int pnum;
  15261. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15262. // Note: "click masters" can do 80+ clicks in 10 seconds
  15263. 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]
  15264. { // begin main client packet processing loop
  15265. sd = (TBL_PC *)session[fd]->session_data;
  15266. if (session[fd]->flag.eof) {
  15267. if (sd) {
  15268. if (sd->state.autotrade) {
  15269. //Disassociate character from the socket connection.
  15270. session[fd]->session_data = NULL;
  15271. sd->fd = 0;
  15272. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15273. } else
  15274. if (sd->state.active) {
  15275. // Player logout display [Valaris]
  15276. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15277. clif_quitsave(fd, sd);
  15278. } else {
  15279. //Unusual logout (during log on/off/map-changer procedure)
  15280. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15281. map_quit(sd);
  15282. }
  15283. } else {
  15284. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15285. }
  15286. do_close(fd);
  15287. return 0;
  15288. }
  15289. if (RFIFOREST(fd) < 2)
  15290. return 0;
  15291. cmd = clif_parse_cmd(fd, sd);
  15292. // identify client's packet version
  15293. if (sd) {
  15294. packet_ver = sd->packet_ver;
  15295. } else {
  15296. // check authentification packet to know packet version
  15297. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15298. if( err ) {// failed to identify packet version
  15299. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15300. err == 1 ? "" :
  15301. err == 2 ? ", possibly for having an invalid account_id" :
  15302. err == 3 ? ", possibly for having an invalid char_id." :
  15303. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15304. err == 4 ? ", possibly for having an invalid login_id1." :
  15305. err == 5 ? ", possibly for having an invalid client_tick." :
  15306. */
  15307. err == 6 ? ", possibly for having an invalid sex." :
  15308. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15309. WFIFOHEAD(fd,packet_len(0x6a));
  15310. WFIFOW(fd,0) = 0x6a;
  15311. WFIFOB(fd,2) = 3; // Rejected from Server
  15312. WFIFOSET(fd,packet_len(0x6a));
  15313. #ifdef DUMP_INVALID_PACKET
  15314. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15315. #endif
  15316. RFIFOSKIP(fd, RFIFOREST(fd));
  15317. set_eof(fd);
  15318. return 0;
  15319. }
  15320. }
  15321. // filter out invalid / unsupported packets
  15322. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15323. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15324. #ifdef DUMP_INVALID_PACKET
  15325. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15326. #endif
  15327. set_eof(fd);
  15328. return 0;
  15329. }
  15330. // determine real packet length
  15331. packet_len = packet_db[packet_ver][cmd].len;
  15332. if (packet_len == -1) { // variable-length packet
  15333. if (RFIFOREST(fd) < 4)
  15334. return 0;
  15335. packet_len = RFIFOW(fd,2);
  15336. if (packet_len < 4 || packet_len > 32768) {
  15337. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15338. #ifdef DUMP_INVALID_PACKET
  15339. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15340. #endif
  15341. set_eof(fd);
  15342. return 0;
  15343. }
  15344. }
  15345. if ((int)RFIFOREST(fd) < packet_len)
  15346. return 0; // not enough data received to form the packet
  15347. #ifdef PACKET_OBFUSCATION
  15348. RFIFOW(fd, 0) = cmd;
  15349. if (sd)
  15350. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15351. #endif
  15352. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15353. packet_db[packet_ver][cmd].func(fd, sd);
  15354. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15355. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15356. ; //Only valid packet when there is no session
  15357. else
  15358. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15359. ; //Only valid packet when player is not on a map
  15360. else
  15361. packet_db[packet_ver][cmd].func(fd, sd);
  15362. }
  15363. #ifdef DUMP_UNKNOWN_PACKET
  15364. else DumpUnknown(fd,sd,cmd,packet_len);
  15365. #endif
  15366. RFIFOSKIP(fd, packet_len);
  15367. }; // main loop end
  15368. return 0;
  15369. }
  15370. /*==========================================
  15371. * Reads packet_db.txt and setups its array reference
  15372. *------------------------------------------*/
  15373. void packetdb_readdb(bool reload)
  15374. {
  15375. char line[1024];
  15376. int cmd,i,j;
  15377. int max_cmd=-1;
  15378. bool skip_ver = false;
  15379. int warned = 0;
  15380. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15381. #ifdef PACKET_OBFUSCATION
  15382. bool key_defined = false;
  15383. int last_key_defined = -1;
  15384. #endif
  15385. int packet_len_table[MAX_PACKET_DB] = {
  15386. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15390. //#0x0040
  15391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15393. #if PACKETVER <= 20081217
  15394. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  15395. #else
  15396. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  15397. #endif
  15398. #if PACKETVER < 2
  15399. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  15400. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  15401. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  15402. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  15403. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  15404. #else
  15405. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  15406. #endif
  15407. //#0x0080
  15408. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  15409. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  15410. #if PACKETVER <= 20100622
  15411. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  15412. #else
  15413. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  15414. #endif
  15415. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  15416. //#0x00C0
  15417. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  15418. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  15419. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  15420. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  15421. //#0x0100
  15422. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  15423. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  15424. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  15425. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  15426. //#0x0140
  15427. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  15428. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  15429. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  15430. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  15431. //#0x0180
  15432. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  15433. #if PACKETVER < 1
  15434. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15435. #else // 196 comodo icon status display for later
  15436. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15437. #endif
  15438. #if PACKETVER < 20081126
  15439. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15440. #else // 0x1a2 changed (35->37)
  15441. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15442. #endif
  15443. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  15444. //#0x01C0, Set 0x1d5=-1
  15445. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  15446. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  15447. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  15448. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  15449. //#0x0200
  15450. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  15451. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  15452. #if PACKETVER < 20071106
  15453. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  15454. #else // 0x22c changed
  15455. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  15456. #endif
  15457. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  15458. //#0x0240
  15459. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  15460. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  15461. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15462. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15463. //#0x0280
  15464. #if PACKETVER < 20070711
  15465. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  15466. #else
  15467. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  15468. #endif
  15469. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  15470. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15471. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  15472. //#0x02C0
  15473. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  15474. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  15475. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  15476. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15477. //#0x0300
  15478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15482. //#0x0340
  15483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15487. //#0x0380
  15488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15492. //#0x03C0
  15493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15497. //#0x0400
  15498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  15502. //#0x0440
  15503. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  15504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15507. //#0x0480
  15508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15512. //#0x04C0
  15513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15517. //#0x0500
  15518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15522. //#0x0540
  15523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15527. //#0x0580
  15528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15532. //#0x05C0
  15533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15537. //#0x0600
  15538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15542. //#0x0640
  15543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15547. //#0x0680
  15548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15552. //#0x06C0
  15553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15557. //#0x0700
  15558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15562. //#0x0740
  15563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15567. //#0x0780
  15568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15572. //#0x07C0
  15573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15574. #if PACKETVER < 20090617
  15575. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15576. #else // 0x7d9 changed
  15577. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15578. #endif
  15579. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15580. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  15581. //#0x0800
  15582. #if PACKETVER < 20091229
  15583. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15584. #else // for Party booking ( PACKETVER >= 20091229 )
  15585. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15586. #endif
  15587. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15588. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15589. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15590. //#0x0840
  15591. #if PACKETVER < 20130000
  15592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15593. #else
  15594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15595. #endif
  15596. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  15597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15599. //#0x0880
  15600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15603. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15604. //#0x08C0
  15605. 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 10,
  15606. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15609. //#0x0900
  15610. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15614. //#0x0940
  15615. 0, 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, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15619. //#0x0980
  15620. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15621. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  15622. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15623. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15624. //#0x09C0
  15625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  15626. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, 0, 0, 0, 0, 7,
  15627. 0, 0, 0, 0, 0, 0, 0, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  15628. 0, 11, 12, 11, 0, 0, 0, 0, 0,143, 0, 0, 0, 0, 0, 0,
  15629. //#0x0a00
  15630. #if PACKETVER >= 20141022
  15631. 269, 0, 0, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 0, 0,
  15632. #else
  15633. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 0, 0,
  15634. #endif
  15635. 0, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  15636. 21, 3, 5, 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15638. };
  15639. struct {
  15640. void (*func)(int, struct map_session_data *);
  15641. char *name;
  15642. } clif_parse_func[]={
  15643. {clif_parse_WantToConnection,"wanttoconnection"},
  15644. {clif_parse_LoadEndAck,"loadendack"},
  15645. {clif_parse_TickSend,"ticksend"},
  15646. {clif_parse_WalkToXY,"walktoxy"},
  15647. {clif_parse_QuitGame,"quitgame"},
  15648. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15649. {clif_parse_GlobalMessage,"globalmessage"},
  15650. {clif_parse_MapMove,"mapmove"},
  15651. {clif_parse_ChangeDir,"changedir"},
  15652. {clif_parse_Emotion,"emotion"},
  15653. {clif_parse_HowManyConnections,"howmanyconnections"},
  15654. {clif_parse_ActionRequest,"actionrequest"},
  15655. {clif_parse_Restart,"restart"},
  15656. {clif_parse_WisMessage,"wis"},
  15657. {clif_parse_Broadcast,"broadcast"},
  15658. {clif_parse_TakeItem,"takeitem"},
  15659. {clif_parse_DropItem,"dropitem"},
  15660. {clif_parse_UseItem,"useitem"},
  15661. {clif_parse_EquipItem,"equipitem"},
  15662. {clif_parse_UnequipItem,"unequipitem"},
  15663. {clif_parse_NpcClicked,"npcclicked"},
  15664. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15665. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15666. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15667. {clif_parse_CreateChatRoom,"createchatroom"},
  15668. {clif_parse_ChatAddMember,"chataddmember"},
  15669. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15670. {clif_parse_ChangeChatOwner,"changechatowner"},
  15671. {clif_parse_KickFromChat,"kickfromchat"},
  15672. {clif_parse_ChatLeave,"chatleave"},
  15673. {clif_parse_TradeRequest,"traderequest"},
  15674. {clif_parse_TradeAck,"tradeack"},
  15675. {clif_parse_TradeAddItem,"tradeadditem"},
  15676. {clif_parse_TradeOk,"tradeok"},
  15677. {clif_parse_TradeCancel,"tradecancel"},
  15678. {clif_parse_TradeCommit,"tradecommit"},
  15679. {clif_parse_StopAttack,"stopattack"},
  15680. {clif_parse_PutItemToCart,"putitemtocart"},
  15681. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15682. {clif_parse_RemoveOption,"removeoption"},
  15683. {clif_parse_ChangeCart,"changecart"},
  15684. {clif_parse_StatusUp,"statusup"},
  15685. {clif_parse_SkillUp,"skillup"},
  15686. {clif_parse_UseSkillToId,"useskilltoid"},
  15687. {clif_parse_UseSkillToPos,"useskilltopos"},
  15688. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15689. {clif_parse_UseSkillMap,"useskillmap"},
  15690. {clif_parse_RequestMemo,"requestmemo"},
  15691. {clif_parse_ProduceMix,"producemix"},
  15692. {clif_parse_Cooking,"cooking"},
  15693. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15694. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15695. {clif_parse_NpcAmountInput,"npcamountinput"},
  15696. {clif_parse_NpcStringInput,"npcstringinput"},
  15697. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15698. {clif_parse_ItemIdentify,"itemidentify"},
  15699. {clif_parse_SelectArrow,"selectarrow"},
  15700. {clif_parse_AutoSpell,"autospell"},
  15701. {clif_parse_UseCard,"usecard"},
  15702. {clif_parse_InsertCard,"insertcard"},
  15703. {clif_parse_RepairItem,"repairitem"},
  15704. {clif_parse_WeaponRefine,"weaponrefine"},
  15705. {clif_parse_SolveCharName,"solvecharname"},
  15706. {clif_parse_ResetChar,"resetchar"},
  15707. {clif_parse_LocalBroadcast,"localbroadcast"},
  15708. {clif_parse_MoveToKafra,"movetokafra"},
  15709. {clif_parse_MoveFromKafra,"movefromkafra"},
  15710. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15711. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15712. {clif_parse_CloseKafra,"closekafra"},
  15713. {clif_parse_CreateParty,"createparty"},
  15714. {clif_parse_CreateParty2,"createparty2"},
  15715. {clif_parse_PartyInvite,"partyinvite"},
  15716. {clif_parse_PartyInvite2,"partyinvite2"},
  15717. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15718. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15719. {clif_parse_LeaveParty,"leaveparty"},
  15720. {clif_parse_RemovePartyMember,"removepartymember"},
  15721. {clif_parse_PartyChangeOption,"partychangeoption"},
  15722. {clif_parse_PartyMessage,"partymessage"},
  15723. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15724. {clif_parse_CloseVending,"closevending"},
  15725. {clif_parse_VendingListReq,"vendinglistreq"},
  15726. {clif_parse_PurchaseReq,"purchasereq"},
  15727. {clif_parse_PurchaseReq2,"purchasereq2"},
  15728. {clif_parse_OpenVending,"openvending"},
  15729. {clif_parse_CreateGuild,"createguild"},
  15730. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15731. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15732. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15733. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15734. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15735. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15736. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15737. {clif_parse_GuildInvite,"guildinvite"},
  15738. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15739. {clif_parse_GuildLeave,"guildleave"},
  15740. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15741. {clif_parse_GuildMessage,"guildmessage"},
  15742. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15743. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15744. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15745. {clif_parse_GuildOpposition,"guildopposition"},
  15746. {clif_parse_GuildBreak,"guildbreak"},
  15747. {clif_parse_PetMenu,"petmenu"},
  15748. {clif_parse_CatchPet,"catchpet"},
  15749. {clif_parse_SelectEgg,"selectegg"},
  15750. {clif_parse_SendEmotion,"sendemotion"},
  15751. {clif_parse_ChangePetName,"changepetname"},
  15752. {clif_parse_GMKick,"gmkick"},
  15753. {clif_parse_GMHide,"gmhide"},
  15754. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15755. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15756. {clif_parse_GMKickAll,"killall"},
  15757. {clif_parse_GMRecall,"recall"},
  15758. {clif_parse_GMRecall,"summon"},
  15759. {clif_parse_GM_Item_Monster,"itemmonster"},
  15760. {clif_parse_GMShift,"remove"},
  15761. {clif_parse_GMShift,"shift"},
  15762. {clif_parse_GMChangeMapType,"changemaptype"},
  15763. {clif_parse_GMRc,"rc"},
  15764. {clif_parse_GMRecall2,"recall2"},
  15765. {clif_parse_GMRemove2,"remove2"},
  15766. {clif_parse_GMFullStrip,"gmfullstrip"},
  15767. {clif_parse_NoviceDoriDori,"sndoridori"},
  15768. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15769. {clif_parse_PMIgnore,"wisexin"},
  15770. {clif_parse_PMIgnoreList,"wisexlist"},
  15771. {clif_parse_PMIgnoreAll,"wisall"},
  15772. {clif_parse_FriendsListAdd,"friendslistadd"},
  15773. {clif_parse_FriendsListRemove,"friendslistremove"},
  15774. {clif_parse_FriendsListReply,"friendslistreply"},
  15775. {clif_parse_Blacksmith,"blacksmith"},
  15776. {clif_parse_Alchemist,"alchemist"},
  15777. {clif_parse_Taekwon,"taekwon"},
  15778. {clif_parse_RankingPk,"rankingpk"},
  15779. {clif_parse_FeelSaveOk,"feelsaveok"},
  15780. {clif_parse_debug,"debug"},
  15781. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15782. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15783. {clif_parse_HomMoveTo,"hommoveto"},
  15784. {clif_parse_HomAttack,"homattack"},
  15785. {clif_parse_HomMenu,"hommenu"},
  15786. {clif_parse_StoragePassword,"storagepassword"},
  15787. {clif_parse_Hotkey,"hotkey"},
  15788. {clif_parse_AutoRevive,"autorevive"},
  15789. {clif_parse_Check,"check"},
  15790. {clif_parse_Adopt_request,"adoptrequest"},
  15791. {clif_parse_Adopt_reply,"adoptreply"},
  15792. // MAIL SYSTEM
  15793. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15794. {clif_parse_Mail_read,"mailread"},
  15795. {clif_parse_Mail_getattach,"mailgetattach"},
  15796. {clif_parse_Mail_delete,"maildelete"},
  15797. {clif_parse_Mail_return,"mailreturn"},
  15798. {clif_parse_Mail_setattach,"mailsetattach"},
  15799. {clif_parse_Mail_winopen,"mailwinopen"},
  15800. {clif_parse_Mail_send,"mailsend"},
  15801. // AUCTION SYSTEM
  15802. {clif_parse_Auction_search,"auctionsearch"},
  15803. {clif_parse_Auction_buysell,"auctionbuysell"},
  15804. {clif_parse_Auction_setitem,"auctionsetitem"},
  15805. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15806. {clif_parse_Auction_register,"auctionregister"},
  15807. {clif_parse_Auction_cancel,"auctioncancel"},
  15808. {clif_parse_Auction_close,"auctionclose"},
  15809. {clif_parse_Auction_bid,"auctionbid"},
  15810. // Quest Log System
  15811. {clif_parse_questStateAck,"queststate"},
  15812. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15813. {clif_parse_EquipTick,"equiptickbox"},
  15814. {clif_parse_BattleChat,"battlechat"},
  15815. {clif_parse_mercenary_action,"mermenu"},
  15816. {clif_parse_progressbar,"progressbar"},
  15817. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15818. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15819. #if PACKETVER >= 20091229
  15820. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15821. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15822. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15823. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15824. #endif
  15825. {clif_parse_BankCheck,"bankcheck"},
  15826. {clif_parse_BankDeposit,"bankdeposit"},
  15827. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15828. {clif_parse_BankOpen,"bankopen"},
  15829. {clif_parse_BankClose,"bankclose"},
  15830. {clif_parse_PVPInfo,"pvpinfo"},
  15831. {clif_parse_LessEffect,"lesseffect"},
  15832. // Buying Store
  15833. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15834. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15835. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15836. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15837. // Store Search
  15838. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15839. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15840. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15841. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15842. // Cashshop
  15843. { clif_parse_cashshop_open_request, "cashshopopen" },
  15844. { clif_parse_cashshop_close, "cashshopclose" },
  15845. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15846. { clif_parse_cashshop_buy, "cashshopbuy" },
  15847. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15848. /* */
  15849. { clif_parse_MoveItem , "moveitem" },
  15850. { clif_parse_PartyTick, "partytick" },
  15851. { clif_parse_dull, "dull" },
  15852. { clif_parse_GuildInvite2 , "guildinvite2" },
  15853. { clif_parse_reqworldinfo, "reqworldinfo"},
  15854. { clif_parse_client_version, "clientversion"},
  15855. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15856. { clif_parse_ranklist, "ranklist"},
  15857. // Market NPC
  15858. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  15859. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  15860. // Roulette
  15861. { clif_parse_RouletteOpen, "rouletteopen" },
  15862. { clif_parse_RouletteInfo, "rouletteinfo" },
  15863. { clif_parse_RouletteClose, "rouletteclose" },
  15864. { clif_parse_RouletteGenerate, "roulettegenerate" },
  15865. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  15866. {NULL,NULL}
  15867. };
  15868. struct {
  15869. char *name; //function name
  15870. int funcidx; //
  15871. } clif_ack_func[]={ //hash
  15872. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15873. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15874. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15875. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15876. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15877. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15878. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15879. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15880. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  15881. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  15882. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  15883. };
  15884. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15885. int f;
  15886. memset(packet_db,0,sizeof(packet_db));
  15887. memset(packet_db_ack,0,sizeof(packet_db_ack));
  15888. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15889. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15890. packet_len(i) = packet_len_table[i];
  15891. clif_config.packet_db_ver = MAX_PACKET_VER;
  15892. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  15893. FILE *fp;
  15894. int ln = 0;
  15895. int entries = 0;
  15896. char *str[64], *p, *str2[64], *p2;
  15897. sprintf(line, "%s/%s", db_path, filename[f]);
  15898. if( (fp = fopen(line,"r")) == NULL ) {
  15899. if (f == 0) {
  15900. ShowFatalError("Can't read %s\n", line);
  15901. exit(EXIT_FAILURE);
  15902. }
  15903. return;
  15904. }
  15905. while( fgets(line, sizeof(line), fp) ) {
  15906. char w1[256],w2[256];
  15907. ln++;
  15908. if(line[0]=='/' && line[1]=='/')
  15909. continue;
  15910. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  15911. if (strcmpi(w1,"packet_ver") == 0) {
  15912. int prev_ver = packet_ver;
  15913. skip_ver = false;
  15914. packet_ver = atoi(w2);
  15915. if ( packet_ver > MAX_PACKET_VER )
  15916. { //Check to avoid overflowing. [Skotlex]
  15917. if( (warned&1) == 0 )
  15918. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15919. warned &= 1;
  15920. skip_ver = true;
  15921. }
  15922. else if( packet_ver < 0 )
  15923. {
  15924. if( (warned&2) == 0 )
  15925. ShowWarning("Negative packet versions are not supported.\n");
  15926. warned &= 2;
  15927. skip_ver = true;
  15928. }
  15929. else if( packet_ver == SERVER )
  15930. {
  15931. if( (warned&4) == 0 )
  15932. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15933. warned &= 4;
  15934. skip_ver = true;
  15935. }
  15936. if( skip_ver )
  15937. {
  15938. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15939. packet_ver = prev_ver;
  15940. continue;
  15941. }
  15942. // copy from previous version into new version and continue
  15943. // - indicating all following packets should be read into the newer version
  15944. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15945. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15946. continue;
  15947. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15948. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  15949. clif_config.packet_db_ver = MAX_PACKET_VER;
  15950. else // to manually set the packet DB version
  15951. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15952. continue;
  15953. }
  15954. #ifdef PACKET_OBFUSCATION
  15955. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  15956. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  15957. trim(w2);
  15958. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  15959. if (!packet_keys[packet_ver])
  15960. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  15961. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  15962. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  15963. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  15964. last_key_defined = packet_ver;
  15965. if (battle_config.etc_log)
  15966. 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]);
  15967. }
  15968. continue;
  15969. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  15970. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  15971. trim(w2);
  15972. if (strcmpi(w2,"default") == 0)
  15973. continue;
  15974. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  15975. clif_cryptKey[0] = strtol(key1, NULL, 0);
  15976. clif_cryptKey[1] = strtol(key2, NULL, 0);
  15977. clif_cryptKey[2] = strtol(key3, NULL, 0);
  15978. key_defined = true;
  15979. if (battle_config.etc_log)
  15980. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  15981. }
  15982. continue;
  15983. }
  15984. #endif
  15985. }
  15986. if( skip_ver )
  15987. continue; // Skipping current packet version
  15988. memset(str,0,sizeof(str));
  15989. for (j = 0, p = line; j < 4 && p; ++j) {
  15990. str[j] = p;
  15991. p = strchr(p,',');
  15992. if (p)
  15993. *p++=0;
  15994. }
  15995. if (str[0] == NULL)
  15996. continue;
  15997. cmd = strtol(str[0],(char **)NULL,0);
  15998. if(max_cmd < cmd)
  15999. max_cmd = cmd;
  16000. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16001. continue;
  16002. if(str[1]==NULL){
  16003. ShowError("packet_db: packet len error\n");
  16004. continue;
  16005. }
  16006. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16007. if(str[2]==NULL){
  16008. packet_db[packet_ver][cmd].func = NULL;
  16009. ln++;
  16010. continue;
  16011. }
  16012. // look up processing function by name
  16013. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16014. if( j < ARRAYLENGTH(clif_parse_func) )
  16015. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16016. else { //search if it's a mapped ack func
  16017. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16018. if( j < ARRAYLENGTH(clif_ack_func)) {
  16019. int fidx = clif_ack_func[j].funcidx;
  16020. packet_db_ack[packet_ver][fidx] = cmd;
  16021. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16022. }
  16023. }
  16024. // set the identifying cmd for the packet_db version
  16025. if (strcmp(str[2],"wanttoconnection")==0)
  16026. clif_config.connect_cmd[packet_ver] = cmd;
  16027. if(str[3]==NULL){
  16028. ShowError("packet_db: packet error\n");
  16029. exit(EXIT_FAILURE);
  16030. }
  16031. for(j = 0, p2 = str[3]; p2; j++){
  16032. short k;
  16033. str2[j] = p2;
  16034. p2 = strchr(p2,':');
  16035. if(p2)
  16036. *p2++=0;
  16037. k = atoi(str2[j]);
  16038. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16039. if( j >= MAX_PACKET_POS )
  16040. {
  16041. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16042. break;
  16043. }
  16044. packet_db[packet_ver][cmd].pos[j] = k;
  16045. }
  16046. entries++;
  16047. }
  16048. fclose(fp);
  16049. if(max_cmd > MAX_PACKET_DB) {
  16050. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16051. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16052. }
  16053. //Locate the nearest version that we still support. [Skotlex]
  16054. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16055. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16056. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16057. }
  16058. sprintf(line, "%s/%s", db_path,filename[f]);
  16059. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16060. }
  16061. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16062. #ifdef PACKET_OBFUSCATION
  16063. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16064. int use_key = last_key_defined;
  16065. if (last_key_defined == -1)
  16066. ShowError("Can't find packet obfuscation keys!\n");
  16067. else {
  16068. if (packet_keys[clif_config.packet_db_ver])
  16069. use_key = clif_config.packet_db_ver;
  16070. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16071. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16072. }
  16073. }
  16074. 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]);
  16075. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16076. if (packet_keys[i]) {
  16077. aFree(packet_keys[i]);
  16078. packet_keys[i] = NULL;
  16079. }
  16080. }
  16081. #endif
  16082. }
  16083. /*==========================================
  16084. *
  16085. *------------------------------------------*/
  16086. void do_init_clif(void) {
  16087. const char* colors[COLOR_MAX] = {
  16088. "0x00FF00",
  16089. "0xFF0000",
  16090. "0xFFFFFF",
  16091. "0xFFFF00",
  16092. };
  16093. int i;
  16094. /**
  16095. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16096. **/
  16097. for(i = 0; i < COLOR_MAX; i++) {
  16098. color_table[i] = strtoul(colors[i],NULL,0);
  16099. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16100. }
  16101. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16102. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16103. #ifdef PACKET_OBFUSCATION
  16104. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16105. #endif
  16106. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16107. packetdb_readdb(false);
  16108. set_defaultparse(clif_parse);
  16109. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16110. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16111. exit(EXIT_FAILURE);
  16112. }
  16113. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16114. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16115. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16116. }
  16117. void do_final_clif(void) {
  16118. ers_destroy(delay_clearunit_ers);
  16119. }