clif.c 557 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426
  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. struct status_data *status = NULL;
  818. unsigned char *buf = WBUFP(buffer, 0);
  819. #if PACKETVER < 20091103
  820. bool type = !pcdb_checkid(vd->class_);
  821. #endif
  822. unsigned short offset = 0;
  823. #if PACKETVER >= 20091103
  824. const char *name;
  825. #endif
  826. sd = BL_CAST(BL_PC, bl);
  827. #if PACKETVER < 20091103
  828. if(type)
  829. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  830. else
  831. #endif
  832. #if PACKETVER < 4
  833. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  834. #elif PACKETVER < 7
  835. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  836. #elif PACKETVER < 20080102
  837. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  838. #elif PACKETVER < 20091103
  839. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  840. #elif PACKETVER < 20101124
  841. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  842. #elif PACKETVER < 20131223
  843. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  844. #elif PACKETVER < 20150513
  845. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  846. #else
  847. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  848. #endif
  849. #if PACKETVER >= 20091103
  850. name = status_get_name(bl);
  851. #if PACKETVER >= 20131223
  852. status = status_get_status_data(bl);
  853. #if PACKETVER < 20110111
  854. WBUFW(buf,2) = (spawn ? 62 : 63)+strlen(name);
  855. #elif PACKETVER < 20131223
  856. WBUFW(buf,2) = (spawn ? 64 : 65)+strlen(name);
  857. #elif PACKETVER < 20150513
  858. WBUFW(buf,2) = (spawn ? 77 : 78)+strlen(name);
  859. #else
  860. WBUFW(buf,2) = (spawn ? 79 : 80)+strlen(name);
  861. #endif
  862. #endif
  863. WBUFB(buf,4) = clif_bl_type(bl);
  864. offset+=3;
  865. buf = WBUFP(buffer,offset);
  866. #elif PACKETVER >= 20071106
  867. if (type) { //Non-player packets
  868. WBUFB(buf,2) = clif_bl_type(bl);
  869. offset++;
  870. buf = WBUFP(buffer,offset);
  871. }
  872. #endif
  873. WBUFL(buf, 2) = bl->id;
  874. #if PACKETVER >= 20131223
  875. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  876. offset+=4;
  877. buf = WBUFP(buffer,offset);
  878. #endif
  879. WBUFW(buf, 6) = status_get_speed(bl);
  880. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  881. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  882. #if PACKETVER < 20091103
  883. if (type&&spawn) { //uses an older and different packet structure
  884. WBUFW(buf,12) = (sc)? sc->option : 0;
  885. WBUFW(buf,14) = vd->hair_style;
  886. WBUFW(buf,16) = vd->weapon;
  887. WBUFW(buf,18) = vd->head_bottom;
  888. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  889. WBUFW(buf,22) = vd->shield;
  890. } else {
  891. #endif
  892. #if PACKETVER >= 20091103
  893. WBUFL(buf,12) = (sc)? sc->option : 0;
  894. offset+=2;
  895. buf = WBUFP(buffer,offset);
  896. #elif PACKETVER >= 7
  897. if (!type) {
  898. WBUFL(buf,12) = (sc)? sc->option : 0;
  899. offset+=2;
  900. buf = WBUFP(buffer,offset);
  901. } else
  902. WBUFW(buf,12) = (sc)? sc->option : 0;
  903. #else
  904. WBUFW(buf,12) = (sc)? sc->option : 0;
  905. #endif
  906. WBUFW(buf,14) = vd->class_;
  907. WBUFW(buf,16) = vd->hair_style;
  908. WBUFW(buf,18) = vd->weapon;
  909. #if PACKETVER < 4
  910. WBUFW(buf,20) = vd->head_bottom;
  911. WBUFW(buf,22) = vd->shield;
  912. #else
  913. WBUFW(buf,20) = vd->shield;
  914. WBUFW(buf,22) = vd->head_bottom;
  915. #endif
  916. #if PACKETVER < 20091103
  917. }
  918. #endif
  919. WBUFW(buf,24) = vd->head_top;
  920. WBUFW(buf,26) = vd->head_mid;
  921. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  922. { //The hell, why flags work like this?
  923. WBUFW(buf,22) = status_get_emblem_id(bl);
  924. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  925. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  926. }
  927. WBUFW(buf,28) = vd->hair_color;
  928. WBUFW(buf,30) = vd->cloth_color;
  929. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  930. #if PACKETVER < 20091103
  931. if (type&&spawn) { //End of packet 0x7c
  932. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  933. WBUFB(buf,35) = vd->sex;
  934. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  935. WBUFB(buf,39) = 0;
  936. WBUFB(buf,40) = 0;
  937. return packet_len(0x7c);
  938. }
  939. #endif
  940. #if PACKETVER >= 20110111
  941. WBUFW(buf,34) = vd->robe;
  942. offset+= 2;
  943. buf = WBUFP(buffer,offset);
  944. #endif
  945. WBUFL(buf,34) = status_get_guild_id(bl);
  946. WBUFW(buf,38) = status_get_emblem_id(bl);
  947. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  948. #if PACKETVER >= 20091103
  949. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  950. offset+=2;
  951. buf = WBUFP(buffer,offset);
  952. #elif PACKETVER >= 7
  953. if (!type) {
  954. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  955. offset+=2;
  956. buf = WBUFP(buffer,offset);
  957. } else
  958. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  959. #else
  960. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  961. #endif
  962. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  963. WBUFB(buf,45) = vd->sex;
  964. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  965. WBUFB(buf,49) = (sd)? 5 : 0;
  966. WBUFB(buf,50) = (sd)? 5 : 0;
  967. if (!spawn) {
  968. WBUFB(buf,51) = vd->dead_sit;
  969. offset++;
  970. buf = WBUFP(buffer,offset);
  971. }
  972. WBUFW(buf,51) = clif_setlevel(bl);
  973. #if PACKETVER < 20091103
  974. if (type) //End for non-player packet
  975. return packet_len(WBUFW(buffer,0));
  976. #endif
  977. #if PACKETVER >= 20080102
  978. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  979. #endif
  980. #if PACKETVER >= 20131223
  981. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl) ) {
  982. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  983. WBUFL(buf,59) = status_get_hp(bl); // HP
  984. WBUFB(buf,63) = (status->mode&MD_BOSS) ? 1 : 0; // isBoss
  985. } else {
  986. WBUFL(buf,55) = -1; // maxHP
  987. WBUFL(buf,59) = -1; // HP
  988. WBUFB(buf,63) = 0; // isBoss
  989. }
  990. #endif
  991. #if PACKETVER >= 20150513
  992. WBUFW(buf,64) = 0; // body
  993. offset+= 2;
  994. buf = WBUFP(buffer,offset);
  995. #endif
  996. #if PACKETVER >= 20091103
  997. memcpy((char*)WBUFP(buf,64), name, NAME_LENGTH);
  998. return WBUFW(buffer,2);
  999. #else
  1000. return packet_len(WBUFW(buffer,0));
  1001. #endif
  1002. }
  1003. /*==========================================
  1004. * Prepares 'unit walking' packet
  1005. *------------------------------------------*/
  1006. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1007. {
  1008. struct map_session_data* sd;
  1009. struct status_change* sc = status_get_sc(bl);
  1010. struct view_data* vd = status_get_viewdata(bl);
  1011. struct status_data *status = NULL;
  1012. unsigned char* buf = WBUFP(buffer,0);
  1013. #if PACKETVER >= 7
  1014. unsigned short offset = 0;
  1015. #endif
  1016. #if PACKETVER >= 20091103
  1017. const char *name;
  1018. #endif
  1019. sd = BL_CAST(BL_PC, bl);
  1020. #if PACKETVER < 4
  1021. WBUFW(buf, 0) = 0x7b;
  1022. #elif PACKETVER < 7
  1023. WBUFW(buf, 0) = 0x1da;
  1024. #elif PACKETVER < 20080102
  1025. WBUFW(buf, 0) = 0x22c;
  1026. #elif PACKETVER < 20091103
  1027. WBUFW(buf, 0) = 0x2ec;
  1028. #elif PACKETVER < 20101124
  1029. WBUFW(buf, 0) = 0x7f7;
  1030. #elif PACKETVER < 20131223
  1031. WBUFW(buf, 0) = 0x856;
  1032. #elif PACKETVER < 20150513
  1033. WBUFW(buf, 0) = 0x9db;
  1034. #else
  1035. WBUFW(buf, 0) = 0x9fd;
  1036. #endif
  1037. #if PACKETVER >= 20091103
  1038. name = status_get_name(bl);
  1039. #if PACKETVER >= 20131223
  1040. status = status_get_status_data(bl);
  1041. #if PACKETVER < 20110111
  1042. WBUFW(buf, 2) = 69+strlen(name);
  1043. #elif PACKETVER < 20131223
  1044. WBUFW(buf, 2) = 71+strlen(name);
  1045. #elif PACKETVER < 20150513
  1046. WBUFW(buf, 2) = 84+strlen(name);
  1047. #else
  1048. WBUFW(buf, 2) = 86+strlen(name);
  1049. #endif
  1050. #endif
  1051. offset+=2;
  1052. buf = WBUFP(buffer,offset);
  1053. #endif
  1054. #if PACKETVER >= 20071106
  1055. WBUFB(buf, 2) = clif_bl_type(bl);
  1056. offset++;
  1057. buf = WBUFP(buffer,offset);
  1058. #endif
  1059. WBUFL(buf, 2) = bl->id;
  1060. #if PACKETVER >= 20131223
  1061. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1062. offset+=4;
  1063. buf = WBUFP(buffer,offset);
  1064. #endif
  1065. WBUFW(buf, 6) = status_get_speed(bl);
  1066. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1067. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1068. #if PACKETVER < 7
  1069. WBUFW(buf,12) = (sc)? sc->option : 0;
  1070. #else
  1071. WBUFL(buf,12) = (sc)? sc->option : 0;
  1072. offset+=2; //Shift the rest of elements by 2 bytes.
  1073. buf = WBUFP(buffer,offset);
  1074. #endif
  1075. WBUFW(buf,14) = vd->class_;
  1076. WBUFW(buf,16) = vd->hair_style;
  1077. WBUFW(buf,18) = vd->weapon;
  1078. #if PACKETVER < 4
  1079. WBUFW(buf,20) = vd->head_bottom;
  1080. WBUFL(buf,22) = gettick();
  1081. WBUFW(buf,26) = vd->shield;
  1082. #else
  1083. WBUFW(buf,20) = vd->shield;
  1084. WBUFW(buf,22) = vd->head_bottom;
  1085. WBUFL(buf,24) = gettick();
  1086. #endif
  1087. WBUFW(buf,28) = vd->head_top;
  1088. WBUFW(buf,30) = vd->head_mid;
  1089. WBUFW(buf,32) = vd->hair_color;
  1090. WBUFW(buf,34) = vd->cloth_color;
  1091. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1092. #if PACKETVER >= 20110111
  1093. WBUFW(buf,38) = vd->robe;
  1094. offset+= 2;
  1095. buf = WBUFP(buffer,offset);
  1096. #endif
  1097. WBUFL(buf,38) = status_get_guild_id(bl);
  1098. WBUFW(buf,42) = status_get_emblem_id(bl);
  1099. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1100. #if PACKETVER < 7
  1101. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1102. #else
  1103. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1104. offset+=2; //Shift the rest of elements by 2 bytes.
  1105. buf = WBUFP(buffer,offset);
  1106. #endif
  1107. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1108. WBUFB(buf,49) = vd->sex;
  1109. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1110. WBUFB(buf,56) = (sd)? 5 : 0;
  1111. WBUFB(buf,57) = (sd)? 5 : 0;
  1112. WBUFW(buf,58) = clif_setlevel(bl);
  1113. #if PACKETVER >= 20080102
  1114. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1115. #endif
  1116. #if PACKETVER >= 20131223
  1117. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl) ) {
  1118. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1119. WBUFL(buf,66) = status_get_hp(bl); // HP
  1120. WBUFB(buf,70) = (status->mode&MD_BOSS) ? 1 : 0; // isBoss
  1121. } else {
  1122. WBUFL(buf,62) = -1; // maxHP
  1123. WBUFL(buf,66) = -1; // HP
  1124. WBUFB(buf,70) = 0; // isBoss
  1125. }
  1126. #endif
  1127. #if PACKETVER >= 20150513
  1128. WBUFW(buf,71) = 0; // body
  1129. offset+= 2;
  1130. buf = WBUFP(buffer,offset);
  1131. #endif
  1132. #if PACKETVER >= 20091103
  1133. memcpy((char*)WBUFP(buf,71), name, NAME_LENGTH);
  1134. return WBUFW(buffer,2);
  1135. #else
  1136. return packet_len(WBUFW(buffer,0));
  1137. #endif
  1138. }
  1139. //Modifies the buffer for disguise characters and sends it to self.
  1140. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1141. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1142. {
  1143. #if PACKETVER >= 20091103
  1144. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1145. WBUFL(buf,5)=-bl->id;
  1146. #elif PACKETVER >= 20071106
  1147. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1148. WBUFL(buf,3)=-bl->id;
  1149. #else
  1150. WBUFL(buf,2)=-bl->id;
  1151. #endif
  1152. clif_send(buf, len, bl, SELF);
  1153. }
  1154. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1155. /// 01b0 <id>.L <type>.B <value>.L
  1156. /// type:
  1157. /// unused
  1158. void clif_class_change(struct block_list *bl,int class_,int type)
  1159. {
  1160. nullpo_retv(bl);
  1161. if(!pcdb_checkid(class_))
  1162. {// player classes yield missing sprites
  1163. unsigned char buf[16];
  1164. WBUFW(buf,0)=0x1b0;
  1165. WBUFL(buf,2)=bl->id;
  1166. WBUFB(buf,6)=type;
  1167. WBUFL(buf,7)=class_;
  1168. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1169. }
  1170. }
  1171. /// Notifies the client of an object's spirits.
  1172. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1173. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1174. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1175. {
  1176. WFIFOHEAD(fd, packet_len(0x1e1));
  1177. WFIFOW(fd,0)=0x1e1;
  1178. WFIFOL(fd,2)=sd->bl.id;
  1179. WFIFOW(fd,6)=sd->spiritball;
  1180. WFIFOSET(fd, packet_len(0x1e1));
  1181. }
  1182. /*==========================================
  1183. * Kagerou/Oboro amulet spirit
  1184. *------------------------------------------*/
  1185. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1186. {
  1187. WFIFOHEAD(fd, packet_len(0x08cf));
  1188. WFIFOW(fd,0)=0x08cf;
  1189. WFIFOL(fd,2)=sd->bl.id;
  1190. WFIFOW(fd,6)=sd->spiritcharm_type;
  1191. WFIFOW(fd,8)=sd->spiritcharm;
  1192. WFIFOSET(fd, packet_len(0x08cf));
  1193. }
  1194. /*==========================================
  1195. * Run when player changes map / refreshes
  1196. * Tells its client to display all weather settings being used by this map
  1197. *------------------------------------------*/
  1198. static void clif_weather_check(struct map_session_data *sd)
  1199. {
  1200. int16 m = sd->bl.m;
  1201. int fd = sd->fd;
  1202. if (map[m].flag.snow
  1203. || map[m].flag.clouds
  1204. || map[m].flag.fog
  1205. || map[m].flag.fireworks
  1206. || map[m].flag.sakura
  1207. || map[m].flag.leaves
  1208. || map[m].flag.clouds2)
  1209. {
  1210. if (map[m].flag.snow)
  1211. clif_specialeffect_single(&sd->bl, 162, fd);
  1212. if (map[m].flag.clouds)
  1213. clif_specialeffect_single(&sd->bl, 233, fd);
  1214. if (map[m].flag.clouds2)
  1215. clif_specialeffect_single(&sd->bl, 516, fd);
  1216. if (map[m].flag.fog)
  1217. clif_specialeffect_single(&sd->bl, 515, fd);
  1218. if (map[m].flag.fireworks) {
  1219. clif_specialeffect_single(&sd->bl, 297, fd);
  1220. clif_specialeffect_single(&sd->bl, 299, fd);
  1221. clif_specialeffect_single(&sd->bl, 301, fd);
  1222. }
  1223. if (map[m].flag.sakura)
  1224. clif_specialeffect_single(&sd->bl, 163, fd);
  1225. if (map[m].flag.leaves)
  1226. clif_specialeffect_single(&sd->bl, 333, fd);
  1227. }
  1228. }
  1229. /**
  1230. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1231. **/
  1232. void clif_weather(int16 m)
  1233. {
  1234. struct s_mapiterator* iter;
  1235. struct map_session_data *sd=NULL;
  1236. iter = mapit_getallusers();
  1237. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1238. {
  1239. if( sd->bl.m == m )
  1240. clif_weather_check(sd);
  1241. }
  1242. mapit_free(iter);
  1243. }
  1244. /**
  1245. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1246. **/
  1247. int clif_spawn(struct block_list *bl)
  1248. {
  1249. unsigned char buf[128];
  1250. struct view_data *vd;
  1251. struct status_change *sc = status_get_sc(bl);
  1252. int len;
  1253. vd = status_get_viewdata(bl);
  1254. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1255. return 0;
  1256. /**
  1257. * Hide NPC from maya purple card.
  1258. **/
  1259. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1260. return 0;
  1261. len = clif_set_unit_idle(bl, buf,true);
  1262. clif_send(buf, len, bl, AREA_WOS);
  1263. if (disguised(bl))
  1264. clif_setdisguise(bl, buf, len);
  1265. if (vd->cloth_color)
  1266. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1267. switch (bl->type)
  1268. {
  1269. case BL_PC:
  1270. {
  1271. TBL_PC *sd = ((TBL_PC*)bl);
  1272. int i;
  1273. if (sd->spiritball > 0)
  1274. clif_spiritball(&sd->bl);
  1275. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1276. clif_specialeffect(bl,423,AREA);
  1277. else if(sd->state.size==SZ_MEDIUM)
  1278. clif_specialeffect(bl,421,AREA);
  1279. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1280. clif_sendbgemblem_area(sd);
  1281. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1282. clif_spiritcharm(sd);
  1283. for (i = 0; i < sd->sc_display_count; i++) {
  1284. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1285. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1286. else
  1287. 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);
  1288. }
  1289. if (sd->status.robe)
  1290. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1291. }
  1292. break;
  1293. case BL_MOB:
  1294. {
  1295. TBL_MOB *md = ((TBL_MOB*)bl);
  1296. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1297. clif_specialeffect(&md->bl,423,AREA);
  1298. else if(md->special_state.size==SZ_MEDIUM)
  1299. clif_specialeffect(&md->bl,421,AREA);
  1300. }
  1301. break;
  1302. case BL_NPC:
  1303. {
  1304. TBL_NPC *nd = ((TBL_NPC*)bl);
  1305. if( nd->size == SZ_BIG )
  1306. clif_specialeffect(&nd->bl,423,AREA);
  1307. else if( nd->size == SZ_MEDIUM )
  1308. clif_specialeffect(&nd->bl,421,AREA);
  1309. }
  1310. break;
  1311. case BL_PET:
  1312. if (vd->head_bottom)
  1313. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1314. break;
  1315. }
  1316. return 0;
  1317. }
  1318. /// Sends information about owned homunculus to the client . [orn]
  1319. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1320. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1321. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1322. {
  1323. struct status_data *status;
  1324. unsigned char buf[128];
  1325. #if PACKETVER < 20141016
  1326. const int cmd = 0x22e;
  1327. int offset = 0;
  1328. #else
  1329. const int cmd = 0x9f7;
  1330. int offset = 2;
  1331. #endif
  1332. int htype;
  1333. nullpo_retv(hd);
  1334. if (!clif_session_isValid(sd))
  1335. return;
  1336. status = &hd->battle_status;
  1337. htype = hom_class2type(hd->homunculus.class_);
  1338. memset(buf,0,packet_len(cmd));
  1339. WBUFW(buf,0) = cmd;
  1340. memcpy(WBUFP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1341. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1342. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1343. WBUFW(buf,27) = hd->homunculus.level;
  1344. WBUFW(buf,29) = hd->homunculus.hunger;
  1345. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1346. WBUFW(buf,33) = 0; // equip id
  1347. #ifdef RENEWAL
  1348. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1349. #else
  1350. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1351. #endif
  1352. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1353. WBUFW(buf,39)=status->hit;
  1354. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1355. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1356. else
  1357. WBUFW(buf,41) = status->cri/10;
  1358. #ifdef RENEWAL
  1359. WBUFW(buf,43) = status->def + status->def2;
  1360. WBUFW(buf,45) = status->mdef + status->mdef2;
  1361. #else
  1362. WBUFW(buf,43) = status->def + status->vit;
  1363. WBUFW(buf,45) = status->mdef;
  1364. #endif
  1365. WBUFW(buf,47) = status->flee;
  1366. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1367. if (status->max_hp > INT16_MAX) {
  1368. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1369. WBUFW(buf,53+offset) = 100;
  1370. } else {
  1371. WBUFW(buf,51) = status->hp;
  1372. WBUFW(buf,53+offset) = status->max_hp;
  1373. }
  1374. #if PACKETVER >= 20141016
  1375. offset += 2;
  1376. #endif
  1377. if (status->max_sp > INT16_MAX) {
  1378. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1379. WBUFW(buf,57+offset) = 100;
  1380. } else {
  1381. WBUFW(buf,55+offset) = status->sp;
  1382. WBUFW(buf,57+offset) = status->max_sp;
  1383. }
  1384. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1385. WBUFL(buf,63+offset) = hd->exp_next;
  1386. switch( htype ) {
  1387. case HT_REG:
  1388. case HT_EVO:
  1389. if( hd->homunculus.level >= battle_config.hom_max_level )
  1390. WBUFL(buf,63+offset) = 0;
  1391. break;
  1392. case HT_S:
  1393. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1394. WBUFL(buf,63+offset) = 0;
  1395. break;
  1396. }
  1397. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1398. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1399. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1400. }
  1401. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1402. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1403. /// type:
  1404. /// unused
  1405. /// state:
  1406. /// 0 = pre-init
  1407. /// 1 = intimacy
  1408. /// 2 = hunger
  1409. /// 3 = accessory?
  1410. /// ? = ignored
  1411. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1412. { //[orn]
  1413. int fd = sd->fd;
  1414. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1415. hom_calc_skilltree(sd->hd, 0);
  1416. WFIFOHEAD(fd, packet_len(0x230));
  1417. WFIFOW(fd,0)=0x230;
  1418. WFIFOB(fd,2)=0;
  1419. WFIFOB(fd,3)=state;
  1420. WFIFOL(fd,4)=sd->hd->bl.id;
  1421. WFIFOL(fd,8)=param;
  1422. WFIFOSET(fd,packet_len(0x230));
  1423. }
  1424. int clif_homskillinfoblock(struct map_session_data *sd)
  1425. { //[orn]
  1426. struct homun_data *hd;
  1427. int fd = sd->fd;
  1428. int i, len=4;
  1429. nullpo_ret(sd);
  1430. hd = sd->hd;
  1431. if ( !hd )
  1432. return 0 ;
  1433. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1434. WFIFOW(fd,0)=0x235;
  1435. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1436. int id = hd->homunculus.hskill[i].id;
  1437. if( id != 0 ){
  1438. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1439. short idx = hom_skill_get_index(id);
  1440. if (idx == -1)
  1441. continue;
  1442. WFIFOW(fd,len ) = id;
  1443. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1444. WFIFOW(fd,len+4) = 0;
  1445. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1446. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1447. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[idx].lv);
  1448. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1449. 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;
  1450. len+=37;
  1451. }
  1452. }
  1453. WFIFOW(fd,2)=len;
  1454. WFIFOSET(fd,len);
  1455. return 0;
  1456. }
  1457. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1458. { //[orn]
  1459. struct homun_data *hd;
  1460. int fd;
  1461. short idx = -1;
  1462. nullpo_retv(sd);
  1463. if ((idx = hom_skill_get_index(skill_id) == -1))
  1464. return;
  1465. fd = sd->fd;
  1466. hd = sd->hd;
  1467. WFIFOHEAD(fd, packet_len(0x239));
  1468. WFIFOW(fd,0) = 0x239;
  1469. WFIFOW(fd,2) = skill_id;
  1470. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1471. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1472. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1473. 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;
  1474. WFIFOSET(fd,packet_len(0x239));
  1475. }
  1476. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1477. {
  1478. int fd=sd->fd;
  1479. WFIFOHEAD(fd,packet_len(0x22f));
  1480. WFIFOW(fd,0)=0x22f;
  1481. WFIFOB(fd,2)=fail;
  1482. WFIFOW(fd,3)=foodid;
  1483. WFIFOSET(fd,packet_len(0x22f));
  1484. return 0;
  1485. }
  1486. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1487. /// 0087 <walk start time>.L <walk data>.6B
  1488. void clif_walkok(struct map_session_data *sd)
  1489. {
  1490. int fd=sd->fd;
  1491. WFIFOHEAD(fd, packet_len(0x87));
  1492. WFIFOW(fd,0)=0x87;
  1493. WFIFOL(fd,2)=gettick();
  1494. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1495. WFIFOSET(fd,packet_len(0x87));
  1496. }
  1497. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1498. {
  1499. uint8 buf[128];
  1500. int len;
  1501. struct status_change *sc = NULL;
  1502. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1503. clif_ally_only = true;
  1504. len = clif_set_unit_walking(bl,ud,buf);
  1505. clif_send(buf,len,bl,AREA_WOS);
  1506. if (disguised(bl))
  1507. clif_setdisguise(bl, buf, len);
  1508. if(vd->cloth_color)
  1509. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1510. switch(bl->type) {
  1511. case BL_PC:
  1512. {
  1513. TBL_PC *sd = ((TBL_PC*)bl);
  1514. // clif_movepc(sd);
  1515. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1516. clif_specialeffect(&sd->bl,423,AREA);
  1517. else if(sd->state.size==SZ_MEDIUM)
  1518. clif_specialeffect(&sd->bl,421,AREA);
  1519. }
  1520. break;
  1521. case BL_MOB:
  1522. {
  1523. TBL_MOB *md = ((TBL_MOB*)bl);
  1524. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1525. clif_specialeffect(&md->bl,423,AREA);
  1526. else if(md->special_state.size==SZ_MEDIUM)
  1527. clif_specialeffect(&md->bl,421,AREA);
  1528. }
  1529. break;
  1530. case BL_PET:
  1531. if(vd->head_bottom) // needed to display pet equip properly
  1532. clif_pet_equip_area((TBL_PET*)bl);
  1533. break;
  1534. }
  1535. clif_ally_only = false;
  1536. }
  1537. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1538. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1539. /// Note: unit must not be self
  1540. void clif_move(struct unit_data *ud)
  1541. {
  1542. unsigned char buf[16];
  1543. struct view_data* vd;
  1544. struct block_list* bl = ud->bl;
  1545. struct status_change *sc = NULL;
  1546. vd = status_get_viewdata(bl);
  1547. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1548. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1549. /**
  1550. * Hide NPC from maya purple card.
  1551. **/
  1552. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1553. return;
  1554. if (ud->state.speed_changed) {
  1555. // Since we don't know how to update the speed of other objects,
  1556. // use the old walk packet to update the data.
  1557. ud->state.speed_changed = 0;
  1558. clif_move2(bl, vd, ud);
  1559. return;
  1560. }
  1561. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1562. clif_ally_only = true;
  1563. WBUFW(buf,0)=0x86;
  1564. WBUFL(buf,2)=bl->id;
  1565. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1566. WBUFL(buf,12)=gettick();
  1567. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1568. if (disguised(bl)) {
  1569. WBUFL(buf,2)=-bl->id;
  1570. clif_send(buf, packet_len(0x86), bl, SELF);
  1571. }
  1572. clif_ally_only = false;
  1573. }
  1574. /*==========================================
  1575. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1576. *------------------------------------------*/
  1577. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1578. {
  1579. struct map_session_data *sd = NULL;
  1580. //Remove player from map server
  1581. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1582. map_quit(sd);
  1583. return 0;
  1584. }
  1585. /*==========================================
  1586. *
  1587. *------------------------------------------*/
  1588. void clif_quitsave(int fd,struct map_session_data *sd) {
  1589. if (!battle_config.prevent_logout ||
  1590. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1591. map_quit(sd);
  1592. else if (sd->fd) {
  1593. //Disassociate session from player (session is deleted after this function was called)
  1594. //And set a timer to make him quit later.
  1595. session[sd->fd]->session_data = NULL;
  1596. sd->fd = 0;
  1597. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1598. }
  1599. }
  1600. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1601. /// 0091 <map name>.16B <x>.W <y>.W
  1602. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1603. {
  1604. int fd;
  1605. nullpo_retv(sd);
  1606. fd = sd->fd;
  1607. WFIFOHEAD(fd,packet_len(0x91));
  1608. WFIFOW(fd,0) = 0x91;
  1609. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1610. WFIFOW(fd,18) = x;
  1611. WFIFOW(fd,20) = y;
  1612. WFIFOSET(fd,packet_len(0x91));
  1613. }
  1614. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1615. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1616. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1617. {
  1618. int fd;
  1619. nullpo_retv(sd);
  1620. fd = sd->fd;
  1621. WFIFOHEAD(fd,packet_len(0x92));
  1622. WFIFOW(fd,0) = 0x92;
  1623. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1624. WFIFOW(fd,18) = x;
  1625. WFIFOW(fd,20) = y;
  1626. WFIFOL(fd,22) = htonl(ip);
  1627. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1628. WFIFOSET(fd,packet_len(0x92));
  1629. }
  1630. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1631. /// This function combines both calls and allows to simplify the calling code
  1632. void clif_blown(struct block_list *bl)
  1633. {
  1634. clif_slide(bl, bl->x, bl->y);
  1635. clif_fixpos(bl);
  1636. }
  1637. /// Visually moves(slides) a character to x,y. If the target cell
  1638. /// isn't walkable, the char doesn't move at all. If the char is
  1639. /// sitting it will stand up (ZC_STOPMOVE).
  1640. /// 0088 <id>.L <x>.W <y>.W
  1641. void clif_fixpos(struct block_list *bl)
  1642. {
  1643. unsigned char buf[10];
  1644. nullpo_retv(bl);
  1645. WBUFW(buf,0) = 0x88;
  1646. WBUFL(buf,2) = bl->id;
  1647. WBUFW(buf,6) = bl->x;
  1648. WBUFW(buf,8) = bl->y;
  1649. clif_send(buf, packet_len(0x88), bl, AREA);
  1650. if( disguised(bl) ) {
  1651. WBUFL(buf,2) = -bl->id;
  1652. clif_send(buf, packet_len(0x88), bl, SELF);
  1653. }
  1654. }
  1655. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1656. /// 00c4 <shop id>.L
  1657. void clif_npcbuysell(struct map_session_data* sd, int id)
  1658. {
  1659. int fd;
  1660. nullpo_retv(sd);
  1661. fd=sd->fd;
  1662. WFIFOHEAD(fd, packet_len(0xc4));
  1663. WFIFOW(fd,0)=0xc4;
  1664. WFIFOL(fd,2)=id;
  1665. WFIFOSET(fd,packet_len(0xc4));
  1666. }
  1667. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1668. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1669. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1670. {
  1671. int fd,i,c;
  1672. bool discount;
  1673. nullpo_retv(sd);
  1674. nullpo_retv(nd);
  1675. fd = sd->fd;
  1676. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1677. WFIFOW(fd,0) = 0xc6;
  1678. c = 0;
  1679. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1680. for( i = 0; i < nd->u.shop.count; i++ )
  1681. {
  1682. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1683. int val = nd->u.shop.shop_item[i].value;
  1684. if( id == NULL )
  1685. continue;
  1686. WFIFOL(fd, 4+c*11) = val;
  1687. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1688. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1689. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1690. c++;
  1691. }
  1692. WFIFOW(fd,2) = 4 + c*11;
  1693. WFIFOSET(fd,WFIFOW(fd,2));
  1694. }
  1695. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1696. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1697. void clif_selllist(struct map_session_data *sd)
  1698. {
  1699. int fd,i,c=0,val;
  1700. nullpo_retv(sd);
  1701. fd=sd->fd;
  1702. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1703. WFIFOW(fd,0)=0xc7;
  1704. for( i = 0; i < MAX_INVENTORY; i++ )
  1705. {
  1706. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1707. {
  1708. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1709. continue;
  1710. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1711. continue; // Cannot Sell Rental Items or Account Bounded Items
  1712. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1713. continue; // Don't allow sale of bound items
  1714. val=sd->inventory_data[i]->value_sell;
  1715. if( val < 0 )
  1716. continue;
  1717. WFIFOW(fd,4+c*10)=i+2;
  1718. WFIFOL(fd,6+c*10)=val;
  1719. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1720. c++;
  1721. }
  1722. }
  1723. WFIFOW(fd,2)=c*10+4;
  1724. WFIFOSET(fd,WFIFOW(fd,2));
  1725. }
  1726. /**
  1727. * Presents list of items, that can be sold to a Market shop.
  1728. * @author: Ind and Yommy
  1729. **/
  1730. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1731. #if PACKETVER >= 20131223
  1732. struct npc_item_list *shop = nd->u.shop.shop_item;
  1733. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1734. struct item_data *id = NULL;
  1735. struct s_packet_db *info;
  1736. int fd;
  1737. nullpo_retv(sd);
  1738. if (sd->state.trading)
  1739. return;
  1740. info = &packet_db[sd->packet_ver][cmd];
  1741. if (!info || info->len == 0)
  1742. return;
  1743. fd = sd->fd;
  1744. WFIFOHEAD(fd, 4 + shop_size * 13);
  1745. WFIFOW(fd,0) = cmd;
  1746. for (i = 0, c = 0; i < shop_size; i++) {
  1747. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1748. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1749. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1750. WFIFOL(fd, 7+c*13) = shop[i].value;
  1751. WFIFOL(fd,11+c*13) = shop[i].qty;
  1752. WFIFOW(fd,15+c*13) = (id->view_id > 0) ? id->view_id : id->nameid;
  1753. c++;
  1754. }
  1755. }
  1756. WFIFOW(fd,2) = 4 + c*13;
  1757. WFIFOSET(fd,WFIFOW(fd,2));
  1758. sd->state.trading = 1;
  1759. #endif
  1760. }
  1761. /// Closes the Market shop window.
  1762. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1763. nullpo_retv(sd);
  1764. sd->npc_shopid = 0;
  1765. sd->state.trading = 0;
  1766. }
  1767. /// Purchase item from Market shop.
  1768. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1769. #if PACKETVER >= 20131223
  1770. unsigned short cmd = 0x9d7, len = 0;
  1771. struct npc_data* nd;
  1772. uint8 result = (res == 0 ? 1 : 0);
  1773. int fd = 0;
  1774. struct s_packet_db *info;
  1775. nullpo_retv(sd);
  1776. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1777. info = &packet_db[sd->packet_ver][cmd];
  1778. if (!info || info->len == 0)
  1779. return;
  1780. fd = sd->fd;
  1781. len = 5 + 8*n;
  1782. WFIFOHEAD(fd, len);
  1783. WFIFOW(fd, 0) = cmd;
  1784. WFIFOW(fd, 2) = len;
  1785. if (result) {
  1786. uint8 i, j;
  1787. struct npc_item_list *shop = nd->u.shop.shop_item;
  1788. unsigned short count = nd->u.shop.count;
  1789. for (i = 0; i < n; i++) {
  1790. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1791. WFIFOW(fd, 7+i*8) = list[i].qty;
  1792. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1793. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1794. }
  1795. }
  1796. WFIFOB(fd, 4) = n;
  1797. WFIFOSET(fd, len);
  1798. #endif
  1799. }
  1800. /// Purchase item from Market shop.
  1801. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1802. #if PACKETVER >= 20131223
  1803. struct s_packet_db* info;
  1804. struct s_npc_buy_list *item_list;
  1805. uint16 len = 0, i = 0;
  1806. uint8 res = 0, n = 0;
  1807. nullpo_retv(sd);
  1808. if (!sd->npc_shopid)
  1809. return;
  1810. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  1811. if (!info || info->len == 0)
  1812. return;
  1813. len = RFIFOW(fd,info->pos[0]);
  1814. n = (len-4) / 6;
  1815. CREATE(item_list, struct s_npc_buy_list, n);
  1816. for (i = 0; i < n; i++) {
  1817. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1818. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1819. }
  1820. res = npc_buylist(sd, n, item_list);
  1821. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1822. aFree(item_list);
  1823. #endif
  1824. }
  1825. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1826. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1827. /// Client behavior (dialog window):
  1828. /// - disable mouse targeting
  1829. /// - open the dialog window
  1830. /// - set npcid of dialog window (0 by default)
  1831. /// - if set to clear on next mes, clear contents
  1832. /// - append this text
  1833. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1834. {
  1835. int fd = sd->fd;
  1836. int slen = strlen(mes) + 9;
  1837. WFIFOHEAD(fd, slen);
  1838. WFIFOW(fd,0)=0xb4;
  1839. WFIFOW(fd,2)=slen;
  1840. WFIFOL(fd,4)=npcid;
  1841. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1842. WFIFOSET(fd,WFIFOW(fd,2));
  1843. }
  1844. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1845. /// 00b5 <npc id>.L
  1846. /// Client behavior (dialog window):
  1847. /// - disable mouse targeting
  1848. /// - open the dialog window
  1849. /// - add 'next' button
  1850. /// When 'next' is pressed:
  1851. /// - 00B9 <npcid of dialog window>.L
  1852. /// - set to clear on next mes
  1853. /// - remove 'next' button
  1854. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1855. {
  1856. int fd;
  1857. nullpo_retv(sd);
  1858. fd=sd->fd;
  1859. WFIFOHEAD(fd, packet_len(0xb5));
  1860. WFIFOW(fd,0)=0xb5;
  1861. WFIFOL(fd,2)=npcid;
  1862. WFIFOSET(fd,packet_len(0xb5));
  1863. }
  1864. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1865. /// 00b6 <npc id>.L
  1866. /// Client behavior:
  1867. /// - if dialog window is open:
  1868. /// - remove 'next' button
  1869. /// - add 'close' button
  1870. /// - else:
  1871. /// - enable mouse targeting
  1872. /// - close the dialog window
  1873. /// - close the menu window
  1874. /// When 'close' is pressed:
  1875. /// - enable mouse targeting
  1876. /// - close the dialog window
  1877. /// - close the menu window
  1878. /// - 0146 <npcid of dialog window>.L
  1879. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1880. {
  1881. int fd;
  1882. nullpo_retv(sd);
  1883. fd=sd->fd;
  1884. WFIFOHEAD(fd, packet_len(0xb6));
  1885. WFIFOW(fd,0)=0xb6;
  1886. WFIFOL(fd,2)=npcid;
  1887. WFIFOSET(fd,packet_len(0xb6));
  1888. }
  1889. /**
  1890. * Close script when player is idle
  1891. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1892. * @author [Ind/Hercules]
  1893. * @param sd : player pointer
  1894. * @param npcid : npc gid to close
  1895. */
  1896. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1897. {
  1898. struct s_packet_db* info;
  1899. int16 len;
  1900. int cmd = 0;
  1901. int fd;
  1902. nullpo_retv(sd);
  1903. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1904. if(!cmd) cmd = 0x8d6; //default
  1905. info = &packet_db[sd->packet_ver][cmd];
  1906. len = info->len;
  1907. fd = sd->fd;
  1908. WFIFOHEAD(fd, len);
  1909. WFIFOW(fd,0)=0x8d6;
  1910. WFIFOL(fd,info->pos[0])=npcid;
  1911. WFIFOSET(fd,len);
  1912. }
  1913. /*==========================================
  1914. *
  1915. *------------------------------------------*/
  1916. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1917. unsigned char *buf;
  1918. int fd = sd->fd;
  1919. sd->state.using_fake_npc = 1;
  1920. WFIFOHEAD(fd, packet_len(0x78));
  1921. buf = WFIFOP(fd,0);
  1922. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1923. WBUFW(buf,0)=0x78;
  1924. #if PACKETVER >= 20071106
  1925. WBUFB(buf,2) = 0; // object type
  1926. buf = WFIFOP(fd,1);
  1927. #endif
  1928. WBUFL(buf,2)=npcid;
  1929. WBUFW(buf,14)=111;
  1930. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1931. WBUFB(buf,49)=5;
  1932. WBUFB(buf,50)=5;
  1933. WFIFOSET(fd, packet_len(0x78));
  1934. }
  1935. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1936. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1937. /// Client behavior:
  1938. /// - disable mouse targeting
  1939. /// - close the menu window
  1940. /// - open the menu window
  1941. /// - add options to the menu (separated in the text by ":")
  1942. /// - set npcid of menu window
  1943. /// - if dialog window is open:
  1944. /// - remove 'next' button
  1945. /// When 'ok' is pressed:
  1946. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1947. /// - close the menu window
  1948. /// When 'cancel' is pressed:
  1949. /// - 00B8 <npcid of menu window>.L <-1>.B
  1950. /// - enable mouse targeting
  1951. /// - close a bunch of windows...
  1952. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1953. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1954. /// TODO investigate behavior of other windows [FlavioJS]
  1955. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1956. {
  1957. int fd = sd->fd;
  1958. int slen = strlen(mes) + 9;
  1959. struct block_list *bl = NULL;
  1960. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1961. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1962. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1963. clif_sendfakenpc(sd, npcid);
  1964. WFIFOHEAD(fd, slen);
  1965. WFIFOW(fd,0)=0xb7;
  1966. WFIFOW(fd,2)=slen;
  1967. WFIFOL(fd,4)=npcid;
  1968. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1969. WFIFOSET(fd,WFIFOW(fd,2));
  1970. }
  1971. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1972. /// 0142 <npc id>.L
  1973. /// Client behavior (inputnum window):
  1974. /// - if npcid exists in the client:
  1975. /// - open the inputnum window
  1976. /// - set npcid of inputnum window
  1977. /// When 'ok' is pressed:
  1978. /// - if inputnum window has text:
  1979. /// - if npcid exists in the client:
  1980. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1981. /// - close inputnum window
  1982. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1983. {
  1984. int fd;
  1985. struct block_list *bl = NULL;
  1986. nullpo_retv(sd);
  1987. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1988. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1989. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1990. clif_sendfakenpc(sd, npcid);
  1991. fd=sd->fd;
  1992. WFIFOHEAD(fd, packet_len(0x142));
  1993. WFIFOW(fd,0)=0x142;
  1994. WFIFOL(fd,2)=npcid;
  1995. WFIFOSET(fd,packet_len(0x142));
  1996. }
  1997. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1998. /// 01d4 <npc id>.L
  1999. /// Client behavior (inputstr window):
  2000. /// - if npcid is 0 or npcid exists in the client:
  2001. /// - open the inputstr window
  2002. /// - set npcid of inputstr window
  2003. /// When 'ok' is pressed:
  2004. /// - if inputstr window has text and isn't an insult(manner.txt):
  2005. /// - if npcid is 0 or npcid exists in the client:
  2006. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2007. /// - close inputstr window
  2008. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2009. {
  2010. int fd;
  2011. struct block_list *bl = NULL;
  2012. nullpo_retv(sd);
  2013. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2014. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2015. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2016. clif_sendfakenpc(sd, npcid);
  2017. fd=sd->fd;
  2018. WFIFOHEAD(fd, packet_len(0x1d4));
  2019. WFIFOW(fd,0)=0x1d4;
  2020. WFIFOL(fd,2)=npcid;
  2021. WFIFOSET(fd,packet_len(0x1d4));
  2022. }
  2023. /// Marks a position on client's minimap (ZC_COMPASS).
  2024. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2025. /// npc id:
  2026. /// is ignored in the client
  2027. /// type:
  2028. /// 0 = display mark for 15 seconds
  2029. /// 1 = display mark until dead or teleported
  2030. /// 2 = remove mark
  2031. /// color:
  2032. /// 0x00RRGGBB
  2033. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2034. {
  2035. int fd;
  2036. nullpo_retv(sd);
  2037. fd=sd->fd;
  2038. WFIFOHEAD(fd, packet_len(0x144));
  2039. WFIFOW(fd,0)=0x144;
  2040. WFIFOL(fd,2)=npc_id;
  2041. WFIFOL(fd,6)=type;
  2042. WFIFOL(fd,10)=x;
  2043. WFIFOL(fd,14)=y;
  2044. WFIFOB(fd,18)=id;
  2045. WFIFOL(fd,19)=color;
  2046. WFIFOSET(fd,packet_len(0x144));
  2047. }
  2048. /// Displays an illustration image.
  2049. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2050. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2051. /// type:
  2052. /// 0 = bottom left corner
  2053. /// 1 = bottom middle
  2054. /// 2 = bottom right corner
  2055. /// 3 = middle of screen, inside a movable window
  2056. /// 4 = middle of screen, movable with a close button, chrome-less
  2057. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2058. {
  2059. int fd;
  2060. nullpo_retv(sd);
  2061. fd=sd->fd;
  2062. WFIFOHEAD(fd, packet_len(0x1b3));
  2063. WFIFOW(fd,0)=0x1b3;
  2064. strncpy((char*)WFIFOP(fd,2),image,64);
  2065. WFIFOB(fd,66)=type;
  2066. WFIFOSET(fd,packet_len(0x1b3));
  2067. }
  2068. /*==========================================
  2069. * Fills in card data from the given item and into the buffer. [Skotlex]
  2070. *------------------------------------------*/
  2071. static void clif_addcards(unsigned char* buf, struct item* item)
  2072. {
  2073. int i=0,j;
  2074. if( item == NULL ) { //Blank data
  2075. WBUFW(buf,0) = 0;
  2076. WBUFW(buf,2) = 0;
  2077. WBUFW(buf,4) = 0;
  2078. WBUFW(buf,6) = 0;
  2079. return;
  2080. }
  2081. if( item->card[0] == CARD0_PET ) { //pet eggs
  2082. WBUFW(buf,0) = 0;
  2083. WBUFW(buf,2) = 0;
  2084. WBUFW(buf,4) = 0;
  2085. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2086. return;
  2087. }
  2088. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2089. WBUFW(buf,0) = item->card[0];
  2090. WBUFW(buf,2) = item->card[1];
  2091. WBUFW(buf,4) = item->card[2];
  2092. WBUFW(buf,6) = item->card[3];
  2093. return;
  2094. }
  2095. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2096. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2097. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2098. //Normal items.
  2099. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2100. WBUFW(buf,0) = j;
  2101. else
  2102. WBUFW(buf,0) = item->card[i];
  2103. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2104. WBUFW(buf,2) = j;
  2105. else
  2106. WBUFW(buf,2) = item->card[i];
  2107. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2108. WBUFW(buf,4) = j;
  2109. else
  2110. WBUFW(buf,4) = item->card[i];
  2111. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2112. WBUFW(buf,6) = j;
  2113. else
  2114. WBUFW(buf,6) = item->card[i];
  2115. }
  2116. /// Fills in part of the item buffers that calls for variable bonuses data. [Rytech]
  2117. static void clif_add_random_options(unsigned char* buf, struct item* item)
  2118. {
  2119. // Dummy data used since this feature isnt supported yet (ITEM_RDM_OPT).
  2120. // A max of 5 random options can be supported.
  2121. int i;
  2122. for (i = 0; i < 5; i++){
  2123. WBUFW(buf,i*5+0) = 0; // OptIndex
  2124. WBUFW(buf,i*5+2) = 0; // Value
  2125. WBUFB(buf,i*5+4) = 0; // Param1
  2126. }
  2127. }
  2128. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2129. /// 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)
  2130. /// 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)
  2131. /// 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)
  2132. /// 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)
  2133. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V6)
  2134. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2135. {
  2136. int fd, header, offs=0;
  2137. #if PACKETVER < 20061218
  2138. header = 0xa0;
  2139. #elif PACKETVER < 20071002
  2140. header = 0x29a;
  2141. #elif PACKETVER < 20120925
  2142. header = 0x2d4;
  2143. #elif PACKETVER < 20150226
  2144. header = 0x990;
  2145. #else
  2146. header = 0xa0c;
  2147. #endif
  2148. nullpo_retv(sd);
  2149. fd = sd->fd;
  2150. if( !session_isActive(fd) ) //Sasuke-
  2151. return;
  2152. WFIFOHEAD(fd,packet_len(header));
  2153. if( fail )
  2154. {
  2155. WFIFOW(fd,offs+0) = header;
  2156. WFIFOW(fd,offs+2) = n+2;
  2157. WFIFOW(fd,offs+4) = amount;
  2158. WFIFOW(fd,offs+6) = 0;
  2159. WFIFOB(fd,offs+8) = 0;
  2160. WFIFOB(fd,offs+9) = 0;
  2161. WFIFOB(fd,offs+10) = 0;
  2162. WFIFOW(fd,offs+11) = 0;
  2163. WFIFOW(fd,offs+13) = 0;
  2164. WFIFOW(fd,offs+15) = 0;
  2165. WFIFOW(fd,offs+17) = 0;
  2166. #if PACKETVER < 20120925
  2167. WFIFOW(fd,offs+19) = 0;
  2168. #else
  2169. WFIFOL(fd,offs+19) = 0;
  2170. offs += 2;
  2171. #endif
  2172. WFIFOB(fd,offs+21) = 0;
  2173. WFIFOB(fd,offs+22) = fail;
  2174. #if PACKETVER >= 20061218
  2175. WFIFOL(fd,offs+23) = 0;
  2176. #endif
  2177. #if PACKETVER >= 20071002
  2178. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2179. #if PACKETVER >= 20150226
  2180. clif_add_random_options(WFIFOP(fd,offs+31), &sd->status.inventory[n]);
  2181. #endif
  2182. #endif
  2183. }
  2184. else
  2185. {
  2186. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2187. return;
  2188. WFIFOW(fd,offs+0) = header;
  2189. WFIFOW(fd,offs+2) = n+2;
  2190. WFIFOW(fd,offs+4) = amount;
  2191. if (sd->inventory_data[n]->view_id > 0)
  2192. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2193. else
  2194. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  2195. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  2196. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  2197. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  2198. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  2199. #if PACKETVER < 20120925
  2200. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2201. #else
  2202. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2203. offs += 2;
  2204. #endif
  2205. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2206. WFIFOB(fd,offs+22) = fail;
  2207. #if PACKETVER >= 20061218
  2208. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  2209. #endif
  2210. #if PACKETVER >= 20071002
  2211. /* Yellow color only for non-stackable item */
  2212. 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;
  2213. #endif
  2214. #if PACKETVER >= 20150226
  2215. clif_add_random_options(WFIFOP(fd,31), &sd->status.inventory[n]);
  2216. #endif
  2217. }
  2218. WFIFOSET(fd,packet_len(header));
  2219. }
  2220. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2221. /// 00af <index>.W <amount>.W
  2222. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2223. {
  2224. int fd;
  2225. nullpo_retv(sd);
  2226. fd=sd->fd;
  2227. WFIFOHEAD(fd, packet_len(0xaf));
  2228. WFIFOW(fd,0)=0xaf;
  2229. WFIFOW(fd,2)=n+2;
  2230. WFIFOW(fd,4)=amount;
  2231. WFIFOSET(fd,packet_len(0xaf));
  2232. }
  2233. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2234. /// 07fa <delete type>.W <index>.W <amount>.W
  2235. /// delete type:
  2236. /// 0 = Normal
  2237. /// 1 = Item used for a skill
  2238. /// 2 = Refine failed
  2239. /// 3 = Material changed
  2240. /// 4 = Moved to storage
  2241. /// 5 = Moved to cart
  2242. /// 6 = Item sold
  2243. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2244. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2245. {
  2246. #if PACKETVER < 20091117
  2247. clif_dropitem(sd,n,amount);
  2248. #else
  2249. int fd;
  2250. nullpo_retv(sd);
  2251. fd=sd->fd;
  2252. WFIFOHEAD(fd, packet_len(0x7fa));
  2253. WFIFOW(fd,0)=0x7fa;
  2254. WFIFOW(fd,2)=reason;
  2255. WFIFOW(fd,4)=n+2;
  2256. WFIFOW(fd,6)=amount;
  2257. WFIFOSET(fd,packet_len(0x7fa));
  2258. #endif
  2259. }
  2260. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2261. char normal = (equip < 0);
  2262. int offset = 0;
  2263. WBUFW(buf,n) = idx; //index
  2264. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2265. WBUFB(buf,n+4) = itemtype(id->nameid);
  2266. if (!normal){ //equip 31B
  2267. WBUFL(buf,n+5) = equip; //location
  2268. WBUFL(buf,n+9) = it->equip; //wear state
  2269. WBUFB(buf,n+13) = it->refine; //refine lvl
  2270. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2271. WBUFL(buf,n+22) = it->expire_time;
  2272. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2273. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2274. #if PACKETVER >= 20150226
  2275. //V6_ITEM_Option
  2276. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2277. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2278. offset += 26;
  2279. #endif
  2280. //V5_ITEM_flag
  2281. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2282. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2283. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2284. }
  2285. else { //normal 24B
  2286. WBUFW(buf,n+5) = it->amount;
  2287. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2288. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2289. WBUFL(buf,n+19) = it->expire_time;
  2290. //V5_ITEM_flag
  2291. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2292. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2293. }
  2294. }
  2295. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2296. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2297. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2298. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2299. #if PACKETVER >= 20120925
  2300. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2301. #else
  2302. WBUFW(buf,n) = idx; //index
  2303. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2304. WBUFB(buf,n+4) = itemtype(id->nameid);
  2305. WBUFB(buf,n+5) = it->identify;
  2306. if (equip >= 0) { //Equippable item 28.B
  2307. WBUFW(buf,n+6) = equip;
  2308. WBUFW(buf,n+8) = it->equip;
  2309. WBUFB(buf,n+10) = it->attribute;
  2310. WBUFB(buf,n+11) = it->refine;
  2311. clif_addcards(WBUFP(buf, n+12), it); //8B
  2312. #if PACKETVER >= 20071002
  2313. WBUFL(buf,n+20) = it->expire_time;
  2314. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2315. #endif
  2316. #if PACKETVER >= 20100629
  2317. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2318. #endif
  2319. } else { //Stackable item. 22.B
  2320. WBUFW(buf,n+6) = it->amount;
  2321. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2322. clif_addcards(WBUFP(buf, n+10), it); //8B
  2323. #if PACKETVER >= 20071002
  2324. WBUFL(buf,n+18) = it->expire_time;
  2325. #endif
  2326. }
  2327. #endif
  2328. }
  2329. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2330. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2331. void clif_inventorylist(struct map_session_data *sd) {
  2332. int i,n,ne,arrow=-1;
  2333. unsigned char *buf;
  2334. unsigned char *bufe;
  2335. #if PACKETVER < 5
  2336. const int s = 10; //Entry size
  2337. #elif PACKETVER < 20080102
  2338. const int s = 18;
  2339. #elif PACKETVER < 20120925
  2340. const int s = 22;
  2341. #else
  2342. const int s = 24;
  2343. #endif
  2344. #if PACKETVER < 20071002
  2345. const int se = 20;
  2346. #elif PACKETVER < 20100629
  2347. const int se = 26;
  2348. #elif PACKETVER < 20120925
  2349. const int se = 28;
  2350. #elif PACKETVER < 20150226
  2351. const int se = 31;
  2352. #else
  2353. const int se = 57;
  2354. #endif
  2355. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2356. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2357. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2358. {
  2359. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2360. continue;
  2361. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2362. { //Non-stackable (Equippable)
  2363. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2364. ne++;
  2365. }
  2366. else { //Stackable.
  2367. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2368. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2369. arrow=i;
  2370. n++;
  2371. }
  2372. }
  2373. if( n )
  2374. {
  2375. #if PACKETVER < 5
  2376. WBUFW(buf,0)=0xa3;
  2377. #elif PACKETVER < 20080102
  2378. WBUFW(buf,0)=0x1ee;
  2379. #elif PACKETVER < 20120925
  2380. WBUFW(buf,0)=0x2e8;
  2381. #else
  2382. WBUFW(buf,0)=0x991;
  2383. #endif
  2384. WBUFW(buf,2)=4+n*s;
  2385. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2386. }
  2387. if( arrow >= 0 )
  2388. clif_arrowequip(sd,arrow);
  2389. if( ne ) {
  2390. #if PACKETVER < 20071002
  2391. WBUFW(bufe,0)=0xa4;
  2392. #elif PACKETVER < 20120925
  2393. WBUFW(bufe,0)=0x2d0;
  2394. #elif PACKETVER < 20150226
  2395. WBUFW(bufe,0)=0x992;
  2396. #else
  2397. WBUFW(bufe,0)=0xa0d;
  2398. #endif
  2399. WBUFW(bufe,2)=4+ne*se;
  2400. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2401. }
  2402. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2403. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2404. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2405. continue;
  2406. if ( sd->status.inventory[i].favorite )
  2407. clif_favorite_item(sd, i);
  2408. }
  2409. #endif
  2410. if( buf ) aFree(buf);
  2411. if( bufe ) aFree(bufe);
  2412. }
  2413. //Required when items break/get-repaired. Only sends equippable item list.
  2414. void clif_equiplist(struct map_session_data *sd)
  2415. {
  2416. int i,n,fd = sd->fd;
  2417. unsigned char *buf;
  2418. #if PACKETVER < 20071002
  2419. const int cmd = 20;
  2420. #elif PACKETVER < 20100629
  2421. const int cmd = 26;
  2422. #elif PACKETVER < 20120925
  2423. const int cmd = 28;
  2424. #elif PACKETVER < 20150226
  2425. const int cmd = 31;
  2426. #else
  2427. const int cmd = 57;
  2428. #endif
  2429. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2430. buf = WFIFOP(fd,0);
  2431. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2432. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2433. continue;
  2434. if(itemdb_isstackable2(sd->inventory_data[i]))
  2435. continue;
  2436. //Equippable
  2437. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2438. n++;
  2439. }
  2440. if (n) {
  2441. #if PACKETVER < 20071002
  2442. WBUFW(buf,0)=0xa4;
  2443. #elif PACKETVER < 20120925
  2444. WBUFW(buf,0)=0x2d0;
  2445. #elif PACKETVER < 20150226
  2446. WBUFW(buf,0)=0x992;
  2447. #else
  2448. WBUFW(buf,0)=0xa0d;
  2449. #endif
  2450. WBUFW(buf,2)=4+n*cmd;
  2451. WFIFOSET(fd,WFIFOW(fd,2));
  2452. }
  2453. }
  2454. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2455. {
  2456. static const int client_buf = 0x5000; // Max buffer to send
  2457. struct item_data *id;
  2458. int i,n,ne,nn;
  2459. unsigned char *buf;
  2460. unsigned char *bufe;
  2461. #if PACKETVER < 5
  2462. const int s = 10; //Entry size.normal item
  2463. const int sidx=4; //start itemlist idx
  2464. const int cmd = 0xa5;
  2465. #elif PACKETVER < 20080102
  2466. const int s = 18;
  2467. const int sidx=4;
  2468. const int cmd = 0x1f0;
  2469. #elif PACKETVER < 20120925
  2470. const int s = 22;
  2471. const int sidx=4;
  2472. const int cmd = 0x2ea;
  2473. #else
  2474. const int s = 24;
  2475. const int sidx = 4+24;
  2476. const int cmd = 0x995;
  2477. #endif
  2478. #if PACKETVER < 20071002
  2479. const int se = 20; //entry size equip
  2480. const int sidxe = 4; //start itemlist idx
  2481. const int cmde = 0xa6;
  2482. #elif PACKETVER < 20100629
  2483. const int se = 26;
  2484. const int sidxe = 4;
  2485. const int cmde = 0x2d1;
  2486. #elif PACKETVER < 20120925
  2487. const int se = 28;
  2488. const int sidxe = 4;
  2489. const int cmde = 0x2d1;
  2490. #elif PACKETVER < 20150226
  2491. const int se = 31;
  2492. const int sidxe = 4+24;
  2493. const int cmde = 0x996;
  2494. #else
  2495. const int se = 57;
  2496. const int sidxe = 4+24;
  2497. const int cmde = 0xa10;
  2498. #endif
  2499. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2500. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2501. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2502. {
  2503. if( items[i].nameid <= 0 )
  2504. continue;
  2505. id = itemdb_search(items[i].nameid);
  2506. if( !itemdb_isstackable2(id) ) { //Equippable
  2507. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2508. ne++;
  2509. }
  2510. else { //Stackable
  2511. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2512. n++;
  2513. }
  2514. }
  2515. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2516. {
  2517. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2518. WFIFOHEAD(sd->fd,sidx+nn*s);
  2519. WFIFOW(sd->fd,0)=cmd;
  2520. WFIFOW(sd->fd,2)=sidx+nn*s;
  2521. #if PACKETVER >= 20120925
  2522. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2523. #endif
  2524. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2525. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2526. }
  2527. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2528. {
  2529. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2530. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2531. WFIFOW(sd->fd,0)=cmde;
  2532. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2533. #if PACKETVER >= 20120925
  2534. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2535. #endif
  2536. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2537. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2538. }
  2539. if( buf ) aFree(buf);
  2540. if( bufe ) aFree(bufe);
  2541. }
  2542. void clif_cartlist(struct map_session_data *sd)
  2543. {
  2544. struct item_data *id;
  2545. int i,n,ne;
  2546. unsigned char *buf;
  2547. unsigned char *bufe;
  2548. #if PACKETVER < 5
  2549. const int s = 10; //Entry size.
  2550. #elif PACKETVER < 20080102
  2551. const int s = 18;
  2552. #elif PACKETVER < 20120925
  2553. const int s = 22;
  2554. #else
  2555. const int s = 24;
  2556. #endif
  2557. #if PACKETVER < 20071002
  2558. const int cmd = 20;
  2559. #elif PACKETVER < 20100629
  2560. const int cmd = 26;
  2561. #elif PACKETVER < 20120925
  2562. const int cmd = 28;
  2563. #elif PACKETVER < 20150226
  2564. const int cmd = 31;
  2565. #else
  2566. const int cmd = 57;
  2567. #endif
  2568. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2569. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2570. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2571. {
  2572. if( sd->status.cart[i].nameid <= 0 )
  2573. continue;
  2574. id = itemdb_search(sd->status.cart[i].nameid);
  2575. if( !itemdb_isstackable2(id) ) { //Equippable
  2576. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2577. ne++;
  2578. }
  2579. else { //Stackable
  2580. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2581. n++;
  2582. }
  2583. }
  2584. if( n )
  2585. {
  2586. #if PACKETVER < 5
  2587. WBUFW(buf,0)=0x123;
  2588. #elif PACKETVER < 20080102
  2589. WBUFW(buf,0)=0x1ef;
  2590. #elif PACKETVER < 20120925
  2591. WBUFW(buf,0)=0x2e9;
  2592. #else
  2593. WBUFW(buf,0)=0x993;
  2594. #endif
  2595. WBUFW(buf,2)=4+n*s;
  2596. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2597. }
  2598. if( ne )
  2599. {
  2600. #if PACKETVER < 20071002
  2601. WBUFW(bufe,0)=0x122;
  2602. #elif PACKETVER < 20120925
  2603. WBUFW(bufe,0)=0x2d2;
  2604. #elif PACKETVER < 20150226
  2605. WBUFW(bufe,0)=0x994;
  2606. #else
  2607. WBUFW(bufe,0)=0xa0f;
  2608. #endif
  2609. WBUFW(bufe,2)=4+ne*cmd;
  2610. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2611. }
  2612. if( buf ) aFree(buf);
  2613. if( bufe ) aFree(bufe);
  2614. }
  2615. /// Removes cart (ZC_CARTOFF).
  2616. /// 012b
  2617. /// Client behaviour:
  2618. /// Closes the cart storage and removes all it's items from memory.
  2619. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2620. void clif_clearcart(int fd)
  2621. {
  2622. WFIFOHEAD(fd, packet_len(0x12b));
  2623. WFIFOW(fd,0) = 0x12b;
  2624. WFIFOSET(fd, packet_len(0x12b));
  2625. }
  2626. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2627. /// 01eb <account id>.L <x>.W <y>.W
  2628. void clif_guild_xy(struct map_session_data *sd)
  2629. {
  2630. unsigned char buf[10];
  2631. nullpo_retv(sd);
  2632. WBUFW(buf,0)=0x1eb;
  2633. WBUFL(buf,2)=sd->status.account_id;
  2634. WBUFW(buf,6)=sd->bl.x;
  2635. WBUFW(buf,8)=sd->bl.y;
  2636. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2637. }
  2638. /*==========================================
  2639. * Sends x/y dot to a single fd. [Skotlex]
  2640. *------------------------------------------*/
  2641. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2642. {
  2643. if( sd->bg_id )
  2644. return;
  2645. WFIFOHEAD(fd,packet_len(0x1eb));
  2646. WFIFOW(fd,0)=0x1eb;
  2647. WFIFOL(fd,2)=sd->status.account_id;
  2648. WFIFOW(fd,6)=sd->bl.x;
  2649. WFIFOW(fd,8)=sd->bl.y;
  2650. WFIFOSET(fd,packet_len(0x1eb));
  2651. }
  2652. // Guild XY locators [Valaris]
  2653. void clif_guild_xy_remove(struct map_session_data *sd)
  2654. {
  2655. unsigned char buf[10];
  2656. nullpo_retv(sd);
  2657. WBUFW(buf,0)=0x1eb;
  2658. WBUFL(buf,2)=sd->status.account_id;
  2659. WBUFW(buf,6)=-1;
  2660. WBUFW(buf,8)=-1;
  2661. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2662. }
  2663. /*==========================================
  2664. *
  2665. *------------------------------------------*/
  2666. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2667. {
  2668. struct map_session_data *sd, *tsd;
  2669. #if PACKETVER < 20100126
  2670. const int cmd = 0x106;
  2671. #else
  2672. const int cmd = 0x80e;
  2673. #endif
  2674. sd = va_arg(ap, struct map_session_data *);
  2675. tsd = (TBL_PC *)bl;
  2676. nullpo_ret(sd);
  2677. nullpo_ret(tsd);
  2678. if( !tsd->fd || tsd == sd )
  2679. return 0;
  2680. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2681. return 0;
  2682. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2683. WFIFOW(tsd->fd,0) = cmd;
  2684. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2685. #if PACKETVER < 20100126
  2686. if( sd->battle_status.max_hp > INT16_MAX )
  2687. { //To correctly display the %hp bar. [Skotlex]
  2688. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2689. WFIFOW(tsd->fd,8) = 100;
  2690. } else {
  2691. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2692. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2693. }
  2694. #else
  2695. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2696. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2697. #endif
  2698. WFIFOSET(tsd->fd,packet_len(cmd));
  2699. return 0;
  2700. }
  2701. /*==========================================
  2702. * Server tells all players that are allowed to view HP bars
  2703. * and are nearby 'sd' that 'sd' hp bar was updated.
  2704. *------------------------------------------*/
  2705. static int clif_hpmeter(struct map_session_data *sd)
  2706. {
  2707. nullpo_ret(sd);
  2708. 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);
  2709. return 0;
  2710. }
  2711. /// Notifies client of a character parameter change.
  2712. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2713. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2714. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2715. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2716. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2717. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2718. /// TODO: Extract individual packets.
  2719. /// FIXME: Packet lengths from packet_len(cmd)
  2720. void clif_updatestatus(struct map_session_data *sd,int type)
  2721. {
  2722. int fd,len=8;
  2723. nullpo_retv(sd);
  2724. fd=sd->fd;
  2725. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2726. return;
  2727. WFIFOHEAD(fd, 14);
  2728. WFIFOW(fd,0)=0xb0;
  2729. WFIFOW(fd,2)=type;
  2730. switch(type){
  2731. // 00b0
  2732. case SP_WEIGHT:
  2733. pc_updateweightstatus(sd);
  2734. WFIFOHEAD(fd,14);
  2735. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2736. WFIFOW(fd,2)=type;
  2737. WFIFOL(fd,4)=sd->weight;
  2738. break;
  2739. case SP_MAXWEIGHT:
  2740. WFIFOL(fd,4)=sd->max_weight;
  2741. break;
  2742. case SP_SPEED:
  2743. WFIFOL(fd,4)=sd->battle_status.speed;
  2744. break;
  2745. case SP_BASELEVEL:
  2746. WFIFOL(fd,4)=sd->status.base_level;
  2747. break;
  2748. case SP_JOBLEVEL:
  2749. WFIFOL(fd,4)=sd->status.job_level;
  2750. break;
  2751. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2752. WFIFOL(fd,4)=sd->status.karma;
  2753. break;
  2754. case SP_MANNER:
  2755. WFIFOL(fd,4)=sd->status.manner;
  2756. break;
  2757. case SP_STATUSPOINT:
  2758. WFIFOL(fd,4)=sd->status.status_point;
  2759. break;
  2760. case SP_SKILLPOINT:
  2761. WFIFOL(fd,4)=sd->status.skill_point;
  2762. break;
  2763. case SP_HIT:
  2764. WFIFOL(fd,4)=sd->battle_status.hit;
  2765. break;
  2766. case SP_FLEE1:
  2767. WFIFOL(fd,4)=sd->battle_status.flee;
  2768. break;
  2769. case SP_FLEE2:
  2770. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2771. break;
  2772. case SP_MAXHP:
  2773. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2774. break;
  2775. case SP_MAXSP:
  2776. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2777. break;
  2778. case SP_HP:
  2779. // On officials the HP never go below 1, even if you die [Lemongrass]
  2780. WFIFOL(fd,4)=max(1,sd->battle_status.hp);
  2781. // TODO: Won't these overwrite the current packet?
  2782. if( map[sd->bl.m].hpmeter_visible )
  2783. clif_hpmeter(sd);
  2784. if( !battle_config.party_hp_mode && sd->status.party_id )
  2785. clif_party_hp(sd);
  2786. if( sd->bg_id )
  2787. clif_bg_hp(sd);
  2788. break;
  2789. case SP_SP:
  2790. WFIFOL(fd,4)=sd->battle_status.sp;
  2791. break;
  2792. case SP_ASPD:
  2793. WFIFOL(fd,4)=sd->battle_status.amotion;
  2794. break;
  2795. case SP_ATK1:
  2796. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2797. break;
  2798. case SP_DEF1:
  2799. WFIFOL(fd,4)=pc_leftside_def(sd);
  2800. break;
  2801. case SP_MDEF1:
  2802. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2803. break;
  2804. case SP_ATK2:
  2805. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2806. break;
  2807. case SP_DEF2:
  2808. WFIFOL(fd,4)=pc_rightside_def(sd);
  2809. break;
  2810. case SP_MDEF2: {
  2811. //negative check (in case you have something like Berserk active)
  2812. int mdef2 = pc_rightside_mdef(sd);
  2813. WFIFOL(fd,4)=
  2814. #ifndef RENEWAL
  2815. ( mdef2 < 0 ) ? 0 :
  2816. #endif
  2817. mdef2;
  2818. }
  2819. break;
  2820. case SP_CRITICAL:
  2821. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2822. break;
  2823. case SP_MATK1:
  2824. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2825. break;
  2826. case SP_MATK2:
  2827. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2828. break;
  2829. case SP_ZENY:
  2830. WFIFOW(fd,0)=0xb1;
  2831. WFIFOL(fd,4)=sd->status.zeny;
  2832. break;
  2833. case SP_BASEEXP:
  2834. WFIFOW(fd,0)=0xb1;
  2835. WFIFOL(fd,4)=sd->status.base_exp;
  2836. break;
  2837. case SP_JOBEXP:
  2838. WFIFOW(fd,0)=0xb1;
  2839. WFIFOL(fd,4)=sd->status.job_exp;
  2840. break;
  2841. case SP_NEXTBASEEXP:
  2842. WFIFOW(fd,0)=0xb1;
  2843. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2844. break;
  2845. case SP_NEXTJOBEXP:
  2846. WFIFOW(fd,0)=0xb1;
  2847. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2848. break;
  2849. /**
  2850. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2851. **/
  2852. case SP_USTR:
  2853. case SP_UAGI:
  2854. case SP_UVIT:
  2855. case SP_UINT:
  2856. case SP_UDEX:
  2857. case SP_ULUK:
  2858. WFIFOW(fd,0)=0xbe;
  2859. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2860. len=5;
  2861. break;
  2862. /**
  2863. * Tells the client how far it is allowed to attack (weapon range)
  2864. **/
  2865. case SP_ATTACKRANGE:
  2866. WFIFOW(fd,0)=0x13a;
  2867. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2868. len=4;
  2869. break;
  2870. case SP_STR:
  2871. WFIFOW(fd,0)=0x141;
  2872. WFIFOL(fd,2)=type;
  2873. WFIFOL(fd,6)=sd->status.str;
  2874. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2875. len=14;
  2876. break;
  2877. case SP_AGI:
  2878. WFIFOW(fd,0)=0x141;
  2879. WFIFOL(fd,2)=type;
  2880. WFIFOL(fd,6)=sd->status.agi;
  2881. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2882. len=14;
  2883. break;
  2884. case SP_VIT:
  2885. WFIFOW(fd,0)=0x141;
  2886. WFIFOL(fd,2)=type;
  2887. WFIFOL(fd,6)=sd->status.vit;
  2888. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2889. len=14;
  2890. break;
  2891. case SP_INT:
  2892. WFIFOW(fd,0)=0x141;
  2893. WFIFOL(fd,2)=type;
  2894. WFIFOL(fd,6)=sd->status.int_;
  2895. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2896. len=14;
  2897. break;
  2898. case SP_DEX:
  2899. WFIFOW(fd,0)=0x141;
  2900. WFIFOL(fd,2)=type;
  2901. WFIFOL(fd,6)=sd->status.dex;
  2902. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2903. len=14;
  2904. break;
  2905. case SP_LUK:
  2906. WFIFOW(fd,0)=0x141;
  2907. WFIFOL(fd,2)=type;
  2908. WFIFOL(fd,6)=sd->status.luk;
  2909. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2910. len=14;
  2911. break;
  2912. case SP_CARTINFO:
  2913. WFIFOW(fd,0)=0x121;
  2914. WFIFOW(fd,2)=sd->cart_num;
  2915. WFIFOW(fd,4)=MAX_CART;
  2916. WFIFOL(fd,6)=sd->cart_weight;
  2917. WFIFOL(fd,10)=sd->cart_weight_max;
  2918. len=14;
  2919. break;
  2920. default:
  2921. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2922. return;
  2923. }
  2924. WFIFOSET(fd,len);
  2925. }
  2926. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2927. /// 01ab <account id>.L <var id>.W <value>.L
  2928. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2929. {
  2930. unsigned char buf[12];
  2931. nullpo_retv(sd);
  2932. WBUFW(buf,0)=0x1ab;
  2933. WBUFL(buf,2)=sd->bl.id;
  2934. WBUFW(buf,6)=type;
  2935. switch(type)
  2936. {
  2937. case SP_MANNER:
  2938. WBUFL(buf,8)=val;
  2939. break;
  2940. default:
  2941. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2942. return;
  2943. }
  2944. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2945. }
  2946. /// Updates sprite/style properties of an object.
  2947. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2948. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2949. void clif_changelook(struct block_list *bl,int type,int val)
  2950. {
  2951. unsigned char buf[16];
  2952. struct map_session_data* sd;
  2953. struct status_change* sc;
  2954. struct view_data* vd;
  2955. enum send_target target = AREA;
  2956. nullpo_retv(bl);
  2957. sd = BL_CAST(BL_PC, bl);
  2958. sc = status_get_sc(bl);
  2959. vd = status_get_viewdata(bl);
  2960. //nullpo_ret(vd);
  2961. if( vd ) //temp hack to let Warp Portal change appearance
  2962. switch(type)
  2963. {
  2964. case LOOK_WEAPON:
  2965. if (sd)
  2966. {
  2967. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2968. val = vd->weapon;
  2969. }
  2970. else vd->weapon = val;
  2971. break;
  2972. case LOOK_SHIELD:
  2973. if (sd)
  2974. {
  2975. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2976. val = vd->shield;
  2977. }
  2978. else vd->shield = val;
  2979. break;
  2980. case LOOK_BASE:
  2981. if (!sd) break;
  2982. if (sd->sc.option&OPTION_COSTUME)
  2983. vd->weapon = vd->shield = 0;
  2984. if (!vd->cloth_color)
  2985. break;
  2986. if (sd) {
  2987. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2988. vd->cloth_color = 0;
  2989. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2990. vd->cloth_color = 0;
  2991. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2992. vd->cloth_color = 0;
  2993. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2994. vd->cloth_color = 0;
  2995. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2996. vd->cloth_color = 0;
  2997. }
  2998. break;
  2999. case LOOK_HAIR:
  3000. vd->hair_style = val;
  3001. break;
  3002. case LOOK_HEAD_BOTTOM:
  3003. vd->head_bottom = val;
  3004. break;
  3005. case LOOK_HEAD_TOP:
  3006. vd->head_top = val;
  3007. break;
  3008. case LOOK_HEAD_MID:
  3009. vd->head_mid = val;
  3010. break;
  3011. case LOOK_HAIR_COLOR:
  3012. vd->hair_color = val;
  3013. break;
  3014. case LOOK_CLOTHES_COLOR:
  3015. if (val && sd) {
  3016. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3017. val = 0;
  3018. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3019. val = 0;
  3020. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3021. val = 0;
  3022. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3023. val = 0;
  3024. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3025. val = 0;
  3026. }
  3027. vd->cloth_color = val;
  3028. break;
  3029. case LOOK_SHOES:
  3030. #if PACKETVER > 3
  3031. if (sd) {
  3032. int n;
  3033. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3034. if(sd->inventory_data[n]->view_id > 0)
  3035. val = sd->inventory_data[n]->view_id;
  3036. else
  3037. val = sd->status.inventory[n].nameid;
  3038. } else
  3039. val = 0;
  3040. }
  3041. #endif
  3042. //Shoes? No packet uses this....
  3043. break;
  3044. case LOOK_BODY:
  3045. // unknown purpose
  3046. break;
  3047. case LOOK_ROBE:
  3048. #if PACKETVER < 20110111
  3049. return;
  3050. #else
  3051. vd->robe = val;
  3052. #endif
  3053. break;
  3054. }
  3055. // prevent leaking the presence of GM-hidden objects
  3056. if( sc && sc->option&OPTION_INVISIBLE )
  3057. target = SELF;
  3058. #if PACKETVER < 4
  3059. WBUFW(buf,0)=0xc3;
  3060. WBUFL(buf,2)=bl->id;
  3061. WBUFB(buf,6)=type;
  3062. WBUFB(buf,7)=val;
  3063. clif_send(buf,packet_len(0xc3),bl,target);
  3064. #else
  3065. WBUFW(buf,0)=0x1d7;
  3066. WBUFL(buf,2)=bl->id;
  3067. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3068. WBUFB(buf,6)=LOOK_WEAPON;
  3069. WBUFW(buf,7)=vd->weapon;
  3070. WBUFW(buf,9)=vd->shield;
  3071. } else {
  3072. WBUFB(buf,6)=type;
  3073. WBUFL(buf,7)=val;
  3074. }
  3075. clif_send(buf,packet_len(0x1d7),bl,target);
  3076. #endif
  3077. }
  3078. //Sends a change-base-look packet required for traps as they are triggered.
  3079. void clif_changetraplook(struct block_list *bl,int val)
  3080. {
  3081. unsigned char buf[32];
  3082. #if PACKETVER < 4
  3083. WBUFW(buf,0)=0xc3;
  3084. WBUFL(buf,2)=bl->id;
  3085. WBUFB(buf,6)=LOOK_BASE;
  3086. WBUFB(buf,7)=val;
  3087. clif_send(buf,packet_len(0xc3),bl,AREA);
  3088. #else
  3089. WBUFW(buf,0)=0x1d7;
  3090. WBUFL(buf,2)=bl->id;
  3091. WBUFB(buf,6)=LOOK_BASE;
  3092. WBUFW(buf,7)=val;
  3093. WBUFW(buf,9)=0;
  3094. clif_send(buf,packet_len(0x1d7),bl,AREA);
  3095. #endif
  3096. }
  3097. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3098. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  3099. {
  3100. unsigned char buf[32];
  3101. #if PACKETVER < 4
  3102. WBUFW(buf,0)=0xc3;
  3103. WBUFL(buf,2)=id;
  3104. WBUFB(buf,6)=type;
  3105. WBUFB(buf,7)=val;
  3106. clif_send(buf,packet_len(0xc3),bl,target);
  3107. #else
  3108. WBUFW(buf,0)=0x1d7;
  3109. WBUFL(buf,2)=id;
  3110. WBUFB(buf,6)=type;
  3111. WBUFW(buf,7)=val;
  3112. WBUFW(buf,9)=0;
  3113. clif_send(buf,packet_len(0x1d7),bl,target);
  3114. #endif
  3115. }
  3116. /// Character status (ZC_STATUS).
  3117. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3118. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3119. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3120. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3121. void clif_initialstatus(struct map_session_data *sd) {
  3122. int fd, mdef2;
  3123. unsigned char *buf;
  3124. nullpo_retv(sd);
  3125. fd=sd->fd;
  3126. WFIFOHEAD(fd,packet_len(0xbd));
  3127. buf=WFIFOP(fd,0);
  3128. WBUFW(buf,0)=0xbd;
  3129. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  3130. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  3131. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  3132. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  3133. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  3134. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  3135. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  3136. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  3137. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  3138. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  3139. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  3140. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  3141. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  3142. WBUFW(buf,16) = pc_leftside_atk(sd);
  3143. WBUFW(buf,18) = pc_rightside_atk(sd);
  3144. WBUFW(buf,20) = pc_rightside_matk(sd);
  3145. WBUFW(buf,22) = pc_leftside_matk(sd);
  3146. WBUFW(buf,24) = pc_leftside_def(sd);
  3147. WBUFW(buf,26) = pc_rightside_def(sd);
  3148. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3149. mdef2 = pc_rightside_mdef(sd);
  3150. WBUFW(buf,30) =
  3151. #ifndef RENEWAL
  3152. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3153. #endif
  3154. mdef2;
  3155. WBUFW(buf,32) = sd->battle_status.hit;
  3156. WBUFW(buf,34) = sd->battle_status.flee;
  3157. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3158. WBUFW(buf,38) = sd->battle_status.cri/10;
  3159. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3160. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3161. WFIFOSET(fd,packet_len(0xbd));
  3162. clif_updatestatus(sd,SP_STR);
  3163. clif_updatestatus(sd,SP_AGI);
  3164. clif_updatestatus(sd,SP_VIT);
  3165. clif_updatestatus(sd,SP_INT);
  3166. clif_updatestatus(sd,SP_DEX);
  3167. clif_updatestatus(sd,SP_LUK);
  3168. clif_updatestatus(sd,SP_ATTACKRANGE);
  3169. clif_updatestatus(sd,SP_ASPD);
  3170. }
  3171. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3172. /// 013c <index>.W
  3173. void clif_arrowequip(struct map_session_data *sd,int val)
  3174. {
  3175. int fd;
  3176. nullpo_retv(sd);
  3177. #if PACKETVER >= 20121128
  3178. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3179. #endif
  3180. fd=sd->fd;
  3181. WFIFOHEAD(fd, packet_len(0x013c));
  3182. WFIFOW(fd,0)=0x013c;
  3183. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  3184. WFIFOSET(fd,packet_len(0x013c));
  3185. }
  3186. /// Ammunition action message (ZC_ACTION_FAILURE).
  3187. /// 013b <type>.W
  3188. /// type:
  3189. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3190. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3191. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3192. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3193. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3194. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3195. void clif_arrow_fail(struct map_session_data *sd,int type)
  3196. {
  3197. int fd;
  3198. nullpo_retv(sd);
  3199. fd=sd->fd;
  3200. WFIFOHEAD(fd, packet_len(0x013b));
  3201. WFIFOW(fd,0)=0x013b;
  3202. WFIFOW(fd,2)=type;
  3203. WFIFOSET(fd,packet_len(0x013b));
  3204. }
  3205. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3206. /// 01ad <packet len>.W { <name id>.W }*
  3207. void clif_arrow_create_list(struct map_session_data *sd)
  3208. {
  3209. int i, c;
  3210. int fd;
  3211. nullpo_retv(sd);
  3212. fd = sd->fd;
  3213. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3214. WFIFOW(fd,0) = 0x1ad;
  3215. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3216. short j, nameid = skill_arrow_db[i].nameid;
  3217. if (nameid > 0 && itemdb_exists(nameid) &&
  3218. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3219. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3220. {
  3221. if ((j = itemdb_viewid(nameid)) > 0)
  3222. WFIFOW(fd,c*2+4) = j;
  3223. else
  3224. WFIFOW(fd,c*2+4) = nameid;
  3225. c++;
  3226. }
  3227. }
  3228. WFIFOW(fd,2) = c*2+4;
  3229. WFIFOSET(fd, WFIFOW(fd,2));
  3230. if (c > 0) {
  3231. sd->menuskill_id = AC_MAKINGARROW;
  3232. sd->menuskill_val = c;
  3233. }
  3234. }
  3235. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3236. /// 00bc <status id>.W <result>.B <value>.B
  3237. /// status id:
  3238. /// SP_STR ~ SP_LUK
  3239. /// result:
  3240. /// 0 = failure
  3241. /// 1 = success
  3242. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3243. {
  3244. int fd;
  3245. nullpo_retv(sd);
  3246. fd=sd->fd;
  3247. WFIFOHEAD(fd,packet_len(0xbc));
  3248. WFIFOW(fd,0)=0xbc;
  3249. WFIFOW(fd,2)=type;
  3250. WFIFOB(fd,4)=ok;
  3251. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3252. WFIFOSET(fd,packet_len(0xbc));
  3253. }
  3254. /// Notifies the client about the result of a request to equip an item.
  3255. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3256. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3257. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3258. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3259. /// @ok: //inversed forv2 v5
  3260. /// 0 = failure
  3261. /// 1 = success
  3262. /// 2 = failure due to low level
  3263. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3264. {
  3265. int fd = 0, cmd = 0, look = 0;
  3266. struct s_packet_db *info = NULL;
  3267. nullpo_retv(sd);
  3268. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3269. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3270. return;
  3271. fd = sd->fd;
  3272. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3273. look = sd->inventory_data[n]->look;
  3274. WFIFOHEAD(fd, info->len);
  3275. WFIFOW(fd, 0) = cmd;
  3276. WFIFOW(fd, info->pos[0]) = n+2;
  3277. switch (cmd) {
  3278. case 0xaa:
  3279. WFIFOW(fd, info->pos[1]) = pos;
  3280. if (sd->packet_ver < date2version(20100629))
  3281. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3282. else {
  3283. WFIFOL(fd, info->pos[2]) = look;
  3284. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3285. }
  3286. break;
  3287. case 0x8d0:
  3288. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3289. flag = 1;
  3290. case 0x999:
  3291. if (cmd == 0x999)
  3292. WFIFOL(fd, info->pos[1]) = pos;
  3293. else
  3294. WFIFOW(fd, info->pos[1]) = pos;
  3295. WFIFOL(fd, info->pos[2]) = look;
  3296. WFIFOW(fd, info->pos[3]) = flag;
  3297. break;
  3298. }
  3299. WFIFOSET(fd, info->len);
  3300. }
  3301. /// Notifies the client about the result of a request to take off an item.
  3302. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3303. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3304. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3305. /// @ok : //inversed for v2 v5
  3306. /// 0 = failure
  3307. /// 1 = success
  3308. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3309. {
  3310. int fd,header,offs=0;
  3311. #if PACKETVER >= 20130000
  3312. header = 0x99a;
  3313. ok = ok ? 0:1;
  3314. #elif PACKETVER >= 20110824
  3315. header = 0x8d1;
  3316. ok = ok ? 0:1;
  3317. #else
  3318. header = 0xac;
  3319. #endif
  3320. nullpo_retv(sd);
  3321. fd=sd->fd;
  3322. WFIFOHEAD(fd,packet_len(header));
  3323. WFIFOW(fd,offs+0)=header;
  3324. WFIFOW(fd,offs+2)=n+2;
  3325. #if PACKETVER >= 20130000
  3326. WFIFOL(fd,offs+4)=pos;
  3327. offs +=2;
  3328. #else
  3329. WFIFOW(fd,offs+4)=pos;
  3330. #endif
  3331. WFIFOB(fd,offs+6)=ok;
  3332. WFIFOSET(fd,packet_len(header));
  3333. }
  3334. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3335. /// 019b <id>.L <effect id>.L
  3336. /// effect id:
  3337. /// 0 = base level up
  3338. /// 1 = job level up
  3339. /// 2 = refine failure
  3340. /// 3 = refine success
  3341. /// 4 = game over
  3342. /// 5 = pharmacy success
  3343. /// 6 = pharmacy failure
  3344. /// 7 = base level up (super novice)
  3345. /// 8 = job level up (super novice)
  3346. /// 9 = base level up (taekwon)
  3347. void clif_misceffect(struct block_list* bl,int type)
  3348. {
  3349. unsigned char buf[32];
  3350. nullpo_retv(bl);
  3351. WBUFW(buf,0) = 0x19b;
  3352. WBUFL(buf,2) = bl->id;
  3353. WBUFL(buf,6) = type;
  3354. clif_send(buf,packet_len(0x19b),bl,AREA);
  3355. }
  3356. /// Notifies clients in the area of a state change.
  3357. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3358. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3359. void clif_changeoption(struct block_list* bl)
  3360. {
  3361. unsigned char buf[32];
  3362. struct status_change *sc;
  3363. struct map_session_data* sd;
  3364. nullpo_retv(bl);
  3365. sc = status_get_sc(bl);
  3366. if (!sc) return; //How can an option change if there's no sc?
  3367. sd = BL_CAST(BL_PC, bl);
  3368. #if PACKETVER >= 7
  3369. WBUFW(buf,0) = 0x229;
  3370. WBUFL(buf,2) = bl->id;
  3371. WBUFW(buf,6) = sc->opt1;
  3372. WBUFW(buf,8) = sc->opt2;
  3373. WBUFL(buf,10) = sc->option;
  3374. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3375. if(disguised(bl)) {
  3376. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3377. WBUFL(buf,2) = -bl->id;
  3378. clif_send(buf,packet_len(0x229),bl,SELF);
  3379. WBUFL(buf,2) = bl->id;
  3380. WBUFL(buf,10) = OPTION_INVISIBLE;
  3381. clif_send(buf,packet_len(0x229),bl,SELF);
  3382. } else
  3383. clif_send(buf,packet_len(0x229),bl,AREA);
  3384. #else
  3385. WBUFW(buf,0) = 0x119;
  3386. WBUFL(buf,2) = bl->id;
  3387. WBUFW(buf,6) = sc->opt1;
  3388. WBUFW(buf,8) = sc->opt2;
  3389. WBUFW(buf,10) = sc->option;
  3390. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3391. if(disguised(bl)) {
  3392. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3393. WBUFL(buf,2) = -bl->id;
  3394. clif_send(buf,packet_len(0x119),bl,SELF);
  3395. WBUFL(buf,2) = bl->id;
  3396. WBUFW(buf,10) = OPTION_INVISIBLE;
  3397. clif_send(buf,packet_len(0x119),bl,SELF);
  3398. } else
  3399. clif_send(buf,packet_len(0x119),bl,AREA);
  3400. #endif
  3401. }
  3402. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3403. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3404. void clif_changeoption2(struct block_list* bl)
  3405. {
  3406. unsigned char buf[20];
  3407. struct status_change *sc;
  3408. sc = status_get_sc(bl);
  3409. if (!sc) return; //How can an option change if there's no sc?
  3410. WBUFW(buf,0) = 0x28a;
  3411. WBUFL(buf,2) = bl->id;
  3412. WBUFL(buf,6) = sc->option;
  3413. WBUFL(buf,10) = clif_setlevel(bl);
  3414. WBUFL(buf,14) = sc->opt3;
  3415. if(disguised(bl)) {
  3416. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3417. WBUFL(buf,2) = -bl->id;
  3418. clif_send(buf,packet_len(0x28a),bl,SELF);
  3419. WBUFL(buf,2) = bl->id;
  3420. WBUFL(buf,6) = OPTION_INVISIBLE;
  3421. clif_send(buf,packet_len(0x28a),bl,SELF);
  3422. } else
  3423. clif_send(buf,packet_len(0x28a),bl,AREA);
  3424. }
  3425. /// Notifies the client about the result of an item use request.
  3426. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3427. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3428. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3429. {
  3430. nullpo_retv(sd);
  3431. if(!ok) {
  3432. int fd=sd->fd;
  3433. WFIFOHEAD(fd,packet_len(0xa8));
  3434. WFIFOW(fd,0)=0xa8;
  3435. WFIFOW(fd,2)=index+2;
  3436. WFIFOW(fd,4)=amount;
  3437. WFIFOB(fd,6)=ok;
  3438. WFIFOSET(fd,packet_len(0xa8));
  3439. }
  3440. else {
  3441. #if PACKETVER < 3
  3442. int fd=sd->fd;
  3443. WFIFOHEAD(fd,packet_len(0xa8));
  3444. WFIFOW(fd,0)=0xa8;
  3445. WFIFOW(fd,2)=index+2;
  3446. WFIFOW(fd,4)=amount;
  3447. WFIFOB(fd,6)=ok;
  3448. WFIFOSET(fd,packet_len(0xa8));
  3449. #else
  3450. unsigned char buf[32];
  3451. WBUFW(buf,0)=0x1c8;
  3452. WBUFW(buf,2)=index+2;
  3453. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3454. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3455. else
  3456. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3457. WBUFL(buf,6)=sd->bl.id;
  3458. WBUFW(buf,10)=amount;
  3459. WBUFB(buf,12)=ok;
  3460. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3461. #endif
  3462. }
  3463. }
  3464. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3465. /// 00d6 <flag>.B
  3466. /// flag:
  3467. /// 0 = Room has been successfully created (opens chat room)
  3468. /// 1 = Room limit exceeded
  3469. /// 2 = Same room already exists
  3470. void clif_createchat(struct map_session_data* sd, int flag)
  3471. {
  3472. int fd;
  3473. nullpo_retv(sd);
  3474. fd = sd->fd;
  3475. WFIFOHEAD(fd,packet_len(0xd6));
  3476. WFIFOW(fd,0) = 0xd6;
  3477. WFIFOB(fd,2) = flag;
  3478. WFIFOSET(fd,packet_len(0xd6));
  3479. }
  3480. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3481. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3482. /// type:
  3483. /// 0 = private (password protected)
  3484. /// 1 = public
  3485. /// 2 = arena (npc waiting room)
  3486. /// 3 = PK zone (non-clickable)
  3487. void clif_dispchat(struct chat_data* cd, int fd)
  3488. {
  3489. unsigned char buf[128];
  3490. uint8 type;
  3491. if( cd == NULL || cd->owner == NULL )
  3492. return;
  3493. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3494. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3495. : 1;
  3496. WBUFW(buf, 0) = 0xd7;
  3497. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3498. WBUFL(buf, 4) = cd->owner->id;
  3499. WBUFL(buf, 8) = cd->bl.id;
  3500. WBUFW(buf,12) = cd->limit;
  3501. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3502. WBUFB(buf,16) = type;
  3503. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3504. if( fd ) {
  3505. WFIFOHEAD(fd,WBUFW(buf,2));
  3506. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3507. WFIFOSET(fd,WBUFW(buf,2));
  3508. } else {
  3509. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3510. }
  3511. }
  3512. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3513. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3514. /// type:
  3515. /// 0 = private (password protected)
  3516. /// 1 = public
  3517. /// 2 = arena (npc waiting room)
  3518. /// 3 = PK zone (non-clickable)
  3519. void clif_changechatstatus(struct chat_data* cd)
  3520. {
  3521. unsigned char buf[128];
  3522. uint8 type;
  3523. if( cd == NULL || cd->usersd[0] == NULL )
  3524. return;
  3525. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3526. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3527. : 1;
  3528. WBUFW(buf, 0) = 0xdf;
  3529. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3530. WBUFL(buf, 4) = cd->owner->id;
  3531. WBUFL(buf, 8) = cd->bl.id;
  3532. WBUFW(buf,12) = cd->limit;
  3533. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3534. WBUFB(buf,16) = type;
  3535. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3536. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3537. }
  3538. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3539. /// 00d8 <chat id>.L
  3540. void clif_clearchat(struct chat_data *cd,int fd)
  3541. {
  3542. unsigned char buf[32];
  3543. nullpo_retv(cd);
  3544. WBUFW(buf,0) = 0xd8;
  3545. WBUFL(buf,2) = cd->bl.id;
  3546. if( fd ) {
  3547. WFIFOHEAD(fd,packet_len(0xd8));
  3548. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3549. WFIFOSET(fd,packet_len(0xd8));
  3550. } else {
  3551. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3552. }
  3553. }
  3554. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3555. /// 00da <result>.B
  3556. /// result:
  3557. /// 0 = room full
  3558. /// 1 = wrong password
  3559. /// 2 = kicked
  3560. /// 3 = success (no message)
  3561. /// 4 = no enough zeny
  3562. /// 5 = too low level
  3563. /// 6 = too high level
  3564. /// 7 = unsuitable job class
  3565. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3566. {
  3567. int fd;
  3568. nullpo_retv(sd);
  3569. fd = sd->fd;
  3570. WFIFOHEAD(fd,packet_len(0xda));
  3571. WFIFOW(fd,0) = 0xda;
  3572. WFIFOB(fd,2) = flag;
  3573. WFIFOSET(fd,packet_len(0xda));
  3574. }
  3575. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3576. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3577. /// role:
  3578. /// 0 = owner (menu)
  3579. /// 1 = normal
  3580. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3581. {
  3582. int fd;
  3583. int i,t;
  3584. nullpo_retv(sd);
  3585. nullpo_retv(cd);
  3586. fd = sd->fd;
  3587. if (!session_isActive(fd))
  3588. return;
  3589. t = (int)(cd->owner->type == BL_NPC);
  3590. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3591. WFIFOW(fd, 0) = 0xdb;
  3592. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3593. WFIFOL(fd, 4) = cd->bl.id;
  3594. if(cd->owner->type == BL_NPC){
  3595. WFIFOL(fd, 30) = 1;
  3596. WFIFOL(fd, 8) = 0;
  3597. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3598. for (i = 0; i < cd->users; i++) {
  3599. WFIFOL(fd, 8+(i+1)*28) = 1;
  3600. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3601. }
  3602. } else
  3603. for (i = 0; i < cd->users; i++) {
  3604. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3605. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3606. }
  3607. WFIFOSET(fd, WFIFOW(fd, 2));
  3608. }
  3609. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3610. /// 00dc <users>.W <name>.24B
  3611. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3612. {
  3613. unsigned char buf[29];
  3614. nullpo_retv(sd);
  3615. nullpo_retv(cd);
  3616. WBUFW(buf, 0) = 0xdc;
  3617. WBUFW(buf, 2) = cd->users;
  3618. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3619. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3620. }
  3621. /// Announce the new owner (ZC_ROLE_CHANGE).
  3622. /// 00e1 <role>.L <nick>.24B
  3623. /// role:
  3624. /// 0 = owner (menu)
  3625. /// 1 = normal
  3626. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3627. {
  3628. unsigned char buf[64];
  3629. nullpo_retv(sd);
  3630. nullpo_retv(cd);
  3631. WBUFW(buf, 0) = 0xe1;
  3632. WBUFL(buf, 2) = 1;
  3633. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3634. WBUFW(buf,30) = 0xe1;
  3635. WBUFL(buf,32) = 0;
  3636. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3637. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3638. }
  3639. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3640. /// 00dd <users>.W <nick>.24B <flag>.B
  3641. /// flag:
  3642. /// 0 = left
  3643. /// 1 = kicked
  3644. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3645. {
  3646. unsigned char buf[32];
  3647. nullpo_retv(sd);
  3648. nullpo_retv(cd);
  3649. WBUFW(buf, 0) = 0xdd;
  3650. WBUFW(buf, 2) = cd->users-1;
  3651. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3652. WBUFB(buf,28) = flag;
  3653. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3654. }
  3655. /// Opens a trade request window from char 'name'.
  3656. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3657. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3658. void clif_traderequest(struct map_session_data* sd, const char* name)
  3659. {
  3660. int fd = sd->fd;
  3661. #if PACKETVER < 6
  3662. WFIFOHEAD(fd,packet_len(0xe5));
  3663. WFIFOW(fd,0) = 0xe5;
  3664. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3665. WFIFOSET(fd,packet_len(0xe5));
  3666. #else
  3667. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3668. if( !tsd ) return;
  3669. WFIFOHEAD(fd,packet_len(0x1f4));
  3670. WFIFOW(fd,0) = 0x1f4;
  3671. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3672. WFIFOL(fd,26) = tsd->status.char_id;
  3673. WFIFOW(fd,30) = tsd->status.base_level;
  3674. WFIFOSET(fd,packet_len(0x1f4));
  3675. #endif
  3676. }
  3677. /// Reply to a trade-request.
  3678. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3679. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3680. /// result:
  3681. /// 0 = Char is too far
  3682. /// 1 = Character does not exist
  3683. /// 2 = Trade failed
  3684. /// 3 = Accept
  3685. /// 4 = Cancel
  3686. /// 5 = Busy
  3687. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3688. {
  3689. int fd = sd->fd;
  3690. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3691. if( PACKETVER < 6 || !tsd ) {
  3692. WFIFOHEAD(fd,packet_len(0xe7));
  3693. WFIFOW(fd,0) = 0xe7;
  3694. WFIFOB(fd,2) = type;
  3695. WFIFOSET(fd,packet_len(0xe7));
  3696. } else {
  3697. WFIFOHEAD(fd,packet_len(0x1f5));
  3698. WFIFOW(fd,0) = 0x1f5;
  3699. WFIFOB(fd,2) = type;
  3700. WFIFOL(fd,3) = tsd->status.char_id;
  3701. WFIFOW(fd,7) = tsd->status.base_level;
  3702. WFIFOSET(fd,packet_len(0x1f5));
  3703. }
  3704. }
  3705. /// Notifies the client about an item from other player in current trade.
  3706. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3707. /// 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)
  3708. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM3)
  3709. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3710. {
  3711. int fd;
  3712. unsigned char *buf;
  3713. #if PACKETVER < 20100223
  3714. const int cmd = 0xe9;
  3715. #elif PACKETVER < 20150226
  3716. const int cmd = 0x80f;
  3717. #else
  3718. const int cmd = 0xa09;
  3719. #endif
  3720. nullpo_retv(sd);
  3721. nullpo_retv(tsd);
  3722. fd = tsd->fd;
  3723. buf = WFIFOP(fd,0);
  3724. WFIFOHEAD(fd,packet_len(cmd));
  3725. WBUFW(buf,0) = cmd;
  3726. if( index == 0 )
  3727. {
  3728. #if PACKETVER < 20100223
  3729. WBUFL(buf,2) = amount; //amount
  3730. WBUFW(buf,6) = 0; // type id
  3731. #else
  3732. WBUFW(buf,2) = 0; // type id
  3733. WBUFB(buf,4) = 0; // item type
  3734. WBUFL(buf,5) = amount; // amount
  3735. buf = WBUFP(buf,1); //Advance 1B
  3736. #endif
  3737. WBUFB(buf,8) = 0; //identify flag
  3738. WBUFB(buf,9) = 0; // attribute
  3739. WBUFB(buf,10)= 0; //refine
  3740. WBUFW(buf,11)= 0; //card (4w)
  3741. WBUFW(buf,13)= 0; //card (4w)
  3742. WBUFW(buf,15)= 0; //card (4w)
  3743. WBUFW(buf,17)= 0; //card (4w)
  3744. #if PACKETVER >= 20150226
  3745. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3746. #endif
  3747. }
  3748. else
  3749. {
  3750. index -= 2; //index fix
  3751. #if PACKETVER < 20100223
  3752. WBUFL(buf,2) = amount; //amount
  3753. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3754. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3755. else
  3756. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3757. #else
  3758. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3759. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3760. else
  3761. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3762. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3763. WBUFL(buf,5) = amount; // amount
  3764. buf = WBUFP(buf,1); //Advance 1B
  3765. #endif
  3766. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3767. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3768. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3769. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3770. #if PACKETVER >= 20150226
  3771. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3772. #endif
  3773. }
  3774. WFIFOSET(fd,packet_len(cmd));
  3775. }
  3776. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3777. /// 00ea <index>.W <result>.B
  3778. /// result:
  3779. /// 0 = success
  3780. /// 1 = overweight
  3781. /// 2 = trade canceled
  3782. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3783. {
  3784. int fd;
  3785. nullpo_retv(sd);
  3786. fd = sd->fd;
  3787. WFIFOHEAD(fd,packet_len(0xea));
  3788. WFIFOW(fd,0) = 0xea;
  3789. WFIFOW(fd,2) = index;
  3790. WFIFOB(fd,4) = fail;
  3791. WFIFOSET(fd,packet_len(0xea));
  3792. }
  3793. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3794. /// 00ec <who>.B
  3795. /// who:
  3796. /// 0 = self
  3797. /// 1 = other player
  3798. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3799. {
  3800. int fd;
  3801. nullpo_retv(sd);
  3802. fd = sd->fd;
  3803. WFIFOHEAD(fd,packet_len(0xec));
  3804. WFIFOW(fd,0) = 0xec;
  3805. WFIFOB(fd,2) = fail;
  3806. WFIFOSET(fd,packet_len(0xec));
  3807. }
  3808. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3809. /// 00ee
  3810. void clif_tradecancelled(struct map_session_data* sd)
  3811. {
  3812. int fd;
  3813. nullpo_retv(sd);
  3814. fd = sd->fd;
  3815. WFIFOHEAD(fd,packet_len(0xee));
  3816. WFIFOW(fd,0) = 0xee;
  3817. WFIFOSET(fd,packet_len(0xee));
  3818. }
  3819. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3820. /// 00f0 <result>.B
  3821. /// result:
  3822. /// 0 = success
  3823. /// 1 = failure
  3824. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3825. {
  3826. int fd;
  3827. nullpo_retv(sd);
  3828. fd = sd->fd;
  3829. WFIFOHEAD(fd,packet_len(0xf0));
  3830. WFIFOW(fd,0) = 0xf0;
  3831. WFIFOB(fd,2) = fail;
  3832. WFIFOSET(fd,packet_len(0xf0));
  3833. }
  3834. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3835. /// 00f1
  3836. /// NOTE: Unknown purpose. Items are not removed until the window is
  3837. /// refreshed (ex. by putting another item in there).
  3838. void clif_tradeundo(struct map_session_data* sd)
  3839. {
  3840. int fd = sd->fd;
  3841. WFIFOHEAD(fd,packet_len(0xf1));
  3842. WFIFOW(fd,0) = 0xf1;
  3843. WFIFOSET(fd,packet_len(0xf1));
  3844. }
  3845. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3846. /// 00f2 <current count>.W <max count>.W
  3847. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3848. {
  3849. int fd;
  3850. nullpo_retv(sd);
  3851. fd=sd->fd;
  3852. WFIFOHEAD(fd,packet_len(0xf2));
  3853. WFIFOW(fd,0) = 0xf2;
  3854. WFIFOW(fd,2) = amount;
  3855. WFIFOW(fd,4) = max_amount;
  3856. WFIFOSET(fd,packet_len(0xf2));
  3857. }
  3858. /// Notifies the client of an item being added to the storage.
  3859. /// 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)
  3860. /// 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)
  3861. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE3)
  3862. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3863. {
  3864. #if PACKETVER < 5
  3865. const int cmd = 0xf4;
  3866. #elif PACKETVER < 20150226
  3867. const int cmd = 0x1c4;
  3868. #else
  3869. const int cmd = 0xa0a;
  3870. #endif
  3871. int view,fd;
  3872. int offset = 0;
  3873. nullpo_retv(sd);
  3874. nullpo_retv(i);
  3875. fd=sd->fd;
  3876. view = itemdb_viewid(i->nameid);
  3877. WFIFOHEAD(fd,packet_len(cmd));
  3878. WFIFOW(fd, 0) = cmd; // Storage item added
  3879. WFIFOW(fd, 2) = index+1; // index
  3880. WFIFOL(fd, 4) = amount; // amount
  3881. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3882. #if PACKETVER >= 5
  3883. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3884. offset += 1;
  3885. #endif
  3886. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3887. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3888. WFIFOB(fd,12+offset) = i->refine; //refine
  3889. clif_addcards(WFIFOP(fd,13+offset), i);
  3890. #if PACKETVER >= 20150226
  3891. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3892. #endif
  3893. WFIFOSET(fd,packet_len(cmd));
  3894. }
  3895. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3896. /// 00f6 <index>.W <amount>.L
  3897. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3898. {
  3899. int fd;
  3900. nullpo_retv(sd);
  3901. fd=sd->fd;
  3902. WFIFOHEAD(fd,packet_len(0xf6));
  3903. WFIFOW(fd,0)=0xf6; // Storage item removed
  3904. WFIFOW(fd,2)=index+1;
  3905. WFIFOL(fd,4)=amount;
  3906. WFIFOSET(fd,packet_len(0xf6));
  3907. }
  3908. /// Closes storage (ZC_CLOSE_STORE).
  3909. /// 00f8
  3910. void clif_storageclose(struct map_session_data* sd)
  3911. {
  3912. int fd;
  3913. nullpo_retv(sd);
  3914. fd=sd->fd;
  3915. WFIFOHEAD(fd,packet_len(0xf8));
  3916. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3917. WFIFOSET(fd,packet_len(0xf8));
  3918. }
  3919. /*==========================================
  3920. * Server tells 'sd' player client the abouts of 'dstsd' player
  3921. *------------------------------------------*/
  3922. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3923. {
  3924. struct block_list *d_bl;
  3925. int i;
  3926. if( dstsd->chatID ) {
  3927. struct chat_data *cd = NULL;
  3928. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3929. clif_dispchat(cd,sd->fd);
  3930. } else if( dstsd->state.vending )
  3931. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3932. else if( dstsd->state.buyingstore )
  3933. clif_buyingstore_entry_single(sd, dstsd);
  3934. if(dstsd->spiritball > 0)
  3935. clif_spiritball_single(sd->fd, dstsd);
  3936. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3937. clif_spiritcharm_single(sd->fd, dstsd);
  3938. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3939. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3940. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3941. else
  3942. 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);
  3943. }
  3944. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3945. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3946. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3947. )
  3948. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3949. // display link (sd - dstsd) to sd
  3950. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3951. if( i < MAX_DEVOTION )
  3952. clif_devotion(&sd->bl, sd);
  3953. // display links (dstsd - devotees) to sd
  3954. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3955. if( i < MAX_DEVOTION )
  3956. clif_devotion(&dstsd->bl, sd);
  3957. // display link (dstsd - crusader) to sd
  3958. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3959. clif_devotion(d_bl, sd);
  3960. }
  3961. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3962. {
  3963. uint8 buf[128];
  3964. struct unit_data *ud;
  3965. struct view_data *vd;
  3966. int len;
  3967. vd = status_get_viewdata(bl);
  3968. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3969. return;
  3970. /**
  3971. * Hide NPC from maya purple card.
  3972. **/
  3973. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3974. return;
  3975. ud = unit_bl2ud(bl);
  3976. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3977. clif_send(buf,len,&sd->bl,SELF);
  3978. if (vd->cloth_color)
  3979. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3980. switch (bl->type)
  3981. {
  3982. case BL_PC:
  3983. {
  3984. TBL_PC* tsd = (TBL_PC*)bl;
  3985. clif_getareachar_pc(sd, tsd);
  3986. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3987. clif_specialeffect_single(bl,423,sd->fd);
  3988. else if(tsd->state.size==SZ_MEDIUM)
  3989. clif_specialeffect_single(bl,421,sd->fd);
  3990. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3991. clif_sendbgemblem_single(sd->fd,tsd);
  3992. if ( tsd->status.robe )
  3993. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3994. if (!&tsd->sc)
  3995. break;
  3996. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3997. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3998. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3999. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  4000. if( tsd->sc.data[SC_MOONSTAR] )
  4001. clif_status_load(bl,SI_MOONSTAR,1);
  4002. if( tsd->sc.data[SC_SUPER_STAR] )
  4003. clif_status_load(bl,SI_SUPER_STAR,1);
  4004. if( tsd->sc.data[SC_DECORATION_OF_MUSIC] )
  4005. clif_status_load(bl,SI_DECORATION_OF_MUSIC,1);
  4006. if( tsd->sc.data[SC_STRANGELIGHTS] )
  4007. clif_status_load(bl,SI_STRANGELIGHTS,1);
  4008. if( tsd->sc.data[SC_ALL_RIDING] )
  4009. clif_status_load(bl,SI_ALL_RIDING,1);
  4010. }
  4011. break;
  4012. case BL_MER: // Devotion Effects
  4013. if( ((TBL_MER*)bl)->devotion_flag )
  4014. clif_devotion(bl, sd);
  4015. break;
  4016. case BL_NPC:
  4017. {
  4018. TBL_NPC* nd = (TBL_NPC*)bl;
  4019. if( nd->chat_id )
  4020. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4021. if( nd->size == SZ_BIG )
  4022. clif_specialeffect_single(bl,423,sd->fd);
  4023. else if( nd->size == SZ_MEDIUM )
  4024. clif_specialeffect_single(bl,421,sd->fd);
  4025. }
  4026. break;
  4027. case BL_MOB:
  4028. {
  4029. TBL_MOB* md = (TBL_MOB*)bl;
  4030. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4031. clif_specialeffect_single(bl,423,sd->fd);
  4032. else if(md->special_state.size==SZ_MEDIUM)
  4033. clif_specialeffect_single(bl,421,sd->fd);
  4034. #if PACKETVER >= 20120404
  4035. if( !(md->status.mode&MD_BOSS) && battle_config.monster_hp_bars_info){
  4036. int i;
  4037. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4038. if( md->dmglog[i].id == sd->status.char_id )
  4039. clif_monster_hp_bar(md, sd->fd);
  4040. }
  4041. #endif
  4042. }
  4043. break;
  4044. case BL_PET:
  4045. if (vd->head_bottom)
  4046. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4047. break;
  4048. }
  4049. }
  4050. //Modifies the type of damage according to status changes [Skotlex]
  4051. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4052. static enum e_damage_type clif_calc_delay(char type, int div, int64 damage, int delay)
  4053. {
  4054. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : (enum e_damage_type)type;
  4055. }
  4056. /*==========================================
  4057. * Estimates walk delay based on the damage criteria. [Skotlex]
  4058. *------------------------------------------*/
  4059. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4060. {
  4061. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4062. return 0;
  4063. if (bl->type == BL_PC) {
  4064. if (battle_config.pc_walk_delay_rate != 100)
  4065. delay = delay*battle_config.pc_walk_delay_rate/100;
  4066. } else
  4067. if (battle_config.walk_delay_rate != 100)
  4068. delay = delay*battle_config.walk_delay_rate/100;
  4069. if (div_ > 1) //Multi-hit skills mean higher delays.
  4070. delay += battle_config.multihit_delay*(div_-1);
  4071. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4072. }
  4073. /// Sends a 'damage' packet (src performs action on dst)
  4074. /// 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)
  4075. /// 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)
  4076. /// 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)
  4077. /// type:
  4078. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4079. /// 1 = pick up item
  4080. /// 2 = sit down
  4081. /// 3 = stand up
  4082. /// 4 = damage (endure)
  4083. /// 5 = (splash?)
  4084. /// 6 = (skill?)
  4085. /// 7 = (repeat damage?)
  4086. /// 8 = multi-hit damage
  4087. /// 9 = multi-hit damage (endure)
  4088. /// 10 = critical hit
  4089. /// 11 = lucky dodge
  4090. /// 12 = (touch skill?)
  4091. 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)
  4092. {
  4093. unsigned char buf[34];
  4094. struct status_change *sc;
  4095. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4096. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4097. #if PACKETVER < 20071113
  4098. const int cmd = 0x8a;
  4099. int offset = 0;
  4100. #elif PACKETVER < 20131223
  4101. const int cmd = 0x2e1;
  4102. int offset = 2;
  4103. #else
  4104. const int cmd = 0x8c8;
  4105. int offset = 3;
  4106. #endif
  4107. nullpo_ret(src);
  4108. nullpo_ret(dst);
  4109. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4110. sc = status_get_sc(dst);
  4111. if(sc && sc->count) {
  4112. if(sc->data[SC_HALLUCINATION]) {
  4113. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4114. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4115. }
  4116. }
  4117. WBUFW(buf,0) = cmd;
  4118. WBUFL(buf,2) = src->id;
  4119. WBUFL(buf,6) = dst->id;
  4120. WBUFL(buf,10) = tick;
  4121. WBUFL(buf,14) = sdelay;
  4122. WBUFL(buf,18) = ddelay;
  4123. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4124. WBUFW(buf,22) = damage ? div : 0;
  4125. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4126. } else {
  4127. #if PACKETVER < 20071113
  4128. WBUFW(buf,22) = min(damage, INT16_MAX);
  4129. WBUFW(buf,27+offset) = damage2;
  4130. #else
  4131. WBUFL(buf,22) = damage;
  4132. WBUFL(buf,27+offset) = damage2;
  4133. #endif
  4134. }
  4135. #if PACKETVER >= 20131223
  4136. WBUFB(buf,26) = 0; // IsSPDamage - Displays blue digits. Need a way to handle this. [Rytech]
  4137. #endif
  4138. WBUFW(buf,24+offset) = div;
  4139. WBUFB(buf,26+offset) = type;
  4140. if(disguised(dst)) {
  4141. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4142. WBUFL(buf,6) = -dst->id;
  4143. clif_send(buf, packet_len(cmd), dst, SELF);
  4144. } else
  4145. clif_send(buf, packet_len(cmd), dst, AREA);
  4146. if(disguised(src)) {
  4147. WBUFL(buf,2) = -src->id;
  4148. if (disguised(dst))
  4149. WBUFL(buf,6) = dst->id;
  4150. #if PACKETVER < 20071113
  4151. if(damage > 0) WBUFW(buf,22) = -1;
  4152. if(damage2 > 0) WBUFW(buf,27) = -1;
  4153. #else
  4154. if(damage > 0) WBUFL(buf,22) = -1;
  4155. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4156. #endif
  4157. clif_send(buf,packet_len(cmd),src,SELF);
  4158. }
  4159. if(src == dst) {
  4160. unit_setdir(src, unit_getdir(src));
  4161. }
  4162. //Return adjusted can't walk delay for further processing.
  4163. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4164. }
  4165. /*==========================================
  4166. * src picks up dst
  4167. *------------------------------------------*/
  4168. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4169. {
  4170. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0);
  4171. unsigned char buf[32];
  4172. nullpo_retv(src);
  4173. nullpo_retv(dst);
  4174. WBUFW(buf, 0) = 0x8a;
  4175. WBUFL(buf, 2) = src->id;
  4176. WBUFL(buf, 6) = dst->id;
  4177. WBUFB(buf,26) = 1;
  4178. clif_send(buf, packet_len(0x8a), src, AREA);
  4179. }
  4180. /*==========================================
  4181. * inform clients in area that `bl` is sitting
  4182. *------------------------------------------*/
  4183. void clif_sitting(struct block_list* bl)
  4184. {
  4185. unsigned char buf[32];
  4186. nullpo_retv(bl);
  4187. WBUFW(buf, 0) = 0x8a;
  4188. WBUFL(buf, 2) = bl->id;
  4189. WBUFB(buf,26) = 2;
  4190. clif_send(buf, packet_len(0x8a), bl, AREA);
  4191. if(disguised(bl)) {
  4192. WBUFL(buf, 2) = - bl->id;
  4193. clif_send(buf, packet_len(0x8a), bl, SELF);
  4194. }
  4195. }
  4196. /*==========================================
  4197. * inform clients in area that `bl` is standing
  4198. *------------------------------------------*/
  4199. void clif_standing(struct block_list* bl)
  4200. {
  4201. unsigned char buf[32];
  4202. nullpo_retv(bl);
  4203. WBUFW(buf, 0) = 0x8a;
  4204. WBUFL(buf, 2) = bl->id;
  4205. WBUFB(buf,26) = 3;
  4206. clif_send(buf, packet_len(0x8a), bl, AREA);
  4207. if(disguised(bl)) {
  4208. WBUFL(buf, 2) = - bl->id;
  4209. clif_send(buf, packet_len(0x8a), bl, SELF);
  4210. }
  4211. }
  4212. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4213. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4214. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4215. {
  4216. unsigned char buf[32];
  4217. WBUFW(buf,0) = 0x192;
  4218. WBUFW(buf,2) = x;
  4219. WBUFW(buf,4) = y;
  4220. WBUFW(buf,6) = type;
  4221. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  4222. if( fd )
  4223. {
  4224. WFIFOHEAD(fd,packet_len(0x192));
  4225. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4226. WFIFOSET(fd,packet_len(0x192));
  4227. }
  4228. else
  4229. {
  4230. struct block_list dummy_bl;
  4231. dummy_bl.type = BL_NUL;
  4232. dummy_bl.x = x;
  4233. dummy_bl.y = y;
  4234. dummy_bl.m = m;
  4235. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4236. }
  4237. }
  4238. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4239. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4240. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4241. {
  4242. int view,fd;
  4243. fd=sd->fd;
  4244. WFIFOHEAD(fd,packet_len(0x9d));
  4245. WFIFOW(fd,0)=0x9d;
  4246. WFIFOL(fd,2)=fitem->bl.id;
  4247. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4248. WFIFOW(fd,6)=view;
  4249. else
  4250. WFIFOW(fd,6)=fitem->item.nameid;
  4251. WFIFOB(fd,8)=fitem->item.identify;
  4252. WFIFOW(fd,9)=fitem->bl.x;
  4253. WFIFOW(fd,11)=fitem->bl.y;
  4254. WFIFOW(fd,13)=fitem->item.amount;
  4255. WFIFOB(fd,15)=fitem->subx;
  4256. WFIFOB(fd,16)=fitem->suby;
  4257. WFIFOSET(fd,packet_len(0x9d));
  4258. }
  4259. /// Notifes client about Graffiti
  4260. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4261. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4262. unsigned char buf[128];
  4263. nullpo_retv(bl);
  4264. nullpo_retv(unit);
  4265. WBUFW(buf, 0) = 0x1c9;
  4266. WBUFL(buf, 2) = unit->bl.id;
  4267. WBUFL(buf, 6) = unit->group->src_id;
  4268. WBUFW(buf,10) = unit->bl.x;
  4269. WBUFW(buf,12) = unit->bl.y;
  4270. WBUFB(buf,14) = unit->group->unit_id;
  4271. WBUFB(buf,15) = 1;
  4272. WBUFB(buf,16) = 1;
  4273. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4274. clif_send(buf,packet_len(0x1c9),bl,target);
  4275. }
  4276. /// Notifies the client of a skill unit.
  4277. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4278. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4279. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4280. /// 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)
  4281. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, uint8 flag) {
  4282. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4283. unsigned char buf[128];
  4284. nullpo_retv(bl);
  4285. nullpo_retv(unit);
  4286. if (bl->type == BL_PC)
  4287. fd = ((TBL_PC*)bl)->fd;
  4288. if (unit->group->state.guildaura)
  4289. return;
  4290. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4291. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4292. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4293. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4294. else
  4295. unit_id = unit->group->unit_id;
  4296. if (flag && battle_config.traps_setting&1) {
  4297. switch(unit->group->skill_id) {
  4298. case HT_ANKLESNARE:
  4299. if (!map_flag_vs(((TBL_PC*)bl)->bl.m))
  4300. break;
  4301. case HT_SKIDTRAP:
  4302. case MA_SKIDTRAP:
  4303. case HT_SHOCKWAVE:
  4304. case HT_SANDMAN:
  4305. case MA_SANDMAN:
  4306. case HT_FLASHER:
  4307. case HT_FREEZINGTRAP:
  4308. case MA_FREEZINGTRAP:
  4309. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for Hunter's traps
  4310. break;
  4311. }
  4312. }
  4313. #if PACKETVER >= 3
  4314. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4315. clif_graffiti(bl, unit, target);
  4316. return;
  4317. }
  4318. #endif
  4319. #if PACKETVER <= 20120702
  4320. header = 0x011f;
  4321. //#if PACKETVER < 20110718
  4322. // header = 0x011f;
  4323. //#elif PACKETVER < 20121212
  4324. // header = 0x08c7;
  4325. #elif PACKETVER < 20130731
  4326. header = 0x099f;
  4327. #else
  4328. header = 0x09ca;
  4329. #endif
  4330. len = packet_len(header);
  4331. WBUFW(buf,pos) = header;
  4332. if (header != 0x011f) {
  4333. WBUFW(buf, pos+2) = len;
  4334. pos += 2;
  4335. }
  4336. WBUFL(buf,pos+2) = unit->bl.id;
  4337. WBUFL(buf,pos+6) = unit->group->src_id;
  4338. WBUFW(buf,pos+10) = unit->bl.x;
  4339. WBUFW(buf,pos+12) = unit->bl.y;
  4340. switch (header) {
  4341. case 0x011f:
  4342. WBUFB(buf,pos+14) = unit_id;
  4343. WBUFB(buf,pos+15) = 1;
  4344. break;
  4345. case 0x08c7:
  4346. WBUFB(buf,pos+14) = unit_id;
  4347. WBUFW(buf,pos+15) = unit->range;
  4348. WBUFB(buf,pos+17) = 1;
  4349. break;
  4350. case 0x099f:
  4351. WBUFL(buf,pos+14) = unit_id;
  4352. WBUFW(buf,pos+18) = unit->range;
  4353. WBUFB(buf,pos+20) = 1;
  4354. break;
  4355. case 0x09ca:
  4356. WBUFL(buf,pos+14) = unit_id;
  4357. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4358. WBUFB(buf,pos+19) = 1;
  4359. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4360. break;
  4361. }
  4362. clif_send(buf, len, bl, target);
  4363. if (unit->group->skill_id == WZ_ICEWALL)
  4364. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4365. }
  4366. /*==========================================
  4367. * Server tells client to remove unit of id 'unit->bl.id'
  4368. *------------------------------------------*/
  4369. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4370. {
  4371. nullpo_retv(unit);
  4372. WFIFOHEAD(fd,packet_len(0x120));
  4373. WFIFOW(fd, 0)=0x120;
  4374. WFIFOL(fd, 2)=unit->bl.id;
  4375. WFIFOSET(fd,packet_len(0x120));
  4376. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4377. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4378. }
  4379. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4380. /// 0120 <id>.L
  4381. void clif_skill_delunit(struct skill_unit *unit)
  4382. {
  4383. unsigned char buf[16];
  4384. nullpo_retv(unit);
  4385. WBUFW(buf, 0)=0x120;
  4386. WBUFL(buf, 2)=unit->bl.id;
  4387. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4388. }
  4389. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4390. /// 01ac <id>.L
  4391. /// Only affects units with class [139,153] client-side.
  4392. void clif_skillunit_update(struct block_list* bl)
  4393. {
  4394. unsigned char buf[6];
  4395. nullpo_retv(bl);
  4396. WBUFW(buf,0) = 0x1ac;
  4397. WBUFL(buf,2) = bl->id;
  4398. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4399. }
  4400. /*==========================================
  4401. *
  4402. *------------------------------------------*/
  4403. static int clif_getareachar(struct block_list* bl,va_list ap)
  4404. {
  4405. struct map_session_data *sd;
  4406. nullpo_ret(bl);
  4407. sd=va_arg(ap,struct map_session_data*);
  4408. if (sd == NULL || !sd->fd)
  4409. return 0;
  4410. switch(bl->type){
  4411. case BL_ITEM:
  4412. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4413. break;
  4414. case BL_SKILL:
  4415. clif_getareachar_skillunit(&sd->bl, (TBL_SKILL*)bl, SELF, 1);
  4416. break;
  4417. default:
  4418. if(&sd->bl == bl)
  4419. break;
  4420. clif_getareachar_unit(sd,bl);
  4421. break;
  4422. }
  4423. return 0;
  4424. }
  4425. /*==========================================
  4426. * tbl has gone out of view-size of bl
  4427. *------------------------------------------*/
  4428. int clif_outsight(struct block_list *bl,va_list ap)
  4429. {
  4430. struct block_list *tbl;
  4431. struct view_data *vd;
  4432. TBL_PC *sd, *tsd;
  4433. tbl=va_arg(ap,struct block_list*);
  4434. if(bl == tbl) return 0;
  4435. sd = BL_CAST(BL_PC, bl);
  4436. tsd = BL_CAST(BL_PC, tbl);
  4437. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4438. nullpo_ret(bl);
  4439. switch(bl->type){
  4440. case BL_PC:
  4441. if(sd->vd.class_ != INVISIBLE_CLASS)
  4442. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4443. if(sd->chatID){
  4444. struct chat_data *cd;
  4445. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4446. if(cd->usersd[0]==sd)
  4447. clif_dispchat(cd,tsd->fd);
  4448. }
  4449. if(sd->state.vending)
  4450. clif_closevendingboard(bl,tsd->fd);
  4451. if(sd->state.buyingstore)
  4452. clif_buyingstore_disappear_entry_single(tsd, sd);
  4453. break;
  4454. case BL_ITEM:
  4455. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4456. break;
  4457. case BL_SKILL:
  4458. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4459. break;
  4460. case BL_NPC:
  4461. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4462. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4463. break;
  4464. default:
  4465. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4466. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4467. break;
  4468. }
  4469. }
  4470. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4471. nullpo_ret(tbl);
  4472. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4473. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4474. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4475. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4476. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4477. }
  4478. return 0;
  4479. }
  4480. /*==========================================
  4481. * tbl has come into view of bl
  4482. *------------------------------------------*/
  4483. int clif_insight(struct block_list *bl,va_list ap)
  4484. {
  4485. struct block_list *tbl;
  4486. TBL_PC *sd, *tsd;
  4487. tbl=va_arg(ap,struct block_list*);
  4488. if (bl == tbl) return 0;
  4489. sd = BL_CAST(BL_PC, bl);
  4490. tsd = BL_CAST(BL_PC, tbl);
  4491. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4492. switch(bl->type){
  4493. case BL_ITEM:
  4494. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4495. break;
  4496. case BL_SKILL:
  4497. clif_getareachar_skillunit(&tsd->bl, (TBL_SKILL*)bl, SELF, 1);
  4498. break;
  4499. default:
  4500. clif_getareachar_unit(tsd,bl);
  4501. break;
  4502. }
  4503. }
  4504. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4505. clif_getareachar_unit(sd,tbl);
  4506. }
  4507. return 0;
  4508. }
  4509. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4510. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4511. void clif_skillinfoblock(struct map_session_data *sd)
  4512. {
  4513. int fd;
  4514. int i,len,id;
  4515. nullpo_retv(sd);
  4516. fd = sd->fd;
  4517. if (!fd)
  4518. return;
  4519. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4520. WFIFOW(fd,0) = 0x10f;
  4521. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4522. {
  4523. if( (id = sd->status.skill[i].id) != 0 )
  4524. {
  4525. // workaround for bugreport:5348
  4526. if (len + 37 > 8192)
  4527. break;
  4528. WFIFOW(fd,len) = id;
  4529. WFIFOL(fd,len+2) = skill_get_inf(id);
  4530. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4531. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4532. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4533. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4534. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4535. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4536. else
  4537. WFIFOB(fd,len+36) = 0;
  4538. len += 37;
  4539. }
  4540. }
  4541. WFIFOW(fd,2)=len;
  4542. WFIFOSET(fd,len);
  4543. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4544. for ( ; i < MAX_SKILL; i++)
  4545. {
  4546. if( (id = sd->status.skill[i].id) != 0 )
  4547. {
  4548. clif_addskill(sd, id);
  4549. clif_skillinfo(sd, id, 0);
  4550. }
  4551. }
  4552. }
  4553. /**
  4554. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4555. **/
  4556. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4557. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4558. void clif_addskill(struct map_session_data *sd, int skill_id)
  4559. {
  4560. int fd;
  4561. uint16 idx = 0;
  4562. nullpo_retv(sd);
  4563. fd = sd->fd;
  4564. if (!fd || !(idx = skill_get_index(skill_id)))
  4565. return;
  4566. if( sd->status.skill[idx].id <= 0 )
  4567. return;
  4568. WFIFOHEAD(fd, packet_len(0x111));
  4569. WFIFOW(fd,0) = 0x111;
  4570. WFIFOW(fd,2) = skill_id;
  4571. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4572. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4573. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4574. WFIFOW(fd,12)= skill_get_range2(&sd->bl, skill_id,sd->status.skill[idx].lv);
  4575. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4576. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4577. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4578. else
  4579. WFIFOB(fd,38) = 0;
  4580. WFIFOSET(fd,packet_len(0x111));
  4581. }
  4582. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4583. /// 0441 <skill id>.W
  4584. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4585. {
  4586. #if PACKETVER >= 20081217
  4587. int fd;
  4588. uint16 idx = 0;
  4589. nullpo_retv(sd);
  4590. fd = sd->fd;
  4591. if (!fd || !(idx = skill_get_index(skill_id)))
  4592. return;
  4593. WFIFOHEAD(fd,packet_len(0x441));
  4594. WFIFOW(fd,0) = 0x441;
  4595. WFIFOW(fd,2) = skill_id;
  4596. WFIFOSET(fd,packet_len(0x441));
  4597. #endif
  4598. clif_skillinfoblock(sd);
  4599. }
  4600. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4601. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4602. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4603. int fd;
  4604. nullpo_retv(sd);
  4605. fd = sd->fd;
  4606. WFIFOHEAD(fd, packet_len(0x10e));
  4607. WFIFOW(fd, 0) = 0x10e;
  4608. WFIFOW(fd, 2) = skill_id;
  4609. WFIFOW(fd, 4) = lv;
  4610. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4611. WFIFOW(fd, 8) = range;
  4612. WFIFOB(fd, 10) = upgradable;
  4613. WFIFOSET(fd, packet_len(0x10e));
  4614. }
  4615. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4616. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4617. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4618. {
  4619. const int fd = sd->fd;
  4620. uint16 idx = skill_get_index(skill_id);
  4621. if (!idx)
  4622. return;
  4623. WFIFOHEAD(fd,packet_len(0x7e1));
  4624. WFIFOW(fd,0) = 0x7e1;
  4625. WFIFOW(fd,2) = skill_id;
  4626. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4627. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4628. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4629. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv);
  4630. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4631. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4632. else
  4633. WFIFOB(fd,14) = 0;
  4634. WFIFOSET(fd,packet_len(0x7e1));
  4635. }
  4636. /// Notifies clients in area, that an object is about to use a skill.
  4637. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4638. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4639. /// property:
  4640. /// 0 = Yellow cast aura
  4641. /// 1 = Water elemental cast aura
  4642. /// 2 = Earth elemental cast aura
  4643. /// 3 = Fire elemental cast aura
  4644. /// 4 = Wind elemental cast aura
  4645. /// 5 = Poison elemental cast aura
  4646. /// 6 = Holy elemental cast aura
  4647. /// ? = like 0
  4648. /// is disposable:
  4649. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4650. /// 1 = no text
  4651. 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)
  4652. {
  4653. #if PACKETVER < 20091124
  4654. const int cmd = 0x13e;
  4655. #else
  4656. const int cmd = 0x7fb;
  4657. #endif
  4658. unsigned char buf[32];
  4659. WBUFW(buf,0) = cmd;
  4660. WBUFL(buf,2) = src_id;
  4661. WBUFL(buf,6) = dst_id;
  4662. WBUFW(buf,10) = dst_x;
  4663. WBUFW(buf,12) = dst_y;
  4664. WBUFW(buf,14) = skill_id;
  4665. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4666. WBUFL(buf,20) = casttime;
  4667. #if PACKETVER >= 20091124
  4668. WBUFB(buf,24) = 0; // isDisposable
  4669. #endif
  4670. if (disguised(bl)) {
  4671. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4672. WBUFL(buf,2) = -src_id;
  4673. clif_send(buf,packet_len(cmd), bl, SELF);
  4674. } else
  4675. clif_send(buf,packet_len(cmd), bl, AREA);
  4676. }
  4677. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4678. /// 01b9 <id>.L
  4679. void clif_skillcastcancel(struct block_list* bl)
  4680. {
  4681. unsigned char buf[16];
  4682. nullpo_retv(bl);
  4683. WBUFW(buf,0) = 0x1b9;
  4684. WBUFL(buf,2) = bl->id;
  4685. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4686. }
  4687. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4688. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4689. /// num (only used when skill id = NV_BASIC and cause = 0):
  4690. /// 0 = "skill failed" MsgStringTable[159]
  4691. /// 1 = "no emotions" MsgStringTable[160]
  4692. /// 2 = "no sit" MsgStringTable[161]
  4693. /// 3 = "no chat" MsgStringTable[162]
  4694. /// 4 = "no party" MsgStringTable[163]
  4695. /// 5 = "no shout" MsgStringTable[164]
  4696. /// 6 = "no PKing" MsgStringTable[165]
  4697. /// 7 = "no alligning" MsgStringTable[383]
  4698. /// ? = ignored
  4699. /// cause:
  4700. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4701. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4702. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4703. /// "skill failed" MsgStringTable[204] (otherwise)
  4704. /// ... = @see enum useskill_fail_cause
  4705. /// ? = ignored
  4706. ///
  4707. /// if(result!=0) doesn't display any of the previous messages
  4708. /// Note: when this packet is received an unknown flag is always set to 0,
  4709. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4710. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4711. {
  4712. int fd;
  4713. if (!sd) { //Since this is the most common nullpo....
  4714. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4715. return;
  4716. }
  4717. fd=sd->fd;
  4718. if (!fd) return;
  4719. if(battle_config.display_skill_fail&1)
  4720. return; //Disable all skill failed messages
  4721. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4722. return; //Disable delay failed messages
  4723. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4724. return;
  4725. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4726. return;
  4727. WFIFOHEAD(fd,packet_len(0x110));
  4728. WFIFOW(fd,0) = 0x110;
  4729. WFIFOW(fd,2) = skill_id;
  4730. WFIFOL(fd,4) = btype;
  4731. WFIFOB(fd,8) = 0;// success
  4732. WFIFOB(fd,9) = cause;
  4733. WFIFOSET(fd,packet_len(0x110));
  4734. }
  4735. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4736. /// 043d <skill ID>.W <tick>.L
  4737. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4738. {
  4739. #if PACKETVER>=20081112
  4740. int fd;
  4741. nullpo_retv(sd);
  4742. fd=sd->fd;
  4743. WFIFOHEAD(fd,packet_len(0x43d));
  4744. WFIFOW(fd,0) = 0x43d;
  4745. WFIFOW(fd,2) = skill_id;
  4746. WFIFOL(fd,4) = tick;
  4747. WFIFOSET(fd,packet_len(0x43d));
  4748. #endif
  4749. }
  4750. /// Skill attack effect and damage.
  4751. /// 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)
  4752. /// 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)
  4753. 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)
  4754. {
  4755. unsigned char buf[64];
  4756. struct status_change *sc;
  4757. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4758. nullpo_ret(src);
  4759. nullpo_ret(dst);
  4760. type = clif_calc_delay(type,div,damage,ddelay);
  4761. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4762. if(sc->data[SC_HALLUCINATION] && damage)
  4763. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4764. }
  4765. #if PACKETVER < 3
  4766. WBUFW(buf,0)=0x114;
  4767. WBUFW(buf,2)=skill_id;
  4768. WBUFL(buf,4)=src->id;
  4769. WBUFL(buf,8)=dst->id;
  4770. WBUFL(buf,12)=tick;
  4771. WBUFL(buf,16)=sdelay;
  4772. WBUFL(buf,20)=ddelay;
  4773. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4774. WBUFW(buf,24)=damage?div:0;
  4775. } else {
  4776. WBUFW(buf,24)=damage;
  4777. }
  4778. WBUFW(buf,26)=skill_lv;
  4779. WBUFW(buf,28)=div;
  4780. WBUFB(buf,30)=type;
  4781. if (disguised(dst)) {
  4782. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4783. WBUFL(buf,8)=-dst->id;
  4784. clif_send(buf,packet_len(0x114),dst,SELF);
  4785. } else
  4786. clif_send(buf,packet_len(0x114),dst,AREA);
  4787. if(disguised(src)) {
  4788. WBUFL(buf,4)=-src->id;
  4789. if (disguised(dst))
  4790. WBUFL(buf,8)=dst->id;
  4791. if(damage > 0)
  4792. WBUFW(buf,24)=-1;
  4793. clif_send(buf,packet_len(0x114),src,SELF);
  4794. }
  4795. #else
  4796. WBUFW(buf,0)=0x1de;
  4797. WBUFW(buf,2)=skill_id;
  4798. WBUFL(buf,4)=src->id;
  4799. WBUFL(buf,8)=dst->id;
  4800. WBUFL(buf,12)=tick;
  4801. WBUFL(buf,16)=sdelay;
  4802. WBUFL(buf,20)=ddelay;
  4803. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4804. WBUFL(buf,24)=damage?div:0;
  4805. } else {
  4806. WBUFL(buf,24)=damage;
  4807. }
  4808. WBUFW(buf,28)=skill_lv;
  4809. WBUFW(buf,30)=div;
  4810. // For some reason, late 2013 and newer clients have
  4811. // a issue that causes players and monsters to endure
  4812. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4813. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4814. #if PACKETVER < 20131223
  4815. WBUFB(buf,32)=type;
  4816. #else
  4817. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4818. #endif
  4819. if (disguised(dst)) {
  4820. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4821. WBUFL(buf,8)=-dst->id;
  4822. clif_send(buf,packet_len(0x1de),dst,SELF);
  4823. } else
  4824. clif_send(buf,packet_len(0x1de),dst,AREA);
  4825. if(disguised(src)) {
  4826. WBUFL(buf,4)=-src->id;
  4827. if (disguised(dst))
  4828. WBUFL(buf,8)=dst->id;
  4829. if(damage > 0)
  4830. WBUFL(buf,24)=-1;
  4831. clif_send(buf,packet_len(0x1de),src,SELF);
  4832. }
  4833. #endif
  4834. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4835. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4836. }
  4837. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4838. /// 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
  4839. /*
  4840. 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)
  4841. {
  4842. unsigned char buf[64];
  4843. struct status_change *sc;
  4844. nullpo_ret(src);
  4845. nullpo_ret(dst);
  4846. type = (type>0)?type:skill_get_hit(skill_id);
  4847. type = clif_calc_delay(type,div,damage,ddelay);
  4848. sc = status_get_sc(dst);
  4849. if(sc && sc->count) {
  4850. if(sc->data[SC_HALLUCINATION] && damage)
  4851. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4852. }
  4853. WBUFW(buf,0)=0x115;
  4854. WBUFW(buf,2)=skill_id;
  4855. WBUFL(buf,4)=src->id;
  4856. WBUFL(buf,8)=dst->id;
  4857. WBUFL(buf,12)=tick;
  4858. WBUFL(buf,16)=sdelay;
  4859. WBUFL(buf,20)=ddelay;
  4860. WBUFW(buf,24)=dst->x;
  4861. WBUFW(buf,26)=dst->y;
  4862. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4863. WBUFW(buf,28)=damage?div:0;
  4864. } else {
  4865. WBUFW(buf,28)=damage;
  4866. }
  4867. WBUFW(buf,30)=skill_lv;
  4868. WBUFW(buf,32)=div;
  4869. WBUFB(buf,34)=type;
  4870. clif_send(buf,packet_len(0x115),src,AREA);
  4871. if(disguised(src)) {
  4872. WBUFL(buf,4)=-src->id;
  4873. if(damage > 0)
  4874. WBUFW(buf,28)=-1;
  4875. clif_send(buf,packet_len(0x115),src,SELF);
  4876. }
  4877. if (disguised(dst)) {
  4878. WBUFL(buf,8)=-dst->id;
  4879. if (disguised(src))
  4880. WBUFL(buf,4)=src->id;
  4881. else if(damage > 0)
  4882. WBUFW(buf,28)=-1;
  4883. clif_send(buf,packet_len(0x115),dst,SELF);
  4884. }
  4885. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4886. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4887. }
  4888. */
  4889. /// Non-damaging skill effect (ZC_USE_SKILL).
  4890. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4891. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4892. {
  4893. unsigned char buf[32];
  4894. nullpo_ret(dst);
  4895. WBUFW(buf,0)=0x11a;
  4896. WBUFW(buf,2)=skill_id;
  4897. WBUFW(buf,4)=min(heal, INT16_MAX);
  4898. WBUFL(buf,6)=dst->id;
  4899. WBUFL(buf,10)=src?src->id:0;
  4900. WBUFB(buf,14)=fail;
  4901. if (disguised(dst)) {
  4902. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4903. WBUFL(buf,6)=-dst->id;
  4904. clif_send(buf,packet_len(0x11a),dst,SELF);
  4905. } else
  4906. clif_send(buf,packet_len(0x11a),dst,AREA);
  4907. if(src && disguised(src)) {
  4908. WBUFL(buf,10)=-src->id;
  4909. if (disguised(dst))
  4910. WBUFL(buf,6)=dst->id;
  4911. clif_send(buf,packet_len(0x11a),src,SELF);
  4912. }
  4913. return fail;
  4914. }
  4915. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4916. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4917. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4918. {
  4919. unsigned char buf[32];
  4920. nullpo_retv(src);
  4921. WBUFW(buf,0)=0x117;
  4922. WBUFW(buf,2)=skill_id;
  4923. WBUFL(buf,4)=src->id;
  4924. WBUFW(buf,8)=val;
  4925. WBUFW(buf,10)=x;
  4926. WBUFW(buf,12)=y;
  4927. WBUFL(buf,14)=tick;
  4928. if(disguised(src)) {
  4929. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4930. WBUFL(buf,4)=-src->id;
  4931. clif_send(buf,packet_len(0x117),src,SELF);
  4932. } else
  4933. clif_send(buf,packet_len(0x117),src,AREA);
  4934. }
  4935. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4936. /// 011c <skill id>.W { <map name>.16B }*4
  4937. 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)
  4938. {
  4939. int fd;
  4940. nullpo_retv(sd);
  4941. fd = sd->fd;
  4942. WFIFOHEAD(fd,packet_len(0x11c));
  4943. WFIFOW(fd,0) = 0x11c;
  4944. WFIFOW(fd,2) = skill_id;
  4945. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4946. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4947. else // normal map name
  4948. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4949. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4950. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4951. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4952. WFIFOSET(fd,packet_len(0x11c));
  4953. sd->menuskill_id = skill_id;
  4954. if (skill_id == AL_WARP)
  4955. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4956. else
  4957. sd->menuskill_val = skill_lv;
  4958. }
  4959. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4960. /// 011e <type>.B
  4961. /// type:
  4962. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4963. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4964. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4965. ///
  4966. /// @param sd Who receives the message
  4967. /// @param type What message
  4968. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4969. {
  4970. int fd;
  4971. nullpo_retv(sd);
  4972. fd=sd->fd;
  4973. WFIFOHEAD(fd,packet_len(0x11e));
  4974. WFIFOW(fd,0)=0x11e;
  4975. WFIFOB(fd,2)=type;
  4976. WFIFOSET(fd,packet_len(0x11e));
  4977. }
  4978. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4979. /// 0189 <type>.W
  4980. /// type:
  4981. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4982. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4983. ///
  4984. /// @param sd Who receives the message
  4985. /// @param type What message
  4986. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4987. {
  4988. int fd;
  4989. nullpo_retv(sd);
  4990. fd=sd->fd;
  4991. WFIFOHEAD(fd,packet_len(0x189));
  4992. WFIFOW(fd,0)=0x189;
  4993. WFIFOW(fd,2)=type;
  4994. WFIFOSET(fd,packet_len(0x189));
  4995. }
  4996. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4997. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4998. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4999. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5000. {
  5001. struct status_data *status;
  5002. unsigned char buf[64];
  5003. int i;//, fix;
  5004. nullpo_retv(sd);
  5005. nullpo_retv(dst);
  5006. if( dst->type != BL_MOB )
  5007. return;
  5008. status = status_get_status_data(dst);
  5009. WBUFW(buf, 0)=0x18c;
  5010. WBUFW(buf, 2)=status_get_class(dst);
  5011. WBUFW(buf, 4)=status_get_lv(dst);
  5012. WBUFW(buf, 6)=status->size;
  5013. WBUFL(buf, 8)=status->hp;
  5014. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5015. +(battle_config.estimation_type&2?status->def2:0);
  5016. WBUFW(buf,14)=status->race;
  5017. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5018. +(battle_config.estimation_type&2?status->mdef2:0);
  5019. WBUFW(buf,18)= status->def_ele;
  5020. for(i=0;i<9;i++)
  5021. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5022. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5023. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5024. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5025. }
  5026. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5027. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5028. /// material id:
  5029. /// unused by the client
  5030. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5031. {
  5032. int i,c,view,fd;
  5033. nullpo_retv(sd);
  5034. if (sd->menuskill_id == skill_id)
  5035. return; //Avoid resending the menu twice or more times...
  5036. if (skill_id == GC_CREATENEWPOISON)
  5037. skill_id = GC_RESEARCHNEWPOISON;
  5038. fd = sd->fd;
  5039. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5040. WFIFOW(fd, 0) = 0x18d;
  5041. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5042. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5043. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5044. )
  5045. {
  5046. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5047. WFIFOW(fd,c*8+ 4) = view;
  5048. else
  5049. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5050. WFIFOW(fd,c*8+ 6) = 0;
  5051. WFIFOW(fd,c*8+ 8) = 0;
  5052. WFIFOW(fd,c*8+10) = 0;
  5053. c++;
  5054. }
  5055. }
  5056. WFIFOW(fd, 2) = c*8+8;
  5057. WFIFOSET(fd,WFIFOW(fd,2));
  5058. if (c > 0) {
  5059. sd->menuskill_id = skill_id;
  5060. sd->menuskill_val = trigger;
  5061. return;
  5062. }
  5063. }
  5064. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5065. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5066. /// mk type:
  5067. /// 1 = cooking
  5068. /// 2 = arrow
  5069. /// 3 = elemental
  5070. /// 4 = GN_MIX_COOKING
  5071. /// 5 = GN_MAKEBOMB
  5072. /// 6 = GN_S_PHARMACY
  5073. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5074. {
  5075. int fd;
  5076. int i, c;
  5077. int view;
  5078. nullpo_retv(sd);
  5079. fd = sd->fd;
  5080. if(sd->menuskill_id == skill_id)
  5081. return; //Avoid resending the menu twice or more times...
  5082. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5083. WFIFOW(fd,0) = 0x25a;
  5084. WFIFOW(fd,4) = list_type; // list type
  5085. c = 0;
  5086. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5087. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5088. continue;
  5089. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5090. WFIFOW(fd, 6 + 2 * c) = view;
  5091. else
  5092. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5093. c++;
  5094. }
  5095. if( c > 0 || skill_id == AM_PHARMACY) {
  5096. sd->menuskill_id = skill_id;
  5097. sd->menuskill_val = trigger;
  5098. sd->menuskill_val2 = qty; // amount.
  5099. WFIFOW(fd,2) = 6 + 2 * c;
  5100. WFIFOSET(fd,WFIFOW(fd,2));
  5101. } else {
  5102. clif_menuskill_clear(sd);
  5103. #if PACKETVER >= 20090922
  5104. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5105. #else
  5106. WFIFOW(fd,2) = 6 + 2 * c;
  5107. WFIFOSET(fd,WFIFOW(fd,2));
  5108. #endif
  5109. }
  5110. }
  5111. /// Notifies clients of a status change.
  5112. /// 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)]
  5113. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5114. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5115. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  5116. {
  5117. unsigned char buf[32];
  5118. struct map_session_data *sd;
  5119. if (type == SI_BLANK) //It shows nothing on the client...
  5120. return;
  5121. nullpo_retv(bl);
  5122. sd = BL_CAST(BL_PC, bl);
  5123. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5124. return;
  5125. #if PACKETVER >= 20120618
  5126. if(flag && battle_config.display_status_timers && sd)
  5127. WBUFW(buf,0)=0x983;
  5128. else
  5129. #elif PACKETVER >= 20090121
  5130. if(flag && battle_config.display_status_timers && sd)
  5131. WBUFW(buf,0)=0x43f;
  5132. else
  5133. #endif
  5134. WBUFW(buf,0)=0x196;
  5135. WBUFW(buf,2)=type;
  5136. WBUFL(buf,4)=bl->id;
  5137. WBUFB(buf,8)=flag;
  5138. #if PACKETVER >= 20120618
  5139. if(flag && battle_config.display_status_timers && sd) {
  5140. if (tick <= 0)
  5141. tick = 9999; // this is indeed what official servers do
  5142. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  5143. WBUFL(buf,13)=tick;
  5144. WBUFL(buf,17) = val1;
  5145. WBUFL(buf,21) = val2;
  5146. WBUFL(buf,25) = val3;
  5147. }
  5148. #elif PACKETVER >= 20090121
  5149. if(flag && battle_config.display_status_timers && sd) {
  5150. if (tick <= 0)
  5151. tick = 9999; // this is indeed what official servers do
  5152. WBUFL(buf,9) = tick;
  5153. WBUFL(buf,13) = val1;
  5154. WBUFL(buf,17) = val2;
  5155. WBUFL(buf,21) = val3;
  5156. }
  5157. #endif
  5158. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  5159. }
  5160. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  5161. unsigned char buf[32];
  5162. if (type == SI_BLANK) //It shows nothing on the client
  5163. return;
  5164. nullpo_retv(bl);
  5165. WBUFW(buf,0) = 0x43f;
  5166. WBUFW(buf,2) = type;
  5167. WBUFL(buf,4) = tid;
  5168. WBUFB(buf,8) = 1;
  5169. WBUFL(buf,9) = 9999;
  5170. WBUFL(buf,13) = val1;
  5171. WBUFL(buf,17) = val2;
  5172. WBUFL(buf,21) = val3;
  5173. clif_send(buf,packet_len(0x43f),bl,target);
  5174. }
  5175. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5176. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5177. //! TODO
  5178. //void clif_efst_enter();
  5179. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5180. /// 008e <packet len>.W <message>.?B
  5181. void clif_displaymessage(const int fd, const char* mes)
  5182. {
  5183. nullpo_retv(mes);
  5184. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5185. if (fd == 0)
  5186. ;
  5187. else {
  5188. char *message, *line;
  5189. message = aStrdup(mes);
  5190. line = strtok(message, "\n");
  5191. #if PACKETVER == 20141022
  5192. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5193. /** so we redirect to ZC_NPC_CHAT **/
  5194. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5195. while(line != NULL) {
  5196. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5197. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5198. if (len > 0) {
  5199. WFIFOHEAD(fd, 13 + len);
  5200. WFIFOW(fd, 0) = 0x2C1;
  5201. WFIFOW(fd, 2) = 13 + len;
  5202. WFIFOL(fd, 4) = 0;
  5203. WFIFOL(fd, 8) = color;
  5204. safestrncpy((char*)WFIFOP(fd, 12), line, len + 1);
  5205. WFIFOSET(fd, WFIFOW(fd, 2));
  5206. }
  5207. #else
  5208. while(line != NULL) {
  5209. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5210. int len = strnlen(line, CHAT_SIZE_MAX);
  5211. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5212. WFIFOHEAD(fd, 5 + len);
  5213. WFIFOW(fd,0) = 0x8e;
  5214. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5215. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  5216. WFIFOSET(fd, 5 + len);
  5217. }
  5218. #endif
  5219. line = strtok(NULL, "\n");
  5220. }
  5221. aFree(message);
  5222. }
  5223. }
  5224. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5225. /// 009a <packet len>.W <message>.?B
  5226. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5227. {
  5228. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5229. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5230. WBUFW(buf,0) = 0x9a;
  5231. WBUFW(buf,2) = 4 + lp + len;
  5232. if (type&BC_BLUE)
  5233. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5234. else if (type&BC_WOE)
  5235. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5236. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5237. clif_send(buf, WBUFW(buf,2), bl, target);
  5238. if (buf)
  5239. aFree(buf);
  5240. }
  5241. /*==========================================
  5242. * Displays a message on a 'bl' to all it's nearby clients
  5243. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5244. *------------------------------------------*/
  5245. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5246. char buf[100];
  5247. int len;
  5248. nullpo_retv(bl);
  5249. if(!message)
  5250. return;
  5251. len = strlen(message)+1;
  5252. if( len > sizeof(buf)-8 ) {
  5253. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5254. len = sizeof(buf)-8;
  5255. }
  5256. WBUFW(buf,0)=0x8d;
  5257. WBUFW(buf,2)=len+8;
  5258. WBUFL(buf,4)=bl->id;
  5259. safestrncpy((char *) WBUFP(buf,8),message,len);
  5260. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5261. }
  5262. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5263. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5264. 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)
  5265. {
  5266. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5267. WBUFW(buf,0) = 0x1c3;
  5268. WBUFW(buf,2) = len + 16;
  5269. WBUFL(buf,4) = fontColor;
  5270. WBUFW(buf,8) = fontType;
  5271. WBUFW(buf,10) = fontSize;
  5272. WBUFW(buf,12) = fontAlign;
  5273. WBUFW(buf,14) = fontY;
  5274. memcpy(WBUFP(buf,16), mes, len);
  5275. clif_send(buf, WBUFW(buf,2), bl, target);
  5276. if (buf)
  5277. aFree(buf);
  5278. }
  5279. /*
  5280. * Display *msg from *sd to all *users in channel
  5281. */
  5282. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5283. DBIterator *iter;
  5284. struct map_session_data *user;
  5285. unsigned short msg_len = strlen(msg) + 1;
  5286. WFIFOHEAD(sd->fd,msg_len + 12);
  5287. WFIFOW(sd->fd,0) = 0x2C1;
  5288. WFIFOW(sd->fd,2) = msg_len + 12;
  5289. WFIFOL(sd->fd,4) = 0;
  5290. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5291. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  5292. iter = db_iterator(channel->users);
  5293. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5294. if( user->fd == sd->fd )
  5295. continue;
  5296. WFIFOHEAD(user->fd,msg_len + 12);
  5297. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5298. WFIFOSET(user->fd, msg_len + 12);
  5299. }
  5300. dbi_destroy(iter);
  5301. WFIFOSET(sd->fd, msg_len + 12);
  5302. }
  5303. /// Displays heal effect (ZC_RECOVERY).
  5304. /// 013d <var id>.W <amount>.W
  5305. /// var id:
  5306. /// 5 = HP (SP_HP)
  5307. /// 7 = SP (SP_SP)
  5308. /// ? = ignored
  5309. void clif_heal(int fd,int type,int val)
  5310. {
  5311. WFIFOHEAD(fd,packet_len(0x13d));
  5312. WFIFOW(fd,0)=0x13d;
  5313. WFIFOW(fd,2)=type;
  5314. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  5315. WFIFOSET(fd,packet_len(0x13d));
  5316. }
  5317. /// Displays resurrection effect (ZC_RESURRECTION).
  5318. /// 0148 <id>.L <type>.W
  5319. /// type:
  5320. /// ignored
  5321. void clif_resurrection(struct block_list *bl,int type)
  5322. {
  5323. unsigned char buf[16];
  5324. nullpo_retv(bl);
  5325. WBUFW(buf,0)=0x148;
  5326. WBUFL(buf,2)=bl->id;
  5327. WBUFW(buf,6)=0;
  5328. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5329. if (disguised(bl))
  5330. clif_spawn(bl);
  5331. }
  5332. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5333. /// 0199 <type>.W
  5334. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5335. {
  5336. int fd;
  5337. nullpo_retv(sd);
  5338. fd=sd->fd;
  5339. WFIFOHEAD(fd,packet_len(0x199));
  5340. WFIFOW(fd,0)=0x199;
  5341. WFIFOW(fd,2)=property;
  5342. WFIFOSET(fd,packet_len(0x199));
  5343. }
  5344. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5345. #if PACKETVER >= 20121010
  5346. unsigned char buf[8];
  5347. unsigned int NotifyProperty =
  5348. ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5349. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5350. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5351. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5352. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5353. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5354. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5355. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5356. ((map[bl->m].flag.noitemconsumption?1:0)<<8)| // DISABLE_COSTUMEITEM - Unknown - (Prevents wearing of costume items?)
  5357. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5358. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5359. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5360. WBUFW(buf,0)=0x99b;
  5361. WBUFW(buf,2)=0x28; // Type - What is it asking for? MAPPROPERTY? MAPTYPE? I don't know. Do we even need it? [Rytech]
  5362. WBUFL(buf,4)=NotifyProperty;
  5363. WBUFW(buf,6) = 0; // sparebit [5-15], + extra[4]
  5364. clif_send(buf,packet_len(0x99b),bl,t);
  5365. #endif
  5366. }
  5367. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5368. /// 01d6 <type>.W
  5369. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5370. {
  5371. int fd;
  5372. nullpo_retv(sd);
  5373. fd=sd->fd;
  5374. WFIFOHEAD(fd,packet_len(0x1D6));
  5375. WFIFOW(fd,0)=0x1D6;
  5376. WFIFOW(fd,2)=type;
  5377. WFIFOSET(fd,packet_len(0x1D6));
  5378. }
  5379. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5380. /// 019a <id>.L <ranking>.L <total>.L
  5381. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5382. {
  5383. if(type == 2) {
  5384. int fd = sd->fd;
  5385. WFIFOHEAD(fd,packet_len(0x19a));
  5386. WFIFOW(fd,0) = 0x19a;
  5387. WFIFOL(fd,2) = sd->bl.id;
  5388. WFIFOL(fd,6) = pvprank;
  5389. WFIFOL(fd,10) = pvpnum;
  5390. WFIFOSET(fd,packet_len(0x19a));
  5391. } else {
  5392. unsigned char buf[32];
  5393. WBUFW(buf,0) = 0x19a;
  5394. WBUFL(buf,2) = sd->bl.id;
  5395. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5396. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5397. else
  5398. WBUFL(buf,6) = pvprank;
  5399. WBUFL(buf,10) = pvpnum;
  5400. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5401. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5402. else if(!type)
  5403. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5404. else
  5405. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5406. }
  5407. }
  5408. /*==========================================
  5409. *
  5410. *------------------------------------------*/
  5411. void clif_map_property_mapall(int map_idx, enum map_property property)
  5412. {
  5413. struct block_list bl;
  5414. unsigned char buf[16];
  5415. bl.id = 0;
  5416. bl.type = BL_NUL;
  5417. bl.m = map_idx;
  5418. WBUFW(buf,0)=0x199;
  5419. WBUFW(buf,2)=property;
  5420. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5421. }
  5422. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5423. /// 0188 <result>.W <index>.W <refine>.W
  5424. /// result:
  5425. /// 0 = success
  5426. /// 1 = failure
  5427. /// 2 = downgrade
  5428. void clif_refine(int fd, int fail, int index, int val)
  5429. {
  5430. WFIFOHEAD(fd,packet_len(0x188));
  5431. WFIFOW(fd,0)=0x188;
  5432. WFIFOW(fd,2)=fail;
  5433. WFIFOW(fd,4)=index+2;
  5434. WFIFOW(fd,6)=val;
  5435. WFIFOSET(fd,packet_len(0x188));
  5436. }
  5437. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5438. /// 0223 <result>.L <nameid>.W
  5439. /// result:
  5440. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5441. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5442. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5443. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5444. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5445. {
  5446. WFIFOHEAD(fd,packet_len(0x223));
  5447. WFIFOW(fd,0)=0x223;
  5448. WFIFOL(fd,2)=result;
  5449. WFIFOW(fd,6)=item_id;
  5450. WFIFOSET(fd,packet_len(0x223));
  5451. }
  5452. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5453. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5454. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5455. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5456. {
  5457. #if PACKETVER < 20091104
  5458. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5459. WFIFOW(fd,0) = 0x97;
  5460. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5461. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5462. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5463. WFIFOSET(fd,WFIFOW(fd,2));
  5464. #else
  5465. struct map_session_data *ssd = map_nick2sd(nick);
  5466. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5467. WFIFOW(fd,0) = 0x97;
  5468. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5469. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5470. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5471. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5472. WFIFOSET(fd,WFIFOW(fd,2));
  5473. #endif
  5474. }
  5475. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5476. /// 0098 <result>.B
  5477. /// result:
  5478. /// 0 = success to send wisper
  5479. /// 1 = target character is not loged in
  5480. /// 2 = ignored by target
  5481. /// 3 = everyone ignored by target
  5482. void clif_wis_end(int fd, int result)
  5483. {
  5484. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5485. if (!sd)
  5486. return;
  5487. #if PACKETVER >= 20131223
  5488. WFIFOHEAD(fd,packet_len(0x9df));
  5489. WFIFOW(fd,0) = 0x9df;
  5490. WFIFOB(fd,2) = (char)result;
  5491. WFIFOL(fd,3) = 0;
  5492. WFIFOSET(fd,packet_len(0x9df));
  5493. #else
  5494. WFIFOHEAD(fd,packet_len(0x98));
  5495. WFIFOW(fd,0) = 0x98;
  5496. WFIFOB(fd,2) = (char)result;
  5497. WFIFOSET(fd,packet_len(0x98));
  5498. #endif
  5499. }
  5500. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5501. /// 0194 <char id>.L <name>.24B
  5502. void clif_solved_charname(int fd, int charid, const char* name)
  5503. {
  5504. WFIFOHEAD(fd,packet_len(0x194));
  5505. WFIFOW(fd,0)=0x194;
  5506. WFIFOL(fd,2)=charid;
  5507. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5508. WFIFOSET(fd,packet_len(0x194));
  5509. }
  5510. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5511. /// 017b <packet len>.W { <name id>.W }*
  5512. void clif_use_card(struct map_session_data *sd,int idx)
  5513. {
  5514. int i,c,ep;
  5515. int fd=sd->fd;
  5516. nullpo_retv(sd);
  5517. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5518. return;
  5519. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5520. return; //Avoid parsing invalid item indexes (no card/no item)
  5521. ep=sd->inventory_data[idx]->equip;
  5522. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5523. WFIFOW(fd,0)=0x17b;
  5524. for(i=c=0;i<MAX_INVENTORY;i++){
  5525. int j;
  5526. if(sd->inventory_data[i] == NULL)
  5527. continue;
  5528. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5529. continue;
  5530. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5531. continue;
  5532. if(sd->status.inventory[i].identify==0 ) //Not identified
  5533. continue;
  5534. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5535. continue;
  5536. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5537. continue;
  5538. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5539. if( j == sd->inventory_data[i]->slot ) // No room
  5540. continue;
  5541. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5542. continue;
  5543. WFIFOW(fd,4+c*2)=i+2;
  5544. c++;
  5545. }
  5546. if( !c ) return; // no item is available for card insertion
  5547. WFIFOW(fd,2)=4+c*2;
  5548. WFIFOSET(fd,WFIFOW(fd,2));
  5549. }
  5550. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5551. /// 017d <equip index>.W <card index>.W <result>.B
  5552. /// result:
  5553. /// 0 = success
  5554. /// 1 = failure
  5555. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5556. {
  5557. int fd;
  5558. nullpo_retv(sd);
  5559. fd=sd->fd;
  5560. WFIFOHEAD(fd,packet_len(0x17d));
  5561. WFIFOW(fd,0)=0x17d;
  5562. WFIFOW(fd,2)=idx_equip+2;
  5563. WFIFOW(fd,4)=idx_card+2;
  5564. WFIFOB(fd,6)=flag;
  5565. WFIFOSET(fd,packet_len(0x17d));
  5566. }
  5567. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5568. /// 0177 <packet len>.W { <name id>.W }*
  5569. void clif_item_identify_list(struct map_session_data *sd)
  5570. {
  5571. int i,c;
  5572. int fd;
  5573. nullpo_retv(sd);
  5574. fd=sd->fd;
  5575. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5576. WFIFOW(fd,0)=0x177;
  5577. for(i=c=0;i<MAX_INVENTORY;i++){
  5578. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5579. WFIFOW(fd,c*2+4)=i+2;
  5580. c++;
  5581. }
  5582. }
  5583. if(c > 0) {
  5584. WFIFOW(fd,2)=c*2+4;
  5585. WFIFOSET(fd,WFIFOW(fd,2));
  5586. sd->menuskill_id = MC_IDENTIFY;
  5587. sd->menuskill_val = c;
  5588. }
  5589. }
  5590. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5591. /// 0179 <index>.W <result>.B
  5592. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5593. {
  5594. int fd;
  5595. nullpo_retv(sd);
  5596. fd=sd->fd;
  5597. WFIFOHEAD(fd,packet_len(0x179));
  5598. WFIFOW(fd, 0)=0x179;
  5599. WFIFOW(fd, 2)=idx+2;
  5600. WFIFOB(fd, 4)=flag;
  5601. WFIFOSET(fd,packet_len(0x179));
  5602. }
  5603. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5604. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5605. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5606. {
  5607. int i,c;
  5608. int fd;
  5609. nullpo_retv(sd);
  5610. nullpo_retv(dstsd);
  5611. fd=sd->fd;
  5612. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5613. WFIFOW(fd,0)=0x1fc;
  5614. for(i=c=0;i<MAX_INVENTORY;i++){
  5615. unsigned short nameid;
  5616. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5617. WFIFOW(fd,c*13+4) = i;
  5618. WFIFOW(fd,c*13+6) = nameid;
  5619. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5620. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5621. c++;
  5622. }
  5623. }
  5624. if(c > 0) {
  5625. WFIFOW(fd,2)=c*13+4;
  5626. WFIFOSET(fd,WFIFOW(fd,2));
  5627. sd->menuskill_id = BS_REPAIRWEAPON;
  5628. sd->menuskill_val = dstsd->bl.id;
  5629. sd->menuskill_val2 = lv;
  5630. }else
  5631. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5632. }
  5633. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5634. /// 01fe <index>.W <result>.B
  5635. /// index:
  5636. /// ignored (inventory index)
  5637. /// result:
  5638. /// 0 = Item repair success.
  5639. /// 1 = Item repair failure.
  5640. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5641. {
  5642. int fd;
  5643. nullpo_retv(sd);
  5644. fd = sd->fd;
  5645. WFIFOHEAD(fd,packet_len(0x1fe));
  5646. WFIFOW(fd, 0)=0x1fe;
  5647. WFIFOW(fd, 2)=idx+2;
  5648. WFIFOB(fd, 4)=flag;
  5649. WFIFOSET(fd,packet_len(0x1fe));
  5650. }
  5651. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5652. /// 02bb <equip location>.W <account id>.L
  5653. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5654. {
  5655. int fd = sd->fd;
  5656. WFIFOHEAD(fd,packet_len(0x2bb));
  5657. WFIFOW(fd,0) = 0x2bb;
  5658. WFIFOW(fd,2) = position;
  5659. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5660. WFIFOSET(fd,packet_len(0x2bb));
  5661. }
  5662. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5663. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5664. void clif_item_refine_list(struct map_session_data *sd)
  5665. {
  5666. int i,c;
  5667. int fd;
  5668. uint16 skill_lv;
  5669. int refine_item[5];
  5670. nullpo_retv(sd);
  5671. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5672. fd=sd->fd;
  5673. refine_item[0] = -1;
  5674. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5675. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5676. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5677. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5678. WFIFOW(fd,0)=0x221;
  5679. for(i=c=0;i<MAX_INVENTORY;i++){
  5680. unsigned char wlv;
  5681. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5682. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5683. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5684. WFIFOW(fd,c*13+ 4)=i+2;
  5685. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5686. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5687. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5688. c++;
  5689. }
  5690. }
  5691. WFIFOW(fd,2)=c*13+4;
  5692. WFIFOSET(fd,WFIFOW(fd,2));
  5693. if (c > 0) {
  5694. sd->menuskill_id = WS_WEAPONREFINE;
  5695. sd->menuskill_val = skill_lv;
  5696. }
  5697. }
  5698. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5699. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5700. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5701. {
  5702. int fd;
  5703. nullpo_retv(sd);
  5704. fd=sd->fd;
  5705. WFIFOHEAD(fd,packet_len(0x147));
  5706. WFIFOW(fd, 0)=0x147;
  5707. WFIFOW(fd, 2)=skill_id;
  5708. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5709. WFIFOW(fd, 6)=0;
  5710. WFIFOW(fd, 8)=skill_lv;
  5711. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5712. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5713. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5714. WFIFOB(fd,38)=0;
  5715. WFIFOSET(fd,packet_len(0x147));
  5716. }
  5717. /// Adds an item to character's cart.
  5718. /// 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)
  5719. /// 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)
  5720. /// 0a0b <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART3)
  5721. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5722. {
  5723. #if PACKETVER < 5
  5724. const int cmd = 0x124;
  5725. #elif PACKETVER < 20150226
  5726. const int cmd = 0x1c5;
  5727. #else
  5728. const int cmd = 0xa0b;
  5729. #endif
  5730. int view,fd;
  5731. unsigned char *buf;
  5732. int offset = 0;
  5733. nullpo_retv(sd);
  5734. fd=sd->fd;
  5735. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5736. return;
  5737. WFIFOHEAD(fd,packet_len(cmd));
  5738. buf=WFIFOP(fd,0);
  5739. WBUFW(buf,0)=cmd;
  5740. WBUFW(buf,2)=n+2;
  5741. WBUFL(buf,4)=amount;
  5742. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5743. WBUFW(buf,8)=view;
  5744. else
  5745. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5746. #if PACKETVER >= 5
  5747. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5748. offset += 1;
  5749. #endif
  5750. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5751. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5752. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5753. clif_addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5754. #if PACKETVER >= 20150226
  5755. clif_add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5756. #endif
  5757. WFIFOSET(fd,packet_len(cmd));
  5758. }
  5759. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5760. /* Acknowledge an item have been added to cart
  5761. * 012c <result>B
  5762. * result :
  5763. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5764. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5765. */
  5766. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5767. {
  5768. int fd;
  5769. unsigned char *buf;
  5770. nullpo_retv(sd);
  5771. fd = sd->fd;
  5772. buf = WFIFOP(fd,0);
  5773. WBUFW(buf,0) = 0x12c;
  5774. WBUFB(buf,2) = flag;
  5775. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5776. }
  5777. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5778. void clif_bank_open(struct map_session_data *sd){
  5779. int fd;
  5780. nullpo_retv(sd);
  5781. fd = sd->fd;
  5782. WFIFOHEAD(fd,4);
  5783. WFIFOW(fd,0) = 0x09b7;
  5784. WFIFOW(fd,2) = 0;
  5785. WFIFOSET(fd,4);
  5786. }
  5787. /*
  5788. * Request to Open the banking system
  5789. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5790. */
  5791. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5792. //TODO check if preventing trade or stuff like that
  5793. //also mark something in case char ain't available for saving, should we check now ?
  5794. nullpo_retv(sd);
  5795. if( !battle_config.feature_banking ) {
  5796. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5797. return;
  5798. }
  5799. else {
  5800. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5801. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5802. if(sd->status.account_id == aid){
  5803. sd->state.banking = 1;
  5804. //request save ?
  5805. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5806. //on succes open bank ?
  5807. clif_bank_open(sd);
  5808. }
  5809. }
  5810. }
  5811. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5812. void clif_bank_close(struct map_session_data *sd){
  5813. int fd;
  5814. nullpo_retv(sd);
  5815. fd = sd->fd;
  5816. WFIFOHEAD(fd,4);
  5817. WFIFOW(fd,0) = 0x09B9;
  5818. WFIFOW(fd,2) = 0;
  5819. WFIFOSET(fd,4);
  5820. }
  5821. /*
  5822. * Request to close the banking system
  5823. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5824. */
  5825. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5826. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5827. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5828. nullpo_retv(sd);
  5829. if( !battle_config.feature_banking ) {
  5830. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5831. //still allow to go trough to not stuck player if we have disable it while they was in
  5832. }
  5833. if(sd->status.account_id == aid){
  5834. sd->state.banking = 0;
  5835. clif_bank_close(sd);
  5836. }
  5837. }
  5838. /*
  5839. * Display how much we got in bank (I suppose)
  5840. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5841. */
  5842. void clif_Bank_Check(struct map_session_data* sd) {
  5843. unsigned char buf[13];
  5844. struct s_packet_db* info;
  5845. int16 len;
  5846. int cmd = 0;
  5847. nullpo_retv(sd);
  5848. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5849. if(!cmd) cmd = 0x09A6; //default
  5850. info = &packet_db[sd->packet_ver][cmd];
  5851. len = info->len;
  5852. if(!len) return; //version as packet disable
  5853. // sd->state.banking = 1; //mark opening and closing
  5854. WBUFW(buf,0) = cmd;
  5855. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5856. WBUFW(buf,info->pos[1]) = 0; //reason
  5857. clif_send(buf,len,&sd->bl,SELF);
  5858. }
  5859. /*
  5860. * Requesting the data in bank
  5861. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5862. */
  5863. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5864. nullpo_retv(sd);
  5865. if( !battle_config.feature_banking ) {
  5866. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5867. return;
  5868. }
  5869. else {
  5870. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5871. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5872. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5873. clif_Bank_Check(sd);
  5874. }
  5875. }
  5876. /*
  5877. * Acknowledge of deposit some money in bank
  5878. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5879. */
  5880. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5881. unsigned char buf[17];
  5882. struct s_packet_db* info;
  5883. int16 len;
  5884. int cmd =0;
  5885. nullpo_retv(sd);
  5886. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5887. if(!cmd) cmd = 0x09A8;
  5888. info = &packet_db[sd->packet_ver][cmd];
  5889. len = info->len;
  5890. if(!len) return; //version as packet disable
  5891. WBUFW(buf,0) = cmd;
  5892. WBUFW(buf,info->pos[0]) = (short)reason;
  5893. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5894. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5895. clif_send(buf,len,&sd->bl,SELF);
  5896. }
  5897. /*
  5898. * Request saving some money in bank
  5899. * @author : original [Yommy/Hercules]
  5900. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5901. */
  5902. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5903. nullpo_retv(sd);
  5904. if( !battle_config.feature_banking ) {
  5905. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5906. return;
  5907. }
  5908. else {
  5909. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5910. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5911. int money = RFIFOL(fd,info->pos[1]);
  5912. if(sd->status.account_id == aid){
  5913. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5914. clif_bank_deposit(sd,reason);
  5915. }
  5916. }
  5917. }
  5918. /*
  5919. * Acknowledge of withdrawing some money from bank
  5920. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5921. */
  5922. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5923. unsigned char buf[17];
  5924. struct s_packet_db* info;
  5925. int16 len;
  5926. int cmd;
  5927. nullpo_retv(sd);
  5928. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5929. if(!cmd) cmd = 0x09AA;
  5930. info = &packet_db[sd->packet_ver][cmd];
  5931. len = info->len;
  5932. if(!len) return; //version as packet disable
  5933. WBUFW(buf,0) = cmd;
  5934. WBUFW(buf,info->pos[0]) = (short)reason;
  5935. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5936. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5937. clif_send(buf,len,&sd->bl,SELF);
  5938. }
  5939. /*
  5940. * Request Withdrawing some money from bank
  5941. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5942. */
  5943. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5944. nullpo_retv(sd);
  5945. if( !battle_config.feature_banking ) {
  5946. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5947. return;
  5948. }
  5949. else {
  5950. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5951. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5952. int money = RFIFOL(fd,info->pos[1]);
  5953. if(sd->status.account_id == aid){
  5954. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5955. clif_bank_withdraw(sd,reason);
  5956. }
  5957. }
  5958. }
  5959. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5960. /// 0125 <index>.W <amount>.L
  5961. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5962. {
  5963. int fd;
  5964. nullpo_retv(sd);
  5965. fd=sd->fd;
  5966. WFIFOHEAD(fd,packet_len(0x125));
  5967. WFIFOW(fd,0)=0x125;
  5968. WFIFOW(fd,2)=n+2;
  5969. WFIFOL(fd,4)=amount;
  5970. WFIFOSET(fd,packet_len(0x125));
  5971. }
  5972. /// Opens the shop creation menu (ZC_OPENSTORE).
  5973. /// 012d <num>.W
  5974. /// num:
  5975. /// number of allowed item slots
  5976. void clif_openvendingreq(struct map_session_data* sd, int num)
  5977. {
  5978. int fd;
  5979. nullpo_retv(sd);
  5980. fd = sd->fd;
  5981. WFIFOHEAD(fd,packet_len(0x12d));
  5982. WFIFOW(fd,0) = 0x12d;
  5983. WFIFOW(fd,2) = num;
  5984. WFIFOSET(fd,packet_len(0x12d));
  5985. }
  5986. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5987. /// 0131 <owner id>.L <message>.80B
  5988. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5989. {
  5990. unsigned char buf[128];
  5991. nullpo_retv(bl);
  5992. WBUFW(buf,0) = 0x131;
  5993. WBUFL(buf,2) = bl->id;
  5994. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5995. if( fd ) {
  5996. WFIFOHEAD(fd,packet_len(0x131));
  5997. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5998. WFIFOSET(fd,packet_len(0x131));
  5999. } else {
  6000. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6001. }
  6002. }
  6003. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6004. /// 0132 <owner id>.L
  6005. void clif_closevendingboard(struct block_list* bl, int fd)
  6006. {
  6007. unsigned char buf[16];
  6008. nullpo_retv(bl);
  6009. WBUFW(buf,0) = 0x132;
  6010. WBUFL(buf,2) = bl->id;
  6011. if( fd ) {
  6012. WFIFOHEAD(fd,packet_len(0x132));
  6013. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6014. WFIFOSET(fd,packet_len(0x132));
  6015. } else {
  6016. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6017. }
  6018. }
  6019. /// Sends a list of items in a shop.
  6020. /// 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)
  6021. /// 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)
  6022. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6023. {
  6024. int i,fd;
  6025. int count;
  6026. struct map_session_data* vsd;
  6027. #if PACKETVER < 20100105
  6028. const int cmd = 0x133;
  6029. const int offset = 8;
  6030. #else
  6031. const int cmd = 0x800;
  6032. const int offset = 12;
  6033. #endif
  6034. #if PACKETVER < 20150226
  6035. const int item_length = 22;
  6036. #else
  6037. const int item_length = 47;
  6038. #endif
  6039. nullpo_retv(sd);
  6040. nullpo_retv(vending);
  6041. nullpo_retv(vsd=map_id2sd(id));
  6042. fd = sd->fd;
  6043. count = vsd->vend_num;
  6044. WFIFOHEAD(fd, offset+count*item_length);
  6045. WFIFOW(fd,0) = cmd;
  6046. WFIFOW(fd,2) = offset+count*item_length;
  6047. WFIFOL(fd,4) = id;
  6048. #if PACKETVER >= 20100105
  6049. WFIFOL(fd,8) = vsd->vender_id;
  6050. #endif
  6051. for( i = 0; i < count; i++ )
  6052. {
  6053. int index = vending[i].index;
  6054. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  6055. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6056. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6057. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6058. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6059. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  6060. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  6061. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  6062. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  6063. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  6064. #if PACKETVER >= 20150226
  6065. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  6066. #endif
  6067. }
  6068. WFIFOSET(fd,WFIFOW(fd,2));
  6069. }
  6070. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6071. /// 0135 <index>.W <amount>.W <result>.B
  6072. /// result:
  6073. /// 0 = success
  6074. /// 1 = not enough zeny
  6075. /// 2 = overweight
  6076. /// 4 = out of stock
  6077. /// 5 = "cannot use an npc shop while in a trade"
  6078. /// 6 = Because the store information was incorrect the item was not purchased.
  6079. /// 7 = No sales information.
  6080. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6081. {
  6082. int fd;
  6083. nullpo_retv(sd);
  6084. fd = sd->fd;
  6085. WFIFOHEAD(fd,packet_len(0x135));
  6086. WFIFOW(fd,0) = 0x135;
  6087. WFIFOW(fd,2) = index+2;
  6088. WFIFOW(fd,4) = amount;
  6089. WFIFOB(fd,6) = fail;
  6090. WFIFOSET(fd,packet_len(0x135));
  6091. }
  6092. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6093. /// 0a28 <Result>.B
  6094. /// result:
  6095. /// 0 = Successed
  6096. /// 1 = Failed
  6097. void clif_openvending_ack(struct map_session_data* sd, int result)
  6098. {
  6099. int fd;
  6100. nullpo_retv(sd);
  6101. fd = sd->fd;
  6102. WFIFOHEAD(fd, 3);
  6103. WFIFOW(fd,0) = 0xa28;
  6104. WFIFOB(fd,2) = result;
  6105. WFIFOSET(fd, 3);
  6106. }
  6107. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6108. /// 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 }*
  6109. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6110. {
  6111. int i,fd;
  6112. int count;
  6113. #if PACKETVER < 20150226
  6114. const int item_length = 22;
  6115. #else
  6116. const int item_length = 47;
  6117. #endif
  6118. nullpo_retv(sd);
  6119. fd = sd->fd;
  6120. count = sd->vend_num;
  6121. WFIFOHEAD(fd, 8+count*item_length);
  6122. WFIFOW(fd,0) = 0x136;
  6123. WFIFOW(fd,2) = 8+count*item_length;
  6124. WFIFOL(fd,4) = id;
  6125. for( i = 0; i < count; i++ ) {
  6126. int index = vending[i].index;
  6127. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  6128. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6129. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6130. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6131. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6132. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  6133. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  6134. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  6135. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  6136. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  6137. #if PACKETVER >= 20150226
  6138. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->status.cart[index]);
  6139. #endif
  6140. }
  6141. WFIFOSET(fd,WFIFOW(fd,2));
  6142. #if PACKETVER >= 20141022
  6143. /// 0 = Successed
  6144. /// 1 = Failed
  6145. clif_openvending_ack(sd, 0);
  6146. #endif
  6147. }
  6148. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  6149. /// 0137 <index>.W <amount>.W
  6150. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  6151. {
  6152. int fd;
  6153. nullpo_retv(sd);
  6154. fd = sd->fd;
  6155. WFIFOHEAD(fd,packet_len(0x137));
  6156. WFIFOW(fd,0) = 0x137;
  6157. WFIFOW(fd,2) = index+2;
  6158. WFIFOW(fd,4) = amount;
  6159. WFIFOSET(fd,packet_len(0x137));
  6160. }
  6161. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6162. /// 00fa <result>.B
  6163. /// result:
  6164. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6165. /// 1 = MsgStringTable[78]="party name already exists"
  6166. /// 2 = MsgStringTable[79]="already in a party"
  6167. /// 3 = cannot organize parties on this map
  6168. /// ? = nothing
  6169. void clif_party_created(struct map_session_data *sd,int result)
  6170. {
  6171. int fd;
  6172. nullpo_retv(sd);
  6173. fd=sd->fd;
  6174. WFIFOHEAD(fd,packet_len(0xfa));
  6175. WFIFOW(fd,0)=0xfa;
  6176. WFIFOB(fd,2)=result;
  6177. WFIFOSET(fd,packet_len(0xfa));
  6178. }
  6179. /// Adds new member to a party.
  6180. /// 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)
  6181. /// 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)
  6182. /// role:
  6183. /// 0 = leader
  6184. /// 1 = normal
  6185. /// state:
  6186. /// 0 = connected
  6187. /// 1 = disconnected
  6188. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6189. {
  6190. unsigned char buf[81];
  6191. int i;
  6192. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6193. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6194. } else {
  6195. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6196. }
  6197. if (i >= MAX_PARTY) return; //Should never happen...
  6198. sd = p->data[i].sd;
  6199. WBUFW(buf, 0) = 0x1e9;
  6200. WBUFL(buf, 2) = sd->status.account_id;
  6201. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6202. WBUFW(buf,10) = sd->bl.x;
  6203. WBUFW(buf,12) = sd->bl.y;
  6204. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6205. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  6206. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  6207. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  6208. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6209. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6210. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6211. }
  6212. /// Sends party information (ZC_GROUP_LIST).
  6213. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6214. /// role:
  6215. /// 0 = leader
  6216. /// 1 = normal
  6217. /// state:
  6218. /// 0 = connected
  6219. /// 1 = disconnected
  6220. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6221. {
  6222. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6223. struct map_session_data* party_sd = NULL;
  6224. int i, c;
  6225. nullpo_retv(p);
  6226. WBUFW(buf,0) = 0xfb;
  6227. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  6228. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6229. {
  6230. struct party_member* m = &p->party.member[i];
  6231. if(!m->account_id) continue;
  6232. if(party_sd == NULL) party_sd = p->data[i].sd;
  6233. WBUFL(buf,28+c*46) = m->account_id;
  6234. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6235. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  6236. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6237. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6238. c++;
  6239. }
  6240. WBUFW(buf,2) = 28+c*46;
  6241. if(sd) { // send only to self
  6242. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6243. } else if (party_sd) { // send to whole party
  6244. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6245. }
  6246. }
  6247. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6248. /// 02c9 <flag>.B
  6249. /// flag:
  6250. /// 0 = allow party invites
  6251. /// 1 = auto-deny party invites
  6252. void clif_partyinvitationstate(struct map_session_data* sd)
  6253. {
  6254. int fd;
  6255. nullpo_retv(sd);
  6256. fd = sd->fd;
  6257. WFIFOHEAD(fd, packet_len(0x2c9));
  6258. WFIFOW(fd, 0) = 0x2c9;
  6259. WFIFOB(fd, 2) = 0; // not implemented
  6260. WFIFOSET(fd, packet_len(0x2c9));
  6261. }
  6262. /// Party invitation request.
  6263. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6264. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6265. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6266. {
  6267. #if PACKETVER < 20070821
  6268. const int cmd = 0xfe;
  6269. #else
  6270. const int cmd = 0x2c6;
  6271. #endif
  6272. int fd;
  6273. struct party_data *p;
  6274. nullpo_retv(sd);
  6275. nullpo_retv(tsd);
  6276. fd=tsd->fd;
  6277. if( (p=party_search(sd->status.party_id))==NULL )
  6278. return;
  6279. WFIFOHEAD(fd,packet_len(cmd));
  6280. WFIFOW(fd,0)=cmd;
  6281. WFIFOL(fd,2)=sd->status.party_id;
  6282. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  6283. WFIFOSET(fd,packet_len(cmd));
  6284. }
  6285. /// Party invite result.
  6286. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6287. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6288. /// result=0 : char is already in a party -> MsgStringTable[80]
  6289. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6290. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6291. /// result=3 : party is full -> MsgStringTable[83]
  6292. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6293. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6294. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6295. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  6296. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  6297. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  6298. {
  6299. int fd;
  6300. nullpo_retv(sd);
  6301. fd=sd->fd;
  6302. #if PACKETVER < 20070904
  6303. if( result == 7 ) {
  6304. clif_displaymessage(fd, msg_txt(sd,3));
  6305. return;
  6306. }
  6307. #endif
  6308. #if PACKETVER < 20070821
  6309. WFIFOHEAD(fd,packet_len(0xfd));
  6310. WFIFOW(fd,0) = 0xfd;
  6311. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6312. WFIFOB(fd,26) = result;
  6313. WFIFOSET(fd,packet_len(0xfd));
  6314. #else
  6315. WFIFOHEAD(fd,packet_len(0x2c5));
  6316. WFIFOW(fd,0) = 0x2c5;
  6317. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  6318. WFIFOL(fd,26) = result;
  6319. WFIFOSET(fd,packet_len(0x2c5));
  6320. #endif
  6321. }
  6322. /// Updates party settings.
  6323. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6324. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6325. /// exp option:
  6326. /// 0 = exp sharing disabled
  6327. /// 1 = exp sharing enabled
  6328. /// 2 = cannot change exp sharing
  6329. ///
  6330. /// flag:
  6331. /// 0 = send to party
  6332. /// 1 = send to sd
  6333. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6334. {
  6335. unsigned char buf[16];
  6336. #if PACKETVER < 20090603
  6337. const int cmd = 0x101;
  6338. #else
  6339. const int cmd = 0x7d8;
  6340. #endif
  6341. nullpo_retv(p);
  6342. if(!sd && flag==0){
  6343. int i;
  6344. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6345. if (i < MAX_PARTY)
  6346. sd = p->data[i].sd;
  6347. }
  6348. if(!sd) return;
  6349. WBUFW(buf,0)=cmd;
  6350. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6351. #if PACKETVER >= 20090603
  6352. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6353. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6354. #endif
  6355. if(flag==0)
  6356. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6357. else
  6358. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6359. }
  6360. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6361. /// result:
  6362. /// 0 = leave
  6363. /// 1 = expel
  6364. /// 2 = cannot leave party on this map
  6365. /// 3 = cannot expel from party on this map
  6366. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, uint32 account_id, const char* name, int flag)
  6367. {
  6368. unsigned char buf[64];
  6369. nullpo_retv(p);
  6370. if(!sd && (flag&0xf0)==0)
  6371. {
  6372. int i;
  6373. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6374. if (i < MAX_PARTY)
  6375. sd = p->data[i].sd;
  6376. }
  6377. if(!sd) return;
  6378. WBUFW(buf,0)=0x105;
  6379. WBUFL(buf,2)=account_id;
  6380. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6381. WBUFB(buf,30)=flag&0x0f;
  6382. if((flag&0xf0)==0)
  6383. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6384. else
  6385. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6386. }
  6387. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6388. /// 0109 <packet len>.W <account id>.L <message>.?B
  6389. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6390. {
  6391. struct map_session_data *sd;
  6392. int i;
  6393. nullpo_retv(p);
  6394. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6395. if(i < MAX_PARTY){
  6396. unsigned char buf[1024];
  6397. if( len > sizeof(buf)-8 )
  6398. {
  6399. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6400. len = sizeof(buf)-8;
  6401. }
  6402. sd = p->data[i].sd;
  6403. WBUFW(buf,0)=0x109;
  6404. WBUFW(buf,2)=len+8;
  6405. WBUFL(buf,4)=account_id;
  6406. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6407. clif_send(buf,len+8,&sd->bl,PARTY);
  6408. }
  6409. }
  6410. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6411. /// 0107 <account id>.L <x>.W <y>.W
  6412. void clif_party_xy(struct map_session_data *sd)
  6413. {
  6414. unsigned char buf[16];
  6415. nullpo_retv(sd);
  6416. WBUFW(buf,0)=0x107;
  6417. WBUFL(buf,2)=sd->status.account_id;
  6418. WBUFW(buf,6)=sd->bl.x;
  6419. WBUFW(buf,8)=sd->bl.y;
  6420. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6421. }
  6422. /*==========================================
  6423. * Sends x/y dot to a single fd. [Skotlex]
  6424. *------------------------------------------*/
  6425. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6426. {
  6427. WFIFOHEAD(fd,packet_len(0x107));
  6428. WFIFOW(fd,0)=0x107;
  6429. WFIFOL(fd,2)=sd->status.account_id;
  6430. WFIFOW(fd,6)=sd->bl.x;
  6431. WFIFOW(fd,8)=sd->bl.y;
  6432. WFIFOSET(fd,packet_len(0x107));
  6433. }
  6434. /// Updates HP bar of a party member.
  6435. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6436. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6437. void clif_party_hp(struct map_session_data *sd)
  6438. {
  6439. unsigned char buf[16];
  6440. #if PACKETVER < 20100126
  6441. const int cmd = 0x106;
  6442. #else
  6443. const int cmd = 0x80e;
  6444. #endif
  6445. nullpo_retv(sd);
  6446. WBUFW(buf,0)=cmd;
  6447. WBUFL(buf,2)=sd->status.account_id;
  6448. #if PACKETVER < 20100126
  6449. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6450. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6451. WBUFW(buf,8) = 100;
  6452. } else {
  6453. WBUFW(buf,6) = sd->battle_status.hp;
  6454. WBUFW(buf,8) = sd->battle_status.max_hp;
  6455. }
  6456. #else
  6457. WBUFL(buf,6) = sd->battle_status.hp;
  6458. WBUFL(buf,10) = sd->battle_status.max_hp;
  6459. #endif
  6460. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6461. }
  6462. /*==========================================
  6463. * Sends HP bar to a single fd. [Skotlex]
  6464. *------------------------------------------*/
  6465. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6466. {
  6467. #if PACKETVER < 20100126
  6468. const int cmd = 0x106;
  6469. #else
  6470. const int cmd = 0x80e;
  6471. #endif
  6472. WFIFOHEAD(fd,packet_len(cmd));
  6473. WFIFOW(fd,0) = cmd;
  6474. WFIFOL(fd,2) = id;
  6475. #if PACKETVER < 20100126
  6476. if( maxhp > INT16_MAX )
  6477. {// To correctly display the %hp bar. [Skotlex]
  6478. WFIFOW(fd,6) = hp/(maxhp/100);
  6479. WFIFOW(fd,8) = 100;
  6480. } else {
  6481. WFIFOW(fd,6) = hp;
  6482. WFIFOW(fd,8) = maxhp;
  6483. }
  6484. #else
  6485. WFIFOL(fd,6) = hp;
  6486. WFIFOL(fd,10) = maxhp;
  6487. #endif
  6488. WFIFOSET(fd, packet_len(cmd));
  6489. }
  6490. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6491. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6492. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6493. {
  6494. int fd;
  6495. nullpo_retv(sd);
  6496. nullpo_retv(bl);
  6497. fd=sd->fd;
  6498. WFIFOHEAD(fd,packet_len(0x139));
  6499. WFIFOW(fd, 0)=0x139;
  6500. WFIFOL(fd, 2)=bl->id;
  6501. WFIFOW(fd, 6)=bl->x;
  6502. WFIFOW(fd, 8)=bl->y;
  6503. WFIFOW(fd,10)=sd->bl.x;
  6504. WFIFOW(fd,12)=sd->bl.y;
  6505. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6506. WFIFOSET(fd,packet_len(0x139));
  6507. }
  6508. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6509. /// 018f <result>.W <name id>.W
  6510. /// result:
  6511. /// 0 = success
  6512. /// 1 = failure
  6513. /// 2 = success (alchemist)
  6514. /// 3 = failure (alchemist)
  6515. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6516. {
  6517. int view,fd;
  6518. nullpo_retv(sd);
  6519. fd = sd->fd;
  6520. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6521. WFIFOHEAD(fd,packet_len(0x18f));
  6522. WFIFOW(fd, 0)=0x18f;
  6523. WFIFOW(fd, 2)=flag;
  6524. if((view = itemdb_viewid(nameid)) > 0)
  6525. WFIFOW(fd, 4)=view;
  6526. else
  6527. WFIFOW(fd, 4)=nameid;
  6528. WFIFOSET(fd,packet_len(0x18f));
  6529. }
  6530. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6531. /// 019e
  6532. void clif_catch_process(struct map_session_data *sd)
  6533. {
  6534. int fd;
  6535. nullpo_retv(sd);
  6536. fd=sd->fd;
  6537. WFIFOHEAD(fd,packet_len(0x19e));
  6538. WFIFOW(fd,0)=0x19e;
  6539. WFIFOSET(fd,packet_len(0x19e));
  6540. }
  6541. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6542. /// 01a0 <result>.B
  6543. /// 0 = failure
  6544. /// 1 = success
  6545. void clif_pet_roulette(struct map_session_data *sd,int data)
  6546. {
  6547. int fd;
  6548. nullpo_retv(sd);
  6549. fd=sd->fd;
  6550. WFIFOHEAD(fd,packet_len(0x1a0));
  6551. WFIFOW(fd,0)=0x1a0;
  6552. WFIFOB(fd,2)=data;
  6553. WFIFOSET(fd,packet_len(0x1a0));
  6554. }
  6555. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6556. /// 01a6 <packet len>.W { <index>.W }*
  6557. void clif_sendegg(struct map_session_data *sd)
  6558. {
  6559. int i,n=0,fd;
  6560. nullpo_retv(sd);
  6561. fd=sd->fd;
  6562. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6563. clif_displaymessage(fd, msg_txt(sd,666));
  6564. return;
  6565. }
  6566. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6567. WFIFOW(fd,0)=0x1a6;
  6568. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6569. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6570. sd->inventory_data[i]->type!=IT_PETEGG ||
  6571. sd->status.inventory[i].amount<=0)
  6572. continue;
  6573. WFIFOW(fd,n*2+4)=i+2;
  6574. n++;
  6575. }
  6576. WFIFOW(fd,2)=4+n*2;
  6577. WFIFOSET(fd,WFIFOW(fd,2));
  6578. sd->menuskill_id = SA_TAMINGMONSTER;
  6579. sd->menuskill_val = -1;
  6580. }
  6581. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6582. /// 01a4 <type>.B <id>.L <data>.L
  6583. /// type:
  6584. /// 0 = pre-init (data = 0)
  6585. /// 1 = intimacy (data = 0~4)
  6586. /// 2 = hunger (data = 0~4)
  6587. /// 3 = accessory
  6588. /// 4 = performance (data = 1~3: normal, 4: special)
  6589. /// 5 = hairstyle
  6590. ///
  6591. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6592. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6593. {
  6594. uint8 buf[16];
  6595. nullpo_retv(pd);
  6596. WBUFW(buf,0) = 0x1a4;
  6597. WBUFB(buf,2) = type;
  6598. WBUFL(buf,3) = pd->bl.id;
  6599. WBUFL(buf,7) = param;
  6600. if (sd)
  6601. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6602. else
  6603. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6604. }
  6605. /// Pet's base data (ZC_PROPERTY_PET).
  6606. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6607. void clif_send_petstatus(struct map_session_data *sd)
  6608. {
  6609. int fd;
  6610. struct s_pet *pet;
  6611. nullpo_retv(sd);
  6612. nullpo_retv(sd->pd);
  6613. fd=sd->fd;
  6614. pet = &sd->pd->pet;
  6615. WFIFOHEAD(fd,packet_len(0x1a2));
  6616. WFIFOW(fd,0)=0x1a2;
  6617. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6618. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6619. WFIFOW(fd,27)=pet->level;
  6620. WFIFOW(fd,29)=pet->hungry;
  6621. WFIFOW(fd,31)=pet->intimate;
  6622. WFIFOW(fd,33)=pet->equip;
  6623. #if PACKETVER >= 20081126
  6624. WFIFOW(fd,35)=pet->class_;
  6625. #endif
  6626. WFIFOSET(fd,packet_len(0x1a2));
  6627. }
  6628. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6629. /// 01aa <id>.L <data>.L
  6630. /// data:
  6631. /// @see CZ_PET_ACT.
  6632. void clif_pet_emotion(struct pet_data *pd,int param)
  6633. {
  6634. unsigned char buf[16];
  6635. nullpo_retv(pd);
  6636. memset(buf,0,packet_len(0x1aa));
  6637. WBUFW(buf,0)=0x1aa;
  6638. WBUFL(buf,2)=pd->bl.id;
  6639. if(param >= 100 && pd->petDB->talk_convert_class) {
  6640. if(pd->petDB->talk_convert_class < 0)
  6641. return;
  6642. else if(pd->petDB->talk_convert_class > 0) {
  6643. // replace mob_id component of talk/act data
  6644. param -= (pd->pet.class_ - 100)*100;
  6645. param += (pd->petDB->talk_convert_class - 100)*100;
  6646. }
  6647. }
  6648. WBUFL(buf,6)=param;
  6649. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6650. }
  6651. /// Result of request to feed a pet (ZC_FEED_PET).
  6652. /// 01a3 <result>.B <name id>.W
  6653. /// result:
  6654. /// 0 = failure
  6655. /// 1 = success
  6656. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6657. {
  6658. int fd;
  6659. nullpo_retv(sd);
  6660. fd=sd->fd;
  6661. WFIFOHEAD(fd,packet_len(0x1a3));
  6662. WFIFOW(fd,0)=0x1a3;
  6663. WFIFOB(fd,2)=fail;
  6664. WFIFOW(fd,3)=foodid;
  6665. WFIFOSET(fd,packet_len(0x1a3));
  6666. }
  6667. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6668. /// 01cd { <skill id>.L }*7
  6669. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6670. {
  6671. int fd;
  6672. nullpo_retv(sd);
  6673. fd=sd->fd;
  6674. WFIFOHEAD(fd,packet_len(0x1cd));
  6675. WFIFOW(fd, 0)=0x1cd;
  6676. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6677. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6678. else
  6679. WFIFOL(fd,2)= 0x00000000;
  6680. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6681. WFIFOL(fd,6)= MG_COLDBOLT;
  6682. else
  6683. WFIFOL(fd,6)= 0x00000000;
  6684. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6685. WFIFOL(fd,10)= MG_FIREBOLT;
  6686. else
  6687. WFIFOL(fd,10)= 0x00000000;
  6688. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6689. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6690. else
  6691. WFIFOL(fd,14)= 0x00000000;
  6692. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6693. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6694. else
  6695. WFIFOL(fd,18)= 0x00000000;
  6696. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6697. WFIFOL(fd,22)= MG_FIREBALL;
  6698. else
  6699. WFIFOL(fd,22)= 0x00000000;
  6700. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6701. WFIFOL(fd,26)= MG_FROSTDIVER;
  6702. else
  6703. WFIFOL(fd,26)= 0x00000000;
  6704. WFIFOSET(fd,packet_len(0x1cd));
  6705. sd->menuskill_id = SA_AUTOSPELL;
  6706. sd->menuskill_val = skill_lv;
  6707. }
  6708. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6709. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6710. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6711. {
  6712. unsigned char buf[56];
  6713. nullpo_retv(src);
  6714. memset(buf,0,packet_len(0x1cf));
  6715. WBUFW(buf,0) = 0x1cf;
  6716. WBUFL(buf,2) = src->id;
  6717. if( src->type == BL_MER )
  6718. {
  6719. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6720. if( md && md->master && md->devotion_flag )
  6721. WBUFL(buf,6) = md->master->bl.id;
  6722. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6723. }
  6724. else
  6725. {
  6726. int i;
  6727. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6728. if( sd == NULL )
  6729. return;
  6730. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6731. WBUFL(buf,6+4*i) = sd->devotion[i];
  6732. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6733. }
  6734. if( tsd )
  6735. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6736. else
  6737. clif_send(buf, packet_len(0x1cf), src, AREA);
  6738. }
  6739. /*==========================================
  6740. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6741. * Notifies clients in an area of an object's spirits.
  6742. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6743. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6744. *------------------------------------------*/
  6745. void clif_spiritball(struct block_list *bl) {
  6746. unsigned char buf[16];
  6747. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6748. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6749. nullpo_retv(bl);
  6750. WBUFW(buf, 0) = 0x1d0;
  6751. WBUFL(buf, 2) = bl->id;
  6752. WBUFW(buf, 6) = 0; //init to 0
  6753. switch(bl->type){
  6754. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6755. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6756. }
  6757. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6758. }
  6759. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6760. /// 01d2 <account id>.L <delay>.L
  6761. void clif_combo_delay(struct block_list *bl,int wait)
  6762. {
  6763. unsigned char buf[32];
  6764. nullpo_retv(bl);
  6765. WBUFW(buf,0)=0x1d2;
  6766. WBUFL(buf,2)=bl->id;
  6767. WBUFL(buf,6)=wait;
  6768. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6769. }
  6770. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6771. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6772. /// flag:
  6773. /// 0 = inactive
  6774. /// 1 = active
  6775. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6776. {
  6777. unsigned char buf[32];
  6778. nullpo_retv(src);
  6779. WBUFW(buf,0)=0x1d1;
  6780. WBUFL(buf,2)=src->id;
  6781. WBUFL(buf,6)=dst_id;
  6782. WBUFL(buf,10)=active;
  6783. clif_send(buf,packet_len(0x1d1),src,AREA);
  6784. }
  6785. /// MVP effect (ZC_MVP).
  6786. /// 010c <account id>.L
  6787. void clif_mvp_effect(struct map_session_data *sd)
  6788. {
  6789. unsigned char buf[16];
  6790. nullpo_retv(sd);
  6791. WBUFW(buf,0)=0x10c;
  6792. WBUFL(buf,2)=sd->bl.id;
  6793. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6794. }
  6795. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6796. /// 010a <name id>.W
  6797. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6798. {
  6799. int view,fd;
  6800. nullpo_retv(sd);
  6801. fd=sd->fd;
  6802. WFIFOHEAD(fd,packet_len(0x10a));
  6803. WFIFOW(fd,0)=0x10a;
  6804. if((view = itemdb_viewid(nameid)) > 0)
  6805. WFIFOW(fd,2)=view;
  6806. else
  6807. WFIFOW(fd,2)=nameid;
  6808. WFIFOSET(fd,packet_len(0x10a));
  6809. }
  6810. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6811. /// 010b <exp>.L
  6812. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6813. {
  6814. int fd;
  6815. nullpo_retv(sd);
  6816. fd=sd->fd;
  6817. WFIFOHEAD(fd,packet_len(0x10b));
  6818. WFIFOW(fd,0)=0x10b;
  6819. WFIFOL(fd,2)=min(exp,(unsigned int)INT32_MAX);
  6820. WFIFOSET(fd,packet_len(0x10b));
  6821. }
  6822. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6823. /// 010d
  6824. ///
  6825. /// "You are the MVP, but cannot obtain the reward because
  6826. /// you are overweight."
  6827. void clif_mvp_noitem(struct map_session_data* sd)
  6828. {
  6829. int fd = sd->fd;
  6830. WFIFOHEAD(fd,packet_len(0x10d));
  6831. WFIFOW(fd,0) = 0x10d;
  6832. WFIFOSET(fd,packet_len(0x10d));
  6833. }
  6834. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6835. /// 0167 <result>.B
  6836. /// result:
  6837. /// 0 = "Guild has been created."
  6838. /// 1 = "You are already in a Guild."
  6839. /// 2 = "That Guild Name already exists."
  6840. /// 3 = "You need the neccessary item to create a Guild."
  6841. void clif_guild_created(struct map_session_data *sd,int flag)
  6842. {
  6843. int fd;
  6844. nullpo_retv(sd);
  6845. fd=sd->fd;
  6846. WFIFOHEAD(fd,packet_len(0x167));
  6847. WFIFOW(fd,0)=0x167;
  6848. WFIFOB(fd,2)=flag;
  6849. WFIFOSET(fd,packet_len(0x167));
  6850. }
  6851. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6852. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6853. /// mode:
  6854. /// &0x01 = allow invite
  6855. /// &0x10 = allow expel
  6856. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6857. {
  6858. int ps,fd;
  6859. nullpo_retv(sd);
  6860. nullpo_retv(g);
  6861. fd=sd->fd;
  6862. ps=guild_getposition(g,sd);
  6863. WFIFOHEAD(fd,packet_len(0x16c));
  6864. WFIFOW(fd,0)=0x16c;
  6865. WFIFOL(fd,2)=g->guild_id;
  6866. WFIFOL(fd,6)=g->emblem_id;
  6867. WFIFOL(fd,10)=g->position[ps].mode;
  6868. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6869. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6870. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6871. WFIFOSET(fd,packet_len(0x16c));
  6872. }
  6873. /// Guild member login notice.
  6874. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6875. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6876. /// status:
  6877. /// 0 = offline
  6878. /// 1 = online
  6879. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6880. {
  6881. unsigned char buf[64];
  6882. struct map_session_data* sd;
  6883. nullpo_retv(g);
  6884. WBUFW(buf, 0)=0x1f2;
  6885. WBUFL(buf, 2)=g->member[idx].account_id;
  6886. WBUFL(buf, 6)=g->member[idx].char_id;
  6887. WBUFL(buf,10)=flag;
  6888. if( ( sd = g->member[idx].sd ) != NULL )
  6889. {
  6890. WBUFW(buf,14) = sd->status.sex;
  6891. WBUFW(buf,16) = sd->status.hair;
  6892. WBUFW(buf,18) = sd->status.hair_color;
  6893. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6894. }
  6895. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6896. {
  6897. WBUFW(buf,14) = 0;
  6898. WBUFW(buf,16) = 0;
  6899. WBUFW(buf,18) = 0;
  6900. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6901. }
  6902. }
  6903. // Function `clif_guild_memberlogin_notice` sends info about
  6904. // logins and logouts of a guild member to the rest members.
  6905. // But at the 1st time (after a player login or map changing)
  6906. // the client won't show the message.
  6907. // So I suggest use this function for sending "first-time-info"
  6908. // to some player on entering the game or changing location.
  6909. // At next time the client would always show the message.
  6910. // The function sends all the statuses in the single packet
  6911. // to economize traffic. [LuzZza]
  6912. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6913. {
  6914. struct guild *g;
  6915. unsigned char buf[14*128];
  6916. int i, count=0, p_len;
  6917. nullpo_retv(sd);
  6918. p_len = packet_len(0x16d);
  6919. if(!(g = sd->guild))
  6920. return;
  6921. for(i=0; i<g->max_member; i++) {
  6922. if(g->member[i].account_id > 0 &&
  6923. g->member[i].account_id != sd->status.account_id) {
  6924. WBUFW(buf,count*p_len) = 0x16d;
  6925. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6926. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6927. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6928. count++;
  6929. }
  6930. }
  6931. clif_send(buf, p_len*count, &sd->bl, SELF);
  6932. }
  6933. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6934. /// 014e <menu flag>.L
  6935. /// menu flag:
  6936. /// 0x00 = Basic Info (always on)
  6937. /// &0x01 = Member manager
  6938. /// &0x02 = Positions
  6939. /// &0x04 = Skills
  6940. /// &0x10 = Expulsion list
  6941. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6942. /// &0x80 = Notice
  6943. void clif_guild_masterormember(struct map_session_data *sd)
  6944. {
  6945. int fd;
  6946. nullpo_retv(sd);
  6947. fd=sd->fd;
  6948. WFIFOHEAD(fd,packet_len(0x14e));
  6949. WFIFOW(fd,0) = 0x14e;
  6950. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6951. WFIFOSET(fd,packet_len(0x14e));
  6952. }
  6953. /// Guild basic information (Territories [Valaris])
  6954. /// 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)
  6955. /// 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)
  6956. void clif_guild_basicinfo(struct map_session_data *sd) {
  6957. int fd;
  6958. struct guild *g;
  6959. nullpo_retv(sd);
  6960. fd = sd->fd;
  6961. if( (g = sd->guild) == NULL )
  6962. return;
  6963. WFIFOHEAD(fd,packet_len(0x1b6));
  6964. WFIFOW(fd, 0)=0x1b6;//0x150;
  6965. WFIFOL(fd, 2)=g->guild_id;
  6966. WFIFOL(fd, 6)=g->guild_lv;
  6967. WFIFOL(fd,10)=g->connect_member;
  6968. WFIFOL(fd,14)=g->max_member;
  6969. WFIFOL(fd,18)=g->average_lv;
  6970. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6971. WFIFOL(fd,26)=g->next_exp;
  6972. WFIFOL(fd,30)=0; // Tax Points
  6973. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6974. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6975. WFIFOL(fd,42)=g->emblem_id;
  6976. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6977. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6978. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6979. WFIFOL(fd,110) = 0; // zeny
  6980. WFIFOSET(fd,packet_len(0x1b6));
  6981. }
  6982. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6983. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6984. void clif_guild_allianceinfo(struct map_session_data *sd)
  6985. {
  6986. int fd,i,c;
  6987. struct guild *g;
  6988. nullpo_retv(sd);
  6989. if( (g = sd->guild) == NULL )
  6990. return;
  6991. fd = sd->fd;
  6992. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6993. WFIFOW(fd, 0)=0x14c;
  6994. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6995. struct guild_alliance *a=&g->alliance[i];
  6996. if(a->guild_id>0){
  6997. WFIFOL(fd,c*32+4)=a->opposition;
  6998. WFIFOL(fd,c*32+8)=a->guild_id;
  6999. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  7000. c++;
  7001. }
  7002. }
  7003. WFIFOW(fd, 2)=c*32+4;
  7004. WFIFOSET(fd,WFIFOW(fd,2));
  7005. }
  7006. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  7007. /// 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 }*
  7008. /// state:
  7009. /// 0 = offline
  7010. /// 1 = online
  7011. /// memo:
  7012. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7013. void clif_guild_memberlist(struct map_session_data *sd)
  7014. {
  7015. int fd;
  7016. int i,c;
  7017. struct guild *g;
  7018. nullpo_retv(sd);
  7019. if( (fd = sd->fd) == 0 )
  7020. return;
  7021. if( (g = sd->guild) == NULL )
  7022. return;
  7023. WFIFOHEAD(fd, g->max_member * 104 + 4);
  7024. WFIFOW(fd, 0)=0x154;
  7025. for(i=0,c=0;i<g->max_member;i++){
  7026. struct guild_member *m=&g->member[i];
  7027. if(m->account_id==0)
  7028. continue;
  7029. WFIFOL(fd,c*104+ 4)=m->account_id;
  7030. WFIFOL(fd,c*104+ 8)=m->char_id;
  7031. WFIFOW(fd,c*104+12)=m->hair;
  7032. WFIFOW(fd,c*104+14)=m->hair_color;
  7033. WFIFOW(fd,c*104+16)=m->gender;
  7034. WFIFOW(fd,c*104+18)=m->class_;
  7035. WFIFOW(fd,c*104+20)=m->lv;
  7036. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7037. WFIFOL(fd,c*104+26)=m->online;
  7038. WFIFOL(fd,c*104+30)=m->position;
  7039. 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.
  7040. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  7041. c++;
  7042. }
  7043. WFIFOW(fd, 2)=c*104+4;
  7044. WFIFOSET(fd,WFIFOW(fd,2));
  7045. }
  7046. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7047. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7048. void clif_guild_positionnamelist(struct map_session_data *sd)
  7049. {
  7050. int i,fd;
  7051. struct guild *g;
  7052. nullpo_retv(sd);
  7053. if( (g = sd->guild) == NULL )
  7054. return;
  7055. fd = sd->fd;
  7056. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7057. WFIFOW(fd, 0)=0x166;
  7058. for(i=0;i<MAX_GUILDPOSITION;i++){
  7059. WFIFOL(fd,i*28+4)=i;
  7060. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7061. }
  7062. WFIFOW(fd,2)=i*28+4;
  7063. WFIFOSET(fd,WFIFOW(fd,2));
  7064. }
  7065. /// Guild position information (ZC_POSITION_INFO).
  7066. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7067. /// mode:
  7068. /// &0x01 = allow invite
  7069. /// &0x10 = allow expel
  7070. /// ranking:
  7071. /// TODO
  7072. void clif_guild_positioninfolist(struct map_session_data *sd)
  7073. {
  7074. int i,fd;
  7075. struct guild *g;
  7076. nullpo_retv(sd);
  7077. if( (g = sd->guild) == NULL )
  7078. return;
  7079. fd = sd->fd;
  7080. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7081. WFIFOW(fd, 0)=0x160;
  7082. for(i=0;i<MAX_GUILDPOSITION;i++){
  7083. struct guild_position *p=&g->position[i];
  7084. WFIFOL(fd,i*16+ 4)=i;
  7085. WFIFOL(fd,i*16+ 8)=p->mode;
  7086. WFIFOL(fd,i*16+12)=i;
  7087. WFIFOL(fd,i*16+16)=p->exp_mode;
  7088. }
  7089. WFIFOW(fd, 2)=i*16+4;
  7090. WFIFOSET(fd,WFIFOW(fd,2));
  7091. }
  7092. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7093. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7094. /// mode:
  7095. /// &0x01 = allow invite
  7096. /// &0x10 = allow expel
  7097. /// ranking:
  7098. /// TODO
  7099. void clif_guild_positionchanged(struct guild *g,int idx)
  7100. {
  7101. // FIXME: This packet is intended to update the clients after a
  7102. // commit of position info changes, not sending one packet per
  7103. // position.
  7104. struct map_session_data *sd;
  7105. unsigned char buf[128];
  7106. nullpo_retv(g);
  7107. WBUFW(buf, 0)=0x174;
  7108. WBUFW(buf, 2)=44; // packet len
  7109. // GUILD_REG_POSITION_INFO{
  7110. WBUFL(buf, 4)=idx;
  7111. WBUFL(buf, 8)=g->position[idx].mode;
  7112. WBUFL(buf,12)=idx;
  7113. WBUFL(buf,16)=g->position[idx].exp_mode;
  7114. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  7115. // }*
  7116. if( (sd=guild_getavailablesd(g))!=NULL )
  7117. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7118. }
  7119. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7120. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7121. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7122. {
  7123. // FIXME: This packet is intended to update the clients after a
  7124. // commit of member position assignment changes, not sending one
  7125. // packet per position.
  7126. struct map_session_data *sd;
  7127. unsigned char buf[64];
  7128. nullpo_retv(g);
  7129. WBUFW(buf, 0)=0x156;
  7130. WBUFW(buf, 2)=16; // packet len
  7131. // MEMBER_POSITION_INFO{
  7132. WBUFL(buf, 4)=g->member[idx].account_id;
  7133. WBUFL(buf, 8)=g->member[idx].char_id;
  7134. WBUFL(buf,12)=g->member[idx].position;
  7135. // }*
  7136. if( (sd=guild_getavailablesd(g))!=NULL )
  7137. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7138. }
  7139. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7140. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7141. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7142. {
  7143. int fd;
  7144. nullpo_retv(sd);
  7145. nullpo_retv(g);
  7146. fd = sd->fd;
  7147. if( g->emblem_len <= 0 )
  7148. return;
  7149. WFIFOHEAD(fd,g->emblem_len+12);
  7150. WFIFOW(fd,0)=0x152;
  7151. WFIFOW(fd,2)=g->emblem_len+12;
  7152. WFIFOL(fd,4)=g->guild_id;
  7153. WFIFOL(fd,8)=g->emblem_id;
  7154. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7155. WFIFOSET(fd,WFIFOW(fd,2));
  7156. }
  7157. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7158. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7159. void clif_guild_emblem_area(struct block_list* bl)
  7160. {
  7161. uint8 buf[12];
  7162. nullpo_retv(bl);
  7163. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7164. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7165. WBUFW(buf,0) = 0x1b4;
  7166. WBUFL(buf,2) = bl->id;
  7167. WBUFL(buf,6) = status_get_guild_id(bl);
  7168. WBUFW(buf,10) = status_get_emblem_id(bl);
  7169. clif_send(buf, 12, bl, AREA_WOS);
  7170. }
  7171. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7172. /// 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 }*
  7173. void clif_guild_skillinfo(struct map_session_data* sd)
  7174. {
  7175. int fd;
  7176. struct guild* g;
  7177. int i,c;
  7178. nullpo_retv(sd);
  7179. if( (g = sd->guild) == NULL )
  7180. return;
  7181. fd = sd->fd;
  7182. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7183. WFIFOW(fd,0) = 0x0162;
  7184. WFIFOW(fd,4) = g->skill_point;
  7185. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7186. {
  7187. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7188. {
  7189. int id = g->skill[i].id;
  7190. int p = 6 + c*37;
  7191. WFIFOW(fd,p+0) = id;
  7192. WFIFOL(fd,p+2) = skill_get_inf(id);
  7193. WFIFOW(fd,p+6) = g->skill[i].lv;
  7194. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7195. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7196. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7197. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7198. c++;
  7199. }
  7200. }
  7201. WFIFOW(fd,2) = 6 + c*37;
  7202. WFIFOSET(fd,WFIFOW(fd,2));
  7203. }
  7204. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7205. /// 016f <subject>.60B <notice>.120B
  7206. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  7207. {
  7208. int fd;
  7209. nullpo_retv(sd);
  7210. nullpo_retv(g);
  7211. fd = sd->fd;
  7212. if ( !session_isActive(fd) )
  7213. return;
  7214. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7215. return;
  7216. WFIFOHEAD(fd,packet_len(0x16f));
  7217. WFIFOW(fd,0) = 0x16f;
  7218. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7219. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7220. WFIFOSET(fd,packet_len(0x16f));
  7221. }
  7222. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7223. /// 016a <guild id>.L <guild name>.24B
  7224. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7225. {
  7226. int fd;
  7227. nullpo_retv(sd);
  7228. nullpo_retv(g);
  7229. fd=sd->fd;
  7230. WFIFOHEAD(fd,packet_len(0x16a));
  7231. WFIFOW(fd,0)=0x16a;
  7232. WFIFOL(fd,2)=g->guild_id;
  7233. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  7234. WFIFOSET(fd,packet_len(0x16a));
  7235. }
  7236. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7237. /// 0169 <answer>.B
  7238. /// answer:
  7239. /// 0 = Already in guild.
  7240. /// 1 = Offer rejected.
  7241. /// 2 = Offer accepted.
  7242. /// 3 = Guild full.
  7243. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7244. {
  7245. int fd;
  7246. nullpo_retv(sd);
  7247. fd=sd->fd;
  7248. WFIFOHEAD(fd,packet_len(0x169));
  7249. WFIFOW(fd,0)=0x169;
  7250. WFIFOB(fd,2)=flag;
  7251. WFIFOSET(fd,packet_len(0x169));
  7252. }
  7253. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7254. /// 015a <char name>.24B <reason>.40B
  7255. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7256. {
  7257. unsigned char buf[128];
  7258. nullpo_retv(sd);
  7259. WBUFW(buf, 0)=0x15a;
  7260. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  7261. memcpy(WBUFP(buf,26),mes,40);
  7262. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7263. }
  7264. /// Notifies clients of a guild of an expelled member.
  7265. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7266. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7267. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7268. {
  7269. unsigned char buf[128];
  7270. #if PACKETVER < 20100803
  7271. const unsigned short cmd = 0x15c;
  7272. #else
  7273. const unsigned short cmd = 0x839;
  7274. #endif
  7275. nullpo_retv(sd);
  7276. WBUFW(buf,0) = cmd;
  7277. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7278. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  7279. #if PACKETVER < 20100803
  7280. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7281. #endif
  7282. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7283. }
  7284. /// Guild expulsion list (ZC_BAN_LIST).
  7285. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7286. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7287. void clif_guild_expulsionlist(struct map_session_data* sd)
  7288. {
  7289. #if PACKETVER < 20100803
  7290. const int offset = NAME_LENGTH*2+40;
  7291. #else
  7292. const int offset = NAME_LENGTH+40;
  7293. #endif
  7294. int fd, i, c = 0;
  7295. struct guild* g;
  7296. nullpo_retv(sd);
  7297. if( (g = sd->guild) == NULL )
  7298. return;
  7299. fd = sd->fd;
  7300. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7301. WFIFOW(fd,0) = 0x163;
  7302. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7303. {
  7304. struct guild_expulsion* e = &g->expulsion[i];
  7305. if( e->account_id > 0 )
  7306. {
  7307. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7308. #if PACKETVER < 20100803
  7309. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7310. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7311. #else
  7312. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7313. #endif
  7314. c++;
  7315. }
  7316. }
  7317. WFIFOW(fd,2) = 4 + c*offset;
  7318. WFIFOSET(fd,WFIFOW(fd,2));
  7319. }
  7320. /// Guild chat message (ZC_GUILD_CHAT).
  7321. /// 017f <packet len>.W <message>.?B
  7322. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7323. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7324. struct map_session_data *sd;
  7325. uint8 buf[256];
  7326. if( len == 0 )
  7327. {
  7328. return;
  7329. }
  7330. else if( len > sizeof(buf)-5 )
  7331. {
  7332. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7333. len = sizeof(buf)-5;
  7334. }
  7335. WBUFW(buf, 0) = 0x17f;
  7336. WBUFW(buf, 2) = len + 5;
  7337. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7338. if ((sd = guild_getavailablesd(g)) != NULL)
  7339. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7340. }
  7341. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7342. /// 0171 <inviter account id>.L <guild name>.24B
  7343. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7344. {
  7345. int fd;
  7346. nullpo_retv(sd);
  7347. fd=sd->fd;
  7348. WFIFOHEAD(fd,packet_len(0x171));
  7349. WFIFOW(fd,0)=0x171;
  7350. WFIFOL(fd,2)=account_id;
  7351. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  7352. WFIFOSET(fd,packet_len(0x171));
  7353. }
  7354. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7355. /// 0173 <answer>.B
  7356. /// answer:
  7357. /// 0 = Already allied.
  7358. /// 1 = You rejected the offer.
  7359. /// 2 = You accepted the offer.
  7360. /// 3 = They have too any alliances.
  7361. /// 4 = You have too many alliances.
  7362. /// 5 = Alliances are disabled.
  7363. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7364. {
  7365. int fd;
  7366. nullpo_retv(sd);
  7367. fd=sd->fd;
  7368. WFIFOHEAD(fd,packet_len(0x173));
  7369. WFIFOW(fd,0)=0x173;
  7370. WFIFOL(fd,2)=flag;
  7371. WFIFOSET(fd,packet_len(0x173));
  7372. }
  7373. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7374. /// 0184 <other guild id>.L <relation>.L
  7375. /// relation:
  7376. /// 0 = Ally
  7377. /// 1 = Enemy
  7378. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7379. {
  7380. int fd;
  7381. nullpo_retv(sd);
  7382. fd = sd->fd;
  7383. if (fd <= 0)
  7384. return;
  7385. WFIFOHEAD(fd,packet_len(0x184));
  7386. WFIFOW(fd,0)=0x184;
  7387. WFIFOL(fd,2)=guild_id;
  7388. WFIFOL(fd,6)=flag;
  7389. WFIFOSET(fd,packet_len(0x184));
  7390. }
  7391. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7392. /// 0181 <result>.B
  7393. /// result:
  7394. /// 0 = Antagonist has been set.
  7395. /// 1 = Guild has too many Antagonists.
  7396. /// 2 = Already set as an Antagonist.
  7397. /// 3 = Antagonists are disabled.
  7398. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7399. {
  7400. int fd;
  7401. nullpo_retv(sd);
  7402. fd=sd->fd;
  7403. WFIFOHEAD(fd,packet_len(0x181));
  7404. WFIFOW(fd,0)=0x181;
  7405. WFIFOB(fd,2)=flag;
  7406. WFIFOSET(fd,packet_len(0x181));
  7407. }
  7408. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7409. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7410. /*
  7411. void clif_guild_allianceadded(struct guild *g,int idx)
  7412. {
  7413. unsigned char buf[64];
  7414. WBUFW(buf,0)=0x185;
  7415. WBUFL(buf,2)=g->alliance[idx].opposition;
  7416. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7417. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7418. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7419. }
  7420. */
  7421. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7422. /// 015e <reason>.L
  7423. /// 0 = success
  7424. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7425. /// 2 = there are still members in the guild
  7426. void clif_guild_broken(struct map_session_data *sd,int flag)
  7427. {
  7428. int fd;
  7429. nullpo_retv(sd);
  7430. fd=sd->fd;
  7431. WFIFOHEAD(fd,packet_len(0x15e));
  7432. WFIFOW(fd,0)=0x15e;
  7433. WFIFOL(fd,2)=flag;
  7434. WFIFOSET(fd,packet_len(0x15e));
  7435. }
  7436. /// Displays emotion on an object (ZC_EMOTION).
  7437. /// 00c0 <id>.L <type>.B
  7438. /// type:
  7439. /// enum emotion_type
  7440. void clif_emotion(struct block_list *bl,int type)
  7441. {
  7442. unsigned char buf[8];
  7443. nullpo_retv(bl);
  7444. WBUFW(buf,0)=0xc0;
  7445. WBUFL(buf,2)=bl->id;
  7446. WBUFB(buf,6)=type;
  7447. clif_send(buf,packet_len(0xc0),bl,AREA);
  7448. }
  7449. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7450. /// 0191 <id>.L <contents>.80B
  7451. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7452. {
  7453. unsigned char buf[MESSAGE_SIZE+6];
  7454. nullpo_retv(bl);
  7455. WBUFW(buf,0) = 0x191;
  7456. WBUFL(buf,2) = bl->id;
  7457. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7458. clif_send(buf,packet_len(0x191),bl,AREA);
  7459. }
  7460. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7461. /// 01ea <id>.L
  7462. void clif_wedding_effect(struct block_list *bl)
  7463. {
  7464. unsigned char buf[6];
  7465. nullpo_retv(bl);
  7466. WBUFW(buf,0) = 0x1ea;
  7467. WBUFL(buf,2) = bl->id;
  7468. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7469. }
  7470. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7471. /// 01e6 <partner name>.24B
  7472. void clif_callpartner(struct map_session_data *sd)
  7473. {
  7474. unsigned char buf[26];
  7475. nullpo_retv(sd);
  7476. WBUFW(buf,0) = 0x1e6;
  7477. if( sd->status.partner_id ) {
  7478. const char *p = map_charid2nick(sd->status.partner_id);
  7479. struct map_session_data *p_sd = pc_get_partner(sd);
  7480. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7481. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7482. else
  7483. WBUFB(buf,2) = 0;
  7484. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7485. WBUFB(buf,2) = 0;
  7486. }
  7487. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7488. }
  7489. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7490. /// 01e4
  7491. /// This packet while still implemented by the client is no longer being officially used.
  7492. /*
  7493. void clif_marriage_process(struct map_session_data *sd)
  7494. {
  7495. int fd;
  7496. nullpo_retv(sd);
  7497. fd=sd->fd;
  7498. WFIFOHEAD(fd,packet_len(0x1e4));
  7499. WFIFOW(fd,0)=0x1e4;
  7500. WFIFOSET(fd,packet_len(0x1e4));
  7501. }
  7502. */
  7503. /// Notice of divorce (ZC_DIVORCE).
  7504. /// 0205 <partner name>.24B
  7505. void clif_divorced(struct map_session_data* sd, const char* name)
  7506. {
  7507. int fd;
  7508. nullpo_retv(sd);
  7509. fd=sd->fd;
  7510. WFIFOHEAD(fd,packet_len(0x205));
  7511. WFIFOW(fd,0)=0x205;
  7512. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7513. WFIFOSET(fd, packet_len(0x205));
  7514. }
  7515. /// Marriage proposal (ZC_REQ_COUPLE).
  7516. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7517. /// This packet while still implemented by the client is no longer being officially used.
  7518. /*
  7519. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7520. {
  7521. nullpo_retv(sd);
  7522. WFIFOHEAD(fd,packet_len(0x1e2));
  7523. WFIFOW(fd,0) = 0x1e2;
  7524. WFIFOL(fd,2) = ssd->status.account_id;
  7525. WFIFOL(fd,6) = ssd->status.char_id;
  7526. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7527. WFIFOSET(fd, packet_len(0x1e2));
  7528. }
  7529. */
  7530. /*==========================================
  7531. *
  7532. *------------------------------------------*/
  7533. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7534. {
  7535. clif_disp_message(&sd->bl, mes, len, SELF);
  7536. }
  7537. /*==========================================
  7538. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7539. *------------------------------------------*/
  7540. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7541. {
  7542. unsigned char buf[256];
  7543. if( len == 0 ) {
  7544. return;
  7545. } else if( len > sizeof(buf)-5 ) {
  7546. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7547. len = sizeof(buf)-5;
  7548. }
  7549. WBUFW(buf, 0) = 0x17f;
  7550. WBUFW(buf, 2) = len + 5;
  7551. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7552. clif_send(buf, WBUFW(buf,2), src, target);
  7553. }
  7554. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7555. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7556. /// 00cd <result>.B
  7557. /// result:
  7558. /// 0 = failure
  7559. /// 1 = success
  7560. void clif_GM_kickack(struct map_session_data *sd, int id)
  7561. {
  7562. int fd;
  7563. nullpo_retv(sd);
  7564. fd = sd->fd;
  7565. WFIFOHEAD(fd,packet_len(0xcd));
  7566. WFIFOW(fd,0) = 0xcd;
  7567. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7568. WFIFOSET(fd, packet_len(0xcd));
  7569. }
  7570. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7571. {
  7572. int fd = tsd->fd;
  7573. if( fd > 0 )
  7574. clif_authfail_fd(fd, 15);
  7575. else {
  7576. // Close vending/buyingstore
  7577. if (sd) {
  7578. if (tsd->state.vending)
  7579. vending_closevending(tsd);
  7580. else if (tsd->state.buyingstore)
  7581. buyingstore_close(tsd);
  7582. }
  7583. map_quit(tsd);
  7584. }
  7585. if( sd )
  7586. clif_GM_kickack(sd,tsd->status.account_id);
  7587. }
  7588. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7589. /// 014a <result>.L
  7590. /// result:
  7591. /// 0 = "A manner point has been successfully aligned."
  7592. /// 1 = MP_FAILURE_EXHAUST
  7593. /// 2 = MP_FAILURE_ALREADY_GIVING
  7594. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7595. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7596. /// 5 = "You got a good point from %s."
  7597. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7598. {
  7599. int fd;
  7600. nullpo_retv(sd);
  7601. fd = sd->fd;
  7602. WFIFOHEAD(fd,packet_len(0x14a));
  7603. WFIFOW(fd,0) = 0x14a;
  7604. WFIFOL(fd,2) = type;
  7605. WFIFOSET(fd, packet_len(0x14a));
  7606. }
  7607. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7608. /// 014b <type>.B <GM name>.24B
  7609. /// type:
  7610. /// 0 = positive (unmute)
  7611. /// 1 = negative (mute)
  7612. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7613. {
  7614. int fd;
  7615. nullpo_retv(sd);
  7616. nullpo_retv(tsd);
  7617. fd = tsd->fd;
  7618. WFIFOHEAD(fd,packet_len(0x14b));
  7619. WFIFOW(fd,0) = 0x14b;
  7620. WFIFOB(fd,2) = type;
  7621. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7622. WFIFOSET(fd, packet_len(0x14b));
  7623. }
  7624. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7625. /// 00d1 <type>.B <result>.B
  7626. /// type:
  7627. /// 0 = /ex (deny)
  7628. /// 1 = /in (allow)
  7629. /// result:
  7630. /// 0 = success
  7631. /// 1 = failure
  7632. /// 2 = too many blocks
  7633. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7634. {
  7635. int fd;
  7636. nullpo_retv(sd);
  7637. fd=sd->fd;
  7638. WFIFOHEAD(fd,packet_len(0xd1));
  7639. WFIFOW(fd,0)=0xd1;
  7640. WFIFOB(fd,2)=type;
  7641. WFIFOB(fd,3)=flag;
  7642. WFIFOSET(fd,packet_len(0xd1));
  7643. }
  7644. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7645. /// 00d2 <type>.B <result>.B
  7646. /// type:
  7647. /// 0 = /exall (deny)
  7648. /// 1 = /inall (allow)
  7649. /// result:
  7650. /// 0 = success
  7651. /// 1 = failure
  7652. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7653. {
  7654. int fd;
  7655. nullpo_retv(sd);
  7656. fd=sd->fd;
  7657. WFIFOHEAD(fd,packet_len(0xd2));
  7658. WFIFOW(fd,0)=0xd2;
  7659. WFIFOB(fd,2)=type;
  7660. WFIFOB(fd,3)=flag;
  7661. WFIFOSET(fd,packet_len(0xd2));
  7662. }
  7663. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7664. /// 07fe <bgm>.24B
  7665. void clif_playBGM(struct map_session_data* sd, const char* name)
  7666. {
  7667. int fd;
  7668. nullpo_retv(sd);
  7669. fd = sd->fd;
  7670. WFIFOHEAD(fd,packet_len(0x7fe));
  7671. WFIFOW(fd,0) = 0x7fe;
  7672. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7673. WFIFOSET(fd,packet_len(0x7fe));
  7674. }
  7675. /// Plays/stops a wave sound (ZC_SOUND).
  7676. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7677. /// file name:
  7678. /// relative to data\wav
  7679. /// act:
  7680. /// 0 = play (once)
  7681. /// 1 = play (repeat, does not work)
  7682. /// 2 = stops all sound instances of file name (does not work)
  7683. /// term:
  7684. /// unknown purpose, only relevant to act = 1
  7685. /// npc id:
  7686. /// The accustic direction of the sound is determined by the
  7687. /// relative position of the NPC to the player (3D sound).
  7688. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7689. {
  7690. int fd;
  7691. nullpo_retv(sd);
  7692. nullpo_retv(bl);
  7693. fd = sd->fd;
  7694. WFIFOHEAD(fd,packet_len(0x1d3));
  7695. WFIFOW(fd,0) = 0x1d3;
  7696. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7697. WFIFOB(fd,26) = type;
  7698. WFIFOL(fd,27) = 0;
  7699. WFIFOL(fd,31) = bl->id;
  7700. WFIFOSET(fd,packet_len(0x1d3));
  7701. }
  7702. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7703. {
  7704. unsigned char buf[40];
  7705. nullpo_retv(bl);
  7706. WBUFW(buf,0) = 0x1d3;
  7707. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7708. WBUFB(buf,26) = type;
  7709. WBUFL(buf,27) = 0;
  7710. WBUFL(buf,31) = bl->id;
  7711. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7712. }
  7713. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7714. /// 01f3 <id>.L <effect id>.L
  7715. /// effect id:
  7716. /// @see doc/effect_list.txt
  7717. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7718. {
  7719. unsigned char buf[24];
  7720. nullpo_retv(bl);
  7721. memset(buf, 0, packet_len(0x1f3));
  7722. WBUFW(buf,0) = 0x1f3;
  7723. WBUFL(buf,2) = bl->id;
  7724. WBUFL(buf,6) = type;
  7725. clif_send(buf, packet_len(0x1f3), bl, target);
  7726. if (disguised(bl)) {
  7727. WBUFL(buf,2) = -bl->id;
  7728. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7729. }
  7730. }
  7731. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7732. {
  7733. WFIFOHEAD(fd,10);
  7734. WFIFOW(fd,0) = 0x1f3;
  7735. WFIFOL(fd,2) = bl->id;
  7736. WFIFOL(fd,6) = type;
  7737. WFIFOSET(fd,10);
  7738. }
  7739. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7740. /// 0284 <id>.L <effect id>.L <num data>.L
  7741. /// effect id:
  7742. /// @see doc/effect_list.txt
  7743. /// num data:
  7744. /// effect-dependent value
  7745. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7746. {
  7747. uint8 buf[14];
  7748. WBUFW(buf,0) = 0x284;
  7749. WBUFL(buf,2) = bl->id;
  7750. WBUFL(buf,6) = effect_id;
  7751. WBUFL(buf,10) = num;
  7752. clif_send(buf, packet_len(0x284), bl, target);
  7753. if( disguised(bl) )
  7754. {
  7755. WBUFL(buf,2) = -bl->id;
  7756. clif_send(buf, packet_len(0x284), bl, SELF);
  7757. }
  7758. }
  7759. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7760. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7761. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7762. unsigned short msg_len = strlen(msg) + 1;
  7763. WFIFOHEAD(fd,msg_len + 12);
  7764. WFIFOW(fd,0) = 0x2C1;
  7765. WFIFOW(fd,2) = msg_len + 12;
  7766. WFIFOL(fd,4) = 0;
  7767. WFIFOL(fd,8) = color; //either color_table or channel_table
  7768. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7769. WFIFOSET(fd, msg_len + 12);
  7770. return 0;
  7771. }
  7772. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7773. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7774. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7775. unsigned short msg_len = strlen(msg) + 1;
  7776. uint8 buf[256];
  7777. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7778. nullpo_retv(bl);
  7779. if( msg_len > sizeof(buf)-12 ) {
  7780. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7781. msg_len = sizeof(buf)-12;
  7782. }
  7783. WBUFW(buf,0) = 0x2C1;
  7784. WBUFW(buf,2) = msg_len + 12;
  7785. WBUFL(buf,4) = bl->id;
  7786. WBUFL(buf,8) = color;
  7787. memcpy((char*)WBUFP(buf,12), msg, msg_len);
  7788. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7789. }
  7790. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7791. {
  7792. unsigned short msg_len = strlen(msg) + 1;
  7793. nullpo_retv(sd);
  7794. if(msg_len > 0) {
  7795. int fd;
  7796. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7797. fd = sd->fd;
  7798. WFIFOHEAD(fd, msg_len+12);
  7799. WFIFOW(fd,0) = 0x2C1;
  7800. WFIFOW(fd,2) = msg_len+12;
  7801. WFIFOL(fd,4) = 0;
  7802. WFIFOL(fd,8) = color;
  7803. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7804. WFIFOSET(fd, WFIFOW(fd,2));
  7805. }
  7806. }
  7807. /**
  7808. * Notifies the client that the storage window is still open
  7809. *
  7810. * Should only be used in cases where the client closed the
  7811. * storage window without server's consent
  7812. */
  7813. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7814. // Notify the client that the storage is open
  7815. if( sd->state.storage_flag == 1 ) {
  7816. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7817. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7818. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7819. }
  7820. // Notify the client that the gstorage is open otherwise it will
  7821. // remain locked forever and nobody will be able to access it
  7822. if( sd->state.storage_flag == 2 ) {
  7823. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7824. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7825. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7826. else {
  7827. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7828. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7829. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7830. }
  7831. }
  7832. }
  7833. // refresh the client's screen, getting rid of any effects
  7834. void clif_refresh(struct map_session_data *sd)
  7835. {
  7836. nullpo_retv(sd);
  7837. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7838. clif_inventorylist(sd);
  7839. if(pc_iscarton(sd)) {
  7840. clif_cartlist(sd);
  7841. clif_updatestatus(sd,SP_CARTINFO);
  7842. }
  7843. clif_updatestatus(sd,SP_WEIGHT);
  7844. clif_updatestatus(sd,SP_MAXWEIGHT);
  7845. clif_updatestatus(sd,SP_STR);
  7846. clif_updatestatus(sd,SP_AGI);
  7847. clif_updatestatus(sd,SP_VIT);
  7848. clif_updatestatus(sd,SP_INT);
  7849. clif_updatestatus(sd,SP_DEX);
  7850. clif_updatestatus(sd,SP_LUK);
  7851. if (sd->spiritball)
  7852. clif_spiritball_single(sd->fd, sd);
  7853. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7854. clif_spiritcharm_single(sd->fd, sd);
  7855. if (sd->vd.cloth_color)
  7856. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7857. if(hom_is_active(sd->hd))
  7858. clif_send_homdata(sd,SP_ACK,0);
  7859. if( sd->md ) {
  7860. clif_mercenary_info(sd);
  7861. clif_mercenary_skillblock(sd);
  7862. }
  7863. if( sd->ed )
  7864. clif_elemental_info(sd);
  7865. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7866. clif_weather_check(sd);
  7867. if( sd->chatID )
  7868. chat_leavechat(sd,0);
  7869. if( sd->state.vending )
  7870. clif_openvending(sd, sd->bl.id, sd->vending);
  7871. if( pc_issit(sd) )
  7872. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7873. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7874. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7875. else
  7876. clif_changed_dir(&sd->bl, SELF);
  7877. // unlike vending, resuming buyingstore crashes the client.
  7878. buyingstore_close(sd);
  7879. mail_clear(sd);
  7880. if( disguised(&sd->bl) ) {/* refresh-da */
  7881. short disguise = sd->disguise;
  7882. pc_disguise(sd, 0);
  7883. pc_disguise(sd, disguise);
  7884. }
  7885. clif_refresh_storagewindow(sd);
  7886. }
  7887. /// Updates the object's (bl) name on client.
  7888. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7889. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7890. void clif_charnameack (int fd, struct block_list *bl)
  7891. {
  7892. unsigned char buf[103];
  7893. int cmd = 0x95;
  7894. nullpo_retv(bl);
  7895. WBUFW(buf,0) = cmd;
  7896. WBUFL(buf,2) = bl->id;
  7897. switch( bl->type )
  7898. {
  7899. case BL_PC:
  7900. {
  7901. struct map_session_data *ssd = (struct map_session_data *)bl;
  7902. struct party_data *p = NULL;
  7903. struct guild *g = NULL;
  7904. int ps = -1;
  7905. //Requesting your own "shadow" name. [Skotlex]
  7906. if (ssd->fd == fd && ssd->disguise)
  7907. WBUFL(buf,2) = -bl->id;
  7908. if( ssd->fakename[0] ) {
  7909. WBUFW(buf, 0) = cmd = 0x195;
  7910. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7911. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7912. break;
  7913. }
  7914. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7915. if( ssd->status.party_id ) {
  7916. p = party_search(ssd->status.party_id);
  7917. }
  7918. if( ssd->status.guild_id ) {
  7919. if( ( g = ssd->guild ) != NULL ) {
  7920. int i;
  7921. 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);
  7922. if( i < g->max_member ) ps = g->member[i].position;
  7923. }
  7924. }
  7925. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7926. p = NULL;
  7927. }
  7928. if (p == NULL && g == NULL)
  7929. break;
  7930. WBUFW(buf, 0) = cmd = 0x195;
  7931. if (p)
  7932. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7933. else
  7934. WBUFB(buf,30) = 0;
  7935. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7936. {
  7937. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7938. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7939. } else { //Assume no guild.
  7940. WBUFB(buf,54) = 0;
  7941. WBUFB(buf,78) = 0;
  7942. }
  7943. }
  7944. break;
  7945. //[blackhole89]
  7946. case BL_HOM:
  7947. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7948. break;
  7949. case BL_MER:
  7950. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7951. break;
  7952. case BL_PET:
  7953. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7954. break;
  7955. case BL_NPC:
  7956. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7957. break;
  7958. case BL_MOB:
  7959. {
  7960. struct mob_data *md = (struct mob_data *)bl;
  7961. nullpo_retv(md);
  7962. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7963. if( md->guardian_data && md->guardian_data->guild_id )
  7964. {
  7965. WBUFW(buf, 0) = cmd = 0x195;
  7966. WBUFB(buf,30) = 0;
  7967. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7968. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7969. }
  7970. else if( battle_config.show_mob_info )
  7971. {
  7972. char mobhp[50], *str_p = mobhp;
  7973. WBUFW(buf, 0) = cmd = 0x195;
  7974. if( battle_config.show_mob_info&4 )
  7975. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7976. if( battle_config.show_mob_info&1 )
  7977. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7978. if( battle_config.show_mob_info&2 )
  7979. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7980. //Even thought mobhp ain't a name, we send it as one so the client
  7981. //can parse it. [Skotlex]
  7982. if( str_p != mobhp )
  7983. {
  7984. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7985. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7986. WBUFB(buf,54) = 0;
  7987. WBUFB(buf,78) = 0;
  7988. }
  7989. }
  7990. }
  7991. break;
  7992. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7993. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7994. // break;
  7995. return;
  7996. case BL_ELEM:
  7997. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7998. break;
  7999. default:
  8000. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  8001. return;
  8002. }
  8003. // if no receipient specified just update nearby clients
  8004. if (fd == 0)
  8005. clif_send(buf, packet_len(cmd), bl, AREA);
  8006. else {
  8007. WFIFOHEAD(fd, packet_len(cmd));
  8008. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  8009. WFIFOSET(fd, packet_len(cmd));
  8010. }
  8011. }
  8012. //Used to update when a char leaves a party/guild. [Skotlex]
  8013. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8014. void clif_charnameupdate (struct map_session_data *ssd)
  8015. {
  8016. unsigned char buf[103];
  8017. int cmd = 0x195, ps = -1;
  8018. struct party_data *p = NULL;
  8019. struct guild *g = NULL;
  8020. nullpo_retv(ssd);
  8021. if( ssd->fakename[0] )
  8022. return; //No need to update as the party/guild was not displayed anyway.
  8023. WBUFW(buf,0) = cmd;
  8024. WBUFL(buf,2) = ssd->bl.id;
  8025. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  8026. if (!battle_config.display_party_name) {
  8027. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  8028. p = party_search(ssd->status.party_id);
  8029. }else{
  8030. if (ssd->status.party_id > 0)
  8031. p = party_search(ssd->status.party_id);
  8032. }
  8033. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  8034. {
  8035. int i;
  8036. 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);
  8037. if( i < g->max_member ) ps = g->member[i].position;
  8038. }
  8039. if( p )
  8040. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  8041. else
  8042. WBUFB(buf,30) = 0;
  8043. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  8044. {
  8045. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  8046. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  8047. }
  8048. else
  8049. {
  8050. WBUFB(buf,54) = 0;
  8051. WBUFB(buf,78) = 0;
  8052. }
  8053. // Update nearby clients
  8054. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  8055. }
  8056. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8057. /// 01ff <id>.L <x>.W <y>.W
  8058. ///
  8059. /// Visually moves(instant) a character to x,y. The char moves even
  8060. /// when the target cell isn't walkable. If the char is sitting it
  8061. /// stays that way.
  8062. void clif_slide(struct block_list *bl, int x, int y)
  8063. {
  8064. unsigned char buf[10];
  8065. nullpo_retv(bl);
  8066. WBUFW(buf, 0) = 0x01ff;
  8067. WBUFL(buf, 2) = bl->id;
  8068. WBUFW(buf, 6) = x;
  8069. WBUFW(buf, 8) = y;
  8070. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8071. if( disguised(bl) )
  8072. {
  8073. WBUFL(buf,2) = -bl->id;
  8074. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8075. }
  8076. }
  8077. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8078. /// 008d <packet len>.W <id>.L <message>.?B
  8079. void clif_disp_overhead(struct block_list *bl, const char* mes)
  8080. {
  8081. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8082. int len_mes = strlen(mes)+1; //Account for \0
  8083. if (len_mes > sizeof(buf)-8) {
  8084. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8085. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8086. }
  8087. // send message to others
  8088. WBUFW(buf,0) = 0x8d;
  8089. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8090. WBUFL(buf,4) = bl->id;
  8091. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  8092. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8093. // send back message to the speaker
  8094. if( bl->type == BL_PC ) {
  8095. WBUFW(buf,0) = 0x8e;
  8096. WBUFW(buf, 2) = len_mes + 4;
  8097. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  8098. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8099. }
  8100. }
  8101. /*==========================
  8102. * Minimap fix [Kevin]
  8103. * Remove dot from minimap
  8104. *--------------------------*/
  8105. void clif_party_xy_remove(struct map_session_data *sd)
  8106. {
  8107. unsigned char buf[16];
  8108. nullpo_retv(sd);
  8109. WBUFW(buf,0)=0x107;
  8110. WBUFL(buf,2)=sd->status.account_id;
  8111. WBUFW(buf,6)=-1;
  8112. WBUFW(buf,8)=-1;
  8113. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8114. }
  8115. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8116. /// 0215 <msg id>.L
  8117. /// msg id:
  8118. /// 0x15 = End all negative status (PA_GOSPEL)
  8119. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8120. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8121. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8122. /// 0x19 = All stats +20 (PA_GOSPEL)
  8123. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8124. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8125. /// 0x1e = DEF +25% (PA_GOSPEL)
  8126. /// 0x1f = ATK +100% (PA_GOSPEL)
  8127. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8128. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8129. /// ? = nothing
  8130. void clif_gospel_info(struct map_session_data *sd, int type)
  8131. {
  8132. int fd=sd->fd;
  8133. WFIFOHEAD(fd,packet_len(0x215));
  8134. WFIFOW(fd,0)=0x215;
  8135. WFIFOL(fd,2)=type;
  8136. WFIFOSET(fd, packet_len(0x215));
  8137. }
  8138. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8139. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8140. /// result:
  8141. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8142. /// star:
  8143. /// 0 = Place of the Sun
  8144. /// 1 = Place of the Moon
  8145. /// 2 = Place of the Stars
  8146. /// 1 = Star Gladiator %s's %s: <mapname>
  8147. /// star:
  8148. /// 0 = Place of the Sun
  8149. /// 1 = Place of the Moon
  8150. /// 2 = Place of the Stars
  8151. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8152. /// star:
  8153. /// 0 = Target of the Sun
  8154. /// 1 = Target of the Moon
  8155. /// 2 = Target of the Stars
  8156. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8157. /// star:
  8158. /// 0 = Monster of the Sun
  8159. /// 1 = Monster of the Moon
  8160. /// 2 = Monster of the Stars
  8161. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8162. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8163. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8164. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8165. /// 40 = Target HP : <monster_id used as HP>
  8166. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8167. {
  8168. int fd = sd->fd;
  8169. WFIFOHEAD(fd,packet_len(0x20e));
  8170. WFIFOW(fd,0) = 0x20e;
  8171. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  8172. WFIFOL(fd,26) = monster_id;
  8173. WFIFOB(fd,30) = star;
  8174. WFIFOB(fd,31) = result;
  8175. WFIFOSET(fd,packet_len(0x20e));
  8176. }
  8177. /*==========================================
  8178. * Info about Star Glaldiator save map [Komurka]
  8179. * type: 1: Information, 0: Map registered
  8180. *------------------------------------------*/
  8181. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8182. {
  8183. char mapname[MAP_NAME_LENGTH_EXT];
  8184. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8185. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8186. }
  8187. /*==========================================
  8188. * Info about Star Glaldiator hate mob [Komurka]
  8189. * type: 1: Register mob, 0: Information.
  8190. *------------------------------------------*/
  8191. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8192. {
  8193. if( pcdb_checkid(class_) ) {
  8194. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8195. } else if( mobdb_checkid(class_) ) {
  8196. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8197. } else {
  8198. 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);
  8199. }
  8200. }
  8201. /*==========================================
  8202. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8203. *------------------------------------------*/
  8204. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8205. {
  8206. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8207. }
  8208. /*==========================================
  8209. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8210. *------------------------------------------*/
  8211. void clif_feel_hate_reset(struct map_session_data *sd)
  8212. {
  8213. clif_starskill(sd, "", 0, 0, 30);
  8214. }
  8215. /// Equip window (un)tick ack (ZC_CONFIG).
  8216. /// 02d9 <type>.L <value>.L
  8217. /// type:
  8218. /// 0 = open equip window
  8219. /// value:
  8220. /// 0 = disabled
  8221. /// 1 = enabled
  8222. void clif_equiptickack(struct map_session_data* sd, int flag)
  8223. {
  8224. int fd;
  8225. nullpo_retv(sd);
  8226. fd = sd->fd;
  8227. WFIFOHEAD(fd, packet_len(0x2d9));
  8228. WFIFOW(fd, 0) = 0x2d9;
  8229. WFIFOL(fd, 2) = 0;
  8230. WFIFOL(fd, 6) = flag;
  8231. WFIFOSET(fd, packet_len(0x2d9));
  8232. }
  8233. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8234. /// 02da <open equip window>.B
  8235. /// open equip window:
  8236. /// 0 = disabled
  8237. /// 1 = enabled
  8238. void clif_equipcheckbox(struct map_session_data* sd)
  8239. {
  8240. int fd;
  8241. nullpo_retv(sd);
  8242. fd = sd->fd;
  8243. WFIFOHEAD(fd, packet_len(0x2da));
  8244. WFIFOW(fd, 0) = 0x2da;
  8245. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8246. WFIFOSET(fd, packet_len(0x2da));
  8247. }
  8248. /// Sends info about a player's equipped items.
  8249. /// 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)
  8250. /// 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)
  8251. /// 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)
  8252. /// 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)
  8253. /// 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)
  8254. /// 0a2d <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.57B* (ZC_EQUIPWIN_MICROSCOPE_V6, PACKETVER >= 20150226)
  8255. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8256. {
  8257. uint8* buf;
  8258. int i, n, fd, offset = 0;
  8259. #if PACKETVER < 20100629
  8260. const int s = 26;
  8261. #elif PACKETVER < 20120925
  8262. const int s = 28;
  8263. #elif PACKETVER < 20150226
  8264. const int s = 31;
  8265. #else
  8266. const int s = 57;
  8267. #endif
  8268. nullpo_retv(sd);
  8269. nullpo_retv(tsd);
  8270. fd = sd->fd;
  8271. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8272. buf = WFIFOP(fd,0);
  8273. #if PACKETVER < 20101124
  8274. WBUFW(buf, 0) = 0x2d7;
  8275. #elif PACKETVER < 20120925
  8276. WBUFW(buf, 0) = 0x859;
  8277. #elif PACKETVER < 20150226
  8278. WBUFW(buf, 0) = 0x997;
  8279. #else
  8280. WBUFW(buf, 0) = 0xa2d;
  8281. #endif
  8282. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  8283. WBUFW(buf,28) = tsd->status.class_;
  8284. WBUFW(buf,30) = tsd->vd.hair_style;
  8285. WBUFW(buf,32) = tsd->vd.head_bottom;
  8286. WBUFW(buf,34) = tsd->vd.head_mid;
  8287. WBUFW(buf,36) = tsd->vd.head_top;
  8288. #if PACKETVER >= 20110111
  8289. WBUFW(buf,38) = tsd->vd.robe;
  8290. offset+= 2;
  8291. buf = WBUFP(buf,2);
  8292. #endif
  8293. WBUFW(buf,38) = tsd->vd.hair_color;
  8294. WBUFW(buf,40) = tsd->vd.cloth_color;
  8295. WBUFB(buf,42) = tsd->vd.sex;
  8296. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8297. {
  8298. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8299. continue;
  8300. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8301. continue;
  8302. // Add item info : refine, identify flag, element, etc.
  8303. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8304. n++;
  8305. }
  8306. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8307. WFIFOSET(fd, WFIFOW(fd, 2));
  8308. }
  8309. /// Display msgstringtable.txt string (ZC_MSG).
  8310. /// 0291 <message>.W
  8311. void clif_msg(struct map_session_data* sd, unsigned short id)
  8312. {
  8313. int fd;
  8314. nullpo_retv(sd);
  8315. fd = sd->fd;
  8316. WFIFOHEAD(fd, packet_len(0x291));
  8317. WFIFOW(fd, 0) = 0x291;
  8318. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8319. WFIFOSET(fd, packet_len(0x291));
  8320. }
  8321. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8322. /// 0x7e2 <message>.W <value>.L
  8323. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8324. {
  8325. int fd = sd->fd;
  8326. WFIFOHEAD(fd, packet_len(0x7e2));
  8327. WFIFOW(fd,0) = 0x7e2;
  8328. WFIFOW(fd,2) = id;
  8329. WFIFOL(fd,4) = value;
  8330. WFIFOSET(fd, packet_len(0x7e2));
  8331. }
  8332. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8333. /// 07e6 <skill id>.W <msg id>.L
  8334. ///
  8335. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8336. /// "[SkillName] Message"
  8337. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8338. {
  8339. int fd = sd->fd;
  8340. WFIFOHEAD(fd, packet_len(0x7e6));
  8341. WFIFOW(fd,0) = 0x7e6;
  8342. WFIFOW(fd,2) = skill_id;
  8343. WFIFOL(fd,4) = msg_id;
  8344. WFIFOSET(fd, packet_len(0x7e6));
  8345. }
  8346. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8347. /// Returns true if the packet was parsed successfully.
  8348. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8349. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8350. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  8351. {
  8352. char *text, *name, *message;
  8353. unsigned int packetlen, textlen, namelen, messagelen;
  8354. int fd = sd->fd;
  8355. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8356. *name_ = NULL;
  8357. *namelen_ = 0;
  8358. *message_ = NULL;
  8359. *messagelen_ = 0;
  8360. packetlen = RFIFOW(fd,info->pos[0]);
  8361. // basic structure checks
  8362. if( packetlen < 4 + 1 )
  8363. { // 4-byte header and at least an empty string is expected
  8364. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8365. return false;
  8366. }
  8367. text = (char*)RFIFOP(fd,info->pos[1]);
  8368. textlen = packetlen - 4;
  8369. // process <name> part of the packet
  8370. if( format == 0 )
  8371. {// name and message are separated by ' : '
  8372. // validate name
  8373. name = text;
  8374. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  8375. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  8376. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  8377. {
  8378. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8379. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8380. set_eof(fd); // Just kick them out to correct it.
  8381. return false;
  8382. }
  8383. message = name + namelen + 3;
  8384. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8385. #if PACKETVER >= 20150900
  8386. message[messagelen] = '\0';
  8387. messagelen++;
  8388. #endif
  8389. }
  8390. else
  8391. {// name has fixed width
  8392. if( textlen < NAME_LENGTH + 1 )
  8393. {
  8394. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8395. return false;
  8396. }
  8397. // validate name
  8398. name = text;
  8399. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8400. if( name[namelen] != '\0' )
  8401. { // only restriction is that the name must be zero-terminated
  8402. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8403. return false;
  8404. }
  8405. message = name + NAME_LENGTH;
  8406. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8407. }
  8408. if( messagelen != strnlen(message, messagelen)+1 )
  8409. { // the declared length must match real length
  8410. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8411. return false;
  8412. }
  8413. // verify <message> part of the packet
  8414. if( message[messagelen-1] != '\0' )
  8415. { // message must be zero-terminated
  8416. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8417. return false;
  8418. }
  8419. if( messagelen > CHAT_SIZE_MAX-1 )
  8420. { // messages mustn't be too long
  8421. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8422. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8423. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8424. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8425. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8426. return false;
  8427. }
  8428. *name_ = name;
  8429. *namelen_ = namelen;
  8430. *message_ = message;
  8431. *messagelen_ = messagelen;
  8432. return true;
  8433. }
  8434. // ---------------------
  8435. // clif_guess_PacketVer
  8436. // ---------------------
  8437. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8438. // error codes:
  8439. // 0 - Success
  8440. // 1 - Unknown packet_ver
  8441. // 2 - Invalid account_id
  8442. // 3 - Invalid char_id
  8443. // 4 - Invalid login_id1 (reserved)
  8444. // 5 - Invalid client_tick (reserved)
  8445. // 6 - Invalid sex
  8446. // Only the first 'invalid' error that appears is used.
  8447. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8448. {
  8449. static int err = 1;
  8450. static int packet_ver = -1;
  8451. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8452. unsigned short cmd;
  8453. if (get_previous)
  8454. {//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]
  8455. if( error )
  8456. *error = err;
  8457. return packet_ver;
  8458. }
  8459. //By default, start searching on the default one.
  8460. err = 1;
  8461. packet_ver = clif_config.packet_db_ver;
  8462. cmd = clif_parse_cmd(fd, NULL);
  8463. packet_len = RFIFOREST(fd);
  8464. #define SET_ERROR(n) \
  8465. if( err == 1 )\
  8466. err = n;\
  8467. //define SET_ERROR
  8468. // FIXME: If the packet is not received at once, this will FAIL.
  8469. // Figure out, when it happens, that only part of the packet is
  8470. // received, or fix the function to be able to deal with that
  8471. // case.
  8472. #define CHECK_PACKET_VER() \
  8473. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8474. ;/* not wanttoconnection or wrong length */\
  8475. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8476. { SET_ERROR(2); }/* invalid account_id */\
  8477. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8478. { SET_ERROR(3); }/* invalid char_id */\
  8479. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8480. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8481. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8482. { SET_ERROR(6); }/* invalid sex */\
  8483. else\
  8484. {\
  8485. err = 0;\
  8486. if( error )\
  8487. *error = 0;\
  8488. return packet_ver;\
  8489. }\
  8490. //define CHECK_PACKET_VER
  8491. CHECK_PACKET_VER();//Default packet version found.
  8492. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8493. CHECK_PACKET_VER();
  8494. }
  8495. if( error )
  8496. *error = err;
  8497. packet_ver = -1;
  8498. return -1;
  8499. #undef SET_ERROR
  8500. #undef CHECK_PACKET_VER
  8501. }
  8502. // ------------
  8503. // clif_parse_*
  8504. // ------------
  8505. // Parses incoming (player) connection
  8506. /// Request to connect to map-server.
  8507. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8508. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8509. /// There are various variants of this packet, some of them have padding between fields.
  8510. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8511. {
  8512. struct block_list* bl;
  8513. struct auth_node* node;
  8514. int cmd, account_id, char_id, login_id1, sex;
  8515. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8516. 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])
  8517. if (sd) {
  8518. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8519. return;
  8520. }
  8521. // Only valid packet version get here
  8522. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8523. cmd = RFIFOW(fd,0);
  8524. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8525. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8526. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8527. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8528. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8529. if( packet_ver < 5 || // reject really old client versions
  8530. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8531. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8532. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8533. {// packet version rejected
  8534. 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));
  8535. WFIFOHEAD(fd,packet_len(0x6a));
  8536. WFIFOW(fd,0) = 0x6a;
  8537. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8538. WFIFOSET(fd,packet_len(0x6a));
  8539. set_eof(fd);
  8540. return;
  8541. }
  8542. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8543. clif_authfail_fd(fd,1);// server closed
  8544. return;
  8545. }
  8546. //Check for double login.
  8547. bl = map_id2bl(account_id);
  8548. if(bl && bl->type != BL_PC) {
  8549. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8550. WFIFOHEAD(fd,packet_len(0x6a));
  8551. WFIFOW(fd,0) = 0x6a;
  8552. WFIFOB(fd,2) = 3; // Rejected by server
  8553. WFIFOSET(fd,packet_len(0x6a));
  8554. set_eof(fd);
  8555. return;
  8556. }
  8557. if (bl ||
  8558. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8559. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8560. {
  8561. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8562. return;
  8563. }
  8564. CREATE(sd, TBL_PC, 1);
  8565. sd->fd = fd;
  8566. sd->packet_ver = packet_ver;
  8567. #ifdef PACKET_OBFUSCATION
  8568. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8569. #endif
  8570. session[fd]->session_data = sd;
  8571. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8572. #if PACKETVER < 20070521
  8573. WFIFOHEAD(fd,4);
  8574. WFIFOL(fd,0) = sd->bl.id;
  8575. WFIFOSET(fd,4);
  8576. #else
  8577. WFIFOHEAD(fd,packet_len(0x283));
  8578. WFIFOW(fd,0) = 0x283;
  8579. WFIFOL(fd,2) = sd->bl.id;
  8580. WFIFOSET(fd,packet_len(0x283));
  8581. #endif
  8582. chrif_authreq(sd,false);
  8583. }
  8584. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8585. /// 007d
  8586. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8587. {
  8588. int i;
  8589. bool guild_notice = false;
  8590. if(sd->bl.prev != NULL)
  8591. return;
  8592. if (!sd->state.active) { //Character loading is not complete yet!
  8593. //Let pc_reg_received reinvoke this when ready.
  8594. sd->state.connect_new = 0;
  8595. return;
  8596. }
  8597. if (sd->state.rewarp) { //Rewarp player.
  8598. sd->state.rewarp = 0;
  8599. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8600. return;
  8601. }
  8602. sd->state.warping = 0;
  8603. // look
  8604. #if PACKETVER < 4
  8605. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8606. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8607. #else
  8608. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8609. #endif
  8610. if(sd->vd.cloth_color)
  8611. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8612. // item
  8613. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8614. pc_checkitem(sd);
  8615. // cart
  8616. if(pc_iscarton(sd)) {
  8617. clif_cartlist(sd);
  8618. clif_updatestatus(sd,SP_CARTINFO);
  8619. }
  8620. // weight
  8621. clif_updatestatus(sd,SP_WEIGHT);
  8622. clif_updatestatus(sd,SP_MAXWEIGHT);
  8623. // guild
  8624. // (needs to go before clif_spawn() to show guild emblems correctly)
  8625. if(sd->status.guild_id)
  8626. guild_send_memberinfoshort(sd,1);
  8627. if(battle_config.pc_invincible_time > 0) {
  8628. if(map_flag_gvg(sd->bl.m))
  8629. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8630. else
  8631. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8632. }
  8633. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8634. map_spawnmobs(sd->bl.m);
  8635. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8636. map[sd->bl.m].users_pvp++;
  8637. }
  8638. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8639. // reset the callshop flag if the player changes map
  8640. sd->state.callshop = 0;
  8641. if(map_addblock(&sd->bl))
  8642. return;
  8643. clif_spawn(&sd->bl);
  8644. // Party
  8645. // (needs to go after clif_spawn() to show hp bars correctly)
  8646. if(sd->status.party_id) {
  8647. party_send_movemap(sd);
  8648. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8649. }
  8650. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8651. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8652. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8653. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8654. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8655. sd->pvp_rank = 0;
  8656. sd->pvp_lastusers = 0;
  8657. sd->pvp_point = 5;
  8658. sd->pvp_won = 0;
  8659. sd->pvp_lost = 0;
  8660. }
  8661. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8662. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8663. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8664. if (map[sd->bl.m].flag.gvg_dungeon)
  8665. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8666. if( map_flag_gvg(sd->bl.m) )
  8667. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8668. // info about nearby objects
  8669. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8670. 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);
  8671. // pet
  8672. if( sd->pd ) {
  8673. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8674. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8675. pet_menu(sd, 3); //Option 3 is return to egg.
  8676. } else {
  8677. if(map_addblock(&sd->pd->bl))
  8678. return;
  8679. clif_spawn(&sd->pd->bl);
  8680. clif_send_petdata(sd,sd->pd,0,0);
  8681. clif_send_petstatus(sd);
  8682. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8683. }
  8684. }
  8685. //homunculus [blackhole89]
  8686. if( hom_is_active(sd->hd) ) {
  8687. if(map_addblock(&sd->hd->bl))
  8688. return;
  8689. clif_spawn(&sd->hd->bl);
  8690. clif_send_homdata(sd,SP_ACK,0);
  8691. clif_hominfo(sd,sd->hd,1);
  8692. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8693. clif_homskillinfoblock(sd);
  8694. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8695. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8696. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8697. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8698. }
  8699. if( sd->md ) {
  8700. if(map_addblock(&sd->md->bl))
  8701. return;
  8702. clif_spawn(&sd->md->bl);
  8703. clif_mercenary_info(sd);
  8704. clif_mercenary_skillblock(sd);
  8705. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8706. }
  8707. if( sd->ed ) {
  8708. if (map_addblock(&sd->ed->bl))
  8709. return;
  8710. clif_spawn(&sd->ed->bl);
  8711. clif_elemental_info(sd);
  8712. clif_elemental_updatestatus(sd,SP_HP);
  8713. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8714. clif_elemental_updatestatus(sd,SP_SP);
  8715. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8716. }
  8717. if(sd->state.connect_new) {
  8718. int lv;
  8719. guild_notice = true;
  8720. sd->state.connect_new = 0;
  8721. clif_skillinfoblock(sd);
  8722. clif_hotkeys_send(sd);
  8723. clif_updatestatus(sd,SP_BASEEXP);
  8724. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8725. clif_updatestatus(sd,SP_JOBEXP);
  8726. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8727. clif_updatestatus(sd,SP_SKILLPOINT);
  8728. clif_initialstatus(sd);
  8729. if (sd->sc.option&OPTION_FALCON)
  8730. clif_status_load(&sd->bl, SI_FALCON, 1);
  8731. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8732. clif_status_load(&sd->bl, SI_RIDING, 1);
  8733. else if (sd->sc.option&OPTION_WUGRIDER)
  8734. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8735. else if (sd->sc.data[SC_ALL_RIDING])
  8736. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8737. if(sd->status.manner < 0)
  8738. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8739. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8740. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8741. if(sd->bl.m == sd->feel_map[0].m
  8742. || sd->bl.m == sd->feel_map[1].m
  8743. || sd->bl.m == sd->feel_map[2].m)
  8744. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8745. }
  8746. if(sd->pd && sd->pd->pet.intimate > 900)
  8747. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8748. if(hom_is_active(sd->hd))
  8749. hom_init_timers(sd->hd);
  8750. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8751. sd->state.night = 1;
  8752. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8753. }
  8754. // Notify everyone that this char logged in [Skotlex].
  8755. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8756. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8757. //Login Event
  8758. npc_script_event(sd, NPCE_LOGIN);
  8759. }
  8760. } else {
  8761. //For some reason the client "loses" these on warp/map-change.
  8762. clif_updatestatus(sd,SP_STR);
  8763. clif_updatestatus(sd,SP_AGI);
  8764. clif_updatestatus(sd,SP_VIT);
  8765. clif_updatestatus(sd,SP_INT);
  8766. clif_updatestatus(sd,SP_DEX);
  8767. clif_updatestatus(sd,SP_LUK);
  8768. // abort currently running script
  8769. sd->state.using_fake_npc = 0;
  8770. sd->state.menu_or_input = 0;
  8771. sd->npc_menu = 0;
  8772. if(sd->npc_id)
  8773. npc_event_dequeue(sd);
  8774. }
  8775. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8776. #if PACKETVER >= 20070918
  8777. clif_partyinvitationstate(sd);
  8778. clif_equipcheckbox(sd);
  8779. #endif
  8780. #ifdef VIP_ENABLE
  8781. if (!sd->disableshowrate) {
  8782. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8783. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8784. }
  8785. #endif
  8786. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8787. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8788. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8789. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8790. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8791. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8792. { //Display night.
  8793. if( !sd->state.night )
  8794. {
  8795. sd->state.night = 1;
  8796. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8797. }
  8798. }
  8799. else if( sd->state.night )
  8800. { //Clear night display.
  8801. sd->state.night = 0;
  8802. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8803. }
  8804. if( map[sd->bl.m].flag.battleground )
  8805. {
  8806. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8807. if( map[sd->bl.m].flag.battleground == 2 )
  8808. clif_bg_updatescore_single(sd);
  8809. }
  8810. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8811. {
  8812. char output[128];
  8813. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8814. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8815. }
  8816. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8817. map[sd->bl.m].hpmeter_visible++;
  8818. sd->state.hpmeter_visible = 1;
  8819. }
  8820. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8821. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8822. sd->state.changemap = false;
  8823. // Instances do not need their own channels
  8824. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8825. channel_mjoin(sd); //join new map
  8826. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8827. clif_guild_notice(sd, sd->guild); // Displays at end
  8828. mail_clear(sd);
  8829. clif_maptypeproperty2(&sd->bl,SELF);
  8830. /* Guild Aura Init */
  8831. if( sd->state.gmaster_flag ) {
  8832. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8833. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8834. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8835. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8836. }
  8837. if( sd->state.vending ) { /* show we have a vending */
  8838. clif_openvending(sd,sd->bl.id,sd->vending);
  8839. clif_showvendingboard(&sd->bl,sd->message,0);
  8840. }
  8841. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8842. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8843. npc_script_event(sd, NPCE_LOADMAP);
  8844. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8845. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8846. if (sd->sc.opt2) //Client loses these on warp.
  8847. clif_changeoption(&sd->bl);
  8848. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8849. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8850. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8851. }
  8852. clif_weather_check(sd);
  8853. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8854. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8855. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8856. else
  8857. sd->areanpc_id = 0;
  8858. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8859. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8860. pc_setdead(sd);
  8861. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8862. if(pc_isdead(sd))
  8863. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8864. else {
  8865. skill_usave_trigger(sd);
  8866. if (battle_config.spawn_direction)
  8867. clif_changed_dir(&sd->bl, SELF);
  8868. }
  8869. // Trigger skill effects if you appear standing on them
  8870. if(!battle_config.pc_invincible_time)
  8871. skill_unit_move(&sd->bl,gettick(),1);
  8872. // NPC Quest / Event Icon Check [Kisuka]
  8873. #if PACKETVER >= 20090218
  8874. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8875. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8876. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8877. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8878. if( sd->class_ == qi->job )
  8879. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8880. } else {
  8881. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8882. }
  8883. }
  8884. }
  8885. #endif
  8886. }
  8887. /// Server's tick (ZC_NOTIFY_TIME).
  8888. /// 007f <time>.L
  8889. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8890. {
  8891. int fd = sd->fd;
  8892. WFIFOHEAD(fd,packet_len(0x7f));
  8893. WFIFOW(fd,0) = 0x7f;
  8894. WFIFOL(fd,2) = time;
  8895. WFIFOSET(fd,packet_len(0x7f));
  8896. }
  8897. /// Request for server's tick.
  8898. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8899. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8900. /// There are various variants of this packet, some of them have padding between fields.
  8901. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8902. {
  8903. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8904. clif_notify_time(sd, gettick());
  8905. }
  8906. /// Sends hotkey bar.
  8907. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8908. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8909. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8910. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8911. void clif_hotkeys_send(struct map_session_data *sd) {
  8912. #ifdef HOTKEY_SAVING
  8913. const int fd = sd->fd;
  8914. int i;
  8915. int offset = 2;
  8916. #if PACKETVER < 20090603
  8917. const int cmd = 0x2b9;
  8918. #elif PACKETVER < 20141022
  8919. const int cmd = 0x7d9;
  8920. #else
  8921. char Rotate = sd->status.hotkey_rowshift;
  8922. const int cmd = 0xa00;
  8923. offset = 3;
  8924. #endif
  8925. if (!fd) return;
  8926. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8927. WFIFOW(fd, 0) = cmd;
  8928. #if PACKETVER >= 20141022
  8929. WFIFOB(fd, 2) = Rotate;
  8930. #endif
  8931. for(i = 0; i < MAX_HOTKEYS; i++) {
  8932. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8933. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8934. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8935. }
  8936. WFIFOSET(fd, packet_len(cmd));
  8937. #endif
  8938. }
  8939. /// Request to update a position on the hotkey row bar
  8940. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  8941. int cmd = RFIFOW(fd, 0);
  8942. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8943. }
  8944. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8945. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8946. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8947. #ifdef HOTKEY_SAVING
  8948. unsigned short idx;
  8949. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8950. idx = RFIFOW(fd, info->pos[0]);
  8951. if (idx >= MAX_HOTKEYS) return;
  8952. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8953. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8954. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8955. #endif
  8956. }
  8957. /// Displays cast-like progress bar (ZC_PROGRESS).
  8958. /// 02f0 <color>.L <time>.L
  8959. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8960. {
  8961. int fd = sd->fd;
  8962. WFIFOHEAD(fd,packet_len(0x2f0));
  8963. WFIFOW(fd,0) = 0x2f0;
  8964. WFIFOL(fd,2) = color;
  8965. WFIFOL(fd,6) = second;
  8966. WFIFOSET(fd,packet_len(0x2f0));
  8967. }
  8968. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8969. /// 02f2
  8970. void clif_progressbar_abort(struct map_session_data * sd)
  8971. {
  8972. int fd = sd->fd;
  8973. WFIFOHEAD(fd,packet_len(0x2f2));
  8974. WFIFOW(fd,0) = 0x2f2;
  8975. WFIFOSET(fd,packet_len(0x2f2));
  8976. }
  8977. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8978. /// 02f1
  8979. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8980. {
  8981. int npc_id = sd->progressbar.npc_id;
  8982. if( gettick() < sd->progressbar.timeout && sd->st )
  8983. sd->st->state = END;
  8984. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8985. npc_scriptcont(sd, npc_id, false);
  8986. }
  8987. /// Request to walk to a certain position on the current map.
  8988. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8989. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8990. /// There are various variants of this packet, some of them have padding between fields.
  8991. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8992. {
  8993. short x, y;
  8994. if (pc_isdead(sd)) {
  8995. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8996. return;
  8997. }
  8998. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8999. ; //You CAN walk on this OPT1 value.
  9000. else if( sd->progressbar.npc_id )
  9001. clif_progressbar_abort(sd);
  9002. else if (pc_cant_act(sd))
  9003. return;
  9004. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9005. return;
  9006. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9007. //A move command one cell west is only valid if the target cell is free
  9008. if(battle_config.official_cell_stack_limit > 0
  9009. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9010. return;
  9011. // Cloaking wall check is actually updated when you click to process next movement
  9012. // not when you move each cell. This is official behaviour.
  9013. if (sd->sc.data[SC_CLOAKING])
  9014. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9015. pc_delinvincibletimer(sd);
  9016. //Set last idle time... [Skotlex]
  9017. if (battle_config.idletime_option&IDLE_WALK)
  9018. sd->idletime = last_tick;
  9019. unit_walktoxy(&sd->bl, x, y, 4);
  9020. }
  9021. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9022. /// 018b <result>.W
  9023. /// result:
  9024. /// 0 = disconnect (quit)
  9025. /// 1 = cannot disconnect (wait 10 seconds)
  9026. /// ? = ignored
  9027. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9028. {
  9029. int fd = sd->fd;
  9030. WFIFOHEAD(fd,packet_len(0x18b));
  9031. WFIFOW(fd,0) = 0x18b;
  9032. WFIFOW(fd,2) = result;
  9033. WFIFOSET(fd,packet_len(0x18b));
  9034. }
  9035. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9036. /// 018a <type>.W
  9037. /// type:
  9038. /// 0 = quit
  9039. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9040. {
  9041. /* Rovert's prevent logout option fixed [Valaris] */
  9042. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9043. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9044. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9045. {
  9046. set_eof(fd);
  9047. pc_damage_log_clear(sd,0);
  9048. clif_disconnect_ack(sd, 0);
  9049. } else {
  9050. clif_disconnect_ack(sd, 1);
  9051. }
  9052. }
  9053. /// Requesting unit's name.
  9054. /// 0094 <id>.L (CZ_REQNAME)
  9055. /// 0368 <id>.L (CZ_REQNAME2)
  9056. /// There are various variants of this packet, some of them have padding between fields.
  9057. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9058. {
  9059. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9060. struct block_list* bl;
  9061. //struct status_change *sc;
  9062. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9063. id = sd->bl.id;
  9064. bl = map_id2bl(id);
  9065. if( bl == NULL )
  9066. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9067. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9068. return; // Block namerequests past view range
  9069. // 'see people in GM hide' cheat detection
  9070. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9071. sc = status_get_sc(bl);
  9072. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9073. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9074. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9075. ) {
  9076. char gm_msg[256];
  9077. 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);
  9078. ShowWarning(gm_msg);
  9079. // information is sent to all online GMs
  9080. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9081. return;
  9082. }
  9083. */
  9084. clif_charnameack(fd, bl);
  9085. }
  9086. /// Validates and processes global messages
  9087. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9088. /// There are various variants of this packet.
  9089. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9090. {
  9091. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9092. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  9093. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  9094. char *name, *message, *fakename = NULL;
  9095. int namelen, messagelen;
  9096. bool is_fake;
  9097. // validate packet and retrieve name and message
  9098. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9099. return;
  9100. if( is_atcommand(fd, sd, message, 1) )
  9101. return;
  9102. if (sd->sc.cant.chat)
  9103. return; //no "chatting" while muted.
  9104. if( battle_config.min_chat_delay ) { //[Skotlex]
  9105. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9106. return;
  9107. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9108. }
  9109. if (battle_config.idletime_option&IDLE_CHAT)
  9110. sd->idletime = last_tick;
  9111. if( sd->gcbind ) {
  9112. channel_send(sd->gcbind,sd,message);
  9113. return;
  9114. }
  9115. /**
  9116. * Fake Name Design by FatalEror (bug report #9)
  9117. **/
  9118. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  9119. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  9120. strcpy(fakename, sd->fakename);
  9121. strcat(fakename, " : ");
  9122. strcat(fakename, message);
  9123. textlen = strlen(fakename) + 1;
  9124. }
  9125. // send message to others (using the send buffer for temp. storage)
  9126. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9127. // send back message to the speaker
  9128. if( is_fake ) {
  9129. WFIFOW(fd,0) = 0x8e;
  9130. WFIFOW(fd,2) = textlen + 4;
  9131. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  9132. aFree(fakename);
  9133. } else {
  9134. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  9135. WFIFOW(fd,0) = 0x8e;
  9136. }
  9137. WFIFOSET(fd, WFIFOW(fd,2));
  9138. #ifdef PCRE_SUPPORT
  9139. // trigger listening npcs
  9140. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  9141. #endif
  9142. // Chat logging type 'O' / Global Chat
  9143. 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);
  9144. }
  9145. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9146. /// Request to warp to a map on given coordinates.
  9147. /// 0140 <map name>.16B <x>.W <y>.W
  9148. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9149. {
  9150. char command[MAP_NAME_LENGTH_EXT+25];
  9151. char* map_name;
  9152. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9153. map_name = (char*)RFIFOP(fd,info->pos[0]);
  9154. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9155. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9156. RFIFOW(fd,info->pos[1]), //x
  9157. RFIFOW(fd,info->pos[2])); //y
  9158. is_atcommand(fd, sd, command, 1);
  9159. }
  9160. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9161. /// 009c <id>.L <head dir>.W <dir>.B
  9162. /// head dir:
  9163. /// 0 = straight
  9164. /// 1 = turned CW
  9165. /// 2 = turned CCW
  9166. /// dir:
  9167. /// 0 = north
  9168. /// 1 = northwest
  9169. /// 2 = west
  9170. /// 3 = southwest
  9171. /// 4 = south
  9172. /// 5 = southeast
  9173. /// 6 = east
  9174. /// 7 = northeast
  9175. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9176. {
  9177. unsigned char buf[64];
  9178. WBUFW(buf,0) = 0x9c;
  9179. WBUFL(buf,2) = bl->id;
  9180. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9181. WBUFB(buf,8) = unit_getdir(bl);
  9182. clif_send(buf, packet_len(0x9c), bl, target);
  9183. if (disguised(bl)) {
  9184. WBUFL(buf,2) = -bl->id;
  9185. WBUFW(buf,6) = 0;
  9186. clif_send(buf, packet_len(0x9c), bl, SELF);
  9187. }
  9188. }
  9189. /// Request to change own body and head direction.
  9190. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9191. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9192. /// There are various variants of this packet, some of them have padding between fields.
  9193. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9194. {
  9195. unsigned char headdir, dir;
  9196. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9197. headdir = RFIFOB(fd,info->pos[0]);
  9198. dir = RFIFOB(fd,info->pos[1]);
  9199. pc_setdir(sd, dir, headdir);
  9200. clif_changed_dir(&sd->bl, AREA_WOS);
  9201. }
  9202. /// Request to show an emotion (CZ_REQ_EMOTION).
  9203. /// 00bf <type>.B
  9204. /// type:
  9205. /// @see enum emotion_type
  9206. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9207. {
  9208. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9209. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  9210. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9211. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9212. return;
  9213. }
  9214. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9215. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9216. sd->emotionlasttime = time(NULL);
  9217. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9218. return;
  9219. }
  9220. sd->emotionlasttime = time(NULL);
  9221. if (battle_config.idletime_option&IDLE_EMOTION)
  9222. sd->idletime = last_tick;
  9223. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9224. emoticon = rnd()%6+E_DICE1;
  9225. }
  9226. clif_emotion(&sd->bl, emoticon);
  9227. } else
  9228. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9229. }
  9230. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9231. /// 00c2 <count>.L
  9232. void clif_user_count(struct map_session_data* sd, int count)
  9233. {
  9234. int fd = sd->fd;
  9235. WFIFOHEAD(fd,packet_len(0xc2));
  9236. WFIFOW(fd,0) = 0xc2;
  9237. WFIFOL(fd,2) = count;
  9238. WFIFOSET(fd,packet_len(0xc2));
  9239. }
  9240. /// /w /who (CZ_REQ_USER_COUNT).
  9241. /// Request to display amount of currently connected players.
  9242. /// 00c1
  9243. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9244. {
  9245. clif_user_count(sd, map_getusers());
  9246. }
  9247. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9248. {
  9249. if (pc_isdead(sd)) {
  9250. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9251. return;
  9252. }
  9253. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9254. // (not all are included in pc_can_attack)
  9255. if (sd->sc.count &&
  9256. (sd->sc.data[SC_TRICKDEAD] ||
  9257. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9258. sd->sc.data[SC_BLADESTOP] ||
  9259. sd->sc.data[SC__MANHOLE] ))
  9260. return;
  9261. if(action_type != 0x00 && action_type != 0x07)
  9262. pc_stop_walking(sd, 1);
  9263. pc_stop_attack(sd);
  9264. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9265. target_id = sd->bl.id;
  9266. switch(action_type)
  9267. {
  9268. case 0x00: // once attack
  9269. case 0x07: // continuous attack
  9270. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9271. return;
  9272. if( sd->sc.option&OPTION_COSTUME )
  9273. return;
  9274. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9275. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9276. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9277. return;
  9278. }
  9279. }
  9280. pc_delinvincibletimer(sd);
  9281. if (battle_config.idletime_option&IDLE_ATTACK)
  9282. sd->idletime = last_tick;
  9283. unit_attack(&sd->bl, target_id, action_type != 0);
  9284. break;
  9285. case 0x02: // sitdown
  9286. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  9287. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9288. break;
  9289. }
  9290. if(pc_issit(sd)) {
  9291. //Bugged client? Just refresh them.
  9292. clif_sitting(&sd->bl);
  9293. return;
  9294. }
  9295. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  9296. break;
  9297. if (sd->sc.count && (
  9298. sd->sc.data[SC_DANCING] ||
  9299. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9300. )) //No sitting during these states either.
  9301. break;
  9302. if (battle_config.idletime_option&IDLE_SIT)
  9303. sd->idletime = last_tick;
  9304. pc_setsit(sd);
  9305. skill_sit(sd, 1);
  9306. clif_sitting(&sd->bl);
  9307. break;
  9308. case 0x03: // standup
  9309. if (!pc_issit(sd)) {
  9310. //Bugged client? Just refresh them.
  9311. clif_standing(&sd->bl);
  9312. return;
  9313. }
  9314. if (pc_setstand(sd, false)) {
  9315. if (battle_config.idletime_option&IDLE_SIT)
  9316. sd->idletime = last_tick;
  9317. skill_sit(sd, 0);
  9318. clif_standing(&sd->bl);
  9319. }
  9320. break;
  9321. }
  9322. }
  9323. /// Request for an action.
  9324. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9325. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9326. /// action:
  9327. /// 0 = attack
  9328. /// 1 = pick up item
  9329. /// 2 = sit down
  9330. /// 3 = stand up
  9331. /// 7 = continous attack
  9332. /// 12 = (touch skill?)
  9333. /// There are various variants of this packet, some of them have padding between fields.
  9334. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9335. {
  9336. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9337. clif_parse_ActionRequest_sub(sd,
  9338. RFIFOB(fd,info->pos[1]),
  9339. RFIFOL(fd,info->pos[0]),
  9340. gettick()
  9341. );
  9342. }
  9343. /// Response to the death/system menu (CZ_RESTART).
  9344. /// 00b2 <type>.B
  9345. /// type:
  9346. /// 0 = restart (respawn)
  9347. /// 1 = char-select (disconnect)
  9348. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9349. {
  9350. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9351. case 0x00:
  9352. pc_respawn(sd,CLR_OUTSIGHT);
  9353. break;
  9354. case 0x01:
  9355. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9356. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  9357. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9358. { //Send to char-server for character selection.
  9359. pc_damage_log_clear(sd,0);
  9360. chrif_charselectreq(sd, session[fd]->client_addr);
  9361. } else {
  9362. clif_disconnect_ack(sd, 1);
  9363. }
  9364. break;
  9365. }
  9366. }
  9367. /// Validates and processes whispered messages (CZ_WHISPER).
  9368. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9369. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9370. {
  9371. struct map_session_data* dstsd;
  9372. int i;
  9373. char *target, *message;
  9374. int namelen, messagelen;
  9375. // validate packet and retrieve name and message
  9376. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  9377. return;
  9378. if ( is_atcommand(fd, sd, message, 1) )
  9379. return;
  9380. if (sd->sc.cant.chat)
  9381. return; //no "chatting" while muted.
  9382. if (battle_config.min_chat_delay) { //[Skotlex]
  9383. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  9384. return;
  9385. }
  9386. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9387. }
  9388. if (battle_config.idletime_option&IDLE_CHAT)
  9389. sd->idletime = last_tick;
  9390. // Chat logging type 'W' / Whisper
  9391. 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);
  9392. //-------------------------------------------------------//
  9393. // Lordalfa - Paperboy - To whisper NPC commands //
  9394. //-------------------------------------------------------//
  9395. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9396. {
  9397. char* str = target+4; //Skip the NPC: string part.
  9398. struct npc_data* npc;
  9399. if ((npc = npc_name2id(str))) {
  9400. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9401. char *split;
  9402. char output[256];
  9403. str = message;
  9404. // skip codepage indicator, if detected
  9405. if( str[0] == '|' && strlen(str) >= 4 )
  9406. str += 3;
  9407. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9408. split = strchr(str,'#');
  9409. if( split == NULL ) { // use the remaining string
  9410. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9411. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9412. split_data[i][0] = '\0';
  9413. break;
  9414. }
  9415. *split = '\0';
  9416. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9417. str = split+1;
  9418. }
  9419. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9420. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9421. set_var(sd,output,(char *) split_data[i]);
  9422. }
  9423. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9424. npc_event(sd,output,0); // Calls the NPC label
  9425. return;
  9426. }
  9427. } else if( target[0] == '#' ) {
  9428. struct Channel *channel = NULL;
  9429. char* chname = target;
  9430. channel = channel_name2channel(chname,sd,3);
  9431. if(channel){
  9432. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9433. channel_send(channel,sd,message);
  9434. }
  9435. else if( channel->pass[0] == '\0') { //no pass needed
  9436. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9437. }
  9438. else {
  9439. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9440. }
  9441. return;
  9442. }
  9443. }
  9444. // searching destination character
  9445. dstsd = map_nick2sd(target);
  9446. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9447. // player is not on this map-server
  9448. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9449. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9450. // and if we ask for 'Test', we must not contact 'test' player
  9451. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9452. intif_wis_message(sd, target, message, messagelen);
  9453. return;
  9454. }
  9455. // if player ignores everyone
  9456. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9457. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9458. clif_wis_end(fd, 1); // 1: target character is not logged in
  9459. else
  9460. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9461. return;
  9462. }
  9463. // if player is autotrading
  9464. if (dstsd->state.autotrade == 1) {
  9465. char output[256];
  9466. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9467. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9468. return;
  9469. }
  9470. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9471. // if player ignores the source character
  9472. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9473. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9474. clif_wis_end(fd, 2); // 2: ignored by target
  9475. return;
  9476. }
  9477. }
  9478. // notify sender of success
  9479. clif_wis_end(fd, 0); // 0: success to send wisper
  9480. // Normal message
  9481. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9482. }
  9483. /// /b /nb (CZ_BROADCAST).
  9484. /// Request to broadcast a message on whole server.
  9485. /// 0099 <packet len>.W <text>.?B 00
  9486. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9487. char command[CHAT_SIZE_MAX+11];
  9488. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9489. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9490. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9491. // as the length varies depending on the command used, just block unreasonably long strings
  9492. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9493. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9494. is_atcommand(fd, sd, command, 1);
  9495. }
  9496. /// Request to pick up an item.
  9497. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9498. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9499. /// There are various variants of this packet, some of them have padding between fields.
  9500. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9501. {
  9502. struct flooritem_data *fitem;
  9503. int map_object_id;
  9504. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9505. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9506. do {
  9507. if (pc_isdead(sd)) {
  9508. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9509. break;
  9510. }
  9511. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9512. break;
  9513. if (pc_cant_act(sd))
  9514. break;
  9515. if (!pc_takeitem(sd, fitem))
  9516. break;
  9517. return;
  9518. } while (0);
  9519. // Client REQUIRES a fail packet or you can no longer pick items.
  9520. clif_additem(sd,0,0,6);
  9521. }
  9522. /// Request to drop an item.
  9523. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9524. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9525. /// There are various variants of this packet, some of them have padding between fields.
  9526. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9527. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9528. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9529. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9530. for(;;) {
  9531. if (pc_isdead(sd))
  9532. break;
  9533. if (pc_cant_act2(sd) || sd->npc_id)
  9534. break;
  9535. if (sd->sc.count && (
  9536. sd->sc.data[SC_AUTOCOUNTER] ||
  9537. sd->sc.data[SC_BLADESTOP] ||
  9538. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9539. ))
  9540. break;
  9541. if (!pc_dropitem(sd, item_index, item_amount))
  9542. break;
  9543. if (battle_config.idletime_option&IDLE_DROPITEM)
  9544. sd->idletime = last_tick;
  9545. return;
  9546. }
  9547. //Because the client does not like being ignored.
  9548. clif_dropitem(sd, item_index,0);
  9549. }
  9550. /// Request to use an item.
  9551. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9552. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9553. /// There are various variants of this packet, some of them have padding between fields.
  9554. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9555. {
  9556. int n;
  9557. if (pc_isdead(sd)) {
  9558. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9559. return;
  9560. }
  9561. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9562. return;
  9563. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9564. if (battle_config.idletime_option&IDLE_USEITEM)
  9565. sd->idletime = last_tick;
  9566. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9567. if(n <0 || n >= MAX_INVENTORY)
  9568. return;
  9569. if (!pc_useitem(sd,n))
  9570. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9571. }
  9572. /// Request to equip an item
  9573. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9574. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9575. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9576. {
  9577. int index;
  9578. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9579. if(pc_isdead(sd)) {
  9580. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9581. return;
  9582. }
  9583. index = RFIFOW(fd,info->pos[0])-2;
  9584. if (index < 0 || index >= MAX_INVENTORY)
  9585. return; //Out of bounds check.
  9586. if(sd->npc_id && !sd->npc_item_flag) {
  9587. return;
  9588. } else if (sd->state.storage_flag || sd->sc.opt1)
  9589. ; //You can equip/unequip stuff while storage is open/under status changes
  9590. else if (pc_cant_act2(sd))
  9591. return;
  9592. if(!sd->status.inventory[index].identify) {
  9593. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9594. return;
  9595. }
  9596. if(!sd->inventory_data[index])
  9597. return;
  9598. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9599. pet_equipitem(sd,index);
  9600. return;
  9601. }
  9602. if (battle_config.idletime_option&IDLE_USEITEM)
  9603. sd->idletime = last_tick;
  9604. //Client doesn't send the position for ammo.
  9605. if(sd->inventory_data[index]->type == IT_AMMO)
  9606. pc_equipitem(sd,index,EQP_AMMO);
  9607. else {
  9608. int req_pos;
  9609. #if PACKETVER >= 20120925
  9610. req_pos = RFIFOL(fd,info->pos[1]);
  9611. #else
  9612. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9613. #endif
  9614. pc_equipitem(sd,index,req_pos);
  9615. }
  9616. }
  9617. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9618. /// 00ab <index>.W
  9619. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9620. {
  9621. int index;
  9622. if(pc_isdead(sd)) {
  9623. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9624. return;
  9625. }
  9626. if (sd->npc_id && !sd->npc_item_flag) {
  9627. return;
  9628. } else if (sd->state.storage_flag || sd->sc.opt1)
  9629. ; //You can equip/unequip stuff while storage is open/under status changes
  9630. else if (pc_cant_act2(sd))
  9631. return;
  9632. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9633. if (battle_config.idletime_option&IDLE_USEITEM)
  9634. sd->idletime = last_tick;
  9635. pc_unequipitem(sd,index,1);
  9636. }
  9637. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9638. /// 0090 <id>.L <type>.B
  9639. /// type:
  9640. /// 1 = click
  9641. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9642. {
  9643. struct block_list *bl;
  9644. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9645. if(pc_isdead(sd)) {
  9646. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9647. return;
  9648. }
  9649. if (pc_cant_act2(sd) || sd->npc_id)
  9650. return;
  9651. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9652. //type = RFIFOB(fd,info->pos[1]);
  9653. if (!bl) return;
  9654. switch (bl->type) {
  9655. case BL_MOB:
  9656. case BL_PC:
  9657. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9658. break;
  9659. case BL_NPC:
  9660. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9661. npc_click(sd,(TBL_NPC*)bl);
  9662. break;
  9663. }
  9664. }
  9665. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9666. /// 00c5 <id>.L <type>.B
  9667. /// type:
  9668. /// 0 = buy
  9669. /// 1 = sell
  9670. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9671. {
  9672. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9673. if (sd->state.trading)
  9674. return;
  9675. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9676. }
  9677. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9678. /// 00ca <result>.B
  9679. /// result:
  9680. /// 0 = "The deal has successfully completed."
  9681. /// 1 = "You do not have enough zeny."
  9682. /// 2 = "You are over your Weight Limit."
  9683. /// 3 = "Out of the maximum capacity, you have too many items."
  9684. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9685. {
  9686. int fd = sd->fd;
  9687. WFIFOHEAD(fd,packet_len(0xca));
  9688. WFIFOW(fd,0) = 0xca;
  9689. WFIFOB(fd,2) = result;
  9690. WFIFOSET(fd,packet_len(0xca));
  9691. }
  9692. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9693. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9694. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9695. {
  9696. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9697. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9698. int result;
  9699. if( sd->state.trading || !sd->npc_shopid )
  9700. result = 1;
  9701. else
  9702. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9703. sd->npc_shopid = 0; //Clear shop data.
  9704. clif_npc_buy_result(sd, result);
  9705. }
  9706. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9707. /// 00cb <result>.B
  9708. /// result:
  9709. /// 0 = "The deal has successfully completed."
  9710. /// 1 = "The deal has failed."
  9711. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9712. {
  9713. int fd = sd->fd;
  9714. WFIFOHEAD(fd,packet_len(0xcb));
  9715. WFIFOW(fd,0) = 0xcb;
  9716. WFIFOB(fd,2) = result;
  9717. WFIFOSET(fd,packet_len(0xcb));
  9718. }
  9719. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9720. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9721. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9722. {
  9723. int fail=0,n;
  9724. unsigned short *item_list;
  9725. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9726. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9727. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9728. if (sd->state.trading || !sd->npc_shopid)
  9729. fail = 1;
  9730. else
  9731. fail = npc_selllist(sd,n,item_list);
  9732. sd->npc_shopid = 0; //Clear shop data.
  9733. clif_npc_sell_result(sd, fail);
  9734. }
  9735. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9736. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9737. /// type:
  9738. /// 0 = private
  9739. /// 1 = public
  9740. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9741. {
  9742. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9743. int len = RFIFOW(fd,info->pos[0])-15;
  9744. int limit = RFIFOW(fd,info->pos[1]);
  9745. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9746. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9747. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9748. char s_password[CHATROOM_PASS_SIZE];
  9749. char s_title[CHATROOM_TITLE_SIZE];
  9750. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9751. return;
  9752. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9753. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9754. return;
  9755. }
  9756. if( npc_isnear(&sd->bl) ) {
  9757. // uncomment to send msg_txt.
  9758. //char output[150];
  9759. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9760. //clif_displaymessage(sd->fd, output);
  9761. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9762. return;
  9763. }
  9764. if( len <= 0 )
  9765. return; // invalid input
  9766. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9767. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9768. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9769. }
  9770. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9771. /// 00d9 <chat ID>.L <passwd>.8B
  9772. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9773. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9774. int chatid = RFIFOL(fd,info->pos[0]);
  9775. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9776. chat_joinchat(sd,chatid,password);
  9777. }
  9778. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9779. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9780. /// type:
  9781. /// 0 = private
  9782. /// 1 = public
  9783. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9784. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9785. int len = RFIFOW(fd,info->pos[0])-15;
  9786. int limit = RFIFOW(fd,info->pos[1]);
  9787. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9788. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9789. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9790. char s_password[CHATROOM_PASS_SIZE];
  9791. char s_title[CHATROOM_TITLE_SIZE];
  9792. if( len <= 0 )
  9793. return; // invalid input
  9794. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9795. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9796. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9797. }
  9798. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9799. /// 00e0 <role>.L <nick>.24B
  9800. /// role:
  9801. /// 0 = owner
  9802. /// 1 = normal
  9803. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9804. {
  9805. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9806. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9807. }
  9808. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9809. /// 00e2 <name>.24B
  9810. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9811. {
  9812. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9813. }
  9814. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9815. /// 00e3
  9816. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9817. {
  9818. chat_leavechat(sd,0);
  9819. }
  9820. //Handles notifying asker and rejecter of what has just ocurred.
  9821. //Type is used to determine the correct msg_txt to use:
  9822. //0:
  9823. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9824. {
  9825. const char* msg;
  9826. char output[256];
  9827. // Your request has been rejected by autoreject option.
  9828. msg = msg_txt(sd,392);
  9829. clif_disp_onlyself(sd, msg, strlen(msg));
  9830. //Notice that a request was rejected.
  9831. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9832. clif_disp_onlyself(tsd, output, strlen(output));
  9833. }
  9834. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9835. /// 00e4 <account id>.L
  9836. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9837. {
  9838. struct map_session_data *t_sd;
  9839. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9840. if(!sd->chatID && pc_cant_act(sd))
  9841. return; //You can trade while in a chatroom.
  9842. // @noask [LuzZza]
  9843. if(t_sd && t_sd->state.noask) {
  9844. clif_noask_sub(sd, t_sd, 0);
  9845. return;
  9846. }
  9847. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9848. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9849. return;
  9850. }
  9851. trade_traderequest(sd,t_sd);
  9852. }
  9853. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9854. /// 00e6 <result>.B
  9855. /// result:
  9856. /// 3 = accepted
  9857. /// 4 = rejected
  9858. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9859. {
  9860. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9861. }
  9862. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9863. /// 00e8 <index>.W <amount>.L
  9864. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9865. {
  9866. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9867. short index = RFIFOW(fd,info->pos[0]);
  9868. int amount = RFIFOL(fd,info->pos[1]);
  9869. if( index == 0 )
  9870. trade_tradeaddzeny(sd, amount);
  9871. else
  9872. trade_tradeadditem(sd, index, (short)amount);
  9873. }
  9874. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9875. /// 00eb
  9876. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9877. {
  9878. trade_tradeok(sd);
  9879. }
  9880. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9881. /// 00ed
  9882. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9883. {
  9884. trade_tradecancel(sd);
  9885. }
  9886. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9887. /// 00ef
  9888. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9889. {
  9890. trade_tradecommit(sd);
  9891. }
  9892. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9893. /// 0118
  9894. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9895. {
  9896. pc_stop_attack(sd);
  9897. }
  9898. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9899. /// 0126 <index>.W <amount>.L
  9900. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9901. {
  9902. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9903. if (pc_istrading(sd))
  9904. return;
  9905. if (!pc_iscarton(sd))
  9906. return;
  9907. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9908. }
  9909. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9910. /// 0127 <index>.W <amount>.L
  9911. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9912. {
  9913. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9914. if (!pc_iscarton(sd))
  9915. return;
  9916. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9917. }
  9918. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9919. /// 012a
  9920. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9921. {
  9922. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9923. #ifdef NEW_CARTS
  9924. && sd->sc.data[SC_PUSH_CART] )
  9925. pc_setcart(sd,0);
  9926. #else
  9927. )
  9928. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9929. #endif
  9930. else // priority to remove this option before we can clear cart
  9931. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9932. }
  9933. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9934. /// 01af <num>.W
  9935. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9936. {// TODO: State tracking?
  9937. int type;
  9938. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9939. return;
  9940. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9941. #ifdef NEW_CARTS
  9942. if( (type == 9 && sd->status.base_level > 131) ||
  9943. (type == 8 && sd->status.base_level > 121) ||
  9944. (type == 7 && sd->status.base_level > 111) ||
  9945. (type == 6 && sd->status.base_level > 101) ||
  9946. (type == 5 && sd->status.base_level > 90) ||
  9947. (type == 4 && sd->status.base_level > 80) ||
  9948. (type == 3 && sd->status.base_level > 65) ||
  9949. (type == 2 && sd->status.base_level > 40) ||
  9950. (type == 1))
  9951. #else
  9952. if( (type == 5 && sd->status.base_level > 90) ||
  9953. (type == 4 && sd->status.base_level > 80) ||
  9954. (type == 3 && sd->status.base_level > 65) ||
  9955. (type == 2 && sd->status.base_level > 40) ||
  9956. (type == 1))
  9957. #endif
  9958. pc_setcart(sd,type);
  9959. }
  9960. /// Request to increase status (CZ_STATUS_CHANGE).
  9961. /// 00bb <status id>.W <amount>.B
  9962. /// status id:
  9963. /// SP_STR ~ SP_LUK
  9964. /// amount:
  9965. /// Old clients always send 1 for this, even when using /str+ and the like.
  9966. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9967. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9968. {
  9969. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9970. if( increase_amount < 0 ) {
  9971. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9972. fd, increase_amount);
  9973. }
  9974. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9975. }
  9976. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9977. /// 0112 <skill id>.W
  9978. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9979. {
  9980. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9981. }
  9982. 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)
  9983. {
  9984. int lv;
  9985. if( !hd )
  9986. return;
  9987. if( skill_isNotOk_hom(skill_id, hd) ) {
  9988. clif_emotion(&hd->bl, E_DOTS);
  9989. return;
  9990. }
  9991. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9992. target_id = hd->bl.id;
  9993. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9994. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9995. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9996. clif_emotion(&hd->bl, E_DOTS);
  9997. if (hd->master)
  9998. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9999. return;
  10000. }
  10001. lv = hom_checkskill(hd, skill_id);
  10002. if( skill_lv > lv )
  10003. skill_lv = lv;
  10004. if( skill_lv )
  10005. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10006. }
  10007. 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)
  10008. {
  10009. int lv;
  10010. if( !hd )
  10011. return;
  10012. if( skill_isNotOk_hom(skill_id, hd) ) {
  10013. clif_emotion(&hd->bl, E_DOTS);
  10014. return;
  10015. }
  10016. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10017. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10018. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10019. clif_emotion(&hd->bl, E_DOTS);
  10020. if (hd->master)
  10021. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10022. return;
  10023. }
  10024. if( hd->sc.data[SC_BASILICA] )
  10025. return;
  10026. lv = hom_checkskill(hd, skill_id);
  10027. if( skill_lv > lv )
  10028. skill_lv = lv;
  10029. if( skill_lv )
  10030. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10031. }
  10032. 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)
  10033. {
  10034. int lv;
  10035. if( !md )
  10036. return;
  10037. if( skill_isNotOk_mercenary(skill_id, md) )
  10038. return;
  10039. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10040. target_id = md->bl.id;
  10041. if( md->ud.skilltimer != INVALID_TIMER )
  10042. {
  10043. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10044. }
  10045. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10046. return;
  10047. lv = mercenary_checkskill(md, skill_id);
  10048. if( skill_lv > lv )
  10049. skill_lv = lv;
  10050. if( skill_lv )
  10051. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10052. }
  10053. 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)
  10054. {
  10055. int lv;
  10056. if( !md )
  10057. return;
  10058. if( skill_isNotOk_mercenary(skill_id, md) )
  10059. return;
  10060. if( md->ud.skilltimer != INVALID_TIMER )
  10061. return;
  10062. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10063. {
  10064. if (md->master)
  10065. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10066. return;
  10067. }
  10068. if( md->sc.data[SC_BASILICA] )
  10069. return;
  10070. lv = mercenary_checkskill(md, skill_id);
  10071. if( skill_lv > lv )
  10072. skill_lv = lv;
  10073. if( skill_lv )
  10074. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10075. }
  10076. /// Request to use a targeted skill.
  10077. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10078. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10079. /// There are various variants of this packet, some of them have padding between fields.
  10080. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10081. {
  10082. uint16 skill_id, skill_lv;
  10083. int inf,target_id;
  10084. unsigned int tick = gettick();
  10085. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10086. skill_lv = RFIFOW(fd,info->pos[0]);
  10087. skill_id = RFIFOW(fd,info->pos[1]);
  10088. target_id = RFIFOL(fd,info->pos[2]);
  10089. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10090. inf = skill_get_inf(skill_id);
  10091. if (inf&INF_GROUND_SKILL || !inf)
  10092. return; //Using a ground/passive skill on a target? WRONG.
  10093. if( SKILL_CHK_HOMUN(skill_id) ) {
  10094. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10095. return;
  10096. }
  10097. if( SKILL_CHK_MERC(skill_id) ) {
  10098. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10099. return;
  10100. }
  10101. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10102. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10103. sd->idletime = last_tick;
  10104. if( sd->npc_id ){
  10105. #ifdef RENEWAL
  10106. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  10107. return;
  10108. #else
  10109. if( !sd->npc_item_flag || !(inf&INF_SELF_SKILL) )
  10110. return;
  10111. #endif
  10112. }
  10113. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10114. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10115. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10116. return;
  10117. if( pc_issit(sd) )
  10118. return;
  10119. if( skill_isNotOk(skill_id, sd) )
  10120. return;
  10121. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10122. target_id = sd->bl.id; // never trust the client
  10123. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10124. target_id = sd->bl.id;
  10125. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10126. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10127. return;
  10128. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10129. if( sd->skillitem != skill_id ) {
  10130. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10131. return;
  10132. }
  10133. }
  10134. if( sd->sc.option&OPTION_COSTUME )
  10135. return;
  10136. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10137. return; // On basilica only caster can use Basilica again to stop it.
  10138. if( sd->menuskill_id ) {
  10139. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10140. clif_menuskill_clear(sd); //Cancel pet capture.
  10141. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10142. return; //Can't use skills while a menu is open.
  10143. }
  10144. if( sd->skillitem == skill_id ) {
  10145. if( skill_lv != sd->skillitemlv )
  10146. skill_lv = sd->skillitemlv;
  10147. if( !(inf&INF_SELF_SKILL) )
  10148. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10149. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10150. return;
  10151. }
  10152. sd->skillitem = sd->skillitemlv = 0;
  10153. if( SKILL_CHK_GUILD(skill_id) ) {
  10154. if( sd->state.gmaster_flag )
  10155. skill_lv = guild_checkskill(sd->guild, skill_id);
  10156. else
  10157. skill_lv = 0;
  10158. } else {
  10159. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10160. }
  10161. pc_delinvincibletimer(sd);
  10162. if( skill_lv )
  10163. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10164. }
  10165. /*==========================================
  10166. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10167. *------------------------------------------*/
  10168. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10169. {
  10170. unsigned int tick = gettick();
  10171. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10172. return; //Using a target skill on the ground? WRONG.
  10173. if( SKILL_CHK_HOMUN(skill_id) ) {
  10174. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10175. return;
  10176. }
  10177. if( SKILL_CHK_MERC(skill_id) ) {
  10178. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10179. return;
  10180. }
  10181. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10182. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10183. sd->idletime = last_tick;
  10184. if( skill_isNotOk(skill_id, sd) )
  10185. return;
  10186. if( skillmoreinfo != -1 ) {
  10187. if( pc_issit(sd) ) {
  10188. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10189. return;
  10190. }
  10191. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10192. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  10193. }
  10194. if( sd->ud.skilltimer != INVALID_TIMER )
  10195. return;
  10196. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10197. if( sd->skillitem != skill_id ) {
  10198. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10199. return;
  10200. }
  10201. }
  10202. if( sd->sc.option&OPTION_COSTUME )
  10203. return;
  10204. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10205. return; // On basilica only caster can use Basilica again to stop it.
  10206. if( sd->menuskill_id ) {
  10207. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10208. clif_menuskill_clear(sd); //Cancel pet capture.
  10209. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10210. return; //Can't use skills while a menu is open.
  10211. }
  10212. pc_delinvincibletimer(sd);
  10213. if( sd->skillitem == skill_id ) {
  10214. if( skill_lv != sd->skillitemlv )
  10215. skill_lv = sd->skillitemlv;
  10216. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10217. } else {
  10218. int lv;
  10219. sd->skillitem = sd->skillitemlv = 0;
  10220. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10221. if( skill_lv > lv )
  10222. skill_lv = lv;
  10223. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10224. }
  10225. }
  10226. }
  10227. /// Request to use a ground skill.
  10228. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10229. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10230. /// There are various variants of this packet, some of them have padding between fields.
  10231. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10232. {
  10233. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10234. if (pc_cant_act(sd))
  10235. return;
  10236. if (pc_issit(sd))
  10237. return;
  10238. clif_parse_UseSkillToPosSub(fd, sd,
  10239. RFIFOW(fd,info->pos[0]), //skill lv
  10240. RFIFOW(fd,info->pos[1]), //skill num
  10241. RFIFOW(fd,info->pos[2]), //pos x
  10242. RFIFOW(fd,info->pos[3]), //pos y
  10243. -1 //Skill more info.
  10244. );
  10245. }
  10246. /// Request to use a ground skill with text.
  10247. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10248. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10249. /// There are various variants of this packet, some of them have padding between fields.
  10250. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10251. {
  10252. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10253. if (pc_cant_act(sd))
  10254. return;
  10255. if (pc_issit(sd))
  10256. return;
  10257. clif_parse_UseSkillToPosSub(fd, sd,
  10258. RFIFOW(fd,info->pos[0]), //Skill lv
  10259. RFIFOW(fd,info->pos[1]), //Skill num
  10260. RFIFOW(fd,info->pos[2]), //pos x
  10261. RFIFOW(fd,info->pos[3]), //pos y
  10262. info->pos[4] //skill more info
  10263. );
  10264. }
  10265. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10266. /// 011b <skill id>.W <map name>.16B
  10267. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10268. {
  10269. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10270. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10271. char map_name[MAP_NAME_LENGTH];
  10272. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  10273. if(skill_id != sd->menuskill_id)
  10274. return;
  10275. //It is possible to use teleport with the storage window open bugreport:8027
  10276. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10277. clif_menuskill_clear(sd);
  10278. return;
  10279. }
  10280. pc_delinvincibletimer(sd);
  10281. skill_castend_map(sd,skill_id,map_name);
  10282. }
  10283. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10284. /// 011d
  10285. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10286. {
  10287. if (!pc_isdead(sd))
  10288. pc_memo(sd,-1);
  10289. }
  10290. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10291. /// 018e <name id>.W { <material id>.W }*3
  10292. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10293. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10294. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10295. int slot1 = RFIFOW(fd,info->pos[1]);
  10296. int slot2 = RFIFOW(fd,info->pos[2]);
  10297. int slot3 = RFIFOW(fd,info->pos[3]);
  10298. short produce_idx = -1;
  10299. switch( sd->menuskill_id ) {
  10300. case -1:
  10301. case AM_PHARMACY:
  10302. case RK_RUNEMASTERY:
  10303. case GC_RESEARCHNEWPOISON:
  10304. break;
  10305. default:
  10306. return;
  10307. }
  10308. if (pc_istrading(sd)) {
  10309. //Make it fail to avoid shop exploits where you sell something different than you see.
  10310. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10311. clif_menuskill_clear(sd);
  10312. return;
  10313. }
  10314. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10315. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10316. clif_menuskill_clear(sd);
  10317. }
  10318. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10319. /// 025b <mk type>.W <name id>.W
  10320. /// mk type:
  10321. /// 1 = cooking
  10322. /// 2 = arrow
  10323. /// 3 = elemental
  10324. /// 4 = GN_MIX_COOKING
  10325. /// 5 = GN_MAKEBOMB
  10326. /// 6 = GN_S_PHARMACY
  10327. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10328. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10329. int type = RFIFOW(fd,info->pos[0]);
  10330. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10331. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10332. short food_idx = -1;
  10333. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10334. return;
  10335. if (pc_istrading(sd)) {
  10336. //Make it fail to avoid shop exploits where you sell something different than you see.
  10337. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10338. clif_menuskill_clear(sd);
  10339. return;
  10340. }
  10341. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10342. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10343. clif_menuskill_clear(sd);
  10344. }
  10345. /// Answer to repair weapon item selection dialog
  10346. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10347. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10348. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10349. {
  10350. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10351. return;
  10352. if (pc_istrading(sd)) {
  10353. //Make it fail to avoid shop exploits where you sell something different than you see.
  10354. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10355. clif_menuskill_clear(sd);
  10356. return;
  10357. }
  10358. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10359. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10360. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10361. //for(i = 0; i<MAX_SLOTS; i++)
  10362. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10363. clif_menuskill_clear(sd);
  10364. }
  10365. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10366. /// 0222 <index>.L
  10367. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10368. {
  10369. int idx;
  10370. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10371. return;
  10372. if (pc_istrading(sd)) {
  10373. //Make it fail to avoid shop exploits where you sell something different than you see.
  10374. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10375. clif_menuskill_clear(sd);
  10376. return;
  10377. }
  10378. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10379. skill_weaponrefine(sd, idx-2);
  10380. clif_menuskill_clear(sd);
  10381. }
  10382. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10383. /// 00b8 <npc id>.L <choice>.B
  10384. /// choice:
  10385. /// 1~254 = menu item
  10386. /// 255 = cancel
  10387. /// NOTE: If there were more than 254 items in the list, choice
  10388. /// overflows to choice%256.
  10389. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10390. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10391. int npc_id = RFIFOL(fd,info->pos[0]);
  10392. uint8 select = RFIFOB(fd,info->pos[1]);
  10393. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10394. #ifdef SECURE_NPCTIMEOUT
  10395. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10396. #endif
  10397. TBL_NPC* nd = map_id2nd(npc_id);
  10398. 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);
  10399. clif_GM_kick(NULL,sd);
  10400. #ifdef SECURE_NPCTIMEOUT
  10401. }
  10402. #endif
  10403. return;
  10404. }
  10405. sd->npc_menu = select;
  10406. npc_scriptcont(sd,npc_id, false);
  10407. }
  10408. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10409. /// 00b9 <npc id>.L
  10410. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10411. {
  10412. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10413. }
  10414. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10415. /// 0143 <npc id>.L <value>.L
  10416. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10417. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10418. int npcid = RFIFOL(fd,info->pos[0]);
  10419. int amount = (int)RFIFOL(fd,info->pos[1]);
  10420. sd->npc_amount = amount;
  10421. npc_scriptcont(sd, npcid, false);
  10422. }
  10423. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10424. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10425. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10426. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10427. int message_len = RFIFOW(fd,info->pos[0])-8;
  10428. int npcid = RFIFOL(fd,info->pos[1]);
  10429. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  10430. if( message_len <= 0 )
  10431. return; // invalid input
  10432. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10433. npc_scriptcont(sd, npcid, false);
  10434. }
  10435. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10436. /// 0146 <npc id>.L
  10437. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10438. {
  10439. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10440. return;
  10441. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10442. }
  10443. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10444. /// 0178 <index>.W
  10445. /// index:
  10446. /// -1 = cancel
  10447. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10448. {
  10449. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10450. if (sd->menuskill_id != MC_IDENTIFY)
  10451. return;
  10452. if( idx == -1 ) {// cancel pressed
  10453. clif_menuskill_clear(sd);
  10454. return;
  10455. }
  10456. skill_identify(sd,idx-2);
  10457. clif_menuskill_clear(sd);
  10458. }
  10459. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10460. /// 01ae <name id>.W
  10461. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10462. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10463. if (pc_istrading(sd)) {
  10464. //Make it fail to avoid shop exploits where you sell something different than you see.
  10465. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10466. clif_menuskill_clear(sd);
  10467. return;
  10468. }
  10469. switch (sd->menuskill_id) {
  10470. case AC_MAKINGARROW:
  10471. skill_arrow_create(sd,nameid);
  10472. break;
  10473. case SA_CREATECON:
  10474. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10475. break;
  10476. case WL_READING_SB:
  10477. skill_spellbook(sd,nameid);
  10478. break;
  10479. case GC_POISONINGWEAPON:
  10480. skill_poisoningweapon(sd,nameid);
  10481. break;
  10482. case NC_MAGICDECOY:
  10483. skill_magicdecoy(sd,nameid);
  10484. break;
  10485. }
  10486. clif_menuskill_clear(sd);
  10487. }
  10488. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10489. /// 01ce <skill id>.L
  10490. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10491. {
  10492. if (sd->menuskill_id != SA_AUTOSPELL)
  10493. return;
  10494. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10495. clif_menuskill_clear(sd);
  10496. }
  10497. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10498. /// 017a <card index>.W
  10499. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10500. {
  10501. if (sd->state.trading != 0)
  10502. return;
  10503. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10504. }
  10505. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10506. /// 017c <card index>.W <equip index>.W
  10507. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10508. {
  10509. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10510. if (sd->state.trading != 0)
  10511. return;
  10512. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10513. }
  10514. /// Request of character's name by char ID.
  10515. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10516. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10517. /// There are various variants of this packet, some of them have padding between fields.
  10518. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10519. {
  10520. int charid;
  10521. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10522. map_reqnickdb(sd, charid);
  10523. }
  10524. /// /resetskill /resetstate (CZ_RESET).
  10525. /// Request to reset stats or skills.
  10526. /// 0197 <type>.W
  10527. /// type:
  10528. /// 0 = state
  10529. /// 1 = skill
  10530. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10531. char cmd[15];
  10532. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10533. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10534. else
  10535. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10536. is_atcommand(fd, sd, cmd, 1);
  10537. }
  10538. /// /lb /nlb (CZ_LOCALBROADCAST).
  10539. /// Request to broadcast a message on current map.
  10540. /// 019c <packet len>.W <text>.?B
  10541. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10542. {
  10543. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10544. char command[CHAT_SIZE_MAX+16];
  10545. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10546. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10547. // as the length varies depending on the command used, just block unreasonably long strings
  10548. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10549. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10550. is_atcommand(fd, sd, command, 1);
  10551. }
  10552. /// Request to move an item from inventory to storage.
  10553. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10554. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10555. /// There are various variants of this packet, some of them have padding between fields.
  10556. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10557. {
  10558. int item_index, item_amount;
  10559. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10560. if (pc_istrading(sd))
  10561. return;
  10562. item_index = RFIFOW(fd,info->pos[0])-2;
  10563. item_amount = RFIFOL(fd,info->pos[1]);
  10564. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10565. return;
  10566. if (sd->state.storage_flag == 1)
  10567. storage_storageadd(sd, item_index, item_amount);
  10568. else
  10569. if (sd->state.storage_flag == 2)
  10570. gstorage_storageadd(sd, item_index, item_amount);
  10571. }
  10572. /// Request to move an item from storage to inventory.
  10573. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10574. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10575. /// There are various variants of this packet, some of them have padding between fields.
  10576. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10577. {
  10578. int item_index, item_amount;
  10579. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10580. item_index = RFIFOW(fd,info->pos[0])-1;
  10581. item_amount = RFIFOL(fd,info->pos[1]);
  10582. if (sd->state.storage_flag == 1)
  10583. storage_storageget(sd, item_index, item_amount);
  10584. else if(sd->state.storage_flag == 2)
  10585. gstorage_storageget(sd, item_index, item_amount);
  10586. }
  10587. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10588. /// 0129 <index>.W <amount>.L
  10589. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10590. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10591. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10592. int amount = RFIFOL(fd,info->pos[1]);
  10593. if( sd->state.vending )
  10594. return;
  10595. if (!pc_iscarton(sd))
  10596. return;
  10597. if (sd->state.storage_flag == 1)
  10598. storage_storageaddfromcart(sd, idx, amount);
  10599. else if (sd->state.storage_flag == 2)
  10600. gstorage_storageaddfromcart(sd, idx, amount);
  10601. }
  10602. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10603. /// 0128 <index>.W <amount>.L
  10604. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10605. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10606. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10607. int amount = RFIFOL(fd,info->pos[1]);
  10608. if( sd->state.vending )
  10609. return;
  10610. if (!pc_iscarton(sd))
  10611. return;
  10612. if (sd->state.storage_flag == 1)
  10613. storage_storagegettocart(sd, idx, amount);
  10614. else
  10615. if (sd->state.storage_flag == 2)
  10616. gstorage_storagegettocart(sd, idx, amount);
  10617. }
  10618. /// Request to close storage (CZ_CLOSE_STORE).
  10619. /// 00f7
  10620. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10621. {
  10622. if( sd->state.storage_flag == 1 )
  10623. storage_storageclose(sd);
  10624. else
  10625. if( sd->state.storage_flag == 2 )
  10626. gstorage_storageclose(sd);
  10627. }
  10628. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10629. /// 023a <info>.W
  10630. /// info:
  10631. /// 0 = password has not been set yet
  10632. /// 1 = storage is password-protected
  10633. /// 8 = too many wrong passwords
  10634. /// ? = ignored
  10635. /// NOTE: This packet is only available on certain non-kRO clients.
  10636. void clif_storagepassword(struct map_session_data* sd, short info)
  10637. {
  10638. int fd = sd->fd;
  10639. WFIFOHEAD(fd,packet_len(0x23a));
  10640. WFIFOW(fd,0) = 0x23a;
  10641. WFIFOW(fd,2) = info;
  10642. WFIFOSET(fd,packet_len(0x23a));
  10643. }
  10644. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10645. /// 023b <type>.W <password>.16B <new password>.16B
  10646. /// type:
  10647. /// 2 = change password
  10648. /// 3 = check password
  10649. /// NOTE: This packet is only available on certain non-kRO clients.
  10650. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10651. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10652. // int type = RFIFOW(fd,info->pos[0]);
  10653. // char* password = RFIFOP(fd,info->pos[1]);
  10654. // char* new_password = RFIFOP(fd,info->pos[2]);
  10655. // storage_changepass(sd,password,new_password);
  10656. }
  10657. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10658. /// 023c <result>.W <error count>.W
  10659. /// result:
  10660. /// 4 = password change success
  10661. /// 5 = password change failure
  10662. /// 6 = password check success
  10663. /// 7 = password check failure
  10664. /// 8 = too many wrong passwords
  10665. /// ? = ignored
  10666. /// NOTE: This packet is only available on certain non-kRO clients.
  10667. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10668. {
  10669. int fd = sd->fd;
  10670. WFIFOHEAD(fd,packet_len(0x23c));
  10671. WFIFOW(fd,0) = 0x23c;
  10672. WFIFOW(fd,2) = result;
  10673. WFIFOW(fd,4) = error_count;
  10674. WFIFOSET(fd,packet_len(0x23c));
  10675. }
  10676. /// Party creation request
  10677. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10678. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10679. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10680. name[NAME_LENGTH-1] = '\0';
  10681. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10682. clif_displaymessage(fd, msg_txt(sd,227));
  10683. return;
  10684. }
  10685. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10686. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10687. return;
  10688. }
  10689. party_create(sd,name,0,0);
  10690. }
  10691. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10692. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10693. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10694. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10695. int item1 = RFIFOB(fd,info->pos[1]);
  10696. int item2 = RFIFOB(fd,info->pos[2]);
  10697. name[NAME_LENGTH-1] = '\0';
  10698. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10699. clif_displaymessage(fd, msg_txt(sd,227));
  10700. return;
  10701. }
  10702. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10703. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10704. return;
  10705. }
  10706. party_create(sd,name,item1,item2);
  10707. }
  10708. /// Party invitation request
  10709. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10710. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10711. {
  10712. struct map_session_data *t_sd;
  10713. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10714. clif_displaymessage(fd, msg_txt(sd,227));
  10715. return;
  10716. }
  10717. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10718. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10719. clif_noask_sub(sd, t_sd, 1);
  10720. return;
  10721. }
  10722. party_invite(sd, t_sd);
  10723. }
  10724. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10725. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10726. struct map_session_data *t_sd;
  10727. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10728. name[NAME_LENGTH-1] = '\0';
  10729. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10730. clif_displaymessage(fd, msg_txt(sd,227));
  10731. return;
  10732. }
  10733. t_sd = map_nick2sd(name);
  10734. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10735. clif_noask_sub(sd, t_sd, 1);
  10736. return;
  10737. }
  10738. party_invite(sd, t_sd);
  10739. }
  10740. /// Party invitation reply
  10741. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10742. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10743. /// flag:
  10744. /// 0 = reject
  10745. /// 1 = accept
  10746. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10747. {
  10748. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10749. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10750. RFIFOL(fd,info->pos[1]));
  10751. }
  10752. //(CZ_PARTY_JOIN_REQ_ACK)
  10753. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10754. {
  10755. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10756. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10757. RFIFOB(fd,info->pos[1]));
  10758. }
  10759. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10760. /// 0100
  10761. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10762. {
  10763. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10764. clif_displaymessage(fd, msg_txt(sd,227));
  10765. return;
  10766. }
  10767. party_leave(sd);
  10768. }
  10769. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10770. /// 0103 <account id>.L <char name>.24B
  10771. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10772. {
  10773. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10774. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10775. clif_displaymessage(fd, msg_txt(sd,227));
  10776. return;
  10777. }
  10778. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10779. (char*)RFIFOP(fd,info->pos[1]));
  10780. }
  10781. /// Request to change party options.
  10782. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10783. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10784. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10785. {
  10786. struct party_data *p;
  10787. int i,expflag;
  10788. int cmd = RFIFOW(fd,0);
  10789. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10790. if( !sd->status.party_id )
  10791. return;
  10792. p = party_search(sd->status.party_id);
  10793. if( p == NULL )
  10794. return;
  10795. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10796. if( i == MAX_PARTY )
  10797. return; //Shouldn't happen
  10798. if( !p->party.member[i].leader )
  10799. return;
  10800. expflag = RFIFOL(fd,info->pos[0]);
  10801. if(cmd == 0x0102){ //Client can't change the item-field
  10802. party_changeoption(sd, expflag, p->party.item);
  10803. }
  10804. else {
  10805. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10806. party_changeoption(sd, expflag, itemflag);
  10807. }
  10808. }
  10809. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10810. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10811. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10812. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10813. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10814. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10815. char *name, *message;
  10816. int namelen, messagelen;
  10817. // validate packet and retrieve name and message
  10818. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10819. return;
  10820. if( is_atcommand(fd, sd, message, 1) )
  10821. return;
  10822. if (sd->sc.cant.chat)
  10823. return; //no "chatting" while muted.
  10824. if( battle_config.min_chat_delay )
  10825. { //[Skotlex]
  10826. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10827. return;
  10828. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10829. }
  10830. if (battle_config.idletime_option&IDLE_CHAT)
  10831. sd->idletime = last_tick;
  10832. party_send_message(sd, text, textlen);
  10833. }
  10834. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10835. /// 07da <account id>.L
  10836. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10837. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10838. }
  10839. /// Party Booking in KRO [Spiria]
  10840. ///
  10841. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10842. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10843. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10844. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10845. short level = RFIFOW(fd,info->pos[0]);
  10846. short mapid = RFIFOW(fd,info->pos[1]);
  10847. int idxpbj = info->pos[2];
  10848. short job[PARTY_BOOKING_JOBS];
  10849. int i;
  10850. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10851. job[i] = RFIFOB(fd,idxpbj+i*2);
  10852. party_booking_register(sd, level, mapid, job);
  10853. }
  10854. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10855. /// 0803 <result>.W
  10856. /// result:
  10857. /// 0 = success
  10858. /// 1 = failure
  10859. /// 2 = already registered
  10860. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10861. {
  10862. int fd = sd->fd;
  10863. WFIFOHEAD(fd,packet_len(0x803));
  10864. WFIFOW(fd,0) = 0x803;
  10865. WFIFOW(fd,2) = flag;
  10866. WFIFOSET(fd,packet_len(0x803));
  10867. }
  10868. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10869. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10870. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10871. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10872. short level = RFIFOW(fd,info->pos[0]);
  10873. short mapid = RFIFOW(fd,info->pos[1]);
  10874. short job = RFIFOW(fd,info->pos[2]);
  10875. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10876. short resultcount = RFIFOW(fd,info->pos[4]);
  10877. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10878. }
  10879. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10880. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10881. /// more results:
  10882. /// 0 = no
  10883. /// 1 = yes
  10884. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10885. {
  10886. int i, j;
  10887. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10888. struct party_booking_ad_info *pb_ad;
  10889. WFIFOHEAD(fd,size*count + 5);
  10890. WFIFOW(fd,0) = 0x805;
  10891. WFIFOW(fd,2) = size*count + 5;
  10892. WFIFOB(fd,4) = more_result;
  10893. for(i=0; i<count; i++)
  10894. {
  10895. pb_ad = results[i];
  10896. WFIFOL(fd,i*size+5) = pb_ad->index;
  10897. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10898. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10899. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10900. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10901. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10902. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10903. }
  10904. WFIFOSET(fd,WFIFOW(fd,2));
  10905. }
  10906. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10907. /// 0806
  10908. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10909. {
  10910. if(party_booking_delete(sd))
  10911. clif_PartyBookingDeleteAck(sd, 0);
  10912. }
  10913. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10914. /// 0807 <result>.W
  10915. /// result:
  10916. /// 0 = success
  10917. /// 1 = success (auto-removed expired ad)
  10918. /// 2 = failure
  10919. /// 3 = nothing registered
  10920. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10921. {
  10922. int fd = sd->fd;
  10923. WFIFOHEAD(fd,packet_len(0x807));
  10924. WFIFOW(fd,0) = 0x807;
  10925. WFIFOW(fd,2) = flag;
  10926. WFIFOSET(fd,packet_len(0x807));
  10927. }
  10928. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10929. /// 0808 { <job>.W }*6
  10930. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10931. {
  10932. short job[PARTY_BOOKING_JOBS];
  10933. int i;
  10934. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10935. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10936. job[i] = RFIFOW(fd,idxpbu+i*2);
  10937. party_booking_update(sd, job);
  10938. }
  10939. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10940. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10941. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10942. {
  10943. int i;
  10944. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10945. if(pb_ad == NULL) return;
  10946. WBUFW(buf,0) = 0x809;
  10947. WBUFL(buf,2) = pb_ad->index;
  10948. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10949. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10950. WBUFW(buf,34) = pb_ad->p_detail.level;
  10951. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10952. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10953. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10954. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10955. }
  10956. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10957. /// 080a <index>.L { <job>.W }*6
  10958. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10959. {
  10960. int i;
  10961. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10962. if(pb_ad == NULL) return;
  10963. WBUFW(buf,0) = 0x80a;
  10964. WBUFL(buf,2) = pb_ad->index;
  10965. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10966. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10967. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10968. }
  10969. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10970. /// 080b <index>.L
  10971. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10972. {
  10973. uint8 buf[6];
  10974. WBUFW(buf,0) = 0x80b;
  10975. WBUFL(buf,2) = index;
  10976. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10977. }
  10978. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10979. /// 012e
  10980. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10981. {
  10982. vending_closevending(sd);
  10983. }
  10984. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10985. /// 0130 <account id>.L
  10986. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10987. {
  10988. if( sd->npc_id ) {// using an NPC
  10989. return;
  10990. }
  10991. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10992. }
  10993. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10994. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10995. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10996. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10997. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10998. int id = (int)RFIFOL(fd,info->pos[1]);
  10999. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11000. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11001. // whether it fails or not, the buy window is closed
  11002. sd->vended_id = 0;
  11003. }
  11004. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11005. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11006. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11007. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11008. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11009. int aid = (int)RFIFOL(fd,info->pos[1]);
  11010. int uid = (int)RFIFOL(fd,info->pos[2]);
  11011. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11012. vending_purchasereq(sd, aid, uid, data, len/4);
  11013. // whether it fails or not, the buy window is closed
  11014. sd->vended_id = 0;
  11015. }
  11016. /// Confirm or cancel the shop preparation window.
  11017. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11018. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11019. /// result:
  11020. /// 0 = canceled
  11021. /// 1 = open
  11022. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11023. int cmd = RFIFOW(fd,0);
  11024. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  11025. short len = (short)RFIFOW(fd,info->pos[0]);
  11026. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  11027. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11028. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11029. len -= 84;
  11030. }
  11031. else { //(CZ_REQ_OPENSTORE2)
  11032. bool flag;
  11033. len -= 85;
  11034. flag = (bool)RFIFOB(fd,info->pos[2]);
  11035. if( !flag )
  11036. sd->state.prevend = 0;
  11037. }
  11038. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11039. return;
  11040. if( map[sd->bl.m].flag.novending ) {
  11041. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11042. return;
  11043. }
  11044. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11045. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11046. return;
  11047. }
  11048. if( message[0] == '\0' ) // invalid input
  11049. return;
  11050. vending_openvending(sd, message, data, len/8, NULL);
  11051. }
  11052. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11053. /// 0165 <char id>.L <guild name>.24B
  11054. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11055. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11056. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11057. name[NAME_LENGTH-1] = '\0';
  11058. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11059. clif_displaymessage(fd, msg_txt(sd,228));
  11060. return;
  11061. }
  11062. guild_create(sd, name);
  11063. }
  11064. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11065. /// 014d
  11066. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11067. {
  11068. clif_guild_masterormember(sd);
  11069. }
  11070. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11071. /// 014f <type>.L
  11072. /// type:
  11073. /// 0 = basic info
  11074. /// 1 = member manager
  11075. /// 2 = positions
  11076. /// 3 = skills
  11077. /// 4 = expulsion list
  11078. /// 5 = unknown (GM_ALLGUILDLIST)
  11079. /// 6 = notice
  11080. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11081. {
  11082. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11083. if( !sd->status.guild_id && !sd->bg_id )
  11084. return;
  11085. switch( type )
  11086. {
  11087. case 0: // Basic Information Guild, hostile alliance information
  11088. clif_guild_basicinfo(sd);
  11089. clif_guild_allianceinfo(sd);
  11090. break;
  11091. case 1: // Members list, list job title
  11092. clif_guild_positionnamelist(sd);
  11093. clif_guild_memberlist(sd);
  11094. break;
  11095. case 2: // List job title, title information list
  11096. clif_guild_positionnamelist(sd);
  11097. clif_guild_positioninfolist(sd);
  11098. break;
  11099. case 3: // Skill list
  11100. clif_guild_skillinfo(sd);
  11101. break;
  11102. case 4: // Expulsion list
  11103. clif_guild_expulsionlist(sd);
  11104. break;
  11105. default:
  11106. ShowError("clif: guild request info: unknown type %d\n", type);
  11107. break;
  11108. }
  11109. }
  11110. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11111. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11112. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11113. {
  11114. int i;
  11115. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11116. int len = RFIFOW(fd,info->pos[0]);
  11117. int idxgpos = info->pos[1];
  11118. if(!sd->state.gmaster_flag)
  11119. return;
  11120. for(i = idxgpos; i < len; i += 40 ){
  11121. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  11122. }
  11123. }
  11124. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11125. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11126. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11127. {
  11128. int i;
  11129. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11130. int len = RFIFOW(fd,info->pos[0]);
  11131. int idxgpos = info->pos[1];
  11132. if(!sd->state.gmaster_flag)
  11133. return;
  11134. for(i=idxgpos;i<len;i+=12){
  11135. guild_change_memberposition(sd->status.guild_id,
  11136. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11137. }
  11138. }
  11139. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11140. /// 0151 <guild id>.L
  11141. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11142. {
  11143. struct guild* g;
  11144. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11145. if( (g = guild_search(guild_id)) != NULL )
  11146. clif_guild_emblem(sd,g);
  11147. }
  11148. /// Validates data of a guild emblem (compressed bitmap)
  11149. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11150. {
  11151. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11152. unsigned long buf_len = sizeof(buf);
  11153. int offset = 0;
  11154. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11155. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11156. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11157. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11158. ))
  11159. return -1;
  11160. if(battle_config.emblem_transparency_limit != 100) {
  11161. int i, transcount = 1, tmp[3];
  11162. for(i = offset; i < buf_len-1; i++) {
  11163. int j = i%3;
  11164. tmp[j] = RBUFL(buf,i);
  11165. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11166. transcount++;
  11167. }
  11168. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11169. return -2;
  11170. }
  11171. return 0;
  11172. }
  11173. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11174. /// 0153 <packet len>.W <emblem data>.?B
  11175. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11176. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11177. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11178. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11179. int emb_val=0;
  11180. if( !emblem_len || !sd->state.gmaster_flag )
  11181. return;
  11182. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  11183. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  11184. return;
  11185. }
  11186. emb_val = clif_validate_emblem(emblem, emblem_len);
  11187. if(emb_val ==-1 ){
  11188. 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);
  11189. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11190. return;
  11191. } else if(emb_val == -2){
  11192. char output[128];
  11193. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11194. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11195. return;
  11196. }
  11197. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11198. }
  11199. /// Guild notice update request (CZ_GUILD_NOTICE).
  11200. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11201. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11202. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11203. int guild_id = RFIFOL(fd,info->pos[0]);
  11204. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  11205. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  11206. if(!sd->state.gmaster_flag)
  11207. return;
  11208. // compensate for some client defects when using multilanguage mode
  11209. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11210. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11211. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11212. guild_change_notice(sd, guild_id, msg1, msg2);
  11213. }
  11214. // Helper function for guild invite functions
  11215. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11216. {
  11217. if (t_sd == NULL) // not online or does not exist
  11218. return 1;
  11219. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11220. clif_displaymessage(fd, msg_txt(sd,228));
  11221. return 1;
  11222. }
  11223. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11224. clif_noask_sub(sd, t_sd, 2);
  11225. return 1;
  11226. }
  11227. guild_invite(sd, t_sd);
  11228. return 0;
  11229. }
  11230. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11231. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11232. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11233. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11234. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11235. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11236. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11237. if (clif_sub_guild_invite(fd, sd, t_sd))
  11238. return;
  11239. }
  11240. /// Guild invite request (/guildinvite)
  11241. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11242. void
  11243. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11244. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11245. if (clif_sub_guild_invite(fd, sd, t_sd))
  11246. return;
  11247. }
  11248. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11249. /// 016b <guild id>.L <answer>.L
  11250. /// answer:
  11251. /// 0 = refuse
  11252. /// 1 = accept
  11253. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11254. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11255. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11256. RFIFOL(fd,info->pos[1]));
  11257. }
  11258. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11259. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11260. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11261. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11262. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11263. clif_displaymessage(fd, msg_txt(sd,228));
  11264. return;
  11265. }
  11266. if( sd->bg_id ) {
  11267. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11268. return;
  11269. }
  11270. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11271. RFIFOL(fd,info->pos[1]),
  11272. RFIFOL(fd,info->pos[2]),
  11273. (char*)RFIFOP(fd,info->pos[3]));
  11274. }
  11275. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11276. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11277. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11278. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11279. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11280. { // Guild locked.
  11281. clif_displaymessage(fd, msg_txt(sd,228));
  11282. return;
  11283. }
  11284. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11285. RFIFOL(fd,info->pos[1]),
  11286. RFIFOL(fd,info->pos[2]),
  11287. (char*)RFIFOP(fd,info->pos[3]));
  11288. }
  11289. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11290. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11291. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11292. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11293. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  11294. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  11295. char *name, *message;
  11296. int namelen, messagelen;
  11297. // validate packet and retrieve name and message
  11298. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11299. return;
  11300. if( is_atcommand(fd, sd, message, 1) )
  11301. return;
  11302. if (sd->sc.cant.chat)
  11303. return; //no "chatting" while muted.
  11304. if( battle_config.min_chat_delay )
  11305. { //[Skotlex]
  11306. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  11307. return;
  11308. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11309. }
  11310. if (battle_config.idletime_option&IDLE_CHAT)
  11311. sd->idletime = last_tick;
  11312. if( sd->bg_id )
  11313. bg_send_message(sd, text, textlen);
  11314. else
  11315. guild_send_message(sd, text, textlen);
  11316. }
  11317. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11318. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11319. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11320. {
  11321. struct map_session_data *t_sd;
  11322. if(!sd->state.gmaster_flag)
  11323. return;
  11324. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11325. clif_displaymessage(fd, msg_txt(sd,228));
  11326. return;
  11327. }
  11328. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11329. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11330. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11331. // @noask [LuzZza]
  11332. if(t_sd && t_sd->state.noask) {
  11333. clif_noask_sub(sd, t_sd, 3);
  11334. return;
  11335. }
  11336. guild_reqalliance(sd,t_sd);
  11337. }
  11338. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11339. /// 0172 <inviter account id>.L <answer>.L
  11340. /// answer:
  11341. /// 0 = refuse
  11342. /// 1 = accept
  11343. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11344. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11345. guild_reply_reqalliance(sd,
  11346. RFIFOL(fd,info->pos[0]),
  11347. RFIFOL(fd,info->pos[1]));
  11348. }
  11349. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11350. /// 0183 <opponent guild id>.L <relation>.L
  11351. /// relation:
  11352. /// 0 = Ally
  11353. /// 1 = Enemy
  11354. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11355. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11356. if(!sd->state.gmaster_flag)
  11357. return;
  11358. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11359. clif_displaymessage(fd, msg_txt(sd,228));
  11360. return;
  11361. }
  11362. guild_delalliance(sd,
  11363. RFIFOL(fd,info->pos[0]),
  11364. RFIFOL(fd,info->pos[1]));
  11365. }
  11366. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11367. /// 0180 <account id>.L
  11368. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11369. {
  11370. struct map_session_data *t_sd;
  11371. if(!sd->state.gmaster_flag)
  11372. return;
  11373. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11374. clif_displaymessage(fd, msg_txt(sd,228));
  11375. return;
  11376. }
  11377. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11378. // @noask [LuzZza]
  11379. if(t_sd && t_sd->state.noask) {
  11380. clif_noask_sub(sd, t_sd, 4);
  11381. return;
  11382. }
  11383. guild_opposition(sd,t_sd);
  11384. }
  11385. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11386. /// 015d <key>.40B
  11387. /// key:
  11388. /// now guild name; might have been (intended) email, since the
  11389. /// field name and size is same as the one in CH_DELETE_CHAR.
  11390. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11391. {
  11392. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11393. clif_displaymessage(fd, msg_txt(sd,228));
  11394. return;
  11395. }
  11396. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11397. }
  11398. /// Pet
  11399. ///
  11400. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11401. /// 01a1 <type>.B
  11402. /// type:
  11403. /// 0 = pet information
  11404. /// 1 = feed
  11405. /// 2 = performance
  11406. /// 3 = return to egg
  11407. /// 4 = unequip accessory
  11408. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11409. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11410. }
  11411. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11412. /// 019f <id>.L
  11413. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11414. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11415. }
  11416. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11417. /// 01a7 <index>.W
  11418. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11419. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11420. return;
  11421. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11422. clif_menuskill_clear(sd);
  11423. }
  11424. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11425. /// 01a9 <data>.L
  11426. /// data:
  11427. /// is either emotion (@see enum emotion_type) or a compound value
  11428. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11429. /// entry (given in parentheses) in data\pettalktable.xml
  11430. /// act id:
  11431. /// 0 = feeding
  11432. /// 1 = hunting
  11433. /// 2 = danger
  11434. /// 3 = dead
  11435. /// 4 = normal (stand)
  11436. /// 5 = special performance (perfor_s)
  11437. /// 6 = level up (levelup)
  11438. /// 7 = performance 1 (perfor_1)
  11439. /// 8 = performance 2 (perfor_2)
  11440. /// 9 = performance 3 (perfor_3)
  11441. /// 10 = log-in greeting (connect)
  11442. /// hungry value:
  11443. /// 0 = very hungry (hungry)
  11444. /// 1 = hungry (bit_hungry)
  11445. /// 2 = satisfied (noting)
  11446. /// 3 = stuffed (full)
  11447. /// 4 = full (so_full)
  11448. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11449. {
  11450. if(sd->pd)
  11451. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11452. }
  11453. /// Request to change pet's name (CZ_RENAME_PET).
  11454. /// 01a5 <name>.24B
  11455. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11456. {
  11457. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11458. }
  11459. /// /kill (CZ_DISCONNECT_CHARACTER).
  11460. /// Request to disconnect a character.
  11461. /// 00cc <account id>.L
  11462. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11463. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11464. {
  11465. struct block_list *target;
  11466. int tid;
  11467. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11468. target = map_id2bl(tid);
  11469. if (!target) {
  11470. clif_GM_kickack(sd, 0);
  11471. return;
  11472. }
  11473. switch (target->type) {
  11474. case BL_PC:
  11475. {
  11476. char command[NAME_LENGTH+6];
  11477. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11478. is_atcommand(fd, sd, command, 1);
  11479. }
  11480. break;
  11481. /**
  11482. * This one does not invoke any atcommand, so we need to check for permissions.
  11483. */
  11484. case BL_MOB:
  11485. {
  11486. char command[100];
  11487. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11488. clif_GM_kickack(sd, 0);
  11489. return;
  11490. }
  11491. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11492. log_atcommand(sd, command);
  11493. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11494. }
  11495. break;
  11496. case BL_NPC:
  11497. {
  11498. struct npc_data* nd = (struct npc_data *)target;
  11499. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11500. npc_unload_duplicates(nd);
  11501. npc_unload(nd,true);
  11502. npc_read_event_script();
  11503. }
  11504. }
  11505. break;
  11506. default:
  11507. clif_GM_kickack(sd, 0);
  11508. }
  11509. }
  11510. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11511. /// Request to disconnect all characters.
  11512. /// 00ce
  11513. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11514. char cmd[15];
  11515. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11516. is_atcommand(fd, sd, cmd, 1);
  11517. }
  11518. /// /remove (CZ_REMOVE_AID).
  11519. /// Request to warp to a character with given login ID.
  11520. /// 01ba <account name>.24B
  11521. /// /shift (CZ_SHIFT).
  11522. /// Request to warp to a character with given name.
  11523. /// 01bb <char name>.24B
  11524. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11525. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11526. char *player_name;
  11527. char command[NAME_LENGTH+8];
  11528. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11529. player_name[NAME_LENGTH-1] = '\0';
  11530. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11531. is_atcommand(fd, sd, command, 1);
  11532. }
  11533. /// /remove (CZ_REMOVE_AID_SSO).
  11534. /// Request to warp to a character with given account ID.
  11535. /// 0843 <account id>.L
  11536. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11537. {
  11538. uint32 account_id;
  11539. struct map_session_data* pl_sd;
  11540. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11541. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11542. char command[NAME_LENGTH+8];
  11543. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11544. is_atcommand(fd, sd, command, 1);
  11545. }
  11546. }
  11547. /// /recall (CZ_RECALL).
  11548. /// Request to summon a player with given login ID to own position.
  11549. /// 01bc <account name>.24B
  11550. /// /summon (CZ_RECALL_GID).
  11551. /// Request to summon a player with given name to own position.
  11552. /// 01bd <char name>.24B
  11553. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11554. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11555. char *player_name;
  11556. char command [NAME_LENGTH+8];
  11557. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11558. player_name[NAME_LENGTH-1] = '\0';
  11559. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11560. is_atcommand(fd, sd, command, 1);
  11561. }
  11562. /// /recall (CZ_RECALL_SSO).
  11563. /// Request to summon a player with given account ID to own position.
  11564. /// 0842 <account id>.L
  11565. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11566. {
  11567. uint32 account_id;
  11568. struct map_session_data* pl_sd;
  11569. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11570. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11571. char command[NAME_LENGTH+8];
  11572. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11573. is_atcommand(fd, sd, command, 1);
  11574. }
  11575. }
  11576. /// /item /monster (CZ_ITEM_CREATE).
  11577. /// Request to execute GM commands.
  11578. /// Usage:
  11579. /// /item n - summon n monster or acquire n item/s
  11580. /// /item money - grants 2147483647 zenies
  11581. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11582. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11583. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11584. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11585. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11586. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11587. /// 013f <item/mob name>.24B
  11588. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11589. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11590. {
  11591. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11592. int mob_id = 0;
  11593. struct item_data *id = NULL;
  11594. struct mob_db *mob = NULL;
  11595. StringBuf command;
  11596. char *str;
  11597. //#if PACKETVER >= 20131218
  11598. // char str[100];
  11599. //#else
  11600. // char str[24];
  11601. //#endif
  11602. str = (char*)RFIFOP(fd,info->pos[0]);
  11603. if (!str || str[0] == '\0')
  11604. return;
  11605. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11606. return;
  11607. trim(str);
  11608. // Zeny
  11609. if( strcmpi(str, "money") == 0 ) {
  11610. StringBuf_Init(&command);
  11611. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11612. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11613. StringBuf_Destroy(&command);
  11614. return;
  11615. }
  11616. // Item
  11617. if( (id = itemdb_searchname(str)) ) {
  11618. StringBuf_Init(&command);
  11619. if( !itemdb_isstackable2(id) ) //Nonstackable
  11620. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11621. else {
  11622. if (id->flag.guid)
  11623. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11624. else
  11625. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11626. }
  11627. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11628. StringBuf_Destroy(&command);
  11629. return;
  11630. }
  11631. // Monster
  11632. if ((mob_id = mobdb_searchname(str)) == 0)
  11633. mob_id = mobdb_checkid(atoi(str));
  11634. if( (mob = mob_db(mob_id)) ) {
  11635. StringBuf_Init(&command);
  11636. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11637. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11638. StringBuf_Destroy(&command);
  11639. return;
  11640. }
  11641. }
  11642. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11643. /// 019d <effect state>.L
  11644. /// effect state:
  11645. /// TODO: Any OPTION_* ?
  11646. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11647. char cmd[6];
  11648. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11649. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11650. is_atcommand(fd, sd, cmd, 1);
  11651. }
  11652. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11653. /// 0149 <account id>.L <type>.B <value>.W
  11654. /// type:
  11655. /// 0 = positive points
  11656. /// 1 = negative points
  11657. /// 2 = self mute (+10 minutes)
  11658. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11659. {
  11660. int id, type, value;
  11661. struct map_session_data *dstsd;
  11662. char command[NAME_LENGTH+15];
  11663. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11664. id = RFIFOL(fd,info->pos[0]);
  11665. type = RFIFOB(fd,info->pos[1]);
  11666. value = RFIFOW(fd,info->pos[2]);
  11667. if( type == 0 )
  11668. value = -value;
  11669. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11670. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11671. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11672. return;
  11673. dstsd = map_id2sd(id);
  11674. if( dstsd == NULL )
  11675. return;
  11676. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11677. is_atcommand(fd, sd, command, 1);
  11678. }
  11679. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11680. /// GM adjustment of a player's manner value by -60.
  11681. /// 0212 <char name>.24B
  11682. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11683. {
  11684. char command[NAME_LENGTH+15];
  11685. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11686. name[NAME_LENGTH-1] = '\0';
  11687. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11688. is_atcommand(fd, sd, command, 1);
  11689. }
  11690. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11691. /// 01e0 <account id>.L <account name>.24B
  11692. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11693. {
  11694. WFIFOHEAD(fd,packet_len(0x1e0));
  11695. WFIFOW(fd,0) = 0x1e0;
  11696. WFIFOL(fd,2) = account_id;
  11697. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11698. WFIFOSET(fd,packet_len(0x1e0));
  11699. }
  11700. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11701. /// 01df <account id>.L
  11702. //! TODO: Figure out how does this actually work
  11703. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11704. {
  11705. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11706. /*
  11707. char query[30];
  11708. safesnprintf(query,sizeof(query),"%d", account_id);
  11709. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11710. */
  11711. clif_account_name(fd, account_id, "");
  11712. }
  11713. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11714. /// GM single cell type change request.
  11715. /// 0198 <x>.W <y>.W <type>.W
  11716. /// type:
  11717. /// 0 = not walkable
  11718. /// 1 = walkable
  11719. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11720. {
  11721. int x,y,type;
  11722. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11723. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11724. return;
  11725. x = RFIFOW(fd,info->pos[0]);
  11726. y = RFIFOW(fd,info->pos[1]);
  11727. type = RFIFOW(fd,info->pos[2]);
  11728. map_setgatcell(sd->bl.m,x,y,type);
  11729. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11730. //FIXME: once players leave the map, the client 'forgets' this information.
  11731. }
  11732. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11733. /// Request to allow/deny whispers from a nick.
  11734. /// 00cf <nick>.24B <type>.B
  11735. /// type:
  11736. /// 0 = (/ex nick) deny speech from nick
  11737. /// 1 = (/in nick) allow speech from nick
  11738. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11739. {
  11740. char* nick;
  11741. uint8 type;
  11742. int i;
  11743. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11744. nick = (char*)RFIFOP(fd,info->pos[0]);
  11745. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11746. type = RFIFOB(fd,info->pos[1]);
  11747. if( type == 0 ) { // Add name to ignore list (block)
  11748. if (strcmp(wisp_server_name, nick) == 0) {
  11749. clif_wisexin(sd, type, 1); // fail
  11750. return;
  11751. }
  11752. // try to find a free spot, while checking for duplicates at the same time
  11753. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11754. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11755. clif_wisexin(sd, type, 2); // too many blocks
  11756. return;
  11757. }
  11758. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11759. clif_wisexin(sd, type, 0); // Aegis reports success.
  11760. return;
  11761. }
  11762. //Insert in position i
  11763. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11764. } else { // Remove name from ignore list (unblock)
  11765. // find entry
  11766. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11767. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11768. clif_wisexin(sd, type, 1); // fail
  11769. return;
  11770. }
  11771. // move everything one place down to overwrite removed entry
  11772. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11773. // wipe last entry
  11774. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11775. }
  11776. clif_wisexin(sd, type, 0); // success
  11777. }
  11778. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11779. /// Request to allow/deny all whispers.
  11780. /// 00d0 <type>.B
  11781. /// type:
  11782. /// 0 = (/exall) deny all speech
  11783. /// 1 = (/inall) allow all speech
  11784. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11785. {
  11786. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11787. if( type == 0 ) {// Deny all
  11788. if( sd->state.ignoreAll ) {
  11789. flag = 1; // fail
  11790. } else {
  11791. sd->state.ignoreAll = 1;
  11792. flag = 0; // success
  11793. }
  11794. } else {//Unblock everyone
  11795. if( sd->state.ignoreAll ) {
  11796. sd->state.ignoreAll = 0;
  11797. flag = 0; // success
  11798. } else {
  11799. if (sd->ignore[0].name[0] != '\0')
  11800. { //Wipe the ignore list.
  11801. memset(sd->ignore, 0, sizeof(sd->ignore));
  11802. flag = 0; // success
  11803. } else {
  11804. flag = 1; // fail
  11805. }
  11806. }
  11807. }
  11808. clif_wisall(sd, type, flag);
  11809. }
  11810. /// Whisper ignore list (ZC_WHISPER_LIST).
  11811. /// 00d4 <packet len>.W { <char name>.24B }*
  11812. void clif_PMIgnoreList(struct map_session_data* sd)
  11813. {
  11814. int i, fd = sd->fd;
  11815. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11816. WFIFOW(fd,0) = 0xd4;
  11817. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11818. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11819. }
  11820. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11821. WFIFOSET(fd,WFIFOW(fd,2));
  11822. }
  11823. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11824. /// 00d3
  11825. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11826. {
  11827. clif_PMIgnoreList(sd);
  11828. }
  11829. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11830. /// 01e7
  11831. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11832. {
  11833. if (sd->state.doridori) return;
  11834. switch (sd->class_&MAPID_UPPERMASK) {
  11835. case MAPID_SOUL_LINKER:
  11836. case MAPID_STAR_GLADIATOR:
  11837. case MAPID_TAEKWON:
  11838. if (!sd->state.rest)
  11839. break;
  11840. case MAPID_SUPER_NOVICE:
  11841. case MAPID_SUPER_BABY:
  11842. case MAPID_SUPER_NOVICE_E:
  11843. case MAPID_SUPER_BABY_E:
  11844. sd->state.doridori=1;
  11845. break;
  11846. }
  11847. }
  11848. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11849. /// 01ed
  11850. /// Note: This packet is caused by 7 lines of any text, followed by
  11851. /// the prayer and an another line of any text. The prayer is
  11852. /// defined by lines 790~793 in data\msgstringtable.txt
  11853. /// "Dear angel, can you hear my voice?"
  11854. /// "I am" (space separated player name) "Super Novice~"
  11855. /// "Help me out~ Please~ T_T"
  11856. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11857. {
  11858. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11859. unsigned int next = pc_nextbaseexp(sd);
  11860. if( next == 0 ) next = pc_thisbaseexp(sd);
  11861. if( next ) {
  11862. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11863. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11864. 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]
  11865. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11866. }
  11867. }
  11868. }
  11869. }
  11870. /// Friends List
  11871. ///
  11872. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11873. /// 0206 <account id>.L <char id>.L <state>.B
  11874. /// state:
  11875. /// 0 = online
  11876. /// 1 = offline
  11877. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11878. {
  11879. int i, fd = sd->fd;
  11880. //Seek friend.
  11881. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11882. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11883. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11884. return; //Not found
  11885. WFIFOHEAD(fd,packet_len(0x206));
  11886. WFIFOW(fd, 0) = 0x206;
  11887. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11888. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11889. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11890. WFIFOSET(fd, packet_len(0x206));
  11891. }
  11892. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11893. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11894. {
  11895. uint32 account_id, char_id, online;
  11896. account_id = va_arg(ap, int);
  11897. char_id = va_arg(ap, int);
  11898. online = va_arg(ap, int);
  11899. clif_friendslist_toggle(sd, account_id, char_id, online);
  11900. return 0;
  11901. }
  11902. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11903. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11904. void clif_friendslist_send(struct map_session_data *sd)
  11905. {
  11906. int i = 0, n, fd = sd->fd;
  11907. // Send friends list
  11908. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11909. WFIFOW(fd, 0) = 0x201;
  11910. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11911. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11912. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11913. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11914. }
  11915. if (i) {
  11916. WFIFOW(fd,2) = 4 + 32 * i;
  11917. WFIFOSET(fd, WFIFOW(fd,2));
  11918. }
  11919. for (n = 0; n < i; n++) { //Sending the online players
  11920. if (map_charid2sd(sd->status.friends[n].char_id))
  11921. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11922. }
  11923. }
  11924. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11925. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11926. /// result:
  11927. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11928. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11929. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11930. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11931. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11932. {
  11933. int fd;
  11934. nullpo_retv(sd);
  11935. fd = sd->fd;
  11936. WFIFOHEAD(fd,packet_len(0x209));
  11937. WFIFOW(fd,0) = 0x209;
  11938. WFIFOW(fd,2) = type;
  11939. if (f_sd) {
  11940. WFIFOL(fd,4) = f_sd->status.account_id;
  11941. WFIFOL(fd,8) = f_sd->status.char_id;
  11942. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11943. }
  11944. WFIFOSET(fd, packet_len(0x209));
  11945. }
  11946. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11947. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11948. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  11949. {
  11950. int fd = sd->fd;
  11951. WFIFOHEAD(fd,packet_len(0x207));
  11952. WFIFOW(fd,0) = 0x207;
  11953. WFIFOL(fd,2) = account_id;
  11954. WFIFOL(fd,6) = char_id;
  11955. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11956. WFIFOSET(fd,packet_len(0x207));
  11957. }
  11958. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11959. /// 0202 <name>.24B
  11960. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11961. {
  11962. struct map_session_data *f_sd;
  11963. int i;
  11964. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11965. // ensure that the request player's friend list is not full
  11966. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11967. if( i == MAX_FRIENDS ) {
  11968. clif_friendslist_reqack(sd, f_sd, 2);
  11969. return;
  11970. }
  11971. // Friend doesn't exist (no player with this name)
  11972. if (f_sd == NULL) {
  11973. clif_displaymessage(fd, msg_txt(sd,3));
  11974. return;
  11975. }
  11976. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11977. return;
  11978. }
  11979. // @noask [LuzZza]
  11980. if(f_sd->state.noask) {
  11981. clif_noask_sub(sd, f_sd, 5);
  11982. return;
  11983. }
  11984. // Friend already exists
  11985. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11986. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11987. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11988. return;
  11989. }
  11990. }
  11991. f_sd->friend_req = sd->status.char_id;
  11992. sd->friend_req = f_sd->status.char_id;
  11993. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11994. }
  11995. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11996. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11997. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11998. /// reply:
  11999. /// 0 = rejected
  12000. /// 1 = accepted
  12001. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12002. {
  12003. struct map_session_data *f_sd;
  12004. uint32 account_id;
  12005. char reply;
  12006. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12007. account_id = RFIFOL(fd,info->pos[0]);
  12008. //char_id = RFIFOL(fd,info->pos[1]);
  12009. if(sd->packet_ver < 6)
  12010. reply = RFIFOB(fd,info->pos[2]);
  12011. else
  12012. reply = RFIFOL(fd,info->pos[2]);
  12013. if( sd->bl.id == account_id ) {// adding oneself as friend
  12014. return;
  12015. }
  12016. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12017. if (f_sd == NULL)
  12018. return;
  12019. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12020. clif_friendslist_reqack(f_sd, sd, 1);
  12021. else {
  12022. int i;
  12023. // Find an empty slot
  12024. for (i = 0; i < MAX_FRIENDS; i++)
  12025. if (f_sd->status.friends[i].char_id == 0)
  12026. break;
  12027. if (i == MAX_FRIENDS) {
  12028. clif_friendslist_reqack(f_sd, sd, 2);
  12029. return;
  12030. }
  12031. f_sd->status.friends[i].account_id = sd->status.account_id;
  12032. f_sd->status.friends[i].char_id = sd->status.char_id;
  12033. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12034. clif_friendslist_reqack(f_sd, sd, 0);
  12035. if (battle_config.friend_auto_add) {
  12036. // Also add f_sd to sd's friendlist.
  12037. for (i = 0; i < MAX_FRIENDS; i++) {
  12038. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12039. return; //No need to add anything.
  12040. if (sd->status.friends[i].char_id == 0)
  12041. break;
  12042. }
  12043. if (i == MAX_FRIENDS) {
  12044. clif_friendslist_reqack(sd, f_sd, 2);
  12045. return;
  12046. }
  12047. sd->status.friends[i].account_id = f_sd->status.account_id;
  12048. sd->status.friends[i].char_id = f_sd->status.char_id;
  12049. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12050. clif_friendslist_reqack(sd, f_sd, 0);
  12051. }
  12052. }
  12053. }
  12054. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12055. /// 0203 <account id>.L <char id>.L
  12056. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12057. {
  12058. struct map_session_data *f_sd = NULL;
  12059. uint32 account_id, char_id;
  12060. int i, j;
  12061. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12062. account_id = RFIFOL(fd,info->pos[0]);
  12063. char_id = RFIFOL(fd,info->pos[1]);
  12064. // Search friend
  12065. for (i = 0; i < MAX_FRIENDS &&
  12066. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12067. if (i == MAX_FRIENDS) {
  12068. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12069. return;
  12070. }
  12071. //remove from friend's list first
  12072. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12073. for (i = 0; i < MAX_FRIENDS &&
  12074. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12075. if (i != MAX_FRIENDS) {
  12076. // move all chars up
  12077. for(j = i + 1; j < MAX_FRIENDS; j++)
  12078. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12079. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12080. //should the guy be notified of some message? we should add it here if so
  12081. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12082. WFIFOW(f_sd->fd,0) = 0x20a;
  12083. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12084. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12085. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12086. }
  12087. } else { //friend not online -- ask char server to delete from his friendlist
  12088. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12089. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12090. return;
  12091. }
  12092. }
  12093. // We can now delete from original requester
  12094. for (i = 0; i < MAX_FRIENDS &&
  12095. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12096. // move all chars up
  12097. for(j = i + 1; j < MAX_FRIENDS; j++)
  12098. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12099. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12100. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12101. WFIFOHEAD(fd,packet_len(0x20a));
  12102. WFIFOW(fd,0) = 0x20a;
  12103. WFIFOL(fd,2) = account_id;
  12104. WFIFOL(fd,6) = char_id;
  12105. WFIFOSET(fd, packet_len(0x20a));
  12106. }
  12107. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12108. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12109. void clif_PVPInfo(struct map_session_data* sd)
  12110. {
  12111. int fd = sd->fd;
  12112. WFIFOHEAD(fd,packet_len(0x210));
  12113. WFIFOW(fd,0) = 0x210;
  12114. WFIFOL(fd,2) = sd->status.char_id;
  12115. WFIFOL(fd,6) = sd->status.account_id;
  12116. WFIFOL(fd,10) = sd->pvp_won; // times won
  12117. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12118. WFIFOL(fd,18) = sd->pvp_point;
  12119. WFIFOSET(fd, packet_len(0x210));
  12120. }
  12121. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12122. /// 020f <char id>.L <account id>.L
  12123. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12124. {
  12125. // TODO: Is there a way to use this on an another player (char/acc id)?
  12126. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12127. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12128. clif_PVPInfo(sd);
  12129. }
  12130. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  12131. /// 0219 { <name>.24B }*10 { <point>.L }*10
  12132. void clif_blacksmith(struct map_session_data* sd)
  12133. {
  12134. int i, fd = sd->fd;
  12135. const char* name;
  12136. WFIFOHEAD(fd,packet_len(0x219));
  12137. WFIFOW(fd,0) = 0x219;
  12138. //Packet size limits this list to 10 elements. [Skotlex]
  12139. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  12140. if (smith_fame_list[i].id > 0) {
  12141. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  12142. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  12143. {
  12144. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  12145. } else
  12146. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  12147. } else
  12148. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  12149. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  12150. }
  12151. for(;i < 10; i++) { //In case the MAX is less than 10.
  12152. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  12153. WFIFOL(fd, 242 + i * 4) = 0;
  12154. }
  12155. WFIFOSET(fd, packet_len(0x219));
  12156. }
  12157. /// /blacksmith (CZ_BLACKSMITH_RANK).
  12158. /// 0217
  12159. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  12160. {
  12161. clif_blacksmith(sd);
  12162. }
  12163. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  12164. /// 021b <points>.L <total points>.L
  12165. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  12166. {
  12167. int fd = sd->fd;
  12168. WFIFOHEAD(fd,packet_len(0x21b));
  12169. WFIFOW(fd,0) = 0x21b;
  12170. WFIFOL(fd,2) = points;
  12171. WFIFOL(fd,6) = sd->status.fame;
  12172. WFIFOSET(fd, packet_len(0x21b));
  12173. }
  12174. /// /alchemist list (ZC_ALCHEMIST_RANK).
  12175. /// 021a { <name>.24B }*10 { <point>.L }*10
  12176. void clif_alchemist(struct map_session_data* sd)
  12177. {
  12178. int i, fd = sd->fd;
  12179. const char* name;
  12180. WFIFOHEAD(fd,packet_len(0x21a));
  12181. WFIFOW(fd,0) = 0x21a;
  12182. //Packet size limits this list to 10 elements. [Skotlex]
  12183. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12184. if (chemist_fame_list[i].id > 0) {
  12185. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  12186. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  12187. {
  12188. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12189. } else
  12190. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  12191. } else
  12192. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12193. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  12194. }
  12195. for(;i < 10; i++) { //In case the MAX is less than 10.
  12196. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12197. WFIFOL(fd, 242 + i * 4) = 0;
  12198. }
  12199. WFIFOSET(fd, packet_len(0x21a));
  12200. }
  12201. /// /alchemist (CZ_ALCHEMIST_RANK).
  12202. /// 0218
  12203. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  12204. {
  12205. clif_alchemist(sd);
  12206. }
  12207. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12208. /// 021c <points>.L <total points>.L
  12209. void clif_fame_alchemist(struct map_session_data *sd, int points)
  12210. {
  12211. int fd = sd->fd;
  12212. WFIFOHEAD(fd,packet_len(0x21c));
  12213. WFIFOW(fd,0) = 0x21c;
  12214. WFIFOL(fd,2) = points;
  12215. WFIFOL(fd,6) = sd->status.fame;
  12216. WFIFOSET(fd, packet_len(0x21c));
  12217. }
  12218. /// /taekwon list (ZC_TAEKWON_RANK).
  12219. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12220. void clif_taekwon(struct map_session_data* sd)
  12221. {
  12222. int i, fd = sd->fd;
  12223. const char* name;
  12224. WFIFOHEAD(fd,packet_len(0x226));
  12225. WFIFOW(fd,0) = 0x226;
  12226. //Packet size limits this list to 10 elements. [Skotlex]
  12227. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  12228. if (taekwon_fame_list[i].id > 0) {
  12229. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  12230. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  12231. {
  12232. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  12233. } else
  12234. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  12235. } else
  12236. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  12237. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  12238. }
  12239. for(;i < 10; i++) { //In case the MAX is less than 10.
  12240. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  12241. WFIFOL(fd, 242 + i * 4) = 0;
  12242. }
  12243. WFIFOSET(fd, packet_len(0x226));
  12244. }
  12245. /// /taekwon (CZ_TAEKWON_RANK).
  12246. /// 0225
  12247. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  12248. {
  12249. clif_taekwon(sd);
  12250. }
  12251. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12252. /// 0224 <points>.L <total points>.L
  12253. void clif_fame_taekwon(struct map_session_data *sd, int points)
  12254. {
  12255. int fd = sd->fd;
  12256. WFIFOHEAD(fd,packet_len(0x224));
  12257. WFIFOW(fd,0) = 0x224;
  12258. WFIFOL(fd,2) = points;
  12259. WFIFOL(fd,6) = sd->status.fame;
  12260. WFIFOSET(fd, packet_len(0x224));
  12261. }
  12262. /// /pk list (ZC_KILLER_RANK).
  12263. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12264. void clif_ranking_pk(struct map_session_data* sd)
  12265. {
  12266. int i, fd = sd->fd;
  12267. WFIFOHEAD(fd,packet_len(0x238));
  12268. WFIFOW(fd,0) = 0x238;
  12269. for(i=0;i<10;i++){
  12270. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  12271. WFIFOL(fd,i*4+242) = 0;
  12272. }
  12273. WFIFOSET(fd, packet_len(0x238));
  12274. }
  12275. /// /pk (CZ_KILLER_RANK).
  12276. /// 0237
  12277. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  12278. {
  12279. clif_ranking_pk(sd);
  12280. }
  12281. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12282. /// 0254 <which>.B
  12283. /// which: (unused atm for security purpose)
  12284. /// 0 = sun
  12285. /// 1 = moon
  12286. /// 2 = star
  12287. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12288. {
  12289. int i;
  12290. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12291. if (sd->menuskill_id != SG_FEEL)
  12292. return;
  12293. i = sd->menuskill_val-1;
  12294. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12295. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12296. sd->feel_map[i].m = sd->bl.m;
  12297. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12298. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12299. // clif_misceffect2(&sd->bl, 0x1b0);
  12300. // clif_misceffect2(&sd->bl, 0x21f);
  12301. clif_feel_info(sd, i, 0);
  12302. clif_menuskill_clear(sd);
  12303. }
  12304. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12305. /// 0253 <which>.B
  12306. /// which:
  12307. /// 0 = sun
  12308. /// 1 = moon
  12309. /// 2 = star
  12310. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12311. {
  12312. WFIFOHEAD(fd,packet_len(0x253));
  12313. WFIFOW(fd,0)=0x253;
  12314. WFIFOB(fd,2)=TOB(skill_lv-1);
  12315. WFIFOSET(fd, packet_len(0x253));
  12316. sd->menuskill_id = SG_FEEL;
  12317. sd->menuskill_val = skill_lv;
  12318. }
  12319. /// Request to change homunculus' name (CZ_RENAME_MER).
  12320. /// 0231 <name>.24B
  12321. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12322. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12323. }
  12324. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12325. /// 0234 <id>.L
  12326. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12327. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12328. struct block_list *bl = NULL;
  12329. struct unit_data *ud = NULL;
  12330. if( sd->md && sd->md->bl.id == id )
  12331. bl = &sd->md->bl;
  12332. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12333. bl = &sd->hd->bl; // Moving Homunculus
  12334. else
  12335. return;
  12336. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12337. ud = unit_bl2ud(bl);
  12338. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12339. }
  12340. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12341. /// 0232 <id>.L <position data>.3B
  12342. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12343. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12344. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12345. struct block_list *bl = NULL;
  12346. short x, y;
  12347. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12348. if( sd->md && sd->md->bl.id == id )
  12349. bl = &sd->md->bl; // Moving Mercenary
  12350. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12351. bl = &sd->hd->bl; // Moving Homunculus
  12352. else
  12353. return;
  12354. unit_walktoxy(bl, x, y, 4);
  12355. }
  12356. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12357. /// 0233 <id>.L <target id>.L <action>.B
  12358. /// action:
  12359. /// always 0
  12360. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12361. {
  12362. struct block_list *bl = NULL;
  12363. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12364. int id = RFIFOL(fd,info->pos[0]);
  12365. int target_id = RFIFOL(fd,info->pos[1]);
  12366. int action_type = RFIFOB(fd,info->pos[2]);
  12367. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12368. bl = &sd->hd->bl;
  12369. else if( sd->md && sd->md->bl.id == id )
  12370. bl = &sd->md->bl;
  12371. else return;
  12372. unit_stop_attack(bl);
  12373. unit_attack(bl, target_id, action_type != 0);
  12374. }
  12375. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12376. /// 022d <type>.W <command>.B
  12377. /// type:
  12378. /// always 0
  12379. /// command:
  12380. /// 0 = homunculus information
  12381. /// 1 = feed
  12382. /// 2 = delete
  12383. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12384. { //[orn]
  12385. int cmd = RFIFOW(fd,0);
  12386. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12387. if(!hom_is_active(sd->hd))
  12388. return;
  12389. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12390. }
  12391. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12392. /// 0292
  12393. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12394. {
  12395. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12396. uint8 hp = 100, sp = 100;
  12397. if (item_position < 0) {
  12398. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12399. // HP restored
  12400. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12401. sp = 0;
  12402. }
  12403. else
  12404. return;
  12405. }
  12406. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12407. return;
  12408. if (!status_revive(&sd->bl, hp, sp))
  12409. return;
  12410. if (item_position < 0)
  12411. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12412. else
  12413. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12414. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12415. }
  12416. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12417. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12418. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12419. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12420. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12421. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12422. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12423. void clif_check(int fd, struct map_session_data* pl_sd)
  12424. {
  12425. WFIFOHEAD(fd,packet_len(0x214));
  12426. WFIFOW(fd, 0) = 0x214;
  12427. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12428. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12429. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12430. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12431. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12432. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12433. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12434. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12435. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12436. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12437. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12438. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12439. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12440. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12441. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12442. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12443. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12444. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12445. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12446. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12447. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12448. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12449. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12450. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12451. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12452. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12453. WFIFOSET(fd,packet_len(0x214));
  12454. }
  12455. /// /check (CZ_REQ_STATUS_GM).
  12456. /// Request character's status values.
  12457. /// 0213 <char name>.24B
  12458. void clif_parse_Check(int fd, struct map_session_data *sd)
  12459. {
  12460. char charname[NAME_LENGTH];
  12461. struct map_session_data* pl_sd;
  12462. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12463. return;
  12464. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12465. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12466. {
  12467. return;
  12468. }
  12469. clif_check(fd, pl_sd);
  12470. }
  12471. /// MAIL SYSTEM
  12472. /// By Zephyrus
  12473. ///
  12474. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12475. /// 0255 <index>.W <result>.B
  12476. /// result:
  12477. /// 0 = success
  12478. /// 1 = failure
  12479. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12480. {
  12481. WFIFOHEAD(fd,packet_len(0x255));
  12482. WFIFOW(fd,0) = 0x255;
  12483. WFIFOW(fd,2) = index;
  12484. WFIFOB(fd,4) = flag;
  12485. WFIFOSET(fd,packet_len(0x255));
  12486. }
  12487. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12488. /// 0245 <result>.B
  12489. /// result:
  12490. /// 0 = success
  12491. /// 1 = failure
  12492. /// 2 = too many items
  12493. void clif_Mail_getattachment(int fd, uint8 result)
  12494. {
  12495. WFIFOHEAD(fd,packet_len(0x245));
  12496. WFIFOW(fd,0) = 0x245;
  12497. WFIFOB(fd,2) = result;
  12498. WFIFOSET(fd,packet_len(0x245));
  12499. }
  12500. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12501. /// 0249 <result>.B
  12502. /// result:
  12503. /// 0 = success
  12504. /// 1 = recipinent does not exist
  12505. void clif_Mail_send(int fd, bool fail)
  12506. {
  12507. WFIFOHEAD(fd,packet_len(0x249));
  12508. WFIFOW(fd,0) = 0x249;
  12509. WFIFOB(fd,2) = fail;
  12510. WFIFOSET(fd,packet_len(0x249));
  12511. }
  12512. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12513. /// 0257 <mail id>.L <result>.W
  12514. /// result:
  12515. /// 0 = success
  12516. /// 1 = failure
  12517. void clif_Mail_delete(int fd, int mail_id, short fail)
  12518. {
  12519. WFIFOHEAD(fd, packet_len(0x257));
  12520. WFIFOW(fd,0) = 0x257;
  12521. WFIFOL(fd,2) = mail_id;
  12522. WFIFOW(fd,6) = fail;
  12523. WFIFOSET(fd, packet_len(0x257));
  12524. }
  12525. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12526. /// 0274 <mail id>.L <result>.W
  12527. /// result:
  12528. /// 0 = success
  12529. /// 1 = failure
  12530. void clif_Mail_return(int fd, int mail_id, short fail)
  12531. {
  12532. WFIFOHEAD(fd,packet_len(0x274));
  12533. WFIFOW(fd,0) = 0x274;
  12534. WFIFOL(fd,2) = mail_id;
  12535. WFIFOW(fd,6) = fail;
  12536. WFIFOSET(fd,packet_len(0x274));
  12537. }
  12538. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12539. /// 024a <mail id>.L <title>.40B <sender>.24B
  12540. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12541. {
  12542. WFIFOHEAD(fd,packet_len(0x24a));
  12543. WFIFOW(fd,0) = 0x24a;
  12544. WFIFOL(fd,2) = mail_id;
  12545. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12546. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12547. WFIFOSET(fd,packet_len(0x24a));
  12548. }
  12549. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12550. /// 0260 <type>.L
  12551. /// type:
  12552. /// 0 = open
  12553. /// 1 = close
  12554. void clif_Mail_window(int fd, int flag)
  12555. {
  12556. WFIFOHEAD(fd,packet_len(0x260));
  12557. WFIFOW(fd,0) = 0x260;
  12558. WFIFOL(fd,2) = flag;
  12559. WFIFOSET(fd,packet_len(0x260));
  12560. }
  12561. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12562. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12563. /// read:
  12564. /// 0 = unread
  12565. /// 1 = read
  12566. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12567. {
  12568. int fd = sd->fd;
  12569. struct mail_data *md = &sd->mail.inbox;
  12570. struct mail_message *msg;
  12571. int len, i, j;
  12572. len = 8 + (73 * md->amount);
  12573. WFIFOHEAD(fd,len);
  12574. WFIFOW(fd,0) = 0x240;
  12575. WFIFOW(fd,2) = len;
  12576. WFIFOL(fd,4) = md->amount;
  12577. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12578. {
  12579. msg = &md->msg[i];
  12580. if (msg->id < 1)
  12581. continue;
  12582. WFIFOL(fd,8+73*j) = msg->id;
  12583. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12584. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12585. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12586. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12587. j++;
  12588. }
  12589. WFIFOSET(fd,len);
  12590. if( md->full ) {// TODO: is this official?
  12591. char output[100];
  12592. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12593. clif_disp_onlyself(sd, output, strlen(output));
  12594. }
  12595. }
  12596. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12597. /// 023f
  12598. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12599. {
  12600. struct mail_data* md = &sd->mail.inbox;
  12601. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12602. intif_Mail_requestinbox(sd->status.char_id, 1);
  12603. else
  12604. clif_Mail_refreshinbox(sd);
  12605. mail_removeitem(sd, 0);
  12606. mail_removezeny(sd, 0);
  12607. }
  12608. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12609. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12610. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12611. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12612. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12613. {
  12614. int i, fd = sd->fd;
  12615. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12616. if( i == MAIL_MAX_INBOX ) {
  12617. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12618. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12619. return;
  12620. } else {
  12621. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12622. struct item *item = &msg->item;
  12623. struct item_data *data;
  12624. int msg_len = strlen(msg->body), len;
  12625. if( msg_len == 0 ) {
  12626. strcpy(msg->body, "(no message)");
  12627. msg_len = strlen(msg->body);
  12628. }
  12629. len = 101 + msg_len;
  12630. WFIFOHEAD(fd,len);
  12631. WFIFOW(fd,0) = 0x242;
  12632. WFIFOW(fd,2) = len;
  12633. WFIFOL(fd,4) = msg->id;
  12634. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12635. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12636. WFIFOL(fd,72) = 0;
  12637. WFIFOL(fd,76) = msg->zeny;
  12638. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12639. WFIFOL(fd,80) = item->amount;
  12640. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12641. WFIFOW(fd,86) = data->type;
  12642. WFIFOB(fd,88) = item->identify;
  12643. WFIFOB(fd,89) = item->attribute;
  12644. WFIFOB(fd,90) = item->refine;
  12645. WFIFOW(fd,91) = item->card[0];
  12646. WFIFOW(fd,93) = item->card[1];
  12647. WFIFOW(fd,95) = item->card[2];
  12648. WFIFOW(fd,97) = item->card[3];
  12649. } else // no item, set all to zero
  12650. memset(WFIFOP(fd,80), 0x00, 19);
  12651. WFIFOB(fd,99) = (unsigned char)msg_len;
  12652. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12653. WFIFOSET(fd,len);
  12654. if (msg->status == MAIL_UNREAD) {
  12655. msg->status = MAIL_READ;
  12656. intif_Mail_read(mail_id);
  12657. clif_parse_Mail_refreshinbox(fd, sd);
  12658. }
  12659. }
  12660. }
  12661. /// Request to open a mail (CZ_MAIL_OPEN).
  12662. /// 0241 <mail id>.L
  12663. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12664. {
  12665. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12666. if( mail_id <= 0 )
  12667. return;
  12668. if( mail_invalid_operation(sd) )
  12669. return;
  12670. clif_Mail_read(sd, mail_id);
  12671. }
  12672. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12673. /// 0244 <mail id>.L
  12674. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12675. {
  12676. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12677. int i;
  12678. bool fail = false;
  12679. if( !chrif_isconnected() )
  12680. return;
  12681. if( mail_id <= 0 )
  12682. return;
  12683. if( mail_invalid_operation(sd) )
  12684. return;
  12685. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12686. if( i == MAIL_MAX_INBOX )
  12687. return;
  12688. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12689. return;
  12690. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12691. clif_Mail_getattachment(fd, 1); //too many zeny
  12692. return;
  12693. }
  12694. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12695. struct item_data *data;
  12696. unsigned int weight;
  12697. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12698. return;
  12699. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12700. case CHKADDITEM_NEW:
  12701. fail = ( pc_inventoryblank(sd) == 0 );
  12702. break;
  12703. case CHKADDITEM_OVERAMOUNT:
  12704. fail = true;
  12705. }
  12706. if( fail ) {
  12707. clif_Mail_getattachment(fd, 1);
  12708. return;
  12709. }
  12710. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12711. if( sd->weight + weight > sd->max_weight ) {
  12712. clif_Mail_getattachment(fd, 2);
  12713. return;
  12714. }
  12715. }
  12716. sd->mail.inbox.msg[i].zeny = 0;
  12717. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12718. clif_Mail_read(sd, mail_id);
  12719. intif_Mail_getattach(sd->status.char_id, mail_id);
  12720. }
  12721. /// Request to delete a mail (CZ_MAIL_DELETE).
  12722. /// 0243 <mail id>.L
  12723. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12724. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12725. int i;
  12726. if( !chrif_isconnected() )
  12727. return;
  12728. if( mail_id <= 0 )
  12729. return;
  12730. if( mail_invalid_operation(sd) )
  12731. return;
  12732. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12733. if (i < MAIL_MAX_INBOX) {
  12734. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12735. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12736. clif_Mail_delete(sd->fd, mail_id, 1);
  12737. return;
  12738. }
  12739. intif_Mail_delete(sd->status.char_id, mail_id);
  12740. }
  12741. }
  12742. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12743. /// 0273 <mail id>.L <receive name>.24B
  12744. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12745. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12746. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12747. int i;
  12748. if( mail_id <= 0 )
  12749. return;
  12750. if( mail_invalid_operation(sd) )
  12751. return;
  12752. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12753. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12754. intif_Mail_return(sd->status.char_id, mail_id);
  12755. else
  12756. clif_Mail_return(sd->fd, mail_id, 1);
  12757. }
  12758. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12759. /// 0247 <index>.W <amount>.L
  12760. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12761. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12762. int idx = RFIFOW(fd,info->pos[0]);
  12763. int amount = RFIFOL(fd,info->pos[1]);
  12764. unsigned char flag;
  12765. if( !chrif_isconnected() )
  12766. return;
  12767. if (idx < 0 || amount < 0)
  12768. return;
  12769. flag = mail_setitem(sd, idx, amount);
  12770. clif_Mail_setattachment(fd,idx,!flag);
  12771. }
  12772. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12773. /// 0246 <type>.W
  12774. /// type:
  12775. /// 0 = reset all
  12776. /// 1 = remove item
  12777. /// 2 = remove zeny
  12778. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12779. {
  12780. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12781. if (type == 0 || type == 1)
  12782. mail_removeitem(sd, 0);
  12783. if (type == 0 || type == 2)
  12784. mail_removezeny(sd, 0);
  12785. }
  12786. /// Request to send mail (CZ_MAIL_SEND).
  12787. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12788. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12789. {
  12790. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12791. if( !chrif_isconnected() )
  12792. return;
  12793. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12794. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12795. return;
  12796. }
  12797. 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]));
  12798. }
  12799. /// AUCTION SYSTEM
  12800. /// By Zephyrus
  12801. ///
  12802. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12803. /// 025f <type>.L
  12804. /// type:
  12805. /// 0 = open
  12806. /// 1 = close
  12807. void clif_Auction_openwindow(struct map_session_data *sd)
  12808. {
  12809. int fd = sd->fd;
  12810. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12811. return;
  12812. if( !battle_config.feature_auction )
  12813. return;
  12814. WFIFOHEAD(fd,packet_len(0x25f));
  12815. WFIFOW(fd,0) = 0x25f;
  12816. WFIFOL(fd,2) = 0;
  12817. WFIFOSET(fd,packet_len(0x25f));
  12818. }
  12819. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12820. /// 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 }*
  12821. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12822. {
  12823. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12824. struct auction_data auction;
  12825. struct item_data *item;
  12826. WFIFOHEAD(fd,12 + (count * 83));
  12827. WFIFOW(fd,0) = 0x252;
  12828. WFIFOW(fd,2) = 12 + (count * 83);
  12829. WFIFOL(fd,4) = pages;
  12830. WFIFOL(fd,8) = count;
  12831. for( i = 0; i < count; i++ ) {
  12832. int k = 12 + (i * 83);
  12833. memcpy(&auction, RBUFP(buf,i * len), len);
  12834. WFIFOL(fd,k) = auction.auction_id;
  12835. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12836. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12837. WFIFOW(fd,28+k) = item->view_id;
  12838. else
  12839. WFIFOW(fd,28+k) = auction.item.nameid;
  12840. WFIFOL(fd,30+k) = auction.type;
  12841. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12842. WFIFOB(fd,36+k) = auction.item.identify;
  12843. WFIFOB(fd,37+k) = auction.item.attribute;
  12844. WFIFOB(fd,38+k) = auction.item.refine;
  12845. WFIFOW(fd,39+k) = auction.item.card[0];
  12846. WFIFOW(fd,41+k) = auction.item.card[1];
  12847. WFIFOW(fd,43+k) = auction.item.card[2];
  12848. WFIFOW(fd,45+k) = auction.item.card[3];
  12849. WFIFOL(fd,47+k) = auction.price;
  12850. WFIFOL(fd,51+k) = auction.buynow;
  12851. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12852. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12853. }
  12854. WFIFOSET(fd,WFIFOW(fd,2));
  12855. }
  12856. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12857. /// 0256 <index>.W <result>.B
  12858. /// result:
  12859. /// 0 = success
  12860. /// 1 = failure
  12861. static void clif_Auction_setitem(int fd, int index, bool fail)
  12862. {
  12863. WFIFOHEAD(fd,packet_len(0x256));
  12864. WFIFOW(fd,0) = 0x256;
  12865. WFIFOW(fd,2) = index;
  12866. WFIFOB(fd,4) = fail;
  12867. WFIFOSET(fd,packet_len(0x256));
  12868. }
  12869. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12870. /// 024b <type>.W
  12871. /// type:
  12872. /// 0 = create (any other action in auction window)
  12873. /// 1 = cancel (cancel pressed on register tab)
  12874. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12875. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12876. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12877. if( sd->auction.amount > 0 )
  12878. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12879. sd->auction.amount = 0;
  12880. }
  12881. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12882. /// 024c <index>.W <count>.L
  12883. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12884. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12885. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12886. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12887. struct item_data *item;
  12888. if( !battle_config.feature_auction )
  12889. return;
  12890. if( sd->auction.amount > 0 )
  12891. sd->auction.amount = 0;
  12892. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12893. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12894. return;
  12895. }
  12896. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12897. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12898. return;
  12899. }
  12900. 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) )
  12901. { // Consumable or pets are not allowed
  12902. clif_Auction_setitem(sd->fd, idx, true);
  12903. return;
  12904. }
  12905. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12906. !sd->status.inventory[idx].identify ||
  12907. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12908. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12909. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12910. ) {
  12911. clif_Auction_setitem(sd->fd, idx, true);
  12912. return;
  12913. }
  12914. sd->auction.index = idx;
  12915. sd->auction.amount = amount;
  12916. clif_Auction_setitem(fd, idx + 2, false);
  12917. }
  12918. /// Result from an auction action (ZC_AUCTION_RESULT).
  12919. /// 0250 <result>.B
  12920. /// result:
  12921. /// 0 = You have failed to bid into the auction
  12922. /// 1 = You have successfully bid in the auction
  12923. /// 2 = The auction has been canceled
  12924. /// 3 = An auction with at least one bidder cannot be canceled
  12925. /// 4 = You cannot register more than 5 items in an auction at a time
  12926. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12927. /// 6 = You have won the auction
  12928. /// 7 = You have failed to win the auction
  12929. /// 8 = You do not have enough Zeny
  12930. /// 9 = You cannot place more than 5 bids at a time
  12931. void clif_Auction_message(int fd, unsigned char flag)
  12932. {
  12933. WFIFOHEAD(fd,packet_len(0x250));
  12934. WFIFOW(fd,0) = 0x250;
  12935. WFIFOB(fd,2) = flag;
  12936. WFIFOSET(fd,packet_len(0x250));
  12937. }
  12938. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12939. /// 025e <result>.W
  12940. /// result:
  12941. /// 0 = You have ended the auction
  12942. /// 1 = You cannot end the auction
  12943. /// 2 = Auction ID is incorrect
  12944. void clif_Auction_close(int fd, unsigned char flag)
  12945. {
  12946. WFIFOHEAD(fd,packet_len(0x25e));
  12947. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12948. WFIFOW(fd,2) = flag;
  12949. WFIFOSET(fd,packet_len(0x25e));
  12950. }
  12951. /// Request to add an auction (CZ_AUCTION_ADD).
  12952. /// 024d <now money>.L <max money>.L <delete hour>.W
  12953. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12954. {
  12955. struct auction_data auction;
  12956. struct item_data *item;
  12957. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12958. if( !battle_config.feature_auction )
  12959. return;
  12960. auction.price = RFIFOL(fd,info->pos[0]);
  12961. auction.buynow = RFIFOL(fd,info->pos[1]);
  12962. auction.hours = RFIFOW(fd,info->pos[2]);
  12963. // Invalid Situations...
  12964. if( sd->auction.amount < 1 ) {
  12965. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12966. return;
  12967. }
  12968. if( auction.price >= auction.buynow ) {
  12969. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12970. return;
  12971. }
  12972. if( auction.hours < 1 || auction.hours > 48 ) {
  12973. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12974. return;
  12975. }
  12976. // Auction checks...
  12977. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12978. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12979. clif_Auction_message(fd, 2); // The auction has been canceled
  12980. return;
  12981. }
  12982. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12983. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12984. return;
  12985. }
  12986. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12987. auction.buynow = battle_config.auction_maximumprice;
  12988. if( auction.price >= auction.buynow )
  12989. auction.price = auction.buynow - 1;
  12990. }
  12991. auction.auction_id = 0;
  12992. auction.seller_id = sd->status.char_id;
  12993. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12994. auction.buyer_id = 0;
  12995. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12996. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12997. {
  12998. clif_Auction_message(fd, 2); // The auction has been canceled
  12999. return;
  13000. }
  13001. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  13002. { // Just in case
  13003. clif_Auction_message(fd, 2); // The auction has been canceled
  13004. return;
  13005. }
  13006. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13007. auction.type = item->type;
  13008. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  13009. auction.item.amount = 1;
  13010. auction.timestamp = 0;
  13011. if( !intif_Auction_register(&auction) )
  13012. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13013. else
  13014. {
  13015. int zeny = auction.hours*battle_config.auction_feeperhour;
  13016. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13017. sd->auction.amount = 0;
  13018. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13019. }
  13020. }
  13021. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13022. /// 024e <auction id>.L
  13023. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13024. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13025. intif_Auction_cancel(sd->status.char_id, auction_id);
  13026. }
  13027. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13028. /// 025d <auction id>.L
  13029. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13030. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13031. intif_Auction_close(sd->status.char_id, auction_id);
  13032. }
  13033. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13034. /// 024f <auction id>.L <money>.L
  13035. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13036. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13037. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13038. int bid = RFIFOL(fd,info->pos[1]);
  13039. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13040. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13041. return;
  13042. }
  13043. if( bid <= 0 )
  13044. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13045. else if( bid > sd->status.zeny )
  13046. clif_Auction_message(fd, 8); // You do not have enough zeny
  13047. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13048. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13049. else {
  13050. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13051. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13052. }
  13053. }
  13054. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13055. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13056. /// search type:
  13057. /// 0 = armor
  13058. /// 1 = weapon
  13059. /// 2 = card
  13060. /// 3 = misc
  13061. /// 4 = name search
  13062. /// 5 = auction id search
  13063. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13064. char search_text[NAME_LENGTH];
  13065. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13066. short type = RFIFOW(fd,info->pos[0]);
  13067. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13068. int page = RFIFOW(fd,info->pos[3]);
  13069. if( !battle_config.feature_auction )
  13070. return;
  13071. clif_parse_Auction_cancelreg(fd, sd);
  13072. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  13073. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13074. }
  13075. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13076. /// 025c <type>.W
  13077. /// type:
  13078. /// 0 = sell (own auctions)
  13079. /// 1 = buy (own bids)
  13080. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13081. {
  13082. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  13083. if( !battle_config.feature_auction )
  13084. return;
  13085. clif_parse_Auction_cancelreg(fd, sd);
  13086. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13087. }
  13088. /// CASH/POINT SHOP
  13089. ///
  13090. void clif_cashshop_open( struct map_session_data* sd ){
  13091. WFIFOHEAD( sd->fd, 10 );
  13092. WFIFOW( sd->fd, 0 ) = 0x845;
  13093. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13094. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13095. WFIFOSET( sd->fd, 10 );
  13096. }
  13097. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13098. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13099. clif_cashshop_open( sd );
  13100. }
  13101. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13102. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13103. // No need to do anything here
  13104. }
  13105. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13106. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13107. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13108. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13109. int j;
  13110. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  13111. return;
  13112. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13113. WFIFOW(fd, 0) = 0x8c0;
  13114. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13115. WFIFOL(fd, 4) = tab;
  13116. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13117. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13118. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13119. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13120. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13121. }
  13122. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13123. }
  13124. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13125. void clif_cashshop_list( int fd ){
  13126. int tab;
  13127. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13128. int length = 8 + cash_shop_items[tab].count * 6;
  13129. int i, offset;
  13130. WFIFOHEAD( fd, length );
  13131. WFIFOW( fd, 0 ) = 0x8ca;
  13132. WFIFOW( fd, 2 ) = length;
  13133. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13134. WFIFOW( fd, 6 ) = tab;
  13135. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13136. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13137. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13138. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13139. }
  13140. WFIFOSET( fd, length );
  13141. }
  13142. }
  13143. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13144. if( !sd->status.cashshop_sent ) {
  13145. clif_cashshop_list( fd );
  13146. sd->status.cashshop_sent = true;
  13147. }
  13148. }
  13149. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13150. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13151. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13152. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13153. {
  13154. int fd,i;
  13155. #if PACKETVER < 20070711
  13156. const int offset = 8;
  13157. #else
  13158. const int offset = 12;
  13159. #endif
  13160. nullpo_retv(sd);
  13161. nullpo_retv(nd);
  13162. fd = sd->fd;
  13163. sd->npc_shopid = nd->bl.id;
  13164. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13165. WFIFOW(fd,0) = 0x287;
  13166. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13167. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  13168. #if PACKETVER >= 20070711
  13169. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  13170. #endif
  13171. for( i = 0; i < nd->u.shop.count; i++ ) {
  13172. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13173. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13174. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13175. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13176. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13177. }
  13178. WFIFOSET(fd,WFIFOW(fd,2));
  13179. }
  13180. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13181. /// 0289 <cash point>.L <error>.W
  13182. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13183. /// error:
  13184. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13185. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13186. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13187. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13188. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13189. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13190. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13191. /// 7 = You can purchase up to 10 items.
  13192. /// 8 = Some items could not be purchased.
  13193. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13194. {
  13195. int fd = sd->fd;
  13196. WFIFOHEAD(fd, packet_len(0x289));
  13197. WFIFOW(fd,0) = 0x289;
  13198. WFIFOL(fd,2) = sd->cashPoints;
  13199. #if PACKETVER < 20070711
  13200. WFIFOW(fd,6) = TOW(error);
  13201. #else
  13202. WFIFOL(fd,6) = sd->kafraPoints;
  13203. WFIFOW(fd,10) = TOW(error);
  13204. #endif
  13205. WFIFOSET(fd, packet_len(0x289));
  13206. }
  13207. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13208. WFIFOHEAD( sd->fd, 16 );
  13209. WFIFOW( sd->fd, 0 ) = 0x849;
  13210. WFIFOL( sd->fd, 2 ) = item_id;
  13211. WFIFOW( sd->fd, 6 ) = result;
  13212. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13213. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13214. WFIFOSET( sd->fd, 16 );
  13215. }
  13216. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13217. /// 0288 <name id>.W <amount>.W
  13218. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13219. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13220. /// 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)
  13221. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  13222. struct s_packet_db* info;
  13223. int cmd = RFIFOW(fd,0);
  13224. nullpo_retv(sd);
  13225. info = &packet_db[sd->packet_ver][cmd];
  13226. if( sd->state.trading || !sd->npc_shopid || !cash_shop_defined) {
  13227. clif_cashshop_ack(sd,1);
  13228. return;
  13229. } else {
  13230. #if PACKETVER < 20101116
  13231. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  13232. short amount = RFIFOW(fd,info->pos[1]);
  13233. int points = RFIFOL(fd,info->pos[2]);
  13234. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13235. #else
  13236. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13237. int len = RFIFOW(fd,info->pos[0]);
  13238. int points = RFIFOL(fd,info->pos[1]);
  13239. int count = RFIFOW(fd,info->pos[2]);
  13240. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13241. if( len < 10 || len != 10 + count * s_itl) {
  13242. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13243. return;
  13244. }
  13245. if(cmd == 0x848) {
  13246. if (cashshop_buylist( sd, points, count, item_list))
  13247. clif_cashshop_ack(sd,0);
  13248. return;
  13249. } else {
  13250. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13251. return;
  13252. }
  13253. #endif
  13254. }
  13255. }
  13256. /// Adoption System
  13257. ///
  13258. /// Adoption message (ZC_BABYMSG).
  13259. /// 0216 <msg>.L
  13260. /// msg:
  13261. /// 0 = "You cannot adopt more than 1 child."
  13262. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13263. /// 2 = "You cannot adopt a married person."
  13264. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13265. {
  13266. int fd = sd->fd;
  13267. WFIFOHEAD(fd,6);
  13268. WFIFOW(fd,0) = 0x216;
  13269. WFIFOL(fd,2) = type;
  13270. WFIFOSET(fd,6);
  13271. }
  13272. /// Adoption confirmation (ZC_REQ_BABY).
  13273. /// 01f6 <account id>.L <char id>.L <name>.B
  13274. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13275. {
  13276. int fd = sd->fd;
  13277. WFIFOHEAD(fd,34);
  13278. WFIFOW(fd,0) = 0x1f6;
  13279. WFIFOL(fd,2) = src->status.account_id;
  13280. WFIFOL(fd,6) = p_id;
  13281. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13282. WFIFOSET(fd,34);
  13283. }
  13284. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13285. /// 01f9 <account id>.L
  13286. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13287. {
  13288. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13289. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13290. if( pc_can_Adopt(sd, p_sd, tsd) )
  13291. {
  13292. tsd->adopt_invite = sd->status.account_id;
  13293. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13294. }
  13295. }
  13296. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13297. /// 01f7 <account id>.L <char id>.L <answer>.L
  13298. /// answer:
  13299. /// 0 = rejected
  13300. /// 1 = accepted
  13301. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13302. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13303. int p1_id = RFIFOL(fd,info->pos[0]);
  13304. int p2_id = RFIFOL(fd,info->pos[1]);
  13305. int result = RFIFOL(fd,info->pos[2]);
  13306. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13307. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13308. int pid = sd->adopt_invite;
  13309. sd->adopt_invite = 0;
  13310. if( p1_sd == NULL || p2_sd == NULL )
  13311. return; // Both players need to be online
  13312. if( pid != p1_sd->status.account_id )
  13313. return; // Incorrect values
  13314. if( result == 0 )
  13315. return; // Rejected
  13316. pc_adoption(p1_sd, p2_sd, sd);
  13317. }
  13318. /// Convex Mirror (ZC_BOSS_INFO).
  13319. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13320. /// infoType:
  13321. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13322. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13323. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13324. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13325. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13326. {
  13327. WFIFOHEAD(fd,70);
  13328. memset(WFIFOP(fd,0),0,70);
  13329. WFIFOW(fd,0) = 0x293;
  13330. if( md != NULL ) {
  13331. if( md->bl.prev != NULL ) { // Boss on This Map
  13332. if( flag ) {
  13333. WFIFOB(fd,2) = 1;
  13334. WFIFOL(fd,3) = md->bl.x;
  13335. WFIFOL(fd,7) = md->bl.y;
  13336. } else
  13337. WFIFOB(fd,2) = 2; // First Time
  13338. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13339. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13340. unsigned int seconds;
  13341. int hours, minutes;
  13342. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13343. hours = seconds / (60 * 60);
  13344. seconds = seconds - (60 * 60 * hours);
  13345. minutes = seconds / 60;
  13346. WFIFOB(fd,2) = 3;
  13347. WFIFOW(fd,11) = hours; // Hours
  13348. WFIFOW(fd,13) = minutes; // Minutes
  13349. }
  13350. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13351. }
  13352. WFIFOSET(fd,70);
  13353. }
  13354. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13355. /// 02d6 <account id>.L
  13356. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13357. {
  13358. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13359. struct map_session_data* tsd = map_id2sd(aid);
  13360. if (!tsd)
  13361. return;
  13362. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13363. clif_viewequip_ack(sd, tsd);
  13364. else
  13365. clif_msg(sd, VIEW_EQUIP_FAIL);
  13366. }
  13367. /// Request to change equip window tick (CZ_CONFIG).
  13368. /// 02d8 <type>.L <flag>.L
  13369. /// type:
  13370. /// 0 = open equip window
  13371. /// flag:
  13372. /// 0 = disabled
  13373. /// 1 = enabled
  13374. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13375. {
  13376. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13377. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13378. sd->status.show_equip = flag;
  13379. clif_equiptickack(sd, flag);
  13380. }
  13381. /// Request to change party invitation tick.
  13382. /// value:
  13383. /// 0 = disabled
  13384. /// 1 = enabled
  13385. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13386. {
  13387. bool flag = RFIFOB(fd,6) ? true : false;
  13388. sd->status.allow_party = flag;
  13389. clif_partytickack(sd, flag);
  13390. }
  13391. /// Questlog System [Kevin] [Inkfish]
  13392. ///
  13393. /**
  13394. * Safe check to init packet len & quest num for player.
  13395. * @param def_len
  13396. * @param info_len Length of each quest info.
  13397. * @param avail_quests Avail quests that player has.
  13398. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13399. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13400. **/
  13401. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13402. (*limit_out) = (0xFFFF - def_len) / info_len;
  13403. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13404. (*len_out) = ((*limit_out) * info_len) + def_len;
  13405. }
  13406. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13407. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13408. /// 097a <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST2)
  13409. /// 09f8 <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST3) // TODO!
  13410. void clif_quest_send_list(struct map_session_data *sd)
  13411. {
  13412. int fd = sd->fd;
  13413. int i;
  13414. int offset = 8;
  13415. int limit = 0;
  13416. #if PACKETVER >= 20141022
  13417. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13418. WFIFOHEAD(fd,i);
  13419. WFIFOW(fd, 0) = 0x97a;
  13420. WFIFOL(fd, 4) = limit;
  13421. for (i = 0; i < limit; i++) {
  13422. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13423. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13424. offset += 4;
  13425. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13426. offset++;
  13427. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13428. offset += 4;
  13429. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13430. offset += 4;
  13431. WFIFOW(fd, offset) = qi->objectives_count;
  13432. offset += 2;
  13433. if( qi->objectives_count > 0 ){
  13434. int j;
  13435. struct mob_db *mob;
  13436. for( j = 0; j < qi->objectives_count; j++ ){
  13437. mob = mob_db(qi->objectives[j].mob);
  13438. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13439. offset += 4;
  13440. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13441. offset += 2;
  13442. WFIFOW(fd, offset) = qi->objectives[j].count;
  13443. offset += 2;
  13444. memcpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13445. offset += NAME_LENGTH;
  13446. }
  13447. }
  13448. }
  13449. WFIFOW(fd, 2) = offset;
  13450. WFIFOSET(fd, offset);
  13451. #else
  13452. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13453. WFIFOHEAD(fd,i);
  13454. WFIFOW(fd, 0) = 0x2b1;
  13455. WFIFOL(fd, 4) = limit;
  13456. for (i = 0; i < limit; i++) {
  13457. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13458. offset += 4;
  13459. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13460. offset += 1;
  13461. }
  13462. WFIFOW(fd, 2) = offset;
  13463. WFIFOSET(fd, offset);
  13464. #endif
  13465. }
  13466. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13467. /// 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
  13468. void clif_quest_send_mission(struct map_session_data *sd)
  13469. {
  13470. int fd = sd->fd;
  13471. int i, j, limit = 0;
  13472. int len = sd->avail_quests*104+8;
  13473. struct mob_db *mob;
  13474. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13475. WFIFOHEAD(fd, len);
  13476. WFIFOW(fd, 0) = 0x2b2;
  13477. WFIFOW(fd, 2) = len;
  13478. WFIFOL(fd, 4) = limit;
  13479. for (i = 0; i < limit; i++) {
  13480. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13481. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13482. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13483. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13484. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13485. for (j = 0 ; j < qi->objectives_count; j++) {
  13486. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13487. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13488. mob = mob_db(qi->objectives[j].mob);
  13489. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13490. }
  13491. }
  13492. WFIFOSET(fd, len);
  13493. }
  13494. /// Notification about a new quest (ZC_ADD_QUEST).
  13495. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13496. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13497. {
  13498. int fd = sd->fd;
  13499. int i;
  13500. struct quest_db *qi = quest_search(qd->quest_id);
  13501. WFIFOHEAD(fd, packet_len(0x2b3));
  13502. WFIFOW(fd, 0) = 0x2b3;
  13503. WFIFOL(fd, 2) = qd->quest_id;
  13504. WFIFOB(fd, 6) = qd->state;
  13505. WFIFOB(fd, 7) = qd->time - qi->time;
  13506. WFIFOL(fd, 11) = qd->time;
  13507. WFIFOW(fd, 15) = qi->objectives_count;
  13508. for (i = 0; i < qi->objectives_count; i++) {
  13509. struct mob_db *mob;
  13510. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13511. WFIFOW(fd, i*30+21) = qd->count[i];
  13512. mob = mob_db(qi->objectives[i].mob);
  13513. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13514. }
  13515. WFIFOSET(fd, packet_len(0x2b3));
  13516. }
  13517. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13518. /// 02b4 <quest id>.L
  13519. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13520. {
  13521. int fd = sd->fd;
  13522. WFIFOHEAD(fd, packet_len(0x2b4));
  13523. WFIFOW(fd, 0) = 0x2b4;
  13524. WFIFOL(fd, 2) = quest_id;
  13525. WFIFOSET(fd, packet_len(0x2b4));
  13526. }
  13527. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13528. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13529. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  13530. {
  13531. int fd = sd->fd;
  13532. int i;
  13533. struct quest_db *qi = quest_search(qd->quest_id);
  13534. int len = qi->objectives_count * 12 + 6;
  13535. WFIFOHEAD(fd, len);
  13536. WFIFOW(fd, 0) = 0x2b5;
  13537. WFIFOW(fd, 2) = len;
  13538. WFIFOW(fd, 4) = qi->objectives_count;
  13539. for (i = 0; i < qi->objectives_count; i++) {
  13540. WFIFOL(fd, i*12+6) = qd->quest_id;
  13541. WFIFOL(fd, i*12+10) = qi->objectives[i].mob;
  13542. WFIFOW(fd, i*12+14) = qi->objectives[i].count;
  13543. WFIFOW(fd, i*12+16) = qd->count[i];
  13544. }
  13545. WFIFOSET(fd, len);
  13546. }
  13547. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13548. /// 02b6 <quest id>.L <active>.B
  13549. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13550. {
  13551. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13552. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13553. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13554. }
  13555. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13556. /// 02b7 <quest id>.L <active>.B
  13557. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13558. {
  13559. int fd = sd->fd;
  13560. WFIFOHEAD(fd, packet_len(0x2b7));
  13561. WFIFOW(fd, 0) = 0x2b7;
  13562. WFIFOL(fd, 2) = quest_id;
  13563. WFIFOB(fd, 6) = active;
  13564. WFIFOSET(fd, packet_len(0x2b7));
  13565. }
  13566. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13567. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13568. /// effect:
  13569. /// 0 = none
  13570. /// 1 = exclamation mark icon
  13571. /// 2 = question mark icon
  13572. /// type:
  13573. /// 0 = yellow
  13574. /// 1 = orange
  13575. /// 2 = green
  13576. /// 3 = purple
  13577. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13578. {
  13579. #if PACKETVER >= 20090218
  13580. int fd = sd->fd;
  13581. WFIFOHEAD(fd, packet_len(0x446));
  13582. WFIFOW(fd, 0) = 0x446;
  13583. WFIFOL(fd, 2) = bl->id;
  13584. WFIFOW(fd, 6) = bl->x;
  13585. WFIFOW(fd, 8) = bl->y;
  13586. WFIFOW(fd, 10) = state;
  13587. WFIFOW(fd, 12) = color;
  13588. WFIFOSET(fd, packet_len(0x446));
  13589. #endif
  13590. }
  13591. /// Mercenary System
  13592. ///
  13593. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13594. /// 02a2 <var id>.W <value>.L
  13595. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13596. {
  13597. struct mercenary_data *md;
  13598. struct status_data *status;
  13599. int fd;
  13600. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13601. return;
  13602. fd = sd->fd;
  13603. status = &md->battle_status;
  13604. WFIFOHEAD(fd,packet_len(0x2a2));
  13605. WFIFOW(fd,0) = 0x2a2;
  13606. WFIFOW(fd,2) = type;
  13607. switch( type ) {
  13608. case SP_ATK1:
  13609. {
  13610. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13611. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13612. }
  13613. break;
  13614. case SP_MATK1:
  13615. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13616. break;
  13617. case SP_HIT:
  13618. WFIFOL(fd,4) = status->hit;
  13619. break;
  13620. case SP_CRITICAL:
  13621. WFIFOL(fd,4) = status->cri/10;
  13622. break;
  13623. case SP_DEF1:
  13624. WFIFOL(fd,4) = status->def;
  13625. break;
  13626. case SP_MDEF1:
  13627. WFIFOL(fd,4) = status->mdef;
  13628. break;
  13629. case SP_MERCFLEE:
  13630. WFIFOL(fd,4) = status->flee;
  13631. break;
  13632. case SP_ASPD:
  13633. WFIFOL(fd,4) = status->amotion;
  13634. break;
  13635. case SP_HP:
  13636. WFIFOL(fd,4) = status->hp;
  13637. break;
  13638. case SP_MAXHP:
  13639. WFIFOL(fd,4) = status->max_hp;
  13640. break;
  13641. case SP_SP:
  13642. WFIFOL(fd,4) = status->sp;
  13643. break;
  13644. case SP_MAXSP:
  13645. WFIFOL(fd,4) = status->max_sp;
  13646. break;
  13647. case SP_MERCKILLS:
  13648. WFIFOL(fd,4) = md->mercenary.kill_count;
  13649. break;
  13650. case SP_MERCFAITH:
  13651. WFIFOL(fd,4) = mercenary_get_faith(md);
  13652. break;
  13653. }
  13654. WFIFOSET(fd,packet_len(0x2a2));
  13655. }
  13656. /// Mercenary base status data (ZC_MER_INIT).
  13657. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13658. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13659. /// <calls>.L <kills>.L <atk range>.W
  13660. void clif_mercenary_info(struct map_session_data *sd)
  13661. {
  13662. int fd;
  13663. struct mercenary_data *md;
  13664. struct status_data *status;
  13665. int atk;
  13666. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13667. return;
  13668. fd = sd->fd;
  13669. status = &md->battle_status;
  13670. WFIFOHEAD(fd,packet_len(0x29b));
  13671. WFIFOW(fd,0) = 0x29b;
  13672. WFIFOL(fd,2) = md->bl.id;
  13673. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13674. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13675. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13676. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13677. WFIFOW(fd,10) = status->hit;
  13678. WFIFOW(fd,12) = status->cri/10;
  13679. WFIFOW(fd,14) = status->def;
  13680. WFIFOW(fd,16) = status->mdef;
  13681. WFIFOW(fd,18) = status->flee;
  13682. WFIFOW(fd,20) = status->amotion;
  13683. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13684. WFIFOW(fd,46) = md->db->lv;
  13685. WFIFOL(fd,48) = status->hp;
  13686. WFIFOL(fd,52) = status->max_hp;
  13687. WFIFOL(fd,56) = status->sp;
  13688. WFIFOL(fd,60) = status->max_sp;
  13689. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13690. WFIFOW(fd,68) = mercenary_get_faith(md);
  13691. WFIFOL(fd,70) = mercenary_get_calls(md);
  13692. WFIFOL(fd,74) = md->mercenary.kill_count;
  13693. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13694. WFIFOSET(fd,packet_len(0x29b));
  13695. }
  13696. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13697. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13698. void clif_mercenary_skillblock(struct map_session_data *sd)
  13699. {
  13700. struct mercenary_data *md;
  13701. int fd, i, len = 4;
  13702. if( sd == NULL || (md = sd->md) == NULL )
  13703. return;
  13704. fd = sd->fd;
  13705. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13706. WFIFOW(fd,0) = 0x29d;
  13707. for( i = 0; i < MAX_MERCSKILL; i++ )
  13708. {
  13709. uint16 id;
  13710. short idx = -1;
  13711. if( (id = md->db->skill[i].id) == 0 )
  13712. continue;
  13713. if ((idx = mercenary_skill_get_index(id)) == -1)
  13714. continue;
  13715. WFIFOW(fd,len) = id;
  13716. WFIFOL(fd,len+2) = skill_get_inf(id);
  13717. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13718. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13719. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv);
  13720. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13721. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13722. len += 37;
  13723. }
  13724. WFIFOW(fd,2) = len;
  13725. WFIFOSET(fd,len);
  13726. }
  13727. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13728. /// 029f <command>.B
  13729. /// 1 = mercenary information
  13730. /// 2 = delete
  13731. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13732. {
  13733. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13734. if( sd->md == NULL )
  13735. return;
  13736. if( option == 2 ) mercenary_delete(sd->md, 2);
  13737. }
  13738. /// Mercenary Message
  13739. /// message:
  13740. /// 0 = Mercenary soldier's duty hour is over.
  13741. /// 1 = Your mercenary soldier has been killed.
  13742. /// 2 = Your mercenary soldier has been fired.
  13743. /// 3 = Your mercenary soldier has ran away.
  13744. void clif_mercenary_message(struct map_session_data* sd, int message){
  13745. clif_msg(sd, MERC_MSG_BASE + message);
  13746. }
  13747. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13748. /// 0298 <name id>.W <seconds>.L
  13749. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13750. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13751. WFIFOHEAD(fd,packet_len(0x298));
  13752. WFIFOW(fd,0) = 0x298;
  13753. WFIFOW(fd,2) = nameid;
  13754. WFIFOL(fd,4) = seconds;
  13755. WFIFOSET(fd,packet_len(0x298));
  13756. }
  13757. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13758. /// 0299 <index>.W <name id>.W
  13759. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13760. { // '<ItemName>' item has been deleted from the Inventory
  13761. WFIFOHEAD(fd,packet_len(0x299));
  13762. WFIFOW(fd,0) = 0x299;
  13763. WFIFOW(fd,2) = index+2;
  13764. WFIFOW(fd,4) = nameid;
  13765. WFIFOSET(fd,packet_len(0x299));
  13766. }
  13767. /// Book Reading (ZC_READ_BOOK).
  13768. /// 0294 <book id>.L <page>.L
  13769. void clif_readbook(int fd, int book_id, int page)
  13770. {
  13771. WFIFOHEAD(fd,packet_len(0x294));
  13772. WFIFOW(fd,0) = 0x294;
  13773. WFIFOL(fd,2) = book_id;
  13774. WFIFOL(fd,6) = page;
  13775. WFIFOSET(fd,packet_len(0x294));
  13776. }
  13777. /// Battlegrounds
  13778. ///
  13779. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13780. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13781. void clif_bg_hp(struct map_session_data *sd)
  13782. {
  13783. unsigned char buf[34];
  13784. const int cmd = 0x2e0;
  13785. nullpo_retv(sd);
  13786. WBUFW(buf,0) = cmd;
  13787. WBUFL(buf,2) = sd->status.account_id;
  13788. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13789. if( sd->battle_status.max_hp > INT16_MAX )
  13790. { // To correctly display the %hp bar. [Skotlex]
  13791. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13792. WBUFW(buf,32) = 100;
  13793. }
  13794. else
  13795. {
  13796. WBUFW(buf,30) = sd->battle_status.hp;
  13797. WBUFW(buf,32) = sd->battle_status.max_hp;
  13798. }
  13799. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13800. }
  13801. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13802. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13803. void clif_bg_xy(struct map_session_data *sd)
  13804. {
  13805. unsigned char buf[36];
  13806. nullpo_retv(sd);
  13807. WBUFW(buf,0)=0x2df;
  13808. WBUFL(buf,2)=sd->status.account_id;
  13809. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13810. WBUFW(buf,30)=sd->status.class_;
  13811. WBUFW(buf,32)=sd->bl.x;
  13812. WBUFW(buf,34)=sd->bl.y;
  13813. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13814. }
  13815. void clif_bg_xy_remove(struct map_session_data *sd)
  13816. {
  13817. unsigned char buf[36];
  13818. nullpo_retv(sd);
  13819. WBUFW(buf,0)=0x2df;
  13820. WBUFL(buf,2)=sd->status.account_id;
  13821. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13822. WBUFW(buf,30)=0;
  13823. WBUFW(buf,32)=-1;
  13824. WBUFW(buf,34)=-1;
  13825. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13826. }
  13827. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13828. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13829. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13830. {
  13831. struct map_session_data *sd;
  13832. unsigned char *buf;
  13833. if( (sd = bg_getavailablesd(bg)) == NULL )
  13834. return;
  13835. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13836. WBUFW(buf,0) = 0x2dc;
  13837. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13838. WBUFL(buf,4) = src_id;
  13839. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13840. memcpy(WBUFP(buf,32), mes, len);
  13841. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13842. if( buf )
  13843. aFree(buf);
  13844. }
  13845. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13846. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13847. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13848. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13849. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13850. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13851. char *name, *message;
  13852. int namelen, messagelen;
  13853. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13854. return;
  13855. if( is_atcommand(fd, sd, message, 1) )
  13856. return;
  13857. if (sd->sc.cant.chat)
  13858. return; //no "chatting" while muted.
  13859. if( battle_config.min_chat_delay ) {
  13860. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13861. return;
  13862. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13863. }
  13864. if (battle_config.idletime_option&IDLE_CHAT)
  13865. sd->idletime = last_tick;
  13866. bg_send_message(sd, text, textlen);
  13867. }
  13868. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13869. /// 02de <camp A points>.W <camp B points>.W
  13870. void clif_bg_updatescore(int16 m)
  13871. {
  13872. struct block_list bl;
  13873. unsigned char buf[6];
  13874. bl.id = 0;
  13875. bl.type = BL_NUL;
  13876. bl.m = m;
  13877. WBUFW(buf,0) = 0x2de;
  13878. WBUFW(buf,2) = map[m].bgscore_lion;
  13879. WBUFW(buf,4) = map[m].bgscore_eagle;
  13880. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13881. }
  13882. void clif_bg_updatescore_single(struct map_session_data *sd)
  13883. {
  13884. int fd;
  13885. nullpo_retv(sd);
  13886. fd = sd->fd;
  13887. WFIFOHEAD(fd,packet_len(0x2de));
  13888. WFIFOW(fd,0) = 0x2de;
  13889. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13890. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13891. WFIFOSET(fd,packet_len(0x2de));
  13892. }
  13893. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13894. /// 02dd <account id>.L <name>.24B <camp>.W
  13895. void clif_sendbgemblem_area(struct map_session_data *sd)
  13896. {
  13897. unsigned char buf[33];
  13898. nullpo_retv(sd);
  13899. WBUFW(buf, 0) = 0x2dd;
  13900. WBUFL(buf,2) = sd->bl.id;
  13901. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13902. WBUFW(buf,30) = sd->bg_id;
  13903. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13904. }
  13905. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13906. {
  13907. nullpo_retv(sd);
  13908. WFIFOHEAD(fd,32);
  13909. WFIFOW(fd,0) = 0x2dd;
  13910. WFIFOL(fd,2) = sd->bl.id;
  13911. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13912. WFIFOW(fd,30) = sd->bg_id;
  13913. WFIFOSET(fd,packet_len(0x2dd));
  13914. }
  13915. /// Custom Fonts (ZC_NOTIFY_FONT).
  13916. /// 02ef <account_id>.L <font id>.W
  13917. void clif_font(struct map_session_data *sd)
  13918. {
  13919. #if PACKETVER >= 20080102
  13920. unsigned char buf[8];
  13921. nullpo_retv(sd);
  13922. WBUFW(buf,0) = 0x2ef;
  13923. WBUFL(buf,2) = sd->bl.id;
  13924. WBUFW(buf,6) = sd->status.font;
  13925. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13926. #endif
  13927. }
  13928. /*==========================================
  13929. * Notifies party members of instance change
  13930. *------------------------------------------*/
  13931. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13932. {
  13933. #if PACKETVER >= 20071128
  13934. unsigned char buf[65];
  13935. if(!sd) return;
  13936. WBUFW(buf,0) = 0x2cb;
  13937. memcpy( WBUFP(buf,2), name, 62 );
  13938. WBUFW(buf,63) = num;
  13939. if(flag) // A timer has changed or been added
  13940. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13941. else // No notification
  13942. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13943. #endif
  13944. return;
  13945. }
  13946. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13947. {
  13948. #if PACKETVER >= 20071128
  13949. unsigned char buf[4];
  13950. if(!sd) return;
  13951. WBUFW(buf,0) = 0x2cc;
  13952. WBUFW(buf,2) = num;
  13953. if(flag) // A timer has changed or been added
  13954. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13955. else // No notification
  13956. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13957. #endif
  13958. return;
  13959. }
  13960. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13961. {
  13962. #if PACKETVER >= 20071128
  13963. unsigned char buf[71];
  13964. if(!sd) return; //party_getavailablesd can return NULL
  13965. WBUFW(buf,0) = 0x2cd;
  13966. memcpy( WBUFP(buf,2), name, 62 );
  13967. WBUFL(buf,63) = limit1;
  13968. WBUFL(buf,67) = limit2;
  13969. if(flag) // A timer has changed or been added
  13970. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13971. else // No notification
  13972. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13973. #endif
  13974. return;
  13975. }
  13976. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13977. {
  13978. #if PACKETVER >= 20071128
  13979. unsigned char buf[10];
  13980. if(!sd) return;
  13981. WBUFW(buf,0) = 0x2ce;
  13982. WBUFL(buf,2) = type;
  13983. WBUFL(buf,6) = limit;
  13984. if(flag) // A timer has changed or been added
  13985. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13986. else // No notification
  13987. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13988. #endif
  13989. return;
  13990. }
  13991. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13992. /// 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
  13993. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13994. {
  13995. #if PACKETVER >= 20071002
  13996. unsigned char buf[22];
  13997. struct item_data* id = itemdb_search(item_data->nameid);
  13998. WBUFW(buf,0) = 0x2b8;
  13999. WBUFL(buf,2) = sd->status.account_id;
  14000. WBUFW(buf,6) = item_data->nameid;
  14001. WBUFB(buf,8) = item_data->identify;
  14002. WBUFB(buf,9) = item_data->attribute;
  14003. WBUFB(buf,10) = item_data->refine;
  14004. clif_addcards(WBUFP(buf,11), item_data);
  14005. WBUFW(buf,19) = id->equip; // equip location
  14006. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14007. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14008. #endif
  14009. }
  14010. /// Display gained exp (ZC_NOTIFY_EXP).
  14011. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14012. /// var id:
  14013. /// SP_BASEEXP, SP_JOBEXP
  14014. /// exp type:
  14015. /// 0 = normal exp gain/loss
  14016. /// 1 = quest exp gain/loss
  14017. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  14018. {
  14019. int fd;
  14020. nullpo_retv(sd);
  14021. fd = sd->fd;
  14022. WFIFOHEAD(fd, packet_len(0x7f6));
  14023. WFIFOW(fd,0) = 0x7f6;
  14024. WFIFOL(fd,2) = sd->bl.id;
  14025. WFIFOL(fd,6) = exp;
  14026. WFIFOW(fd,10) = type;
  14027. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  14028. WFIFOSET(fd,packet_len(0x7f6));
  14029. }
  14030. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14031. /// type:
  14032. /// 0 = Displays 'value' for 5 seconds.
  14033. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14034. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14035. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14036. /// value:
  14037. /// 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).
  14038. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14039. {
  14040. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14041. WFIFOW(sd->fd,0) = 0x1b1;
  14042. WFIFOB(sd->fd,2) = type;
  14043. WFIFOL(sd->fd,3) = value;
  14044. WFIFOSET(sd->fd, packet_len(0x1b1));
  14045. }
  14046. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14047. /// 021d <state>.L
  14048. /// state:
  14049. /// 0 = Full effects
  14050. /// 1 = Reduced effects
  14051. ///
  14052. /// NOTE: The state is used on Aegis for sending skill unit packet
  14053. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14054. /// whenever possible. Due to the way the decision check is
  14055. /// constructed, this state tracking was rendered useless,
  14056. /// as the only skill unit, that is sent with 0x1c9 is
  14057. /// Graffiti.
  14058. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14059. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14060. sd->state.lesseffect = ( isLess != 0 );
  14061. }
  14062. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14063. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  14064. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  14065. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14066. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14067. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14068. int type = RFIFOL(fd,info->pos[1]);
  14069. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14070. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14071. if( sd->state.trading || sd->npc_shopid )
  14072. return;
  14073. if( flag == 0 || n == 0) {
  14074. clif_menuskill_clear(sd);
  14075. return; // Canceled by player.
  14076. }
  14077. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14078. clif_menuskill_clear(sd);
  14079. return; // Prevent hacking.
  14080. }
  14081. switch( type ) {
  14082. case 0: // Change Material
  14083. skill_changematerial(sd,n,item_list);
  14084. break;
  14085. case 1: // Level 1: Pure to Rough
  14086. case 2: // Level 2: Rough to Pure
  14087. skill_elementalanalysis(sd,n,type,item_list);
  14088. break;
  14089. }
  14090. clif_menuskill_clear(sd);
  14091. return;
  14092. }
  14093. /*==========================================
  14094. * Elemental System
  14095. *==========================================*/
  14096. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14097. struct elemental_data *ed;
  14098. struct status_data *status;
  14099. int fd;
  14100. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14101. return;
  14102. fd = sd->fd;
  14103. status = &ed->battle_status;
  14104. WFIFOHEAD(fd,8);
  14105. WFIFOW(fd,0) = 0x81e;
  14106. WFIFOW(fd,2) = type;
  14107. switch( type ) {
  14108. case SP_HP:
  14109. WFIFOL(fd,4) = status->hp;
  14110. break;
  14111. case SP_MAXHP:
  14112. WFIFOL(fd,4) = status->max_hp;
  14113. break;
  14114. case SP_SP:
  14115. WFIFOL(fd,4) = status->sp;
  14116. break;
  14117. case SP_MAXSP:
  14118. WFIFOL(fd,4) = status->max_sp;
  14119. break;
  14120. }
  14121. WFIFOSET(fd,8);
  14122. }
  14123. void clif_elemental_info(struct map_session_data *sd) {
  14124. int fd;
  14125. struct elemental_data *ed;
  14126. struct status_data *status;
  14127. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14128. return;
  14129. fd = sd->fd;
  14130. status = &ed->battle_status;
  14131. WFIFOHEAD(fd,22);
  14132. WFIFOW(fd, 0) = 0x81d;
  14133. WFIFOL(fd, 2) = ed->bl.id;
  14134. WFIFOL(fd, 6) = status->hp;
  14135. WFIFOL(fd,10) = status->max_hp;
  14136. WFIFOL(fd,14) = status->sp;
  14137. WFIFOL(fd,18) = status->max_sp;
  14138. WFIFOSET(fd,22);
  14139. }
  14140. /// Buying Store System
  14141. ///
  14142. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14143. /// 0810 <slots>.B
  14144. void clif_buyingstore_open(struct map_session_data* sd)
  14145. {
  14146. int fd = sd->fd;
  14147. WFIFOHEAD(fd,packet_len(0x810));
  14148. WFIFOW(fd,0) = 0x810;
  14149. WFIFOB(fd,2) = sd->buyingstore.slots;
  14150. WFIFOSET(fd,packet_len(0x810));
  14151. }
  14152. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14153. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14154. /// result:
  14155. /// 0 = cancel
  14156. /// 1 = open
  14157. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14158. {
  14159. const unsigned int blocksize = 8;
  14160. uint8* itemlist;
  14161. char storename[MESSAGE_SIZE];
  14162. unsigned char result;
  14163. int zenylimit;
  14164. unsigned int count, packet_len;
  14165. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14166. packet_len = RFIFOW(fd,info->pos[0]);
  14167. // TODO: Make this check global for all variable length packets.
  14168. if( packet_len < 89 )
  14169. {// minimum packet length
  14170. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14171. return;
  14172. }
  14173. zenylimit = RFIFOL(fd,info->pos[1]);
  14174. result = RFIFOL(fd,info->pos[2]);
  14175. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  14176. itemlist = RFIFOP(fd,info->pos[4]);
  14177. // so that buyingstore_create knows, how many elements it has access to
  14178. packet_len-= info->pos[4];
  14179. if( packet_len%blocksize )
  14180. {
  14181. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14182. return;
  14183. }
  14184. count = packet_len/blocksize;
  14185. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14186. }
  14187. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14188. /// 0812 <result>.W <total weight>.L
  14189. /// result:
  14190. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14191. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14192. /// 8 = "No sale (purchase) information available." (0x705)
  14193. /// ? = nothing
  14194. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14195. {
  14196. int fd = sd->fd;
  14197. WFIFOHEAD(fd,packet_len(0x812));
  14198. WFIFOW(fd,0) = 0x812;
  14199. WFIFOW(fd,2) = result;
  14200. WFIFOL(fd,4) = weight;
  14201. WFIFOSET(fd,packet_len(0x812));
  14202. }
  14203. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14204. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14205. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14206. {
  14207. int fd = sd->fd;
  14208. unsigned int i;
  14209. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14210. WFIFOW(fd,0) = 0x813;
  14211. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14212. WFIFOL(fd,4) = sd->bl.id;
  14213. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14214. for( i = 0; i < sd->buyingstore.slots; i++ )
  14215. {
  14216. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14217. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14218. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14219. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14220. }
  14221. WFIFOSET(fd,WFIFOW(fd,2));
  14222. }
  14223. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14224. /// 0814 <account id>.L <store name>.80B
  14225. void clif_buyingstore_entry(struct map_session_data* sd)
  14226. {
  14227. uint8 buf[86];
  14228. WBUFW(buf,0) = 0x814;
  14229. WBUFL(buf,2) = sd->bl.id;
  14230. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14231. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14232. }
  14233. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14234. {
  14235. int fd = sd->fd;
  14236. WFIFOHEAD(fd,packet_len(0x814));
  14237. WFIFOW(fd,0) = 0x814;
  14238. WFIFOL(fd,2) = pl_sd->bl.id;
  14239. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14240. WFIFOSET(fd,packet_len(0x814));
  14241. }
  14242. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14243. /// 0815
  14244. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14245. {
  14246. buyingstore_close(sd);
  14247. }
  14248. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14249. /// 0816 <account id>.L
  14250. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14251. {
  14252. uint8 buf[6];
  14253. WBUFW(buf,0) = 0x816;
  14254. WBUFL(buf,2) = sd->bl.id;
  14255. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14256. }
  14257. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14258. {
  14259. int fd = sd->fd;
  14260. WFIFOHEAD(fd,packet_len(0x816));
  14261. WFIFOW(fd,0) = 0x816;
  14262. WFIFOL(fd,2) = pl_sd->bl.id;
  14263. WFIFOSET(fd,packet_len(0x816));
  14264. }
  14265. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14266. /// 0817 <account id>.L
  14267. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14268. {
  14269. uint32 account_id;
  14270. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14271. buyingstore_open(sd, account_id);
  14272. }
  14273. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14274. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14275. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14276. {
  14277. int fd = sd->fd;
  14278. unsigned int i;
  14279. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14280. WFIFOW(fd,0) = 0x818;
  14281. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14282. WFIFOL(fd,4) = pl_sd->bl.id;
  14283. WFIFOL(fd,8) = pl_sd->buyer_id;
  14284. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14285. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14286. {
  14287. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14288. 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.
  14289. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14290. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14291. }
  14292. WFIFOSET(fd,WFIFOW(fd,2));
  14293. }
  14294. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14295. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14296. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14297. {
  14298. const unsigned int blocksize = 6;
  14299. uint8* itemlist;
  14300. uint32 account_id;
  14301. unsigned int count, packet_len, buyer_id;
  14302. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14303. packet_len = RFIFOW(fd,info->pos[0]);
  14304. if( packet_len < 12 )
  14305. {// minimum packet length
  14306. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14307. return;
  14308. }
  14309. account_id = RFIFOL(fd,info->pos[1]);
  14310. buyer_id = RFIFOL(fd,info->pos[2]);
  14311. itemlist = RFIFOP(fd,info->pos[3]);
  14312. // so that buyingstore_trade knows, how many elements it has access to
  14313. packet_len-= info->pos[3];
  14314. if( packet_len%blocksize )
  14315. {
  14316. 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);
  14317. return;
  14318. }
  14319. count = packet_len/blocksize;
  14320. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14321. }
  14322. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14323. /// 081a <result>.W
  14324. /// result:
  14325. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14326. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14327. /// ? = nothing
  14328. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14329. {
  14330. int fd = sd->fd;
  14331. WFIFOHEAD(fd,packet_len(0x81a));
  14332. WFIFOW(fd,0) = 0x81a;
  14333. WFIFOW(fd,2) = result;
  14334. WFIFOSET(fd,packet_len(0x81a));
  14335. }
  14336. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  14337. /// 081b <name id>.W <amount>.W <limit zeny>.L
  14338. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  14339. {
  14340. int fd = sd->fd;
  14341. WFIFOHEAD(fd,packet_len(0x81b));
  14342. WFIFOW(fd,0) = 0x81b;
  14343. WFIFOW(fd,2) = nameid;
  14344. WFIFOW(fd,4) = amount; // amount of nameid received
  14345. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  14346. WFIFOSET(fd,packet_len(0x81b));
  14347. }
  14348. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14349. /// 081c <index>.W <amount>.W <price>.L
  14350. /// message:
  14351. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14352. ///
  14353. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14354. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14355. {
  14356. int fd = sd->fd;
  14357. WFIFOHEAD(fd,packet_len(0x81c));
  14358. WFIFOW(fd,0) = 0x81c;
  14359. WFIFOW(fd,2) = index+2;
  14360. WFIFOW(fd,4) = amount;
  14361. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14362. WFIFOSET(fd,packet_len(0x81c));
  14363. }
  14364. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14365. /// 0824 <result>.W <name id>.W
  14366. /// result:
  14367. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14368. /// 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)
  14369. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14370. /// ? = nothing
  14371. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14372. {
  14373. int fd = sd->fd;
  14374. WFIFOHEAD(fd,packet_len(0x824));
  14375. WFIFOW(fd,0) = 0x824;
  14376. WFIFOW(fd,2) = result;
  14377. WFIFOW(fd,4) = nameid;
  14378. WFIFOSET(fd,packet_len(0x824));
  14379. }
  14380. /// Search Store Info System
  14381. ///
  14382. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14383. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14384. /// type:
  14385. /// 0 = Vending
  14386. /// 1 = Buying Store
  14387. ///
  14388. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14389. /// amount of card slots. If the client does not know about the item it
  14390. /// cannot be searched.
  14391. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14392. {
  14393. const unsigned int blocksize = 2;
  14394. const uint8* itemlist;
  14395. const uint8* cardlist;
  14396. unsigned char type;
  14397. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14398. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14399. packet_len = RFIFOW(fd,info->pos[0]);
  14400. if( packet_len < 15 )
  14401. {// minimum packet length
  14402. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14403. return;
  14404. }
  14405. type = RFIFOB(fd,info->pos[1]);
  14406. max_price = RFIFOL(fd,info->pos[2]);
  14407. min_price = RFIFOL(fd,info->pos[3]);
  14408. item_count = RFIFOB(fd,info->pos[4]);
  14409. card_count = RFIFOB(fd,info->pos[5]);
  14410. itemlist = RFIFOP(fd,info->pos[6]);
  14411. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14412. // check, if there is enough data for the claimed count of items
  14413. packet_len-= info->pos[6];
  14414. if( packet_len%blocksize )
  14415. {
  14416. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14417. return;
  14418. }
  14419. count = packet_len/blocksize;
  14420. if( count < item_count+card_count )
  14421. {
  14422. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14423. return;
  14424. }
  14425. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14426. }
  14427. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14428. /// 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 }*
  14429. /// is first page:
  14430. /// 0 = appends to existing results
  14431. /// 1 = clears previous results before displaying this result set
  14432. /// is next page:
  14433. /// 0 = no "next" label
  14434. /// 1 = "next" label to retrieve more results
  14435. void clif_search_store_info_ack(struct map_session_data* sd)
  14436. {
  14437. const unsigned int blocksize = MESSAGE_SIZE+26;
  14438. int fd = sd->fd;
  14439. unsigned int i, start, end;
  14440. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14441. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14442. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14443. WFIFOW(fd,0) = 0x836;
  14444. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14445. WFIFOB(fd,4) = !sd->searchstore.pages;
  14446. WFIFOB(fd,5) = searchstore_querynext(sd);
  14447. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14448. for( i = start; i < end; i++ ) {
  14449. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14450. struct item it;
  14451. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14452. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14453. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14454. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14455. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14456. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14457. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14458. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14459. // make-up an item for clif_addcards
  14460. memset(&it, 0, sizeof(it));
  14461. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14462. it.nameid = ssitem->nameid;
  14463. it.amount = ssitem->amount;
  14464. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14465. }
  14466. WFIFOSET(fd,WFIFOW(fd,2));
  14467. }
  14468. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14469. /// 0837 <reason>.B
  14470. /// reason:
  14471. /// 0 = "No matching stores were found." (0x70b)
  14472. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14473. /// 2 = "You cannot search anymore." (0x706)
  14474. /// 3 = "You cannot search yet." (0x708)
  14475. /// 4 = "No sale (purchase) information available." (0x705)
  14476. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14477. {
  14478. int fd = sd->fd;
  14479. WFIFOHEAD(fd,packet_len(0x837));
  14480. WFIFOW(fd,0) = 0x837;
  14481. WFIFOB(fd,2) = reason;
  14482. WFIFOSET(fd,packet_len(0x837));
  14483. }
  14484. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14485. /// 0838
  14486. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14487. {
  14488. searchstore_next(sd);
  14489. }
  14490. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14491. /// 083a <type>.W <remaining uses>.B
  14492. /// type:
  14493. /// 0 = Search Stores
  14494. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14495. void clif_open_search_store_info(struct map_session_data* sd)
  14496. {
  14497. int fd = sd->fd;
  14498. WFIFOHEAD(fd,packet_len(0x83a));
  14499. WFIFOW(fd,0) = 0x83a;
  14500. WFIFOW(fd,2) = sd->searchstore.effect;
  14501. #if PACKETVER > 20100701
  14502. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14503. #endif
  14504. WFIFOSET(fd,packet_len(0x83a));
  14505. }
  14506. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14507. /// 083b
  14508. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14509. {
  14510. searchstore_close(sd);
  14511. }
  14512. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14513. /// 083c <account id>.L <store id>.L <nameid>.W
  14514. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14515. {
  14516. unsigned short nameid;
  14517. uint32 account_id, store_id;
  14518. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14519. account_id = RFIFOL(fd,info->pos[0]);
  14520. store_id = RFIFOL(fd,info->pos[1]);
  14521. nameid = RFIFOW(fd,info->pos[2]);
  14522. searchstore_click(sd, account_id, store_id, nameid);
  14523. }
  14524. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14525. /// 083d <xPos>.W <yPos>.W
  14526. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14527. {
  14528. int fd = sd->fd;
  14529. WFIFOHEAD(fd,packet_len(0x83d));
  14530. WFIFOW(fd,0) = 0x83d;
  14531. WFIFOW(fd,2) = x;
  14532. WFIFOW(fd,4) = y;
  14533. WFIFOSET(fd,packet_len(0x83d));
  14534. }
  14535. /// Parse function for packet debugging.
  14536. void clif_parse_debug(int fd,struct map_session_data *sd)
  14537. {
  14538. int cmd, packet_len;
  14539. // clif_parse ensures, that there is at least 2 bytes of data
  14540. cmd = RFIFOW(fd,0);
  14541. if( sd ) {
  14542. packet_len = packet_db[sd->packet_ver][cmd].len;
  14543. if( packet_len == 0 )
  14544. {// unknown
  14545. packet_len = RFIFOREST(fd);
  14546. }
  14547. else if( packet_len == -1 )
  14548. {// variable length
  14549. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14550. }
  14551. 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);
  14552. }
  14553. else
  14554. {
  14555. packet_len = RFIFOREST(fd);
  14556. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14557. }
  14558. ShowDump(RFIFOP(fd,0), packet_len);
  14559. }
  14560. /*==========================================
  14561. * Server tells client to display a window similar to Magnifier (item) one
  14562. * Server populates the window with avilable elemental converter options according to player's inventory
  14563. *------------------------------------------*/
  14564. int clif_elementalconverter_list(struct map_session_data *sd) {
  14565. int i,c,view,fd;
  14566. nullpo_ret(sd);
  14567. /// Main client packet processing function
  14568. fd=sd->fd;
  14569. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14570. WFIFOW(fd, 0)=0x1ad;
  14571. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14572. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14573. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14574. WFIFOW(fd,c*2+ 4)= view;
  14575. else
  14576. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14577. c++;
  14578. }
  14579. }
  14580. WFIFOW(fd,2) = c*2+4;
  14581. WFIFOSET(fd, WFIFOW(fd,2));
  14582. if (c > 0) {
  14583. sd->menuskill_id = SA_CREATECON;
  14584. sd->menuskill_val = c;
  14585. }
  14586. return 0;
  14587. }
  14588. /**
  14589. * Rune Knight
  14590. **/
  14591. void clif_millenniumshield(struct block_list *bl, short shields) {
  14592. #if PACKETVER >= 20081217
  14593. unsigned char buf[10];
  14594. WBUFW(buf,0) = 0x440;
  14595. WBUFL(buf,2) = bl->id;
  14596. WBUFW(buf,6) = shields;
  14597. WBUFW(buf,8) = 0;
  14598. clif_send(buf,packet_len(0x440),bl,AREA);
  14599. #endif
  14600. }
  14601. /**
  14602. * Warlock
  14603. **/
  14604. /*==========================================
  14605. * Spellbook list [LimitLine/3CeAM]
  14606. *------------------------------------------*/
  14607. int clif_spellbook_list(struct map_session_data *sd)
  14608. {
  14609. int i, c;
  14610. int fd;
  14611. nullpo_ret(sd);
  14612. fd = sd->fd;
  14613. WFIFOHEAD(fd, 8 * 8 + 8);
  14614. WFIFOW(fd,0) = 0x1ad;
  14615. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14616. {
  14617. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14618. {
  14619. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14620. c++;
  14621. }
  14622. }
  14623. if( c > 0 )
  14624. {
  14625. WFIFOW(fd,2) = c * 2 + 4;
  14626. WFIFOSET(fd, WFIFOW(fd, 2));
  14627. sd->menuskill_id = WL_READING_SB;
  14628. sd->menuskill_val = c;
  14629. }
  14630. else{
  14631. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14632. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14633. }
  14634. return 1;
  14635. }
  14636. /**
  14637. * Mechanic
  14638. **/
  14639. /*==========================================
  14640. * Magic Decoy Material List
  14641. *------------------------------------------*/
  14642. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14643. int i, c;
  14644. int fd;
  14645. nullpo_ret(sd);
  14646. fd = sd->fd;
  14647. WFIFOHEAD(fd, 8 * 8 + 8);
  14648. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14649. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14650. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14651. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14652. c ++;
  14653. }
  14654. }
  14655. if( c > 0 ) {
  14656. sd->menuskill_id = NC_MAGICDECOY;
  14657. sd->menuskill_val = skill_lv;
  14658. sd->sc.comet_x = x;
  14659. sd->sc.comet_y = y;
  14660. WFIFOW(fd,2) = c * 2 + 4;
  14661. WFIFOSET(fd, WFIFOW(fd, 2));
  14662. } else {
  14663. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14664. return 0;
  14665. }
  14666. return 1;
  14667. }
  14668. /*==========================================
  14669. * Guillotine Cross Poisons List
  14670. *------------------------------------------*/
  14671. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14672. int i, c;
  14673. int fd;
  14674. nullpo_ret(sd);
  14675. fd = sd->fd;
  14676. WFIFOHEAD(fd, 8 * 8 + 8);
  14677. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14678. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14679. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14680. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14681. c ++;
  14682. }
  14683. }
  14684. if( c > 0 ) {
  14685. sd->menuskill_id = GC_POISONINGWEAPON;
  14686. sd->menuskill_val = skill_lv;
  14687. WFIFOW(fd,2) = c * 2 + 4;
  14688. WFIFOSET(fd, WFIFOW(fd, 2));
  14689. } else {
  14690. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14691. return 0;
  14692. }
  14693. return 1;
  14694. }
  14695. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14696. int fd, i, c;
  14697. nullpo_ret(sd);
  14698. fd = sd->fd;
  14699. if( !fd ) return 0;
  14700. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14701. return 0;
  14702. WFIFOHEAD(fd, 2 * 6 + 4);
  14703. WFIFOW(fd,0) = 0x442;
  14704. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14705. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14706. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14707. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14708. {
  14709. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14710. c++;
  14711. }
  14712. if( c > 0 ) {
  14713. WFIFOW(fd,2) = 8 + c * 2;
  14714. WFIFOL(fd,4) = c;
  14715. WFIFOSET(fd,WFIFOW(fd,2));
  14716. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14717. sd->menuskill_val = c;
  14718. } else {
  14719. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14720. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14721. }
  14722. return 1;
  14723. }
  14724. /*===========================================
  14725. * Skill list for Four Elemental Analysis
  14726. * and Change Material skills.
  14727. *------------------------------------------*/
  14728. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14729. {
  14730. #if PACKETVER >= 20090922
  14731. int fd;
  14732. nullpo_ret(sd);
  14733. sd->menuskill_id = skill_id; // To prevent hacking.
  14734. sd->menuskill_val = skill_lv;
  14735. if( skill_id == GN_CHANGEMATERIAL )
  14736. skill_lv = 0; // Changematerial
  14737. fd = sd->fd;
  14738. WFIFOHEAD(fd,packet_len(0x7e3));
  14739. WFIFOW(fd,0) = 0x7e3;
  14740. WFIFOL(fd,2) = skill_lv;
  14741. WFIFOL(fd,4) = 0;
  14742. WFIFOSET(fd,packet_len(0x7e3));
  14743. #endif
  14744. return 1;
  14745. }
  14746. /*==========================================
  14747. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14748. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14749. * RFIFOL(fd,2) - type (currently not used)
  14750. *------------------------------------------*/
  14751. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14752. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14753. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14754. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14755. return;
  14756. if( pc_istrading(sd) ) {
  14757. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14758. clif_menuskill_clear(sd);
  14759. return;
  14760. }
  14761. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14762. clif_menuskill_clear(sd);
  14763. }
  14764. /*==========================================
  14765. * Kagerou/Oboro amulet spirit
  14766. *------------------------------------------*/
  14767. void clif_spiritcharm(struct map_session_data *sd)
  14768. {
  14769. unsigned char buf[10];
  14770. nullpo_retv(sd);
  14771. WBUFW(buf,0)=0x08cf;
  14772. WBUFL(buf,2)=sd->bl.id;
  14773. WBUFW(buf,6)=sd->spiritcharm_type;
  14774. WBUFW(buf,8)=sd->spiritcharm;
  14775. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14776. }
  14777. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14778. /// 0907 <index>.W
  14779. ///
  14780. /// R 0908 <index>.w <type>.b
  14781. /// type:
  14782. /// 0 = move item to personal tab
  14783. /// 1 = move item to normal tab
  14784. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14785. #if PACKETVER >= 20111122
  14786. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14787. int index = RFIFOW(fd,info->pos[0])-2;
  14788. int type = RFIFOB(fd, info->pos[1]);
  14789. /* can't move while dead. */
  14790. if(pc_isdead(sd)) {
  14791. return;
  14792. }
  14793. if (index < 0 || index >= MAX_INVENTORY)
  14794. return;
  14795. if ( sd->status.inventory[index].favorite && type == 1 )
  14796. sd->status.inventory[index].favorite = 0;
  14797. else if( type == 0 )
  14798. sd->status.inventory[index].favorite = 1;
  14799. else
  14800. return;/* nothing to do. */
  14801. clif_favorite_item(sd, index);
  14802. #endif
  14803. }
  14804. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14805. /// 0900 <index>.W <favorite>.B
  14806. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14807. int fd = sd->fd;
  14808. WFIFOHEAD(fd,packet_len(0x908));
  14809. WFIFOW(fd,0) = 0x908;
  14810. WFIFOW(fd,2) = index+2;
  14811. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14812. WFIFOSET(fd,packet_len(0x908));
  14813. }
  14814. void clif_snap( struct block_list *bl, short x, short y ) {
  14815. unsigned char buf[10];
  14816. WBUFW(buf,0) = 0x8d2;
  14817. WBUFL(buf,2) = bl->id;
  14818. WBUFW(buf,6) = x;
  14819. WBUFW(buf,8) = y;
  14820. if( disguised(bl) )
  14821. {
  14822. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14823. WBUFL(buf,2) = -bl->id;
  14824. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14825. } else
  14826. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14827. }
  14828. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14829. #if PACKETVER >= 20120404
  14830. WFIFOHEAD(fd,packet_len(0x977));
  14831. WFIFOW(fd,0) = 0x977;
  14832. WFIFOL(fd,2) = md->bl.id;
  14833. WFIFOL(fd,6) = md->status.hp;
  14834. WFIFOL(fd,10) = md->status.max_hp;
  14835. WFIFOSET(fd,packet_len(0x977));
  14836. #endif
  14837. }
  14838. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14839. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14840. return;
  14841. }
  14842. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14843. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14844. WFIFOW(sd->fd,0) = 0x2c9;
  14845. WFIFOB(sd->fd,2) = flag;
  14846. WFIFOSET(sd->fd, packet_len(0x2c9));
  14847. }
  14848. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14849. /// 0979 <world name>.24B <char name>.24B
  14850. void clif_ackworldinfo(struct map_session_data* sd) {
  14851. int fd;
  14852. nullpo_retv(sd);
  14853. fd = sd->fd;
  14854. WFIFOHEAD(fd,packet_len(0x979));
  14855. WFIFOW(fd,0)=0x979;
  14856. //AID -> world name ?
  14857. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14858. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14859. WFIFOSET(fd,packet_len(0x979));
  14860. }
  14861. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14862. /// 0978 <AID>.L
  14863. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14864. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14865. if(sd) clif_ackworldinfo(sd);
  14866. }
  14867. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14868. /// 0447
  14869. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14870. //if(sd)
  14871. ;
  14872. }
  14873. /// req world info (CZ_CLIENT_VERSION)
  14874. /// 044A <version>.L
  14875. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14876. //if(sd)
  14877. ;
  14878. }
  14879. /// Ranking list
  14880. /// ranking pointlist { <name>.24B <point>.L }*10
  14881. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14882. struct fame_list* list;
  14883. int skip = 0;
  14884. switch(rankingtype+1) { //to keep the same case as char.c
  14885. case 1: list = smith_fame_list; break;
  14886. case 2: list = chemist_fame_list; break;
  14887. case 3: list = taekwon_fame_list; break;
  14888. default: skip=1; break;
  14889. }
  14890. if(!skip) {
  14891. int i;
  14892. //Packet size limits this list to 10 elements. [Skotlex]
  14893. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14894. if (list[i].id > 0) {
  14895. const char* name;
  14896. if (strcmp(list[i].name, "-") == 0 &&
  14897. (name = map_charid2nick(list[i].id)) != NULL)
  14898. {
  14899. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14900. } else {
  14901. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14902. }
  14903. } else {
  14904. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14905. }
  14906. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14907. }
  14908. for(;i < 10; i++) { //In case the MAX is less than 10.
  14909. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14910. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14911. }
  14912. }
  14913. }
  14914. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14915. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14916. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14917. int mypoint = 0;
  14918. WBUFW(buf,0) = 0x97d;
  14919. WBUFW(buf,2) = rankingType;
  14920. clif_sub_ranklist(buf,4,sd,rankingType);
  14921. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14922. case MAPID_BLACKSMITH:
  14923. case MAPID_ALCHEMIST:
  14924. case MAPID_TAEKWON:
  14925. mypoint = sd->status.fame;
  14926. }
  14927. WBUFL(buf,284) = mypoint; //mypoint
  14928. clif_send(buf, 288, &sd->bl, SELF);
  14929. }
  14930. /*
  14931. * 097c <type> (CZ_REQ_RANKING)
  14932. * type
  14933. * 0: /blacksmith
  14934. * 1: /alchemist
  14935. * 2: /taekwon
  14936. * 3: /pk
  14937. * */
  14938. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14939. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14940. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14941. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14942. }
  14943. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14944. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14945. #if PACKETVER < 20130710
  14946. switch(rankingtype){
  14947. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14948. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14949. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14950. }
  14951. #else
  14952. int fd=sd->fd;
  14953. WFIFOHEAD(fd,14);
  14954. WFIFOW(fd,0) = 0x97e;
  14955. WFIFOW(fd,2) = rankingtype;
  14956. WFIFOL(fd,4) = point;
  14957. WFIFOL(fd,8) = sd->status.fame;
  14958. WFIFOSET(fd,12);
  14959. #endif
  14960. }
  14961. /**
  14962. * Transmit personal information to player. (rates)
  14963. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14964. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14965. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14966. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14967. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14968. * FIXME!
  14969. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14970. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14971. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14972. */
  14973. #ifdef VIP_ENABLE
  14974. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14975. if (sd) {
  14976. struct s_packet_db* info;
  14977. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14978. int cmd = 0, fd, i = 0;
  14979. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14980. int details_bexp[PINFO_MAX];
  14981. int details_drop[PINFO_MAX];
  14982. int details_penalty[PINFO_MAX];
  14983. int penalty_const;
  14984. /**
  14985. * Set for EXP
  14986. */
  14987. //0:PCRoom
  14988. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14989. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14990. details_bexp[0] = 0;
  14991. else {
  14992. if (details_bexp[0] < 100) {
  14993. details_bexp[0] = 100 - details_bexp[0];
  14994. details_bexp[0] = 0 - details_bexp[0];
  14995. }
  14996. else
  14997. details_bexp[0] = details_bexp[0] - 100;
  14998. }
  14999. //1:Premium
  15000. if (pc_isvip(sd)) {
  15001. details_bexp[1] = battle_config.vip_base_exp_increase;
  15002. if (details_bexp[1] < 0)
  15003. details_bexp[1] = 0 - details_bexp[1];
  15004. }
  15005. else
  15006. details_bexp[1] = 0;
  15007. //2:Server
  15008. details_bexp[2] = battle_config.base_exp_rate;
  15009. if (details_bexp[2] == 100)
  15010. details_bexp[2] = 0;
  15011. else {
  15012. if (details_bexp[2] < 100) {
  15013. details_bexp[2] = 100 - details_bexp[2];
  15014. details_bexp[2] = 0 - details_bexp[2];
  15015. }
  15016. else
  15017. details_bexp[2] = details_bexp[2] - 100;
  15018. }
  15019. //3:TPLUS
  15020. details_bexp[3] = 0;
  15021. /* End - EXP set*/
  15022. /**
  15023. * Set for Drop rate
  15024. */
  15025. //0:PCRoom
  15026. details_drop[0] = 0;
  15027. //1:Premium
  15028. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15029. if (pc_isvip(sd)) {
  15030. if (details_drop[1] < 0)
  15031. details_drop[1] = 0 - details_drop[1];
  15032. }
  15033. else
  15034. details_drop[1] = 0;
  15035. //2:Server
  15036. details_drop[2] = battle_config.item_rate_common;
  15037. if (details_drop[2] == 100)
  15038. details_drop[2] = 0;
  15039. else {
  15040. if (details_drop[2] < 100) {
  15041. details_drop[2] = 100 - details_drop[2];
  15042. details_drop[2] = 0 - details_drop[2];
  15043. }
  15044. else
  15045. details_drop[2] = details_drop[2] - 100;
  15046. }
  15047. //3:TPLUS
  15048. details_drop[3] = 0;
  15049. /* End - Drop set*/
  15050. /**
  15051. * Set for Penalty rate
  15052. */
  15053. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  15054. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  15055. //0:PCRoom
  15056. details_penalty[0] = 0;
  15057. //1:Premium
  15058. if (pc_isvip(sd)) {
  15059. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  15060. if (details_penalty[1] == 100)
  15061. details_penalty[1] = 0;
  15062. else {
  15063. if (details_penalty[1] < 100) {
  15064. details_penalty[1] = 100 - details_penalty[1];
  15065. details_penalty[1] = 0 - details_penalty[1];
  15066. }
  15067. else
  15068. details_penalty[1] = details_penalty[1] - 100;
  15069. }
  15070. }
  15071. else
  15072. details_penalty[1] = 0;
  15073. //2:Server
  15074. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  15075. if (details_penalty[2] == 100)
  15076. details_penalty[2] = 0;
  15077. else {
  15078. if (details_penalty[2] < 100) {
  15079. details_penalty[2] = 100 - details_penalty[2];
  15080. details_penalty[2] = 0 - details_penalty[2];
  15081. }
  15082. else
  15083. details_penalty[2] = details_penalty[2] - 100;
  15084. }
  15085. //3:TPLUS
  15086. details_penalty[3] = 0;
  15087. /* End - Penalty set*/
  15088. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  15089. info = &packet_db[sd->packet_ver][cmd];
  15090. len = info->len; //this is the base len without details
  15091. if(!len) return; //version as packet disable
  15092. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15093. szdetails = 7;
  15094. factor = 1;
  15095. }
  15096. else if (cmd == 0x097b) {
  15097. tot_baseexp *= factor;
  15098. tot_drop *= factor;
  15099. tot_penalty *= factor;
  15100. }
  15101. fd = sd->fd;
  15102. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15103. WFIFOW(fd,0) = cmd;
  15104. for (i = 0; i < maxinfotype; i++) {
  15105. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15106. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15107. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15108. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15109. tot_baseexp += details_bexp[i]*factor;
  15110. tot_drop += details_penalty[i]*factor;
  15111. tot_penalty += details_drop[i]*factor;
  15112. len += szdetails;
  15113. }
  15114. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15115. if (cmd == 0x08cb) { //0x08cb version
  15116. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15117. WFIFOW(fd,info->pos[2]) = tot_drop;
  15118. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15119. }
  15120. else { //2013-08-07aRagexe uses 0x097b
  15121. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15122. WFIFOL(fd,info->pos[2]) = tot_drop;
  15123. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15124. }
  15125. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15126. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15127. WFIFOSET(fd,len);
  15128. }
  15129. }
  15130. #endif
  15131. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15132. char cmd[30];
  15133. int t_aid = RFIFOL(fd,2);
  15134. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15135. is_atcommand(fd, sd, cmd, 1);
  15136. }
  15137. /**
  15138. * Marks Crimson Marker target on mini-map to the caster
  15139. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15140. * @param fd
  15141. * @param bl Crimson Marker target
  15142. **/
  15143. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15144. struct s_packet_db* info;
  15145. int cmd = 0;
  15146. int16 len;
  15147. unsigned char buf[11];
  15148. nullpo_retv(sd);
  15149. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  15150. if (!cmd)
  15151. cmd = 0x09C1; //default
  15152. info = &packet_db[sd->packet_ver][cmd];
  15153. if (!(len = info->len))
  15154. return;
  15155. WBUFW(buf, 0) = cmd;
  15156. WBUFL(buf, info->pos[0]) = bl->id;
  15157. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15158. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15159. clif_send(buf, len, &sd->bl, SELF);
  15160. }
  15161. /**
  15162. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15163. **/
  15164. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15165. struct s_packet_db *info = NULL;
  15166. int cmd = 0;
  15167. nullpo_retv(sd);
  15168. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  15169. info = &packet_db[sd->packet_ver][cmd];
  15170. if (!cmd || !info->len)
  15171. return;
  15172. WFIFOHEAD(sd->fd, info->len);
  15173. WFIFOW(sd->fd, 0) = cmd;
  15174. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15175. WFIFOSET(sd->fd, info->len);
  15176. }
  15177. /// [Ind/Hercules]
  15178. void clif_showscript(struct block_list* bl, const char* message) {
  15179. char buf[256];
  15180. size_t len;
  15181. nullpo_retv(bl);
  15182. if(!message)
  15183. return;
  15184. len = strlen(message)+1;
  15185. if( len > sizeof(buf)-8 ) {
  15186. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15187. len = sizeof(buf)-8;
  15188. }
  15189. WBUFW(buf,0) = 0x8b3;
  15190. WBUFW(buf,2) = (len+8);
  15191. WBUFL(buf,4) = bl->id;
  15192. safestrncpy((char *) WBUFP(buf,8), message, len);
  15193. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, ALL_CLIENT);
  15194. }
  15195. /// [Ind/Hercules]
  15196. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15197. unsigned char buf[10];
  15198. nullpo_retv(sd);
  15199. WBUFW(buf,0) = 0x7fc;
  15200. WBUFL(buf,2) = prev_leader_aid;
  15201. WBUFL(buf,6) = new_leader_aid;
  15202. clif_send(buf,packet_len(0x7fc),&sd->bl,PARTY);
  15203. }
  15204. /**
  15205. * Decrypt packet identifier for player
  15206. * @param fd
  15207. * @param sd
  15208. * @param packet_ver
  15209. * Orig author [Ind/Hercules]
  15210. **/
  15211. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15212. #ifndef PACKET_OBFUSCATION
  15213. return RFIFOW(fd, 0);
  15214. #else
  15215. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15216. if (sd)
  15217. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15218. else
  15219. 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.
  15220. return cmd; // Return the decrypted packet ID.
  15221. #endif
  15222. }
  15223. #ifdef DUMP_UNKNOWN_PACKET
  15224. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15225. {
  15226. const char* packet_txt = "save/packet.txt";
  15227. FILE* fp;
  15228. time_t time_server;
  15229. struct tm *datetime;
  15230. char datestr[512];
  15231. time(&time_server); // get time in seconds since 1/1/1970
  15232. datetime = localtime(&time_server); // convert seconds in structure
  15233. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15234. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15235. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15236. if( sd ) {
  15237. 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);
  15238. } else {
  15239. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15240. }
  15241. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15242. fprintf(fp, "\n");
  15243. fclose(fp);
  15244. } else {
  15245. ShowError("Failed to write '%s'.\n", packet_txt);
  15246. // Dump on console instead
  15247. if( sd ) {
  15248. 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);
  15249. } else {
  15250. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15251. }
  15252. ShowDump(RFIFOP(fd,0), packet_len);
  15253. }
  15254. }
  15255. #endif
  15256. /// Roulette System
  15257. /// Author: Yommy
  15258. /**
  15259. * Opens Roulette window
  15260. * @param fd
  15261. * @param sd
  15262. */
  15263. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15264. {
  15265. nullpo_retv(sd);
  15266. if (!battle_config.feature_roulette) {
  15267. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15268. return;
  15269. }
  15270. WFIFOHEAD(fd,packet_len(0xa1a));
  15271. WFIFOW(fd,0) = 0xa1a;
  15272. WFIFOB(fd,2) = 0; // result
  15273. WFIFOL(fd,3) = 0; // serial
  15274. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15275. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15276. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15277. WFIFOL(fd,11) = sd->roulette_point.gold;
  15278. WFIFOL(fd,15) = sd->roulette_point.silver;
  15279. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15280. WFIFOSET(fd,packet_len(0xa1a));
  15281. }
  15282. /**
  15283. * Generates information to be displayed
  15284. * @param fd
  15285. * @param sd
  15286. */
  15287. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15288. {
  15289. unsigned short i, j, count = 0;
  15290. int len = 8 + (42 * 8);
  15291. nullpo_retv(sd);
  15292. if (!battle_config.feature_roulette) {
  15293. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15294. return;
  15295. }
  15296. WFIFOHEAD(fd,len);
  15297. WFIFOW(fd,0) = 0xa1c;
  15298. WFIFOW(fd,2) = len;
  15299. WFIFOL(fd,4) = 1; // serial
  15300. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15301. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15302. WFIFOW(fd,8 * count + 8) = i;
  15303. WFIFOW(fd,8 * count + 10) = j;
  15304. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15305. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15306. count++;
  15307. }
  15308. }
  15309. WFIFOSET(fd,len);
  15310. return;
  15311. }
  15312. /**
  15313. * Closes Roulette window
  15314. * @param fd
  15315. * @param sd
  15316. */
  15317. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15318. {
  15319. nullpo_retv(sd);
  15320. if (!battle_config.feature_roulette) {
  15321. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15322. return;
  15323. }
  15324. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15325. return;
  15326. }
  15327. /**
  15328. *
  15329. **/
  15330. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15331. #if PACKETVER >= 20141016
  15332. uint16 cmd = 0xa22;
  15333. unsigned char buf[5];
  15334. nullpo_retv(sd);
  15335. if (packet_db[sd->packet_ver][cmd].len == 0)
  15336. return;
  15337. WBUFW(buf,0) = cmd;
  15338. WBUFB(buf,2) = type;
  15339. WBUFW(buf,3) = 0; //! TODO: Additional item
  15340. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15341. #endif
  15342. }
  15343. /**
  15344. * Claim roulette reward
  15345. * @param sd Player
  15346. * @return 0:Success
  15347. **/
  15348. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15349. struct item it;
  15350. uint8 res = 1;
  15351. nullpo_retr(1, sd);
  15352. if (sd->roulette.prizeIdx < 0)
  15353. return RECV_ITEM_FAILED;
  15354. memset(&it, 0, sizeof(it));
  15355. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15356. it.identify = 1;
  15357. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15358. ; // onSuccess
  15359. }
  15360. sd->roulette.claimPrize = false;
  15361. sd->roulette.prizeStage = 0;
  15362. sd->roulette.prizeIdx = -1;
  15363. sd->roulette.stage = 0;
  15364. return res;
  15365. }
  15366. /**
  15367. * Process the stage and attempt to give a prize
  15368. * @param fd
  15369. * @param sd
  15370. */
  15371. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15372. {
  15373. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15374. short stage = sd->roulette.stage;
  15375. nullpo_retv(sd);
  15376. if (!battle_config.feature_roulette) {
  15377. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15378. return;
  15379. }
  15380. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15381. stage = sd->roulette.stage = 0;
  15382. if (!stage) {
  15383. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15384. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15385. }
  15386. if (result == GENERATE_ROULETTE_SUCCESS) {
  15387. if (!stage) {
  15388. if (sd->roulette_point.bronze > 0) {
  15389. sd->roulette_point.bronze -= 1;
  15390. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15391. } else if (sd->roulette_point.silver > 9) {
  15392. sd->roulette_point.silver -= 10;
  15393. stage = sd->roulette.stage = 2;
  15394. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15395. } else if (sd->roulette_point.gold > 9) {
  15396. sd->roulette_point.gold -= 10;
  15397. stage = sd->roulette.stage = 4;
  15398. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15399. }
  15400. }
  15401. sd->roulette.prizeStage = stage;
  15402. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15403. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15404. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15405. clif_roulette_getitem(sd);
  15406. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15407. return;
  15408. }
  15409. else {
  15410. sd->roulette.claimPrize = true;
  15411. sd->roulette.stage++;
  15412. }
  15413. }
  15414. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15415. }
  15416. /**
  15417. * Request to cash in prize
  15418. * @param fd
  15419. * @param sd
  15420. */
  15421. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15422. {
  15423. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15424. nullpo_retv(sd);
  15425. if (!battle_config.feature_roulette) {
  15426. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15427. return;
  15428. }
  15429. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15430. switch (clif_roulette_getitem(sd)) {
  15431. case 0:
  15432. type = RECV_ITEM_SUCCESS;
  15433. break;
  15434. case 1:
  15435. case 4:
  15436. case 5:
  15437. type = RECV_ITEM_OVERCOUNT;
  15438. break;
  15439. case 2:
  15440. type = RECV_ITEM_OVERWEIGHT;
  15441. break;
  15442. case 7:
  15443. default:
  15444. type = RECV_ITEM_FAILED;
  15445. break;
  15446. }
  15447. }
  15448. clif_roulette_recvitem_ack(sd,type);
  15449. return;
  15450. }
  15451. /**
  15452. * Update Roulette window with current stats
  15453. * @param sd
  15454. * @param result
  15455. * @param stage
  15456. * @param prizeIdx
  15457. * @param bonusItemID
  15458. */
  15459. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15460. {
  15461. int fd = sd->fd;
  15462. nullpo_retv(sd);
  15463. WFIFOHEAD(fd,packet_len(0xa20));
  15464. WFIFOW(fd,0) = 0xa20;
  15465. WFIFOB(fd,2) = result;
  15466. WFIFOW(fd,3) = stage;
  15467. WFIFOW(fd,5) = prizeIdx;
  15468. WFIFOW(fd,7) = bonusItemID;
  15469. WFIFOL(fd,9) = sd->roulette_point.gold;
  15470. WFIFOL(fd,13) = sd->roulette_point.silver;
  15471. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15472. WFIFOSET(fd,packet_len(0xa20));
  15473. }
  15474. /// MERGE ITEM
  15475. /**
  15476. * Acknowledge the client about item merger result
  15477. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15478. * @param fd
  15479. * @param sd
  15480. **/
  15481. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15482. unsigned char buf[9];
  15483. struct s_packet_db *info = NULL;
  15484. short cmd = 0;
  15485. nullpo_retv(sd);
  15486. if (!clif_session_isValid(sd))
  15487. return;
  15488. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15489. return;
  15490. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15491. return;
  15492. WBUFW(buf, 0) = cmd;
  15493. WBUFW(buf, info->pos[0]) = index;
  15494. WBUFW(buf, info->pos[1]) = count;
  15495. WBUFB(buf, info->pos[2]) = type;
  15496. clif_send(buf, info->len, &sd->bl, SELF);
  15497. }
  15498. /**
  15499. * Check if item has the pair to be merged
  15500. * @param sd
  15501. * @param it Item
  15502. * @return True if has pair, False if not
  15503. **/
  15504. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15505. struct item *it_;
  15506. unsigned short i;
  15507. nullpo_retr(false, sd);
  15508. ARR_FIND(0, MAX_INVENTORY, i, (it_ = &sd->status.inventory[i]) && it->nameid == it_->nameid && it->bound == it_->bound && memcmp(it_, it, sizeof(struct item)) != 0);
  15509. if (i < MAX_INVENTORY)
  15510. return true;
  15511. return false;
  15512. }
  15513. /**
  15514. * Check if item can be merged
  15515. * @param id Item Data
  15516. * @param it Item
  15517. * @return True if can be merged, False if not
  15518. **/
  15519. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15520. if (!id || !it)
  15521. return false;
  15522. if (id->type == IT_CASH)
  15523. return false;
  15524. if (!itemdb_isstackable2(id))
  15525. return false;
  15526. if (itemdb_isspecial(it->card[0]))
  15527. return false;
  15528. if (!it->unique_id)
  15529. return false;
  15530. return true;
  15531. }
  15532. /**
  15533. * Open available item to be merged.
  15534. * Only show 1 item in 1 process.
  15535. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15536. * @param sd
  15537. **/
  15538. void clif_merge_item_open(struct map_session_data *sd) {
  15539. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15540. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15541. int len = 0;
  15542. struct s_packet_db *info = NULL;
  15543. struct item *it;
  15544. nullpo_retv(sd);
  15545. if (!clif_session_isValid(sd))
  15546. return;
  15547. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15548. return;
  15549. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15550. return;
  15551. // Get entries
  15552. for (i = 0; i < MAX_INVENTORY; i++) {
  15553. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15554. continue;
  15555. if (clif_merge_item_has_pair(sd, it))
  15556. indexes[n++] = i;
  15557. }
  15558. if (n < 2) { // No item need to be merged
  15559. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15560. return;
  15561. }
  15562. WBUFW(buf, 0) = cmd;
  15563. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15564. for (i = 0; i < n; i++) {
  15565. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15566. }
  15567. clif_send(buf, len, &sd->bl, SELF);
  15568. }
  15569. /**
  15570. * Process item merger
  15571. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15572. * @param fd
  15573. * @param sd
  15574. **/
  15575. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15576. struct s_packet_db *info = NULL;
  15577. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15578. unsigned int count = 0;
  15579. struct item_data *id = NULL;
  15580. nullpo_retv(sd);
  15581. if (!clif_session_isValid(sd))
  15582. return;
  15583. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15584. return;
  15585. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15586. if (n < 2) { // No item need to be merged
  15587. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15588. return;
  15589. }
  15590. for (i = 0, j = 0; i < n; i++) {
  15591. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15592. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15593. continue;
  15594. indexes[j] = idx;
  15595. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15596. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15597. return;
  15598. }
  15599. count += sd->status.inventory[idx].amount;
  15600. j++;
  15601. }
  15602. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15603. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15604. return;
  15605. }
  15606. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15607. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15608. return;
  15609. }
  15610. // Merrrrge!!!!
  15611. for (i = 1; i < n; i++) {
  15612. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15613. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15614. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15615. sd->inventory_data[idx] = NULL;
  15616. clif_delitem(sd, idx, amt, 0);
  15617. }
  15618. sd->status.inventory[indexes[0]].amount = count;
  15619. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15620. }
  15621. /**
  15622. * Cancel item merge
  15623. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15624. * @param fd
  15625. * @param sd
  15626. **/
  15627. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15628. return; // Nothing todo yet
  15629. }
  15630. /**
  15631. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15632. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15633. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15634. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15635. **/
  15636. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type, const char *srcname) {
  15637. unsigned char buf[9 + NAME_LENGTH * 2];
  15638. unsigned short cmd = 0;
  15639. struct s_packet_db *info = NULL;
  15640. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15641. return;
  15642. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15643. return;
  15644. WBUFW(buf, 0) = 0x7fd;
  15645. WBUFB(buf, 4) = type;
  15646. WBUFW(buf, 5) = nameid;
  15647. WBUFB(buf, 7) = NAME_LENGTH;
  15648. safestrncpy((char *)WBUFP(buf, 8), char_name, NAME_LENGTH);
  15649. switch (type) {
  15650. case ITEMOBTAIN_TYPE_BOXITEM:
  15651. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15652. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15653. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15654. break;
  15655. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15656. {
  15657. struct mob_db *db = mob_db(container);
  15658. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15659. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15660. safestrncpy((char *)WBUFP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15661. }
  15662. break;
  15663. case ITEMOBTAIN_TYPE_NPC:
  15664. default:
  15665. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15666. break;
  15667. }
  15668. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15669. }
  15670. void clif_dressing_room(struct map_session_data *sd, int view)
  15671. {
  15672. int fd;
  15673. nullpo_retv(sd);
  15674. fd = sd->fd;
  15675. WFIFOHEAD(fd, packet_len(0xa02));
  15676. WFIFOW(fd,0) = 0xa02;
  15677. WFIFOW(fd,2) = view;
  15678. WFIFOSET(fd, packet_len(0xa02));
  15679. }
  15680. /*==========================================
  15681. * Main client packet processing function
  15682. *------------------------------------------*/
  15683. static int clif_parse(int fd)
  15684. {
  15685. int cmd, packet_ver, packet_len, err;
  15686. TBL_PC* sd;
  15687. int pnum;
  15688. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15689. // Note: "click masters" can do 80+ clicks in 10 seconds
  15690. 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]
  15691. { // begin main client packet processing loop
  15692. sd = (TBL_PC *)session[fd]->session_data;
  15693. if (session[fd]->flag.eof) {
  15694. if (sd) {
  15695. if (sd->state.autotrade) {
  15696. //Disassociate character from the socket connection.
  15697. session[fd]->session_data = NULL;
  15698. sd->fd = 0;
  15699. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15700. } else
  15701. if (sd->state.active) {
  15702. // Player logout display [Valaris]
  15703. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15704. clif_quitsave(fd, sd);
  15705. } else {
  15706. //Unusual logout (during log on/off/map-changer procedure)
  15707. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15708. map_quit(sd);
  15709. }
  15710. } else {
  15711. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15712. }
  15713. do_close(fd);
  15714. return 0;
  15715. }
  15716. if (RFIFOREST(fd) < 2)
  15717. return 0;
  15718. cmd = clif_parse_cmd(fd, sd);
  15719. // identify client's packet version
  15720. if (sd) {
  15721. packet_ver = sd->packet_ver;
  15722. } else {
  15723. // check authentification packet to know packet version
  15724. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15725. if( err ) {// failed to identify packet version
  15726. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15727. err == 1 ? "" :
  15728. err == 2 ? ", possibly for having an invalid account_id" :
  15729. err == 3 ? ", possibly for having an invalid char_id." :
  15730. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15731. err == 4 ? ", possibly for having an invalid login_id1." :
  15732. err == 5 ? ", possibly for having an invalid client_tick." :
  15733. */
  15734. err == 6 ? ", possibly for having an invalid sex." :
  15735. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15736. WFIFOHEAD(fd,packet_len(0x6a));
  15737. WFIFOW(fd,0) = 0x6a;
  15738. WFIFOB(fd,2) = 3; // Rejected from Server
  15739. WFIFOSET(fd,packet_len(0x6a));
  15740. #ifdef DUMP_INVALID_PACKET
  15741. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15742. #endif
  15743. RFIFOSKIP(fd, RFIFOREST(fd));
  15744. set_eof(fd);
  15745. return 0;
  15746. }
  15747. }
  15748. // filter out invalid / unsupported packets
  15749. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15750. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15751. #ifdef DUMP_INVALID_PACKET
  15752. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15753. #endif
  15754. set_eof(fd);
  15755. return 0;
  15756. }
  15757. // determine real packet length
  15758. packet_len = packet_db[packet_ver][cmd].len;
  15759. if (packet_len == -1) { // variable-length packet
  15760. if (RFIFOREST(fd) < 4)
  15761. return 0;
  15762. packet_len = RFIFOW(fd,2);
  15763. if (packet_len < 4 || packet_len > 32768) {
  15764. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15765. #ifdef DUMP_INVALID_PACKET
  15766. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15767. #endif
  15768. set_eof(fd);
  15769. return 0;
  15770. }
  15771. }
  15772. if ((int)RFIFOREST(fd) < packet_len)
  15773. return 0; // not enough data received to form the packet
  15774. #ifdef PACKET_OBFUSCATION
  15775. RFIFOW(fd, 0) = cmd;
  15776. if (sd)
  15777. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15778. #endif
  15779. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15780. packet_db[packet_ver][cmd].func(fd, sd);
  15781. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15782. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15783. ; //Only valid packet when there is no session
  15784. else
  15785. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15786. ; //Only valid packet when player is not on a map
  15787. else
  15788. packet_db[packet_ver][cmd].func(fd, sd);
  15789. }
  15790. #ifdef DUMP_UNKNOWN_PACKET
  15791. else DumpUnknown(fd,sd,cmd,packet_len);
  15792. #endif
  15793. RFIFOSKIP(fd, packet_len);
  15794. }; // main loop end
  15795. return 0;
  15796. }
  15797. /*==========================================
  15798. * Reads packet_db.txt and setups its array reference
  15799. *------------------------------------------*/
  15800. void packetdb_readdb(bool reload)
  15801. {
  15802. char line[1024];
  15803. int cmd,i,j;
  15804. int max_cmd=-1;
  15805. bool skip_ver = false;
  15806. int warned = 0;
  15807. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15808. #ifdef PACKET_OBFUSCATION
  15809. bool key_defined = false;
  15810. int last_key_defined = -1;
  15811. #endif
  15812. int packet_len_table[MAX_PACKET_DB] = {
  15813. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15817. //#0x0040
  15818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15820. #if PACKETVER <= 20081217
  15821. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  15822. #else
  15823. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  15824. #endif
  15825. #if PACKETVER < 2
  15826. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  15827. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  15828. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  15829. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  15830. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  15831. #else
  15832. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  15833. #endif
  15834. //#0x0080
  15835. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  15836. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  15837. #if PACKETVER <= 20100622
  15838. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  15839. #else
  15840. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  15841. #endif
  15842. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  15843. //#0x00C0
  15844. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  15845. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  15846. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  15847. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  15848. //#0x0100
  15849. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  15850. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  15851. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  15852. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  15853. //#0x0140
  15854. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  15855. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  15856. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  15857. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  15858. //#0x0180
  15859. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  15860. #if PACKETVER < 1
  15861. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15862. #else // 196 comodo icon status display for later
  15863. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  15864. #endif
  15865. #if PACKETVER < 20081126
  15866. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15867. #else // 0x1a2 changed (35->37)
  15868. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  15869. #endif
  15870. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  15871. //#0x01C0, Set 0x1d5=-1
  15872. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  15873. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  15874. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  15875. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  15876. //#0x0200
  15877. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  15878. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  15879. #if PACKETVER < 20071106
  15880. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  15881. #else // 0x22c changed
  15882. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  15883. #endif
  15884. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  15885. //#0x0240
  15886. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  15887. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  15888. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15889. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15890. //#0x0280
  15891. #if PACKETVER < 20070711
  15892. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  15893. #else
  15894. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  15895. #endif
  15896. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  15897. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15898. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  15899. //#0x02C0
  15900. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  15901. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  15902. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  15903. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15904. //#0x0300
  15905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15909. //#0x0340
  15910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15914. //#0x0380
  15915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15919. //#0x03C0
  15920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15924. //#0x0400
  15925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  15929. //#0x0440
  15930. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  15931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15934. //#0x0480
  15935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15939. //#0x04C0
  15940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15944. //#0x0500
  15945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15949. //#0x0540
  15950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15954. //#0x0580
  15955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15959. //#0x05C0
  15960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15964. //#0x0600
  15965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15969. //#0x0640
  15970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15974. //#0x0680
  15975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15979. //#0x06C0
  15980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15984. //#0x0700
  15985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15989. //#0x0740
  15990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15994. //#0x0780
  15995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15999. //#0x07C0
  16000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16001. #if PACKETVER < 20090617
  16002. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  16003. #else // 0x7d9 changed
  16004. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  16005. #endif
  16006. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  16007. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  16008. //#0x0800
  16009. #if PACKETVER < 20091229
  16010. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  16011. #else // for Party booking ( PACKETVER >= 20091229 )
  16012. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  16013. #endif
  16014. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  16015. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16016. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  16017. //#0x0840
  16018. #if PACKETVER < 20130000
  16019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16020. #else
  16021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  16022. #endif
  16023. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  16024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16026. //#0x0880
  16027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16030. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16031. //#0x08C0
  16032. 0, 0, 0, 0, 0, 0, 0, 20, 34, 0, 0, 0, 0, 0, 0, 10,
  16033. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16036. //#0x0900
  16037. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  16038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16041. //#0x0940
  16042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  16045. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, -1, 0, 0, 0, 0, 0,
  16046. //#0x0980
  16047. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16048. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  16049. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  16050. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  16051. //#0x09C0
  16052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0,102, 0,
  16053. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, -1, -1, -1, 0, 7,
  16054. 0, 0, 0, 0, 0, 0, 0, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  16055. 0, 11, 12, 11, 0, 0, 0, 75, -1,143, 0, 0, 0, -1, -1, -1,
  16056. //#0x0A00
  16057. #if PACKETVER >= 20141022
  16058. 269, 3, 4, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 0, -1,
  16059. #else
  16060. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 0, 0,
  16061. #endif
  16062. -1, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  16063. 21, 3, 5, 0, 66, 0, 0, 0, 3, 0, 0, 0, 0, -1, 0, 0,
  16064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16065. };
  16066. struct {
  16067. void (*func)(int, struct map_session_data *);
  16068. char *name;
  16069. } clif_parse_func[]={
  16070. {clif_parse_WantToConnection,"wanttoconnection"},
  16071. {clif_parse_LoadEndAck,"loadendack"},
  16072. {clif_parse_TickSend,"ticksend"},
  16073. {clif_parse_WalkToXY,"walktoxy"},
  16074. {clif_parse_QuitGame,"quitgame"},
  16075. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  16076. {clif_parse_GlobalMessage,"globalmessage"},
  16077. {clif_parse_MapMove,"mapmove"},
  16078. {clif_parse_ChangeDir,"changedir"},
  16079. {clif_parse_Emotion,"emotion"},
  16080. {clif_parse_HowManyConnections,"howmanyconnections"},
  16081. {clif_parse_ActionRequest,"actionrequest"},
  16082. {clif_parse_Restart,"restart"},
  16083. {clif_parse_WisMessage,"wis"},
  16084. {clif_parse_Broadcast,"broadcast"},
  16085. {clif_parse_TakeItem,"takeitem"},
  16086. {clif_parse_DropItem,"dropitem"},
  16087. {clif_parse_UseItem,"useitem"},
  16088. {clif_parse_EquipItem,"equipitem"},
  16089. {clif_parse_UnequipItem,"unequipitem"},
  16090. {clif_parse_NpcClicked,"npcclicked"},
  16091. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  16092. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  16093. {clif_parse_NpcSellListSend,"npcselllistsend"},
  16094. {clif_parse_CreateChatRoom,"createchatroom"},
  16095. {clif_parse_ChatAddMember,"chataddmember"},
  16096. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  16097. {clif_parse_ChangeChatOwner,"changechatowner"},
  16098. {clif_parse_KickFromChat,"kickfromchat"},
  16099. {clif_parse_ChatLeave,"chatleave"},
  16100. {clif_parse_TradeRequest,"traderequest"},
  16101. {clif_parse_TradeAck,"tradeack"},
  16102. {clif_parse_TradeAddItem,"tradeadditem"},
  16103. {clif_parse_TradeOk,"tradeok"},
  16104. {clif_parse_TradeCancel,"tradecancel"},
  16105. {clif_parse_TradeCommit,"tradecommit"},
  16106. {clif_parse_StopAttack,"stopattack"},
  16107. {clif_parse_PutItemToCart,"putitemtocart"},
  16108. {clif_parse_GetItemFromCart,"getitemfromcart"},
  16109. {clif_parse_RemoveOption,"removeoption"},
  16110. {clif_parse_ChangeCart,"changecart"},
  16111. {clif_parse_StatusUp,"statusup"},
  16112. {clif_parse_SkillUp,"skillup"},
  16113. {clif_parse_UseSkillToId,"useskilltoid"},
  16114. {clif_parse_UseSkillToPos,"useskilltopos"},
  16115. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  16116. {clif_parse_UseSkillMap,"useskillmap"},
  16117. {clif_parse_RequestMemo,"requestmemo"},
  16118. {clif_parse_ProduceMix,"producemix"},
  16119. {clif_parse_Cooking,"cooking"},
  16120. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  16121. {clif_parse_NpcNextClicked,"npcnextclicked"},
  16122. {clif_parse_NpcAmountInput,"npcamountinput"},
  16123. {clif_parse_NpcStringInput,"npcstringinput"},
  16124. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  16125. {clif_parse_ItemIdentify,"itemidentify"},
  16126. {clif_parse_SelectArrow,"selectarrow"},
  16127. {clif_parse_AutoSpell,"autospell"},
  16128. {clif_parse_UseCard,"usecard"},
  16129. {clif_parse_InsertCard,"insertcard"},
  16130. {clif_parse_RepairItem,"repairitem"},
  16131. {clif_parse_WeaponRefine,"weaponrefine"},
  16132. {clif_parse_SolveCharName,"solvecharname"},
  16133. {clif_parse_ResetChar,"resetchar"},
  16134. {clif_parse_LocalBroadcast,"localbroadcast"},
  16135. {clif_parse_MoveToKafra,"movetokafra"},
  16136. {clif_parse_MoveFromKafra,"movefromkafra"},
  16137. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  16138. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  16139. {clif_parse_CloseKafra,"closekafra"},
  16140. {clif_parse_CreateParty,"createparty"},
  16141. {clif_parse_CreateParty2,"createparty2"},
  16142. {clif_parse_PartyInvite,"partyinvite"},
  16143. {clif_parse_PartyInvite2,"partyinvite2"},
  16144. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  16145. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  16146. {clif_parse_LeaveParty,"leaveparty"},
  16147. {clif_parse_RemovePartyMember,"removepartymember"},
  16148. {clif_parse_PartyChangeOption,"partychangeoption"},
  16149. {clif_parse_PartyMessage,"partymessage"},
  16150. {clif_parse_PartyChangeLeader,"partychangeleader"},
  16151. {clif_parse_CloseVending,"closevending"},
  16152. {clif_parse_VendingListReq,"vendinglistreq"},
  16153. {clif_parse_PurchaseReq,"purchasereq"},
  16154. {clif_parse_PurchaseReq2,"purchasereq2"},
  16155. {clif_parse_OpenVending,"openvending"},
  16156. {clif_parse_CreateGuild,"createguild"},
  16157. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  16158. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  16159. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  16160. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  16161. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  16162. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  16163. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  16164. {clif_parse_GuildInvite,"guildinvite"},
  16165. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  16166. {clif_parse_GuildLeave,"guildleave"},
  16167. {clif_parse_GuildExpulsion,"guildexpulsion"},
  16168. {clif_parse_GuildMessage,"guildmessage"},
  16169. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  16170. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  16171. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  16172. {clif_parse_GuildOpposition,"guildopposition"},
  16173. {clif_parse_GuildBreak,"guildbreak"},
  16174. {clif_parse_PetMenu,"petmenu"},
  16175. {clif_parse_CatchPet,"catchpet"},
  16176. {clif_parse_SelectEgg,"selectegg"},
  16177. {clif_parse_SendEmotion,"sendemotion"},
  16178. {clif_parse_ChangePetName,"changepetname"},
  16179. {clif_parse_GMKick,"gmkick"},
  16180. {clif_parse_GMHide,"gmhide"},
  16181. {clif_parse_GMReqNoChat,"gmreqnochat"},
  16182. {clif_parse_GMReqAccountName,"gmreqaccname"},
  16183. {clif_parse_GMKickAll,"killall"},
  16184. {clif_parse_GMRecall,"recall"},
  16185. {clif_parse_GMRecall,"summon"},
  16186. {clif_parse_GM_Item_Monster,"itemmonster"},
  16187. {clif_parse_GMShift,"remove"},
  16188. {clif_parse_GMShift,"shift"},
  16189. {clif_parse_GMChangeMapType,"changemaptype"},
  16190. {clif_parse_GMRc,"rc"},
  16191. {clif_parse_GMRecall2,"recall2"},
  16192. {clif_parse_GMRemove2,"remove2"},
  16193. {clif_parse_GMFullStrip,"gmfullstrip"},
  16194. {clif_parse_NoviceDoriDori,"sndoridori"},
  16195. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  16196. {clif_parse_PMIgnore,"wisexin"},
  16197. {clif_parse_PMIgnoreList,"wisexlist"},
  16198. {clif_parse_PMIgnoreAll,"wisall"},
  16199. {clif_parse_FriendsListAdd,"friendslistadd"},
  16200. {clif_parse_FriendsListRemove,"friendslistremove"},
  16201. {clif_parse_FriendsListReply,"friendslistreply"},
  16202. {clif_parse_Blacksmith,"blacksmith"},
  16203. {clif_parse_Alchemist,"alchemist"},
  16204. {clif_parse_Taekwon,"taekwon"},
  16205. {clif_parse_RankingPk,"rankingpk"},
  16206. {clif_parse_FeelSaveOk,"feelsaveok"},
  16207. {clif_parse_debug,"debug"},
  16208. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16209. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16210. {clif_parse_HomMoveTo,"hommoveto"},
  16211. {clif_parse_HomAttack,"homattack"},
  16212. {clif_parse_HomMenu,"hommenu"},
  16213. {clif_parse_StoragePassword,"storagepassword"},
  16214. {clif_parse_Hotkey,"hotkey"},
  16215. {clif_parse_AutoRevive,"autorevive"},
  16216. {clif_parse_Check,"check"},
  16217. {clif_parse_Adopt_request,"adoptrequest"},
  16218. {clif_parse_Adopt_reply,"adoptreply"},
  16219. // MAIL SYSTEM
  16220. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16221. {clif_parse_Mail_read,"mailread"},
  16222. {clif_parse_Mail_getattach,"mailgetattach"},
  16223. {clif_parse_Mail_delete,"maildelete"},
  16224. {clif_parse_Mail_return,"mailreturn"},
  16225. {clif_parse_Mail_setattach,"mailsetattach"},
  16226. {clif_parse_Mail_winopen,"mailwinopen"},
  16227. {clif_parse_Mail_send,"mailsend"},
  16228. // AUCTION SYSTEM
  16229. {clif_parse_Auction_search,"auctionsearch"},
  16230. {clif_parse_Auction_buysell,"auctionbuysell"},
  16231. {clif_parse_Auction_setitem,"auctionsetitem"},
  16232. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16233. {clif_parse_Auction_register,"auctionregister"},
  16234. {clif_parse_Auction_cancel,"auctioncancel"},
  16235. {clif_parse_Auction_close,"auctionclose"},
  16236. {clif_parse_Auction_bid,"auctionbid"},
  16237. // Quest Log System
  16238. {clif_parse_questStateAck,"queststate"},
  16239. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16240. {clif_parse_EquipTick,"equiptickbox"},
  16241. {clif_parse_BattleChat,"battlechat"},
  16242. {clif_parse_mercenary_action,"mermenu"},
  16243. {clif_parse_progressbar,"progressbar"},
  16244. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16245. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16246. #if PACKETVER >= 20091229
  16247. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16248. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16249. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16250. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16251. #endif
  16252. {clif_parse_BankCheck,"bankcheck"},
  16253. {clif_parse_BankDeposit,"bankdeposit"},
  16254. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16255. {clif_parse_BankOpen,"bankopen"},
  16256. {clif_parse_BankClose,"bankclose"},
  16257. {clif_parse_PVPInfo,"pvpinfo"},
  16258. {clif_parse_LessEffect,"lesseffect"},
  16259. // Buying Store
  16260. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16261. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16262. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16263. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16264. // Store Search
  16265. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16266. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16267. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16268. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16269. // Cashshop
  16270. { clif_parse_cashshop_open_request, "cashshopopen" },
  16271. { clif_parse_cashshop_close, "cashshopclose" },
  16272. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16273. { clif_parse_cashshop_buy, "cashshopbuy" },
  16274. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16275. /* */
  16276. { clif_parse_MoveItem , "moveitem" },
  16277. { clif_parse_PartyTick, "partytick" },
  16278. { clif_parse_dull, "dull" },
  16279. { clif_parse_GuildInvite2 , "guildinvite2" },
  16280. { clif_parse_reqworldinfo, "reqworldinfo"},
  16281. { clif_parse_client_version, "clientversion"},
  16282. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16283. { clif_parse_ranklist, "ranklist"},
  16284. // Market NPC
  16285. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16286. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16287. // Roulette
  16288. { clif_parse_RouletteOpen, "rouletteopen" },
  16289. { clif_parse_RouletteInfo, "rouletteinfo" },
  16290. { clif_parse_RouletteClose, "rouletteclose" },
  16291. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16292. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16293. // Merge Item
  16294. { clif_parse_merge_item_req, "mergeitem_req"},
  16295. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16296. // HotkeyRowShift
  16297. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16298. {NULL,NULL}
  16299. };
  16300. struct {
  16301. char *name; //function name
  16302. int funcidx; //
  16303. } clif_ack_func[]={ //hash
  16304. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16305. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16306. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16307. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16308. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16309. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16310. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16311. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16312. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16313. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16314. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16315. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16316. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16317. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16318. };
  16319. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16320. int f;
  16321. memset(packet_db,0,sizeof(packet_db));
  16322. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16323. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16324. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16325. packet_len(i) = packet_len_table[i];
  16326. clif_config.packet_db_ver = MAX_PACKET_VER;
  16327. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16328. FILE *fp;
  16329. int ln = 0;
  16330. int entries = 0;
  16331. char *str[64], *p, *str2[64], *p2;
  16332. sprintf(line, "%s/%s", db_path, filename[f]);
  16333. if( (fp = fopen(line,"r")) == NULL ) {
  16334. if (f == 0) {
  16335. ShowFatalError("Can't read %s\n", line);
  16336. exit(EXIT_FAILURE);
  16337. }
  16338. return;
  16339. }
  16340. while( fgets(line, sizeof(line), fp) ) {
  16341. char w1[256],w2[256];
  16342. ln++;
  16343. if(line[0]=='/' && line[1]=='/')
  16344. continue;
  16345. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16346. if (strcmpi(w1,"packet_ver") == 0) {
  16347. int prev_ver = packet_ver;
  16348. skip_ver = false;
  16349. packet_ver = atoi(w2);
  16350. if ( packet_ver > MAX_PACKET_VER )
  16351. { //Check to avoid overflowing. [Skotlex]
  16352. if( (warned&1) == 0 )
  16353. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16354. warned &= 1;
  16355. skip_ver = true;
  16356. }
  16357. else if( packet_ver < 0 )
  16358. {
  16359. if( (warned&2) == 0 )
  16360. ShowWarning("Negative packet versions are not supported.\n");
  16361. warned &= 2;
  16362. skip_ver = true;
  16363. }
  16364. else if( packet_ver == SERVER )
  16365. {
  16366. if( (warned&4) == 0 )
  16367. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16368. warned &= 4;
  16369. skip_ver = true;
  16370. }
  16371. if( skip_ver )
  16372. {
  16373. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16374. packet_ver = prev_ver;
  16375. continue;
  16376. }
  16377. // copy from previous version into new version and continue
  16378. // - indicating all following packets should be read into the newer version
  16379. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16380. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16381. continue;
  16382. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16383. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16384. clif_config.packet_db_ver = MAX_PACKET_VER;
  16385. else // to manually set the packet DB version
  16386. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16387. continue;
  16388. }
  16389. #ifdef PACKET_OBFUSCATION
  16390. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16391. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16392. trim(w2);
  16393. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16394. if (!packet_keys[packet_ver])
  16395. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16396. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16397. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16398. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16399. last_key_defined = packet_ver;
  16400. if (battle_config.etc_log)
  16401. 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]);
  16402. }
  16403. continue;
  16404. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16405. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16406. trim(w2);
  16407. if (strcmpi(w2,"default") == 0)
  16408. continue;
  16409. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16410. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16411. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16412. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16413. key_defined = true;
  16414. if (battle_config.etc_log)
  16415. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16416. }
  16417. continue;
  16418. }
  16419. #endif
  16420. }
  16421. if( skip_ver )
  16422. continue; // Skipping current packet version
  16423. memset(str,0,sizeof(str));
  16424. for (j = 0, p = line; j < 4 && p; ++j) {
  16425. str[j] = p;
  16426. p = strchr(p,',');
  16427. if (p)
  16428. *p++=0;
  16429. }
  16430. if (str[0] == NULL)
  16431. continue;
  16432. cmd = strtol(str[0],(char **)NULL,0);
  16433. if(max_cmd < cmd)
  16434. max_cmd = cmd;
  16435. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16436. continue;
  16437. if(str[1]==NULL){
  16438. ShowError("packet_db: packet len error\n");
  16439. continue;
  16440. }
  16441. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16442. if(str[2]==NULL){
  16443. packet_db[packet_ver][cmd].func = NULL;
  16444. ln++;
  16445. continue;
  16446. }
  16447. // look up processing function by name
  16448. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16449. if( j < ARRAYLENGTH(clif_parse_func) )
  16450. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16451. else { //search if it's a mapped ack func
  16452. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16453. if( j < ARRAYLENGTH(clif_ack_func)) {
  16454. int fidx = clif_ack_func[j].funcidx;
  16455. packet_db_ack[packet_ver][fidx] = cmd;
  16456. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16457. }
  16458. }
  16459. // set the identifying cmd for the packet_db version
  16460. if (strcmp(str[2],"wanttoconnection")==0)
  16461. clif_config.connect_cmd[packet_ver] = cmd;
  16462. if(str[3]==NULL){
  16463. ShowError("packet_db: packet error\n");
  16464. exit(EXIT_FAILURE);
  16465. }
  16466. for(j = 0, p2 = str[3]; p2; j++){
  16467. short k;
  16468. str2[j] = p2;
  16469. p2 = strchr(p2,':');
  16470. if(p2)
  16471. *p2++=0;
  16472. k = atoi(str2[j]);
  16473. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16474. if( j >= MAX_PACKET_POS )
  16475. {
  16476. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16477. break;
  16478. }
  16479. packet_db[packet_ver][cmd].pos[j] = k;
  16480. }
  16481. entries++;
  16482. }
  16483. fclose(fp);
  16484. if(max_cmd > MAX_PACKET_DB) {
  16485. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16486. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16487. }
  16488. //Locate the nearest version that we still support. [Skotlex]
  16489. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16490. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16491. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16492. }
  16493. sprintf(line, "%s/%s", db_path,filename[f]);
  16494. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16495. }
  16496. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16497. #ifdef PACKET_OBFUSCATION
  16498. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16499. int use_key = last_key_defined;
  16500. if (last_key_defined == -1)
  16501. ShowError("Can't find packet obfuscation keys!\n");
  16502. else {
  16503. if (packet_keys[clif_config.packet_db_ver])
  16504. use_key = clif_config.packet_db_ver;
  16505. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16506. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16507. }
  16508. }
  16509. 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]);
  16510. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16511. if (packet_keys[i]) {
  16512. aFree(packet_keys[i]);
  16513. packet_keys[i] = NULL;
  16514. }
  16515. }
  16516. #endif
  16517. }
  16518. /*==========================================
  16519. *
  16520. *------------------------------------------*/
  16521. void do_init_clif(void) {
  16522. const char* colors[COLOR_MAX] = {
  16523. "0x00FF00",
  16524. "0xFF0000",
  16525. "0xFFFFFF",
  16526. "0xFFFF00",
  16527. };
  16528. int i;
  16529. /**
  16530. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16531. **/
  16532. for(i = 0; i < COLOR_MAX; i++) {
  16533. color_table[i] = strtoul(colors[i],NULL,0);
  16534. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16535. }
  16536. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16537. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16538. #ifdef PACKET_OBFUSCATION
  16539. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16540. #endif
  16541. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16542. packetdb_readdb(false);
  16543. set_defaultparse(clif_parse);
  16544. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16545. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16546. exit(EXIT_FAILURE);
  16547. }
  16548. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16549. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16550. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16551. }
  16552. void do_final_clif(void) {
  16553. ers_destroy(delay_clearunit_ers);
  16554. }