clif.c 564 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601
  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. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  555. void clif_authok(struct map_session_data *sd)
  556. {
  557. #if PACKETVER < 20080102
  558. const int cmd = 0x73;
  559. #elif PACKETVER < 20141022
  560. const int cmd = 0x2eb;
  561. #else
  562. const int cmd = 0xa18;
  563. #endif
  564. int fd = sd->fd;
  565. WFIFOHEAD(fd,packet_len(cmd));
  566. WFIFOW(fd, 0) = cmd;
  567. WFIFOL(fd, 2) = gettick();
  568. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  569. WFIFOB(fd, 9) = 5; // ignored
  570. WFIFOB(fd,10) = 5; // ignored
  571. #if PACKETVER >= 20080102
  572. WFIFOW(fd,11) = sd->status.font;
  573. #endif
  574. #if PACKETVER >= 20141016
  575. WFIFOB(fd,13) = sd->status.sex;
  576. #endif
  577. WFIFOSET(fd,packet_len(cmd));
  578. }
  579. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  580. /// 0074 <error code>.B
  581. /// error code:
  582. /// 0 = client type mismatch
  583. /// 1 = ID mismatch
  584. /// 2 = mobile - out of available time
  585. /// 3 = mobile - already logged in
  586. /// 4 = mobile - waiting state
  587. void clif_authrefuse(int fd, uint8 error_code)
  588. {
  589. WFIFOHEAD(fd,packet_len(0x74));
  590. WFIFOW(fd,0) = 0x74;
  591. WFIFOB(fd,2) = error_code;
  592. WFIFOSET(fd,packet_len(0x74));
  593. }
  594. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  595. /// 0081 <error code>.B
  596. /// error code:
  597. /// 0 = BAN_UNFAIR
  598. /// 1 = server closed -> MsgStringTable[4]
  599. /// 2 = ID already logged in -> MsgStringTable[5]
  600. /// 3 = timeout/too much lag -> MsgStringTable[241]
  601. /// 4 = server full -> MsgStringTable[264]
  602. /// 5 = underaged -> MsgStringTable[305]
  603. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  604. /// 9 = too many connections from this ip -> MsgStringTable[529]
  605. /// 10 = out of available time paid for -> MsgStringTable[530]
  606. /// 11 = BAN_PAY_SUSPEND
  607. /// 12 = BAN_PAY_CHANGE
  608. /// 13 = BAN_PAY_WRONGIP
  609. /// 14 = BAN_PAY_PNGAMEROOM
  610. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  611. /// 16 = BAN_JAPAN_REFUSE1
  612. /// 17 = BAN_JAPAN_REFUSE2
  613. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  614. /// 100 = BAN_PC_IP_UNFAIR
  615. /// 101 = BAN_PC_IP_COUNT_ALL
  616. /// 102 = BAN_PC_IP_COUNT
  617. /// 103 = BAN_GRAVITY_MEM_AGREE
  618. /// 104 = BAN_GAME_MEM_AGREE
  619. /// 105 = BAN_HAN_VALID
  620. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  621. /// 107 = BAN_OVER_CHARACTER_LIST
  622. /// 108 = BAN_IP_BLOCK
  623. /// 109 = BAN_INVALID_PWD_CNT
  624. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  625. /// ? = disconnected -> MsgStringTable[3]
  626. void clif_authfail_fd(int fd, int type)
  627. {
  628. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  629. return;
  630. WFIFOHEAD(fd, packet_len(0x81));
  631. WFIFOW(fd,0) = 0x81;
  632. WFIFOB(fd,2) = type;
  633. WFIFOSET(fd,packet_len(0x81));
  634. set_eof(fd);
  635. }
  636. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  637. /// 00b3 <type>.B
  638. /// type:
  639. /// 1 = disconnect, char-select
  640. /// ? = nothing
  641. void clif_charselectok(int id, uint8 ok)
  642. {
  643. struct map_session_data* sd;
  644. int fd;
  645. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  646. return;
  647. fd = sd->fd;
  648. WFIFOHEAD(fd,packet_len(0xb3));
  649. WFIFOW(fd,0) = 0xb3;
  650. WFIFOB(fd,2) = ok;
  651. WFIFOSET(fd,packet_len(0xb3));
  652. }
  653. /// Makes an item appear on the ground.
  654. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  655. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  656. void clif_dropflooritem(struct flooritem_data* fitem)
  657. {
  658. #if PACKETVER >= 20130000
  659. uint8 buf[19];
  660. uint32 header=0x84b;
  661. #else
  662. uint8 buf[17];
  663. uint32 header=0x09e;
  664. #endif
  665. int view, offset=0;
  666. nullpo_retv(fitem);
  667. if (fitem->item.nameid == 0)
  668. return;
  669. WBUFW(buf, offset+0) = header;
  670. WBUFL(buf, offset+2) = fitem->bl.id;
  671. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  672. #if PACKETVER >= 20130000
  673. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  674. offset +=2;
  675. #endif
  676. WBUFB(buf, offset+8) = fitem->item.identify;
  677. WBUFW(buf, offset+9) = fitem->bl.x;
  678. WBUFW(buf, offset+11) = fitem->bl.y;
  679. WBUFB(buf, offset+13) = fitem->subx;
  680. WBUFB(buf, offset+14) = fitem->suby;
  681. WBUFW(buf, offset+15) = fitem->item.amount;
  682. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  683. }
  684. /// Makes an item disappear from the ground.
  685. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  686. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  687. {
  688. unsigned char buf[16];
  689. nullpo_retv(fitem);
  690. WBUFW(buf,0) = 0xa1;
  691. WBUFL(buf,2) = fitem->bl.id;
  692. if (fd == 0) {
  693. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  694. } else {
  695. WFIFOHEAD(fd,packet_len(0xa1));
  696. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  697. WFIFOSET(fd,packet_len(0xa1));
  698. }
  699. }
  700. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  701. /// 0080 <id>.L <type>.B
  702. /// type:
  703. /// 0 = out of sight
  704. /// 1 = died
  705. /// 2 = logged out
  706. /// 3 = teleport
  707. /// 4 = trickdead
  708. void clif_clearunit_single(int id, clr_type type, int fd)
  709. {
  710. WFIFOHEAD(fd, packet_len(0x80));
  711. WFIFOW(fd,0) = 0x80;
  712. WFIFOL(fd,2) = id;
  713. WFIFOB(fd,6) = type;
  714. WFIFOSET(fd, packet_len(0x80));
  715. }
  716. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  717. /// 0080 <id>.L <type>.B
  718. /// type:
  719. /// 0 = out of sight
  720. /// 1 = died
  721. /// 2 = logged out
  722. /// 3 = teleport
  723. /// 4 = trickdead
  724. void clif_clearunit_area(struct block_list* bl, clr_type type)
  725. {
  726. unsigned char buf[8];
  727. nullpo_retv(bl);
  728. WBUFW(buf,0) = 0x80;
  729. WBUFL(buf,2) = bl->id;
  730. WBUFB(buf,6) = type;
  731. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  732. if(disguised(bl)) {
  733. WBUFL(buf,2) = -bl->id;
  734. clif_send(buf, packet_len(0x80), bl, SELF);
  735. }
  736. }
  737. /// Used to make monsters with player-sprites disappear after dying
  738. /// like normal monsters, because the client does not remove those
  739. /// automatically.
  740. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  741. {
  742. struct block_list *bl = (struct block_list *)data;
  743. clif_clearunit_area(bl, (clr_type) id);
  744. ers_free(delay_clearunit_ers,bl);
  745. return 0;
  746. }
  747. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  748. {
  749. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  750. memcpy (tbl, bl, sizeof (struct block_list));
  751. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  752. }
  753. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  754. {
  755. if(sd->sc.option&OPTION_COSTUME)
  756. {
  757. *rhand = *lhand = 0;
  758. return;
  759. }
  760. #if PACKETVER < 4
  761. *rhand = sd->status.weapon;
  762. *lhand = sd->status.shield;
  763. #else
  764. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  765. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  766. {
  767. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  768. if (id->view_id > 0)
  769. *rhand = id->view_id;
  770. else
  771. *rhand = id->nameid;
  772. } else
  773. *rhand = 0;
  774. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  775. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  776. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  777. {
  778. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  779. if (id->view_id > 0)
  780. *lhand = id->view_id;
  781. else
  782. *lhand = id->nameid;
  783. } else
  784. *lhand = 0;
  785. #endif
  786. }
  787. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  788. static int clif_setlevel_sub(int lv) {
  789. if( lv < battle_config.max_lv ) {
  790. ;
  791. } else if( lv < battle_config.aura_lv ) {
  792. lv = battle_config.max_lv - 1;
  793. } else {
  794. lv = battle_config.max_lv;
  795. }
  796. return lv;
  797. }
  798. static int clif_setlevel(struct block_list* bl) {
  799. int lv = status_get_lv(bl);
  800. if( battle_config.client_limit_unit_lv&bl->type )
  801. return clif_setlevel_sub(lv);
  802. switch( bl->type ) {
  803. case BL_NPC:
  804. case BL_PET:
  805. // npcs and pets do not have level
  806. return 0;
  807. }
  808. return lv;
  809. }
  810. /*==========================================
  811. * Prepares 'unit standing/spawning' packet
  812. *------------------------------------------*/
  813. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  814. {
  815. struct map_session_data* sd;
  816. struct status_change* sc = status_get_sc(bl);
  817. struct view_data* vd = status_get_viewdata(bl);
  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 < 20120221
  843. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  844. #elif PACKETVER < 20131223
  845. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  846. #elif PACKETVER < 20150513
  847. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  848. #else
  849. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  850. #endif
  851. #if PACKETVER >= 20091103
  852. name = status_get_name(bl);
  853. #if PACKETVER < 20110111
  854. WBUFW(buf,2) = (spawn ? 62 : 63)+strlen(name);
  855. #elif PACKETVER < 20120221
  856. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  857. #elif PACKETVER < 20130807
  858. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  859. #else
  860. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  861. #endif
  862. WBUFB(buf,4) = clif_bl_type(bl);
  863. offset+=3;
  864. buf = WBUFP(buffer,offset);
  865. #elif PACKETVER >= 20071106
  866. if (type) { //Non-player packets
  867. WBUFB(buf,2) = clif_bl_type(bl);
  868. offset++;
  869. buf = WBUFP(buffer,offset);
  870. }
  871. #endif
  872. WBUFL(buf, 2) = bl->id;
  873. #if PACKETVER >= 20131223
  874. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  875. offset+=4;
  876. buf = WBUFP(buffer,offset);
  877. #endif
  878. WBUFW(buf, 6) = status_get_speed(bl);
  879. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  880. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  881. #if PACKETVER < 20091103
  882. if (type&&spawn) { //uses an older and different packet structure
  883. WBUFW(buf,12) = (sc)? sc->option : 0;
  884. WBUFW(buf,14) = vd->hair_style;
  885. WBUFW(buf,16) = vd->weapon;
  886. WBUFW(buf,18) = vd->head_bottom;
  887. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  888. WBUFW(buf,22) = vd->shield;
  889. } else {
  890. #endif
  891. #if PACKETVER >= 20091103
  892. WBUFL(buf,12) = (sc)? sc->option : 0;
  893. offset+=2;
  894. buf = WBUFP(buffer,offset);
  895. #elif PACKETVER >= 7
  896. if (!type) {
  897. WBUFL(buf,12) = (sc)? sc->option : 0;
  898. offset+=2;
  899. buf = WBUFP(buffer,offset);
  900. } else
  901. WBUFW(buf,12) = (sc)? sc->option : 0;
  902. #else
  903. WBUFW(buf,12) = (sc)? sc->option : 0;
  904. #endif
  905. WBUFW(buf,14) = vd->class_;
  906. WBUFW(buf,16) = vd->hair_style;
  907. WBUFW(buf,18) = vd->weapon;
  908. #if PACKETVER < 4
  909. WBUFW(buf,20) = vd->head_bottom;
  910. WBUFW(buf,22) = vd->shield;
  911. #else
  912. WBUFW(buf,20) = vd->shield;
  913. WBUFW(buf,22) = vd->head_bottom;
  914. #endif
  915. #if PACKETVER < 20091103
  916. }
  917. #endif
  918. WBUFW(buf,24) = vd->head_top;
  919. WBUFW(buf,26) = vd->head_mid;
  920. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  921. { //The hell, why flags work like this?
  922. WBUFW(buf,22) = status_get_emblem_id(bl);
  923. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  924. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  925. }
  926. WBUFW(buf,28) = vd->hair_color;
  927. WBUFW(buf,30) = vd->cloth_color;
  928. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  929. #if PACKETVER < 20091103
  930. if (type&&spawn) { //End of packet 0x7c
  931. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  932. WBUFB(buf,35) = vd->sex;
  933. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  934. WBUFB(buf,39) = 0;
  935. WBUFB(buf,40) = 0;
  936. return packet_len(0x7c);
  937. }
  938. #endif
  939. #if PACKETVER >= 20110111
  940. WBUFW(buf,34) = vd->robe;
  941. offset+= 2;
  942. buf = WBUFP(buffer,offset);
  943. #endif
  944. WBUFL(buf,34) = status_get_guild_id(bl);
  945. WBUFW(buf,38) = status_get_emblem_id(bl);
  946. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  947. #if PACKETVER >= 20091103
  948. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  949. offset+=2;
  950. buf = WBUFP(buffer,offset);
  951. #elif PACKETVER >= 7
  952. if (!type) {
  953. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  954. offset+=2;
  955. buf = WBUFP(buffer,offset);
  956. } else
  957. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  958. #else
  959. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  960. #endif
  961. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  962. WBUFB(buf,45) = vd->sex;
  963. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  964. WBUFB(buf,49) = (sd)? 5 : 0;
  965. WBUFB(buf,50) = (sd)? 5 : 0;
  966. if (!spawn) {
  967. WBUFB(buf,51) = vd->dead_sit;
  968. offset++;
  969. buf = WBUFP(buffer,offset);
  970. }
  971. WBUFW(buf,51) = clif_setlevel(bl);
  972. #if PACKETVER < 20091103
  973. if (type) //End for non-player packet
  974. return packet_len(WBUFW(buffer,0));
  975. #endif
  976. #if PACKETVER >= 20080102
  977. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  978. #endif
  979. #if PACKETVER >= 20120221
  980. if ( battle_config.monster_hp_bars_info && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  981. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  982. WBUFL(buf,59) = status_get_hp(bl); // HP
  983. } else {
  984. WBUFL(buf,55) = -1; // maxHP
  985. WBUFL(buf,59) = -1; // HP
  986. }
  987. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  988. #endif
  989. #if PACKETVER >= 20150513
  990. WBUFW(buf,64) = vd->body_style; // body
  991. offset+= 2;
  992. buf = WBUFP(buffer,offset);
  993. #endif
  994. #if PACKETVER >= 20091103
  995. #if PACKETVER >= 20120221
  996. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  997. #else
  998. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  999. #endif
  1000. return WBUFW(buffer,2);
  1001. #else
  1002. return packet_len(WBUFW(buffer,0));
  1003. #endif
  1004. }
  1005. /*==========================================
  1006. * Prepares 'unit walking' packet
  1007. *------------------------------------------*/
  1008. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1009. {
  1010. struct map_session_data* sd;
  1011. struct status_change* sc = status_get_sc(bl);
  1012. struct view_data* vd = status_get_viewdata(bl);
  1013. unsigned char* buf = WBUFP(buffer,0);
  1014. #if PACKETVER >= 7
  1015. unsigned short offset = 0;
  1016. #endif
  1017. #if PACKETVER >= 20091103
  1018. const char *name;
  1019. #endif
  1020. sd = BL_CAST(BL_PC, bl);
  1021. #if PACKETVER < 4
  1022. WBUFW(buf, 0) = 0x7b;
  1023. #elif PACKETVER < 7
  1024. WBUFW(buf, 0) = 0x1da;
  1025. #elif PACKETVER < 20080102
  1026. WBUFW(buf, 0) = 0x22c;
  1027. #elif PACKETVER < 20091103
  1028. WBUFW(buf, 0) = 0x2ec;
  1029. #elif PACKETVER < 20101124
  1030. WBUFW(buf, 0) = 0x7f7;
  1031. #elif PACKETVER < 20120221
  1032. WBUFW(buf, 0) = 0x856;
  1033. #elif PACKETVER < 20131223
  1034. WBUFW(buf, 0) = 0x914;
  1035. #elif PACKETVER < 20150513
  1036. WBUFW(buf, 0) = 0x9db;
  1037. #else
  1038. WBUFW(buf, 0) = 0x9fd;
  1039. #endif
  1040. #if PACKETVER >= 20091103
  1041. name = status_get_name(bl);
  1042. #if PACKETVER < 20110111
  1043. WBUFW(buf, 2) = 69+strlen(name);
  1044. #elif PACKETVER < 20120221
  1045. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1046. #elif PACKETVER < 20130807
  1047. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1048. #else
  1049. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  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 >= 20120221
  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. } else {
  1121. WBUFL(buf,62) = -1; // maxHP
  1122. WBUFL(buf,66) = -1; // HP
  1123. }
  1124. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1125. #endif
  1126. #if PACKETVER >= 20150513
  1127. WBUFW(buf,71) = vd->body_style; // body
  1128. offset+= 2;
  1129. buf = WBUFP(buffer,offset);
  1130. #endif
  1131. #if PACKETVER >= 20091103
  1132. #if PACKETVER >= 20120221
  1133. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1134. #else
  1135. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1136. #endif
  1137. return WBUFW(buffer,2);
  1138. #else
  1139. return packet_len(WBUFW(buffer,0));
  1140. #endif
  1141. }
  1142. //Modifies the buffer for disguise characters and sends it to self.
  1143. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1144. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1145. {
  1146. #if PACKETVER >= 20091103
  1147. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1148. WBUFL(buf,5)=-bl->id;
  1149. #elif PACKETVER >= 20071106
  1150. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1151. WBUFL(buf,3)=-bl->id;
  1152. #else
  1153. WBUFL(buf,2)=-bl->id;
  1154. #endif
  1155. clif_send(buf, len, bl, SELF);
  1156. }
  1157. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1158. /// 01b0 <id>.L <type>.B <value>.L
  1159. /// type:
  1160. /// unused
  1161. void clif_class_change(struct block_list *bl,int class_,int type)
  1162. {
  1163. nullpo_retv(bl);
  1164. if(!pcdb_checkid(class_))
  1165. {// player classes yield missing sprites
  1166. unsigned char buf[16];
  1167. WBUFW(buf,0)=0x1b0;
  1168. WBUFL(buf,2)=bl->id;
  1169. WBUFB(buf,6)=type;
  1170. WBUFL(buf,7)=class_;
  1171. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1172. }
  1173. }
  1174. /// Notifies the client of an object's spirits.
  1175. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1176. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1177. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1178. {
  1179. WFIFOHEAD(fd, packet_len(0x1e1));
  1180. WFIFOW(fd,0)=0x1e1;
  1181. WFIFOL(fd,2)=sd->bl.id;
  1182. WFIFOW(fd,6)=sd->spiritball;
  1183. WFIFOSET(fd, packet_len(0x1e1));
  1184. }
  1185. /*==========================================
  1186. * Kagerou/Oboro amulet spirit
  1187. *------------------------------------------*/
  1188. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1189. {
  1190. WFIFOHEAD(fd, packet_len(0x08cf));
  1191. WFIFOW(fd,0)=0x08cf;
  1192. WFIFOL(fd,2)=sd->bl.id;
  1193. WFIFOW(fd,6)=sd->spiritcharm_type;
  1194. WFIFOW(fd,8)=sd->spiritcharm;
  1195. WFIFOSET(fd, packet_len(0x08cf));
  1196. }
  1197. /*==========================================
  1198. * Run when player changes map / refreshes
  1199. * Tells its client to display all weather settings being used by this map
  1200. *------------------------------------------*/
  1201. static void clif_weather_check(struct map_session_data *sd)
  1202. {
  1203. int16 m = sd->bl.m;
  1204. int fd = sd->fd;
  1205. if (map[m].flag.snow
  1206. || map[m].flag.clouds
  1207. || map[m].flag.fog
  1208. || map[m].flag.fireworks
  1209. || map[m].flag.sakura
  1210. || map[m].flag.leaves
  1211. || map[m].flag.clouds2)
  1212. {
  1213. if (map[m].flag.snow)
  1214. clif_specialeffect_single(&sd->bl, 162, fd);
  1215. if (map[m].flag.clouds)
  1216. clif_specialeffect_single(&sd->bl, 233, fd);
  1217. if (map[m].flag.clouds2)
  1218. clif_specialeffect_single(&sd->bl, 516, fd);
  1219. if (map[m].flag.fog)
  1220. clif_specialeffect_single(&sd->bl, 515, fd);
  1221. if (map[m].flag.fireworks) {
  1222. clif_specialeffect_single(&sd->bl, 297, fd);
  1223. clif_specialeffect_single(&sd->bl, 299, fd);
  1224. clif_specialeffect_single(&sd->bl, 301, fd);
  1225. }
  1226. if (map[m].flag.sakura)
  1227. clif_specialeffect_single(&sd->bl, 163, fd);
  1228. if (map[m].flag.leaves)
  1229. clif_specialeffect_single(&sd->bl, 333, fd);
  1230. }
  1231. }
  1232. /**
  1233. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1234. **/
  1235. void clif_weather(int16 m)
  1236. {
  1237. struct s_mapiterator* iter;
  1238. struct map_session_data *sd=NULL;
  1239. iter = mapit_getallusers();
  1240. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1241. {
  1242. if( sd->bl.m == m )
  1243. clif_weather_check(sd);
  1244. }
  1245. mapit_free(iter);
  1246. }
  1247. /**
  1248. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1249. **/
  1250. int clif_spawn(struct block_list *bl)
  1251. {
  1252. unsigned char buf[128];
  1253. struct view_data *vd;
  1254. int len;
  1255. vd = status_get_viewdata(bl);
  1256. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1257. return 0;
  1258. /**
  1259. * Hide NPC from maya purple card.
  1260. **/
  1261. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1262. return 0;
  1263. len = clif_set_unit_idle(bl, buf,true);
  1264. clif_send(buf, len, bl, AREA_WOS);
  1265. if (disguised(bl))
  1266. clif_setdisguise(bl, buf, len);
  1267. if (vd->cloth_color)
  1268. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1269. if (vd->body_style)
  1270. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1271. switch (bl->type)
  1272. {
  1273. case BL_PC:
  1274. {
  1275. TBL_PC *sd = ((TBL_PC*)bl);
  1276. if (sd->spiritball > 0)
  1277. clif_spiritball(&sd->bl);
  1278. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1279. clif_specialeffect(bl,423,AREA);
  1280. else if(sd->state.size==SZ_MEDIUM)
  1281. clif_specialeffect(bl,421,AREA);
  1282. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1283. clif_sendbgemblem_area(sd);
  1284. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1285. clif_spiritcharm(sd);
  1286. if (sd->status.robe)
  1287. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1288. clif_efst_status_change_sub(sd, bl, AREA);
  1289. clif_hat_effects(sd,bl,AREA);
  1290. }
  1291. break;
  1292. case BL_MOB:
  1293. {
  1294. TBL_MOB *md = ((TBL_MOB*)bl);
  1295. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1296. clif_specialeffect(&md->bl,423,AREA);
  1297. else if(md->special_state.size==SZ_MEDIUM)
  1298. clif_specialeffect(&md->bl,421,AREA);
  1299. }
  1300. break;
  1301. case BL_NPC:
  1302. {
  1303. TBL_NPC *nd = ((TBL_NPC*)bl);
  1304. if( nd->size == SZ_BIG )
  1305. clif_specialeffect(&nd->bl,423,AREA);
  1306. else if( nd->size == SZ_MEDIUM )
  1307. clif_specialeffect(&nd->bl,421,AREA);
  1308. }
  1309. break;
  1310. case BL_PET:
  1311. if (vd->head_bottom)
  1312. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1313. break;
  1314. }
  1315. return 0;
  1316. }
  1317. /// Sends information about owned homunculus to the client . [orn]
  1318. /// 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)
  1319. /// 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)
  1320. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1321. {
  1322. struct status_data *status;
  1323. unsigned char buf[128];
  1324. #if PACKETVER < 20141016
  1325. const int cmd = 0x22e;
  1326. int offset = 0;
  1327. #else
  1328. const int cmd = 0x9f7;
  1329. int offset = 2;
  1330. #endif
  1331. int htype;
  1332. nullpo_retv(hd);
  1333. if (!clif_session_isValid(sd))
  1334. return;
  1335. status = &hd->battle_status;
  1336. htype = hom_class2type(hd->homunculus.class_);
  1337. memset(buf,0,packet_len(cmd));
  1338. WBUFW(buf,0) = cmd;
  1339. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1340. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1341. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1342. WBUFW(buf,27) = hd->homunculus.level;
  1343. WBUFW(buf,29) = hd->homunculus.hunger;
  1344. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1345. WBUFW(buf,33) = 0; // equip id
  1346. #ifdef RENEWAL
  1347. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1348. #else
  1349. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1350. #endif
  1351. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1352. WBUFW(buf,39)=status->hit;
  1353. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1354. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1355. else
  1356. WBUFW(buf,41) = status->cri/10;
  1357. #ifdef RENEWAL
  1358. WBUFW(buf,43) = status->def + status->def2;
  1359. WBUFW(buf,45) = status->mdef + status->mdef2;
  1360. #else
  1361. WBUFW(buf,43) = status->def + status->vit;
  1362. WBUFW(buf,45) = status->mdef;
  1363. #endif
  1364. WBUFW(buf,47) = status->flee;
  1365. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1366. if (status->max_hp > INT16_MAX) {
  1367. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1368. WBUFW(buf,53+offset) = 100;
  1369. } else {
  1370. WBUFW(buf,51) = status->hp;
  1371. WBUFW(buf,53+offset) = status->max_hp;
  1372. }
  1373. #if PACKETVER >= 20141016
  1374. offset += 2;
  1375. #endif
  1376. if (status->max_sp > INT16_MAX) {
  1377. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1378. WBUFW(buf,57+offset) = 100;
  1379. } else {
  1380. WBUFW(buf,55+offset) = status->sp;
  1381. WBUFW(buf,57+offset) = status->max_sp;
  1382. }
  1383. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1384. WBUFL(buf,63+offset) = hd->exp_next;
  1385. switch( htype ) {
  1386. case HT_REG:
  1387. case HT_EVO:
  1388. if( hd->homunculus.level >= battle_config.hom_max_level )
  1389. WBUFL(buf,63+offset) = 0;
  1390. break;
  1391. case HT_S:
  1392. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1393. WBUFL(buf,63+offset) = 0;
  1394. break;
  1395. }
  1396. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1397. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1398. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1399. }
  1400. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1401. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1402. /// type:
  1403. /// unused
  1404. /// state:
  1405. /// 0 = pre-init
  1406. /// 1 = intimacy
  1407. /// 2 = hunger
  1408. /// 3 = accessory?
  1409. /// ? = ignored
  1410. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1411. { //[orn]
  1412. int fd = sd->fd;
  1413. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1414. hom_calc_skilltree(sd->hd, 0);
  1415. WFIFOHEAD(fd, packet_len(0x230));
  1416. WFIFOW(fd,0)=0x230;
  1417. WFIFOB(fd,2)=0;
  1418. WFIFOB(fd,3)=state;
  1419. WFIFOL(fd,4)=sd->hd->bl.id;
  1420. WFIFOL(fd,8)=param;
  1421. WFIFOSET(fd,packet_len(0x230));
  1422. }
  1423. int clif_homskillinfoblock(struct map_session_data *sd)
  1424. { //[orn]
  1425. struct homun_data *hd;
  1426. int fd = sd->fd;
  1427. int i, len=4;
  1428. nullpo_ret(sd);
  1429. hd = sd->hd;
  1430. if ( !hd )
  1431. return 0 ;
  1432. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1433. WFIFOW(fd,0)=0x235;
  1434. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1435. int id = hd->homunculus.hskill[i].id;
  1436. if( id != 0 ){
  1437. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1438. short idx = hom_skill_get_index(id);
  1439. if (idx == -1)
  1440. continue;
  1441. WFIFOW(fd,len ) = id;
  1442. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1443. WFIFOW(fd,len+4) = 0;
  1444. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1445. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1446. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1447. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1448. 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;
  1449. len+=37;
  1450. }
  1451. }
  1452. WFIFOW(fd,2)=len;
  1453. WFIFOSET(fd,len);
  1454. return 0;
  1455. }
  1456. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1457. { //[orn]
  1458. struct homun_data *hd;
  1459. int fd;
  1460. short idx = -1;
  1461. nullpo_retv(sd);
  1462. if ((idx = hom_skill_get_index(skill_id) == -1))
  1463. return;
  1464. fd = sd->fd;
  1465. hd = sd->hd;
  1466. WFIFOHEAD(fd, packet_len(0x239));
  1467. WFIFOW(fd,0) = 0x239;
  1468. WFIFOW(fd,2) = skill_id;
  1469. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1470. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1471. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1472. 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;
  1473. WFIFOSET(fd,packet_len(0x239));
  1474. }
  1475. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1476. {
  1477. int fd=sd->fd;
  1478. WFIFOHEAD(fd,packet_len(0x22f));
  1479. WFIFOW(fd,0)=0x22f;
  1480. WFIFOB(fd,2)=fail;
  1481. WFIFOW(fd,3)=foodid;
  1482. WFIFOSET(fd,packet_len(0x22f));
  1483. return 0;
  1484. }
  1485. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1486. /// 0087 <walk start time>.L <walk data>.6B
  1487. void clif_walkok(struct map_session_data *sd)
  1488. {
  1489. int fd=sd->fd;
  1490. WFIFOHEAD(fd, packet_len(0x87));
  1491. WFIFOW(fd,0)=0x87;
  1492. WFIFOL(fd,2)=gettick();
  1493. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1494. WFIFOSET(fd,packet_len(0x87));
  1495. }
  1496. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1497. {
  1498. uint8 buf[128];
  1499. int len;
  1500. struct status_change *sc = NULL;
  1501. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1502. clif_ally_only = true;
  1503. len = clif_set_unit_walking(bl,ud,buf);
  1504. clif_send(buf,len,bl,AREA_WOS);
  1505. if (disguised(bl))
  1506. clif_setdisguise(bl, buf, len);
  1507. if(vd->cloth_color)
  1508. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1509. if(vd->body_style)
  1510. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1511. switch(bl->type) {
  1512. case BL_PC:
  1513. {
  1514. TBL_PC *sd = ((TBL_PC*)bl);
  1515. // clif_movepc(sd);
  1516. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1517. clif_specialeffect(&sd->bl,423,AREA);
  1518. else if(sd->state.size==SZ_MEDIUM)
  1519. clif_specialeffect(&sd->bl,421,AREA);
  1520. if (sd->status.robe)
  1521. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1522. }
  1523. break;
  1524. case BL_MOB:
  1525. {
  1526. TBL_MOB *md = ((TBL_MOB*)bl);
  1527. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1528. clif_specialeffect(&md->bl,423,AREA);
  1529. else if(md->special_state.size==SZ_MEDIUM)
  1530. clif_specialeffect(&md->bl,421,AREA);
  1531. }
  1532. break;
  1533. case BL_PET:
  1534. if(vd->head_bottom) // needed to display pet equip properly
  1535. clif_pet_equip_area((TBL_PET*)bl);
  1536. break;
  1537. }
  1538. clif_ally_only = false;
  1539. }
  1540. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1541. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1542. /// Note: unit must not be self
  1543. void clif_move(struct unit_data *ud)
  1544. {
  1545. unsigned char buf[16];
  1546. struct view_data* vd;
  1547. struct block_list* bl = ud->bl;
  1548. struct status_change *sc = NULL;
  1549. vd = status_get_viewdata(bl);
  1550. if (!vd )
  1551. return;
  1552. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1553. else if( vd->class_ == INVISIBLE_CLASS ){
  1554. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1555. if(disguised(bl)) {
  1556. WBUFW(buf,0)=0x86;
  1557. WBUFL(buf,2)=-bl->id;
  1558. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1559. WBUFL(buf,12)=gettick();
  1560. clif_send(buf, packet_len(0x86), bl, SELF);
  1561. }
  1562. return;
  1563. }
  1564. /**
  1565. * Hide NPC from maya purple card.
  1566. **/
  1567. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1568. return;
  1569. if (ud->state.speed_changed) {
  1570. // Since we don't know how to update the speed of other objects,
  1571. // use the old walk packet to update the data.
  1572. ud->state.speed_changed = 0;
  1573. clif_move2(bl, vd, ud);
  1574. return;
  1575. }
  1576. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1577. clif_ally_only = true;
  1578. WBUFW(buf,0)=0x86;
  1579. WBUFL(buf,2)=bl->id;
  1580. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1581. WBUFL(buf,12)=gettick();
  1582. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1583. if (disguised(bl)) {
  1584. WBUFL(buf,2)=-bl->id;
  1585. clif_send(buf, packet_len(0x86), bl, SELF);
  1586. }
  1587. clif_ally_only = false;
  1588. }
  1589. /*==========================================
  1590. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1591. *------------------------------------------*/
  1592. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1593. {
  1594. struct map_session_data *sd = NULL;
  1595. //Remove player from map server
  1596. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1597. map_quit(sd);
  1598. return 0;
  1599. }
  1600. /*==========================================
  1601. *
  1602. *------------------------------------------*/
  1603. void clif_quitsave(int fd,struct map_session_data *sd) {
  1604. if (!battle_config.prevent_logout ||
  1605. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1606. map_quit(sd);
  1607. else if (sd->fd) {
  1608. //Disassociate session from player (session is deleted after this function was called)
  1609. //And set a timer to make him quit later.
  1610. session[sd->fd]->session_data = NULL;
  1611. sd->fd = 0;
  1612. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1613. }
  1614. }
  1615. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1616. /// 0091 <map name>.16B <x>.W <y>.W
  1617. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1618. {
  1619. int fd;
  1620. nullpo_retv(sd);
  1621. fd = sd->fd;
  1622. WFIFOHEAD(fd,packet_len(0x91));
  1623. WFIFOW(fd,0) = 0x91;
  1624. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1625. WFIFOW(fd,18) = x;
  1626. WFIFOW(fd,20) = y;
  1627. WFIFOSET(fd,packet_len(0x91));
  1628. }
  1629. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1630. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1631. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1632. {
  1633. int fd;
  1634. nullpo_retv(sd);
  1635. fd = sd->fd;
  1636. WFIFOHEAD(fd,packet_len(0x92));
  1637. WFIFOW(fd,0) = 0x92;
  1638. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1639. WFIFOW(fd,18) = x;
  1640. WFIFOW(fd,20) = y;
  1641. WFIFOL(fd,22) = htonl(ip);
  1642. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1643. WFIFOSET(fd,packet_len(0x92));
  1644. }
  1645. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1646. /// This function combines both calls and allows to simplify the calling code
  1647. void clif_blown(struct block_list *bl)
  1648. {
  1649. clif_slide(bl, bl->x, bl->y);
  1650. clif_fixpos(bl);
  1651. }
  1652. /// Visually moves(slides) a character to x,y. If the target cell
  1653. /// isn't walkable, the char doesn't move at all. If the char is
  1654. /// sitting it will stand up (ZC_STOPMOVE).
  1655. /// 0088 <id>.L <x>.W <y>.W
  1656. void clif_fixpos(struct block_list *bl)
  1657. {
  1658. unsigned char buf[10];
  1659. nullpo_retv(bl);
  1660. WBUFW(buf,0) = 0x88;
  1661. WBUFL(buf,2) = bl->id;
  1662. WBUFW(buf,6) = bl->x;
  1663. WBUFW(buf,8) = bl->y;
  1664. clif_send(buf, packet_len(0x88), bl, AREA);
  1665. if( disguised(bl) ) {
  1666. WBUFL(buf,2) = -bl->id;
  1667. clif_send(buf, packet_len(0x88), bl, SELF);
  1668. }
  1669. }
  1670. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1671. /// 00c4 <shop id>.L
  1672. void clif_npcbuysell(struct map_session_data* sd, int id)
  1673. {
  1674. int fd;
  1675. nullpo_retv(sd);
  1676. fd=sd->fd;
  1677. WFIFOHEAD(fd, packet_len(0xc4));
  1678. WFIFOW(fd,0)=0xc4;
  1679. WFIFOL(fd,2)=id;
  1680. WFIFOSET(fd,packet_len(0xc4));
  1681. }
  1682. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1683. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1684. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1685. {
  1686. int fd,i,c;
  1687. bool discount;
  1688. nullpo_retv(sd);
  1689. nullpo_retv(nd);
  1690. fd = sd->fd;
  1691. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1692. WFIFOW(fd,0) = 0xc6;
  1693. c = 0;
  1694. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1695. for( i = 0; i < nd->u.shop.count; i++ )
  1696. {
  1697. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1698. int val = nd->u.shop.shop_item[i].value;
  1699. if( id == NULL )
  1700. continue;
  1701. WFIFOL(fd, 4+c*11) = val;
  1702. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1703. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1704. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1705. c++;
  1706. }
  1707. WFIFOW(fd,2) = 4 + c*11;
  1708. WFIFOSET(fd,WFIFOW(fd,2));
  1709. }
  1710. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1711. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1712. void clif_selllist(struct map_session_data *sd)
  1713. {
  1714. int fd,i,c=0,val;
  1715. nullpo_retv(sd);
  1716. fd=sd->fd;
  1717. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1718. WFIFOW(fd,0)=0xc7;
  1719. for( i = 0; i < MAX_INVENTORY; i++ )
  1720. {
  1721. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1722. {
  1723. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1724. continue;
  1725. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1726. continue; // Cannot Sell Rental Items or Account Bounded Items
  1727. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1728. continue; // Don't allow sale of bound items
  1729. val=sd->inventory_data[i]->value_sell;
  1730. if( val < 0 )
  1731. continue;
  1732. WFIFOW(fd,4+c*10)=i+2;
  1733. WFIFOL(fd,6+c*10)=val;
  1734. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1735. c++;
  1736. }
  1737. }
  1738. WFIFOW(fd,2)=c*10+4;
  1739. WFIFOSET(fd,WFIFOW(fd,2));
  1740. }
  1741. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1742. /// 09d4
  1743. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1744. // TODO: State tracking?
  1745. sd->npc_shopid = 0;
  1746. }
  1747. /**
  1748. * Presents list of items, that can be sold to a Market shop.
  1749. * @author: Ind and Yommy
  1750. **/
  1751. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1752. #if PACKETVER >= 20131223
  1753. struct npc_item_list *shop = nd->u.shop.shop_item;
  1754. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1755. struct item_data *id = NULL;
  1756. struct s_packet_db *info;
  1757. int fd;
  1758. nullpo_retv(sd);
  1759. if (sd->state.trading)
  1760. return;
  1761. info = &packet_db[sd->packet_ver][cmd];
  1762. if (!info || info->len == 0)
  1763. return;
  1764. fd = sd->fd;
  1765. WFIFOHEAD(fd, 4 + shop_size * 13);
  1766. WFIFOW(fd,0) = cmd;
  1767. for (i = 0, c = 0; i < shop_size; i++) {
  1768. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1769. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1770. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1771. WFIFOL(fd, 7+c*13) = shop[i].value;
  1772. WFIFOL(fd,11+c*13) = shop[i].qty;
  1773. WFIFOW(fd,15+c*13) = (id->view_id > 0) ? id->view_id : id->nameid;
  1774. c++;
  1775. }
  1776. }
  1777. WFIFOW(fd,2) = 4 + c*13;
  1778. WFIFOSET(fd,WFIFOW(fd,2));
  1779. sd->state.trading = 1;
  1780. #endif
  1781. }
  1782. /// Closes the Market shop window.
  1783. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1784. nullpo_retv(sd);
  1785. sd->npc_shopid = 0;
  1786. sd->state.trading = 0;
  1787. }
  1788. /// Purchase item from Market shop.
  1789. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1790. #if PACKETVER >= 20131223
  1791. unsigned short cmd = 0x9d7, len = 0;
  1792. struct npc_data* nd;
  1793. uint8 result = (res == 0 ? 1 : 0);
  1794. int fd = 0;
  1795. struct s_packet_db *info;
  1796. nullpo_retv(sd);
  1797. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1798. info = &packet_db[sd->packet_ver][cmd];
  1799. if (!info || info->len == 0)
  1800. return;
  1801. fd = sd->fd;
  1802. len = 5 + 8*n;
  1803. WFIFOHEAD(fd, len);
  1804. WFIFOW(fd, 0) = cmd;
  1805. WFIFOW(fd, 2) = len;
  1806. if (result) {
  1807. uint8 i, j;
  1808. struct npc_item_list *shop = nd->u.shop.shop_item;
  1809. unsigned short count = nd->u.shop.count;
  1810. for (i = 0; i < n; i++) {
  1811. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1812. WFIFOW(fd, 7+i*8) = list[i].qty;
  1813. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1814. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1815. }
  1816. }
  1817. WFIFOB(fd, 4) = n;
  1818. WFIFOSET(fd, len);
  1819. #endif
  1820. }
  1821. /// Purchase item from Market shop.
  1822. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1823. #if PACKETVER >= 20131223
  1824. struct s_packet_db* info;
  1825. struct s_npc_buy_list *item_list;
  1826. uint16 len = 0, i = 0;
  1827. uint8 res = 0, n = 0;
  1828. nullpo_retv(sd);
  1829. if (!sd->npc_shopid)
  1830. return;
  1831. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  1832. if (!info || info->len == 0)
  1833. return;
  1834. len = RFIFOW(fd,info->pos[0]);
  1835. n = (len-4) / 6;
  1836. CREATE(item_list, struct s_npc_buy_list, n);
  1837. for (i = 0; i < n; i++) {
  1838. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1839. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1840. }
  1841. res = npc_buylist(sd, n, item_list);
  1842. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1843. aFree(item_list);
  1844. #endif
  1845. }
  1846. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1847. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1848. /// Client behavior (dialog window):
  1849. /// - disable mouse targeting
  1850. /// - open the dialog window
  1851. /// - set npcid of dialog window (0 by default)
  1852. /// - if set to clear on next mes, clear contents
  1853. /// - append this text
  1854. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1855. {
  1856. int fd = sd->fd;
  1857. int slen = strlen(mes) + 9;
  1858. WFIFOHEAD(fd, slen);
  1859. WFIFOW(fd,0)=0xb4;
  1860. WFIFOW(fd,2)=slen;
  1861. WFIFOL(fd,4)=npcid;
  1862. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1863. WFIFOSET(fd,WFIFOW(fd,2));
  1864. }
  1865. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1866. /// 00b5 <npc id>.L
  1867. /// Client behavior (dialog window):
  1868. /// - disable mouse targeting
  1869. /// - open the dialog window
  1870. /// - add 'next' button
  1871. /// When 'next' is pressed:
  1872. /// - 00B9 <npcid of dialog window>.L
  1873. /// - set to clear on next mes
  1874. /// - remove 'next' button
  1875. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1876. {
  1877. int fd;
  1878. nullpo_retv(sd);
  1879. fd=sd->fd;
  1880. WFIFOHEAD(fd, packet_len(0xb5));
  1881. WFIFOW(fd,0)=0xb5;
  1882. WFIFOL(fd,2)=npcid;
  1883. WFIFOSET(fd,packet_len(0xb5));
  1884. }
  1885. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1886. /// 00b6 <npc id>.L
  1887. /// Client behavior:
  1888. /// - if dialog window is open:
  1889. /// - remove 'next' button
  1890. /// - add 'close' button
  1891. /// - else:
  1892. /// - enable mouse targeting
  1893. /// - close the dialog window
  1894. /// - close the menu window
  1895. /// When 'close' is pressed:
  1896. /// - enable mouse targeting
  1897. /// - close the dialog window
  1898. /// - close the menu window
  1899. /// - 0146 <npcid of dialog window>.L
  1900. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1901. {
  1902. int fd;
  1903. nullpo_retv(sd);
  1904. fd=sd->fd;
  1905. WFIFOHEAD(fd, packet_len(0xb6));
  1906. WFIFOW(fd,0)=0xb6;
  1907. WFIFOL(fd,2)=npcid;
  1908. WFIFOSET(fd,packet_len(0xb6));
  1909. }
  1910. /**
  1911. * Close script when player is idle
  1912. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1913. * @author [Ind/Hercules]
  1914. * @param sd : player pointer
  1915. * @param npcid : npc gid to close
  1916. */
  1917. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1918. {
  1919. struct s_packet_db* info;
  1920. int16 len;
  1921. int cmd = 0;
  1922. int fd;
  1923. nullpo_retv(sd);
  1924. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1925. if(!cmd) cmd = 0x8d6; //default
  1926. info = &packet_db[sd->packet_ver][cmd];
  1927. len = info->len;
  1928. fd = sd->fd;
  1929. WFIFOHEAD(fd, len);
  1930. WFIFOW(fd,0)=0x8d6;
  1931. WFIFOL(fd,info->pos[0])=npcid;
  1932. WFIFOSET(fd,len);
  1933. }
  1934. /*==========================================
  1935. *
  1936. *------------------------------------------*/
  1937. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1938. unsigned char *buf;
  1939. int fd = sd->fd;
  1940. sd->state.using_fake_npc = 1;
  1941. WFIFOHEAD(fd, packet_len(0x78));
  1942. buf = WFIFOP(fd,0);
  1943. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1944. WBUFW(buf,0)=0x78;
  1945. #if PACKETVER >= 20071106
  1946. WBUFB(buf,2) = 0; // object type
  1947. buf = WFIFOP(fd,1);
  1948. #endif
  1949. WBUFL(buf,2)=npcid;
  1950. WBUFW(buf,14)=111;
  1951. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1952. WBUFB(buf,49)=5;
  1953. WBUFB(buf,50)=5;
  1954. WFIFOSET(fd, packet_len(0x78));
  1955. }
  1956. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1957. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1958. /// Client behavior:
  1959. /// - disable mouse targeting
  1960. /// - close the menu window
  1961. /// - open the menu window
  1962. /// - add options to the menu (separated in the text by ":")
  1963. /// - set npcid of menu window
  1964. /// - if dialog window is open:
  1965. /// - remove 'next' button
  1966. /// When 'ok' is pressed:
  1967. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1968. /// - close the menu window
  1969. /// When 'cancel' is pressed:
  1970. /// - 00B8 <npcid of menu window>.L <-1>.B
  1971. /// - enable mouse targeting
  1972. /// - close a bunch of windows...
  1973. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1974. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1975. /// TODO investigate behavior of other windows [FlavioJS]
  1976. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1977. {
  1978. int fd = sd->fd;
  1979. int slen = strlen(mes) + 9;
  1980. struct block_list *bl = NULL;
  1981. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1982. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1983. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1984. clif_sendfakenpc(sd, npcid);
  1985. WFIFOHEAD(fd, slen);
  1986. WFIFOW(fd,0)=0xb7;
  1987. WFIFOW(fd,2)=slen;
  1988. WFIFOL(fd,4)=npcid;
  1989. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1990. WFIFOSET(fd,WFIFOW(fd,2));
  1991. }
  1992. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1993. /// 0142 <npc id>.L
  1994. /// Client behavior (inputnum window):
  1995. /// - if npcid exists in the client:
  1996. /// - open the inputnum window
  1997. /// - set npcid of inputnum window
  1998. /// When 'ok' is pressed:
  1999. /// - if inputnum window has text:
  2000. /// - if npcid exists in the client:
  2001. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2002. /// - close inputnum window
  2003. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2004. {
  2005. int fd;
  2006. struct block_list *bl = NULL;
  2007. nullpo_retv(sd);
  2008. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2009. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2010. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2011. clif_sendfakenpc(sd, npcid);
  2012. fd=sd->fd;
  2013. WFIFOHEAD(fd, packet_len(0x142));
  2014. WFIFOW(fd,0)=0x142;
  2015. WFIFOL(fd,2)=npcid;
  2016. WFIFOSET(fd,packet_len(0x142));
  2017. }
  2018. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2019. /// 01d4 <npc id>.L
  2020. /// Client behavior (inputstr window):
  2021. /// - if npcid is 0 or npcid exists in the client:
  2022. /// - open the inputstr window
  2023. /// - set npcid of inputstr window
  2024. /// When 'ok' is pressed:
  2025. /// - if inputstr window has text and isn't an insult(manner.txt):
  2026. /// - if npcid is 0 or npcid exists in the client:
  2027. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2028. /// - close inputstr window
  2029. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2030. {
  2031. int fd;
  2032. struct block_list *bl = NULL;
  2033. nullpo_retv(sd);
  2034. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2035. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2036. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2037. clif_sendfakenpc(sd, npcid);
  2038. fd=sd->fd;
  2039. WFIFOHEAD(fd, packet_len(0x1d4));
  2040. WFIFOW(fd,0)=0x1d4;
  2041. WFIFOL(fd,2)=npcid;
  2042. WFIFOSET(fd,packet_len(0x1d4));
  2043. }
  2044. /// Marks a position on client's minimap (ZC_COMPASS).
  2045. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2046. /// npc id:
  2047. /// is ignored in the client
  2048. /// type:
  2049. /// 0 = display mark for 15 seconds
  2050. /// 1 = display mark until dead or teleported
  2051. /// 2 = remove mark
  2052. /// color:
  2053. /// 0x00RRGGBB
  2054. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2055. {
  2056. int fd;
  2057. nullpo_retv(sd);
  2058. fd=sd->fd;
  2059. WFIFOHEAD(fd, packet_len(0x144));
  2060. WFIFOW(fd,0)=0x144;
  2061. WFIFOL(fd,2)=npc_id;
  2062. WFIFOL(fd,6)=type;
  2063. WFIFOL(fd,10)=x;
  2064. WFIFOL(fd,14)=y;
  2065. WFIFOB(fd,18)=id;
  2066. WFIFOL(fd,19)=color;
  2067. WFIFOSET(fd,packet_len(0x144));
  2068. }
  2069. /// Displays an illustration image.
  2070. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2071. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2072. /// type:
  2073. /// 0 = bottom left corner
  2074. /// 1 = bottom middle
  2075. /// 2 = bottom right corner
  2076. /// 3 = middle of screen, inside a movable window
  2077. /// 4 = middle of screen, movable with a close button, chrome-less
  2078. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2079. {
  2080. int fd;
  2081. nullpo_retv(sd);
  2082. fd=sd->fd;
  2083. WFIFOHEAD(fd, packet_len(0x1b3));
  2084. WFIFOW(fd,0)=0x1b3;
  2085. strncpy(WFIFOCP(fd,2),image,64);
  2086. WFIFOB(fd,66)=type;
  2087. WFIFOSET(fd,packet_len(0x1b3));
  2088. }
  2089. /*==========================================
  2090. * Fills in card data from the given item and into the buffer. [Skotlex]
  2091. *------------------------------------------*/
  2092. static void clif_addcards(unsigned char* buf, struct item* item)
  2093. {
  2094. int i=0,j;
  2095. if( item == NULL ) { //Blank data
  2096. WBUFW(buf,0) = 0;
  2097. WBUFW(buf,2) = 0;
  2098. WBUFW(buf,4) = 0;
  2099. WBUFW(buf,6) = 0;
  2100. return;
  2101. }
  2102. if( item->card[0] == CARD0_PET ) { //pet eggs
  2103. WBUFW(buf,0) = 0;
  2104. WBUFW(buf,2) = 0;
  2105. WBUFW(buf,4) = 0;
  2106. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2107. return;
  2108. }
  2109. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2110. WBUFW(buf,0) = item->card[0];
  2111. WBUFW(buf,2) = item->card[1];
  2112. WBUFW(buf,4) = item->card[2];
  2113. WBUFW(buf,6) = item->card[3];
  2114. return;
  2115. }
  2116. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2117. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2118. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2119. //Normal items.
  2120. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2121. WBUFW(buf,0) = j;
  2122. else
  2123. WBUFW(buf,0) = item->card[i];
  2124. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2125. WBUFW(buf,2) = j;
  2126. else
  2127. WBUFW(buf,2) = item->card[i];
  2128. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2129. WBUFW(buf,4) = j;
  2130. else
  2131. WBUFW(buf,4) = item->card[i];
  2132. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2133. WBUFW(buf,6) = j;
  2134. else
  2135. WBUFW(buf,6) = item->card[i];
  2136. }
  2137. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2138. /// A maximum of 5 random options can be supported.
  2139. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2140. #if PACKETVER >= 20150226
  2141. int i;
  2142. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2143. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2144. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2145. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2146. }
  2147. #if MAX_ITEM_RDM_OPT < 5
  2148. for ( ; i < 5; i++) {
  2149. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2150. WBUFW(buf, i*5 + 2) = 0; // Value
  2151. WBUFB(buf, i*5 + 4) = 0; // Param1
  2152. }
  2153. #endif
  2154. #endif
  2155. }
  2156. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2157. /// 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)
  2158. /// 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)
  2159. /// 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)
  2160. /// 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)
  2161. /// 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)
  2162. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2163. {
  2164. int fd, header, offs=0;
  2165. #if PACKETVER < 20061218
  2166. header = 0xa0;
  2167. #elif PACKETVER < 20071002
  2168. header = 0x29a;
  2169. #elif PACKETVER < 20120925
  2170. header = 0x2d4;
  2171. #elif PACKETVER < 20150226
  2172. header = 0x990;
  2173. #else
  2174. header = 0xa0c;
  2175. #endif
  2176. nullpo_retv(sd);
  2177. fd = sd->fd;
  2178. if( !session_isActive(fd) ) //Sasuke-
  2179. return;
  2180. WFIFOHEAD(fd,packet_len(header));
  2181. if( fail )
  2182. {
  2183. WFIFOW(fd,offs+0) = header;
  2184. WFIFOW(fd,offs+2) = n+2;
  2185. WFIFOW(fd,offs+4) = amount;
  2186. WFIFOW(fd,offs+6) = 0;
  2187. WFIFOB(fd,offs+8) = 0;
  2188. WFIFOB(fd,offs+9) = 0;
  2189. WFIFOB(fd,offs+10) = 0;
  2190. WFIFOW(fd,offs+11) = 0;
  2191. WFIFOW(fd,offs+13) = 0;
  2192. WFIFOW(fd,offs+15) = 0;
  2193. WFIFOW(fd,offs+17) = 0;
  2194. #if PACKETVER < 20120925
  2195. WFIFOW(fd,offs+19) = 0;
  2196. #else
  2197. WFIFOL(fd,offs+19) = 0;
  2198. offs += 2;
  2199. #endif
  2200. WFIFOB(fd,offs+21) = 0;
  2201. WFIFOB(fd,offs+22) = fail;
  2202. #if PACKETVER >= 20061218
  2203. WFIFOL(fd,offs+23) = 0;
  2204. #endif
  2205. #if PACKETVER >= 20071002
  2206. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2207. #if PACKETVER >= 20150226
  2208. clif_add_random_options(WFIFOP(fd,offs+31), &sd->status.inventory[n]);
  2209. #endif
  2210. #endif
  2211. }
  2212. else
  2213. {
  2214. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2215. return;
  2216. WFIFOW(fd,offs+0) = header;
  2217. WFIFOW(fd,offs+2) = n+2;
  2218. WFIFOW(fd,offs+4) = amount;
  2219. if (sd->inventory_data[n]->view_id > 0)
  2220. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2221. else
  2222. WFIFOW(fd,offs+6) = sd->status.inventory[n].nameid;
  2223. WFIFOB(fd,offs+8) = sd->status.inventory[n].identify;
  2224. WFIFOB(fd,offs+9) = sd->status.inventory[n].attribute;
  2225. WFIFOB(fd,offs+10) = sd->status.inventory[n].refine;
  2226. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  2227. #if PACKETVER < 20120925
  2228. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2229. #else
  2230. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2231. offs += 2;
  2232. #endif
  2233. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2234. WFIFOB(fd,offs+22) = fail;
  2235. #if PACKETVER >= 20061218
  2236. WFIFOL(fd,offs+23) = sd->status.inventory[n].expire_time;
  2237. #endif
  2238. #if PACKETVER >= 20071002
  2239. /* Yellow color only for non-stackable item */
  2240. 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;
  2241. #endif
  2242. #if PACKETVER >= 20150226
  2243. clif_add_random_options(WFIFOP(fd,31), &sd->status.inventory[n]);
  2244. #endif
  2245. }
  2246. WFIFOSET(fd,packet_len(header));
  2247. }
  2248. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2249. /// 00af <index>.W <amount>.W
  2250. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2251. {
  2252. int fd;
  2253. nullpo_retv(sd);
  2254. fd=sd->fd;
  2255. WFIFOHEAD(fd, packet_len(0xaf));
  2256. WFIFOW(fd,0)=0xaf;
  2257. WFIFOW(fd,2)=n+2;
  2258. WFIFOW(fd,4)=amount;
  2259. WFIFOSET(fd,packet_len(0xaf));
  2260. }
  2261. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2262. /// 07fa <delete type>.W <index>.W <amount>.W
  2263. /// delete type:
  2264. /// 0 = Normal
  2265. /// 1 = Item used for a skill
  2266. /// 2 = Refine failed
  2267. /// 3 = Material changed
  2268. /// 4 = Moved to storage
  2269. /// 5 = Moved to cart
  2270. /// 6 = Item sold
  2271. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2272. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2273. {
  2274. #if PACKETVER < 20091117
  2275. clif_dropitem(sd,n,amount);
  2276. #else
  2277. int fd;
  2278. nullpo_retv(sd);
  2279. fd=sd->fd;
  2280. WFIFOHEAD(fd, packet_len(0x7fa));
  2281. WFIFOW(fd,0)=0x7fa;
  2282. WFIFOW(fd,2)=reason;
  2283. WFIFOW(fd,4)=n+2;
  2284. WFIFOW(fd,6)=amount;
  2285. WFIFOSET(fd,packet_len(0x7fa));
  2286. #endif
  2287. }
  2288. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2289. char normal = (equip < 0);
  2290. int offset = 0;
  2291. WBUFW(buf,n) = idx; //index
  2292. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2293. WBUFB(buf,n+4) = itemtype(id->nameid);
  2294. if (!normal){ //equip 31B
  2295. WBUFL(buf,n+5) = equip; //location
  2296. WBUFL(buf,n+9) = it->equip; //wear state
  2297. WBUFB(buf,n+13) = it->refine; //refine lvl
  2298. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2299. WBUFL(buf,n+22) = it->expire_time;
  2300. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2301. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2302. #if PACKETVER >= 20150226
  2303. //V6_ITEM_Option
  2304. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2305. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2306. offset += 26;
  2307. #endif
  2308. //V5_ITEM_flag
  2309. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2310. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2311. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2312. }
  2313. else { //normal 24B
  2314. WBUFW(buf,n+5) = it->amount;
  2315. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2316. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2317. WBUFL(buf,n+19) = it->expire_time;
  2318. //V5_ITEM_flag
  2319. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2320. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2321. }
  2322. }
  2323. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2324. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2325. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2326. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2327. #if PACKETVER >= 20120925
  2328. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2329. #else
  2330. WBUFW(buf,n) = idx; //index
  2331. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2332. WBUFB(buf,n+4) = itemtype(id->nameid);
  2333. WBUFB(buf,n+5) = it->identify;
  2334. if (equip >= 0) { //Equippable item 28.B
  2335. WBUFW(buf,n+6) = equip;
  2336. WBUFW(buf,n+8) = it->equip;
  2337. WBUFB(buf,n+10) = it->attribute;
  2338. WBUFB(buf,n+11) = it->refine;
  2339. clif_addcards(WBUFP(buf, n+12), it); //8B
  2340. #if PACKETVER >= 20071002
  2341. WBUFL(buf,n+20) = it->expire_time;
  2342. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2343. #endif
  2344. #if PACKETVER >= 20100629
  2345. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2346. #endif
  2347. } else { //Stackable item. 22.B
  2348. WBUFW(buf,n+6) = it->amount;
  2349. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2350. clif_addcards(WBUFP(buf, n+10), it); //8B
  2351. #if PACKETVER >= 20071002
  2352. WBUFL(buf,n+18) = it->expire_time;
  2353. #endif
  2354. }
  2355. #endif
  2356. }
  2357. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2358. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2359. void clif_inventorylist(struct map_session_data *sd) {
  2360. int i,n,ne,arrow=-1;
  2361. unsigned char *buf;
  2362. unsigned char *bufe;
  2363. #if PACKETVER < 5
  2364. const int s = 10; //Entry size
  2365. #elif PACKETVER < 20080102
  2366. const int s = 18;
  2367. #elif PACKETVER < 20120925
  2368. const int s = 22;
  2369. #else
  2370. const int s = 24;
  2371. #endif
  2372. #if PACKETVER < 20071002
  2373. const int se = 20;
  2374. #elif PACKETVER < 20100629
  2375. const int se = 26;
  2376. #elif PACKETVER < 20120925
  2377. const int se = 28;
  2378. #elif PACKETVER < 20150226
  2379. const int se = 31;
  2380. #else
  2381. const int se = 57;
  2382. #endif
  2383. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2384. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2385. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2386. {
  2387. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2388. continue;
  2389. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2390. { //Non-stackable (Equippable)
  2391. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2392. ne++;
  2393. }
  2394. else { //Stackable.
  2395. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2396. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2397. arrow=i;
  2398. n++;
  2399. }
  2400. }
  2401. if( n )
  2402. {
  2403. #if PACKETVER < 5
  2404. WBUFW(buf,0)=0xa3;
  2405. #elif PACKETVER < 20080102
  2406. WBUFW(buf,0)=0x1ee;
  2407. #elif PACKETVER < 20120925
  2408. WBUFW(buf,0)=0x2e8;
  2409. #else
  2410. WBUFW(buf,0)=0x991;
  2411. #endif
  2412. WBUFW(buf,2)=4+n*s;
  2413. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2414. }
  2415. if( arrow >= 0 )
  2416. clif_arrowequip(sd,arrow);
  2417. if( ne ) {
  2418. #if PACKETVER < 20071002
  2419. WBUFW(bufe,0)=0xa4;
  2420. #elif PACKETVER < 20120925
  2421. WBUFW(bufe,0)=0x2d0;
  2422. #elif PACKETVER < 20150226
  2423. WBUFW(bufe,0)=0x992;
  2424. #else
  2425. WBUFW(bufe,0)=0xa0d;
  2426. #endif
  2427. WBUFW(bufe,2)=4+ne*se;
  2428. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2429. }
  2430. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2431. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2432. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2433. continue;
  2434. if ( sd->status.inventory[i].favorite )
  2435. clif_favorite_item(sd, i);
  2436. }
  2437. #endif
  2438. if( buf ) aFree(buf);
  2439. if( bufe ) aFree(bufe);
  2440. }
  2441. //Required when items break/get-repaired. Only sends equippable item list.
  2442. void clif_equiplist(struct map_session_data *sd)
  2443. {
  2444. int i,n,fd = sd->fd;
  2445. unsigned char *buf;
  2446. #if PACKETVER < 20071002
  2447. const int cmd = 20;
  2448. #elif PACKETVER < 20100629
  2449. const int cmd = 26;
  2450. #elif PACKETVER < 20120925
  2451. const int cmd = 28;
  2452. #elif PACKETVER < 20150226
  2453. const int cmd = 31;
  2454. #else
  2455. const int cmd = 57;
  2456. #endif
  2457. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2458. buf = WFIFOP(fd,0);
  2459. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2460. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2461. continue;
  2462. if(itemdb_isstackable2(sd->inventory_data[i]))
  2463. continue;
  2464. //Equippable
  2465. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2466. n++;
  2467. }
  2468. if (n) {
  2469. #if PACKETVER < 20071002
  2470. WBUFW(buf,0)=0xa4;
  2471. #elif PACKETVER < 20120925
  2472. WBUFW(buf,0)=0x2d0;
  2473. #elif PACKETVER < 20150226
  2474. WBUFW(buf,0)=0x992;
  2475. #else
  2476. WBUFW(buf,0)=0xa0d;
  2477. #endif
  2478. WBUFW(buf,2)=4+n*cmd;
  2479. WFIFOSET(fd,WFIFOW(fd,2));
  2480. }
  2481. }
  2482. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2483. {
  2484. static const int client_buf = 0x5000; // Max buffer to send
  2485. struct item_data *id;
  2486. int i,n,ne,nn;
  2487. unsigned char *buf;
  2488. unsigned char *bufe;
  2489. #if PACKETVER < 5
  2490. const int s = 10; //Entry size.normal item
  2491. const int sidx=4; //start itemlist idx
  2492. const int cmd = 0xa5;
  2493. #elif PACKETVER < 20080102
  2494. const int s = 18;
  2495. const int sidx=4;
  2496. const int cmd = 0x1f0;
  2497. #elif PACKETVER < 20120925
  2498. const int s = 22;
  2499. const int sidx=4;
  2500. const int cmd = 0x2ea;
  2501. #else
  2502. const int s = 24;
  2503. const int sidx = 4+24;
  2504. const int cmd = 0x995;
  2505. #endif
  2506. #if PACKETVER < 20071002
  2507. const int se = 20; //entry size equip
  2508. const int sidxe = 4; //start itemlist idx
  2509. const int cmde = 0xa6;
  2510. #elif PACKETVER < 20100629
  2511. const int se = 26;
  2512. const int sidxe = 4;
  2513. const int cmde = 0x2d1;
  2514. #elif PACKETVER < 20120925
  2515. const int se = 28;
  2516. const int sidxe = 4;
  2517. const int cmde = 0x2d1;
  2518. #elif PACKETVER < 20150226
  2519. const int se = 31;
  2520. const int sidxe = 4+24;
  2521. const int cmde = 0x996;
  2522. #else
  2523. const int se = 57;
  2524. const int sidxe = 4+24;
  2525. const int cmde = 0xa10;
  2526. #endif
  2527. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2528. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2529. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2530. {
  2531. if( items[i].nameid <= 0 )
  2532. continue;
  2533. id = itemdb_search(items[i].nameid);
  2534. if( !itemdb_isstackable2(id) ) { //Equippable
  2535. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2536. ne++;
  2537. }
  2538. else { //Stackable
  2539. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2540. n++;
  2541. }
  2542. }
  2543. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2544. {
  2545. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2546. WFIFOHEAD(sd->fd,sidx+nn*s);
  2547. WFIFOW(sd->fd,0)=cmd;
  2548. WFIFOW(sd->fd,2)=sidx+nn*s;
  2549. #if PACKETVER >= 20120925
  2550. memset(WFIFOCP(sd->fd,4),0,24); //storename
  2551. #endif
  2552. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2553. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2554. }
  2555. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2556. {
  2557. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2558. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2559. WFIFOW(sd->fd,0)=cmde;
  2560. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2561. #if PACKETVER >= 20120925
  2562. memset(WFIFOCP(sd->fd,4),0,24); //storename
  2563. #endif
  2564. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2565. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2566. }
  2567. if( buf ) aFree(buf);
  2568. if( bufe ) aFree(bufe);
  2569. }
  2570. void clif_cartlist(struct map_session_data *sd)
  2571. {
  2572. struct item_data *id;
  2573. int i,n,ne;
  2574. unsigned char *buf;
  2575. unsigned char *bufe;
  2576. #if PACKETVER < 5
  2577. const int s = 10; //Entry size.
  2578. #elif PACKETVER < 20080102
  2579. const int s = 18;
  2580. #elif PACKETVER < 20120925
  2581. const int s = 22;
  2582. #else
  2583. const int s = 24;
  2584. #endif
  2585. #if PACKETVER < 20071002
  2586. const int cmd = 20;
  2587. #elif PACKETVER < 20100629
  2588. const int cmd = 26;
  2589. #elif PACKETVER < 20120925
  2590. const int cmd = 28;
  2591. #elif PACKETVER < 20150226
  2592. const int cmd = 31;
  2593. #else
  2594. const int cmd = 57;
  2595. #endif
  2596. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2597. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2598. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2599. {
  2600. if( sd->status.cart[i].nameid <= 0 )
  2601. continue;
  2602. id = itemdb_search(sd->status.cart[i].nameid);
  2603. if( !itemdb_isstackable2(id) ) { //Equippable
  2604. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2605. ne++;
  2606. }
  2607. else { //Stackable
  2608. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2609. n++;
  2610. }
  2611. }
  2612. if( n )
  2613. {
  2614. #if PACKETVER < 5
  2615. WBUFW(buf,0)=0x123;
  2616. #elif PACKETVER < 20080102
  2617. WBUFW(buf,0)=0x1ef;
  2618. #elif PACKETVER < 20120925
  2619. WBUFW(buf,0)=0x2e9;
  2620. #else
  2621. WBUFW(buf,0)=0x993;
  2622. #endif
  2623. WBUFW(buf,2)=4+n*s;
  2624. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2625. }
  2626. if( ne )
  2627. {
  2628. #if PACKETVER < 20071002
  2629. WBUFW(bufe,0)=0x122;
  2630. #elif PACKETVER < 20120925
  2631. WBUFW(bufe,0)=0x2d2;
  2632. #elif PACKETVER < 20150226
  2633. WBUFW(bufe,0)=0x994;
  2634. #else
  2635. WBUFW(bufe,0)=0xa0f;
  2636. #endif
  2637. WBUFW(bufe,2)=4+ne*cmd;
  2638. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2639. }
  2640. if( buf ) aFree(buf);
  2641. if( bufe ) aFree(bufe);
  2642. }
  2643. /// Removes cart (ZC_CARTOFF).
  2644. /// 012b
  2645. /// Client behaviour:
  2646. /// Closes the cart storage and removes all it's items from memory.
  2647. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2648. void clif_clearcart(int fd)
  2649. {
  2650. WFIFOHEAD(fd, packet_len(0x12b));
  2651. WFIFOW(fd,0) = 0x12b;
  2652. WFIFOSET(fd, packet_len(0x12b));
  2653. }
  2654. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2655. /// 01eb <account id>.L <x>.W <y>.W
  2656. void clif_guild_xy(struct map_session_data *sd)
  2657. {
  2658. unsigned char buf[10];
  2659. nullpo_retv(sd);
  2660. WBUFW(buf,0)=0x1eb;
  2661. WBUFL(buf,2)=sd->status.account_id;
  2662. WBUFW(buf,6)=sd->bl.x;
  2663. WBUFW(buf,8)=sd->bl.y;
  2664. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2665. }
  2666. /*==========================================
  2667. * Sends x/y dot to a single fd. [Skotlex]
  2668. *------------------------------------------*/
  2669. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2670. {
  2671. if( sd->bg_id )
  2672. return;
  2673. WFIFOHEAD(fd,packet_len(0x1eb));
  2674. WFIFOW(fd,0)=0x1eb;
  2675. WFIFOL(fd,2)=sd->status.account_id;
  2676. WFIFOW(fd,6)=sd->bl.x;
  2677. WFIFOW(fd,8)=sd->bl.y;
  2678. WFIFOSET(fd,packet_len(0x1eb));
  2679. }
  2680. // Guild XY locators [Valaris]
  2681. void clif_guild_xy_remove(struct map_session_data *sd)
  2682. {
  2683. unsigned char buf[10];
  2684. nullpo_retv(sd);
  2685. WBUFW(buf,0)=0x1eb;
  2686. WBUFL(buf,2)=sd->status.account_id;
  2687. WBUFW(buf,6)=-1;
  2688. WBUFW(buf,8)=-1;
  2689. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2690. }
  2691. /*==========================================
  2692. *
  2693. *------------------------------------------*/
  2694. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2695. {
  2696. struct map_session_data *sd, *tsd;
  2697. #if PACKETVER < 20100126
  2698. const int cmd = 0x106;
  2699. #else
  2700. const int cmd = 0x80e;
  2701. #endif
  2702. sd = va_arg(ap, struct map_session_data *);
  2703. tsd = (TBL_PC *)bl;
  2704. nullpo_ret(sd);
  2705. nullpo_ret(tsd);
  2706. if( !tsd->fd || tsd == sd )
  2707. return 0;
  2708. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2709. return 0;
  2710. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2711. WFIFOW(tsd->fd,0) = cmd;
  2712. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2713. #if PACKETVER < 20100126
  2714. if( sd->battle_status.max_hp > INT16_MAX )
  2715. { //To correctly display the %hp bar. [Skotlex]
  2716. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2717. WFIFOW(tsd->fd,8) = 100;
  2718. } else {
  2719. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2720. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2721. }
  2722. #else
  2723. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2724. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2725. #endif
  2726. WFIFOSET(tsd->fd,packet_len(cmd));
  2727. return 0;
  2728. }
  2729. /*==========================================
  2730. * Server tells all players that are allowed to view HP bars
  2731. * and are nearby 'sd' that 'sd' hp bar was updated.
  2732. *------------------------------------------*/
  2733. static int clif_hpmeter(struct map_session_data *sd)
  2734. {
  2735. nullpo_ret(sd);
  2736. 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);
  2737. return 0;
  2738. }
  2739. /// Notifies client of a character parameter change.
  2740. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2741. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2742. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2743. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2744. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2745. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2746. /// TODO: Extract individual packets.
  2747. /// FIXME: Packet lengths from packet_len(cmd)
  2748. void clif_updatestatus(struct map_session_data *sd,int type)
  2749. {
  2750. int fd,len=8;
  2751. nullpo_retv(sd);
  2752. fd=sd->fd;
  2753. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2754. return;
  2755. WFIFOHEAD(fd, 14);
  2756. WFIFOW(fd,0)=0xb0;
  2757. WFIFOW(fd,2)=type;
  2758. switch(type){
  2759. // 00b0
  2760. case SP_WEIGHT:
  2761. pc_updateweightstatus(sd);
  2762. WFIFOHEAD(fd,14);
  2763. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2764. WFIFOW(fd,2)=type;
  2765. WFIFOL(fd,4)=sd->weight;
  2766. break;
  2767. case SP_MAXWEIGHT:
  2768. WFIFOL(fd,4)=sd->max_weight;
  2769. break;
  2770. case SP_SPEED:
  2771. WFIFOL(fd,4)=sd->battle_status.speed;
  2772. break;
  2773. case SP_BASELEVEL:
  2774. WFIFOL(fd,4)=sd->status.base_level;
  2775. break;
  2776. case SP_JOBLEVEL:
  2777. WFIFOL(fd,4)=sd->status.job_level;
  2778. break;
  2779. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2780. WFIFOL(fd,4)=sd->status.karma;
  2781. break;
  2782. case SP_MANNER:
  2783. WFIFOL(fd,4)=sd->status.manner;
  2784. break;
  2785. case SP_STATUSPOINT:
  2786. WFIFOL(fd,4)=sd->status.status_point;
  2787. break;
  2788. case SP_SKILLPOINT:
  2789. WFIFOL(fd,4)=sd->status.skill_point;
  2790. break;
  2791. case SP_HIT:
  2792. WFIFOL(fd,4)=sd->battle_status.hit;
  2793. break;
  2794. case SP_FLEE1:
  2795. WFIFOL(fd,4)=sd->battle_status.flee;
  2796. break;
  2797. case SP_FLEE2:
  2798. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2799. break;
  2800. case SP_MAXHP:
  2801. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2802. break;
  2803. case SP_MAXSP:
  2804. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2805. break;
  2806. case SP_HP:
  2807. // On officials the HP never go below 1, even if you die [Lemongrass]
  2808. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2809. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2810. // TODO: Won't these overwrite the current packet?
  2811. if( map[sd->bl.m].hpmeter_visible )
  2812. clif_hpmeter(sd);
  2813. if( !battle_config.party_hp_mode && sd->status.party_id )
  2814. clif_party_hp(sd);
  2815. if( sd->bg_id )
  2816. clif_bg_hp(sd);
  2817. break;
  2818. case SP_SP:
  2819. WFIFOL(fd,4)=sd->battle_status.sp;
  2820. break;
  2821. case SP_ASPD:
  2822. WFIFOL(fd,4)=sd->battle_status.amotion;
  2823. break;
  2824. case SP_ATK1:
  2825. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2826. break;
  2827. case SP_DEF1:
  2828. WFIFOL(fd,4)=pc_leftside_def(sd);
  2829. break;
  2830. case SP_MDEF1:
  2831. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2832. break;
  2833. case SP_ATK2:
  2834. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2835. break;
  2836. case SP_DEF2:
  2837. WFIFOL(fd,4)=pc_rightside_def(sd);
  2838. break;
  2839. case SP_MDEF2: {
  2840. //negative check (in case you have something like Berserk active)
  2841. int mdef2 = pc_rightside_mdef(sd);
  2842. WFIFOL(fd,4)=
  2843. #ifndef RENEWAL
  2844. ( mdef2 < 0 ) ? 0 :
  2845. #endif
  2846. mdef2;
  2847. }
  2848. break;
  2849. case SP_CRITICAL:
  2850. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2851. break;
  2852. case SP_MATK1:
  2853. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2854. break;
  2855. case SP_MATK2:
  2856. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2857. break;
  2858. case SP_ZENY:
  2859. WFIFOW(fd,0)=0xb1;
  2860. WFIFOL(fd,4)=sd->status.zeny;
  2861. break;
  2862. case SP_BASEEXP:
  2863. WFIFOW(fd,0)=0xb1;
  2864. WFIFOL(fd,4)=sd->status.base_exp;
  2865. break;
  2866. case SP_JOBEXP:
  2867. WFIFOW(fd,0)=0xb1;
  2868. WFIFOL(fd,4)=sd->status.job_exp;
  2869. break;
  2870. case SP_NEXTBASEEXP:
  2871. WFIFOW(fd,0)=0xb1;
  2872. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2873. break;
  2874. case SP_NEXTJOBEXP:
  2875. WFIFOW(fd,0)=0xb1;
  2876. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2877. break;
  2878. /**
  2879. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2880. **/
  2881. case SP_USTR:
  2882. case SP_UAGI:
  2883. case SP_UVIT:
  2884. case SP_UINT:
  2885. case SP_UDEX:
  2886. case SP_ULUK:
  2887. WFIFOW(fd,0)=0xbe;
  2888. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2889. len=5;
  2890. break;
  2891. /**
  2892. * Tells the client how far it is allowed to attack (weapon range)
  2893. **/
  2894. case SP_ATTACKRANGE:
  2895. WFIFOW(fd,0)=0x13a;
  2896. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2897. len=4;
  2898. break;
  2899. case SP_STR:
  2900. WFIFOW(fd,0)=0x141;
  2901. WFIFOL(fd,2)=type;
  2902. WFIFOL(fd,6)=sd->status.str;
  2903. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2904. len=14;
  2905. break;
  2906. case SP_AGI:
  2907. WFIFOW(fd,0)=0x141;
  2908. WFIFOL(fd,2)=type;
  2909. WFIFOL(fd,6)=sd->status.agi;
  2910. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2911. len=14;
  2912. break;
  2913. case SP_VIT:
  2914. WFIFOW(fd,0)=0x141;
  2915. WFIFOL(fd,2)=type;
  2916. WFIFOL(fd,6)=sd->status.vit;
  2917. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2918. len=14;
  2919. break;
  2920. case SP_INT:
  2921. WFIFOW(fd,0)=0x141;
  2922. WFIFOL(fd,2)=type;
  2923. WFIFOL(fd,6)=sd->status.int_;
  2924. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2925. len=14;
  2926. break;
  2927. case SP_DEX:
  2928. WFIFOW(fd,0)=0x141;
  2929. WFIFOL(fd,2)=type;
  2930. WFIFOL(fd,6)=sd->status.dex;
  2931. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2932. len=14;
  2933. break;
  2934. case SP_LUK:
  2935. WFIFOW(fd,0)=0x141;
  2936. WFIFOL(fd,2)=type;
  2937. WFIFOL(fd,6)=sd->status.luk;
  2938. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2939. len=14;
  2940. break;
  2941. case SP_CARTINFO:
  2942. WFIFOW(fd,0)=0x121;
  2943. WFIFOW(fd,2)=sd->cart_num;
  2944. WFIFOW(fd,4)=MAX_CART;
  2945. WFIFOL(fd,6)=sd->cart_weight;
  2946. WFIFOL(fd,10)=sd->cart_weight_max;
  2947. len=14;
  2948. break;
  2949. default:
  2950. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2951. return;
  2952. }
  2953. WFIFOSET(fd,len);
  2954. }
  2955. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2956. /// 01ab <account id>.L <var id>.W <value>.L
  2957. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2958. {
  2959. unsigned char buf[12];
  2960. nullpo_retv(sd);
  2961. WBUFW(buf,0)=0x1ab;
  2962. WBUFL(buf,2)=sd->bl.id;
  2963. WBUFW(buf,6)=type;
  2964. switch(type)
  2965. {
  2966. case SP_MANNER:
  2967. WBUFL(buf,8)=val;
  2968. break;
  2969. default:
  2970. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2971. return;
  2972. }
  2973. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2974. }
  2975. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2976. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2977. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  2978. unsigned char buf[32];
  2979. #if PACKETVER < 4
  2980. const int cmd = 0xc3;
  2981. #else
  2982. const int cmd = 0x1d7;
  2983. #endif
  2984. WBUFW(buf,0) = cmd;
  2985. WBUFL(buf,2) = id;
  2986. WBUFB(buf,6) = type;
  2987. WBUFW(buf,7) = val;
  2988. #if PACKETVER >= 4
  2989. WBUFW(buf,9) = val2;
  2990. #endif
  2991. clif_send(buf,packet_len(cmd), bl, target);
  2992. }
  2993. /// Updates sprite/style properties of an object.
  2994. void clif_changelook(struct block_list *bl, int type, int val) {
  2995. struct map_session_data* sd;
  2996. struct status_change* sc;
  2997. struct view_data* vd;
  2998. enum send_target target = AREA;
  2999. int val2 = 0;
  3000. nullpo_retv(bl);
  3001. sd = BL_CAST(BL_PC, bl);
  3002. sc = status_get_sc(bl);
  3003. vd = status_get_viewdata(bl);
  3004. if( vd ) //temp hack to let Warp Portal change appearance
  3005. switch(type) {
  3006. case LOOK_WEAPON:
  3007. if (sd) {
  3008. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3009. val = vd->weapon;
  3010. }
  3011. else
  3012. vd->weapon = val;
  3013. break;
  3014. case LOOK_SHIELD:
  3015. if (sd) {
  3016. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3017. val = vd->shield;
  3018. }
  3019. else
  3020. vd->shield = val;
  3021. break;
  3022. case LOOK_BASE:
  3023. if (!sd)
  3024. break;
  3025. if ( val == INVISIBLE_CLASS )
  3026. return;
  3027. if (sd->sc.option&OPTION_COSTUME)
  3028. vd->weapon = vd->shield = 0;
  3029. if (!vd->cloth_color)
  3030. break;
  3031. if (sd) {
  3032. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3033. vd->cloth_color = 0;
  3034. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3035. vd->cloth_color = 0;
  3036. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3037. vd->cloth_color = 0;
  3038. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3039. vd->cloth_color = 0;
  3040. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3041. vd->cloth_color = 0;
  3042. if (vd->body_style && (
  3043. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3044. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3045. sd->sc.option&OPTION_OKTOBERFEST))
  3046. vd->body_style = 0;
  3047. }
  3048. break;
  3049. case LOOK_HAIR:
  3050. vd->hair_style = val;
  3051. break;
  3052. case LOOK_HEAD_BOTTOM:
  3053. vd->head_bottom = val;
  3054. break;
  3055. case LOOK_HEAD_TOP:
  3056. vd->head_top = val;
  3057. break;
  3058. case LOOK_HEAD_MID:
  3059. vd->head_mid = val;
  3060. break;
  3061. case LOOK_HAIR_COLOR:
  3062. vd->hair_color = val;
  3063. break;
  3064. case LOOK_CLOTHES_COLOR:
  3065. if (val && sd) {
  3066. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3067. val = 0;
  3068. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3069. val = 0;
  3070. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3071. val = 0;
  3072. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3073. val = 0;
  3074. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3075. val = 0;
  3076. }
  3077. vd->cloth_color = val;
  3078. break;
  3079. case LOOK_SHOES:
  3080. #if PACKETVER > 3
  3081. if (sd) {
  3082. int n;
  3083. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3084. if(sd->inventory_data[n]->view_id > 0)
  3085. val = sd->inventory_data[n]->view_id;
  3086. else
  3087. val = sd->status.inventory[n].nameid;
  3088. } else
  3089. val = 0;
  3090. }
  3091. #endif
  3092. //Shoes? No packet uses this....
  3093. break;
  3094. case LOOK_BODY:
  3095. // unknown purpose
  3096. break;
  3097. case LOOK_ROBE:
  3098. #if PACKETVER < 20110111
  3099. return;
  3100. #else
  3101. vd->robe = val;
  3102. #endif
  3103. break;
  3104. case LOOK_BODY2:
  3105. #if PACKETVER < 20150513
  3106. return;
  3107. #else
  3108. if (val && (
  3109. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3110. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3111. sd->sc.option&OPTION_OKTOBERFEST))
  3112. val = 0;
  3113. vd->body_style = val;
  3114. #endif
  3115. break;
  3116. }
  3117. // prevent leaking the presence of GM-hidden objects
  3118. if( sc && sc->option&OPTION_INVISIBLE )
  3119. target = SELF;
  3120. #if PACKETVER < 4
  3121. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3122. #else
  3123. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3124. nullpo_retv(vd);
  3125. type = LOOK_WEAPON;
  3126. val = vd->weapon;
  3127. val2 = vd->shield;
  3128. }
  3129. if( disguised(bl) ) {
  3130. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3131. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3132. } else
  3133. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3134. #endif
  3135. }
  3136. //Sends a change-base-look packet required for traps as they are triggered.
  3137. void clif_changetraplook(struct block_list *bl,int val) {
  3138. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3139. }
  3140. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3141. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3142. clif_sprite_change(bl, id, type, val, 0, target);
  3143. }
  3144. /// Character status (ZC_STATUS).
  3145. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3146. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3147. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3148. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3149. void clif_initialstatus(struct map_session_data *sd) {
  3150. int fd, mdef2;
  3151. unsigned char *buf;
  3152. nullpo_retv(sd);
  3153. fd=sd->fd;
  3154. WFIFOHEAD(fd, packet_len(0xbd));
  3155. buf = WFIFOP(fd,0);
  3156. WBUFW(buf,0) = 0xbd;
  3157. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3158. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3159. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3160. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3161. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3162. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3163. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3164. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3165. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3166. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3167. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3168. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3169. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3170. WBUFW(buf,16) = pc_leftside_atk(sd);
  3171. WBUFW(buf,18) = pc_rightside_atk(sd);
  3172. WBUFW(buf,20) = pc_rightside_matk(sd);
  3173. WBUFW(buf,22) = pc_leftside_matk(sd);
  3174. WBUFW(buf,24) = pc_leftside_def(sd);
  3175. WBUFW(buf,26) = pc_rightside_def(sd);
  3176. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3177. mdef2 = pc_rightside_mdef(sd);
  3178. WBUFW(buf,30) =
  3179. #ifndef RENEWAL
  3180. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3181. #endif
  3182. mdef2;
  3183. WBUFW(buf,32) = sd->battle_status.hit;
  3184. WBUFW(buf,34) = sd->battle_status.flee;
  3185. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3186. WBUFW(buf,38) = sd->battle_status.cri/10;
  3187. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3188. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3189. WFIFOSET(fd, packet_len(0xbd));
  3190. clif_updatestatus(sd, SP_STR);
  3191. clif_updatestatus(sd, SP_AGI);
  3192. clif_updatestatus(sd, SP_VIT);
  3193. clif_updatestatus(sd, SP_INT);
  3194. clif_updatestatus(sd, SP_DEX);
  3195. clif_updatestatus(sd, SP_LUK);
  3196. clif_updatestatus(sd, SP_ATTACKRANGE);
  3197. clif_updatestatus(sd, SP_ASPD);
  3198. }
  3199. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3200. /// 013c <index>.W
  3201. void clif_arrowequip(struct map_session_data *sd,int val) {
  3202. int fd;
  3203. nullpo_retv(sd);
  3204. #if PACKETVER >= 20121128
  3205. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3206. #endif
  3207. fd=sd->fd;
  3208. WFIFOHEAD(fd, packet_len(0x013c));
  3209. WFIFOW(fd,0) = 0x013c;
  3210. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3211. WFIFOSET(fd, packet_len(0x013c));
  3212. }
  3213. /// Ammunition action message (ZC_ACTION_FAILURE).
  3214. /// 013b <type>.W
  3215. /// type:
  3216. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3217. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3218. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3219. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3220. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3221. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3222. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3223. int fd;
  3224. nullpo_retv(sd);
  3225. fd=sd->fd;
  3226. WFIFOHEAD(fd, packet_len(0x013b));
  3227. WFIFOW(fd,0) = 0x013b;
  3228. WFIFOW(fd,2) = type;
  3229. WFIFOSET(fd, packet_len(0x013b));
  3230. }
  3231. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3232. /// 01ad <packet len>.W { <name id>.W }*
  3233. void clif_arrow_create_list(struct map_session_data *sd)
  3234. {
  3235. int i, c;
  3236. int fd;
  3237. nullpo_retv(sd);
  3238. fd = sd->fd;
  3239. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3240. WFIFOW(fd,0) = 0x1ad;
  3241. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3242. short j, nameid = skill_arrow_db[i].nameid;
  3243. if (nameid > 0 && itemdb_exists(nameid) &&
  3244. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3245. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  3246. {
  3247. if ((j = itemdb_viewid(nameid)) > 0)
  3248. WFIFOW(fd,c*2+4) = j;
  3249. else
  3250. WFIFOW(fd,c*2+4) = nameid;
  3251. c++;
  3252. }
  3253. }
  3254. WFIFOW(fd,2) = c*2+4;
  3255. WFIFOSET(fd, WFIFOW(fd,2));
  3256. if (c > 0) {
  3257. sd->menuskill_id = AC_MAKINGARROW;
  3258. sd->menuskill_val = c;
  3259. }
  3260. }
  3261. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3262. /// 00bc <status id>.W <result>.B <value>.B
  3263. /// status id:
  3264. /// SP_STR ~ SP_LUK
  3265. /// result:
  3266. /// 0 = failure
  3267. /// 1 = success
  3268. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3269. int fd;
  3270. nullpo_retv(sd);
  3271. fd=sd->fd;
  3272. WFIFOHEAD(fd, packet_len(0xbc));
  3273. WFIFOW(fd,0) = 0xbc;
  3274. WFIFOW(fd,2) = type;
  3275. WFIFOB(fd,4) = ok;
  3276. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3277. WFIFOSET(fd, packet_len(0xbc));
  3278. }
  3279. /// Notifies the client about the result of a request to equip an item.
  3280. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3281. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3282. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3283. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3284. /// @ok: //inversed forv2 v5
  3285. /// 0 = failure
  3286. /// 1 = success
  3287. /// 2 = failure due to low level
  3288. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3289. {
  3290. int fd = 0, cmd = 0, look = 0;
  3291. struct s_packet_db *info = NULL;
  3292. nullpo_retv(sd);
  3293. cmd = packet_db_ack[sd->packet_ver][ZC_WEAR_EQUIP_ACK];
  3294. if (!cmd || !(info = &packet_db[sd->packet_ver][cmd]) || !info->len)
  3295. return;
  3296. fd = sd->fd;
  3297. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3298. look = sd->inventory_data[n]->look;
  3299. WFIFOHEAD(fd, info->len);
  3300. WFIFOW(fd, 0) = cmd;
  3301. WFIFOW(fd, info->pos[0]) = n+2;
  3302. switch (cmd) {
  3303. case 0xaa:
  3304. WFIFOW(fd, info->pos[1]) = pos;
  3305. if (sd->packet_ver < date2version(20100629))
  3306. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3307. else {
  3308. WFIFOL(fd, info->pos[2]) = look;
  3309. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3310. }
  3311. break;
  3312. case 0x8d0:
  3313. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3314. flag = 1;
  3315. case 0x999:
  3316. if (cmd == 0x999)
  3317. WFIFOL(fd, info->pos[1]) = pos;
  3318. else
  3319. WFIFOW(fd, info->pos[1]) = pos;
  3320. WFIFOL(fd, info->pos[2]) = look;
  3321. WFIFOW(fd, info->pos[3]) = flag;
  3322. break;
  3323. }
  3324. WFIFOSET(fd, info->len);
  3325. }
  3326. /// Notifies the client about the result of a request to take off an item.
  3327. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3328. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3329. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3330. /// @ok : //inversed for v2 v5
  3331. /// 0 = failure
  3332. /// 1 = success
  3333. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3334. {
  3335. int fd, header, offs = 0;
  3336. #if PACKETVER >= 20130000
  3337. header = 0x99a;
  3338. ok = ok ? 0 : 1;
  3339. #elif PACKETVER >= 20110824
  3340. header = 0x8d1;
  3341. ok = ok ? 0 : 1;
  3342. #else
  3343. header = 0xac;
  3344. #endif
  3345. nullpo_retv(sd);
  3346. fd=sd->fd;
  3347. WFIFOHEAD(fd, packet_len(header));
  3348. WFIFOW(fd,offs+0) = header;
  3349. WFIFOW(fd,offs+2) = n+2;
  3350. #if PACKETVER >= 20130000
  3351. WFIFOL(fd,offs+4) = pos;
  3352. offs += 2;
  3353. #else
  3354. WFIFOW(fd,offs+4) = pos;
  3355. #endif
  3356. WFIFOB(fd,offs+6) = ok;
  3357. WFIFOSET(fd, packet_len(header));
  3358. }
  3359. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3360. /// 019b <id>.L <effect id>.L
  3361. /// effect id:
  3362. /// 0 = base level up
  3363. /// 1 = job level up
  3364. /// 2 = refine failure
  3365. /// 3 = refine success
  3366. /// 4 = game over
  3367. /// 5 = pharmacy success
  3368. /// 6 = pharmacy failure
  3369. /// 7 = base level up (super novice)
  3370. /// 8 = job level up (super novice)
  3371. /// 9 = base level up (taekwon)
  3372. void clif_misceffect(struct block_list* bl,int type)
  3373. {
  3374. unsigned char buf[32];
  3375. nullpo_retv(bl);
  3376. WBUFW(buf,0) = 0x19b;
  3377. WBUFL(buf,2) = bl->id;
  3378. WBUFL(buf,6) = type;
  3379. clif_send(buf,packet_len(0x19b),bl,AREA);
  3380. }
  3381. /// Notifies clients in the area of a state change.
  3382. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3383. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3384. void clif_changeoption(struct block_list* bl)
  3385. {
  3386. unsigned char buf[32];
  3387. struct status_change *sc;
  3388. struct map_session_data* sd;
  3389. nullpo_retv(bl);
  3390. sc = status_get_sc(bl);
  3391. if (!sc) return; //How can an option change if there's no sc?
  3392. sd = BL_CAST(BL_PC, bl);
  3393. #if PACKETVER >= 7
  3394. WBUFW(buf,0) = 0x229;
  3395. WBUFL(buf,2) = bl->id;
  3396. WBUFW(buf,6) = sc->opt1;
  3397. WBUFW(buf,8) = sc->opt2;
  3398. WBUFL(buf,10) = sc->option;
  3399. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3400. if(disguised(bl)) {
  3401. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3402. WBUFL(buf,2) = -bl->id;
  3403. clif_send(buf,packet_len(0x229),bl,SELF);
  3404. WBUFL(buf,2) = bl->id;
  3405. WBUFL(buf,10) = OPTION_INVISIBLE;
  3406. clif_send(buf,packet_len(0x229),bl,SELF);
  3407. } else
  3408. clif_send(buf,packet_len(0x229),bl,AREA);
  3409. #else
  3410. WBUFW(buf,0) = 0x119;
  3411. WBUFL(buf,2) = bl->id;
  3412. WBUFW(buf,6) = sc->opt1;
  3413. WBUFW(buf,8) = sc->opt2;
  3414. WBUFW(buf,10) = sc->option;
  3415. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3416. if(disguised(bl)) {
  3417. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3418. WBUFL(buf,2) = -bl->id;
  3419. clif_send(buf,packet_len(0x119),bl,SELF);
  3420. WBUFL(buf,2) = bl->id;
  3421. WBUFW(buf,10) = OPTION_INVISIBLE;
  3422. clif_send(buf,packet_len(0x119),bl,SELF);
  3423. } else
  3424. clif_send(buf,packet_len(0x119),bl,AREA);
  3425. #endif
  3426. }
  3427. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3428. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3429. void clif_changeoption2(struct block_list* bl)
  3430. {
  3431. unsigned char buf[20];
  3432. struct status_change *sc;
  3433. sc = status_get_sc(bl);
  3434. if (!sc) return; //How can an option change if there's no sc?
  3435. WBUFW(buf,0) = 0x28a;
  3436. WBUFL(buf,2) = bl->id;
  3437. WBUFL(buf,6) = sc->option;
  3438. WBUFL(buf,10) = clif_setlevel(bl);
  3439. WBUFL(buf,14) = sc->opt3;
  3440. if(disguised(bl)) {
  3441. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3442. WBUFL(buf,2) = -bl->id;
  3443. clif_send(buf,packet_len(0x28a),bl,SELF);
  3444. WBUFL(buf,2) = bl->id;
  3445. WBUFL(buf,6) = OPTION_INVISIBLE;
  3446. clif_send(buf,packet_len(0x28a),bl,SELF);
  3447. } else
  3448. clif_send(buf,packet_len(0x28a),bl,AREA);
  3449. }
  3450. /// Notifies the client about the result of an item use request.
  3451. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3452. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3453. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3454. {
  3455. nullpo_retv(sd);
  3456. if(!ok) {
  3457. int fd=sd->fd;
  3458. WFIFOHEAD(fd,packet_len(0xa8));
  3459. WFIFOW(fd,0)=0xa8;
  3460. WFIFOW(fd,2)=index+2;
  3461. WFIFOW(fd,4)=amount;
  3462. WFIFOB(fd,6)=ok;
  3463. WFIFOSET(fd,packet_len(0xa8));
  3464. }
  3465. else {
  3466. #if PACKETVER < 3
  3467. int fd=sd->fd;
  3468. WFIFOHEAD(fd,packet_len(0xa8));
  3469. WFIFOW(fd,0)=0xa8;
  3470. WFIFOW(fd,2)=index+2;
  3471. WFIFOW(fd,4)=amount;
  3472. WFIFOB(fd,6)=ok;
  3473. WFIFOSET(fd,packet_len(0xa8));
  3474. #else
  3475. unsigned char buf[32];
  3476. WBUFW(buf,0)=0x1c8;
  3477. WBUFW(buf,2)=index+2;
  3478. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3479. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3480. else
  3481. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3482. WBUFL(buf,6)=sd->bl.id;
  3483. WBUFW(buf,10)=amount;
  3484. WBUFB(buf,12)=ok;
  3485. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3486. #endif
  3487. }
  3488. }
  3489. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3490. /// 00d6 <flag>.B
  3491. /// flag:
  3492. /// 0 = Room has been successfully created (opens chat room)
  3493. /// 1 = Room limit exceeded
  3494. /// 2 = Same room already exists
  3495. void clif_createchat(struct map_session_data* sd, int flag)
  3496. {
  3497. int fd;
  3498. nullpo_retv(sd);
  3499. fd = sd->fd;
  3500. WFIFOHEAD(fd,packet_len(0xd6));
  3501. WFIFOW(fd,0) = 0xd6;
  3502. WFIFOB(fd,2) = flag;
  3503. WFIFOSET(fd,packet_len(0xd6));
  3504. }
  3505. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3506. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3507. /// type:
  3508. /// 0 = private (password protected)
  3509. /// 1 = public
  3510. /// 2 = arena (npc waiting room)
  3511. /// 3 = PK zone (non-clickable)
  3512. void clif_dispchat(struct chat_data* cd, int fd)
  3513. {
  3514. unsigned char buf[128];
  3515. uint8 type;
  3516. if( cd == NULL || cd->owner == NULL )
  3517. return;
  3518. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3519. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3520. : 1;
  3521. WBUFW(buf, 0) = 0xd7;
  3522. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3523. WBUFL(buf, 4) = cd->owner->id;
  3524. WBUFL(buf, 8) = cd->bl.id;
  3525. WBUFW(buf,12) = cd->limit;
  3526. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3527. WBUFB(buf,16) = type;
  3528. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3529. if( fd ) {
  3530. WFIFOHEAD(fd,WBUFW(buf,2));
  3531. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3532. WFIFOSET(fd,WBUFW(buf,2));
  3533. } else {
  3534. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3535. }
  3536. }
  3537. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3538. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3539. /// type:
  3540. /// 0 = private (password protected)
  3541. /// 1 = public
  3542. /// 2 = arena (npc waiting room)
  3543. /// 3 = PK zone (non-clickable)
  3544. void clif_changechatstatus(struct chat_data* cd)
  3545. {
  3546. unsigned char buf[128];
  3547. uint8 type;
  3548. if( cd == NULL || cd->usersd[0] == NULL )
  3549. return;
  3550. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3551. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3552. : 1;
  3553. WBUFW(buf, 0) = 0xdf;
  3554. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3555. WBUFL(buf, 4) = cd->owner->id;
  3556. WBUFL(buf, 8) = cd->bl.id;
  3557. WBUFW(buf,12) = cd->limit;
  3558. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3559. WBUFB(buf,16) = type;
  3560. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3561. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3562. }
  3563. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3564. /// 00d8 <chat id>.L
  3565. void clif_clearchat(struct chat_data *cd,int fd)
  3566. {
  3567. unsigned char buf[32];
  3568. nullpo_retv(cd);
  3569. WBUFW(buf,0) = 0xd8;
  3570. WBUFL(buf,2) = cd->bl.id;
  3571. if( fd ) {
  3572. WFIFOHEAD(fd,packet_len(0xd8));
  3573. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3574. WFIFOSET(fd,packet_len(0xd8));
  3575. } else {
  3576. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3577. }
  3578. }
  3579. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3580. /// 00da <result>.B
  3581. /// result:
  3582. /// 0 = room full
  3583. /// 1 = wrong password
  3584. /// 2 = kicked
  3585. /// 3 = success (no message)
  3586. /// 4 = no enough zeny
  3587. /// 5 = too low level
  3588. /// 6 = too high level
  3589. /// 7 = unsuitable job class
  3590. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3591. {
  3592. int fd;
  3593. nullpo_retv(sd);
  3594. fd = sd->fd;
  3595. WFIFOHEAD(fd,packet_len(0xda));
  3596. WFIFOW(fd,0) = 0xda;
  3597. WFIFOB(fd,2) = flag;
  3598. WFIFOSET(fd,packet_len(0xda));
  3599. }
  3600. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3601. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3602. /// role:
  3603. /// 0 = owner (menu)
  3604. /// 1 = normal
  3605. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3606. {
  3607. int fd;
  3608. int i,t;
  3609. nullpo_retv(sd);
  3610. nullpo_retv(cd);
  3611. fd = sd->fd;
  3612. if (!session_isActive(fd))
  3613. return;
  3614. t = (int)(cd->owner->type == BL_NPC);
  3615. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3616. WFIFOW(fd, 0) = 0xdb;
  3617. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3618. WFIFOL(fd, 4) = cd->bl.id;
  3619. if(cd->owner->type == BL_NPC){
  3620. WFIFOL(fd, 30) = 1;
  3621. WFIFOL(fd, 8) = 0;
  3622. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3623. for (i = 0; i < cd->users; i++) {
  3624. WFIFOL(fd, 8+(i+1)*28) = 1;
  3625. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3626. }
  3627. }else{
  3628. for (i = 0; i < cd->users; i++) {
  3629. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3630. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3631. }
  3632. }
  3633. WFIFOSET(fd, WFIFOW(fd, 2));
  3634. }
  3635. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3636. /// 00dc <users>.W <name>.24B
  3637. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3638. {
  3639. unsigned char buf[29];
  3640. nullpo_retv(sd);
  3641. nullpo_retv(cd);
  3642. WBUFW(buf, 0) = 0xdc;
  3643. WBUFW(buf, 2) = cd->users;
  3644. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3645. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3646. }
  3647. /// Announce the new owner (ZC_ROLE_CHANGE).
  3648. /// 00e1 <role>.L <nick>.24B
  3649. /// role:
  3650. /// 0 = owner (menu)
  3651. /// 1 = normal
  3652. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3653. {
  3654. unsigned char buf[64];
  3655. nullpo_retv(sd);
  3656. nullpo_retv(cd);
  3657. WBUFW(buf, 0) = 0xe1;
  3658. WBUFL(buf, 2) = 1;
  3659. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3660. WBUFW(buf,30) = 0xe1;
  3661. WBUFL(buf,32) = 0;
  3662. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3663. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3664. }
  3665. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3666. /// 00dd <users>.W <nick>.24B <flag>.B
  3667. /// flag:
  3668. /// 0 = left
  3669. /// 1 = kicked
  3670. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3671. {
  3672. unsigned char buf[32];
  3673. nullpo_retv(sd);
  3674. nullpo_retv(cd);
  3675. WBUFW(buf, 0) = 0xdd;
  3676. WBUFW(buf, 2) = cd->users-1;
  3677. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3678. WBUFB(buf,28) = flag;
  3679. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3680. }
  3681. /// Opens a trade request window from char 'name'.
  3682. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3683. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3684. void clif_traderequest(struct map_session_data* sd, const char* name)
  3685. {
  3686. int fd = sd->fd;
  3687. #if PACKETVER < 6
  3688. WFIFOHEAD(fd,packet_len(0xe5));
  3689. WFIFOW(fd,0) = 0xe5;
  3690. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3691. WFIFOSET(fd,packet_len(0xe5));
  3692. #else
  3693. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3694. if( !tsd ) return;
  3695. WFIFOHEAD(fd,packet_len(0x1f4));
  3696. WFIFOW(fd,0) = 0x1f4;
  3697. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3698. WFIFOL(fd,26) = tsd->status.char_id;
  3699. WFIFOW(fd,30) = tsd->status.base_level;
  3700. WFIFOSET(fd,packet_len(0x1f4));
  3701. #endif
  3702. }
  3703. /// Reply to a trade-request.
  3704. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3705. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3706. /// result:
  3707. /// 0 = Char is too far
  3708. /// 1 = Character does not exist
  3709. /// 2 = Trade failed
  3710. /// 3 = Accept
  3711. /// 4 = Cancel
  3712. /// 5 = Busy
  3713. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3714. {
  3715. int fd = sd->fd;
  3716. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3717. if( PACKETVER < 6 || !tsd ) {
  3718. WFIFOHEAD(fd,packet_len(0xe7));
  3719. WFIFOW(fd,0) = 0xe7;
  3720. WFIFOB(fd,2) = type;
  3721. WFIFOSET(fd,packet_len(0xe7));
  3722. } else {
  3723. WFIFOHEAD(fd,packet_len(0x1f5));
  3724. WFIFOW(fd,0) = 0x1f5;
  3725. WFIFOB(fd,2) = type;
  3726. WFIFOL(fd,3) = tsd->status.char_id;
  3727. WFIFOW(fd,7) = tsd->status.base_level;
  3728. WFIFOSET(fd,packet_len(0x1f5));
  3729. }
  3730. }
  3731. /// Notifies the client about an item from other player in current trade.
  3732. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3733. /// 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)
  3734. /// 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)
  3735. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3736. {
  3737. int fd;
  3738. unsigned char *buf;
  3739. #if PACKETVER < 20100223
  3740. const int cmd = 0xe9;
  3741. #elif PACKETVER < 20150226
  3742. const int cmd = 0x80f;
  3743. #else
  3744. const int cmd = 0xa09;
  3745. #endif
  3746. nullpo_retv(sd);
  3747. nullpo_retv(tsd);
  3748. fd = tsd->fd;
  3749. buf = WFIFOP(fd,0);
  3750. WFIFOHEAD(fd,packet_len(cmd));
  3751. WBUFW(buf,0) = cmd;
  3752. if( index == 0 )
  3753. {
  3754. #if PACKETVER < 20100223
  3755. WBUFL(buf,2) = amount; //amount
  3756. WBUFW(buf,6) = 0; // type id
  3757. #else
  3758. WBUFW(buf,2) = 0; // type id
  3759. WBUFB(buf,4) = 0; // item type
  3760. WBUFL(buf,5) = amount; // amount
  3761. buf = WBUFP(buf,1); //Advance 1B
  3762. #endif
  3763. WBUFB(buf,8) = 0; //identify flag
  3764. WBUFB(buf,9) = 0; // attribute
  3765. WBUFB(buf,10)= 0; //refine
  3766. WBUFW(buf,11)= 0; //card (4w)
  3767. WBUFW(buf,13)= 0; //card (4w)
  3768. WBUFW(buf,15)= 0; //card (4w)
  3769. WBUFW(buf,17)= 0; //card (4w)
  3770. #if PACKETVER >= 20150226
  3771. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3772. #endif
  3773. }
  3774. else
  3775. {
  3776. index -= 2; //index fix
  3777. #if PACKETVER < 20100223
  3778. WBUFL(buf,2) = amount; //amount
  3779. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3780. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3781. else
  3782. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3783. #else
  3784. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3785. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3786. else
  3787. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3788. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3789. WBUFL(buf,5) = amount; // amount
  3790. buf = WBUFP(buf,1); //Advance 1B
  3791. #endif
  3792. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3793. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3794. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3795. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3796. #if PACKETVER >= 20150226
  3797. clif_add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3798. #endif
  3799. }
  3800. WFIFOSET(fd,packet_len(cmd));
  3801. }
  3802. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3803. /// 00ea <index>.W <result>.B
  3804. /// result:
  3805. /// 0 = success
  3806. /// 1 = overweight
  3807. /// 2 = trade canceled
  3808. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3809. {
  3810. int fd;
  3811. nullpo_retv(sd);
  3812. fd = sd->fd;
  3813. WFIFOHEAD(fd,packet_len(0xea));
  3814. WFIFOW(fd,0) = 0xea;
  3815. WFIFOW(fd,2) = index;
  3816. WFIFOB(fd,4) = fail;
  3817. WFIFOSET(fd,packet_len(0xea));
  3818. }
  3819. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3820. /// 00ec <who>.B
  3821. /// who:
  3822. /// 0 = self
  3823. /// 1 = other player
  3824. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3825. {
  3826. int fd;
  3827. nullpo_retv(sd);
  3828. fd = sd->fd;
  3829. WFIFOHEAD(fd,packet_len(0xec));
  3830. WFIFOW(fd,0) = 0xec;
  3831. WFIFOB(fd,2) = fail;
  3832. WFIFOSET(fd,packet_len(0xec));
  3833. }
  3834. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3835. /// 00ee
  3836. void clif_tradecancelled(struct map_session_data* sd)
  3837. {
  3838. int fd;
  3839. nullpo_retv(sd);
  3840. fd = sd->fd;
  3841. WFIFOHEAD(fd,packet_len(0xee));
  3842. WFIFOW(fd,0) = 0xee;
  3843. WFIFOSET(fd,packet_len(0xee));
  3844. }
  3845. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3846. /// 00f0 <result>.B
  3847. /// result:
  3848. /// 0 = success
  3849. /// 1 = failure
  3850. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3851. {
  3852. int fd;
  3853. nullpo_retv(sd);
  3854. fd = sd->fd;
  3855. WFIFOHEAD(fd,packet_len(0xf0));
  3856. WFIFOW(fd,0) = 0xf0;
  3857. WFIFOB(fd,2) = fail;
  3858. WFIFOSET(fd,packet_len(0xf0));
  3859. }
  3860. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3861. /// 00f1
  3862. /// NOTE: Unknown purpose. Items are not removed until the window is
  3863. /// refreshed (ex. by putting another item in there).
  3864. void clif_tradeundo(struct map_session_data* sd)
  3865. {
  3866. int fd = sd->fd;
  3867. WFIFOHEAD(fd,packet_len(0xf1));
  3868. WFIFOW(fd,0) = 0xf1;
  3869. WFIFOSET(fd,packet_len(0xf1));
  3870. }
  3871. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3872. /// 00f2 <current count>.W <max count>.W
  3873. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3874. {
  3875. int fd;
  3876. nullpo_retv(sd);
  3877. fd=sd->fd;
  3878. WFIFOHEAD(fd,packet_len(0xf2));
  3879. WFIFOW(fd,0) = 0xf2;
  3880. WFIFOW(fd,2) = amount;
  3881. WFIFOW(fd,4) = max_amount;
  3882. WFIFOSET(fd,packet_len(0xf2));
  3883. }
  3884. /// Notifies the client of an item being added to the storage.
  3885. /// 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)
  3886. /// 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)
  3887. /// 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)
  3888. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3889. {
  3890. #if PACKETVER < 5
  3891. const int cmd = 0xf4;
  3892. #elif PACKETVER < 20150226
  3893. const int cmd = 0x1c4;
  3894. #else
  3895. const int cmd = 0xa0a;
  3896. #endif
  3897. int view,fd;
  3898. int offset = 0;
  3899. nullpo_retv(sd);
  3900. nullpo_retv(i);
  3901. fd=sd->fd;
  3902. view = itemdb_viewid(i->nameid);
  3903. WFIFOHEAD(fd,packet_len(cmd));
  3904. WFIFOW(fd, 0) = cmd; // Storage item added
  3905. WFIFOW(fd, 2) = index+1; // index
  3906. WFIFOL(fd, 4) = amount; // amount
  3907. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3908. #if PACKETVER >= 5
  3909. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3910. offset += 1;
  3911. #endif
  3912. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3913. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3914. WFIFOB(fd,12+offset) = i->refine; //refine
  3915. clif_addcards(WFIFOP(fd,13+offset), i);
  3916. #if PACKETVER >= 20150226
  3917. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3918. #endif
  3919. WFIFOSET(fd,packet_len(cmd));
  3920. }
  3921. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3922. /// 00f6 <index>.W <amount>.L
  3923. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3924. {
  3925. int fd;
  3926. nullpo_retv(sd);
  3927. fd=sd->fd;
  3928. WFIFOHEAD(fd,packet_len(0xf6));
  3929. WFIFOW(fd,0)=0xf6; // Storage item removed
  3930. WFIFOW(fd,2)=index+1;
  3931. WFIFOL(fd,4)=amount;
  3932. WFIFOSET(fd,packet_len(0xf6));
  3933. }
  3934. /// Closes storage (ZC_CLOSE_STORE).
  3935. /// 00f8
  3936. void clif_storageclose(struct map_session_data* sd)
  3937. {
  3938. int fd;
  3939. nullpo_retv(sd);
  3940. fd=sd->fd;
  3941. WFIFOHEAD(fd,packet_len(0xf8));
  3942. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3943. WFIFOSET(fd,packet_len(0xf8));
  3944. }
  3945. /*==========================================
  3946. * Server tells 'sd' player client the abouts of 'dstsd' player
  3947. *------------------------------------------*/
  3948. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3949. {
  3950. struct block_list *d_bl;
  3951. int i;
  3952. if( dstsd->chatID ) {
  3953. struct chat_data *cd = NULL;
  3954. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3955. clif_dispchat(cd,sd->fd);
  3956. } else if( dstsd->state.vending )
  3957. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3958. else if( dstsd->state.buyingstore )
  3959. clif_buyingstore_entry_single(sd, dstsd);
  3960. if(dstsd->spiritball > 0)
  3961. clif_spiritball_single(sd->fd, dstsd);
  3962. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  3963. clif_spiritcharm_single(sd->fd, dstsd);
  3964. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3965. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3966. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3967. )
  3968. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3969. // display link (sd - dstsd) to sd
  3970. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3971. if( i < MAX_DEVOTION )
  3972. clif_devotion(&sd->bl, sd);
  3973. // display links (dstsd - devotees) to sd
  3974. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  3975. if( i < MAX_DEVOTION )
  3976. clif_devotion(&dstsd->bl, sd);
  3977. // display link (dstsd - crusader) to sd
  3978. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3979. clif_devotion(d_bl, sd);
  3980. }
  3981. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3982. {
  3983. uint8 buf[128];
  3984. struct unit_data *ud;
  3985. struct view_data *vd;
  3986. int len;
  3987. vd = status_get_viewdata(bl);
  3988. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3989. return;
  3990. /**
  3991. * Hide NPC from maya purple card.
  3992. **/
  3993. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3994. return;
  3995. ud = unit_bl2ud(bl);
  3996. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3997. clif_send(buf,len,&sd->bl,SELF);
  3998. if (vd->cloth_color)
  3999. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4000. if (vd->body_style)
  4001. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4002. switch (bl->type)
  4003. {
  4004. case BL_PC:
  4005. {
  4006. TBL_PC* tsd = (TBL_PC*)bl;
  4007. clif_getareachar_pc(sd, tsd);
  4008. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4009. clif_specialeffect_single(bl,423,sd->fd);
  4010. else if(tsd->state.size==SZ_MEDIUM)
  4011. clif_specialeffect_single(bl,421,sd->fd);
  4012. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4013. clif_sendbgemblem_single(sd->fd,tsd);
  4014. if ( tsd->status.robe )
  4015. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4016. clif_efst_status_change_sub(sd, bl, SELF);
  4017. clif_hat_effects(sd,bl,SELF);
  4018. }
  4019. break;
  4020. case BL_MER: // Devotion Effects
  4021. if( ((TBL_MER*)bl)->devotion_flag )
  4022. clif_devotion(bl, sd);
  4023. break;
  4024. case BL_NPC:
  4025. {
  4026. TBL_NPC* nd = (TBL_NPC*)bl;
  4027. if( nd->chat_id )
  4028. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4029. if( nd->size == SZ_BIG )
  4030. clif_specialeffect_single(bl,423,sd->fd);
  4031. else if( nd->size == SZ_MEDIUM )
  4032. clif_specialeffect_single(bl,421,sd->fd);
  4033. }
  4034. break;
  4035. case BL_MOB:
  4036. {
  4037. TBL_MOB* md = (TBL_MOB*)bl;
  4038. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4039. clif_specialeffect_single(bl,423,sd->fd);
  4040. else if(md->special_state.size==SZ_MEDIUM)
  4041. clif_specialeffect_single(bl,421,sd->fd);
  4042. #if PACKETVER >= 20120404
  4043. if( battle_config.monster_hp_bars_info){
  4044. int i;
  4045. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4046. if( md->dmglog[i].id == sd->status.char_id )
  4047. clif_monster_hp_bar(md, sd->fd);
  4048. }
  4049. #endif
  4050. }
  4051. break;
  4052. case BL_PET:
  4053. if (vd->head_bottom)
  4054. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4055. break;
  4056. }
  4057. }
  4058. //Modifies the type of damage according to status changes [Skotlex]
  4059. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4060. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4061. {
  4062. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4063. }
  4064. /*==========================================
  4065. * Estimates walk delay based on the damage criteria. [Skotlex]
  4066. *------------------------------------------*/
  4067. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4068. {
  4069. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4070. return 0;
  4071. if (bl->type == BL_PC) {
  4072. if (battle_config.pc_walk_delay_rate != 100)
  4073. delay = delay*battle_config.pc_walk_delay_rate/100;
  4074. } else
  4075. if (battle_config.walk_delay_rate != 100)
  4076. delay = delay*battle_config.walk_delay_rate/100;
  4077. if (div_ > 1) //Multi-hit skills mean higher delays.
  4078. delay += battle_config.multihit_delay*(div_-1);
  4079. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4080. }
  4081. /// Sends a 'damage' packet (src performs action on dst)
  4082. /// 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)
  4083. /// 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)
  4084. /// 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)
  4085. /// type:
  4086. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4087. /// 1 = pick up item
  4088. /// 2 = sit down
  4089. /// 3 = stand up
  4090. /// 4 = damage (endure)
  4091. /// 5 = (splash?)
  4092. /// 6 = (skill?)
  4093. /// 7 = (repeat damage?)
  4094. /// 8 = multi-hit damage
  4095. /// 9 = multi-hit damage (endure)
  4096. /// 10 = critical hit
  4097. /// 11 = lucky dodge
  4098. /// 12 = (touch skill?)
  4099. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4100. {
  4101. unsigned char buf[34];
  4102. struct status_change *sc;
  4103. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4104. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4105. #if PACKETVER < 20071113
  4106. const int cmd = 0x8a;
  4107. int offset = 0;
  4108. #elif PACKETVER < 20131223
  4109. const int cmd = 0x2e1;
  4110. int offset = 2;
  4111. #else
  4112. const int cmd = 0x8c8;
  4113. int offset = 3;
  4114. #endif
  4115. nullpo_ret(src);
  4116. nullpo_ret(dst);
  4117. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4118. sc = status_get_sc(dst);
  4119. if(sc && sc->count) {
  4120. if(sc->data[SC_HALLUCINATION]) {
  4121. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4122. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4123. }
  4124. }
  4125. WBUFW(buf,0) = cmd;
  4126. WBUFL(buf,2) = src->id;
  4127. WBUFL(buf,6) = dst->id;
  4128. WBUFL(buf,10) = tick;
  4129. WBUFL(buf,14) = sdelay;
  4130. WBUFL(buf,18) = ddelay;
  4131. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4132. WBUFW(buf,22) = damage ? div : 0;
  4133. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4134. } else {
  4135. #if PACKETVER < 20071113
  4136. WBUFW(buf,22) = min(damage, INT16_MAX);
  4137. WBUFW(buf,27+offset) = damage2;
  4138. #else
  4139. WBUFL(buf,22) = damage;
  4140. WBUFL(buf,27+offset) = damage2;
  4141. #endif
  4142. }
  4143. #if PACKETVER >= 20131223
  4144. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4145. #endif
  4146. WBUFW(buf,24+offset) = div;
  4147. WBUFB(buf,26+offset) = type;
  4148. if(disguised(dst)) {
  4149. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4150. WBUFL(buf,6) = -dst->id;
  4151. clif_send(buf, packet_len(cmd), dst, SELF);
  4152. } else
  4153. clif_send(buf, packet_len(cmd), dst, AREA);
  4154. if(disguised(src)) {
  4155. WBUFL(buf,2) = -src->id;
  4156. if (disguised(dst))
  4157. WBUFL(buf,6) = dst->id;
  4158. #if PACKETVER < 20071113
  4159. if(damage > 0) WBUFW(buf,22) = -1;
  4160. if(damage2 > 0) WBUFW(buf,27) = -1;
  4161. #else
  4162. if(damage > 0) WBUFL(buf,22) = -1;
  4163. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4164. #endif
  4165. clif_send(buf,packet_len(cmd),src,SELF);
  4166. }
  4167. if(src == dst) {
  4168. unit_setdir(src, unit_getdir(src));
  4169. }
  4170. //Return adjusted can't walk delay for further processing.
  4171. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4172. }
  4173. /*==========================================
  4174. * src picks up dst
  4175. *------------------------------------------*/
  4176. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4177. {
  4178. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4179. unsigned char buf[32];
  4180. nullpo_retv(src);
  4181. nullpo_retv(dst);
  4182. WBUFW(buf, 0) = 0x8a;
  4183. WBUFL(buf, 2) = src->id;
  4184. WBUFL(buf, 6) = dst->id;
  4185. WBUFB(buf,26) = 1;
  4186. clif_send(buf, packet_len(0x8a), src, AREA);
  4187. }
  4188. /*==========================================
  4189. * inform clients in area that `bl` is sitting
  4190. *------------------------------------------*/
  4191. void clif_sitting(struct block_list* bl)
  4192. {
  4193. unsigned char buf[32];
  4194. nullpo_retv(bl);
  4195. WBUFW(buf, 0) = 0x8a;
  4196. WBUFL(buf, 2) = bl->id;
  4197. WBUFB(buf,26) = 2;
  4198. clif_send(buf, packet_len(0x8a), bl, AREA);
  4199. if(disguised(bl)) {
  4200. WBUFL(buf, 2) = - bl->id;
  4201. clif_send(buf, packet_len(0x8a), bl, SELF);
  4202. }
  4203. }
  4204. /*==========================================
  4205. * inform clients in area that `bl` is standing
  4206. *------------------------------------------*/
  4207. void clif_standing(struct block_list* bl)
  4208. {
  4209. unsigned char buf[32];
  4210. nullpo_retv(bl);
  4211. WBUFW(buf, 0) = 0x8a;
  4212. WBUFL(buf, 2) = bl->id;
  4213. WBUFB(buf,26) = 3;
  4214. clif_send(buf, packet_len(0x8a), bl, AREA);
  4215. if(disguised(bl)) {
  4216. WBUFL(buf, 2) = - bl->id;
  4217. clif_send(buf, packet_len(0x8a), bl, SELF);
  4218. }
  4219. }
  4220. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4221. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4222. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4223. {
  4224. unsigned char buf[32];
  4225. WBUFW(buf,0) = 0x192;
  4226. WBUFW(buf,2) = x;
  4227. WBUFW(buf,4) = y;
  4228. WBUFW(buf,6) = type;
  4229. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4230. if( fd )
  4231. {
  4232. WFIFOHEAD(fd,packet_len(0x192));
  4233. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4234. WFIFOSET(fd,packet_len(0x192));
  4235. }
  4236. else
  4237. {
  4238. struct block_list dummy_bl;
  4239. dummy_bl.type = BL_NUL;
  4240. dummy_bl.x = x;
  4241. dummy_bl.y = y;
  4242. dummy_bl.m = m;
  4243. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4244. }
  4245. }
  4246. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4247. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4248. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4249. {
  4250. int view,fd;
  4251. fd=sd->fd;
  4252. WFIFOHEAD(fd,packet_len(0x9d));
  4253. WFIFOW(fd,0)=0x9d;
  4254. WFIFOL(fd,2)=fitem->bl.id;
  4255. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4256. WFIFOW(fd,6)=view;
  4257. else
  4258. WFIFOW(fd,6)=fitem->item.nameid;
  4259. WFIFOB(fd,8)=fitem->item.identify;
  4260. WFIFOW(fd,9)=fitem->bl.x;
  4261. WFIFOW(fd,11)=fitem->bl.y;
  4262. WFIFOW(fd,13)=fitem->item.amount;
  4263. WFIFOB(fd,15)=fitem->subx;
  4264. WFIFOB(fd,16)=fitem->suby;
  4265. WFIFOSET(fd,packet_len(0x9d));
  4266. }
  4267. /// Notifes client about Graffiti
  4268. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4269. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4270. unsigned char buf[128];
  4271. nullpo_retv(bl);
  4272. nullpo_retv(unit);
  4273. WBUFW(buf, 0) = 0x1c9;
  4274. WBUFL(buf, 2) = unit->bl.id;
  4275. WBUFL(buf, 6) = unit->group->src_id;
  4276. WBUFW(buf,10) = unit->bl.x;
  4277. WBUFW(buf,12) = unit->bl.y;
  4278. WBUFB(buf,14) = unit->group->unit_id;
  4279. WBUFB(buf,15) = 1;
  4280. WBUFB(buf,16) = 1;
  4281. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4282. clif_send(buf,packet_len(0x1c9),bl,target);
  4283. }
  4284. /// Notifies the client of a skill unit.
  4285. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4286. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4287. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4288. /// 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)
  4289. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4290. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4291. unsigned char buf[128];
  4292. nullpo_retv(bl);
  4293. nullpo_retv(unit);
  4294. if (bl->type == BL_PC)
  4295. fd = ((TBL_PC*)bl)->fd;
  4296. if (unit->group->state.guildaura)
  4297. return;
  4298. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4299. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4300. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4301. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4302. else
  4303. unit_id = unit->group->unit_id;
  4304. if (!visible)
  4305. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4306. #if PACKETVER >= 3
  4307. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4308. clif_graffiti(bl, unit, target);
  4309. return;
  4310. }
  4311. #endif
  4312. #if PACKETVER <= 20120702
  4313. header = 0x011f;
  4314. //#if PACKETVER < 20110718
  4315. // header = 0x011f;
  4316. //#elif PACKETVER < 20121212
  4317. // header = 0x08c7;
  4318. #elif PACKETVER < 20130731
  4319. header = 0x099f;
  4320. #else
  4321. header = 0x09ca;
  4322. #endif
  4323. len = packet_len(header);
  4324. WBUFW(buf,pos) = header;
  4325. if (header != 0x011f) {
  4326. WBUFW(buf, pos+2) = len;
  4327. pos += 2;
  4328. }
  4329. WBUFL(buf,pos+2) = unit->bl.id;
  4330. WBUFL(buf,pos+6) = unit->group->src_id;
  4331. WBUFW(buf,pos+10) = unit->bl.x;
  4332. WBUFW(buf,pos+12) = unit->bl.y;
  4333. switch (header) {
  4334. case 0x011f:
  4335. WBUFB(buf,pos+14) = unit_id;
  4336. WBUFB(buf,pos+15) = visible;
  4337. break;
  4338. case 0x08c7:
  4339. WBUFB(buf,pos+14) = unit_id;
  4340. WBUFW(buf,pos+15) = unit->range;
  4341. WBUFB(buf,pos+17) = visible;
  4342. break;
  4343. case 0x099f:
  4344. WBUFL(buf,pos+14) = unit_id;
  4345. WBUFW(buf,pos+18) = unit->range;
  4346. WBUFB(buf,pos+20) = visible;
  4347. break;
  4348. case 0x09ca:
  4349. WBUFL(buf,pos+14) = unit_id;
  4350. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4351. WBUFB(buf,pos+19) = visible;
  4352. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4353. break;
  4354. }
  4355. clif_send(buf, len, bl, target);
  4356. if (unit->group->skill_id == WZ_ICEWALL)
  4357. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4358. }
  4359. /*==========================================
  4360. * Server tells client to remove unit of id 'unit->bl.id'
  4361. *------------------------------------------*/
  4362. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4363. {
  4364. nullpo_retv(unit);
  4365. WFIFOHEAD(fd,packet_len(0x120));
  4366. WFIFOW(fd, 0)=0x120;
  4367. WFIFOL(fd, 2)=unit->bl.id;
  4368. WFIFOSET(fd,packet_len(0x120));
  4369. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4370. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4371. }
  4372. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4373. /// 0120 <id>.L
  4374. void clif_skill_delunit(struct skill_unit *unit)
  4375. {
  4376. unsigned char buf[16];
  4377. nullpo_retv(unit);
  4378. WBUFW(buf, 0)=0x120;
  4379. WBUFL(buf, 2)=unit->bl.id;
  4380. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4381. }
  4382. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4383. /// 01ac <id>.L
  4384. /// Only affects units with class [139,153] client-side.
  4385. void clif_skillunit_update(struct block_list* bl)
  4386. {
  4387. unsigned char buf[6];
  4388. nullpo_retv(bl);
  4389. WBUFW(buf,0) = 0x1ac;
  4390. WBUFL(buf,2) = bl->id;
  4391. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4392. }
  4393. /*==========================================
  4394. *
  4395. *------------------------------------------*/
  4396. static int clif_getareachar(struct block_list* bl,va_list ap)
  4397. {
  4398. struct map_session_data *sd;
  4399. nullpo_ret(bl);
  4400. sd=va_arg(ap,struct map_session_data*);
  4401. if (sd == NULL || !sd->fd)
  4402. return 0;
  4403. switch(bl->type){
  4404. case BL_ITEM:
  4405. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4406. break;
  4407. case BL_SKILL:
  4408. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4409. break;
  4410. default:
  4411. if(&sd->bl == bl)
  4412. break;
  4413. clif_getareachar_unit(sd,bl);
  4414. break;
  4415. }
  4416. return 0;
  4417. }
  4418. /*==========================================
  4419. * tbl has gone out of view-size of bl
  4420. *------------------------------------------*/
  4421. int clif_outsight(struct block_list *bl,va_list ap)
  4422. {
  4423. struct block_list *tbl;
  4424. struct view_data *vd;
  4425. TBL_PC *sd, *tsd;
  4426. tbl=va_arg(ap,struct block_list*);
  4427. if(bl == tbl) return 0;
  4428. sd = BL_CAST(BL_PC, bl);
  4429. tsd = BL_CAST(BL_PC, tbl);
  4430. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4431. nullpo_ret(bl);
  4432. switch(bl->type){
  4433. case BL_PC:
  4434. if(sd->vd.class_ != INVISIBLE_CLASS)
  4435. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4436. if(sd->chatID){
  4437. struct chat_data *cd;
  4438. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4439. if(cd->usersd[0]==sd)
  4440. clif_dispchat(cd,tsd->fd);
  4441. }
  4442. if(sd->state.vending)
  4443. clif_closevendingboard(bl,tsd->fd);
  4444. if(sd->state.buyingstore)
  4445. clif_buyingstore_disappear_entry_single(tsd, sd);
  4446. break;
  4447. case BL_ITEM:
  4448. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4449. break;
  4450. case BL_SKILL:
  4451. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4452. break;
  4453. case BL_NPC:
  4454. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4455. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4456. break;
  4457. default:
  4458. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4459. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4460. break;
  4461. }
  4462. }
  4463. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4464. nullpo_ret(tbl);
  4465. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4466. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4467. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4468. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4469. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4470. }
  4471. return 0;
  4472. }
  4473. /*==========================================
  4474. * tbl has come into view of bl
  4475. *------------------------------------------*/
  4476. int clif_insight(struct block_list *bl,va_list ap)
  4477. {
  4478. struct block_list *tbl;
  4479. TBL_PC *sd, *tsd;
  4480. tbl=va_arg(ap,struct block_list*);
  4481. if (bl == tbl) return 0;
  4482. sd = BL_CAST(BL_PC, bl);
  4483. tsd = BL_CAST(BL_PC, tbl);
  4484. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4485. switch(bl->type){
  4486. case BL_ITEM:
  4487. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4488. break;
  4489. case BL_SKILL:
  4490. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4491. break;
  4492. default:
  4493. clif_getareachar_unit(tsd,bl);
  4494. break;
  4495. }
  4496. }
  4497. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4498. clif_getareachar_unit(sd,tbl);
  4499. }
  4500. return 0;
  4501. }
  4502. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4503. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4504. void clif_skillinfoblock(struct map_session_data *sd)
  4505. {
  4506. int fd;
  4507. int i,len,id;
  4508. nullpo_retv(sd);
  4509. fd = sd->fd;
  4510. if (!fd)
  4511. return;
  4512. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4513. WFIFOW(fd,0) = 0x10f;
  4514. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4515. {
  4516. if( (id = sd->status.skill[i].id) != 0 )
  4517. {
  4518. // workaround for bugreport:5348
  4519. if (len + 37 > 8192)
  4520. break;
  4521. WFIFOW(fd,len) = id;
  4522. WFIFOL(fd,len+2) = skill_get_inf(id);
  4523. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4524. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4525. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4526. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4527. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4528. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4529. else
  4530. WFIFOB(fd,len+36) = 0;
  4531. len += 37;
  4532. }
  4533. }
  4534. WFIFOW(fd,2)=len;
  4535. WFIFOSET(fd,len);
  4536. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4537. for ( ; i < MAX_SKILL; i++)
  4538. {
  4539. if( (id = sd->status.skill[i].id) != 0 )
  4540. {
  4541. clif_addskill(sd, id);
  4542. clif_skillinfo(sd, id, 0);
  4543. }
  4544. }
  4545. }
  4546. /**
  4547. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4548. **/
  4549. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4550. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4551. void clif_addskill(struct map_session_data *sd, int skill_id)
  4552. {
  4553. int fd;
  4554. uint16 idx = 0;
  4555. nullpo_retv(sd);
  4556. fd = sd->fd;
  4557. if (!fd || !(idx = skill_get_index(skill_id)))
  4558. return;
  4559. if( sd->status.skill[idx].id <= 0 )
  4560. return;
  4561. WFIFOHEAD(fd, packet_len(0x111));
  4562. WFIFOW(fd,0) = 0x111;
  4563. WFIFOW(fd,2) = skill_id;
  4564. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4565. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4566. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4567. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4568. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4569. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4570. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4571. else
  4572. WFIFOB(fd,38) = 0;
  4573. WFIFOSET(fd,packet_len(0x111));
  4574. }
  4575. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4576. /// 0441 <skill id>.W
  4577. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4578. {
  4579. #if PACKETVER >= 20081217
  4580. int fd;
  4581. uint16 idx = 0;
  4582. nullpo_retv(sd);
  4583. fd = sd->fd;
  4584. if (!fd || !(idx = skill_get_index(skill_id)))
  4585. return;
  4586. WFIFOHEAD(fd,packet_len(0x441));
  4587. WFIFOW(fd,0) = 0x441;
  4588. WFIFOW(fd,2) = skill_id;
  4589. WFIFOSET(fd,packet_len(0x441));
  4590. #endif
  4591. clif_skillinfoblock(sd);
  4592. }
  4593. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4594. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4595. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4596. int fd;
  4597. nullpo_retv(sd);
  4598. fd = sd->fd;
  4599. WFIFOHEAD(fd, packet_len(0x10e));
  4600. WFIFOW(fd, 0) = 0x10e;
  4601. WFIFOW(fd, 2) = skill_id;
  4602. WFIFOW(fd, 4) = lv;
  4603. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4604. WFIFOW(fd, 8) = range;
  4605. WFIFOB(fd, 10) = upgradable;
  4606. WFIFOSET(fd, packet_len(0x10e));
  4607. }
  4608. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4609. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4610. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4611. {
  4612. const int fd = sd->fd;
  4613. uint16 idx = skill_get_index(skill_id);
  4614. if (!idx)
  4615. return;
  4616. WFIFOHEAD(fd,packet_len(0x7e1));
  4617. WFIFOW(fd,0) = 0x7e1;
  4618. WFIFOW(fd,2) = skill_id;
  4619. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4620. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4621. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4622. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4623. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4624. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4625. else
  4626. WFIFOB(fd,14) = 0;
  4627. WFIFOSET(fd,packet_len(0x7e1));
  4628. }
  4629. /// Notifies clients in area, that an object is about to use a skill.
  4630. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4631. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4632. /// property:
  4633. /// 0 = Yellow cast aura
  4634. /// 1 = Water elemental cast aura
  4635. /// 2 = Earth elemental cast aura
  4636. /// 3 = Fire elemental cast aura
  4637. /// 4 = Wind elemental cast aura
  4638. /// 5 = Poison elemental cast aura
  4639. /// 6 = Holy elemental cast aura
  4640. /// ? = like 0
  4641. /// is disposable:
  4642. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4643. /// 1 = no text
  4644. 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)
  4645. {
  4646. #if PACKETVER < 20091124
  4647. const int cmd = 0x13e;
  4648. #else
  4649. const int cmd = 0x7fb;
  4650. #endif
  4651. unsigned char buf[32];
  4652. WBUFW(buf,0) = cmd;
  4653. WBUFL(buf,2) = src_id;
  4654. WBUFL(buf,6) = dst_id;
  4655. WBUFW(buf,10) = dst_x;
  4656. WBUFW(buf,12) = dst_y;
  4657. WBUFW(buf,14) = skill_id;
  4658. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4659. WBUFL(buf,20) = casttime;
  4660. #if PACKETVER >= 20091124
  4661. WBUFB(buf,24) = 0; // isDisposable
  4662. #endif
  4663. if (disguised(bl)) {
  4664. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4665. WBUFL(buf,2) = -src_id;
  4666. clif_send(buf,packet_len(cmd), bl, SELF);
  4667. } else
  4668. clif_send(buf,packet_len(cmd), bl, AREA);
  4669. }
  4670. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4671. /// 01b9 <id>.L
  4672. void clif_skillcastcancel(struct block_list* bl)
  4673. {
  4674. unsigned char buf[16];
  4675. nullpo_retv(bl);
  4676. WBUFW(buf,0) = 0x1b9;
  4677. WBUFL(buf,2) = bl->id;
  4678. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4679. }
  4680. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4681. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4682. /// num (only used when skill id = NV_BASIC and cause = 0):
  4683. /// 0 = "skill failed" MsgStringTable[159]
  4684. /// 1 = "no emotions" MsgStringTable[160]
  4685. /// 2 = "no sit" MsgStringTable[161]
  4686. /// 3 = "no chat" MsgStringTable[162]
  4687. /// 4 = "no party" MsgStringTable[163]
  4688. /// 5 = "no shout" MsgStringTable[164]
  4689. /// 6 = "no PKing" MsgStringTable[165]
  4690. /// 7 = "no alligning" MsgStringTable[383]
  4691. /// ? = ignored
  4692. /// cause:
  4693. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4694. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4695. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4696. /// "skill failed" MsgStringTable[204] (otherwise)
  4697. /// ... = @see enum useskill_fail_cause
  4698. /// ? = ignored
  4699. ///
  4700. /// if(result!=0) doesn't display any of the previous messages
  4701. /// Note: when this packet is received an unknown flag is always set to 0,
  4702. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4703. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4704. {
  4705. int fd;
  4706. if (!sd) { //Since this is the most common nullpo....
  4707. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4708. return;
  4709. }
  4710. fd=sd->fd;
  4711. if (!fd) return;
  4712. if(battle_config.display_skill_fail&1)
  4713. return; //Disable all skill failed messages
  4714. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4715. return; //Disable delay failed messages
  4716. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4717. return;
  4718. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4719. return;
  4720. WFIFOHEAD(fd,packet_len(0x110));
  4721. WFIFOW(fd,0) = 0x110;
  4722. WFIFOW(fd,2) = skill_id;
  4723. WFIFOL(fd,4) = btype;
  4724. WFIFOB(fd,8) = 0;// success
  4725. WFIFOB(fd,9) = cause;
  4726. WFIFOSET(fd,packet_len(0x110));
  4727. }
  4728. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4729. /// 043d <skill ID>.W <tick>.L
  4730. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4731. {
  4732. #if PACKETVER>=20081112
  4733. int fd;
  4734. nullpo_retv(sd);
  4735. fd=sd->fd;
  4736. WFIFOHEAD(fd,packet_len(0x43d));
  4737. WFIFOW(fd,0) = 0x43d;
  4738. WFIFOW(fd,2) = skill_id;
  4739. WFIFOL(fd,4) = tick;
  4740. WFIFOSET(fd,packet_len(0x43d));
  4741. #endif
  4742. }
  4743. /// Skill attack effect and damage.
  4744. /// 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)
  4745. /// 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)
  4746. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4747. {
  4748. unsigned char buf[64];
  4749. struct status_change *sc;
  4750. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4751. nullpo_ret(src);
  4752. nullpo_ret(dst);
  4753. type = clif_calc_delay(type,div,damage,ddelay);
  4754. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4755. if(sc->data[SC_HALLUCINATION] && damage)
  4756. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4757. }
  4758. #if PACKETVER < 3
  4759. WBUFW(buf,0)=0x114;
  4760. WBUFW(buf,2)=skill_id;
  4761. WBUFL(buf,4)=src->id;
  4762. WBUFL(buf,8)=dst->id;
  4763. WBUFL(buf,12)=tick;
  4764. WBUFL(buf,16)=sdelay;
  4765. WBUFL(buf,20)=ddelay;
  4766. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4767. WBUFW(buf,24)=damage?div:0;
  4768. } else {
  4769. WBUFW(buf,24)=damage;
  4770. }
  4771. WBUFW(buf,26)=skill_lv;
  4772. WBUFW(buf,28)=div;
  4773. WBUFB(buf,30)=type;
  4774. if (disguised(dst)) {
  4775. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4776. WBUFL(buf,8)=-dst->id;
  4777. clif_send(buf,packet_len(0x114),dst,SELF);
  4778. } else
  4779. clif_send(buf,packet_len(0x114),dst,AREA);
  4780. if(disguised(src)) {
  4781. WBUFL(buf,4)=-src->id;
  4782. if (disguised(dst))
  4783. WBUFL(buf,8)=dst->id;
  4784. if(damage > 0)
  4785. WBUFW(buf,24)=-1;
  4786. clif_send(buf,packet_len(0x114),src,SELF);
  4787. }
  4788. #else
  4789. WBUFW(buf,0)=0x1de;
  4790. WBUFW(buf,2)=skill_id;
  4791. WBUFL(buf,4)=src->id;
  4792. WBUFL(buf,8)=dst->id;
  4793. WBUFL(buf,12)=tick;
  4794. WBUFL(buf,16)=sdelay;
  4795. WBUFL(buf,20)=ddelay;
  4796. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4797. WBUFL(buf,24)=damage?div:0;
  4798. } else {
  4799. WBUFL(buf,24)=damage;
  4800. }
  4801. WBUFW(buf,28)=skill_lv;
  4802. WBUFW(buf,30)=div;
  4803. // For some reason, late 2013 and newer clients have
  4804. // a issue that causes players and monsters to endure
  4805. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4806. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4807. #if PACKETVER < 20131223
  4808. WBUFB(buf,32)=type;
  4809. #else
  4810. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4811. #endif
  4812. if (disguised(dst)) {
  4813. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4814. WBUFL(buf,8)=-dst->id;
  4815. clif_send(buf,packet_len(0x1de),dst,SELF);
  4816. } else
  4817. clif_send(buf,packet_len(0x1de),dst,AREA);
  4818. if(disguised(src)) {
  4819. WBUFL(buf,4)=-src->id;
  4820. if (disguised(dst))
  4821. WBUFL(buf,8)=dst->id;
  4822. if(damage > 0)
  4823. WBUFL(buf,24)=-1;
  4824. clif_send(buf,packet_len(0x1de),src,SELF);
  4825. }
  4826. #endif
  4827. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4828. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4829. }
  4830. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4831. /// 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
  4832. /*
  4833. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4834. {
  4835. unsigned char buf[64];
  4836. struct status_change *sc;
  4837. nullpo_ret(src);
  4838. nullpo_ret(dst);
  4839. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4840. type = clif_calc_delay(type,div,damage,ddelay);
  4841. sc = status_get_sc(dst);
  4842. if(sc && sc->count) {
  4843. if(sc->data[SC_HALLUCINATION] && damage)
  4844. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4845. }
  4846. WBUFW(buf,0)=0x115;
  4847. WBUFW(buf,2)=skill_id;
  4848. WBUFL(buf,4)=src->id;
  4849. WBUFL(buf,8)=dst->id;
  4850. WBUFL(buf,12)=tick;
  4851. WBUFL(buf,16)=sdelay;
  4852. WBUFL(buf,20)=ddelay;
  4853. WBUFW(buf,24)=dst->x;
  4854. WBUFW(buf,26)=dst->y;
  4855. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4856. WBUFW(buf,28)=damage?div:0;
  4857. } else {
  4858. WBUFW(buf,28)=damage;
  4859. }
  4860. WBUFW(buf,30)=skill_lv;
  4861. WBUFW(buf,32)=div;
  4862. WBUFB(buf,34)=type;
  4863. clif_send(buf,packet_len(0x115),src,AREA);
  4864. if(disguised(src)) {
  4865. WBUFL(buf,4)=-src->id;
  4866. if(damage > 0)
  4867. WBUFW(buf,28)=-1;
  4868. clif_send(buf,packet_len(0x115),src,SELF);
  4869. }
  4870. if (disguised(dst)) {
  4871. WBUFL(buf,8)=-dst->id;
  4872. if (disguised(src))
  4873. WBUFL(buf,4)=src->id;
  4874. else if(damage > 0)
  4875. WBUFW(buf,28)=-1;
  4876. clif_send(buf,packet_len(0x115),dst,SELF);
  4877. }
  4878. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4879. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4880. }
  4881. */
  4882. /// Non-damaging skill effect
  4883. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4884. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4885. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4886. {
  4887. unsigned char buf[17];
  4888. #if PACKETVER < 20130731
  4889. const int cmd = 0x11a;
  4890. #else
  4891. const int cmd = 0x9cb;
  4892. #endif
  4893. int offset = 0;
  4894. nullpo_ret(dst);
  4895. WBUFW(buf,0) = cmd;
  4896. WBUFW(buf,2) = skill_id;
  4897. #if PACKETVER < 20130731
  4898. WBUFW(buf,4) = min(heal, INT16_MAX);
  4899. #else
  4900. WBUFL(buf,4) = min(heal, INT32_MAX);
  4901. offset += 2;
  4902. #endif
  4903. WBUFL(buf,6+offset) = dst->id;
  4904. WBUFL(buf,10+offset) = src ? src->id : 0;
  4905. WBUFB(buf,14+offset) = fail;
  4906. if (disguised(dst)) {
  4907. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4908. WBUFL(buf,6+offset) = -dst->id;
  4909. clif_send(buf, packet_len(cmd), dst, SELF);
  4910. } else
  4911. clif_send(buf, packet_len(cmd), dst, AREA);
  4912. if(src && disguised(src)) {
  4913. WBUFL(buf,10+offset) = -src->id;
  4914. if (disguised(dst))
  4915. WBUFL(buf,6+offset) = dst->id;
  4916. clif_send(buf, packet_len(cmd), src, SELF);
  4917. }
  4918. return fail;
  4919. }
  4920. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4921. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4922. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4923. {
  4924. unsigned char buf[32];
  4925. nullpo_retv(src);
  4926. WBUFW(buf,0)=0x117;
  4927. WBUFW(buf,2)=skill_id;
  4928. WBUFL(buf,4)=src->id;
  4929. WBUFW(buf,8)=val;
  4930. WBUFW(buf,10)=x;
  4931. WBUFW(buf,12)=y;
  4932. WBUFL(buf,14)=tick;
  4933. if(disguised(src)) {
  4934. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4935. WBUFL(buf,4)=-src->id;
  4936. clif_send(buf,packet_len(0x117),src,SELF);
  4937. } else
  4938. clif_send(buf,packet_len(0x117),src,AREA);
  4939. }
  4940. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4941. /// 011c <skill id>.W { <map name>.16B }*4
  4942. 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)
  4943. {
  4944. int fd;
  4945. nullpo_retv(sd);
  4946. fd = sd->fd;
  4947. WFIFOHEAD(fd,packet_len(0x11c));
  4948. WFIFOW(fd,0) = 0x11c;
  4949. WFIFOW(fd,2) = skill_id;
  4950. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4951. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  4952. else // normal map name
  4953. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  4954. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  4955. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  4956. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  4957. WFIFOSET(fd,packet_len(0x11c));
  4958. sd->menuskill_id = skill_id;
  4959. if (skill_id == AL_WARP) {
  4960. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4961. sd->state.workinprogress = WIP_DISABLE_ALL;
  4962. } else
  4963. sd->menuskill_val = skill_lv;
  4964. }
  4965. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4966. /// 011e <type>.B
  4967. /// type:
  4968. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4969. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4970. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4971. ///
  4972. /// @param sd Who receives the message
  4973. /// @param type What message
  4974. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4975. {
  4976. int fd;
  4977. nullpo_retv(sd);
  4978. fd=sd->fd;
  4979. WFIFOHEAD(fd,packet_len(0x11e));
  4980. WFIFOW(fd,0)=0x11e;
  4981. WFIFOB(fd,2)=type;
  4982. WFIFOSET(fd,packet_len(0x11e));
  4983. }
  4984. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4985. /// 0189 <type>.W
  4986. /// type:
  4987. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4988. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4989. ///
  4990. /// @param sd Who receives the message
  4991. /// @param type What message
  4992. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4993. {
  4994. int fd;
  4995. nullpo_retv(sd);
  4996. fd=sd->fd;
  4997. WFIFOHEAD(fd,packet_len(0x189));
  4998. WFIFOW(fd,0)=0x189;
  4999. WFIFOW(fd,2)=type;
  5000. WFIFOSET(fd,packet_len(0x189));
  5001. }
  5002. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5003. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5004. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5005. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5006. {
  5007. struct status_data *status;
  5008. unsigned char buf[64];
  5009. int i;//, fix;
  5010. nullpo_retv(sd);
  5011. nullpo_retv(dst);
  5012. if( dst->type != BL_MOB )
  5013. return;
  5014. status = status_get_status_data(dst);
  5015. WBUFW(buf, 0)=0x18c;
  5016. WBUFW(buf, 2)=status_get_class(dst);
  5017. WBUFW(buf, 4)=status_get_lv(dst);
  5018. WBUFW(buf, 6)=status->size;
  5019. WBUFL(buf, 8)=status->hp;
  5020. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5021. +(battle_config.estimation_type&2?status->def2:0);
  5022. WBUFW(buf,14)=status->race;
  5023. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5024. +(battle_config.estimation_type&2?status->mdef2:0);
  5025. WBUFW(buf,18)= status->def_ele;
  5026. for(i=0;i<9;i++)
  5027. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5028. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5029. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5030. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5031. }
  5032. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5033. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5034. /// material id:
  5035. /// unused by the client
  5036. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5037. {
  5038. int i,c,view,fd;
  5039. nullpo_retv(sd);
  5040. if (sd->menuskill_id == skill_id)
  5041. return; //Avoid resending the menu twice or more times...
  5042. if (skill_id == GC_CREATENEWPOISON)
  5043. skill_id = GC_RESEARCHNEWPOISON;
  5044. fd = sd->fd;
  5045. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5046. WFIFOW(fd, 0) = 0x18d;
  5047. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5048. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5049. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5050. )
  5051. {
  5052. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5053. WFIFOW(fd,c*8+ 4) = view;
  5054. else
  5055. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5056. WFIFOW(fd,c*8+ 6) = 0;
  5057. WFIFOW(fd,c*8+ 8) = 0;
  5058. WFIFOW(fd,c*8+10) = 0;
  5059. c++;
  5060. }
  5061. }
  5062. WFIFOW(fd, 2) = c*8+8;
  5063. WFIFOSET(fd,WFIFOW(fd,2));
  5064. if (c > 0) {
  5065. sd->menuskill_id = skill_id;
  5066. sd->menuskill_val = trigger;
  5067. return;
  5068. }
  5069. }
  5070. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5071. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5072. /// mk type:
  5073. /// 1 = cooking
  5074. /// 2 = arrow
  5075. /// 3 = elemental
  5076. /// 4 = GN_MIX_COOKING
  5077. /// 5 = GN_MAKEBOMB
  5078. /// 6 = GN_S_PHARMACY
  5079. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5080. {
  5081. int fd;
  5082. int i, c;
  5083. int view;
  5084. nullpo_retv(sd);
  5085. fd = sd->fd;
  5086. if(sd->menuskill_id == skill_id)
  5087. return; //Avoid resending the menu twice or more times...
  5088. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5089. WFIFOW(fd,0) = 0x25a;
  5090. WFIFOW(fd,4) = list_type; // list type
  5091. c = 0;
  5092. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5093. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5094. continue;
  5095. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5096. WFIFOW(fd, 6 + 2 * c) = view;
  5097. else
  5098. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5099. c++;
  5100. }
  5101. if( c > 0 || skill_id == AM_PHARMACY) {
  5102. sd->menuskill_id = skill_id;
  5103. sd->menuskill_val = trigger;
  5104. sd->menuskill_val2 = qty; // amount.
  5105. WFIFOW(fd,2) = 6 + 2 * c;
  5106. WFIFOSET(fd,WFIFOW(fd,2));
  5107. } else {
  5108. clif_menuskill_clear(sd);
  5109. #if PACKETVER >= 20090922
  5110. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5111. #else
  5112. WFIFOW(fd,2) = 6 + 2 * c;
  5113. WFIFOSET(fd,WFIFOW(fd,2));
  5114. #endif
  5115. }
  5116. }
  5117. /// Notifies clients of a status change.
  5118. /// 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)]
  5119. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5120. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5121. /// @param bl Sends packet to clients around this object
  5122. /// @param id ID of object that has this effect
  5123. /// @param type Status icon see enum si_type
  5124. /// @param flag 1:Active, 0:Deactive
  5125. /// @param tick Duration in ms
  5126. /// @param val1
  5127. /// @param val2
  5128. /// @param val3
  5129. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, int tick, int val1, int val2, int val3, enum send_target target_type)
  5130. {
  5131. unsigned char buf[32];
  5132. if (type == SI_BLANK) //It shows nothing on the client...
  5133. return;
  5134. if (type == SI_ACTIONDELAY && tick == 0)
  5135. return;
  5136. nullpo_retv(bl);
  5137. #if PACKETVER >= 20120618
  5138. if (flag && battle_config.display_status_timers)
  5139. WBUFW(buf,0) = 0x983;
  5140. else
  5141. #elif PACKETVER >= 20090121
  5142. if (flag && battle_config.display_status_timers)
  5143. WBUFW(buf,0) = 0x43f;
  5144. else
  5145. #endif
  5146. WBUFW(buf,0) = 0x196;
  5147. WBUFW(buf,2) = type;
  5148. WBUFL(buf,4) = id;
  5149. WBUFB(buf,8) = flag;
  5150. #if PACKETVER >= 20120618
  5151. if (flag && battle_config.display_status_timers) {
  5152. if (tick <= 0)
  5153. tick = 9999; // this is indeed what official servers do
  5154. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5155. WBUFL(buf,13) = tick;
  5156. WBUFL(buf,17) = val1;
  5157. WBUFL(buf,21) = val2;
  5158. WBUFL(buf,25) = val3;
  5159. }
  5160. #elif PACKETVER >= 20090121
  5161. if (flag && battle_config.display_status_timers) {
  5162. if (tick <= 0)
  5163. tick = 9999; // this is indeed what official servers do
  5164. WBUFL(buf,9) = tick;
  5165. WBUFL(buf,13) = val1;
  5166. WBUFL(buf,17) = val2;
  5167. WBUFL(buf,21) = val3;
  5168. }
  5169. #endif
  5170. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5171. }
  5172. /* Sends status effect to clients around the bl
  5173. * @param bl Object that has the effect
  5174. * @param type Status icon see enum si_type
  5175. * @param flag 1:Active, 0:Deactive
  5176. * @param tick Duration in ms
  5177. * @param val1
  5178. * @param val2
  5179. * @param val3
  5180. */
  5181. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5182. struct map_session_data *sd = NULL;
  5183. if (type == SI_BLANK) //It shows nothing on the client...
  5184. return;
  5185. if (type == SI_ACTIONDELAY && tick == 0)
  5186. return;
  5187. nullpo_retv(bl);
  5188. sd = BL_CAST(BL_PC, bl);
  5189. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5190. return;
  5191. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (sd->status.option&OPTION_INVISIBLE ? SELF : AREA) : AREA_WOS)));
  5192. }
  5193. /**
  5194. * Send any active EFST to those around.
  5195. * @param sd: Player to send the packet to
  5196. * @param bl: Objects walking into view
  5197. * @param target: Client send type
  5198. */
  5199. void clif_efst_status_change_sub(struct map_session_data *sd, struct block_list *bl, enum send_target target) {
  5200. struct map_session_data *tsd = NULL;
  5201. unsigned char i;
  5202. nullpo_retv(sd);
  5203. nullpo_retv(bl);
  5204. if (target == SELF)
  5205. tsd = (TBL_PC *)bl;
  5206. else
  5207. tsd = sd;
  5208. for (i = 0; i < tsd->sc_display_count; i++) {
  5209. enum sc_type type = tsd->sc_display[i]->type;
  5210. struct status_change *sc = status_get_sc(bl);
  5211. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5212. int tick = 0;
  5213. if (td)
  5214. tick = DIFF_TICK(td->tick, gettick());
  5215. #if PACKETVER > 20120418
  5216. clif_efst_status_change((target == SELF) ? &sd->bl : bl, bl->id, target, StatusIconChangeTable[type], tick, tsd->sc_display[i]->val1, tsd->sc_display[i]->val2, tsd->sc_display[i]->val3);
  5217. #else
  5218. clif_status_change_sub(&sd->bl, bl->id, StatusIconChangeTable[type], 1, tick, tsd->sc_display[i]->val1, tsd->sc_display[i]->val2, tsd->sc_display[i]->val3, target);
  5219. #endif
  5220. }
  5221. }
  5222. /// Notifies the client when a player enters the screen with an active EFST.
  5223. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5224. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5225. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, int tick, int val1, int val2, int val3) {
  5226. #if PACKETVER >= 20111108
  5227. unsigned char buf[32];
  5228. #if PACKETVER >= 20120618
  5229. const int cmd = 0x984;
  5230. #elif PACKETVER >= 20111108
  5231. const int cmd = 0x8ff;
  5232. #endif
  5233. int offset = 0;
  5234. if (type == SI_BLANK)
  5235. return;
  5236. nullpo_retv(bl);
  5237. if (tick <= 0)
  5238. tick = 9999;
  5239. WBUFW(buf,offset + 0) = cmd;
  5240. WBUFL(buf,offset + 2) = tid;
  5241. WBUFW(buf,offset + 6) = type;
  5242. #if PACKETVER >= 20111108
  5243. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5244. #if PACKETVER >= 20120618
  5245. WBUFL(buf,offset + 12) = tick;
  5246. offset += 4;
  5247. #endif
  5248. WBUFL(buf,offset + 12) = val1;
  5249. WBUFL(buf,offset + 16) = val2;
  5250. WBUFL(buf,offset + 20) = val3;
  5251. #endif
  5252. clif_send(buf,packet_len(cmd),bl,target);
  5253. #endif
  5254. }
  5255. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5256. /// 008e <packet len>.W <message>.?B
  5257. void clif_displaymessage(const int fd, const char* mes)
  5258. {
  5259. nullpo_retv(mes);
  5260. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5261. if (fd == 0)
  5262. ;
  5263. else {
  5264. char *message, *line;
  5265. message = aStrdup(mes);
  5266. line = strtok(message, "\n");
  5267. #if PACKETVER == 20141022
  5268. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5269. /** so we redirect to ZC_NPC_CHAT **/
  5270. //clif_colormes(fd, color_table[COLOR_DEFAULT], mes);
  5271. while(line != NULL) {
  5272. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5273. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5274. if (len > 0) {
  5275. WFIFOHEAD(fd, 13 + len);
  5276. WFIFOW(fd, 0) = 0x2C1;
  5277. WFIFOW(fd, 2) = 13 + len;
  5278. WFIFOL(fd, 4) = 0;
  5279. WFIFOL(fd, 8) = color;
  5280. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5281. WFIFOSET(fd, WFIFOW(fd, 2));
  5282. }
  5283. #else
  5284. while(line != NULL) {
  5285. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5286. int len = strnlen(line, CHAT_SIZE_MAX);
  5287. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5288. WFIFOHEAD(fd, 5 + len);
  5289. WFIFOW(fd,0) = 0x8e;
  5290. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5291. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5292. WFIFOSET(fd, 5 + len);
  5293. }
  5294. #endif
  5295. line = strtok(NULL, "\n");
  5296. }
  5297. aFree(message);
  5298. }
  5299. }
  5300. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5301. /// 009a <packet len>.W <message>.?B
  5302. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5303. {
  5304. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5305. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5306. WBUFW(buf,0) = 0x9a;
  5307. WBUFW(buf,2) = 4 + lp + len;
  5308. if (type&BC_BLUE)
  5309. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5310. else if (type&BC_WOE)
  5311. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5312. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5313. clif_send(buf, WBUFW(buf,2), bl, target);
  5314. if (buf)
  5315. aFree(buf);
  5316. }
  5317. /*==========================================
  5318. * Displays a message on a 'bl' to all it's nearby clients
  5319. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  5320. *------------------------------------------*/
  5321. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5322. char buf[100];
  5323. int len;
  5324. nullpo_retv(bl);
  5325. if(!message)
  5326. return;
  5327. len = strlen(message)+1;
  5328. if( len > sizeof(buf)-8 ) {
  5329. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5330. len = sizeof(buf)-8;
  5331. }
  5332. WBUFW(buf,0)=0x8d;
  5333. WBUFW(buf,2)=len+8;
  5334. WBUFL(buf,4)=bl->id;
  5335. safestrncpy(WBUFCP(buf,8),message,len);
  5336. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5337. }
  5338. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5339. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5340. 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)
  5341. {
  5342. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5343. WBUFW(buf,0) = 0x1c3;
  5344. WBUFW(buf,2) = len + 16;
  5345. WBUFL(buf,4) = fontColor;
  5346. WBUFW(buf,8) = fontType;
  5347. WBUFW(buf,10) = fontSize;
  5348. WBUFW(buf,12) = fontAlign;
  5349. WBUFW(buf,14) = fontY;
  5350. memcpy(WBUFP(buf,16), mes, len);
  5351. clif_send(buf, WBUFW(buf,2), bl, target);
  5352. if (buf)
  5353. aFree(buf);
  5354. }
  5355. /*
  5356. * Display *msg from *sd to all *users in channel
  5357. */
  5358. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  5359. DBIterator *iter;
  5360. struct map_session_data *user;
  5361. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  5362. WFIFOHEAD(sd->fd,msg_len + 12);
  5363. WFIFOW(sd->fd,0) = 0x2C1;
  5364. WFIFOW(sd->fd,2) = msg_len + 12;
  5365. WFIFOL(sd->fd,4) = 0;
  5366. WFIFOL(sd->fd,8) = channel_config.colors[color];
  5367. safestrncpy(WFIFOCP(sd->fd,12), msg, msg_len);
  5368. iter = db_iterator(channel->users);
  5369. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5370. if( user->fd == sd->fd )
  5371. continue;
  5372. WFIFOHEAD(user->fd,msg_len + 12);
  5373. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  5374. WFIFOSET(user->fd, msg_len + 12);
  5375. }
  5376. dbi_destroy(iter);
  5377. WFIFOSET(sd->fd, msg_len + 12);
  5378. }
  5379. /// Displays heal effect.
  5380. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5381. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5382. /// var id:
  5383. /// 5 = HP (SP_HP)
  5384. /// 7 = SP (SP_SP)
  5385. /// ? = ignored
  5386. void clif_heal(int fd,int type,int val) {
  5387. #if PACKETVER < 20141022
  5388. const int cmd = 0x13d;
  5389. #else
  5390. const int cmd = 0xa27;
  5391. #endif
  5392. WFIFOHEAD(fd, packet_len(cmd));
  5393. WFIFOW(fd,0) = cmd;
  5394. WFIFOW(fd,2) = type;
  5395. #if PACKETVER < 20141022
  5396. WFIFOW(fd,4) = min(val, INT16_MAX);
  5397. #else
  5398. WFIFOL(fd,4) = min(val, INT32_MAX);
  5399. #endif
  5400. WFIFOSET(fd, packet_len(cmd));
  5401. }
  5402. /// Displays resurrection effect (ZC_RESURRECTION).
  5403. /// 0148 <id>.L <type>.W
  5404. /// type:
  5405. /// ignored
  5406. void clif_resurrection(struct block_list *bl,int type)
  5407. {
  5408. unsigned char buf[16];
  5409. nullpo_retv(bl);
  5410. WBUFW(buf,0)=0x148;
  5411. WBUFL(buf,2)=bl->id;
  5412. WBUFW(buf,6)=0;
  5413. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5414. if (disguised(bl))
  5415. clif_spawn(bl);
  5416. }
  5417. /// Sets the map property
  5418. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5419. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5420. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5421. {
  5422. #if PACKETVER >= 20121010
  5423. short cmd = 0x99b;
  5424. unsigned char buf[8];
  5425. #else
  5426. short cmd = 0x199;
  5427. unsigned char buf[4];
  5428. #endif
  5429. WBUFW(buf,0)=cmd;
  5430. WBUFW(buf,2)=property;
  5431. #if PACKETVER >= 20121010
  5432. WBUFL(buf,4) = ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5433. ((map[bl->m].flag.battleground || map_flag_gvg(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5434. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5435. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5436. ((map[bl->m].flag.nolockon?1:0)<<4)| // DISABLE_LOCKON - Unknown (By the name it might disable cursor lock-on)
  5437. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5438. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5439. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5440. ((map[bl->m].flag.nocostume?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5441. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5442. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5443. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5444. #endif
  5445. clif_send(buf,packet_len(cmd),bl,t);
  5446. }
  5447. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5448. /// 01d6 <type>.W
  5449. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5450. {
  5451. int fd;
  5452. nullpo_retv(sd);
  5453. fd=sd->fd;
  5454. WFIFOHEAD(fd,packet_len(0x1D6));
  5455. WFIFOW(fd,0)=0x1D6;
  5456. WFIFOW(fd,2)=type;
  5457. WFIFOSET(fd,packet_len(0x1D6));
  5458. }
  5459. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5460. /// 019a <id>.L <ranking>.L <total>.L
  5461. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5462. {
  5463. if(type == 2) {
  5464. int fd = sd->fd;
  5465. WFIFOHEAD(fd,packet_len(0x19a));
  5466. WFIFOW(fd,0) = 0x19a;
  5467. WFIFOL(fd,2) = sd->bl.id;
  5468. WFIFOL(fd,6) = pvprank;
  5469. WFIFOL(fd,10) = pvpnum;
  5470. WFIFOSET(fd,packet_len(0x19a));
  5471. } else {
  5472. unsigned char buf[32];
  5473. WBUFW(buf,0) = 0x19a;
  5474. WBUFL(buf,2) = sd->bl.id;
  5475. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5476. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5477. else
  5478. WBUFL(buf,6) = pvprank;
  5479. WBUFL(buf,10) = pvpnum;
  5480. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5481. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5482. else if(!type)
  5483. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5484. else
  5485. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5486. }
  5487. }
  5488. /*==========================================
  5489. *
  5490. *------------------------------------------*/
  5491. void clif_map_property_mapall(int map_idx, enum map_property property)
  5492. {
  5493. struct block_list bl;
  5494. bl.id = 0;
  5495. bl.type = BL_NUL;
  5496. bl.m = map_idx;
  5497. clif_map_property( &bl, property, ALL_SAMEMAP );
  5498. }
  5499. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5500. /// 0188 <result>.W <index>.W <refine>.W
  5501. /// result:
  5502. /// 0 = success
  5503. /// 1 = failure
  5504. /// 2 = downgrade
  5505. void clif_refine(int fd, int fail, int index, int val)
  5506. {
  5507. WFIFOHEAD(fd,packet_len(0x188));
  5508. WFIFOW(fd,0)=0x188;
  5509. WFIFOW(fd,2)=fail;
  5510. WFIFOW(fd,4)=index+2;
  5511. WFIFOW(fd,6)=val;
  5512. WFIFOSET(fd,packet_len(0x188));
  5513. }
  5514. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5515. /// 0223 <result>.L <nameid>.W
  5516. /// result:
  5517. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5518. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5519. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5520. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5521. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5522. {
  5523. WFIFOHEAD(fd,packet_len(0x223));
  5524. WFIFOW(fd,0)=0x223;
  5525. WFIFOL(fd,2)=result;
  5526. WFIFOW(fd,6)=item_id;
  5527. WFIFOSET(fd,packet_len(0x223));
  5528. }
  5529. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5530. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5531. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5532. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5533. {
  5534. #if PACKETVER < 20091104
  5535. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5536. WFIFOW(fd,0) = 0x97;
  5537. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5538. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5539. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5540. WFIFOSET(fd,WFIFOW(fd,2));
  5541. #else
  5542. struct map_session_data *ssd = map_nick2sd(nick);
  5543. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5544. WFIFOW(fd,0) = 0x97;
  5545. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5546. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5547. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5548. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5549. WFIFOSET(fd,WFIFOW(fd,2));
  5550. #endif
  5551. }
  5552. /// Inform the player about the result of his whisper action
  5553. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5554. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5555. /// result:
  5556. /// 0 = success to send wisper
  5557. /// 1 = target character is not loged in
  5558. /// 2 = ignored by target
  5559. /// 3 = everyone ignored by target
  5560. void clif_wis_end(int fd, int result)
  5561. {
  5562. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5563. #if PACKETVER < 20131223
  5564. const int cmd = 0x98;
  5565. #else
  5566. const int cmd = 0x9df;
  5567. #endif
  5568. if (!sd)
  5569. return;
  5570. WFIFOHEAD(fd,packet_len(cmd));
  5571. WFIFOW(fd,0) = cmd;
  5572. WFIFOB(fd,2) = (char)result;
  5573. #if PACKETVER >= 20131223
  5574. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5575. #endif
  5576. WFIFOSET(fd,packet_len(cmd));
  5577. }
  5578. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5579. /// 0194 <char id>.L <name>.24B
  5580. void clif_solved_charname(int fd, int charid, const char* name)
  5581. {
  5582. WFIFOHEAD(fd,packet_len(0x194));
  5583. WFIFOW(fd,0)=0x194;
  5584. WFIFOL(fd,2)=charid;
  5585. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5586. WFIFOSET(fd,packet_len(0x194));
  5587. }
  5588. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5589. /// 017b <packet len>.W { <name id>.W }*
  5590. void clif_use_card(struct map_session_data *sd,int idx)
  5591. {
  5592. int i,c,ep;
  5593. int fd=sd->fd;
  5594. nullpo_retv(sd);
  5595. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5596. return;
  5597. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5598. return; //Avoid parsing invalid item indexes (no card/no item)
  5599. ep=sd->inventory_data[idx]->equip;
  5600. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5601. WFIFOW(fd,0)=0x17b;
  5602. for(i=c=0;i<MAX_INVENTORY;i++){
  5603. int j;
  5604. if(sd->inventory_data[i] == NULL)
  5605. continue;
  5606. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5607. continue;
  5608. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5609. continue;
  5610. if(sd->status.inventory[i].identify==0 ) //Not identified
  5611. continue;
  5612. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5613. continue;
  5614. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5615. continue;
  5616. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5617. if( j == sd->inventory_data[i]->slot ) // No room
  5618. continue;
  5619. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5620. continue;
  5621. WFIFOW(fd,4+c*2)=i+2;
  5622. c++;
  5623. }
  5624. if( !c ) return; // no item is available for card insertion
  5625. WFIFOW(fd,2)=4+c*2;
  5626. WFIFOSET(fd,WFIFOW(fd,2));
  5627. }
  5628. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5629. /// 017d <equip index>.W <card index>.W <result>.B
  5630. /// result:
  5631. /// 0 = success
  5632. /// 1 = failure
  5633. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5634. {
  5635. int fd;
  5636. nullpo_retv(sd);
  5637. fd=sd->fd;
  5638. WFIFOHEAD(fd,packet_len(0x17d));
  5639. WFIFOW(fd,0)=0x17d;
  5640. WFIFOW(fd,2)=idx_equip+2;
  5641. WFIFOW(fd,4)=idx_card+2;
  5642. WFIFOB(fd,6)=flag;
  5643. WFIFOSET(fd,packet_len(0x17d));
  5644. }
  5645. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5646. /// 0177 <packet len>.W { <name id>.W }*
  5647. void clif_item_identify_list(struct map_session_data *sd)
  5648. {
  5649. int i,c;
  5650. int fd;
  5651. nullpo_retv(sd);
  5652. fd=sd->fd;
  5653. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5654. WFIFOW(fd,0)=0x177;
  5655. for(i=c=0;i<MAX_INVENTORY;i++){
  5656. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5657. WFIFOW(fd,c*2+4)=i+2;
  5658. c++;
  5659. }
  5660. }
  5661. if(c > 0) {
  5662. WFIFOW(fd,2)=c*2+4;
  5663. WFIFOSET(fd,WFIFOW(fd,2));
  5664. sd->menuskill_id = MC_IDENTIFY;
  5665. sd->menuskill_val = c;
  5666. sd->state.workinprogress = WIP_DISABLE_ALL;
  5667. }
  5668. }
  5669. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5670. /// 0179 <index>.W <result>.B
  5671. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5672. {
  5673. int fd;
  5674. nullpo_retv(sd);
  5675. fd=sd->fd;
  5676. WFIFOHEAD(fd,packet_len(0x179));
  5677. WFIFOW(fd, 0)=0x179;
  5678. WFIFOW(fd, 2)=idx+2;
  5679. WFIFOB(fd, 4)=flag;
  5680. WFIFOSET(fd,packet_len(0x179));
  5681. }
  5682. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5683. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5684. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5685. {
  5686. int i,c;
  5687. int fd;
  5688. nullpo_retv(sd);
  5689. nullpo_retv(dstsd);
  5690. fd=sd->fd;
  5691. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5692. WFIFOW(fd,0)=0x1fc;
  5693. for(i=c=0;i<MAX_INVENTORY;i++){
  5694. unsigned short nameid;
  5695. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5696. WFIFOW(fd,c*13+4) = i;
  5697. WFIFOW(fd,c*13+6) = nameid;
  5698. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5699. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5700. c++;
  5701. }
  5702. }
  5703. if(c > 0) {
  5704. WFIFOW(fd,2)=c*13+4;
  5705. WFIFOSET(fd,WFIFOW(fd,2));
  5706. sd->menuskill_id = BS_REPAIRWEAPON;
  5707. sd->menuskill_val = dstsd->bl.id;
  5708. sd->menuskill_val2 = lv;
  5709. }else
  5710. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5711. }
  5712. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5713. /// 01fe <index>.W <result>.B
  5714. /// index:
  5715. /// ignored (inventory index)
  5716. /// result:
  5717. /// 0 = Item repair success.
  5718. /// 1 = Item repair failure.
  5719. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5720. {
  5721. int fd;
  5722. nullpo_retv(sd);
  5723. fd = sd->fd;
  5724. WFIFOHEAD(fd,packet_len(0x1fe));
  5725. WFIFOW(fd, 0)=0x1fe;
  5726. WFIFOW(fd, 2)=idx+2;
  5727. WFIFOB(fd, 4)=flag;
  5728. WFIFOSET(fd,packet_len(0x1fe));
  5729. }
  5730. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5731. /// 02bb <equip location>.W <account id>.L
  5732. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5733. {
  5734. int fd = sd->fd;
  5735. WFIFOHEAD(fd,packet_len(0x2bb));
  5736. WFIFOW(fd,0) = 0x2bb;
  5737. WFIFOW(fd,2) = position;
  5738. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5739. WFIFOSET(fd,packet_len(0x2bb));
  5740. }
  5741. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5742. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5743. void clif_item_refine_list(struct map_session_data *sd)
  5744. {
  5745. int i,c;
  5746. int fd;
  5747. uint16 skill_lv;
  5748. int refine_item[5];
  5749. nullpo_retv(sd);
  5750. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5751. fd=sd->fd;
  5752. refine_item[0] = -1;
  5753. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5754. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5755. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5756. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5757. WFIFOW(fd,0)=0x221;
  5758. for(i=c=0;i<MAX_INVENTORY;i++){
  5759. unsigned char wlv;
  5760. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5761. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5762. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5763. WFIFOW(fd,c*13+ 4)=i+2;
  5764. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5765. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5766. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5767. c++;
  5768. }
  5769. }
  5770. WFIFOW(fd,2)=c*13+4;
  5771. WFIFOSET(fd,WFIFOW(fd,2));
  5772. if (c > 0) {
  5773. sd->menuskill_id = WS_WEAPONREFINE;
  5774. sd->menuskill_val = skill_lv;
  5775. }
  5776. }
  5777. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5778. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5779. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5780. {
  5781. int fd;
  5782. nullpo_retv(sd);
  5783. fd=sd->fd;
  5784. WFIFOHEAD(fd,packet_len(0x147));
  5785. WFIFOW(fd, 0)=0x147;
  5786. WFIFOW(fd, 2)=skill_id;
  5787. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5788. WFIFOW(fd, 6)=0;
  5789. WFIFOW(fd, 8)=skill_lv;
  5790. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5791. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5792. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5793. WFIFOB(fd,38)=0;
  5794. WFIFOSET(fd,packet_len(0x147));
  5795. }
  5796. /// Adds an item to character's cart.
  5797. /// 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)
  5798. /// 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)
  5799. /// 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)
  5800. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5801. {
  5802. #if PACKETVER < 5
  5803. const int cmd = 0x124;
  5804. #elif PACKETVER < 20150226
  5805. const int cmd = 0x1c5;
  5806. #else
  5807. const int cmd = 0xa0b;
  5808. #endif
  5809. int view,fd;
  5810. unsigned char *buf;
  5811. int offset = 0;
  5812. nullpo_retv(sd);
  5813. fd=sd->fd;
  5814. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5815. return;
  5816. WFIFOHEAD(fd,packet_len(cmd));
  5817. buf=WFIFOP(fd,0);
  5818. WBUFW(buf,0)=cmd;
  5819. WBUFW(buf,2)=n+2;
  5820. WBUFL(buf,4)=amount;
  5821. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5822. WBUFW(buf,8)=view;
  5823. else
  5824. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5825. #if PACKETVER >= 5
  5826. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5827. offset += 1;
  5828. #endif
  5829. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5830. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5831. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5832. clif_addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5833. #if PACKETVER >= 20150226
  5834. clif_add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5835. #endif
  5836. WFIFOSET(fd,packet_len(cmd));
  5837. }
  5838. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5839. /* Acknowledge an item have been added to cart
  5840. * 012c <result>B
  5841. * result :
  5842. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5843. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5844. */
  5845. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5846. {
  5847. int fd;
  5848. unsigned char *buf;
  5849. nullpo_retv(sd);
  5850. fd = sd->fd;
  5851. buf = WFIFOP(fd,0);
  5852. WBUFW(buf,0) = 0x12c;
  5853. WBUFB(buf,2) = flag;
  5854. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5855. }
  5856. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5857. void clif_bank_open(struct map_session_data *sd){
  5858. int fd;
  5859. nullpo_retv(sd);
  5860. fd = sd->fd;
  5861. WFIFOHEAD(fd,4);
  5862. WFIFOW(fd,0) = 0x09b7;
  5863. WFIFOW(fd,2) = 0;
  5864. WFIFOSET(fd,4);
  5865. }
  5866. /*
  5867. * Request to Open the banking system
  5868. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5869. */
  5870. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5871. //TODO check if preventing trade or stuff like that
  5872. //also mark something in case char ain't available for saving, should we check now ?
  5873. nullpo_retv(sd);
  5874. if( !battle_config.feature_banking ) {
  5875. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5876. return;
  5877. }
  5878. else {
  5879. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5880. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5881. if(sd->status.account_id == aid){
  5882. sd->state.banking = 1;
  5883. //request save ?
  5884. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5885. //on succes open bank ?
  5886. clif_bank_open(sd);
  5887. }
  5888. }
  5889. }
  5890. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5891. void clif_bank_close(struct map_session_data *sd){
  5892. int fd;
  5893. nullpo_retv(sd);
  5894. fd = sd->fd;
  5895. WFIFOHEAD(fd,4);
  5896. WFIFOW(fd,0) = 0x09B9;
  5897. WFIFOW(fd,2) = 0;
  5898. WFIFOSET(fd,4);
  5899. }
  5900. /*
  5901. * Request to close the banking system
  5902. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5903. */
  5904. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5905. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5906. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5907. nullpo_retv(sd);
  5908. if( !battle_config.feature_banking ) {
  5909. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5910. //still allow to go trough to not stuck player if we have disable it while they was in
  5911. }
  5912. if(sd->status.account_id == aid){
  5913. sd->state.banking = 0;
  5914. clif_bank_close(sd);
  5915. }
  5916. }
  5917. /*
  5918. * Display how much we got in bank (I suppose)
  5919. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5920. */
  5921. void clif_Bank_Check(struct map_session_data* sd) {
  5922. unsigned char buf[13];
  5923. struct s_packet_db* info;
  5924. int16 len;
  5925. int cmd = 0;
  5926. nullpo_retv(sd);
  5927. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5928. if(!cmd) cmd = 0x09A6; //default
  5929. info = &packet_db[sd->packet_ver][cmd];
  5930. len = info->len;
  5931. if(!len) return; //version as packet disable
  5932. // sd->state.banking = 1; //mark opening and closing
  5933. WBUFW(buf,0) = cmd;
  5934. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  5935. WBUFW(buf,info->pos[1]) = 0; //reason
  5936. clif_send(buf,len,&sd->bl,SELF);
  5937. }
  5938. /*
  5939. * Requesting the data in bank
  5940. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5941. */
  5942. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5943. nullpo_retv(sd);
  5944. if( !battle_config.feature_banking ) {
  5945. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5946. return;
  5947. }
  5948. else {
  5949. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5950. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5951. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5952. clif_Bank_Check(sd);
  5953. }
  5954. }
  5955. /*
  5956. * Acknowledge of deposit some money in bank
  5957. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5958. */
  5959. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5960. unsigned char buf[17];
  5961. struct s_packet_db* info;
  5962. int16 len;
  5963. int cmd =0;
  5964. nullpo_retv(sd);
  5965. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5966. if(!cmd) cmd = 0x09A8;
  5967. info = &packet_db[sd->packet_ver][cmd];
  5968. len = info->len;
  5969. if(!len) return; //version as packet disable
  5970. WBUFW(buf,0) = cmd;
  5971. WBUFW(buf,info->pos[0]) = (short)reason;
  5972. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  5973. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5974. clif_send(buf,len,&sd->bl,SELF);
  5975. }
  5976. /*
  5977. * Request saving some money in bank
  5978. * @author : original [Yommy/Hercules]
  5979. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5980. */
  5981. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5982. nullpo_retv(sd);
  5983. if( !battle_config.feature_banking ) {
  5984. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5985. return;
  5986. }
  5987. else {
  5988. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5989. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5990. int money = RFIFOL(fd,info->pos[1]);
  5991. if(sd->status.account_id == aid){
  5992. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5993. clif_bank_deposit(sd,reason);
  5994. }
  5995. }
  5996. }
  5997. /*
  5998. * Acknowledge of withdrawing some money from bank
  5999. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6000. */
  6001. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6002. unsigned char buf[17];
  6003. struct s_packet_db* info;
  6004. int16 len;
  6005. int cmd;
  6006. nullpo_retv(sd);
  6007. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  6008. if(!cmd) cmd = 0x09AA;
  6009. info = &packet_db[sd->packet_ver][cmd];
  6010. len = info->len;
  6011. if(!len) return; //version as packet disable
  6012. WBUFW(buf,0) = cmd;
  6013. WBUFW(buf,info->pos[0]) = (short)reason;
  6014. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6015. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6016. clif_send(buf,len,&sd->bl,SELF);
  6017. }
  6018. /*
  6019. * Request Withdrawing some money from bank
  6020. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6021. */
  6022. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6023. nullpo_retv(sd);
  6024. if( !battle_config.feature_banking ) {
  6025. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  6026. return;
  6027. }
  6028. else {
  6029. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  6030. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6031. int money = RFIFOL(fd,info->pos[1]);
  6032. if(sd->status.account_id == aid){
  6033. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6034. clif_bank_withdraw(sd,reason);
  6035. }
  6036. }
  6037. }
  6038. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6039. /// 0125 <index>.W <amount>.L
  6040. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6041. {
  6042. int fd;
  6043. nullpo_retv(sd);
  6044. fd=sd->fd;
  6045. WFIFOHEAD(fd,packet_len(0x125));
  6046. WFIFOW(fd,0)=0x125;
  6047. WFIFOW(fd,2)=n+2;
  6048. WFIFOL(fd,4)=amount;
  6049. WFIFOSET(fd,packet_len(0x125));
  6050. }
  6051. /// Opens the shop creation menu (ZC_OPENSTORE).
  6052. /// 012d <num>.W
  6053. /// num:
  6054. /// number of allowed item slots
  6055. void clif_openvendingreq(struct map_session_data* sd, int num)
  6056. {
  6057. int fd;
  6058. nullpo_retv(sd);
  6059. fd = sd->fd;
  6060. WFIFOHEAD(fd,packet_len(0x12d));
  6061. WFIFOW(fd,0) = 0x12d;
  6062. WFIFOW(fd,2) = num;
  6063. WFIFOSET(fd,packet_len(0x12d));
  6064. }
  6065. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6066. /// 0131 <owner id>.L <message>.80B
  6067. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6068. {
  6069. unsigned char buf[128];
  6070. nullpo_retv(bl);
  6071. WBUFW(buf,0) = 0x131;
  6072. WBUFL(buf,2) = bl->id;
  6073. safestrncpy(WBUFCP(buf,6), message, 80);
  6074. if( fd ) {
  6075. WFIFOHEAD(fd,packet_len(0x131));
  6076. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6077. WFIFOSET(fd,packet_len(0x131));
  6078. } else {
  6079. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6080. }
  6081. }
  6082. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6083. /// 0132 <owner id>.L
  6084. void clif_closevendingboard(struct block_list* bl, int fd)
  6085. {
  6086. unsigned char buf[16];
  6087. nullpo_retv(bl);
  6088. WBUFW(buf,0) = 0x132;
  6089. WBUFL(buf,2) = bl->id;
  6090. if( fd ) {
  6091. WFIFOHEAD(fd,packet_len(0x132));
  6092. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6093. WFIFOSET(fd,packet_len(0x132));
  6094. } else {
  6095. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6096. }
  6097. }
  6098. /// Sends a list of items in a shop.
  6099. /// 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)
  6100. /// 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)
  6101. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6102. {
  6103. int i,fd;
  6104. int count;
  6105. struct map_session_data* vsd;
  6106. #if PACKETVER < 20100105
  6107. const int cmd = 0x133;
  6108. const int offset = 8;
  6109. #else
  6110. const int cmd = 0x800;
  6111. const int offset = 12;
  6112. #endif
  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. nullpo_retv(vending);
  6120. nullpo_retv(vsd=map_id2sd(id));
  6121. fd = sd->fd;
  6122. count = vsd->vend_num;
  6123. WFIFOHEAD(fd, offset+count*item_length);
  6124. WFIFOW(fd,0) = cmd;
  6125. WFIFOW(fd,2) = offset+count*item_length;
  6126. WFIFOL(fd,4) = id;
  6127. #if PACKETVER >= 20100105
  6128. WFIFOL(fd,8) = vsd->vender_id;
  6129. #endif
  6130. for( i = 0; i < count; i++ )
  6131. {
  6132. int index = vending[i].index;
  6133. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  6134. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6135. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6136. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6137. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6138. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  6139. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  6140. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  6141. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  6142. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  6143. #if PACKETVER >= 20150226
  6144. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  6145. #endif
  6146. }
  6147. WFIFOSET(fd,WFIFOW(fd,2));
  6148. }
  6149. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6150. /// 0135 <index>.W <amount>.W <result>.B
  6151. /// result:
  6152. /// 0 = success
  6153. /// 1 = not enough zeny
  6154. /// 2 = overweight
  6155. /// 4 = out of stock
  6156. /// 5 = "cannot use an npc shop while in a trade"
  6157. /// 6 = Because the store information was incorrect the item was not purchased.
  6158. /// 7 = No sales information.
  6159. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6160. {
  6161. int fd;
  6162. nullpo_retv(sd);
  6163. fd = sd->fd;
  6164. WFIFOHEAD(fd,packet_len(0x135));
  6165. WFIFOW(fd,0) = 0x135;
  6166. WFIFOW(fd,2) = index+2;
  6167. WFIFOW(fd,4) = amount;
  6168. WFIFOB(fd,6) = fail;
  6169. WFIFOSET(fd,packet_len(0x135));
  6170. }
  6171. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6172. /// 0a28 <Result>.B
  6173. /// result:
  6174. /// 0 = Successed
  6175. /// 1 = Failed
  6176. void clif_openvending_ack(struct map_session_data* sd, int result)
  6177. {
  6178. int fd;
  6179. nullpo_retv(sd);
  6180. fd = sd->fd;
  6181. WFIFOHEAD(fd, 3);
  6182. WFIFOW(fd,0) = 0xa28;
  6183. WFIFOB(fd,2) = result;
  6184. WFIFOSET(fd, 3);
  6185. }
  6186. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6187. /// 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 }*
  6188. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6189. {
  6190. int i,fd;
  6191. int count;
  6192. #if PACKETVER < 20150226
  6193. const int item_length = 22;
  6194. #else
  6195. const int item_length = 47;
  6196. #endif
  6197. nullpo_retv(sd);
  6198. fd = sd->fd;
  6199. count = sd->vend_num;
  6200. WFIFOHEAD(fd, 8+count*item_length);
  6201. WFIFOW(fd,0) = 0x136;
  6202. WFIFOW(fd,2) = 8+count*item_length;
  6203. WFIFOL(fd,4) = id;
  6204. for( i = 0; i < count; i++ ) {
  6205. int index = vending[i].index;
  6206. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  6207. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6208. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6209. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6210. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6211. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  6212. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  6213. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  6214. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  6215. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  6216. #if PACKETVER >= 20150226
  6217. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->status.cart[index]);
  6218. #endif
  6219. }
  6220. WFIFOSET(fd,WFIFOW(fd,2));
  6221. #if PACKETVER >= 20141022
  6222. /// 0 = Successed
  6223. /// 1 = Failed
  6224. clif_openvending_ack(sd, 0);
  6225. #endif
  6226. }
  6227. /// Inform merchant that someone has bought an item.
  6228. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6229. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6230. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6231. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6232. const int cmd = 0x137;
  6233. #else
  6234. const int cmd = 0x9e5;
  6235. #endif
  6236. int fd = sd->fd;
  6237. nullpo_retv(sd);
  6238. WFIFOHEAD(fd,packet_len(cmd));
  6239. WFIFOW(fd,0) = cmd;
  6240. WFIFOW(fd,2) = index+2;
  6241. WFIFOW(fd,4) = amount;
  6242. #if PACKETVER >= 20141016
  6243. WFIFOL(fd,6) = char_id; // GID
  6244. WFIFOL(fd,10) = (int)time(NULL); // Date
  6245. WFIFOL(fd,14) = zeny; // zeny
  6246. #endif
  6247. WFIFOSET(fd,packet_len(cmd));
  6248. }
  6249. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6250. /// 00fa <result>.B
  6251. /// result:
  6252. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6253. /// 1 = MsgStringTable[78]="party name already exists"
  6254. /// 2 = MsgStringTable[79]="already in a party"
  6255. /// 3 = cannot organize parties on this map
  6256. /// ? = nothing
  6257. void clif_party_created(struct map_session_data *sd,int result)
  6258. {
  6259. int fd;
  6260. nullpo_retv(sd);
  6261. fd=sd->fd;
  6262. WFIFOHEAD(fd,packet_len(0xfa));
  6263. WFIFOW(fd,0)=0xfa;
  6264. WFIFOB(fd,2)=result;
  6265. WFIFOSET(fd,packet_len(0xfa));
  6266. }
  6267. /// Adds new member to a party.
  6268. /// 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)
  6269. /// 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)
  6270. /// role:
  6271. /// 0 = leader
  6272. /// 1 = normal
  6273. /// state:
  6274. /// 0 = connected
  6275. /// 1 = disconnected
  6276. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6277. {
  6278. unsigned char buf[81];
  6279. int i;
  6280. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6281. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6282. } else {
  6283. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6284. }
  6285. if (i >= MAX_PARTY) return; //Should never happen...
  6286. sd = p->data[i].sd;
  6287. WBUFW(buf, 0) = 0x1e9;
  6288. WBUFL(buf, 2) = sd->status.account_id;
  6289. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6290. WBUFW(buf,10) = sd->bl.x;
  6291. WBUFW(buf,12) = sd->bl.y;
  6292. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  6293. safestrncpy(WBUFCP(buf,15), p->party.name, NAME_LENGTH);
  6294. safestrncpy(WBUFCP(buf,39), sd->status.name, NAME_LENGTH);
  6295. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,63));
  6296. WBUFB(buf,79) = (p->party.item&1)?1:0;
  6297. WBUFB(buf,80) = (p->party.item&2)?1:0;
  6298. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  6299. }
  6300. /// Sends party information (ZC_GROUP_LIST).
  6301. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6302. /// role:
  6303. /// 0 = leader
  6304. /// 1 = normal
  6305. /// state:
  6306. /// 0 = connected
  6307. /// 1 = disconnected
  6308. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6309. {
  6310. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  6311. struct map_session_data* party_sd = NULL;
  6312. int i, c;
  6313. nullpo_retv(p);
  6314. WBUFW(buf,0) = 0xfb;
  6315. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6316. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6317. {
  6318. struct party_member* m = &p->party.member[i];
  6319. if(!m->account_id) continue;
  6320. if(party_sd == NULL) party_sd = p->data[i].sd;
  6321. WBUFL(buf,28+c*46) = m->account_id;
  6322. safestrncpy(WBUFCP(buf,28+c*46+4), m->name, NAME_LENGTH);
  6323. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,28+c*46+28));
  6324. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  6325. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  6326. c++;
  6327. }
  6328. WBUFW(buf,2) = 28+c*46;
  6329. if(sd) { // send only to self
  6330. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6331. } else if (party_sd) { // send to whole party
  6332. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6333. }
  6334. }
  6335. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6336. /// 02c9 <flag>.B
  6337. /// flag:
  6338. /// 0 = allow party invites
  6339. /// 1 = auto-deny party invites
  6340. void clif_partyinvitationstate(struct map_session_data* sd)
  6341. {
  6342. int fd;
  6343. nullpo_retv(sd);
  6344. fd = sd->fd;
  6345. WFIFOHEAD(fd, packet_len(0x2c9));
  6346. WFIFOW(fd, 0) = 0x2c9;
  6347. WFIFOB(fd, 2) = 0; // not implemented
  6348. WFIFOSET(fd, packet_len(0x2c9));
  6349. }
  6350. /// Party invitation request.
  6351. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6352. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6353. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6354. {
  6355. #if PACKETVER < 20070821
  6356. const int cmd = 0xfe;
  6357. #else
  6358. const int cmd = 0x2c6;
  6359. #endif
  6360. int fd;
  6361. struct party_data *p;
  6362. nullpo_retv(sd);
  6363. nullpo_retv(tsd);
  6364. fd=tsd->fd;
  6365. if( (p=party_search(sd->status.party_id))==NULL )
  6366. return;
  6367. WFIFOHEAD(fd,packet_len(cmd));
  6368. WFIFOW(fd,0)=cmd;
  6369. WFIFOL(fd,2)=sd->status.party_id;
  6370. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6371. WFIFOSET(fd,packet_len(cmd));
  6372. }
  6373. /// Party invite result.
  6374. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6375. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6376. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6377. {
  6378. int fd;
  6379. nullpo_retv(sd);
  6380. fd=sd->fd;
  6381. #if PACKETVER < 20070904
  6382. if( reply == PARTY_REPLY_OFFLINE ) {
  6383. clif_displaymessage(fd, msg_txt(sd,3));
  6384. return;
  6385. }
  6386. #endif
  6387. #if PACKETVER < 20070821
  6388. WFIFOHEAD(fd,packet_len(0xfd));
  6389. WFIFOW(fd,0) = 0xfd;
  6390. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6391. WFIFOB(fd,26) = reply;
  6392. WFIFOSET(fd,packet_len(0xfd));
  6393. #else
  6394. WFIFOHEAD(fd,packet_len(0x2c5));
  6395. WFIFOW(fd,0) = 0x2c5;
  6396. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6397. WFIFOL(fd,26) = reply;
  6398. WFIFOSET(fd,packet_len(0x2c5));
  6399. #endif
  6400. }
  6401. /// Updates party settings.
  6402. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6403. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6404. /// exp option:
  6405. /// 0 = exp sharing disabled
  6406. /// 1 = exp sharing enabled
  6407. /// 2 = cannot change exp sharing
  6408. ///
  6409. /// flag:
  6410. /// 0 = send to party
  6411. /// 1 = send to sd
  6412. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6413. {
  6414. unsigned char buf[16];
  6415. #if PACKETVER < 20090603
  6416. const int cmd = 0x101;
  6417. #else
  6418. const int cmd = 0x7d8;
  6419. #endif
  6420. nullpo_retv(p);
  6421. if(!sd && flag==0){
  6422. int i;
  6423. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6424. if (i < MAX_PARTY)
  6425. sd = p->data[i].sd;
  6426. }
  6427. if(!sd) return;
  6428. WBUFW(buf,0)=cmd;
  6429. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6430. #if PACKETVER >= 20090603
  6431. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6432. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6433. #endif
  6434. if(flag==0)
  6435. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6436. else
  6437. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6438. }
  6439. /**
  6440. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6441. * @param sd Send the notification for this player
  6442. * @param account_id Account ID of kicked member
  6443. * @param name Name of kicked member
  6444. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6445. * @param target Send target
  6446. **/
  6447. void clif_party_withdraw(struct map_session_data *sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target) {
  6448. unsigned char buf[2+4+NAME_LENGTH+1];
  6449. if (!sd)
  6450. return;
  6451. WBUFW(buf,0) = 0x0105;
  6452. WBUFL(buf,2) = account_id;
  6453. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6454. WBUFB(buf,6+NAME_LENGTH) = result;
  6455. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6456. }
  6457. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6458. /// 0109 <packet len>.W <account id>.L <message>.?B
  6459. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6460. {
  6461. struct map_session_data *sd;
  6462. int i;
  6463. nullpo_retv(p);
  6464. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6465. if(i < MAX_PARTY){
  6466. unsigned char buf[1024];
  6467. if( len > sizeof(buf)-8 )
  6468. {
  6469. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6470. len = sizeof(buf)-8;
  6471. }
  6472. sd = p->data[i].sd;
  6473. WBUFW(buf,0)=0x109;
  6474. WBUFW(buf,2)=len+8;
  6475. WBUFL(buf,4)=account_id;
  6476. safestrncpy(WBUFCP(buf,8), mes, len);
  6477. clif_send(buf,len+8,&sd->bl,PARTY);
  6478. }
  6479. }
  6480. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6481. /// 0107 <account id>.L <x>.W <y>.W
  6482. void clif_party_xy(struct map_session_data *sd)
  6483. {
  6484. unsigned char buf[16];
  6485. nullpo_retv(sd);
  6486. WBUFW(buf,0)=0x107;
  6487. WBUFL(buf,2)=sd->status.account_id;
  6488. WBUFW(buf,6)=sd->bl.x;
  6489. WBUFW(buf,8)=sd->bl.y;
  6490. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6491. }
  6492. /*==========================================
  6493. * Sends x/y dot to a single fd. [Skotlex]
  6494. *------------------------------------------*/
  6495. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6496. {
  6497. WFIFOHEAD(fd,packet_len(0x107));
  6498. WFIFOW(fd,0)=0x107;
  6499. WFIFOL(fd,2)=sd->status.account_id;
  6500. WFIFOW(fd,6)=sd->bl.x;
  6501. WFIFOW(fd,8)=sd->bl.y;
  6502. WFIFOSET(fd,packet_len(0x107));
  6503. }
  6504. /// Updates HP bar of a party member.
  6505. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6506. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6507. void clif_party_hp(struct map_session_data *sd)
  6508. {
  6509. unsigned char buf[16];
  6510. #if PACKETVER < 20100126
  6511. const int cmd = 0x106;
  6512. #else
  6513. const int cmd = 0x80e;
  6514. #endif
  6515. nullpo_retv(sd);
  6516. WBUFW(buf,0)=cmd;
  6517. WBUFL(buf,2)=sd->status.account_id;
  6518. #if PACKETVER < 20100126
  6519. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6520. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6521. WBUFW(buf,8) = 100;
  6522. } else {
  6523. WBUFW(buf,6) = sd->battle_status.hp;
  6524. WBUFW(buf,8) = sd->battle_status.max_hp;
  6525. }
  6526. #else
  6527. WBUFL(buf,6) = sd->battle_status.hp;
  6528. WBUFL(buf,10) = sd->battle_status.max_hp;
  6529. #endif
  6530. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6531. }
  6532. /*==========================================
  6533. * Sends HP bar to a single fd. [Skotlex]
  6534. *------------------------------------------*/
  6535. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6536. {
  6537. #if PACKETVER < 20100126
  6538. const int cmd = 0x106;
  6539. #else
  6540. const int cmd = 0x80e;
  6541. #endif
  6542. WFIFOHEAD(fd,packet_len(cmd));
  6543. WFIFOW(fd,0) = cmd;
  6544. WFIFOL(fd,2) = id;
  6545. #if PACKETVER < 20100126
  6546. if( maxhp > INT16_MAX )
  6547. {// To correctly display the %hp bar. [Skotlex]
  6548. WFIFOW(fd,6) = hp/(maxhp/100);
  6549. WFIFOW(fd,8) = 100;
  6550. } else {
  6551. WFIFOW(fd,6) = hp;
  6552. WFIFOW(fd,8) = maxhp;
  6553. }
  6554. #else
  6555. WFIFOL(fd,6) = hp;
  6556. WFIFOL(fd,10) = maxhp;
  6557. #endif
  6558. WFIFOSET(fd, packet_len(cmd));
  6559. }
  6560. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6561. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6562. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6563. {
  6564. int fd;
  6565. nullpo_retv(sd);
  6566. nullpo_retv(bl);
  6567. fd=sd->fd;
  6568. WFIFOHEAD(fd,packet_len(0x139));
  6569. WFIFOW(fd, 0)=0x139;
  6570. WFIFOL(fd, 2)=bl->id;
  6571. WFIFOW(fd, 6)=bl->x;
  6572. WFIFOW(fd, 8)=bl->y;
  6573. WFIFOW(fd,10)=sd->bl.x;
  6574. WFIFOW(fd,12)=sd->bl.y;
  6575. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6576. WFIFOSET(fd,packet_len(0x139));
  6577. }
  6578. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6579. /// 018f <result>.W <name id>.W
  6580. /// result:
  6581. /// 0 = success
  6582. /// 1 = failure
  6583. /// 2 = success (alchemist)
  6584. /// 3 = failure (alchemist)
  6585. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6586. {
  6587. int view,fd;
  6588. nullpo_retv(sd);
  6589. fd = sd->fd;
  6590. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6591. WFIFOHEAD(fd,packet_len(0x18f));
  6592. WFIFOW(fd, 0)=0x18f;
  6593. WFIFOW(fd, 2)=flag;
  6594. if((view = itemdb_viewid(nameid)) > 0)
  6595. WFIFOW(fd, 4)=view;
  6596. else
  6597. WFIFOW(fd, 4)=nameid;
  6598. WFIFOSET(fd,packet_len(0x18f));
  6599. }
  6600. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6601. /// 019e
  6602. void clif_catch_process(struct map_session_data *sd)
  6603. {
  6604. int fd;
  6605. nullpo_retv(sd);
  6606. fd=sd->fd;
  6607. WFIFOHEAD(fd,packet_len(0x19e));
  6608. WFIFOW(fd,0)=0x19e;
  6609. WFIFOSET(fd,packet_len(0x19e));
  6610. }
  6611. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6612. /// 01a0 <result>.B
  6613. /// 0 = failure
  6614. /// 1 = success
  6615. void clif_pet_roulette(struct map_session_data *sd,int data)
  6616. {
  6617. int fd;
  6618. nullpo_retv(sd);
  6619. fd=sd->fd;
  6620. WFIFOHEAD(fd,packet_len(0x1a0));
  6621. WFIFOW(fd,0)=0x1a0;
  6622. WFIFOB(fd,2)=data;
  6623. WFIFOSET(fd,packet_len(0x1a0));
  6624. }
  6625. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6626. /// 01a6 <packet len>.W { <index>.W }*
  6627. void clif_sendegg(struct map_session_data *sd)
  6628. {
  6629. int i,n=0,fd;
  6630. nullpo_retv(sd);
  6631. fd=sd->fd;
  6632. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6633. clif_displaymessage(fd, msg_txt(sd,666));
  6634. return;
  6635. }
  6636. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6637. WFIFOW(fd,0)=0x1a6;
  6638. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6639. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6640. sd->inventory_data[i]->type!=IT_PETEGG ||
  6641. sd->status.inventory[i].amount<=0)
  6642. continue;
  6643. WFIFOW(fd,n*2+4)=i+2;
  6644. n++;
  6645. }
  6646. WFIFOW(fd,2)=4+n*2;
  6647. WFIFOSET(fd,WFIFOW(fd,2));
  6648. sd->menuskill_id = SA_TAMINGMONSTER;
  6649. sd->menuskill_val = -1;
  6650. }
  6651. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6652. /// 01a4 <type>.B <id>.L <data>.L
  6653. /// type:
  6654. /// 0 = pre-init (data = 0)
  6655. /// 1 = intimacy (data = 0~4)
  6656. /// 2 = hunger (data = 0~4)
  6657. /// 3 = accessory
  6658. /// 4 = performance (data = 1~3: normal, 4: special)
  6659. /// 5 = hairstyle
  6660. ///
  6661. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6662. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6663. {
  6664. uint8 buf[16];
  6665. nullpo_retv(pd);
  6666. WBUFW(buf,0) = 0x1a4;
  6667. WBUFB(buf,2) = type;
  6668. WBUFL(buf,3) = pd->bl.id;
  6669. WBUFL(buf,7) = param;
  6670. if (sd)
  6671. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6672. else
  6673. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6674. }
  6675. /// Pet's base data (ZC_PROPERTY_PET).
  6676. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6677. void clif_send_petstatus(struct map_session_data *sd)
  6678. {
  6679. int fd;
  6680. struct s_pet *pet;
  6681. nullpo_retv(sd);
  6682. nullpo_retv(sd->pd);
  6683. fd=sd->fd;
  6684. pet = &sd->pd->pet;
  6685. WFIFOHEAD(fd,packet_len(0x1a2));
  6686. WFIFOW(fd,0)=0x1a2;
  6687. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6688. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6689. WFIFOW(fd,27)=pet->level;
  6690. WFIFOW(fd,29)=pet->hungry;
  6691. WFIFOW(fd,31)=pet->intimate;
  6692. WFIFOW(fd,33)=pet->equip;
  6693. #if PACKETVER >= 20081126
  6694. WFIFOW(fd,35)=pet->class_;
  6695. #endif
  6696. WFIFOSET(fd,packet_len(0x1a2));
  6697. }
  6698. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6699. /// 01aa <id>.L <data>.L
  6700. /// data:
  6701. /// @see CZ_PET_ACT.
  6702. void clif_pet_emotion(struct pet_data *pd,int param)
  6703. {
  6704. unsigned char buf[16];
  6705. nullpo_retv(pd);
  6706. memset(buf,0,packet_len(0x1aa));
  6707. WBUFW(buf,0)=0x1aa;
  6708. WBUFL(buf,2)=pd->bl.id;
  6709. if(param >= 100 && pd->petDB->talk_convert_class) {
  6710. if(pd->petDB->talk_convert_class < 0)
  6711. return;
  6712. else if(pd->petDB->talk_convert_class > 0) {
  6713. // replace mob_id component of talk/act data
  6714. param -= (pd->pet.class_ - 100)*100;
  6715. param += (pd->petDB->talk_convert_class - 100)*100;
  6716. }
  6717. }
  6718. WBUFL(buf,6)=param;
  6719. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6720. }
  6721. /// Result of request to feed a pet (ZC_FEED_PET).
  6722. /// 01a3 <result>.B <name id>.W
  6723. /// result:
  6724. /// 0 = failure
  6725. /// 1 = success
  6726. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6727. {
  6728. int fd;
  6729. nullpo_retv(sd);
  6730. fd=sd->fd;
  6731. WFIFOHEAD(fd,packet_len(0x1a3));
  6732. WFIFOW(fd,0)=0x1a3;
  6733. WFIFOB(fd,2)=fail;
  6734. WFIFOW(fd,3)=foodid;
  6735. WFIFOSET(fd,packet_len(0x1a3));
  6736. }
  6737. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6738. /// 01cd { <skill id>.L }*7
  6739. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6740. {
  6741. int fd;
  6742. nullpo_retv(sd);
  6743. fd=sd->fd;
  6744. WFIFOHEAD(fd,packet_len(0x1cd));
  6745. WFIFOW(fd, 0)=0x1cd;
  6746. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6747. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6748. else
  6749. WFIFOL(fd,2)= 0x00000000;
  6750. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6751. WFIFOL(fd,6)= MG_COLDBOLT;
  6752. else
  6753. WFIFOL(fd,6)= 0x00000000;
  6754. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6755. WFIFOL(fd,10)= MG_FIREBOLT;
  6756. else
  6757. WFIFOL(fd,10)= 0x00000000;
  6758. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6759. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6760. else
  6761. WFIFOL(fd,14)= 0x00000000;
  6762. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6763. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6764. else
  6765. WFIFOL(fd,18)= 0x00000000;
  6766. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6767. WFIFOL(fd,22)= MG_FIREBALL;
  6768. else
  6769. WFIFOL(fd,22)= 0x00000000;
  6770. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6771. WFIFOL(fd,26)= MG_FROSTDIVER;
  6772. else
  6773. WFIFOL(fd,26)= 0x00000000;
  6774. WFIFOSET(fd,packet_len(0x1cd));
  6775. sd->menuskill_id = SA_AUTOSPELL;
  6776. sd->menuskill_val = skill_lv;
  6777. }
  6778. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6779. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6780. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6781. {
  6782. unsigned char buf[56];
  6783. nullpo_retv(src);
  6784. memset(buf,0,packet_len(0x1cf));
  6785. WBUFW(buf,0) = 0x1cf;
  6786. WBUFL(buf,2) = src->id;
  6787. if( src->type == BL_MER )
  6788. {
  6789. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6790. if( md && md->master && md->devotion_flag )
  6791. WBUFL(buf,6) = md->master->bl.id;
  6792. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6793. }
  6794. else
  6795. {
  6796. int i;
  6797. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6798. if( sd == NULL )
  6799. return;
  6800. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6801. WBUFL(buf,6+4*i) = sd->devotion[i];
  6802. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6803. }
  6804. if( tsd )
  6805. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6806. else
  6807. clif_send(buf, packet_len(0x1cf), src, AREA);
  6808. }
  6809. /*==========================================
  6810. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6811. * Notifies clients in an area of an object's spirits.
  6812. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6813. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6814. *------------------------------------------*/
  6815. void clif_spiritball(struct block_list *bl) {
  6816. unsigned char buf[16];
  6817. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6818. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6819. nullpo_retv(bl);
  6820. WBUFW(buf, 0) = 0x1d0;
  6821. WBUFL(buf, 2) = bl->id;
  6822. WBUFW(buf, 6) = 0; //init to 0
  6823. switch(bl->type){
  6824. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6825. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6826. }
  6827. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6828. }
  6829. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6830. /// 01d2 <account id>.L <delay>.L
  6831. void clif_combo_delay(struct block_list *bl,int wait)
  6832. {
  6833. unsigned char buf[32];
  6834. nullpo_retv(bl);
  6835. WBUFW(buf,0)=0x1d2;
  6836. WBUFL(buf,2)=bl->id;
  6837. WBUFL(buf,6)=wait;
  6838. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6839. }
  6840. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6841. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6842. /// flag:
  6843. /// 0 = inactive
  6844. /// 1 = active
  6845. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6846. {
  6847. unsigned char buf[32];
  6848. nullpo_retv(src);
  6849. WBUFW(buf,0)=0x1d1;
  6850. WBUFL(buf,2)=src->id;
  6851. WBUFL(buf,6)=dst_id;
  6852. WBUFL(buf,10)=active;
  6853. clif_send(buf,packet_len(0x1d1),src,AREA);
  6854. }
  6855. /// MVP effect (ZC_MVP).
  6856. /// 010c <account id>.L
  6857. void clif_mvp_effect(struct map_session_data *sd)
  6858. {
  6859. unsigned char buf[16];
  6860. nullpo_retv(sd);
  6861. WBUFW(buf,0)=0x10c;
  6862. WBUFL(buf,2)=sd->bl.id;
  6863. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6864. }
  6865. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6866. /// 010a <name id>.W
  6867. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6868. {
  6869. int view,fd;
  6870. nullpo_retv(sd);
  6871. fd=sd->fd;
  6872. WFIFOHEAD(fd,packet_len(0x10a));
  6873. WFIFOW(fd,0)=0x10a;
  6874. if((view = itemdb_viewid(nameid)) > 0)
  6875. WFIFOW(fd,2)=view;
  6876. else
  6877. WFIFOW(fd,2)=nameid;
  6878. WFIFOSET(fd,packet_len(0x10a));
  6879. }
  6880. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6881. /// 010b <exp>.L
  6882. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  6883. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  6884. if (battle_config.mvp_exp_reward_message) {
  6885. char e_msg[CHAT_SIZE_MAX];
  6886. sprintf(e_msg, msg_txt(sd, 717), exp);
  6887. clif_colormes(sd->fd, color_table[COLOR_CYAN], e_msg); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  6888. }
  6889. #else
  6890. int fd;
  6891. nullpo_retv(sd);
  6892. fd = sd->fd;
  6893. WFIFOHEAD(fd, packet_len(0x10b));
  6894. WFIFOW(fd,0) = 0x10b;
  6895. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  6896. WFIFOSET(fd, packet_len(0x10b));
  6897. #endif
  6898. }
  6899. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6900. /// 010d
  6901. ///
  6902. /// "You are the MVP, but cannot obtain the reward because
  6903. /// you are overweight."
  6904. void clif_mvp_noitem(struct map_session_data* sd)
  6905. {
  6906. int fd = sd->fd;
  6907. WFIFOHEAD(fd,packet_len(0x10d));
  6908. WFIFOW(fd,0) = 0x10d;
  6909. WFIFOSET(fd,packet_len(0x10d));
  6910. }
  6911. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6912. /// 0167 <result>.B
  6913. /// result:
  6914. /// 0 = "Guild has been created."
  6915. /// 1 = "You are already in a Guild."
  6916. /// 2 = "That Guild Name already exists."
  6917. /// 3 = "You need the neccessary item to create a Guild."
  6918. void clif_guild_created(struct map_session_data *sd,int flag)
  6919. {
  6920. int fd;
  6921. nullpo_retv(sd);
  6922. fd=sd->fd;
  6923. WFIFOHEAD(fd,packet_len(0x167));
  6924. WFIFOW(fd,0)=0x167;
  6925. WFIFOB(fd,2)=flag;
  6926. WFIFOSET(fd,packet_len(0x167));
  6927. }
  6928. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6929. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6930. /// mode:
  6931. /// &0x01 = allow invite
  6932. /// &0x10 = allow expel
  6933. void clif_guild_belonginfo(struct map_session_data *sd)
  6934. {
  6935. int ps,fd;
  6936. struct guild* g;
  6937. nullpo_retv(sd);
  6938. nullpo_retv(g = sd->guild);
  6939. fd=sd->fd;
  6940. ps=guild_getposition(sd);
  6941. WFIFOHEAD(fd,packet_len(0x16c));
  6942. WFIFOW(fd,0)=0x16c;
  6943. WFIFOL(fd,2)=g->guild_id;
  6944. WFIFOL(fd,6)=g->emblem_id;
  6945. WFIFOL(fd,10)=g->position[ps].mode;
  6946. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6947. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6948. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  6949. WFIFOSET(fd,packet_len(0x16c));
  6950. }
  6951. /// Guild member login notice.
  6952. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6953. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6954. /// status:
  6955. /// 0 = offline
  6956. /// 1 = online
  6957. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6958. {
  6959. unsigned char buf[64];
  6960. struct map_session_data* sd;
  6961. nullpo_retv(g);
  6962. WBUFW(buf, 0)=0x1f2;
  6963. WBUFL(buf, 2)=g->member[idx].account_id;
  6964. WBUFL(buf, 6)=g->member[idx].char_id;
  6965. WBUFL(buf,10)=flag;
  6966. if( ( sd = g->member[idx].sd ) != NULL )
  6967. {
  6968. WBUFW(buf,14) = sd->status.sex;
  6969. WBUFW(buf,16) = sd->status.hair;
  6970. WBUFW(buf,18) = sd->status.hair_color;
  6971. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6972. }
  6973. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6974. {
  6975. WBUFW(buf,14) = 0;
  6976. WBUFW(buf,16) = 0;
  6977. WBUFW(buf,18) = 0;
  6978. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6979. }
  6980. }
  6981. // Function `clif_guild_memberlogin_notice` sends info about
  6982. // logins and logouts of a guild member to the rest members.
  6983. // But at the 1st time (after a player login or map changing)
  6984. // the client won't show the message.
  6985. // So I suggest use this function for sending "first-time-info"
  6986. // to some player on entering the game or changing location.
  6987. // At next time the client would always show the message.
  6988. // The function sends all the statuses in the single packet
  6989. // to economize traffic. [LuzZza]
  6990. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6991. {
  6992. struct guild *g;
  6993. unsigned char buf[14*128];
  6994. int i, count=0, p_len;
  6995. nullpo_retv(sd);
  6996. p_len = packet_len(0x16d);
  6997. if(!(g = sd->guild))
  6998. return;
  6999. for(i=0; i<g->max_member; i++) {
  7000. if(g->member[i].account_id > 0 &&
  7001. g->member[i].account_id != sd->status.account_id) {
  7002. WBUFW(buf,count*p_len) = 0x16d;
  7003. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7004. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7005. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7006. count++;
  7007. }
  7008. }
  7009. clif_send(buf, p_len*count, &sd->bl, SELF);
  7010. }
  7011. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7012. /// 014e <menu flag>.L
  7013. /// menu flag:
  7014. /// 0x00 = Basic Info (always on)
  7015. /// &0x01 = Member manager
  7016. /// &0x02 = Positions
  7017. /// &0x04 = Skills
  7018. /// &0x10 = Expulsion list
  7019. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7020. /// &0x80 = Notice
  7021. void clif_guild_masterormember(struct map_session_data *sd)
  7022. {
  7023. int fd;
  7024. nullpo_retv(sd);
  7025. fd=sd->fd;
  7026. WFIFOHEAD(fd,packet_len(0x14e));
  7027. WFIFOW(fd,0) = 0x14e;
  7028. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7029. WFIFOSET(fd,packet_len(0x14e));
  7030. }
  7031. /// Guild basic information (Territories [Valaris])
  7032. /// 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)
  7033. /// 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)
  7034. void clif_guild_basicinfo(struct map_session_data *sd) {
  7035. int fd;
  7036. struct guild *g;
  7037. nullpo_retv(sd);
  7038. fd = sd->fd;
  7039. if( (g = sd->guild) == NULL )
  7040. return;
  7041. WFIFOHEAD(fd,packet_len(0x1b6));
  7042. WFIFOW(fd, 0)=0x1b6;//0x150;
  7043. WFIFOL(fd, 2)=g->guild_id;
  7044. WFIFOL(fd, 6)=g->guild_lv;
  7045. WFIFOL(fd,10)=g->connect_member;
  7046. WFIFOL(fd,14)=g->max_member;
  7047. WFIFOL(fd,18)=g->average_lv;
  7048. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7049. WFIFOL(fd,26)=g->next_exp;
  7050. WFIFOL(fd,30)=0; // Tax Points
  7051. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7052. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7053. WFIFOL(fd,42)=g->emblem_id;
  7054. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7055. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7056. safestrncpy(WFIFOCP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7057. WFIFOL(fd,110) = 0; // zeny
  7058. WFIFOSET(fd,packet_len(0x1b6));
  7059. }
  7060. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7061. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7062. void clif_guild_allianceinfo(struct map_session_data *sd)
  7063. {
  7064. int fd,i,c;
  7065. struct guild *g;
  7066. nullpo_retv(sd);
  7067. if( (g = sd->guild) == NULL )
  7068. return;
  7069. fd = sd->fd;
  7070. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7071. WFIFOW(fd, 0)=0x14c;
  7072. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7073. struct guild_alliance *a=&g->alliance[i];
  7074. if(a->guild_id>0){
  7075. WFIFOL(fd,c*32+4)=a->opposition;
  7076. WFIFOL(fd,c*32+8)=a->guild_id;
  7077. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7078. c++;
  7079. }
  7080. }
  7081. WFIFOW(fd, 2)=c*32+4;
  7082. WFIFOSET(fd,WFIFOW(fd,2));
  7083. }
  7084. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  7085. /// 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 }*
  7086. /// state:
  7087. /// 0 = offline
  7088. /// 1 = online
  7089. /// memo:
  7090. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7091. void clif_guild_memberlist(struct map_session_data *sd)
  7092. {
  7093. int fd;
  7094. int i,c;
  7095. struct guild *g;
  7096. nullpo_retv(sd);
  7097. if( (fd = sd->fd) == 0 )
  7098. return;
  7099. if( (g = sd->guild) == NULL )
  7100. return;
  7101. WFIFOHEAD(fd, g->max_member * 104 + 4);
  7102. WFIFOW(fd, 0)=0x154;
  7103. for(i=0,c=0;i<g->max_member;i++){
  7104. struct guild_member *m=&g->member[i];
  7105. if(m->account_id==0)
  7106. continue;
  7107. WFIFOL(fd,c*104+ 4)=m->account_id;
  7108. WFIFOL(fd,c*104+ 8)=m->char_id;
  7109. WFIFOW(fd,c*104+12)=m->hair;
  7110. WFIFOW(fd,c*104+14)=m->hair_color;
  7111. WFIFOW(fd,c*104+16)=m->gender;
  7112. WFIFOW(fd,c*104+18)=m->class_;
  7113. WFIFOW(fd,c*104+20)=m->lv;
  7114. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7115. WFIFOL(fd,c*104+26)=m->online;
  7116. WFIFOL(fd,c*104+30)=m->position;
  7117. 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.
  7118. safestrncpy(WFIFOCP(fd,c*104+84),m->name,NAME_LENGTH);
  7119. c++;
  7120. }
  7121. WFIFOW(fd, 2)=c*104+4;
  7122. WFIFOSET(fd,WFIFOW(fd,2));
  7123. }
  7124. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7125. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7126. void clif_guild_positionnamelist(struct map_session_data *sd)
  7127. {
  7128. int i,fd;
  7129. struct guild *g;
  7130. nullpo_retv(sd);
  7131. if( (g = sd->guild) == NULL )
  7132. return;
  7133. fd = sd->fd;
  7134. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7135. WFIFOW(fd, 0)=0x166;
  7136. for(i=0;i<MAX_GUILDPOSITION;i++){
  7137. WFIFOL(fd,i*28+4)=i;
  7138. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7139. }
  7140. WFIFOW(fd,2)=i*28+4;
  7141. WFIFOSET(fd,WFIFOW(fd,2));
  7142. }
  7143. /// Guild position information (ZC_POSITION_INFO).
  7144. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7145. /// mode:
  7146. /// &0x01 = allow invite
  7147. /// &0x10 = allow expel
  7148. /// ranking:
  7149. /// TODO
  7150. void clif_guild_positioninfolist(struct map_session_data *sd)
  7151. {
  7152. int i,fd;
  7153. struct guild *g;
  7154. nullpo_retv(sd);
  7155. if( (g = sd->guild) == NULL )
  7156. return;
  7157. fd = sd->fd;
  7158. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7159. WFIFOW(fd, 0)=0x160;
  7160. for(i=0;i<MAX_GUILDPOSITION;i++){
  7161. struct guild_position *p=&g->position[i];
  7162. WFIFOL(fd,i*16+ 4)=i;
  7163. WFIFOL(fd,i*16+ 8)=p->mode;
  7164. WFIFOL(fd,i*16+12)=i;
  7165. WFIFOL(fd,i*16+16)=p->exp_mode;
  7166. }
  7167. WFIFOW(fd, 2)=i*16+4;
  7168. WFIFOSET(fd,WFIFOW(fd,2));
  7169. }
  7170. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7171. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7172. /// mode:
  7173. /// &0x01 = allow invite
  7174. /// &0x10 = allow expel
  7175. /// ranking:
  7176. /// TODO
  7177. void clif_guild_positionchanged(struct guild *g,int idx)
  7178. {
  7179. // FIXME: This packet is intended to update the clients after a
  7180. // commit of position info changes, not sending one packet per
  7181. // position.
  7182. struct map_session_data *sd;
  7183. unsigned char buf[128];
  7184. nullpo_retv(g);
  7185. WBUFW(buf, 0)=0x174;
  7186. WBUFW(buf, 2)=44; // packet len
  7187. // GUILD_REG_POSITION_INFO{
  7188. WBUFL(buf, 4)=idx;
  7189. WBUFL(buf, 8)=g->position[idx].mode;
  7190. WBUFL(buf,12)=idx;
  7191. WBUFL(buf,16)=g->position[idx].exp_mode;
  7192. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7193. // }*
  7194. if( (sd=guild_getavailablesd(g))!=NULL )
  7195. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7196. }
  7197. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7198. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7199. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7200. {
  7201. // FIXME: This packet is intended to update the clients after a
  7202. // commit of member position assignment changes, not sending one
  7203. // packet per position.
  7204. struct map_session_data *sd;
  7205. unsigned char buf[64];
  7206. nullpo_retv(g);
  7207. WBUFW(buf, 0)=0x156;
  7208. WBUFW(buf, 2)=16; // packet len
  7209. // MEMBER_POSITION_INFO{
  7210. WBUFL(buf, 4)=g->member[idx].account_id;
  7211. WBUFL(buf, 8)=g->member[idx].char_id;
  7212. WBUFL(buf,12)=g->member[idx].position;
  7213. // }*
  7214. if( (sd=guild_getavailablesd(g))!=NULL )
  7215. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7216. }
  7217. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7218. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7219. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7220. {
  7221. int fd;
  7222. nullpo_retv(sd);
  7223. nullpo_retv(g);
  7224. fd = sd->fd;
  7225. if( g->emblem_len <= 0 )
  7226. return;
  7227. WFIFOHEAD(fd,g->emblem_len+12);
  7228. WFIFOW(fd,0)=0x152;
  7229. WFIFOW(fd,2)=g->emblem_len+12;
  7230. WFIFOL(fd,4)=g->guild_id;
  7231. WFIFOL(fd,8)=g->emblem_id;
  7232. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7233. WFIFOSET(fd,WFIFOW(fd,2));
  7234. }
  7235. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7236. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7237. void clif_guild_emblem_area(struct block_list* bl)
  7238. {
  7239. uint8 buf[12];
  7240. nullpo_retv(bl);
  7241. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7242. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7243. WBUFW(buf,0) = 0x1b4;
  7244. WBUFL(buf,2) = bl->id;
  7245. WBUFL(buf,6) = status_get_guild_id(bl);
  7246. WBUFW(buf,10) = status_get_emblem_id(bl);
  7247. clif_send(buf, 12, bl, AREA_WOS);
  7248. }
  7249. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7250. /// 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 }*
  7251. void clif_guild_skillinfo(struct map_session_data* sd)
  7252. {
  7253. int fd;
  7254. struct guild* g;
  7255. int i,c;
  7256. nullpo_retv(sd);
  7257. if( (g = sd->guild) == NULL )
  7258. return;
  7259. fd = sd->fd;
  7260. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7261. WFIFOW(fd,0) = 0x0162;
  7262. WFIFOW(fd,4) = g->skill_point;
  7263. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7264. {
  7265. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7266. {
  7267. int id = g->skill[i].id;
  7268. int p = 6 + c*37;
  7269. WFIFOW(fd,p+0) = id;
  7270. WFIFOL(fd,p+2) = skill_get_inf(id);
  7271. WFIFOW(fd,p+6) = g->skill[i].lv;
  7272. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7273. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7274. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7275. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7276. c++;
  7277. }
  7278. }
  7279. WFIFOW(fd,2) = 6 + c*37;
  7280. WFIFOSET(fd,WFIFOW(fd,2));
  7281. }
  7282. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7283. /// 016f <subject>.60B <notice>.120B
  7284. void clif_guild_notice(struct map_session_data* sd)
  7285. {
  7286. int fd;
  7287. struct guild* g;
  7288. nullpo_retv(sd);
  7289. nullpo_retv(g = sd->guild);
  7290. fd = sd->fd;
  7291. if ( !session_isActive(fd) )
  7292. return;
  7293. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7294. return;
  7295. WFIFOHEAD(fd,packet_len(0x16f));
  7296. WFIFOW(fd,0) = 0x16f;
  7297. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7298. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7299. WFIFOSET(fd,packet_len(0x16f));
  7300. }
  7301. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7302. /// 016a <guild id>.L <guild name>.24B
  7303. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7304. {
  7305. int fd;
  7306. nullpo_retv(sd);
  7307. nullpo_retv(g);
  7308. fd=sd->fd;
  7309. WFIFOHEAD(fd,packet_len(0x16a));
  7310. WFIFOW(fd,0)=0x16a;
  7311. WFIFOL(fd,2)=g->guild_id;
  7312. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7313. WFIFOSET(fd,packet_len(0x16a));
  7314. }
  7315. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7316. /// 0169 <answer>.B
  7317. /// answer:
  7318. /// 0 = Already in guild.
  7319. /// 1 = Offer rejected.
  7320. /// 2 = Offer accepted.
  7321. /// 3 = Guild full.
  7322. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7323. {
  7324. int fd;
  7325. nullpo_retv(sd);
  7326. fd=sd->fd;
  7327. WFIFOHEAD(fd,packet_len(0x169));
  7328. WFIFOW(fd,0)=0x169;
  7329. WFIFOB(fd,2)=flag;
  7330. WFIFOSET(fd,packet_len(0x169));
  7331. }
  7332. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7333. /// 015a <char name>.24B <reason>.40B
  7334. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7335. {
  7336. unsigned char buf[128];
  7337. nullpo_retv(sd);
  7338. WBUFW(buf, 0)=0x15a;
  7339. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7340. memcpy(WBUFP(buf,26),mes,40);
  7341. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7342. }
  7343. /// Notifies clients of a guild of an expelled member.
  7344. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7345. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7346. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7347. {
  7348. unsigned char buf[128];
  7349. #if PACKETVER < 20100803
  7350. const unsigned short cmd = 0x15c;
  7351. #else
  7352. const unsigned short cmd = 0x839;
  7353. #endif
  7354. nullpo_retv(sd);
  7355. WBUFW(buf,0) = cmd;
  7356. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7357. safestrncpy(WBUFCP(buf,26), mes, 40);
  7358. #if PACKETVER < 20100803
  7359. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7360. #endif
  7361. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7362. }
  7363. /// Guild expulsion list (ZC_BAN_LIST).
  7364. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7365. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7366. void clif_guild_expulsionlist(struct map_session_data* sd)
  7367. {
  7368. #if PACKETVER < 20100803
  7369. const int offset = NAME_LENGTH*2+40;
  7370. #else
  7371. const int offset = NAME_LENGTH+40;
  7372. #endif
  7373. int fd, i, c = 0;
  7374. struct guild* g;
  7375. nullpo_retv(sd);
  7376. if( (g = sd->guild) == NULL )
  7377. return;
  7378. fd = sd->fd;
  7379. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7380. WFIFOW(fd,0) = 0x163;
  7381. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7382. {
  7383. struct guild_expulsion* e = &g->expulsion[i];
  7384. if( e->account_id > 0 )
  7385. {
  7386. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7387. #if PACKETVER < 20100803
  7388. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7389. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7390. #else
  7391. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7392. #endif
  7393. c++;
  7394. }
  7395. }
  7396. WFIFOW(fd,2) = 4 + c*offset;
  7397. WFIFOSET(fd,WFIFOW(fd,2));
  7398. }
  7399. /// Guild chat message (ZC_GUILD_CHAT).
  7400. /// 017f <packet len>.W <message>.?B
  7401. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7402. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7403. struct map_session_data *sd;
  7404. uint8 buf[256];
  7405. if( len == 0 )
  7406. {
  7407. return;
  7408. }
  7409. else if( len > sizeof(buf)-5 )
  7410. {
  7411. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7412. len = sizeof(buf)-5;
  7413. }
  7414. WBUFW(buf, 0) = 0x17f;
  7415. WBUFW(buf, 2) = len + 5;
  7416. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7417. if ((sd = guild_getavailablesd(g)) != NULL)
  7418. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7419. }
  7420. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7421. /// 0171 <inviter account id>.L <guild name>.24B
  7422. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7423. {
  7424. int fd;
  7425. nullpo_retv(sd);
  7426. fd=sd->fd;
  7427. WFIFOHEAD(fd,packet_len(0x171));
  7428. WFIFOW(fd,0)=0x171;
  7429. WFIFOL(fd,2)=account_id;
  7430. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7431. WFIFOSET(fd,packet_len(0x171));
  7432. }
  7433. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7434. /// 0173 <answer>.B
  7435. /// answer:
  7436. /// 0 = Already allied.
  7437. /// 1 = You rejected the offer.
  7438. /// 2 = You accepted the offer.
  7439. /// 3 = They have too any alliances.
  7440. /// 4 = You have too many alliances.
  7441. /// 5 = Alliances are disabled.
  7442. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7443. {
  7444. int fd;
  7445. nullpo_retv(sd);
  7446. fd=sd->fd;
  7447. WFIFOHEAD(fd,packet_len(0x173));
  7448. WFIFOW(fd,0)=0x173;
  7449. WFIFOL(fd,2)=flag;
  7450. WFIFOSET(fd,packet_len(0x173));
  7451. }
  7452. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7453. /// 0184 <other guild id>.L <relation>.L
  7454. /// relation:
  7455. /// 0 = Ally
  7456. /// 1 = Enemy
  7457. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7458. {
  7459. int fd;
  7460. nullpo_retv(sd);
  7461. fd = sd->fd;
  7462. if (fd <= 0)
  7463. return;
  7464. WFIFOHEAD(fd,packet_len(0x184));
  7465. WFIFOW(fd,0)=0x184;
  7466. WFIFOL(fd,2)=guild_id;
  7467. WFIFOL(fd,6)=flag;
  7468. WFIFOSET(fd,packet_len(0x184));
  7469. }
  7470. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7471. /// 0181 <result>.B
  7472. /// result:
  7473. /// 0 = Antagonist has been set.
  7474. /// 1 = Guild has too many Antagonists.
  7475. /// 2 = Already set as an Antagonist.
  7476. /// 3 = Antagonists are disabled.
  7477. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7478. {
  7479. int fd;
  7480. nullpo_retv(sd);
  7481. fd=sd->fd;
  7482. WFIFOHEAD(fd,packet_len(0x181));
  7483. WFIFOW(fd,0)=0x181;
  7484. WFIFOB(fd,2)=flag;
  7485. WFIFOSET(fd,packet_len(0x181));
  7486. }
  7487. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7488. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7489. /*
  7490. void clif_guild_allianceadded(struct guild *g,int idx)
  7491. {
  7492. unsigned char buf[64];
  7493. WBUFW(buf,0)=0x185;
  7494. WBUFL(buf,2)=g->alliance[idx].opposition;
  7495. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7496. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7497. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7498. }
  7499. */
  7500. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7501. /// 015e <reason>.L
  7502. /// 0 = success
  7503. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7504. /// 2 = there are still members in the guild
  7505. void clif_guild_broken(struct map_session_data *sd,int flag)
  7506. {
  7507. int fd;
  7508. nullpo_retv(sd);
  7509. fd=sd->fd;
  7510. WFIFOHEAD(fd,packet_len(0x15e));
  7511. WFIFOW(fd,0)=0x15e;
  7512. WFIFOL(fd,2)=flag;
  7513. WFIFOSET(fd,packet_len(0x15e));
  7514. }
  7515. /// Displays emotion on an object (ZC_EMOTION).
  7516. /// 00c0 <id>.L <type>.B
  7517. /// type:
  7518. /// enum emotion_type
  7519. void clif_emotion(struct block_list *bl,int type)
  7520. {
  7521. unsigned char buf[8];
  7522. nullpo_retv(bl);
  7523. WBUFW(buf,0)=0xc0;
  7524. WBUFL(buf,2)=bl->id;
  7525. WBUFB(buf,6)=type;
  7526. clif_send(buf,packet_len(0xc0),bl,AREA);
  7527. }
  7528. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7529. /// 0191 <id>.L <contents>.80B
  7530. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7531. {
  7532. unsigned char buf[MESSAGE_SIZE+6];
  7533. nullpo_retv(bl);
  7534. WBUFW(buf,0) = 0x191;
  7535. WBUFL(buf,2) = bl->id;
  7536. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7537. clif_send(buf,packet_len(0x191),bl,AREA);
  7538. }
  7539. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7540. /// 01ea <id>.L
  7541. void clif_wedding_effect(struct block_list *bl)
  7542. {
  7543. unsigned char buf[6];
  7544. nullpo_retv(bl);
  7545. WBUFW(buf,0) = 0x1ea;
  7546. WBUFL(buf,2) = bl->id;
  7547. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7548. }
  7549. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7550. /// 01e6 <partner name>.24B
  7551. void clif_callpartner(struct map_session_data *sd)
  7552. {
  7553. unsigned char buf[26];
  7554. nullpo_retv(sd);
  7555. WBUFW(buf,0) = 0x1e6;
  7556. if( sd->status.partner_id ) {
  7557. const char *p = map_charid2nick(sd->status.partner_id);
  7558. struct map_session_data *p_sd = pc_get_partner(sd);
  7559. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7560. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7561. else
  7562. WBUFB(buf,2) = 0;
  7563. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7564. WBUFB(buf,2) = 0;
  7565. }
  7566. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7567. }
  7568. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7569. /// 01e4
  7570. /// This packet while still implemented by the client is no longer being officially used.
  7571. /*
  7572. void clif_marriage_process(struct map_session_data *sd)
  7573. {
  7574. int fd;
  7575. nullpo_retv(sd);
  7576. fd=sd->fd;
  7577. WFIFOHEAD(fd,packet_len(0x1e4));
  7578. WFIFOW(fd,0)=0x1e4;
  7579. WFIFOSET(fd,packet_len(0x1e4));
  7580. }
  7581. */
  7582. /// Notice of divorce (ZC_DIVORCE).
  7583. /// 0205 <partner name>.24B
  7584. void clif_divorced(struct map_session_data* sd, const char* name)
  7585. {
  7586. int fd;
  7587. nullpo_retv(sd);
  7588. fd=sd->fd;
  7589. WFIFOHEAD(fd,packet_len(0x205));
  7590. WFIFOW(fd,0)=0x205;
  7591. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7592. WFIFOSET(fd, packet_len(0x205));
  7593. }
  7594. /// Marriage proposal (ZC_REQ_COUPLE).
  7595. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7596. /// This packet while still implemented by the client is no longer being officially used.
  7597. /*
  7598. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7599. {
  7600. nullpo_retv(sd);
  7601. WFIFOHEAD(fd,packet_len(0x1e2));
  7602. WFIFOW(fd,0) = 0x1e2;
  7603. WFIFOL(fd,2) = ssd->status.account_id;
  7604. WFIFOL(fd,6) = ssd->status.char_id;
  7605. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7606. WFIFOSET(fd, packet_len(0x1e2));
  7607. }
  7608. */
  7609. /*==========================================
  7610. *
  7611. *------------------------------------------*/
  7612. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7613. {
  7614. clif_disp_message(&sd->bl, mes, len, SELF);
  7615. }
  7616. /*==========================================
  7617. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7618. *------------------------------------------*/
  7619. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7620. {
  7621. unsigned char buf[256];
  7622. if( len == 0 ) {
  7623. return;
  7624. } else if( len > sizeof(buf)-5 ) {
  7625. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7626. len = sizeof(buf)-5;
  7627. }
  7628. WBUFW(buf, 0) = 0x17f;
  7629. WBUFW(buf, 2) = len + 5;
  7630. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7631. clif_send(buf, WBUFW(buf,2), src, target);
  7632. }
  7633. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7634. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7635. /// 00cd <result>.B
  7636. /// result:
  7637. /// 0 = failure
  7638. /// 1 = success
  7639. void clif_GM_kickack(struct map_session_data *sd, int id)
  7640. {
  7641. int fd;
  7642. nullpo_retv(sd);
  7643. fd = sd->fd;
  7644. WFIFOHEAD(fd,packet_len(0xcd));
  7645. WFIFOW(fd,0) = 0xcd;
  7646. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7647. WFIFOSET(fd, packet_len(0xcd));
  7648. }
  7649. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7650. {
  7651. int fd = tsd->fd;
  7652. if( fd > 0 )
  7653. clif_authfail_fd(fd, 15);
  7654. else {
  7655. // Close vending/buyingstore
  7656. if (sd) {
  7657. if (tsd->state.vending)
  7658. vending_closevending(tsd);
  7659. else if (tsd->state.buyingstore)
  7660. buyingstore_close(tsd);
  7661. }
  7662. map_quit(tsd);
  7663. }
  7664. if( sd )
  7665. clif_GM_kickack(sd,tsd->status.account_id);
  7666. }
  7667. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7668. /// 014a <result>.L
  7669. /// result:
  7670. /// 0 = "A manner point has been successfully aligned."
  7671. /// 1 = MP_FAILURE_EXHAUST
  7672. /// 2 = MP_FAILURE_ALREADY_GIVING
  7673. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7674. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7675. /// 5 = "You got a good point from %s."
  7676. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7677. {
  7678. int fd;
  7679. nullpo_retv(sd);
  7680. fd = sd->fd;
  7681. WFIFOHEAD(fd,packet_len(0x14a));
  7682. WFIFOW(fd,0) = 0x14a;
  7683. WFIFOL(fd,2) = type;
  7684. WFIFOSET(fd, packet_len(0x14a));
  7685. }
  7686. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7687. /// 014b <type>.B <GM name>.24B
  7688. /// type:
  7689. /// 0 = positive (unmute)
  7690. /// 1 = negative (mute)
  7691. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7692. {
  7693. int fd;
  7694. nullpo_retv(sd);
  7695. nullpo_retv(tsd);
  7696. fd = tsd->fd;
  7697. WFIFOHEAD(fd,packet_len(0x14b));
  7698. WFIFOW(fd,0) = 0x14b;
  7699. WFIFOB(fd,2) = type;
  7700. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7701. WFIFOSET(fd, packet_len(0x14b));
  7702. }
  7703. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7704. /// 00d1 <type>.B <result>.B
  7705. /// type:
  7706. /// 0 = /ex (deny)
  7707. /// 1 = /in (allow)
  7708. /// result:
  7709. /// 0 = success
  7710. /// 1 = failure
  7711. /// 2 = too many blocks
  7712. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7713. {
  7714. int fd;
  7715. nullpo_retv(sd);
  7716. fd=sd->fd;
  7717. WFIFOHEAD(fd,packet_len(0xd1));
  7718. WFIFOW(fd,0)=0xd1;
  7719. WFIFOB(fd,2)=type;
  7720. WFIFOB(fd,3)=flag;
  7721. WFIFOSET(fd,packet_len(0xd1));
  7722. }
  7723. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7724. /// 00d2 <type>.B <result>.B
  7725. /// type:
  7726. /// 0 = /exall (deny)
  7727. /// 1 = /inall (allow)
  7728. /// result:
  7729. /// 0 = success
  7730. /// 1 = failure
  7731. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7732. {
  7733. int fd;
  7734. nullpo_retv(sd);
  7735. fd=sd->fd;
  7736. WFIFOHEAD(fd,packet_len(0xd2));
  7737. WFIFOW(fd,0)=0xd2;
  7738. WFIFOB(fd,2)=type;
  7739. WFIFOB(fd,3)=flag;
  7740. WFIFOSET(fd,packet_len(0xd2));
  7741. }
  7742. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7743. /// 07fe <bgm>.24B
  7744. void clif_playBGM(struct map_session_data* sd, const char* name)
  7745. {
  7746. int fd;
  7747. nullpo_retv(sd);
  7748. fd = sd->fd;
  7749. WFIFOHEAD(fd,packet_len(0x7fe));
  7750. WFIFOW(fd,0) = 0x7fe;
  7751. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7752. WFIFOSET(fd,packet_len(0x7fe));
  7753. }
  7754. /// Plays/stops a wave sound (ZC_SOUND).
  7755. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7756. /// file name:
  7757. /// relative to data\wav
  7758. /// act:
  7759. /// 0 = play (once)
  7760. /// 1 = play (repeat, does not work)
  7761. /// 2 = stops all sound instances of file name (does not work)
  7762. /// term:
  7763. /// unknown purpose, only relevant to act = 1
  7764. /// npc id:
  7765. /// The accustic direction of the sound is determined by the
  7766. /// relative position of the NPC to the player (3D sound).
  7767. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7768. {
  7769. int fd;
  7770. nullpo_retv(sd);
  7771. nullpo_retv(bl);
  7772. fd = sd->fd;
  7773. WFIFOHEAD(fd,packet_len(0x1d3));
  7774. WFIFOW(fd,0) = 0x1d3;
  7775. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7776. WFIFOB(fd,26) = type;
  7777. WFIFOL(fd,27) = 0;
  7778. WFIFOL(fd,31) = bl->id;
  7779. WFIFOSET(fd,packet_len(0x1d3));
  7780. }
  7781. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7782. {
  7783. unsigned char buf[40];
  7784. nullpo_retv(bl);
  7785. WBUFW(buf,0) = 0x1d3;
  7786. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7787. WBUFB(buf,26) = type;
  7788. WBUFL(buf,27) = 0;
  7789. WBUFL(buf,31) = bl->id;
  7790. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7791. }
  7792. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7793. /// 01f3 <id>.L <effect id>.L
  7794. /// effect id:
  7795. /// @see doc/effect_list.txt
  7796. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7797. {
  7798. unsigned char buf[24];
  7799. nullpo_retv(bl);
  7800. memset(buf, 0, packet_len(0x1f3));
  7801. WBUFW(buf,0) = 0x1f3;
  7802. WBUFL(buf,2) = bl->id;
  7803. WBUFL(buf,6) = type;
  7804. clif_send(buf, packet_len(0x1f3), bl, target);
  7805. if (disguised(bl)) {
  7806. WBUFL(buf,2) = -bl->id;
  7807. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7808. }
  7809. }
  7810. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7811. {
  7812. WFIFOHEAD(fd,10);
  7813. WFIFOW(fd,0) = 0x1f3;
  7814. WFIFOL(fd,2) = bl->id;
  7815. WFIFOL(fd,6) = type;
  7816. WFIFOSET(fd,10);
  7817. }
  7818. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7819. /// 0284 <id>.L <effect id>.L <num data>.L
  7820. /// effect id:
  7821. /// @see doc/effect_list.txt
  7822. /// num data:
  7823. /// effect-dependent value
  7824. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7825. {
  7826. uint8 buf[14];
  7827. WBUFW(buf,0) = 0x284;
  7828. WBUFL(buf,2) = bl->id;
  7829. WBUFL(buf,6) = effect_id;
  7830. WBUFL(buf,10) = num;
  7831. clif_send(buf, packet_len(0x284), bl, target);
  7832. if( disguised(bl) )
  7833. {
  7834. WBUFL(buf,2) = -bl->id;
  7835. clif_send(buf, packet_len(0x284), bl, SELF);
  7836. }
  7837. }
  7838. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7839. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7840. int clif_colormes(int fd, unsigned long color, const char* msg) {
  7841. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7842. WFIFOHEAD(fd,msg_len + 12);
  7843. WFIFOW(fd,0) = 0x2C1;
  7844. WFIFOW(fd,2) = msg_len + 12;
  7845. WFIFOL(fd,4) = 0;
  7846. WFIFOL(fd,8) = color; //either color_table or channel_table
  7847. safestrncpy(WFIFOCP(fd,12), msg, msg_len);
  7848. WFIFOSET(fd, msg_len + 12);
  7849. return 0;
  7850. }
  7851. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7852. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7853. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7854. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7855. uint8 buf[256];
  7856. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7857. nullpo_retv(bl);
  7858. if( msg_len > sizeof(buf)-12 ) {
  7859. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7860. msg_len = sizeof(buf)-12;
  7861. }
  7862. WBUFW(buf,0) = 0x2C1;
  7863. WBUFW(buf,2) = msg_len + 12;
  7864. WBUFL(buf,4) = bl->id;
  7865. WBUFL(buf,8) = color;
  7866. memcpy(WBUFCP(buf,12), msg, msg_len);
  7867. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7868. }
  7869. void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
  7870. {
  7871. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  7872. nullpo_retv(sd);
  7873. if(msg_len > 0) {
  7874. int fd;
  7875. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7876. fd = sd->fd;
  7877. WFIFOHEAD(fd, msg_len+12);
  7878. WFIFOW(fd,0) = 0x2C1;
  7879. WFIFOW(fd,2) = msg_len+12;
  7880. WFIFOL(fd,4) = 0;
  7881. WFIFOL(fd,8) = color;
  7882. safestrncpy(WFIFOCP(fd,12), msg, msg_len);
  7883. WFIFOSET(fd, WFIFOW(fd,2));
  7884. }
  7885. }
  7886. /**
  7887. * Notifies the client that the storage window is still open
  7888. *
  7889. * Should only be used in cases where the client closed the
  7890. * storage window without server's consent
  7891. */
  7892. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7893. // Notify the client that the storage is open
  7894. if( sd->state.storage_flag == 1 ) {
  7895. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7896. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7897. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7898. }
  7899. // Notify the client that the gstorage is open otherwise it will
  7900. // remain locked forever and nobody will be able to access it
  7901. if( sd->state.storage_flag == 2 ) {
  7902. struct guild_storage *gstor = gstorage_get_storage(sd->status.guild_id);
  7903. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7904. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7905. else {
  7906. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7907. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7908. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7909. }
  7910. }
  7911. }
  7912. // refresh the client's screen, getting rid of any effects
  7913. void clif_refresh(struct map_session_data *sd)
  7914. {
  7915. nullpo_retv(sd);
  7916. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7917. clif_inventorylist(sd);
  7918. if(pc_iscarton(sd)) {
  7919. clif_cartlist(sd);
  7920. clif_updatestatus(sd,SP_CARTINFO);
  7921. }
  7922. clif_updatestatus(sd,SP_WEIGHT);
  7923. clif_updatestatus(sd,SP_MAXWEIGHT);
  7924. clif_updatestatus(sd,SP_STR);
  7925. clif_updatestatus(sd,SP_AGI);
  7926. clif_updatestatus(sd,SP_VIT);
  7927. clif_updatestatus(sd,SP_INT);
  7928. clif_updatestatus(sd,SP_DEX);
  7929. clif_updatestatus(sd,SP_LUK);
  7930. if (sd->spiritball)
  7931. clif_spiritball_single(sd->fd, sd);
  7932. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  7933. clif_spiritcharm_single(sd->fd, sd);
  7934. if (sd->vd.cloth_color)
  7935. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7936. if (sd->vd.body_style)
  7937. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7938. if(hom_is_active(sd->hd))
  7939. clif_send_homdata(sd,SP_ACK,0);
  7940. if( sd->md ) {
  7941. clif_mercenary_info(sd);
  7942. clif_mercenary_skillblock(sd);
  7943. }
  7944. if( sd->ed )
  7945. clif_elemental_info(sd);
  7946. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7947. clif_weather_check(sd);
  7948. if( sd->chatID )
  7949. chat_leavechat(sd,0);
  7950. if( sd->state.vending )
  7951. clif_openvending(sd, sd->bl.id, sd->vending);
  7952. if( pc_issit(sd) )
  7953. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7954. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7955. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7956. else
  7957. clif_changed_dir(&sd->bl, SELF);
  7958. clif_efst_status_change_sub(sd,&sd->bl,SELF);
  7959. // unlike vending, resuming buyingstore crashes the client.
  7960. buyingstore_close(sd);
  7961. mail_clear(sd);
  7962. if( disguised(&sd->bl) ) {/* refresh-da */
  7963. short disguise = sd->disguise;
  7964. pc_disguise(sd, 0);
  7965. pc_disguise(sd, disguise);
  7966. }
  7967. clif_refresh_storagewindow(sd);
  7968. }
  7969. /// Updates the object's (bl) name on client.
  7970. /// Used to update when a char leaves a party/guild. [Skotlex]
  7971. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7972. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7973. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7974. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  7975. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  7976. unsigned char buf[106];
  7977. int cmd = 0x95;
  7978. nullpo_retv(src);
  7979. nullpo_retv(bl);
  7980. WBUFW(buf,0) = cmd;
  7981. WBUFL(buf,2) = bl->id;
  7982. switch( bl->type )
  7983. {
  7984. case BL_PC:
  7985. {
  7986. struct map_session_data *sd = (struct map_session_data *)bl;
  7987. struct party_data *p = NULL;
  7988. #if PACKETVER >= 20150513
  7989. WBUFW(buf, 0) = cmd = 0xa30;
  7990. #else
  7991. WBUFW(buf, 0) = cmd = 0x195;
  7992. #endif
  7993. //Requesting your own "shadow" name. [Skotlex]
  7994. if( src == bl && target == SELF && sd->disguise ){
  7995. WBUFL(buf,2) = -bl->id;
  7996. }
  7997. if( sd->fakename[0] ) {
  7998. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  7999. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8000. #if PACKETVER >= 20150513
  8001. WBUFL(buf,102) = 0; // Title ID
  8002. #endif
  8003. break;
  8004. }
  8005. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8006. if( sd->status.party_id ){
  8007. p = party_search(sd->status.party_id);
  8008. }
  8009. // do not display party unless the player is also in a guild
  8010. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8011. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8012. }else{
  8013. WBUFB(buf,30) = 0;
  8014. }
  8015. if( sd->guild ){
  8016. int position;
  8017. // Will get the position of the guild the player is in
  8018. position = guild_getposition(sd);
  8019. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8020. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8021. }else{ //Assume no guild.
  8022. WBUFB(buf,54) = 0;
  8023. WBUFB(buf,78) = 0;
  8024. }
  8025. #if PACKETVER >= 20150513
  8026. WBUFL(buf,102) = 0; // Title ID
  8027. #endif
  8028. }
  8029. break;
  8030. //[blackhole89]
  8031. case BL_HOM:
  8032. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8033. break;
  8034. case BL_MER:
  8035. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8036. break;
  8037. case BL_PET:
  8038. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8039. break;
  8040. case BL_NPC:
  8041. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8042. break;
  8043. case BL_MOB:
  8044. {
  8045. struct mob_data *md = (struct mob_data *)bl;
  8046. nullpo_retv(md);
  8047. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8048. if( md->guardian_data && md->guardian_data->guild_id )
  8049. {
  8050. WBUFW(buf, 0) = cmd = 0x195;
  8051. WBUFB(buf,30) = 0;
  8052. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8053. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8054. }
  8055. else if( battle_config.show_mob_info )
  8056. {
  8057. char mobhp[50], *str_p = mobhp;
  8058. WBUFW(buf, 0) = cmd = 0x195;
  8059. if( battle_config.show_mob_info&4 )
  8060. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8061. if( battle_config.show_mob_info&1 )
  8062. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8063. if( battle_config.show_mob_info&2 )
  8064. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8065. //Even thought mobhp ain't a name, we send it as one so the client
  8066. //can parse it. [Skotlex]
  8067. if( str_p != mobhp )
  8068. {
  8069. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8070. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8071. WBUFB(buf,54) = 0;
  8072. WBUFB(buf,78) = 0;
  8073. }
  8074. }
  8075. }
  8076. break;
  8077. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8078. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8079. // break;
  8080. return;
  8081. case BL_ELEM:
  8082. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8083. break;
  8084. default:
  8085. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8086. return;
  8087. }
  8088. clif_send(buf, packet_len(cmd), src, target);
  8089. }
  8090. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8091. /// 01ff <id>.L <x>.W <y>.W
  8092. ///
  8093. /// Visually moves(instant) a character to x,y. The char moves even
  8094. /// when the target cell isn't walkable. If the char is sitting it
  8095. /// stays that way.
  8096. void clif_slide(struct block_list *bl, int x, int y)
  8097. {
  8098. unsigned char buf[10];
  8099. nullpo_retv(bl);
  8100. WBUFW(buf, 0) = 0x01ff;
  8101. WBUFL(buf, 2) = bl->id;
  8102. WBUFW(buf, 6) = x;
  8103. WBUFW(buf, 8) = y;
  8104. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8105. if( disguised(bl) )
  8106. {
  8107. WBUFL(buf,2) = -bl->id;
  8108. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8109. }
  8110. }
  8111. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8112. /// 008d <packet len>.W <id>.L <message>.?B
  8113. void clif_disp_overhead(struct block_list *bl, const char* mes)
  8114. {
  8115. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8116. int len_mes = strlen(mes)+1; //Account for \0
  8117. if (len_mes > sizeof(buf)-8) {
  8118. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8119. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8120. }
  8121. // send message to others
  8122. WBUFW(buf,0) = 0x8d;
  8123. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8124. WBUFL(buf,4) = bl->id;
  8125. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8126. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8127. // send back message to the speaker
  8128. if( bl->type == BL_PC ) {
  8129. WBUFW(buf,0) = 0x8e;
  8130. WBUFW(buf, 2) = len_mes + 4;
  8131. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8132. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8133. }
  8134. }
  8135. /*==========================
  8136. * Minimap fix [Kevin]
  8137. * Remove dot from minimap
  8138. *--------------------------*/
  8139. void clif_party_xy_remove(struct map_session_data *sd)
  8140. {
  8141. unsigned char buf[16];
  8142. nullpo_retv(sd);
  8143. WBUFW(buf,0)=0x107;
  8144. WBUFL(buf,2)=sd->status.account_id;
  8145. WBUFW(buf,6)=-1;
  8146. WBUFW(buf,8)=-1;
  8147. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8148. }
  8149. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8150. /// 0215 <msg id>.L
  8151. /// msg id:
  8152. /// 0x15 = End all negative status (PA_GOSPEL)
  8153. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8154. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8155. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8156. /// 0x19 = All stats +20 (PA_GOSPEL)
  8157. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8158. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8159. /// 0x1e = DEF +25% (PA_GOSPEL)
  8160. /// 0x1f = ATK +100% (PA_GOSPEL)
  8161. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8162. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8163. /// ? = nothing
  8164. void clif_gospel_info(struct map_session_data *sd, int type)
  8165. {
  8166. int fd=sd->fd;
  8167. WFIFOHEAD(fd,packet_len(0x215));
  8168. WFIFOW(fd,0)=0x215;
  8169. WFIFOL(fd,2)=type;
  8170. WFIFOSET(fd, packet_len(0x215));
  8171. }
  8172. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8173. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8174. /// result:
  8175. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8176. /// star:
  8177. /// 0 = Place of the Sun
  8178. /// 1 = Place of the Moon
  8179. /// 2 = Place of the Stars
  8180. /// 1 = Star Gladiator %s's %s: <mapname>
  8181. /// star:
  8182. /// 0 = Place of the Sun
  8183. /// 1 = Place of the Moon
  8184. /// 2 = Place of the Stars
  8185. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8186. /// star:
  8187. /// 0 = Target of the Sun
  8188. /// 1 = Target of the Moon
  8189. /// 2 = Target of the Stars
  8190. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8191. /// star:
  8192. /// 0 = Monster of the Sun
  8193. /// 1 = Monster of the Moon
  8194. /// 2 = Monster of the Stars
  8195. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8196. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8197. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8198. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8199. /// 40 = Target HP : <monster_id used as HP>
  8200. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8201. {
  8202. int fd = sd->fd;
  8203. WFIFOHEAD(fd,packet_len(0x20e));
  8204. WFIFOW(fd,0) = 0x20e;
  8205. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8206. WFIFOL(fd,26) = monster_id;
  8207. WFIFOB(fd,30) = star;
  8208. WFIFOB(fd,31) = result;
  8209. WFIFOSET(fd,packet_len(0x20e));
  8210. }
  8211. /*==========================================
  8212. * Info about Star Glaldiator save map [Komurka]
  8213. * type: 1: Information, 0: Map registered
  8214. *------------------------------------------*/
  8215. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8216. {
  8217. char mapname[MAP_NAME_LENGTH_EXT];
  8218. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8219. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8220. }
  8221. /*==========================================
  8222. * Info about Star Glaldiator hate mob [Komurka]
  8223. * type: 1: Register mob, 0: Information.
  8224. *------------------------------------------*/
  8225. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8226. {
  8227. if( pcdb_checkid(class_) ) {
  8228. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8229. } else if( mobdb_checkid(class_) ) {
  8230. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8231. } else {
  8232. 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);
  8233. }
  8234. }
  8235. /*==========================================
  8236. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8237. *------------------------------------------*/
  8238. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8239. {
  8240. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8241. }
  8242. /*==========================================
  8243. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8244. *------------------------------------------*/
  8245. void clif_feel_hate_reset(struct map_session_data *sd)
  8246. {
  8247. clif_starskill(sd, "", 0, 0, 30);
  8248. }
  8249. /// Equip window (un)tick ack (ZC_CONFIG).
  8250. /// 02d9 <type>.L <value>.L
  8251. /// type:
  8252. /// 0 = open equip window
  8253. /// value:
  8254. /// 0 = disabled
  8255. /// 1 = enabled
  8256. void clif_equiptickack(struct map_session_data* sd, int flag)
  8257. {
  8258. int fd;
  8259. nullpo_retv(sd);
  8260. fd = sd->fd;
  8261. WFIFOHEAD(fd, packet_len(0x2d9));
  8262. WFIFOW(fd, 0) = 0x2d9;
  8263. WFIFOL(fd, 2) = 0;
  8264. WFIFOL(fd, 6) = flag;
  8265. WFIFOSET(fd, packet_len(0x2d9));
  8266. }
  8267. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8268. /// 02da <open equip window>.B
  8269. /// open equip window:
  8270. /// 0 = disabled
  8271. /// 1 = enabled
  8272. void clif_equipcheckbox(struct map_session_data* sd)
  8273. {
  8274. int fd;
  8275. nullpo_retv(sd);
  8276. fd = sd->fd;
  8277. WFIFOHEAD(fd, packet_len(0x2da));
  8278. WFIFOW(fd, 0) = 0x2da;
  8279. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8280. WFIFOSET(fd, packet_len(0x2da));
  8281. }
  8282. /// Sends info about a player's equipped items.
  8283. /// 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)
  8284. /// 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)
  8285. /// 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)
  8286. /// 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)
  8287. /// 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)
  8288. /// 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)
  8289. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8290. {
  8291. uint8* buf;
  8292. int i, n, fd, offset = 0;
  8293. #if PACKETVER < 20100629
  8294. const int s = 26;
  8295. #elif PACKETVER < 20120925
  8296. const int s = 28;
  8297. #elif PACKETVER < 20150226
  8298. const int s = 31;
  8299. #else
  8300. const int s = 57;
  8301. #endif
  8302. nullpo_retv(sd);
  8303. nullpo_retv(tsd);
  8304. fd = sd->fd;
  8305. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8306. buf = WFIFOP(fd,0);
  8307. #if PACKETVER < 20101124
  8308. WBUFW(buf, 0) = 0x2d7;
  8309. #elif PACKETVER < 20120925
  8310. WBUFW(buf, 0) = 0x859;
  8311. #elif PACKETVER < 20150226
  8312. WBUFW(buf, 0) = 0x997;
  8313. #else
  8314. WBUFW(buf, 0) = 0xa2d;
  8315. #endif
  8316. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8317. WBUFW(buf,28) = tsd->status.class_;
  8318. WBUFW(buf,30) = tsd->vd.hair_style;
  8319. WBUFW(buf,32) = tsd->vd.head_bottom;
  8320. WBUFW(buf,34) = tsd->vd.head_mid;
  8321. WBUFW(buf,36) = tsd->vd.head_top;
  8322. #if PACKETVER >= 20110111
  8323. WBUFW(buf,38) = tsd->vd.robe;
  8324. offset+= 2;
  8325. buf = WBUFP(buf,2);
  8326. #endif
  8327. WBUFW(buf,38) = tsd->vd.hair_color;
  8328. WBUFW(buf,40) = tsd->vd.cloth_color;
  8329. WBUFB(buf,42) = tsd->vd.sex;
  8330. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8331. {
  8332. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8333. continue;
  8334. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8335. continue;
  8336. // Add item info : refine, identify flag, element, etc.
  8337. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8338. n++;
  8339. }
  8340. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8341. WFIFOSET(fd, WFIFOW(fd, 2));
  8342. }
  8343. /// Display msgstringtable.txt string (ZC_MSG).
  8344. /// 0291 <message>.W
  8345. void clif_msg(struct map_session_data* sd, unsigned short id)
  8346. {
  8347. int fd;
  8348. nullpo_retv(sd);
  8349. fd = sd->fd;
  8350. WFIFOHEAD(fd, packet_len(0x291));
  8351. WFIFOW(fd, 0) = 0x291;
  8352. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8353. WFIFOSET(fd, packet_len(0x291));
  8354. }
  8355. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8356. /// 0x7e2 <message>.W <value>.L
  8357. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8358. {
  8359. int fd = sd->fd;
  8360. WFIFOHEAD(fd, packet_len(0x7e2));
  8361. WFIFOW(fd,0) = 0x7e2;
  8362. WFIFOW(fd,2) = id;
  8363. WFIFOL(fd,4) = value;
  8364. WFIFOSET(fd, packet_len(0x7e2));
  8365. }
  8366. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8367. /// 07e6 <skill id>.W <msg id>.L
  8368. ///
  8369. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8370. /// "[SkillName] Message"
  8371. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8372. {
  8373. int fd = sd->fd;
  8374. WFIFOHEAD(fd, packet_len(0x7e6));
  8375. WFIFOW(fd,0) = 0x7e6;
  8376. WFIFOW(fd,2) = skill_id;
  8377. WFIFOL(fd,4) = msg_id;
  8378. WFIFOSET(fd, packet_len(0x7e6));
  8379. }
  8380. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8381. /// Returns true if the packet was parsed successfully.
  8382. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8383. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8384. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8385. char* seperator = " : ";
  8386. int fd;
  8387. struct s_packet_db* info;
  8388. uint16 packetLength, inputLength;
  8389. const char *input, *name, *message;
  8390. size_t nameLength, messageLength;
  8391. fd = sd->fd;
  8392. info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8393. packetLength = RFIFOW(fd,info->pos[0]);
  8394. input = RFIFOCP(fd,info->pos[1]);
  8395. // basic structure check for the 4-byte header
  8396. if( packetLength < 4 ){
  8397. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8398. return false;
  8399. }else{
  8400. inputLength = packetLength - 4;
  8401. }
  8402. // process <name> part of the packet
  8403. if( whisperFormat ) {
  8404. // name has fixed width
  8405. if( inputLength < NAME_LENGTH + 1 ) {
  8406. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8407. return false;
  8408. }
  8409. name = input;
  8410. // validate name
  8411. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8412. // only restriction is that the name must be zero-terminated
  8413. if( name[nameLength] != '\0' ) {
  8414. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8415. return false;
  8416. }
  8417. message = input + NAME_LENGTH;
  8418. messageLength = inputLength - NAME_LENGTH;
  8419. }else{
  8420. // name and message are separated by ' : '
  8421. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8422. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8423. // check if there's enough data provided
  8424. if( inputLength < nameLength + seperatorLength + 1 ){
  8425. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8426. return false;
  8427. }
  8428. name = input;
  8429. // validate name
  8430. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8431. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8432. {
  8433. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8434. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8435. set_eof(sd->fd); // Just kick them out to correct it.
  8436. return false;
  8437. }
  8438. message = input + nameLength + seperatorLength;
  8439. messageLength = inputLength - nameLength - seperatorLength;
  8440. }
  8441. #if PACKETVER < 20151001
  8442. // the declared length must match real length
  8443. if( messageLength != strnlen(message, messageLength)+1 ) {
  8444. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8445. return false;
  8446. }
  8447. // verify <message> part of the packet
  8448. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8449. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8450. return false;
  8451. }
  8452. #else
  8453. // No zero termination anymore
  8454. messageLength += 1;
  8455. #endif
  8456. // messages mustn't be too long
  8457. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8458. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8459. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8460. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8461. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8462. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8463. return false;
  8464. }
  8465. // If it is not a whisper message, set the name to the fakename of the player
  8466. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8467. strcpy( out_name, sd->fakename );
  8468. }else{
  8469. safestrncpy( out_name, name, nameLength + 1 );
  8470. }
  8471. safestrncpy( out_message, message, messageLength );
  8472. if( whisperFormat ){
  8473. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8474. out_full_message[nameLength] = '\0';
  8475. }else{
  8476. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8477. }
  8478. if( is_atcommand( fd, sd, out_message, 1 ) )
  8479. return false;
  8480. if (sd->sc.cant.chat)
  8481. return false; //no "chatting" while muted.
  8482. if( battle_config.min_chat_delay ) { //[Skotlex]
  8483. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8484. return false;
  8485. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8486. }
  8487. if (battle_config.idletime_option&IDLE_CHAT)
  8488. sd->idletime = last_tick;
  8489. return true;
  8490. }
  8491. // ---------------------
  8492. // clif_guess_PacketVer
  8493. // ---------------------
  8494. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8495. // error codes:
  8496. // 0 - Success
  8497. // 1 - Unknown packet_ver
  8498. // 2 - Invalid account_id
  8499. // 3 - Invalid char_id
  8500. // 4 - Invalid login_id1 (reserved)
  8501. // 5 - Invalid client_tick (reserved)
  8502. // 6 - Invalid sex
  8503. // Only the first 'invalid' error that appears is used.
  8504. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8505. {
  8506. static int err = 1;
  8507. static int packet_ver = -1;
  8508. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8509. unsigned short cmd;
  8510. if (get_previous)
  8511. {//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]
  8512. if( error )
  8513. *error = err;
  8514. return packet_ver;
  8515. }
  8516. //By default, start searching on the default one.
  8517. err = 1;
  8518. packet_ver = clif_config.packet_db_ver;
  8519. cmd = clif_parse_cmd(fd, NULL);
  8520. packet_len = RFIFOREST(fd);
  8521. #define SET_ERROR(n) \
  8522. if( err == 1 )\
  8523. err = n;\
  8524. //define SET_ERROR
  8525. // FIXME: If the packet is not received at once, this will FAIL.
  8526. // Figure out, when it happens, that only part of the packet is
  8527. // received, or fix the function to be able to deal with that
  8528. // case.
  8529. #define CHECK_PACKET_VER() \
  8530. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8531. ;/* not wanttoconnection or wrong length */\
  8532. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8533. { SET_ERROR(2); }/* invalid account_id */\
  8534. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8535. { SET_ERROR(3); }/* invalid char_id */\
  8536. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8537. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8538. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8539. { SET_ERROR(6); }/* invalid sex */\
  8540. else\
  8541. {\
  8542. err = 0;\
  8543. if( error )\
  8544. *error = 0;\
  8545. return packet_ver;\
  8546. }\
  8547. //define CHECK_PACKET_VER
  8548. CHECK_PACKET_VER();//Default packet version found.
  8549. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8550. CHECK_PACKET_VER();
  8551. }
  8552. if( error )
  8553. *error = err;
  8554. packet_ver = -1;
  8555. return -1;
  8556. #undef SET_ERROR
  8557. #undef CHECK_PACKET_VER
  8558. }
  8559. // ------------
  8560. // clif_parse_*
  8561. // ------------
  8562. // Parses incoming (player) connection
  8563. /// Request to connect to map-server.
  8564. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8565. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8566. /// There are various variants of this packet, some of them have padding between fields.
  8567. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8568. {
  8569. struct block_list* bl;
  8570. struct auth_node* node;
  8571. int cmd, account_id, char_id, login_id1, sex;
  8572. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8573. 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])
  8574. if (sd) {
  8575. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8576. return;
  8577. }
  8578. // Only valid packet version get here
  8579. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8580. cmd = RFIFOW(fd,0);
  8581. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8582. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8583. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8584. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8585. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8586. if( packet_ver < 5 || // reject really old client versions
  8587. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8588. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8589. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8590. {// packet version rejected
  8591. 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));
  8592. WFIFOHEAD(fd,packet_len(0x6a));
  8593. WFIFOW(fd,0) = 0x6a;
  8594. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8595. WFIFOSET(fd,packet_len(0x6a));
  8596. set_eof(fd);
  8597. return;
  8598. }
  8599. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8600. clif_authfail_fd(fd,1);// server closed
  8601. return;
  8602. }
  8603. //Check for double login.
  8604. bl = map_id2bl(account_id);
  8605. if(bl && bl->type != BL_PC) {
  8606. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8607. WFIFOHEAD(fd,packet_len(0x6a));
  8608. WFIFOW(fd,0) = 0x6a;
  8609. WFIFOB(fd,2) = 3; // Rejected by server
  8610. WFIFOSET(fd,packet_len(0x6a));
  8611. set_eof(fd);
  8612. return;
  8613. }
  8614. if (bl ||
  8615. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8616. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8617. {
  8618. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8619. return;
  8620. }
  8621. CREATE(sd, TBL_PC, 1);
  8622. sd->fd = fd;
  8623. sd->packet_ver = packet_ver;
  8624. #ifdef PACKET_OBFUSCATION
  8625. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8626. #endif
  8627. session[fd]->session_data = sd;
  8628. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8629. #if PACKETVER < 20070521
  8630. WFIFOHEAD(fd,4);
  8631. WFIFOL(fd,0) = sd->bl.id;
  8632. WFIFOSET(fd,4);
  8633. #else
  8634. WFIFOHEAD(fd,packet_len(0x283));
  8635. WFIFOW(fd,0) = 0x283;
  8636. WFIFOL(fd,2) = sd->bl.id;
  8637. WFIFOSET(fd,packet_len(0x283));
  8638. #endif
  8639. chrif_authreq(sd,false);
  8640. }
  8641. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8642. /// 007d
  8643. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8644. {
  8645. bool guild_notice = false;
  8646. if(sd->bl.prev != NULL)
  8647. return;
  8648. if (!sd->state.active) { //Character loading is not complete yet!
  8649. //Let pc_reg_received reinvoke this when ready.
  8650. sd->state.connect_new = 0;
  8651. return;
  8652. }
  8653. if (sd->state.rewarp) { //Rewarp player.
  8654. sd->state.rewarp = 0;
  8655. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8656. return;
  8657. }
  8658. sd->state.warping = 0;
  8659. // look
  8660. #if PACKETVER < 4
  8661. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8662. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8663. #else
  8664. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8665. #endif
  8666. pc_set_costume_view(sd);
  8667. if(sd->vd.cloth_color)
  8668. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8669. if(sd->vd.body_style)
  8670. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8671. // item
  8672. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8673. pc_checkitem(sd);
  8674. // cart
  8675. if(pc_iscarton(sd)) {
  8676. clif_cartlist(sd);
  8677. clif_updatestatus(sd,SP_CARTINFO);
  8678. }
  8679. // weight
  8680. clif_updatestatus(sd,SP_WEIGHT);
  8681. clif_updatestatus(sd,SP_MAXWEIGHT);
  8682. // guild
  8683. // (needs to go before clif_spawn() to show guild emblems correctly)
  8684. if(sd->status.guild_id)
  8685. guild_send_memberinfoshort(sd,1);
  8686. if(battle_config.pc_invincible_time > 0) {
  8687. if(map_flag_gvg(sd->bl.m))
  8688. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8689. else
  8690. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8691. }
  8692. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8693. map_spawnmobs(sd->bl.m);
  8694. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8695. map[sd->bl.m].users_pvp++;
  8696. }
  8697. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8698. // reset the callshop flag if the player changes map
  8699. sd->state.callshop = 0;
  8700. if(map_addblock(&sd->bl))
  8701. return;
  8702. clif_spawn(&sd->bl);
  8703. // Party
  8704. // (needs to go after clif_spawn() to show hp bars correctly)
  8705. if(sd->status.party_id) {
  8706. party_send_movemap(sd);
  8707. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8708. }
  8709. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8710. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8711. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8712. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8713. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8714. sd->pvp_rank = 0;
  8715. sd->pvp_lastusers = 0;
  8716. sd->pvp_point = 5;
  8717. sd->pvp_won = 0;
  8718. sd->pvp_lost = 0;
  8719. }
  8720. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8721. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8722. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8723. else if (map[sd->bl.m].flag.gvg_dungeon)
  8724. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8725. else if( map_flag_gvg(sd->bl.m) )
  8726. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8727. else
  8728. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8729. // info about nearby objects
  8730. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8731. 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);
  8732. // pet
  8733. if( sd->pd ) {
  8734. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8735. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8736. pet_menu(sd, 3); //Option 3 is return to egg.
  8737. } else {
  8738. if(map_addblock(&sd->pd->bl))
  8739. return;
  8740. clif_spawn(&sd->pd->bl);
  8741. clif_send_petdata(sd,sd->pd,0,0);
  8742. clif_send_petstatus(sd);
  8743. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8744. }
  8745. }
  8746. //homunculus [blackhole89]
  8747. if( hom_is_active(sd->hd) ) {
  8748. if(map_addblock(&sd->hd->bl))
  8749. return;
  8750. clif_spawn(&sd->hd->bl);
  8751. clif_send_homdata(sd,SP_ACK,0);
  8752. clif_hominfo(sd,sd->hd,1);
  8753. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8754. clif_homskillinfoblock(sd);
  8755. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8756. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8757. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8758. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8759. }
  8760. if( sd->md ) {
  8761. if(map_addblock(&sd->md->bl))
  8762. return;
  8763. clif_spawn(&sd->md->bl);
  8764. clif_mercenary_info(sd);
  8765. clif_mercenary_skillblock(sd);
  8766. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8767. }
  8768. if( sd->ed ) {
  8769. if (map_addblock(&sd->ed->bl))
  8770. return;
  8771. clif_spawn(&sd->ed->bl);
  8772. clif_elemental_info(sd);
  8773. clif_elemental_updatestatus(sd,SP_HP);
  8774. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8775. clif_elemental_updatestatus(sd,SP_SP);
  8776. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8777. }
  8778. if(sd->state.connect_new) {
  8779. int lv;
  8780. guild_notice = true;
  8781. clif_skillinfoblock(sd);
  8782. clif_hotkeys_send(sd);
  8783. clif_updatestatus(sd,SP_BASEEXP);
  8784. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8785. clif_updatestatus(sd,SP_JOBEXP);
  8786. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8787. clif_updatestatus(sd,SP_SKILLPOINT);
  8788. clif_initialstatus(sd);
  8789. if (sd->sc.option&OPTION_FALCON)
  8790. clif_status_load(&sd->bl, SI_FALCON, 1);
  8791. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8792. clif_status_load(&sd->bl, SI_RIDING, 1);
  8793. else if (sd->sc.option&OPTION_WUGRIDER)
  8794. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8795. else if (sd->sc.data[SC_ALL_RIDING])
  8796. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8797. if(sd->status.manner < 0)
  8798. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8799. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8800. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8801. if(sd->bl.m == sd->feel_map[0].m
  8802. || sd->bl.m == sd->feel_map[1].m
  8803. || sd->bl.m == sd->feel_map[2].m)
  8804. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8805. }
  8806. if(sd->pd && sd->pd->pet.intimate > 900)
  8807. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8808. if(hom_is_active(sd->hd))
  8809. hom_init_timers(sd->hd);
  8810. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8811. sd->state.night = 1;
  8812. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8813. }
  8814. // Notify everyone that this char logged in [Skotlex].
  8815. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8816. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8817. //Login Event
  8818. npc_script_event(sd, NPCE_LOGIN);
  8819. }
  8820. } else {
  8821. //For some reason the client "loses" these on warp/map-change.
  8822. clif_updatestatus(sd,SP_STR);
  8823. clif_updatestatus(sd,SP_AGI);
  8824. clif_updatestatus(sd,SP_VIT);
  8825. clif_updatestatus(sd,SP_INT);
  8826. clif_updatestatus(sd,SP_DEX);
  8827. clif_updatestatus(sd,SP_LUK);
  8828. // abort currently running script
  8829. sd->state.using_fake_npc = 0;
  8830. sd->state.menu_or_input = 0;
  8831. sd->npc_menu = 0;
  8832. if(sd->npc_id)
  8833. npc_event_dequeue(sd);
  8834. }
  8835. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8836. #if PACKETVER >= 20070918
  8837. clif_partyinvitationstate(sd);
  8838. clif_equipcheckbox(sd);
  8839. #endif
  8840. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8841. clif_guild_notice(sd); // Displays after VIP
  8842. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8843. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8844. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8845. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8846. { //Display night.
  8847. if( !sd->state.night )
  8848. {
  8849. sd->state.night = 1;
  8850. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8851. }
  8852. }
  8853. else if( sd->state.night )
  8854. { //Clear night display.
  8855. sd->state.night = 0;
  8856. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8857. }
  8858. if( map[sd->bl.m].flag.battleground )
  8859. {
  8860. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8861. if( map[sd->bl.m].flag.battleground == 2 )
  8862. clif_bg_updatescore_single(sd);
  8863. }
  8864. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8865. {
  8866. char output[128];
  8867. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8868. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8869. }
  8870. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8871. map[sd->bl.m].hpmeter_visible++;
  8872. sd->state.hpmeter_visible = 1;
  8873. }
  8874. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  8875. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8876. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8877. #ifdef VIP_ENABLE
  8878. if (!sd->state.connect_new &&
  8879. !sd->vip.disableshowrate &&
  8880. sd->state.pmap != sd->bl.m &&
  8881. map[sd->state.pmap].adjust.bexp != map[sd->bl.m].adjust.bexp
  8882. )
  8883. {
  8884. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8885. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8886. }
  8887. #endif
  8888. // Instances do not need their own channels
  8889. if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8890. channel_mjoin(sd); //join new map
  8891. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8892. clif_guild_notice(sd); // Displays at end
  8893. mail_clear(sd);
  8894. /* Guild Aura Init */
  8895. if( sd->state.gmaster_flag ) {
  8896. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8897. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8898. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8899. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8900. }
  8901. if( sd->state.vending ) { /* show we have a vending */
  8902. clif_openvending(sd,sd->bl.id,sd->vending);
  8903. clif_showvendingboard(&sd->bl,sd->message,0);
  8904. }
  8905. // Don't trigger NPC event or opening vending/buyingstore will be failed
  8906. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  8907. npc_script_event(sd, NPCE_LOADMAP);
  8908. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  8909. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8910. if (sd->sc.opt2) //Client loses these on warp.
  8911. clif_changeoption(&sd->bl);
  8912. if ((sd->sc.data[SC_MONSTER_TRANSFORM] || sd->sc.data[SC_ACTIVE_MONSTER_TRANSFORM]) && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8913. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8914. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  8915. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8916. }
  8917. clif_weather_check(sd);
  8918. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8919. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8920. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8921. else
  8922. sd->areanpc_id = 0;
  8923. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8924. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8925. pc_setdead(sd);
  8926. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8927. if(pc_isdead(sd))
  8928. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8929. else {
  8930. skill_usave_trigger(sd);
  8931. if (battle_config.spawn_direction)
  8932. clif_changed_dir(&sd->bl, SELF);
  8933. }
  8934. // Trigger skill effects if you appear standing on them
  8935. if(!battle_config.pc_invincible_time)
  8936. skill_unit_move(&sd->bl,gettick(),1);
  8937. pc_show_questinfo_reinit(sd);
  8938. pc_show_questinfo(sd);
  8939. sd->state.connect_new = 0;
  8940. sd->state.changemap = false;
  8941. }
  8942. /// Server's tick (ZC_NOTIFY_TIME).
  8943. /// 007f <time>.L
  8944. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8945. {
  8946. int fd = sd->fd;
  8947. WFIFOHEAD(fd,packet_len(0x7f));
  8948. WFIFOW(fd,0) = 0x7f;
  8949. WFIFOL(fd,2) = time;
  8950. WFIFOSET(fd,packet_len(0x7f));
  8951. }
  8952. /// Request for server's tick.
  8953. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8954. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8955. /// There are various variants of this packet, some of them have padding between fields.
  8956. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8957. {
  8958. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8959. clif_notify_time(sd, gettick());
  8960. }
  8961. /// Sends hotkey bar.
  8962. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8963. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8964. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8965. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8966. void clif_hotkeys_send(struct map_session_data *sd) {
  8967. #ifdef HOTKEY_SAVING
  8968. const int fd = sd->fd;
  8969. int i;
  8970. int offset = 2;
  8971. #if PACKETVER < 20090603
  8972. const int cmd = 0x2b9;
  8973. #elif PACKETVER < 20141022
  8974. const int cmd = 0x7d9;
  8975. #else
  8976. char Rotate = sd->status.hotkey_rowshift;
  8977. const int cmd = 0xa00;
  8978. offset = 3;
  8979. #endif
  8980. if (!fd) return;
  8981. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  8982. WFIFOW(fd, 0) = cmd;
  8983. #if PACKETVER >= 20141022
  8984. WFIFOB(fd, 2) = Rotate;
  8985. #endif
  8986. for(i = 0; i < MAX_HOTKEYS; i++) {
  8987. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8988. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8989. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  8990. }
  8991. WFIFOSET(fd, packet_len(cmd));
  8992. #endif
  8993. }
  8994. /// Request to update a position on the hotkey row bar
  8995. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  8996. int cmd = RFIFOW(fd, 0);
  8997. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8998. }
  8999. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9000. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9001. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9002. #ifdef HOTKEY_SAVING
  9003. unsigned short idx;
  9004. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9005. idx = RFIFOW(fd, info->pos[0]);
  9006. if (idx >= MAX_HOTKEYS) return;
  9007. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9008. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9009. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9010. #endif
  9011. }
  9012. /// Displays cast-like progress bar (ZC_PROGRESS).
  9013. /// 02f0 <color>.L <time>.L
  9014. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9015. {
  9016. int fd = sd->fd;
  9017. WFIFOHEAD(fd,packet_len(0x2f0));
  9018. WFIFOW(fd,0) = 0x2f0;
  9019. WFIFOL(fd,2) = color;
  9020. WFIFOL(fd,6) = second;
  9021. WFIFOSET(fd,packet_len(0x2f0));
  9022. }
  9023. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9024. /// 02f2
  9025. void clif_progressbar_abort(struct map_session_data * sd)
  9026. {
  9027. int fd = sd->fd;
  9028. WFIFOHEAD(fd,packet_len(0x2f2));
  9029. WFIFOW(fd,0) = 0x2f2;
  9030. WFIFOSET(fd,packet_len(0x2f2));
  9031. }
  9032. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9033. /// 02f1
  9034. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9035. {
  9036. int npc_id = sd->progressbar.npc_id;
  9037. if( gettick() < sd->progressbar.timeout && sd->st )
  9038. sd->st->state = END;
  9039. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9040. sd->state.workinprogress = WIP_DISABLE_NONE;
  9041. npc_scriptcont(sd, npc_id, false);
  9042. }
  9043. /// Request to walk to a certain position on the current map.
  9044. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9045. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9046. /// There are various variants of this packet, some of them have padding between fields.
  9047. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9048. {
  9049. short x, y;
  9050. if (pc_isdead(sd)) {
  9051. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9052. return;
  9053. }
  9054. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9055. ; //You CAN walk on this OPT1 value.
  9056. else if (sd->progressbar.npc_id) {
  9057. clif_progressbar_abort(sd);
  9058. return; // First walk attempt cancels the progress bar
  9059. } else if (pc_cant_act(sd))
  9060. return;
  9061. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9062. return;
  9063. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9064. //A move command one cell west is only valid if the target cell is free
  9065. if(battle_config.official_cell_stack_limit > 0
  9066. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9067. return;
  9068. // Cloaking wall check is actually updated when you click to process next movement
  9069. // not when you move each cell. This is official behaviour.
  9070. if (sd->sc.data[SC_CLOAKING])
  9071. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9072. pc_delinvincibletimer(sd);
  9073. //Set last idle time... [Skotlex]
  9074. if (battle_config.idletime_option&IDLE_WALK)
  9075. sd->idletime = last_tick;
  9076. unit_walktoxy(&sd->bl, x, y, 4);
  9077. }
  9078. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9079. /// 018b <result>.W
  9080. /// result:
  9081. /// 0 = disconnect (quit)
  9082. /// 1 = cannot disconnect (wait 10 seconds)
  9083. /// ? = ignored
  9084. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9085. {
  9086. int fd = sd->fd;
  9087. WFIFOHEAD(fd,packet_len(0x18b));
  9088. WFIFOW(fd,0) = 0x18b;
  9089. WFIFOW(fd,2) = result;
  9090. WFIFOSET(fd,packet_len(0x18b));
  9091. }
  9092. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9093. /// 018a <type>.W
  9094. /// type:
  9095. /// 0 = quit
  9096. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9097. {
  9098. /* Rovert's prevent logout option fixed [Valaris] */
  9099. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9100. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9101. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9102. {
  9103. set_eof(fd);
  9104. pc_damage_log_clear(sd,0);
  9105. clif_disconnect_ack(sd, 0);
  9106. } else {
  9107. clif_disconnect_ack(sd, 1);
  9108. }
  9109. }
  9110. /// Requesting unit's name.
  9111. /// 0094 <id>.L (CZ_REQNAME)
  9112. /// 0368 <id>.L (CZ_REQNAME2)
  9113. /// There are various variants of this packet, some of them have padding between fields.
  9114. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9115. {
  9116. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9117. struct block_list* bl;
  9118. //struct status_change *sc;
  9119. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9120. id = sd->bl.id;
  9121. bl = map_id2bl(id);
  9122. if( bl == NULL )
  9123. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9124. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9125. return; // Block namerequests past view range
  9126. // 'see people in GM hide' cheat detection
  9127. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9128. sc = status_get_sc(bl);
  9129. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9130. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9131. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9132. ) {
  9133. char gm_msg[256];
  9134. 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);
  9135. ShowWarning(gm_msg);
  9136. // information is sent to all online GMs
  9137. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9138. return;
  9139. }
  9140. */
  9141. clif_name(&sd->bl,bl,SELF);
  9142. }
  9143. /// Validates and processes global messages
  9144. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9145. /// There are various variants of this packet.
  9146. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9147. {
  9148. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9149. size_t length;
  9150. // validate packet and retrieve name and message
  9151. if( !clif_process_message(sd, false, name, message, output ) )
  9152. return;
  9153. if( sd->gcbind ) {
  9154. channel_send(sd->gcbind,sd,message);
  9155. return;
  9156. }
  9157. // send message to others (using the send buffer for temp. storage)
  9158. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9159. length = strlen(output) + 1;
  9160. // send back message to the speaker
  9161. WFIFOHEAD(fd,4+length);
  9162. WFIFOW(fd,0) = 0x8e;
  9163. WFIFOW(fd,2) = (uint16)(4+length);
  9164. safestrncpy(WFIFOCP(fd,4), output, length );
  9165. WFIFOSET(fd, WFIFOW(fd,2));
  9166. #ifdef PCRE_SUPPORT
  9167. // trigger listening npcs
  9168. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9169. #endif
  9170. // Chat logging type 'O' / Global Chat
  9171. 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);
  9172. }
  9173. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9174. /// Request to warp to a map on given coordinates.
  9175. /// 0140 <map name>.16B <x>.W <y>.W
  9176. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9177. {
  9178. char command[MAP_NAME_LENGTH_EXT+25];
  9179. char* map_name;
  9180. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9181. map_name = RFIFOCP(fd,info->pos[0]);
  9182. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9183. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9184. RFIFOW(fd,info->pos[1]), //x
  9185. RFIFOW(fd,info->pos[2])); //y
  9186. is_atcommand(fd, sd, command, 1);
  9187. }
  9188. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9189. /// 009c <id>.L <head dir>.W <dir>.B
  9190. /// head dir:
  9191. /// 0 = straight
  9192. /// 1 = turned CW
  9193. /// 2 = turned CCW
  9194. /// dir:
  9195. /// 0 = north
  9196. /// 1 = northwest
  9197. /// 2 = west
  9198. /// 3 = southwest
  9199. /// 4 = south
  9200. /// 5 = southeast
  9201. /// 6 = east
  9202. /// 7 = northeast
  9203. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9204. {
  9205. unsigned char buf[64];
  9206. WBUFW(buf,0) = 0x9c;
  9207. WBUFL(buf,2) = bl->id;
  9208. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9209. WBUFB(buf,8) = unit_getdir(bl);
  9210. clif_send(buf, packet_len(0x9c), bl, target);
  9211. if (disguised(bl)) {
  9212. WBUFL(buf,2) = -bl->id;
  9213. WBUFW(buf,6) = 0;
  9214. clif_send(buf, packet_len(0x9c), bl, SELF);
  9215. }
  9216. }
  9217. /// Request to change own body and head direction.
  9218. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9219. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9220. /// There are various variants of this packet, some of them have padding between fields.
  9221. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9222. {
  9223. unsigned char headdir, dir;
  9224. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9225. headdir = RFIFOB(fd,info->pos[0]);
  9226. dir = RFIFOB(fd,info->pos[1]);
  9227. pc_setdir(sd, dir, headdir);
  9228. clif_changed_dir(&sd->bl, AREA_WOS);
  9229. }
  9230. /// Request to show an emotion (CZ_REQ_EMOTION).
  9231. /// 00bf <type>.B
  9232. /// type:
  9233. /// @see enum emotion_type
  9234. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9235. {
  9236. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9237. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9238. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9239. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9240. return;
  9241. }
  9242. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9243. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9244. sd->emotionlasttime = time(NULL);
  9245. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9246. return;
  9247. }
  9248. sd->emotionlasttime = time(NULL);
  9249. if (battle_config.idletime_option&IDLE_EMOTION)
  9250. sd->idletime = last_tick;
  9251. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9252. emoticon = rnd()%6+E_DICE1;
  9253. }
  9254. clif_emotion(&sd->bl, emoticon);
  9255. } else
  9256. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9257. }
  9258. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9259. /// 00c2 <count>.L
  9260. void clif_user_count(struct map_session_data* sd, int count)
  9261. {
  9262. int fd = sd->fd;
  9263. WFIFOHEAD(fd,packet_len(0xc2));
  9264. WFIFOW(fd,0) = 0xc2;
  9265. WFIFOL(fd,2) = count;
  9266. WFIFOSET(fd,packet_len(0xc2));
  9267. }
  9268. /// /w /who (CZ_REQ_USER_COUNT).
  9269. /// Request to display amount of currently connected players.
  9270. /// 00c1
  9271. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9272. {
  9273. clif_user_count(sd, map_getusers());
  9274. }
  9275. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9276. {
  9277. if (pc_isdead(sd)) {
  9278. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9279. return;
  9280. }
  9281. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9282. // (not all are included in pc_can_attack)
  9283. if (sd->sc.count &&
  9284. (sd->sc.data[SC_TRICKDEAD] ||
  9285. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9286. sd->sc.data[SC_BLADESTOP] ||
  9287. sd->sc.data[SC__MANHOLE] ||
  9288. sd->sc.data[SC_SUHIDE] ))
  9289. return;
  9290. if(action_type != 0x00 && action_type != 0x07)
  9291. pc_stop_walking(sd, 1);
  9292. pc_stop_attack(sd);
  9293. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9294. target_id = sd->bl.id;
  9295. switch(action_type)
  9296. {
  9297. case 0x00: // once attack
  9298. case 0x07: // continuous attack
  9299. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9300. return;
  9301. if( sd->sc.option&OPTION_COSTUME )
  9302. return;
  9303. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9304. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9305. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9306. return;
  9307. }
  9308. }
  9309. pc_delinvincibletimer(sd);
  9310. if (battle_config.idletime_option&IDLE_ATTACK)
  9311. sd->idletime = last_tick;
  9312. unit_attack(&sd->bl, target_id, action_type != 0);
  9313. break;
  9314. case 0x02: // sitdown
  9315. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9316. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9317. break;
  9318. }
  9319. if(pc_issit(sd)) {
  9320. //Bugged client? Just refresh them.
  9321. clif_sitting(&sd->bl);
  9322. return;
  9323. }
  9324. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9325. break;
  9326. if (sd->sc.count && (
  9327. sd->sc.data[SC_DANCING] ||
  9328. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9329. )) //No sitting during these states either.
  9330. break;
  9331. if (battle_config.idletime_option&IDLE_SIT)
  9332. sd->idletime = last_tick;
  9333. pc_setsit(sd);
  9334. skill_sit(sd, 1);
  9335. clif_sitting(&sd->bl);
  9336. break;
  9337. case 0x03: // standup
  9338. if (!pc_issit(sd)) {
  9339. //Bugged client? Just refresh them.
  9340. clif_standing(&sd->bl);
  9341. return;
  9342. }
  9343. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9344. break;
  9345. if (pc_setstand(sd, false)) {
  9346. if (battle_config.idletime_option&IDLE_SIT)
  9347. sd->idletime = last_tick;
  9348. skill_sit(sd, 0);
  9349. clif_standing(&sd->bl);
  9350. }
  9351. break;
  9352. }
  9353. }
  9354. /// Request for an action.
  9355. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9356. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9357. /// action:
  9358. /// 0 = attack
  9359. /// 1 = pick up item
  9360. /// 2 = sit down
  9361. /// 3 = stand up
  9362. /// 7 = continous attack
  9363. /// 12 = (touch skill?)
  9364. /// There are various variants of this packet, some of them have padding between fields.
  9365. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9366. {
  9367. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9368. clif_parse_ActionRequest_sub(sd,
  9369. RFIFOB(fd,info->pos[1]),
  9370. RFIFOL(fd,info->pos[0]),
  9371. gettick()
  9372. );
  9373. }
  9374. /// Response to the death/system menu (CZ_RESTART).
  9375. /// 00b2 <type>.B
  9376. /// type:
  9377. /// 0 = restart (respawn)
  9378. /// 1 = char-select (disconnect)
  9379. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9380. {
  9381. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  9382. case 0x00:
  9383. pc_respawn(sd,CLR_OUTSIGHT);
  9384. break;
  9385. case 0x01:
  9386. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9387. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9388. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9389. { //Send to char-server for character selection.
  9390. pc_damage_log_clear(sd,0);
  9391. chrif_charselectreq(sd, session[fd]->client_addr);
  9392. } else {
  9393. clif_disconnect_ack(sd, 1);
  9394. }
  9395. break;
  9396. }
  9397. }
  9398. /// Validates and processes whispered messages (CZ_WHISPER).
  9399. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9400. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9401. {
  9402. struct map_session_data* dstsd;
  9403. int i;
  9404. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9405. // validate packet and retrieve name and message
  9406. if( !clif_process_message( sd, true, target, message, output ) )
  9407. return;
  9408. // Chat logging type 'W' / Whisper
  9409. 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);
  9410. //-------------------------------------------------------//
  9411. // Lordalfa - Paperboy - To whisper NPC commands //
  9412. //-------------------------------------------------------//
  9413. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9414. {
  9415. char* str = target+4; //Skip the NPC: string part.
  9416. struct npc_data* npc;
  9417. if ((npc = npc_name2id(str))) {
  9418. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9419. char *split;
  9420. char event[EVENT_NAME_LENGTH];
  9421. str = message;
  9422. // skip codepage indicator, if detected
  9423. if( str[0] == '|' && strlen(str) >= 4 )
  9424. str += 3;
  9425. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9426. split = strchr(str,'#');
  9427. if( split == NULL ) { // use the remaining string
  9428. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9429. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9430. split_data[i][0] = '\0';
  9431. break;
  9432. }
  9433. *split = '\0';
  9434. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9435. str = split+1;
  9436. }
  9437. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9438. char variablename[CHAT_SIZE_MAX];
  9439. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9440. set_var(sd,variablename,(char *) split_data[i]);
  9441. }
  9442. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9443. npc_event(sd,event,0); // Calls the NPC label
  9444. return;
  9445. }
  9446. } else if( target[0] == '#' ) {
  9447. struct Channel *channel = NULL;
  9448. char* chname = target;
  9449. channel = channel_name2channel(chname,sd,3);
  9450. if(channel){
  9451. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9452. channel_send(channel,sd,message);
  9453. }
  9454. else if( channel->pass[0] == '\0') { //no pass needed
  9455. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9456. }
  9457. else {
  9458. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9459. }
  9460. return;
  9461. }
  9462. }
  9463. // searching destination character
  9464. dstsd = map_nick2sd(target);
  9465. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9466. // player is not on this map-server
  9467. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9468. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9469. // and if we ask for 'Test', we must not contact 'test' player
  9470. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9471. intif_wis_message(sd, target, message, strlen(message));
  9472. return;
  9473. }
  9474. // if player ignores everyone
  9475. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9476. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9477. clif_wis_end(fd, 1); // 1: target character is not logged in
  9478. else
  9479. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9480. return;
  9481. }
  9482. // if player is autotrading
  9483. if (dstsd->state.autotrade == 1){
  9484. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9485. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9486. return;
  9487. }
  9488. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9489. // if player ignores the source character
  9490. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9491. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9492. clif_wis_end(fd, 2); // 2: ignored by target
  9493. return;
  9494. }
  9495. }
  9496. // notify sender of success
  9497. clif_wis_end(fd, 0); // 0: success to send wisper
  9498. // Normal message
  9499. clif_wis_message(dstsd->fd, sd->status.name, message, strlen(message)+1 );
  9500. }
  9501. /// /b /nb (CZ_BROADCAST).
  9502. /// Request to broadcast a message on whole server.
  9503. /// 0099 <packet len>.W <text>.?B 00
  9504. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9505. char command[CHAT_SIZE_MAX+11];
  9506. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9507. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9508. char* msg = RFIFOCP(fd,info->pos[1]);
  9509. // as the length varies depending on the command used, just block unreasonably long strings
  9510. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9511. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9512. is_atcommand(fd, sd, command, 1);
  9513. }
  9514. /// Request to pick up an item.
  9515. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9516. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9517. /// There are various variants of this packet, some of them have padding between fields.
  9518. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9519. {
  9520. struct flooritem_data *fitem;
  9521. int map_object_id;
  9522. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9523. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9524. do {
  9525. if (pc_isdead(sd)) {
  9526. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9527. break;
  9528. }
  9529. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9530. break;
  9531. if (pc_cant_act(sd))
  9532. break;
  9533. if (!pc_takeitem(sd, fitem))
  9534. break;
  9535. return;
  9536. } while (0);
  9537. // Client REQUIRES a fail packet or you can no longer pick items.
  9538. clif_additem(sd,0,0,6);
  9539. }
  9540. /// Request to drop an item.
  9541. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9542. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9543. /// There are various variants of this packet, some of them have padding between fields.
  9544. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9545. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9546. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9547. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9548. for(;;) {
  9549. if (pc_isdead(sd))
  9550. break;
  9551. if (pc_cant_act2(sd) || sd->npc_id)
  9552. break;
  9553. if (sd->sc.count && (
  9554. sd->sc.data[SC_AUTOCOUNTER] ||
  9555. sd->sc.data[SC_BLADESTOP] ||
  9556. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9557. ))
  9558. break;
  9559. if (!pc_dropitem(sd, item_index, item_amount))
  9560. break;
  9561. if (battle_config.idletime_option&IDLE_DROPITEM)
  9562. sd->idletime = last_tick;
  9563. return;
  9564. }
  9565. //Because the client does not like being ignored.
  9566. clif_dropitem(sd, item_index,0);
  9567. }
  9568. /// Request to use an item.
  9569. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9570. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9571. /// There are various variants of this packet, some of them have padding between fields.
  9572. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9573. {
  9574. int n;
  9575. if (pc_isdead(sd)) {
  9576. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9577. return;
  9578. }
  9579. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9580. return;
  9581. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9582. if (battle_config.idletime_option&IDLE_USEITEM)
  9583. sd->idletime = last_tick;
  9584. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9585. if(n <0 || n >= MAX_INVENTORY)
  9586. return;
  9587. if (!pc_useitem(sd,n))
  9588. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9589. }
  9590. /// Request to equip an item
  9591. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9592. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9593. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9594. {
  9595. int index;
  9596. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9597. if(pc_isdead(sd)) {
  9598. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9599. return;
  9600. }
  9601. index = RFIFOW(fd,info->pos[0])-2;
  9602. if (index < 0 || index >= MAX_INVENTORY)
  9603. return; //Out of bounds check.
  9604. if(sd->npc_id && !sd->npc_item_flag) {
  9605. return;
  9606. } else if (sd->state.storage_flag || sd->sc.opt1)
  9607. ; //You can equip/unequip stuff while storage is open/under status changes
  9608. else if (pc_cant_act2(sd))
  9609. return;
  9610. if(!sd->status.inventory[index].identify) {
  9611. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9612. return;
  9613. }
  9614. if(!sd->inventory_data[index])
  9615. return;
  9616. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9617. pet_equipitem(sd,index);
  9618. return;
  9619. }
  9620. if (battle_config.idletime_option&IDLE_USEITEM)
  9621. sd->idletime = last_tick;
  9622. //Client doesn't send the position for ammo.
  9623. if(sd->inventory_data[index]->type == IT_AMMO)
  9624. pc_equipitem(sd,index,EQP_AMMO);
  9625. else {
  9626. int req_pos;
  9627. #if PACKETVER >= 20120925
  9628. req_pos = RFIFOL(fd,info->pos[1]);
  9629. #else
  9630. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9631. #endif
  9632. pc_equipitem(sd,index,req_pos);
  9633. }
  9634. }
  9635. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9636. /// 00ab <index>.W
  9637. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9638. {
  9639. int index;
  9640. if(pc_isdead(sd)) {
  9641. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9642. return;
  9643. }
  9644. if (sd->npc_id && !sd->npc_item_flag) {
  9645. return;
  9646. } else if (sd->state.storage_flag || sd->sc.opt1)
  9647. ; //You can equip/unequip stuff while storage is open/under status changes
  9648. else if (pc_cant_act2(sd))
  9649. return;
  9650. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9651. if (battle_config.idletime_option&IDLE_USEITEM)
  9652. sd->idletime = last_tick;
  9653. pc_unequipitem(sd,index,1);
  9654. }
  9655. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9656. /// 0090 <id>.L <type>.B
  9657. /// type:
  9658. /// 1 = click
  9659. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9660. {
  9661. struct block_list *bl;
  9662. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9663. if(pc_isdead(sd)) {
  9664. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9665. return;
  9666. }
  9667. #ifdef RENEWAL
  9668. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_NPC)) {
  9669. clif_msg(sd, WORK_IN_PROGRESS);
  9670. return;
  9671. }
  9672. #endif
  9673. if (pc_cant_act2(sd) || sd->npc_id)
  9674. return;
  9675. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9676. //type = RFIFOB(fd,info->pos[1]);
  9677. if (!bl) return;
  9678. switch (bl->type) {
  9679. case BL_MOB:
  9680. case BL_PC:
  9681. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9682. break;
  9683. case BL_NPC:
  9684. #ifdef RENEWAL
  9685. if (sd->ud.skill_id < RK_ENCHANTBLADE && sd->ud.skilltimer != INVALID_TIMER) { // Should only show an error message for non-3rd job skills with a running timer
  9686. clif_msg(sd, WORK_IN_PROGRESS);
  9687. break;
  9688. }
  9689. #endif
  9690. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9691. npc_click(sd,(TBL_NPC*)bl);
  9692. break;
  9693. }
  9694. }
  9695. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9696. /// 00c5 <id>.L <type>.B
  9697. /// type:
  9698. /// 0 = buy
  9699. /// 1 = sell
  9700. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9701. {
  9702. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9703. if (sd->state.trading)
  9704. return;
  9705. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9706. }
  9707. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9708. /// 00ca <result>.B
  9709. /// result:
  9710. /// 0 = "The deal has successfully completed."
  9711. /// 1 = "You do not have enough zeny."
  9712. /// 2 = "You are over your Weight Limit."
  9713. /// 3 = "Out of the maximum capacity, you have too many items."
  9714. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9715. {
  9716. int fd = sd->fd;
  9717. WFIFOHEAD(fd,packet_len(0xca));
  9718. WFIFOW(fd,0) = 0xca;
  9719. WFIFOB(fd,2) = result;
  9720. WFIFOSET(fd,packet_len(0xca));
  9721. }
  9722. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9723. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9724. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9725. {
  9726. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9727. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9728. int result;
  9729. if( sd->state.trading || !sd->npc_shopid )
  9730. result = 1;
  9731. else
  9732. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9733. sd->npc_shopid = 0; //Clear shop data.
  9734. clif_npc_buy_result(sd, result);
  9735. }
  9736. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9737. /// 00cb <result>.B
  9738. /// result:
  9739. /// 0 = "The deal has successfully completed."
  9740. /// 1 = "The deal has failed."
  9741. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9742. {
  9743. int fd = sd->fd;
  9744. WFIFOHEAD(fd,packet_len(0xcb));
  9745. WFIFOW(fd,0) = 0xcb;
  9746. WFIFOB(fd,2) = result;
  9747. WFIFOSET(fd,packet_len(0xcb));
  9748. }
  9749. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9750. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9751. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9752. {
  9753. int fail=0,n;
  9754. unsigned short *item_list;
  9755. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9756. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9757. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9758. if (sd->state.trading || !sd->npc_shopid)
  9759. fail = 1;
  9760. else
  9761. fail = npc_selllist(sd,n,item_list);
  9762. sd->npc_shopid = 0; //Clear shop data.
  9763. clif_npc_sell_result(sd, fail);
  9764. }
  9765. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9766. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9767. /// type:
  9768. /// 0 = private
  9769. /// 1 = public
  9770. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9771. {
  9772. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9773. int len = RFIFOW(fd,info->pos[0])-15;
  9774. int limit = RFIFOW(fd,info->pos[1]);
  9775. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9776. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  9777. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  9778. char s_password[CHATROOM_PASS_SIZE];
  9779. char s_title[CHATROOM_TITLE_SIZE];
  9780. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9781. return;
  9782. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9783. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9784. return;
  9785. }
  9786. if( npc_isnear(&sd->bl) ) {
  9787. // uncomment to send msg_txt.
  9788. //char output[150];
  9789. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9790. //clif_displaymessage(sd->fd, output);
  9791. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9792. return;
  9793. }
  9794. if( len <= 0 )
  9795. return; // invalid input
  9796. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9797. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9798. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9799. }
  9800. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9801. /// 00d9 <chat ID>.L <passwd>.8B
  9802. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9803. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9804. int chatid = RFIFOL(fd,info->pos[0]);
  9805. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  9806. chat_joinchat(sd,chatid,password);
  9807. }
  9808. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9809. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9810. /// type:
  9811. /// 0 = private
  9812. /// 1 = public
  9813. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9814. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9815. int len = RFIFOW(fd,info->pos[0])-15;
  9816. int limit = RFIFOW(fd,info->pos[1]);
  9817. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9818. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  9819. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  9820. char s_password[CHATROOM_PASS_SIZE];
  9821. char s_title[CHATROOM_TITLE_SIZE];
  9822. if( len <= 0 )
  9823. return; // invalid input
  9824. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9825. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9826. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9827. }
  9828. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9829. /// 00e0 <role>.L <nick>.24B
  9830. /// role:
  9831. /// 0 = owner
  9832. /// 1 = normal
  9833. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9834. {
  9835. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9836. chat_changechatowner(sd,RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9837. }
  9838. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9839. /// 00e2 <name>.24B
  9840. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9841. {
  9842. chat_kickchat(sd,RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9843. }
  9844. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9845. /// 00e3
  9846. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9847. {
  9848. chat_leavechat(sd,0);
  9849. }
  9850. //Handles notifying asker and rejecter of what has just ocurred.
  9851. //Type is used to determine the correct msg_txt to use:
  9852. //0:
  9853. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9854. {
  9855. const char* msg;
  9856. char output[256];
  9857. // Your request has been rejected by autoreject option.
  9858. msg = msg_txt(sd,392);
  9859. clif_disp_onlyself(sd, msg, strlen(msg));
  9860. //Notice that a request was rejected.
  9861. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9862. clif_disp_onlyself(tsd, output, strlen(output));
  9863. }
  9864. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9865. /// 00e4 <account id>.L
  9866. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9867. {
  9868. struct map_session_data *t_sd;
  9869. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9870. if(!sd->chatID && pc_cant_act(sd))
  9871. return; //You can trade while in a chatroom.
  9872. // @noask [LuzZza]
  9873. if(t_sd && t_sd->state.noask) {
  9874. clif_noask_sub(sd, t_sd, 0);
  9875. return;
  9876. }
  9877. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9878. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9879. return;
  9880. }
  9881. trade_traderequest(sd,t_sd);
  9882. }
  9883. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9884. /// 00e6 <result>.B
  9885. /// result:
  9886. /// 3 = accepted
  9887. /// 4 = rejected
  9888. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9889. {
  9890. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9891. }
  9892. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9893. /// 00e8 <index>.W <amount>.L
  9894. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9895. {
  9896. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9897. short index = RFIFOW(fd,info->pos[0]);
  9898. int amount = RFIFOL(fd,info->pos[1]);
  9899. if( index == 0 )
  9900. trade_tradeaddzeny(sd, amount);
  9901. else
  9902. trade_tradeadditem(sd, index, (short)amount);
  9903. }
  9904. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9905. /// 00eb
  9906. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9907. {
  9908. trade_tradeok(sd);
  9909. }
  9910. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9911. /// 00ed
  9912. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9913. {
  9914. trade_tradecancel(sd);
  9915. }
  9916. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9917. /// 00ef
  9918. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9919. {
  9920. trade_tradecommit(sd);
  9921. }
  9922. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9923. /// 0118
  9924. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9925. {
  9926. pc_stop_attack(sd);
  9927. if (sd) sd->ud.state.attack_continue = 0;
  9928. }
  9929. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9930. /// 0126 <index>.W <amount>.L
  9931. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9932. {
  9933. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9934. if (pc_istrading(sd))
  9935. return;
  9936. if (!pc_iscarton(sd))
  9937. return;
  9938. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9939. }
  9940. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9941. /// 0127 <index>.W <amount>.L
  9942. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9943. {
  9944. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9945. if (!pc_iscarton(sd))
  9946. return;
  9947. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9948. }
  9949. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9950. /// 012a
  9951. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9952. {
  9953. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9954. #ifdef NEW_CARTS
  9955. && sd->sc.data[SC_PUSH_CART] )
  9956. pc_setcart(sd,0);
  9957. #else
  9958. )
  9959. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9960. #endif
  9961. else // priority to remove this option before we can clear cart
  9962. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9963. }
  9964. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  9965. /// 097f <Length>.W <identity>.L <type>.B
  9966. void clif_SelectCart(struct map_session_data *sd) {
  9967. #if PACKETVER >= 20150826
  9968. int i = 0, carts = 3;
  9969. int fd = sd->fd;
  9970. WFIFOHEAD(fd,8 + carts);
  9971. WFIFOW(fd,0) = 0x97f;
  9972. WFIFOW(fd,2) = 8 + carts;
  9973. WFIFOL(fd,4) = sd->status.account_id;
  9974. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  9975. for( i = 0; i < carts; i++ ) {
  9976. WFIFOB(fd,8 + i) = 10 + i;
  9977. }
  9978. WFIFOSET(fd,8 + carts);
  9979. #endif
  9980. }
  9981. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  9982. /// 0980 <identity>.L <type>.B
  9983. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  9984. #if PACKETVER >= 20150826
  9985. int type;
  9986. // Check identity
  9987. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  9988. return;
  9989. type = (int)RFIFOB(fd,6);
  9990. // Check type
  9991. if( type < 10 || type > MAX_CARTS )
  9992. return;
  9993. pc_setcart(sd, type);
  9994. #endif
  9995. }
  9996. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9997. /// 01af <num>.W
  9998. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9999. {// TODO: State tracking?
  10000. int type;
  10001. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10002. return;
  10003. #ifdef RENEWAL
  10004. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10005. clif_msg(sd, WORK_IN_PROGRESS);
  10006. return;
  10007. }
  10008. #endif
  10009. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10010. if(
  10011. #ifdef NEW_CARTS
  10012. (type == 9 && sd->status.base_level > 130) ||
  10013. (type == 8 && sd->status.base_level > 120) ||
  10014. (type == 7 && sd->status.base_level > 110) ||
  10015. (type == 6 && sd->status.base_level > 100) ||
  10016. #endif
  10017. (type == 5 && sd->status.base_level > 90) ||
  10018. (type == 4 && sd->status.base_level > 80) ||
  10019. (type == 3 && sd->status.base_level > 65) ||
  10020. (type == 2 && sd->status.base_level > 40) ||
  10021. (type == 1))
  10022. pc_setcart(sd, type);
  10023. }
  10024. /// Request to increase status (CZ_STATUS_CHANGE).
  10025. /// 00bb <status id>.W <amount>.B
  10026. /// status id:
  10027. /// SP_STR ~ SP_LUK
  10028. /// amount:
  10029. /// Old clients always send 1 for this, even when using /str+ and the like.
  10030. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10031. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10032. {
  10033. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10034. if( increase_amount < 0 ) {
  10035. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10036. fd, increase_amount);
  10037. }
  10038. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  10039. }
  10040. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10041. /// 0112 <skill id>.W
  10042. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10043. {
  10044. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10045. }
  10046. 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)
  10047. {
  10048. int lv;
  10049. if( !hd )
  10050. return;
  10051. if( skill_isNotOk_hom(skill_id, hd) ) {
  10052. clif_emotion(&hd->bl, E_DOTS);
  10053. return;
  10054. }
  10055. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10056. target_id = hd->bl.id;
  10057. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10058. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10059. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10060. clif_emotion(&hd->bl, E_DOTS);
  10061. if (hd->master)
  10062. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10063. return;
  10064. }
  10065. lv = hom_checkskill(hd, skill_id);
  10066. if( skill_lv > lv )
  10067. skill_lv = lv;
  10068. if( skill_lv )
  10069. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10070. }
  10071. 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)
  10072. {
  10073. int lv;
  10074. if( !hd )
  10075. return;
  10076. if( skill_isNotOk_hom(skill_id, hd) ) {
  10077. clif_emotion(&hd->bl, E_DOTS);
  10078. return;
  10079. }
  10080. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10081. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10082. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10083. clif_emotion(&hd->bl, E_DOTS);
  10084. if (hd->master)
  10085. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10086. return;
  10087. }
  10088. if( hd->sc.data[SC_BASILICA] )
  10089. return;
  10090. lv = hom_checkskill(hd, skill_id);
  10091. if( skill_lv > lv )
  10092. skill_lv = lv;
  10093. if( skill_lv )
  10094. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10095. }
  10096. 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)
  10097. {
  10098. int lv;
  10099. if( !md )
  10100. return;
  10101. if( skill_isNotOk_mercenary(skill_id, md) )
  10102. return;
  10103. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10104. target_id = md->bl.id;
  10105. if( md->ud.skilltimer != INVALID_TIMER )
  10106. {
  10107. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10108. }
  10109. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10110. return;
  10111. lv = mercenary_checkskill(md, skill_id);
  10112. if( skill_lv > lv )
  10113. skill_lv = lv;
  10114. if( skill_lv )
  10115. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10116. }
  10117. 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)
  10118. {
  10119. int lv;
  10120. if( !md )
  10121. return;
  10122. if( skill_isNotOk_mercenary(skill_id, md) )
  10123. return;
  10124. if( md->ud.skilltimer != INVALID_TIMER )
  10125. return;
  10126. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10127. {
  10128. if (md->master)
  10129. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10130. return;
  10131. }
  10132. if( md->sc.data[SC_BASILICA] )
  10133. return;
  10134. lv = mercenary_checkskill(md, skill_id);
  10135. if( skill_lv > lv )
  10136. skill_lv = lv;
  10137. if( skill_lv )
  10138. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10139. }
  10140. /// Request to use a targeted skill.
  10141. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10142. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10143. /// There are various variants of this packet, some of them have padding between fields.
  10144. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10145. {
  10146. uint16 skill_id, skill_lv;
  10147. int inf,target_id;
  10148. unsigned int tick = gettick();
  10149. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10150. skill_lv = RFIFOW(fd,info->pos[0]);
  10151. skill_id = RFIFOW(fd,info->pos[1]);
  10152. target_id = RFIFOL(fd,info->pos[2]);
  10153. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10154. inf = skill_get_inf(skill_id);
  10155. if (inf&INF_GROUND_SKILL || !inf)
  10156. return; //Using a ground/passive skill on a target? WRONG.
  10157. if( SKILL_CHK_HOMUN(skill_id) ) {
  10158. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10159. return;
  10160. }
  10161. if( SKILL_CHK_MERC(skill_id) ) {
  10162. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10163. return;
  10164. }
  10165. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10166. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10167. sd->idletime = last_tick;
  10168. if (sd->npc_id) {
  10169. #ifdef RENEWAL
  10170. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10171. clif_msg(sd, WORK_IN_PROGRESS);
  10172. return;
  10173. }
  10174. #else
  10175. if (!sd->npc_item_flag || !(inf&INF_SELF_SKILL))
  10176. return;
  10177. #endif
  10178. }
  10179. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10180. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10181. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10182. return;
  10183. if( pc_issit(sd) )
  10184. return;
  10185. if( skill_isNotOk(skill_id, sd) )
  10186. return;
  10187. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10188. target_id = sd->bl.id; // never trust the client
  10189. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10190. target_id = sd->bl.id;
  10191. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10192. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10193. return;
  10194. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10195. if( sd->skillitem != skill_id ) {
  10196. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10197. return;
  10198. }
  10199. }
  10200. if( sd->sc.option&OPTION_COSTUME )
  10201. return;
  10202. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10203. return; // On basilica only caster can use Basilica again to stop it.
  10204. if( sd->menuskill_id ) {
  10205. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10206. clif_menuskill_clear(sd); //Cancel pet capture.
  10207. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10208. return; //Can't use skills while a menu is open.
  10209. }
  10210. if( sd->skillitem == skill_id ) {
  10211. if( skill_lv != sd->skillitemlv )
  10212. skill_lv = sd->skillitemlv;
  10213. if( !(inf&INF_SELF_SKILL) )
  10214. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10215. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10216. return;
  10217. }
  10218. sd->skillitem = sd->skillitemlv = 0;
  10219. if( SKILL_CHK_GUILD(skill_id) ) {
  10220. if( sd->state.gmaster_flag )
  10221. skill_lv = guild_checkskill(sd->guild, skill_id);
  10222. else
  10223. skill_lv = 0;
  10224. } else {
  10225. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10226. }
  10227. pc_delinvincibletimer(sd);
  10228. if( skill_lv )
  10229. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10230. }
  10231. /*==========================================
  10232. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10233. *------------------------------------------*/
  10234. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10235. {
  10236. unsigned int tick = gettick();
  10237. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10238. return; //Using a target skill on the ground? WRONG.
  10239. if( SKILL_CHK_HOMUN(skill_id) ) {
  10240. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10241. return;
  10242. }
  10243. if( SKILL_CHK_MERC(skill_id) ) {
  10244. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10245. return;
  10246. }
  10247. #ifdef RENEWAL
  10248. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10249. clif_msg(sd, WORK_IN_PROGRESS);
  10250. return;
  10251. }
  10252. #endif
  10253. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10254. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10255. sd->idletime = last_tick;
  10256. if( skill_isNotOk(skill_id, sd) )
  10257. return;
  10258. if( skillmoreinfo != -1 ) {
  10259. if( pc_issit(sd) ) {
  10260. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10261. return;
  10262. }
  10263. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10264. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10265. }
  10266. if( sd->ud.skilltimer != INVALID_TIMER )
  10267. return;
  10268. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10269. if( sd->skillitem != skill_id ) {
  10270. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10271. return;
  10272. }
  10273. }
  10274. if( sd->sc.option&OPTION_COSTUME )
  10275. return;
  10276. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10277. return; // On basilica only caster can use Basilica again to stop it.
  10278. if( sd->menuskill_id ) {
  10279. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10280. clif_menuskill_clear(sd); //Cancel pet capture.
  10281. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10282. return; //Can't use skills while a menu is open.
  10283. }
  10284. pc_delinvincibletimer(sd);
  10285. if( sd->skillitem == skill_id ) {
  10286. if( skill_lv != sd->skillitemlv )
  10287. skill_lv = sd->skillitemlv;
  10288. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10289. } else {
  10290. int lv;
  10291. sd->skillitem = sd->skillitemlv = 0;
  10292. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10293. if( skill_lv > lv )
  10294. skill_lv = lv;
  10295. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10296. }
  10297. }
  10298. }
  10299. /// Request to use a ground skill.
  10300. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10301. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10302. /// There are various variants of this packet, some of them have padding between fields.
  10303. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10304. {
  10305. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10306. if (pc_cant_act(sd))
  10307. return;
  10308. if (pc_issit(sd))
  10309. return;
  10310. clif_parse_UseSkillToPosSub(fd, sd,
  10311. RFIFOW(fd,info->pos[0]), //skill lv
  10312. RFIFOW(fd,info->pos[1]), //skill num
  10313. RFIFOW(fd,info->pos[2]), //pos x
  10314. RFIFOW(fd,info->pos[3]), //pos y
  10315. -1 //Skill more info.
  10316. );
  10317. }
  10318. /// Request to use a ground skill with text.
  10319. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10320. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10321. /// There are various variants of this packet, some of them have padding between fields.
  10322. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10323. {
  10324. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10325. if (pc_cant_act(sd))
  10326. return;
  10327. if (pc_issit(sd))
  10328. return;
  10329. clif_parse_UseSkillToPosSub(fd, sd,
  10330. RFIFOW(fd,info->pos[0]), //Skill lv
  10331. RFIFOW(fd,info->pos[1]), //Skill num
  10332. RFIFOW(fd,info->pos[2]), //pos x
  10333. RFIFOW(fd,info->pos[3]), //pos y
  10334. info->pos[4] //skill more info
  10335. );
  10336. }
  10337. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10338. /// 011b <skill id>.W <map name>.16B
  10339. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10340. {
  10341. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10342. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10343. char map_name[MAP_NAME_LENGTH];
  10344. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10345. sd->state.workinprogress = WIP_DISABLE_NONE;
  10346. if(skill_id != sd->menuskill_id)
  10347. return;
  10348. //It is possible to use teleport with the storage window open bugreport:8027
  10349. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10350. clif_menuskill_clear(sd);
  10351. return;
  10352. }
  10353. pc_delinvincibletimer(sd);
  10354. skill_castend_map(sd,skill_id,map_name);
  10355. }
  10356. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10357. /// 011d
  10358. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10359. {
  10360. if (!pc_isdead(sd))
  10361. pc_memo(sd,-1);
  10362. }
  10363. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10364. /// 018e <name id>.W { <material id>.W }*3
  10365. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10366. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10367. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10368. int slot1 = RFIFOW(fd,info->pos[1]);
  10369. int slot2 = RFIFOW(fd,info->pos[2]);
  10370. int slot3 = RFIFOW(fd,info->pos[3]);
  10371. short produce_idx = -1;
  10372. switch( sd->menuskill_id ) {
  10373. case -1:
  10374. case AM_PHARMACY:
  10375. case RK_RUNEMASTERY:
  10376. case GC_RESEARCHNEWPOISON:
  10377. break;
  10378. default:
  10379. return;
  10380. }
  10381. if (pc_istrading(sd)) {
  10382. //Make it fail to avoid shop exploits where you sell something different than you see.
  10383. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10384. clif_menuskill_clear(sd);
  10385. return;
  10386. }
  10387. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10388. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10389. clif_menuskill_clear(sd);
  10390. }
  10391. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10392. /// 025b <mk type>.W <name id>.W
  10393. /// mk type:
  10394. /// 1 = cooking
  10395. /// 2 = arrow
  10396. /// 3 = elemental
  10397. /// 4 = GN_MIX_COOKING
  10398. /// 5 = GN_MAKEBOMB
  10399. /// 6 = GN_S_PHARMACY
  10400. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10401. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10402. int type = RFIFOW(fd,info->pos[0]);
  10403. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10404. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10405. short food_idx = -1;
  10406. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10407. return;
  10408. if (pc_istrading(sd)) {
  10409. //Make it fail to avoid shop exploits where you sell something different than you see.
  10410. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10411. clif_menuskill_clear(sd);
  10412. return;
  10413. }
  10414. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10415. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10416. clif_menuskill_clear(sd);
  10417. }
  10418. /// Answer to repair weapon item selection dialog
  10419. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10420. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10421. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10422. {
  10423. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10424. return;
  10425. if (pc_istrading(sd)) {
  10426. //Make it fail to avoid shop exploits where you sell something different than you see.
  10427. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10428. clif_menuskill_clear(sd);
  10429. return;
  10430. }
  10431. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10432. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10433. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10434. //for(i = 0; i<MAX_SLOTS; i++)
  10435. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  10436. clif_menuskill_clear(sd);
  10437. }
  10438. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10439. /// 0222 <index>.L
  10440. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10441. {
  10442. int idx;
  10443. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10444. return;
  10445. if (pc_istrading(sd)) {
  10446. //Make it fail to avoid shop exploits where you sell something different than you see.
  10447. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10448. clif_menuskill_clear(sd);
  10449. return;
  10450. }
  10451. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10452. skill_weaponrefine(sd, idx-2);
  10453. clif_menuskill_clear(sd);
  10454. }
  10455. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10456. /// 00b8 <npc id>.L <choice>.B
  10457. /// choice:
  10458. /// 1~254 = menu item
  10459. /// 255 = cancel
  10460. /// NOTE: If there were more than 254 items in the list, choice
  10461. /// overflows to choice%256.
  10462. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10463. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10464. int npc_id = RFIFOL(fd,info->pos[0]);
  10465. uint8 select = RFIFOB(fd,info->pos[1]);
  10466. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10467. #ifdef SECURE_NPCTIMEOUT
  10468. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10469. #endif
  10470. TBL_NPC* nd = map_id2nd(npc_id);
  10471. 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);
  10472. clif_GM_kick(NULL,sd);
  10473. #ifdef SECURE_NPCTIMEOUT
  10474. }
  10475. #endif
  10476. return;
  10477. }
  10478. sd->npc_menu = select;
  10479. npc_scriptcont(sd,npc_id, false);
  10480. }
  10481. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10482. /// 00b9 <npc id>.L
  10483. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10484. {
  10485. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  10486. }
  10487. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10488. /// 0143 <npc id>.L <value>.L
  10489. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10490. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10491. int npcid = RFIFOL(fd,info->pos[0]);
  10492. int amount = (int)RFIFOL(fd,info->pos[1]);
  10493. sd->npc_amount = amount;
  10494. npc_scriptcont(sd, npcid, false);
  10495. }
  10496. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10497. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10498. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10499. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10500. int message_len = RFIFOW(fd,info->pos[0])-8;
  10501. int npcid = RFIFOL(fd,info->pos[1]);
  10502. const char* message = RFIFOCP(fd,info->pos[2]);
  10503. if( message_len <= 0 )
  10504. return; // invalid input
  10505. #if PACKETVER >= 20151001
  10506. message_len++;
  10507. #endif
  10508. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10509. npc_scriptcont(sd, npcid, false);
  10510. }
  10511. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10512. /// 0146 <npc id>.L
  10513. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10514. {
  10515. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10516. return;
  10517. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10518. }
  10519. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10520. /// 0178 <index>.W
  10521. /// index:
  10522. /// -1 = cancel
  10523. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10524. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2;
  10525. if (sd->menuskill_id != MC_IDENTIFY)
  10526. return;
  10527. // Ignore the request
  10528. // - Invalid item index
  10529. // - Invalid item ID or item doesn't exist
  10530. // - Item is already identified
  10531. if (idx < 0 || idx >= MAX_INVENTORY ||
  10532. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10533. sd->status.inventory[idx].identify) {// cancel pressed
  10534. sd->state.workinprogress = WIP_DISABLE_NONE;
  10535. clif_menuskill_clear(sd);
  10536. return;
  10537. }
  10538. skill_identify(sd, idx);
  10539. clif_menuskill_clear(sd);
  10540. }
  10541. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10542. /// 01ae <name id>.W
  10543. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10544. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10545. if (pc_istrading(sd)) {
  10546. //Make it fail to avoid shop exploits where you sell something different than you see.
  10547. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10548. clif_menuskill_clear(sd);
  10549. return;
  10550. }
  10551. switch (sd->menuskill_id) {
  10552. case AC_MAKINGARROW:
  10553. skill_arrow_create(sd,nameid);
  10554. break;
  10555. case SA_CREATECON:
  10556. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10557. break;
  10558. case WL_READING_SB:
  10559. skill_spellbook(sd,nameid);
  10560. break;
  10561. case GC_POISONINGWEAPON:
  10562. skill_poisoningweapon(sd,nameid);
  10563. break;
  10564. case NC_MAGICDECOY:
  10565. skill_magicdecoy(sd,nameid);
  10566. break;
  10567. }
  10568. clif_menuskill_clear(sd);
  10569. }
  10570. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10571. /// 01ce <skill id>.L
  10572. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10573. {
  10574. if (sd->menuskill_id != SA_AUTOSPELL)
  10575. return;
  10576. sd->state.workinprogress = WIP_DISABLE_NONE;
  10577. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10578. clif_menuskill_clear(sd);
  10579. }
  10580. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10581. /// 017a <card index>.W
  10582. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10583. {
  10584. if (sd->state.trading != 0)
  10585. return;
  10586. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10587. }
  10588. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10589. /// 017c <card index>.W <equip index>.W
  10590. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10591. {
  10592. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10593. if (sd->state.trading != 0)
  10594. return;
  10595. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10596. }
  10597. /// Request of character's name by char ID.
  10598. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10599. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10600. /// There are various variants of this packet, some of them have padding between fields.
  10601. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10602. {
  10603. int charid;
  10604. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10605. map_reqnickdb(sd, charid);
  10606. }
  10607. /// /resetskill /resetstate (CZ_RESET).
  10608. /// Request to reset stats or skills.
  10609. /// 0197 <type>.W
  10610. /// type:
  10611. /// 0 = state
  10612. /// 1 = skill
  10613. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10614. char cmd[15];
  10615. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10616. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10617. else
  10618. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10619. is_atcommand(fd, sd, cmd, 1);
  10620. }
  10621. /// /lb /nlb (CZ_LOCALBROADCAST).
  10622. /// Request to broadcast a message on current map.
  10623. /// 019c <packet len>.W <text>.?B
  10624. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10625. {
  10626. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10627. char command[CHAT_SIZE_MAX+16];
  10628. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10629. char* msg = RFIFOCP(fd,info->pos[1]);
  10630. // as the length varies depending on the command used, just block unreasonably long strings
  10631. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10632. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10633. is_atcommand(fd, sd, command, 1);
  10634. }
  10635. /// Request to move an item from inventory to storage.
  10636. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10637. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10638. /// There are various variants of this packet, some of them have padding between fields.
  10639. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10640. {
  10641. int item_index, item_amount;
  10642. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10643. if (pc_istrading(sd))
  10644. return;
  10645. item_index = RFIFOW(fd,info->pos[0])-2;
  10646. item_amount = RFIFOL(fd,info->pos[1]);
  10647. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10648. return;
  10649. if (sd->state.storage_flag == 1)
  10650. storage_storageadd(sd, item_index, item_amount);
  10651. else
  10652. if (sd->state.storage_flag == 2)
  10653. gstorage_storageadd(sd, item_index, item_amount);
  10654. }
  10655. /// Request to move an item from storage to inventory.
  10656. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10657. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10658. /// There are various variants of this packet, some of them have padding between fields.
  10659. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10660. {
  10661. int item_index, item_amount;
  10662. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10663. item_index = RFIFOW(fd,info->pos[0])-1;
  10664. item_amount = RFIFOL(fd,info->pos[1]);
  10665. if (sd->state.storage_flag == 1)
  10666. storage_storageget(sd, item_index, item_amount);
  10667. else if(sd->state.storage_flag == 2)
  10668. gstorage_storageget(sd, item_index, item_amount);
  10669. }
  10670. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10671. /// 0129 <index>.W <amount>.L
  10672. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10673. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10674. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10675. int amount = RFIFOL(fd,info->pos[1]);
  10676. if( sd->state.vending )
  10677. return;
  10678. if (!pc_iscarton(sd))
  10679. return;
  10680. if (sd->state.storage_flag == 1)
  10681. storage_storageaddfromcart(sd, idx, amount);
  10682. else if (sd->state.storage_flag == 2)
  10683. gstorage_storageaddfromcart(sd, idx, amount);
  10684. }
  10685. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10686. /// 0128 <index>.W <amount>.L
  10687. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10688. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10689. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10690. int amount = RFIFOL(fd,info->pos[1]);
  10691. if( sd->state.vending )
  10692. return;
  10693. if (!pc_iscarton(sd))
  10694. return;
  10695. if (sd->state.storage_flag == 1)
  10696. storage_storagegettocart(sd, idx, amount);
  10697. else
  10698. if (sd->state.storage_flag == 2)
  10699. gstorage_storagegettocart(sd, idx, amount);
  10700. }
  10701. /// Request to close storage (CZ_CLOSE_STORE).
  10702. /// 00f7
  10703. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10704. {
  10705. if( sd->state.storage_flag == 1 )
  10706. storage_storageclose(sd);
  10707. else
  10708. if( sd->state.storage_flag == 2 )
  10709. gstorage_storageclose(sd);
  10710. }
  10711. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10712. /// 023a <info>.W
  10713. /// info:
  10714. /// 0 = password has not been set yet
  10715. /// 1 = storage is password-protected
  10716. /// 8 = too many wrong passwords
  10717. /// ? = ignored
  10718. /// NOTE: This packet is only available on certain non-kRO clients.
  10719. void clif_storagepassword(struct map_session_data* sd, short info)
  10720. {
  10721. int fd = sd->fd;
  10722. WFIFOHEAD(fd,packet_len(0x23a));
  10723. WFIFOW(fd,0) = 0x23a;
  10724. WFIFOW(fd,2) = info;
  10725. WFIFOSET(fd,packet_len(0x23a));
  10726. }
  10727. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10728. /// 023b <type>.W <password>.16B <new password>.16B
  10729. /// type:
  10730. /// 2 = change password
  10731. /// 3 = check password
  10732. /// NOTE: This packet is only available on certain non-kRO clients.
  10733. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10734. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10735. // int type = RFIFOW(fd,info->pos[0]);
  10736. // char* password = RFIFOP(fd,info->pos[1]);
  10737. // char* new_password = RFIFOP(fd,info->pos[2]);
  10738. // storage_changepass(sd,password,new_password);
  10739. }
  10740. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10741. /// 023c <result>.W <error count>.W
  10742. /// result:
  10743. /// 4 = password change success
  10744. /// 5 = password change failure
  10745. /// 6 = password check success
  10746. /// 7 = password check failure
  10747. /// 8 = too many wrong passwords
  10748. /// ? = ignored
  10749. /// NOTE: This packet is only available on certain non-kRO clients.
  10750. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10751. {
  10752. int fd = sd->fd;
  10753. WFIFOHEAD(fd,packet_len(0x23c));
  10754. WFIFOW(fd,0) = 0x23c;
  10755. WFIFOW(fd,2) = result;
  10756. WFIFOW(fd,4) = error_count;
  10757. WFIFOSET(fd,packet_len(0x23c));
  10758. }
  10759. /// Party creation request
  10760. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10761. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10762. char* name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10763. name[NAME_LENGTH-1] = '\0';
  10764. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10765. clif_displaymessage(fd, msg_txt(sd,227));
  10766. return;
  10767. }
  10768. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10769. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10770. return;
  10771. }
  10772. party_create(sd,name,0,0);
  10773. }
  10774. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10775. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10776. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10777. char* name = RFIFOCP(fd,info->pos[0]);
  10778. int item1 = RFIFOB(fd,info->pos[1]);
  10779. int item2 = RFIFOB(fd,info->pos[2]);
  10780. name[NAME_LENGTH-1] = '\0';
  10781. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10782. clif_displaymessage(fd, msg_txt(sd,227));
  10783. return;
  10784. }
  10785. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10786. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10787. return;
  10788. }
  10789. party_create(sd,name,item1,item2);
  10790. }
  10791. /// Party invitation request
  10792. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10793. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10794. {
  10795. struct map_session_data *t_sd;
  10796. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10797. clif_displaymessage(fd, msg_txt(sd,227));
  10798. return;
  10799. }
  10800. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10801. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10802. clif_noask_sub(sd, t_sd, 1);
  10803. return;
  10804. }
  10805. party_invite(sd, t_sd);
  10806. }
  10807. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10808. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10809. struct map_session_data *t_sd;
  10810. char *name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10811. name[NAME_LENGTH-1] = '\0';
  10812. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10813. clif_displaymessage(fd, msg_txt(sd,227));
  10814. return;
  10815. }
  10816. t_sd = map_nick2sd(name);
  10817. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10818. clif_noask_sub(sd, t_sd, 1);
  10819. return;
  10820. }
  10821. party_invite(sd, t_sd);
  10822. }
  10823. /// Party invitation reply
  10824. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10825. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10826. /// flag:
  10827. /// 0 = reject
  10828. /// 1 = accept
  10829. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10830. {
  10831. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10832. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10833. RFIFOL(fd,info->pos[1]));
  10834. }
  10835. //(CZ_PARTY_JOIN_REQ_ACK)
  10836. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10837. {
  10838. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10839. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10840. RFIFOB(fd,info->pos[1]));
  10841. }
  10842. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10843. /// 0100
  10844. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10845. {
  10846. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10847. clif_displaymessage(fd, msg_txt(sd,227));
  10848. return;
  10849. }
  10850. party_leave(sd);
  10851. }
  10852. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10853. /// 0103 <account id>.L <char name>.24B
  10854. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10855. {
  10856. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10857. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10858. clif_displaymessage(fd, msg_txt(sd,227));
  10859. return;
  10860. }
  10861. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10862. RFIFOCP(fd,info->pos[1]));
  10863. }
  10864. /// Request to change party options.
  10865. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10866. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10867. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10868. {
  10869. struct party_data *p;
  10870. int i,expflag;
  10871. int cmd = RFIFOW(fd,0);
  10872. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10873. if( !sd->status.party_id )
  10874. return;
  10875. p = party_search(sd->status.party_id);
  10876. if( p == NULL )
  10877. return;
  10878. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10879. if( i == MAX_PARTY )
  10880. return; //Shouldn't happen
  10881. if( !p->party.member[i].leader )
  10882. return;
  10883. expflag = RFIFOL(fd,info->pos[0]);
  10884. if(cmd == 0x0102){ //Client can't change the item-field
  10885. party_changeoption(sd, expflag, p->party.item);
  10886. }
  10887. else {
  10888. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10889. party_changeoption(sd, expflag, itemflag);
  10890. }
  10891. }
  10892. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10893. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10894. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10895. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10896. // validate packet and retrieve name and message
  10897. if( !clif_process_message( sd, false, name, message, output ) )
  10898. return;
  10899. party_send_message(sd, output, strlen(output) + 1 );
  10900. }
  10901. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10902. /// 07da <account id>.L
  10903. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10904. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10905. }
  10906. /// Party Booking in KRO [Spiria]
  10907. ///
  10908. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10909. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10910. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10911. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10912. short level = RFIFOW(fd,info->pos[0]);
  10913. short mapid = RFIFOW(fd,info->pos[1]);
  10914. int idxpbj = info->pos[2];
  10915. short job[MAX_PARTY_BOOKING_JOBS];
  10916. int i;
  10917. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  10918. job[i] = RFIFOB(fd,idxpbj+i*2);
  10919. party_booking_register(sd, level, mapid, job);
  10920. }
  10921. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10922. /// 0803 <result>.W
  10923. /// result:
  10924. /// 0 = success
  10925. /// 1 = failure
  10926. /// 2 = already registered
  10927. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10928. {
  10929. int fd = sd->fd;
  10930. WFIFOHEAD(fd,packet_len(0x803));
  10931. WFIFOW(fd,0) = 0x803;
  10932. WFIFOW(fd,2) = flag;
  10933. WFIFOSET(fd,packet_len(0x803));
  10934. }
  10935. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10936. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10937. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10938. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10939. short level = RFIFOW(fd,info->pos[0]);
  10940. short mapid = RFIFOW(fd,info->pos[1]);
  10941. short job = RFIFOW(fd,info->pos[2]);
  10942. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10943. short resultcount = RFIFOW(fd,info->pos[4]);
  10944. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10945. }
  10946. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10947. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10948. /// more results:
  10949. /// 0 = no
  10950. /// 1 = yes
  10951. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10952. {
  10953. int i, j;
  10954. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10955. struct party_booking_ad_info *pb_ad;
  10956. WFIFOHEAD(fd,size*count + 5);
  10957. WFIFOW(fd,0) = 0x805;
  10958. WFIFOW(fd,2) = size*count + 5;
  10959. WFIFOB(fd,4) = more_result;
  10960. for(i=0; i<count; i++)
  10961. {
  10962. pb_ad = results[i];
  10963. WFIFOL(fd,i*size+5) = pb_ad->index;
  10964. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10965. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10966. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10967. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10968. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  10969. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10970. }
  10971. WFIFOSET(fd,WFIFOW(fd,2));
  10972. }
  10973. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10974. /// 0806
  10975. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10976. {
  10977. if(party_booking_delete(sd))
  10978. clif_PartyBookingDeleteAck(sd, 0);
  10979. }
  10980. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10981. /// 0807 <result>.W
  10982. /// result:
  10983. /// 0 = success
  10984. /// 1 = success (auto-removed expired ad)
  10985. /// 2 = failure
  10986. /// 3 = nothing registered
  10987. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10988. {
  10989. int fd = sd->fd;
  10990. WFIFOHEAD(fd,packet_len(0x807));
  10991. WFIFOW(fd,0) = 0x807;
  10992. WFIFOW(fd,2) = flag;
  10993. WFIFOSET(fd,packet_len(0x807));
  10994. }
  10995. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10996. /// 0808 { <job>.W }*6
  10997. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10998. {
  10999. short job[MAX_PARTY_BOOKING_JOBS];
  11000. int i;
  11001. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  11002. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11003. job[i] = RFIFOW(fd,idxpbu+i*2);
  11004. party_booking_update(sd, job);
  11005. }
  11006. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11007. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11008. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11009. {
  11010. int i;
  11011. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11012. if(pb_ad == NULL) return;
  11013. WBUFW(buf,0) = 0x809;
  11014. WBUFL(buf,2) = pb_ad->index;
  11015. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11016. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11017. WBUFW(buf,34) = pb_ad->p_detail.level;
  11018. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11019. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11020. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11021. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11022. }
  11023. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11024. /// 080a <index>.L { <job>.W }*6
  11025. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11026. {
  11027. int i;
  11028. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11029. if(pb_ad == NULL) return;
  11030. WBUFW(buf,0) = 0x80a;
  11031. WBUFL(buf,2) = pb_ad->index;
  11032. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11033. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11034. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11035. }
  11036. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11037. /// 080b <index>.L
  11038. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11039. {
  11040. uint8 buf[6];
  11041. WBUFW(buf,0) = 0x80b;
  11042. WBUFL(buf,2) = index;
  11043. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11044. }
  11045. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11046. /// 012e
  11047. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11048. {
  11049. vending_closevending(sd);
  11050. }
  11051. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11052. /// 0130 <account id>.L
  11053. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11054. {
  11055. if( sd->npc_id ) {// using an NPC
  11056. return;
  11057. }
  11058. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11059. }
  11060. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11061. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11062. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11063. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11064. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11065. int id = (int)RFIFOL(fd,info->pos[1]);
  11066. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11067. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11068. // whether it fails or not, the buy window is closed
  11069. sd->vended_id = 0;
  11070. }
  11071. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11072. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11073. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11074. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11075. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11076. int aid = (int)RFIFOL(fd,info->pos[1]);
  11077. int uid = (int)RFIFOL(fd,info->pos[2]);
  11078. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11079. vending_purchasereq(sd, aid, uid, data, len/4);
  11080. // whether it fails or not, the buy window is closed
  11081. sd->vended_id = 0;
  11082. }
  11083. /// Confirm or cancel the shop preparation window.
  11084. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11085. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11086. /// result:
  11087. /// 0 = canceled
  11088. /// 1 = open
  11089. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11090. int cmd = RFIFOW(fd,0);
  11091. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  11092. short len = (short)RFIFOW(fd,info->pos[0]);
  11093. const char* message = RFIFOCP(fd,info->pos[1]);
  11094. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11095. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11096. len -= 84;
  11097. }
  11098. else { //(CZ_REQ_OPENSTORE2)
  11099. bool flag;
  11100. len -= 85;
  11101. flag = (bool)RFIFOB(fd,info->pos[2]);
  11102. if (!flag) {
  11103. sd->state.prevend = 0;
  11104. sd->state.workinprogress = WIP_DISABLE_NONE;
  11105. }
  11106. }
  11107. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11108. return;
  11109. if( map[sd->bl.m].flag.novending ) {
  11110. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11111. return;
  11112. }
  11113. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11114. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11115. return;
  11116. }
  11117. if( message[0] == '\0' ) // invalid input
  11118. return;
  11119. vending_openvending(sd, message, data, len/8, NULL);
  11120. }
  11121. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11122. /// 0165 <char id>.L <guild name>.24B
  11123. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11124. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11125. char* name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11126. name[NAME_LENGTH-1] = '\0';
  11127. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11128. clif_displaymessage(fd, msg_txt(sd,228));
  11129. return;
  11130. }
  11131. guild_create(sd, name);
  11132. }
  11133. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11134. /// 014d
  11135. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11136. {
  11137. clif_guild_masterormember(sd);
  11138. }
  11139. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11140. /// 014f <type>.L
  11141. /// type:
  11142. /// 0 = basic info
  11143. /// 1 = member manager
  11144. /// 2 = positions
  11145. /// 3 = skills
  11146. /// 4 = expulsion list
  11147. /// 5 = unknown (GM_ALLGUILDLIST)
  11148. /// 6 = notice
  11149. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11150. {
  11151. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11152. if( !sd->status.guild_id && !sd->bg_id )
  11153. return;
  11154. switch( type )
  11155. {
  11156. case 0: // Basic Information Guild, hostile alliance information
  11157. clif_guild_basicinfo(sd);
  11158. clif_guild_allianceinfo(sd);
  11159. break;
  11160. case 1: // Members list, list job title
  11161. clif_guild_positionnamelist(sd);
  11162. clif_guild_memberlist(sd);
  11163. break;
  11164. case 2: // List job title, title information list
  11165. clif_guild_positionnamelist(sd);
  11166. clif_guild_positioninfolist(sd);
  11167. break;
  11168. case 3: // Skill list
  11169. clif_guild_skillinfo(sd);
  11170. break;
  11171. case 4: // Expulsion list
  11172. clif_guild_expulsionlist(sd);
  11173. break;
  11174. default:
  11175. ShowError("clif: guild request info: unknown type %d\n", type);
  11176. break;
  11177. }
  11178. }
  11179. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11180. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11181. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11182. {
  11183. int i;
  11184. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11185. int len = RFIFOW(fd,info->pos[0]);
  11186. int idxgpos = info->pos[1];
  11187. if(!sd->state.gmaster_flag)
  11188. return;
  11189. for(i = idxgpos; i < len; i += 40 ){
  11190. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11191. }
  11192. }
  11193. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11194. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11195. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11196. {
  11197. int i;
  11198. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11199. int len = RFIFOW(fd,info->pos[0]);
  11200. int idxgpos = info->pos[1];
  11201. if(!sd->state.gmaster_flag)
  11202. return;
  11203. for(i=idxgpos;i<len;i+=12){
  11204. guild_change_memberposition(sd->status.guild_id,
  11205. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11206. }
  11207. }
  11208. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11209. /// 0151 <guild id>.L
  11210. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11211. {
  11212. struct guild* g;
  11213. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11214. if( (g = guild_search(guild_id)) != NULL )
  11215. clif_guild_emblem(sd,g);
  11216. }
  11217. /// Validates data of a guild emblem (compressed bitmap)
  11218. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11219. EMBVALIDATE_SUCCESS = 0,
  11220. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11221. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11222. };
  11223. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11224. {
  11225. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11226. unsigned long buf_len = sizeof(buf);
  11227. int offset = 0;
  11228. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11229. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11230. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11231. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11232. ))
  11233. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11234. if(battle_config.emblem_transparency_limit != 100) {
  11235. int i, transcount = 1, tmp[3];
  11236. for(i = offset; i < buf_len-1; i++) {
  11237. int j = i%3;
  11238. tmp[j] = RBUFL(buf,i);
  11239. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11240. transcount++;
  11241. }
  11242. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11243. return EMBVALIDATE_ERR_TRANSPARENCY;
  11244. }
  11245. return EMBVALIDATE_SUCCESS;
  11246. }
  11247. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11248. /// 0153 <packet len>.W <emblem data>.?B
  11249. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11250. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11251. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11252. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11253. int emb_val=0;
  11254. if( !emblem_len || !sd->state.gmaster_flag )
  11255. return;
  11256. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11257. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  11258. return;
  11259. }
  11260. emb_val = clif_validate_emblem(emblem, emblem_len);
  11261. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11262. 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);
  11263. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  11264. return;
  11265. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11266. char output[128];
  11267. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11268. clif_colormes(sd->fd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11269. return;
  11270. }
  11271. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11272. }
  11273. /// Guild notice update request (CZ_GUILD_NOTICE).
  11274. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11275. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11276. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11277. int guild_id = RFIFOL(fd,info->pos[0]);
  11278. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11279. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11280. if(!sd->state.gmaster_flag)
  11281. return;
  11282. // compensate for some client defects when using multilanguage mode
  11283. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11284. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11285. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11286. guild_change_notice(sd, guild_id, msg1, msg2);
  11287. }
  11288. // Helper function for guild invite functions
  11289. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11290. {
  11291. if (t_sd == NULL) // not online or does not exist
  11292. return 1;
  11293. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11294. clif_displaymessage(fd, msg_txt(sd,228));
  11295. return 1;
  11296. }
  11297. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11298. clif_noask_sub(sd, t_sd, 2);
  11299. return 1;
  11300. }
  11301. guild_invite(sd, t_sd);
  11302. return 0;
  11303. }
  11304. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11305. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11306. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11307. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11308. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11309. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11310. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11311. if (clif_sub_guild_invite(fd, sd, t_sd))
  11312. return;
  11313. }
  11314. /// Guild invite request (/guildinvite)
  11315. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11316. void
  11317. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11318. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11319. if (clif_sub_guild_invite(fd, sd, t_sd))
  11320. return;
  11321. }
  11322. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11323. /// 016b <guild id>.L <answer>.L
  11324. /// answer:
  11325. /// 0 = refuse
  11326. /// 1 = accept
  11327. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11328. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11329. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11330. RFIFOL(fd,info->pos[1]));
  11331. }
  11332. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11333. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11334. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11335. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11336. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11337. clif_displaymessage(fd, msg_txt(sd,228));
  11338. return;
  11339. }
  11340. if( sd->bg_id ) {
  11341. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11342. return;
  11343. }
  11344. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11345. RFIFOL(fd,info->pos[1]),
  11346. RFIFOL(fd,info->pos[2]),
  11347. RFIFOCP(fd,info->pos[3]));
  11348. }
  11349. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11350. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11351. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11352. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11353. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11354. { // Guild locked.
  11355. clif_displaymessage(fd, msg_txt(sd,228));
  11356. return;
  11357. }
  11358. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11359. RFIFOL(fd,info->pos[1]),
  11360. RFIFOL(fd,info->pos[2]),
  11361. RFIFOCP(fd,info->pos[3]));
  11362. }
  11363. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11364. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11365. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11366. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11367. // validate packet and retrieve name and message
  11368. if( !clif_process_message( sd, false, name, message, output ) )
  11369. return;
  11370. if( sd->bg_id )
  11371. bg_send_message(sd, output, strlen(output) );
  11372. else
  11373. guild_send_message(sd, output, strlen(output) );
  11374. }
  11375. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11376. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11377. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11378. {
  11379. struct map_session_data *t_sd;
  11380. if(!sd->state.gmaster_flag)
  11381. return;
  11382. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11383. clif_displaymessage(fd, msg_txt(sd,228));
  11384. return;
  11385. }
  11386. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11387. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11388. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  11389. // @noask [LuzZza]
  11390. if(t_sd && t_sd->state.noask) {
  11391. clif_noask_sub(sd, t_sd, 3);
  11392. return;
  11393. }
  11394. guild_reqalliance(sd,t_sd);
  11395. }
  11396. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11397. /// 0172 <inviter account id>.L <answer>.L
  11398. /// answer:
  11399. /// 0 = refuse
  11400. /// 1 = accept
  11401. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11402. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11403. guild_reply_reqalliance(sd,
  11404. RFIFOL(fd,info->pos[0]),
  11405. RFIFOL(fd,info->pos[1]));
  11406. }
  11407. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11408. /// 0183 <opponent guild id>.L <relation>.L
  11409. /// relation:
  11410. /// 0 = Ally
  11411. /// 1 = Enemy
  11412. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11413. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11414. if(!sd->state.gmaster_flag)
  11415. return;
  11416. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11417. clif_displaymessage(fd, msg_txt(sd,228));
  11418. return;
  11419. }
  11420. guild_delalliance(sd,
  11421. RFIFOL(fd,info->pos[0]),
  11422. RFIFOL(fd,info->pos[1]));
  11423. }
  11424. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11425. /// 0180 <account id>.L
  11426. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11427. {
  11428. struct map_session_data *t_sd;
  11429. if(!sd->state.gmaster_flag)
  11430. return;
  11431. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11432. clif_displaymessage(fd, msg_txt(sd,228));
  11433. return;
  11434. }
  11435. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11436. // @noask [LuzZza]
  11437. if(t_sd && t_sd->state.noask) {
  11438. clif_noask_sub(sd, t_sd, 4);
  11439. return;
  11440. }
  11441. guild_opposition(sd,t_sd);
  11442. }
  11443. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11444. /// 015d <key>.40B
  11445. /// key:
  11446. /// now guild name; might have been (intended) email, since the
  11447. /// field name and size is same as the one in CH_DELETE_CHAR.
  11448. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11449. {
  11450. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11451. clif_displaymessage(fd, msg_txt(sd,228));
  11452. return;
  11453. }
  11454. guild_break(sd,RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11455. }
  11456. /// Pet
  11457. ///
  11458. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11459. /// 01a1 <type>.B
  11460. /// type:
  11461. /// 0 = pet information
  11462. /// 1 = feed
  11463. /// 2 = performance
  11464. /// 3 = return to egg
  11465. /// 4 = unequip accessory
  11466. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11467. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11468. }
  11469. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11470. /// 019f <id>.L
  11471. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11472. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11473. }
  11474. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11475. /// 01a7 <index>.W
  11476. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11477. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11478. return;
  11479. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  11480. clif_menuskill_clear(sd);
  11481. }
  11482. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11483. /// 01a9 <data>.L
  11484. /// data:
  11485. /// is either emotion (@see enum emotion_type) or a compound value
  11486. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11487. /// entry (given in parentheses) in data\pettalktable.xml
  11488. /// act id:
  11489. /// 0 = feeding
  11490. /// 1 = hunting
  11491. /// 2 = danger
  11492. /// 3 = dead
  11493. /// 4 = normal (stand)
  11494. /// 5 = special performance (perfor_s)
  11495. /// 6 = level up (levelup)
  11496. /// 7 = performance 1 (perfor_1)
  11497. /// 8 = performance 2 (perfor_2)
  11498. /// 9 = performance 3 (perfor_3)
  11499. /// 10 = log-in greeting (connect)
  11500. /// hungry value:
  11501. /// 0 = very hungry (hungry)
  11502. /// 1 = hungry (bit_hungry)
  11503. /// 2 = satisfied (noting)
  11504. /// 3 = stuffed (full)
  11505. /// 4 = full (so_full)
  11506. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11507. {
  11508. if(sd->pd)
  11509. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11510. }
  11511. /// Request to change pet's name (CZ_RENAME_PET).
  11512. /// 01a5 <name>.24B
  11513. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11514. {
  11515. pet_change_name(sd,RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11516. }
  11517. /// /kill (CZ_DISCONNECT_CHARACTER).
  11518. /// Request to disconnect a character.
  11519. /// 00cc <account id>.L
  11520. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11521. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11522. {
  11523. struct block_list *target;
  11524. int tid;
  11525. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11526. target = map_id2bl(tid);
  11527. if (!target) {
  11528. clif_GM_kickack(sd, 0);
  11529. return;
  11530. }
  11531. switch (target->type) {
  11532. case BL_PC:
  11533. {
  11534. char command[NAME_LENGTH+6];
  11535. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11536. is_atcommand(fd, sd, command, 1);
  11537. }
  11538. break;
  11539. /**
  11540. * This one does not invoke any atcommand, so we need to check for permissions.
  11541. */
  11542. case BL_MOB:
  11543. {
  11544. char command[100];
  11545. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11546. clif_GM_kickack(sd, 0);
  11547. return;
  11548. }
  11549. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11550. log_atcommand(sd, command);
  11551. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11552. }
  11553. break;
  11554. case BL_NPC:
  11555. {
  11556. struct npc_data* nd = (struct npc_data *)target;
  11557. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11558. npc_unload_duplicates(nd);
  11559. npc_unload(nd,true);
  11560. npc_read_event_script();
  11561. }
  11562. }
  11563. break;
  11564. default:
  11565. clif_GM_kickack(sd, 0);
  11566. }
  11567. }
  11568. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11569. /// Request to disconnect all characters.
  11570. /// 00ce
  11571. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11572. char cmd[15];
  11573. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11574. is_atcommand(fd, sd, cmd, 1);
  11575. }
  11576. /// /remove (CZ_REMOVE_AID).
  11577. /// Request to warp to a character with given login ID.
  11578. /// 01ba <account name>.24B
  11579. /// /shift (CZ_SHIFT).
  11580. /// Request to warp to a character with given name.
  11581. /// 01bb <char name>.24B
  11582. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11583. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11584. char *player_name;
  11585. char command[NAME_LENGTH+8];
  11586. player_name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11587. player_name[NAME_LENGTH-1] = '\0';
  11588. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11589. is_atcommand(fd, sd, command, 1);
  11590. }
  11591. /// /remove (CZ_REMOVE_AID_SSO).
  11592. /// Request to warp to a character with given account ID.
  11593. /// 0843 <account id>.L
  11594. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11595. {
  11596. uint32 account_id;
  11597. struct map_session_data* pl_sd;
  11598. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11599. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11600. char command[NAME_LENGTH+8];
  11601. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11602. is_atcommand(fd, sd, command, 1);
  11603. }
  11604. }
  11605. /// /recall (CZ_RECALL).
  11606. /// Request to summon a player with given login ID to own position.
  11607. /// 01bc <account name>.24B
  11608. /// /summon (CZ_RECALL_GID).
  11609. /// Request to summon a player with given name to own position.
  11610. /// 01bd <char name>.24B
  11611. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11612. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11613. char *player_name;
  11614. char command [NAME_LENGTH+8];
  11615. player_name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11616. player_name[NAME_LENGTH-1] = '\0';
  11617. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11618. is_atcommand(fd, sd, command, 1);
  11619. }
  11620. /// /recall (CZ_RECALL_SSO).
  11621. /// Request to summon a player with given account ID to own position.
  11622. /// 0842 <account id>.L
  11623. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11624. {
  11625. uint32 account_id;
  11626. struct map_session_data* pl_sd;
  11627. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11628. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11629. char command[NAME_LENGTH+8];
  11630. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11631. is_atcommand(fd, sd, command, 1);
  11632. }
  11633. }
  11634. /// /item /monster (CZ_ITEM_CREATE).
  11635. /// Request to execute GM commands.
  11636. /// Usage:
  11637. /// /item n - summon n monster or acquire n item/s
  11638. /// /item money - grants 2147483647 zenies
  11639. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11640. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11641. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11642. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11643. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11644. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11645. /// 013f <item/mob name>.24B
  11646. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11647. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11648. {
  11649. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11650. int mob_id = 0;
  11651. struct item_data *id = NULL;
  11652. struct mob_db *mob = NULL;
  11653. StringBuf command;
  11654. char *str;
  11655. //#if PACKETVER >= 20131218
  11656. // char str[100];
  11657. //#else
  11658. // char str[24];
  11659. //#endif
  11660. str = RFIFOCP(fd,info->pos[0]);
  11661. if (!str || str[0] == '\0')
  11662. return;
  11663. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11664. return;
  11665. trim(str);
  11666. // Zeny
  11667. if( strcmpi(str, "money") == 0 ) {
  11668. StringBuf_Init(&command);
  11669. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11670. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11671. StringBuf_Destroy(&command);
  11672. return;
  11673. }
  11674. // Item
  11675. if( (id = itemdb_searchname(str)) ) {
  11676. StringBuf_Init(&command);
  11677. if( !itemdb_isstackable2(id) ) //Nonstackable
  11678. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11679. else {
  11680. if (id->flag.guid)
  11681. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11682. else
  11683. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11684. }
  11685. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11686. StringBuf_Destroy(&command);
  11687. return;
  11688. }
  11689. // Monster
  11690. if ((mob_id = mobdb_searchname(str)) == 0)
  11691. mob_id = mobdb_checkid(atoi(str));
  11692. if( (mob = mob_db(mob_id)) ) {
  11693. StringBuf_Init(&command);
  11694. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11695. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11696. StringBuf_Destroy(&command);
  11697. return;
  11698. }
  11699. }
  11700. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11701. /// 019d <effect state>.L
  11702. /// effect state:
  11703. /// TODO: Any OPTION_* ?
  11704. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11705. char cmd[6];
  11706. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11707. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11708. is_atcommand(fd, sd, cmd, 1);
  11709. }
  11710. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11711. /// 0149 <account id>.L <type>.B <value>.W
  11712. /// type:
  11713. /// 0 = positive points
  11714. /// 1 = negative points
  11715. /// 2 = self mute (+10 minutes)
  11716. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11717. {
  11718. int id, type, value;
  11719. struct map_session_data *dstsd;
  11720. char command[NAME_LENGTH+15];
  11721. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11722. id = RFIFOL(fd,info->pos[0]);
  11723. type = RFIFOB(fd,info->pos[1]);
  11724. value = RFIFOW(fd,info->pos[2]);
  11725. if( type == 0 )
  11726. value = -value;
  11727. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11728. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11729. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11730. return;
  11731. dstsd = map_id2sd(id);
  11732. if( dstsd == NULL )
  11733. return;
  11734. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11735. is_atcommand(fd, sd, command, 1);
  11736. }
  11737. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11738. /// GM adjustment of a player's manner value by -60.
  11739. /// 0212 <char name>.24B
  11740. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11741. {
  11742. char command[NAME_LENGTH+15];
  11743. char *name = RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11744. name[NAME_LENGTH-1] = '\0';
  11745. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11746. is_atcommand(fd, sd, command, 1);
  11747. }
  11748. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11749. /// 01e0 <account id>.L <account name>.24B
  11750. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11751. {
  11752. WFIFOHEAD(fd,packet_len(0x1e0));
  11753. WFIFOW(fd,0) = 0x1e0;
  11754. WFIFOL(fd,2) = account_id;
  11755. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  11756. WFIFOSET(fd,packet_len(0x1e0));
  11757. }
  11758. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11759. /// 01df <account id>.L
  11760. //! TODO: Figure out how does this actually work
  11761. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11762. {
  11763. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11764. /*
  11765. char query[30];
  11766. safesnprintf(query,sizeof(query),"%d", account_id);
  11767. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11768. */
  11769. clif_account_name(fd, account_id, "");
  11770. }
  11771. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11772. /// GM single cell type change request.
  11773. /// 0198 <x>.W <y>.W <type>.W
  11774. /// type:
  11775. /// 0 = not walkable
  11776. /// 1 = walkable
  11777. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11778. {
  11779. int x,y,type;
  11780. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11781. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11782. return;
  11783. x = RFIFOW(fd,info->pos[0]);
  11784. y = RFIFOW(fd,info->pos[1]);
  11785. type = RFIFOW(fd,info->pos[2]);
  11786. map_setgatcell(sd->bl.m,x,y,type);
  11787. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11788. //FIXME: once players leave the map, the client 'forgets' this information.
  11789. }
  11790. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11791. /// Request to allow/deny whispers from a nick.
  11792. /// 00cf <nick>.24B <type>.B
  11793. /// type:
  11794. /// 0 = (/ex nick) deny speech from nick
  11795. /// 1 = (/in nick) allow speech from nick
  11796. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11797. {
  11798. char* nick;
  11799. uint8 type;
  11800. int i;
  11801. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11802. nick = RFIFOCP(fd,info->pos[0]);
  11803. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11804. type = RFIFOB(fd,info->pos[1]);
  11805. if( type == 0 ) { // Add name to ignore list (block)
  11806. if (strcmp(wisp_server_name, nick) == 0) {
  11807. clif_wisexin(sd, type, 1); // fail
  11808. return;
  11809. }
  11810. // try to find a free spot, while checking for duplicates at the same time
  11811. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11812. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11813. clif_wisexin(sd, type, 2); // too many blocks
  11814. return;
  11815. }
  11816. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11817. clif_wisexin(sd, type, 0); // Aegis reports success.
  11818. return;
  11819. }
  11820. //Insert in position i
  11821. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11822. } else { // Remove name from ignore list (unblock)
  11823. // find entry
  11824. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11825. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11826. clif_wisexin(sd, type, 1); // fail
  11827. return;
  11828. }
  11829. // move everything one place down to overwrite removed entry
  11830. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11831. // wipe last entry
  11832. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11833. }
  11834. clif_wisexin(sd, type, 0); // success
  11835. }
  11836. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11837. /// Request to allow/deny all whispers.
  11838. /// 00d0 <type>.B
  11839. /// type:
  11840. /// 0 = (/exall) deny all speech
  11841. /// 1 = (/inall) allow all speech
  11842. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11843. {
  11844. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11845. if( type == 0 ) {// Deny all
  11846. if( sd->state.ignoreAll ) {
  11847. flag = 1; // fail
  11848. } else {
  11849. sd->state.ignoreAll = 1;
  11850. flag = 0; // success
  11851. }
  11852. } else {//Unblock everyone
  11853. if( sd->state.ignoreAll ) {
  11854. sd->state.ignoreAll = 0;
  11855. flag = 0; // success
  11856. } else {
  11857. if (sd->ignore[0].name[0] != '\0')
  11858. { //Wipe the ignore list.
  11859. memset(sd->ignore, 0, sizeof(sd->ignore));
  11860. flag = 0; // success
  11861. } else {
  11862. flag = 1; // fail
  11863. }
  11864. }
  11865. }
  11866. clif_wisall(sd, type, flag);
  11867. }
  11868. /// Whisper ignore list (ZC_WHISPER_LIST).
  11869. /// 00d4 <packet len>.W { <char name>.24B }*
  11870. void clif_PMIgnoreList(struct map_session_data* sd)
  11871. {
  11872. int i, fd = sd->fd;
  11873. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11874. WFIFOW(fd,0) = 0xd4;
  11875. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11876. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11877. }
  11878. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11879. WFIFOSET(fd,WFIFOW(fd,2));
  11880. }
  11881. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11882. /// 00d3
  11883. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11884. {
  11885. clif_PMIgnoreList(sd);
  11886. }
  11887. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11888. /// 01e7
  11889. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11890. {
  11891. if (sd->state.doridori) return;
  11892. switch (sd->class_&MAPID_UPPERMASK) {
  11893. case MAPID_SOUL_LINKER:
  11894. case MAPID_STAR_GLADIATOR:
  11895. case MAPID_TAEKWON:
  11896. if (!sd->state.rest)
  11897. break;
  11898. case MAPID_SUPER_NOVICE:
  11899. case MAPID_SUPER_BABY:
  11900. case MAPID_SUPER_NOVICE_E:
  11901. case MAPID_SUPER_BABY_E:
  11902. sd->state.doridori=1;
  11903. break;
  11904. }
  11905. }
  11906. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11907. /// 01ed
  11908. /// Note: This packet is caused by 7 lines of any text, followed by
  11909. /// the prayer and an another line of any text. The prayer is
  11910. /// defined by lines 790~793 in data\msgstringtable.txt
  11911. /// "Dear angel, can you hear my voice?"
  11912. /// "I am" (space separated player name) "Super Novice~"
  11913. /// "Help me out~ Please~ T_T"
  11914. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11915. {
  11916. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  11917. unsigned int next = pc_nextbaseexp(sd);
  11918. if( next ) {
  11919. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11920. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11921. 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]
  11922. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11923. }
  11924. }
  11925. }
  11926. }
  11927. /// Friends List
  11928. ///
  11929. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11930. /// 0206 <account id>.L <char id>.L <state>.B
  11931. /// state:
  11932. /// 0 = online
  11933. /// 1 = offline
  11934. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  11935. {
  11936. int i, fd = sd->fd;
  11937. //Seek friend.
  11938. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11939. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11940. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11941. return; //Not found
  11942. WFIFOHEAD(fd,packet_len(0x206));
  11943. WFIFOW(fd, 0) = 0x206;
  11944. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11945. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11946. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11947. WFIFOSET(fd, packet_len(0x206));
  11948. }
  11949. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11950. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11951. {
  11952. uint32 account_id, char_id, online;
  11953. account_id = va_arg(ap, int);
  11954. char_id = va_arg(ap, int);
  11955. online = va_arg(ap, int);
  11956. clif_friendslist_toggle(sd, account_id, char_id, online);
  11957. return 0;
  11958. }
  11959. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11960. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11961. void clif_friendslist_send(struct map_session_data *sd)
  11962. {
  11963. int i = 0, n, fd = sd->fd;
  11964. // Send friends list
  11965. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11966. WFIFOW(fd, 0) = 0x201;
  11967. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11968. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11969. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11970. safestrncpy(WFIFOCP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  11971. }
  11972. if (i) {
  11973. WFIFOW(fd,2) = 4 + 32 * i;
  11974. WFIFOSET(fd, WFIFOW(fd,2));
  11975. }
  11976. for (n = 0; n < i; n++) { //Sending the online players
  11977. if (map_charid2sd(sd->status.friends[n].char_id))
  11978. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11979. }
  11980. }
  11981. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11982. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11983. /// result:
  11984. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11985. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11986. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11987. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11988. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11989. {
  11990. int fd;
  11991. nullpo_retv(sd);
  11992. fd = sd->fd;
  11993. WFIFOHEAD(fd,packet_len(0x209));
  11994. WFIFOW(fd,0) = 0x209;
  11995. WFIFOW(fd,2) = type;
  11996. if (f_sd) {
  11997. WFIFOL(fd,4) = f_sd->status.account_id;
  11998. WFIFOL(fd,8) = f_sd->status.char_id;
  11999. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12000. }
  12001. WFIFOSET(fd, packet_len(0x209));
  12002. }
  12003. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12004. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12005. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12006. {
  12007. int fd = sd->fd;
  12008. WFIFOHEAD(fd,packet_len(0x207));
  12009. WFIFOW(fd,0) = 0x207;
  12010. WFIFOL(fd,2) = account_id;
  12011. WFIFOL(fd,6) = char_id;
  12012. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12013. WFIFOSET(fd,packet_len(0x207));
  12014. }
  12015. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12016. /// 0202 <name>.24B
  12017. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12018. {
  12019. struct map_session_data *f_sd;
  12020. int i;
  12021. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12022. // ensure that the request player's friend list is not full
  12023. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12024. if( i == MAX_FRIENDS ) {
  12025. clif_friendslist_reqack(sd, f_sd, 2);
  12026. return;
  12027. }
  12028. // Friend doesn't exist (no player with this name)
  12029. if (f_sd == NULL) {
  12030. clif_displaymessage(fd, msg_txt(sd,3));
  12031. return;
  12032. }
  12033. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12034. return;
  12035. }
  12036. // @noask [LuzZza]
  12037. if(f_sd->state.noask) {
  12038. clif_noask_sub(sd, f_sd, 5);
  12039. return;
  12040. }
  12041. // Friend already exists
  12042. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12043. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12044. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12045. return;
  12046. }
  12047. }
  12048. f_sd->friend_req = sd->status.char_id;
  12049. sd->friend_req = f_sd->status.char_id;
  12050. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12051. }
  12052. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12053. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12054. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12055. /// reply:
  12056. /// 0 = rejected
  12057. /// 1 = accepted
  12058. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12059. {
  12060. struct map_session_data *f_sd;
  12061. uint32 account_id;
  12062. char reply;
  12063. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12064. account_id = RFIFOL(fd,info->pos[0]);
  12065. //char_id = RFIFOL(fd,info->pos[1]);
  12066. if(sd->packet_ver < 6)
  12067. reply = RFIFOB(fd,info->pos[2]);
  12068. else
  12069. reply = RFIFOL(fd,info->pos[2]);
  12070. if( sd->bl.id == account_id ) {// adding oneself as friend
  12071. return;
  12072. }
  12073. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12074. if (f_sd == NULL)
  12075. return;
  12076. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12077. clif_friendslist_reqack(f_sd, sd, 1);
  12078. else {
  12079. int i;
  12080. // Find an empty slot
  12081. for (i = 0; i < MAX_FRIENDS; i++)
  12082. if (f_sd->status.friends[i].char_id == 0)
  12083. break;
  12084. if (i == MAX_FRIENDS) {
  12085. clif_friendslist_reqack(f_sd, sd, 2);
  12086. return;
  12087. }
  12088. f_sd->status.friends[i].account_id = sd->status.account_id;
  12089. f_sd->status.friends[i].char_id = sd->status.char_id;
  12090. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12091. clif_friendslist_reqack(f_sd, sd, 0);
  12092. if (battle_config.friend_auto_add) {
  12093. // Also add f_sd to sd's friendlist.
  12094. for (i = 0; i < MAX_FRIENDS; i++) {
  12095. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12096. return; //No need to add anything.
  12097. if (sd->status.friends[i].char_id == 0)
  12098. break;
  12099. }
  12100. if (i == MAX_FRIENDS) {
  12101. clif_friendslist_reqack(sd, f_sd, 2);
  12102. return;
  12103. }
  12104. sd->status.friends[i].account_id = f_sd->status.account_id;
  12105. sd->status.friends[i].char_id = f_sd->status.char_id;
  12106. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12107. clif_friendslist_reqack(sd, f_sd, 0);
  12108. }
  12109. }
  12110. }
  12111. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12112. /// 0203 <account id>.L <char id>.L
  12113. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12114. {
  12115. struct map_session_data *f_sd = NULL;
  12116. uint32 account_id, char_id;
  12117. int i, j;
  12118. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12119. account_id = RFIFOL(fd,info->pos[0]);
  12120. char_id = RFIFOL(fd,info->pos[1]);
  12121. // Search friend
  12122. for (i = 0; i < MAX_FRIENDS &&
  12123. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12124. if (i == MAX_FRIENDS) {
  12125. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12126. return;
  12127. }
  12128. //remove from friend's list first
  12129. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12130. for (i = 0; i < MAX_FRIENDS &&
  12131. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12132. if (i != MAX_FRIENDS) {
  12133. // move all chars up
  12134. for(j = i + 1; j < MAX_FRIENDS; j++)
  12135. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12136. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12137. //should the guy be notified of some message? we should add it here if so
  12138. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12139. WFIFOW(f_sd->fd,0) = 0x20a;
  12140. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12141. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12142. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12143. }
  12144. } else { //friend not online -- ask char server to delete from his friendlist
  12145. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12146. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12147. return;
  12148. }
  12149. }
  12150. // We can now delete from original requester
  12151. for (i = 0; i < MAX_FRIENDS &&
  12152. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12153. // move all chars up
  12154. for(j = i + 1; j < MAX_FRIENDS; j++)
  12155. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12156. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12157. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12158. WFIFOHEAD(fd,packet_len(0x20a));
  12159. WFIFOW(fd,0) = 0x20a;
  12160. WFIFOL(fd,2) = account_id;
  12161. WFIFOL(fd,6) = char_id;
  12162. WFIFOSET(fd, packet_len(0x20a));
  12163. }
  12164. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12165. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12166. void clif_PVPInfo(struct map_session_data* sd)
  12167. {
  12168. int fd = sd->fd;
  12169. WFIFOHEAD(fd,packet_len(0x210));
  12170. WFIFOW(fd,0) = 0x210;
  12171. WFIFOL(fd,2) = sd->status.char_id;
  12172. WFIFOL(fd,6) = sd->status.account_id;
  12173. WFIFOL(fd,10) = sd->pvp_won; // times won
  12174. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12175. WFIFOL(fd,18) = sd->pvp_point;
  12176. WFIFOSET(fd, packet_len(0x210));
  12177. }
  12178. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12179. /// 020f <char id>.L <account id>.L
  12180. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12181. {
  12182. // TODO: Is there a way to use this on an another player (char/acc id)?
  12183. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12184. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12185. clif_PVPInfo(sd);
  12186. }
  12187. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12188. /// 0254 <which>.B
  12189. /// which: (unused atm for security purpose)
  12190. /// 0 = sun
  12191. /// 1 = moon
  12192. /// 2 = star
  12193. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12194. {
  12195. int i;
  12196. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12197. if (sd->menuskill_id != SG_FEEL)
  12198. return;
  12199. i = sd->menuskill_val-1;
  12200. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12201. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12202. sd->feel_map[i].m = sd->bl.m;
  12203. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12204. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12205. // clif_misceffect2(&sd->bl, 0x1b0);
  12206. // clif_misceffect2(&sd->bl, 0x21f);
  12207. clif_feel_info(sd, i, 0);
  12208. clif_menuskill_clear(sd);
  12209. }
  12210. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12211. /// 0253 <which>.B
  12212. /// which:
  12213. /// 0 = sun
  12214. /// 1 = moon
  12215. /// 2 = star
  12216. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12217. {
  12218. WFIFOHEAD(fd,packet_len(0x253));
  12219. WFIFOW(fd,0)=0x253;
  12220. WFIFOB(fd,2)=TOB(skill_lv-1);
  12221. WFIFOSET(fd, packet_len(0x253));
  12222. sd->menuskill_id = SG_FEEL;
  12223. sd->menuskill_val = skill_lv;
  12224. }
  12225. /// Request to change homunculus' name (CZ_RENAME_MER).
  12226. /// 0231 <name>.24B
  12227. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12228. hom_change_name(sd,RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12229. }
  12230. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12231. /// 0234 <id>.L
  12232. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12233. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12234. struct block_list *bl = NULL;
  12235. struct unit_data *ud = NULL;
  12236. if( sd->md && sd->md->bl.id == id )
  12237. bl = &sd->md->bl;
  12238. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12239. bl = &sd->hd->bl; // Moving Homunculus
  12240. else
  12241. return;
  12242. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12243. ud = unit_bl2ud(bl);
  12244. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12245. }
  12246. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12247. /// 0232 <id>.L <position data>.3B
  12248. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12249. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12250. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12251. struct block_list *bl = NULL;
  12252. short x, y;
  12253. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12254. if( sd->md && sd->md->bl.id == id )
  12255. bl = &sd->md->bl; // Moving Mercenary
  12256. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12257. bl = &sd->hd->bl; // Moving Homunculus
  12258. else
  12259. return;
  12260. unit_walktoxy(bl, x, y, 4);
  12261. }
  12262. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12263. /// 0233 <id>.L <target id>.L <action>.B
  12264. /// action:
  12265. /// always 0
  12266. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12267. {
  12268. struct block_list *bl = NULL;
  12269. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12270. int id = RFIFOL(fd,info->pos[0]);
  12271. int target_id = RFIFOL(fd,info->pos[1]);
  12272. int action_type = RFIFOB(fd,info->pos[2]);
  12273. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12274. bl = &sd->hd->bl;
  12275. else if( sd->md && sd->md->bl.id == id )
  12276. bl = &sd->md->bl;
  12277. else return;
  12278. unit_stop_attack(bl);
  12279. unit_attack(bl, target_id, action_type != 0);
  12280. }
  12281. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12282. /// 022d <type>.W <command>.B
  12283. /// type:
  12284. /// always 0
  12285. /// command:
  12286. /// 0 = homunculus information
  12287. /// 1 = feed
  12288. /// 2 = delete
  12289. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12290. { //[orn]
  12291. int cmd = RFIFOW(fd,0);
  12292. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12293. if(!hom_is_active(sd->hd))
  12294. return;
  12295. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  12296. }
  12297. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12298. /// 0292
  12299. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12300. {
  12301. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12302. uint8 hp = 100, sp = 100;
  12303. if (item_position < 0) {
  12304. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12305. // HP restored
  12306. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12307. sp = 0;
  12308. }
  12309. else
  12310. return;
  12311. }
  12312. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12313. return;
  12314. if (!status_revive(&sd->bl, hp, sp))
  12315. return;
  12316. if (item_position < 0)
  12317. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12318. else
  12319. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12320. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12321. }
  12322. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12323. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12324. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12325. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12326. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12327. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12328. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12329. void clif_check(int fd, struct map_session_data* pl_sd)
  12330. {
  12331. WFIFOHEAD(fd,packet_len(0x214));
  12332. WFIFOW(fd, 0) = 0x214;
  12333. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12334. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12335. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12336. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12337. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12338. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12339. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12340. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12341. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12342. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12343. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12344. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12345. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12346. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12347. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12348. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12349. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12350. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12351. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12352. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12353. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12354. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12355. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12356. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12357. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12358. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12359. WFIFOSET(fd,packet_len(0x214));
  12360. }
  12361. /// /check (CZ_REQ_STATUS_GM).
  12362. /// Request character's status values.
  12363. /// 0213 <char name>.24B
  12364. void clif_parse_Check(int fd, struct map_session_data *sd)
  12365. {
  12366. char charname[NAME_LENGTH];
  12367. struct map_session_data* pl_sd;
  12368. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12369. return;
  12370. safestrncpy(charname, RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12371. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12372. {
  12373. return;
  12374. }
  12375. clif_check(fd, pl_sd);
  12376. }
  12377. /// MAIL SYSTEM
  12378. /// By Zephyrus
  12379. ///
  12380. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12381. /// 0255 <index>.W <result>.B
  12382. /// result:
  12383. /// 0 = success
  12384. /// 1 = failure
  12385. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12386. {
  12387. WFIFOHEAD(fd,packet_len(0x255));
  12388. WFIFOW(fd,0) = 0x255;
  12389. WFIFOW(fd,2) = index;
  12390. WFIFOB(fd,4) = flag;
  12391. WFIFOSET(fd,packet_len(0x255));
  12392. }
  12393. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12394. /// 0245 <result>.B
  12395. /// result:
  12396. /// 0 = success
  12397. /// 1 = failure
  12398. /// 2 = too many items
  12399. void clif_Mail_getattachment(int fd, uint8 result)
  12400. {
  12401. WFIFOHEAD(fd,packet_len(0x245));
  12402. WFIFOW(fd,0) = 0x245;
  12403. WFIFOB(fd,2) = result;
  12404. WFIFOSET(fd,packet_len(0x245));
  12405. }
  12406. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12407. /// 0249 <result>.B
  12408. /// result:
  12409. /// 0 = success
  12410. /// 1 = recipinent does not exist
  12411. void clif_Mail_send(int fd, bool fail)
  12412. {
  12413. WFIFOHEAD(fd,packet_len(0x249));
  12414. WFIFOW(fd,0) = 0x249;
  12415. WFIFOB(fd,2) = fail;
  12416. WFIFOSET(fd,packet_len(0x249));
  12417. }
  12418. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12419. /// 0257 <mail id>.L <result>.W
  12420. /// result:
  12421. /// 0 = success
  12422. /// 1 = failure
  12423. void clif_Mail_delete(int fd, int mail_id, short fail)
  12424. {
  12425. WFIFOHEAD(fd, packet_len(0x257));
  12426. WFIFOW(fd,0) = 0x257;
  12427. WFIFOL(fd,2) = mail_id;
  12428. WFIFOW(fd,6) = fail;
  12429. WFIFOSET(fd, packet_len(0x257));
  12430. }
  12431. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12432. /// 0274 <mail id>.L <result>.W
  12433. /// result:
  12434. /// 0 = success
  12435. /// 1 = failure
  12436. void clif_Mail_return(int fd, int mail_id, short fail)
  12437. {
  12438. WFIFOHEAD(fd,packet_len(0x274));
  12439. WFIFOW(fd,0) = 0x274;
  12440. WFIFOL(fd,2) = mail_id;
  12441. WFIFOW(fd,6) = fail;
  12442. WFIFOSET(fd,packet_len(0x274));
  12443. }
  12444. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12445. /// 024a <mail id>.L <title>.40B <sender>.24B
  12446. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12447. {
  12448. WFIFOHEAD(fd,packet_len(0x24a));
  12449. WFIFOW(fd,0) = 0x24a;
  12450. WFIFOL(fd,2) = mail_id;
  12451. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12452. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12453. WFIFOSET(fd,packet_len(0x24a));
  12454. }
  12455. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12456. /// 0260 <type>.L
  12457. /// type:
  12458. /// 0 = open
  12459. /// 1 = close
  12460. void clif_Mail_window(int fd, int flag)
  12461. {
  12462. WFIFOHEAD(fd,packet_len(0x260));
  12463. WFIFOW(fd,0) = 0x260;
  12464. WFIFOL(fd,2) = flag;
  12465. WFIFOSET(fd,packet_len(0x260));
  12466. }
  12467. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12468. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12469. /// read:
  12470. /// 0 = unread
  12471. /// 1 = read
  12472. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12473. {
  12474. int fd = sd->fd;
  12475. struct mail_data *md = &sd->mail.inbox;
  12476. struct mail_message *msg;
  12477. int len, i, j;
  12478. len = 8 + (73 * md->amount);
  12479. WFIFOHEAD(fd,len);
  12480. WFIFOW(fd,0) = 0x240;
  12481. WFIFOW(fd,2) = len;
  12482. WFIFOL(fd,4) = md->amount;
  12483. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12484. {
  12485. msg = &md->msg[i];
  12486. if (msg->id < 1)
  12487. continue;
  12488. WFIFOL(fd,8+73*j) = msg->id;
  12489. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12490. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12491. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12492. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12493. j++;
  12494. }
  12495. WFIFOSET(fd,len);
  12496. if( md->full ) {// TODO: is this official?
  12497. char output[100];
  12498. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12499. clif_disp_onlyself(sd, output, strlen(output));
  12500. }
  12501. }
  12502. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12503. /// 023f
  12504. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12505. {
  12506. struct mail_data* md = &sd->mail.inbox;
  12507. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12508. intif_Mail_requestinbox(sd->status.char_id, 1);
  12509. else
  12510. clif_Mail_refreshinbox(sd);
  12511. mail_removeitem(sd, 0);
  12512. mail_removezeny(sd, 0);
  12513. }
  12514. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12515. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12516. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12517. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12518. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12519. {
  12520. int i, fd = sd->fd;
  12521. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12522. if( i == MAIL_MAX_INBOX ) {
  12523. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12524. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12525. return;
  12526. } else {
  12527. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12528. struct item *item = &msg->item;
  12529. struct item_data *data;
  12530. int msg_len = strlen(msg->body), len;
  12531. if( msg_len == 0 ) {
  12532. strcpy(msg->body, "(no message)");
  12533. msg_len = strlen(msg->body);
  12534. }
  12535. len = 101 + msg_len;
  12536. WFIFOHEAD(fd,len);
  12537. WFIFOW(fd,0) = 0x242;
  12538. WFIFOW(fd,2) = len;
  12539. WFIFOL(fd,4) = msg->id;
  12540. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12541. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12542. WFIFOL(fd,72) = 0;
  12543. WFIFOL(fd,76) = msg->zeny;
  12544. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12545. WFIFOL(fd,80) = item->amount;
  12546. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12547. WFIFOW(fd,86) = data->type;
  12548. WFIFOB(fd,88) = item->identify;
  12549. WFIFOB(fd,89) = item->attribute;
  12550. WFIFOB(fd,90) = item->refine;
  12551. WFIFOW(fd,91) = item->card[0];
  12552. WFIFOW(fd,93) = item->card[1];
  12553. WFIFOW(fd,95) = item->card[2];
  12554. WFIFOW(fd,97) = item->card[3];
  12555. } else // no item, set all to zero
  12556. memset(WFIFOP(fd,80), 0x00, 19);
  12557. WFIFOB(fd,99) = (unsigned char)msg_len;
  12558. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  12559. WFIFOSET(fd,len);
  12560. if (msg->status == MAIL_UNREAD) {
  12561. msg->status = MAIL_READ;
  12562. intif_Mail_read(mail_id);
  12563. clif_parse_Mail_refreshinbox(fd, sd);
  12564. }
  12565. }
  12566. }
  12567. /// Request to open a mail (CZ_MAIL_OPEN).
  12568. /// 0241 <mail id>.L
  12569. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12570. {
  12571. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12572. if( mail_id <= 0 )
  12573. return;
  12574. if( mail_invalid_operation(sd) )
  12575. return;
  12576. clif_Mail_read(sd, mail_id);
  12577. }
  12578. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12579. /// 0244 <mail id>.L
  12580. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12581. {
  12582. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12583. int i;
  12584. bool fail = false;
  12585. if( !chrif_isconnected() )
  12586. return;
  12587. if( mail_id <= 0 )
  12588. return;
  12589. if( mail_invalid_operation(sd) )
  12590. return;
  12591. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12592. if( i == MAIL_MAX_INBOX )
  12593. return;
  12594. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12595. return;
  12596. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12597. clif_Mail_getattachment(fd, 1); //too many zeny
  12598. return;
  12599. }
  12600. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12601. struct item_data *data;
  12602. unsigned int weight;
  12603. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12604. return;
  12605. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12606. case CHKADDITEM_NEW:
  12607. fail = ( pc_inventoryblank(sd) == 0 );
  12608. break;
  12609. case CHKADDITEM_OVERAMOUNT:
  12610. fail = true;
  12611. }
  12612. if( fail ) {
  12613. clif_Mail_getattachment(fd, 1);
  12614. return;
  12615. }
  12616. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12617. if( sd->weight + weight > sd->max_weight ) {
  12618. clif_Mail_getattachment(fd, 2);
  12619. return;
  12620. }
  12621. }
  12622. sd->mail.inbox.msg[i].zeny = 0;
  12623. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12624. clif_Mail_read(sd, mail_id);
  12625. intif_Mail_getattach(sd->status.char_id, mail_id);
  12626. }
  12627. /// Request to delete a mail (CZ_MAIL_DELETE).
  12628. /// 0243 <mail id>.L
  12629. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12630. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12631. int i;
  12632. if( !chrif_isconnected() )
  12633. return;
  12634. if( mail_id <= 0 )
  12635. return;
  12636. if( mail_invalid_operation(sd) )
  12637. return;
  12638. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12639. if (i < MAIL_MAX_INBOX) {
  12640. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12641. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12642. clif_Mail_delete(sd->fd, mail_id, 1);
  12643. return;
  12644. }
  12645. intif_Mail_delete(sd->status.char_id, mail_id);
  12646. }
  12647. }
  12648. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12649. /// 0273 <mail id>.L <receive name>.24B
  12650. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12651. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12652. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12653. int i;
  12654. if( mail_id <= 0 )
  12655. return;
  12656. if( mail_invalid_operation(sd) )
  12657. return;
  12658. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12659. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12660. intif_Mail_return(sd->status.char_id, mail_id);
  12661. else
  12662. clif_Mail_return(sd->fd, mail_id, 1);
  12663. }
  12664. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12665. /// 0247 <index>.W <amount>.L
  12666. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12667. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12668. int idx = RFIFOW(fd,info->pos[0]);
  12669. int amount = RFIFOL(fd,info->pos[1]);
  12670. unsigned char flag;
  12671. if( !chrif_isconnected() )
  12672. return;
  12673. if (idx < 0 || amount < 0)
  12674. return;
  12675. flag = mail_setitem(sd, idx, amount);
  12676. clif_Mail_setattachment(fd,idx,!flag);
  12677. }
  12678. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12679. /// 0246 <type>.W
  12680. /// type:
  12681. /// 0 = reset all
  12682. /// 1 = remove item
  12683. /// 2 = remove zeny
  12684. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12685. {
  12686. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12687. if (type == 0 || type == 1)
  12688. mail_removeitem(sd, 0);
  12689. if (type == 0 || type == 2)
  12690. mail_removezeny(sd, 0);
  12691. }
  12692. /// Request to send mail (CZ_MAIL_SEND).
  12693. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12694. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12695. {
  12696. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12697. if( !chrif_isconnected() )
  12698. return;
  12699. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12700. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12701. return;
  12702. }
  12703. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  12704. }
  12705. /// AUCTION SYSTEM
  12706. /// By Zephyrus
  12707. ///
  12708. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12709. /// 025f <type>.L
  12710. /// type:
  12711. /// 0 = open
  12712. /// 1 = close
  12713. void clif_Auction_openwindow(struct map_session_data *sd)
  12714. {
  12715. int fd = sd->fd;
  12716. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12717. return;
  12718. if( !battle_config.feature_auction )
  12719. return;
  12720. WFIFOHEAD(fd,packet_len(0x25f));
  12721. WFIFOW(fd,0) = 0x25f;
  12722. WFIFOL(fd,2) = 0;
  12723. WFIFOSET(fd,packet_len(0x25f));
  12724. }
  12725. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12726. /// 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 }*
  12727. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12728. {
  12729. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12730. struct auction_data auction;
  12731. struct item_data *item;
  12732. WFIFOHEAD(fd,12 + (count * 83));
  12733. WFIFOW(fd,0) = 0x252;
  12734. WFIFOW(fd,2) = 12 + (count * 83);
  12735. WFIFOL(fd,4) = pages;
  12736. WFIFOL(fd,8) = count;
  12737. for( i = 0; i < count; i++ ) {
  12738. int k = 12 + (i * 83);
  12739. memcpy(&auction, RBUFP(buf,i * len), len);
  12740. WFIFOL(fd,k) = auction.auction_id;
  12741. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12742. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12743. WFIFOW(fd,28+k) = item->view_id;
  12744. else
  12745. WFIFOW(fd,28+k) = auction.item.nameid;
  12746. WFIFOL(fd,30+k) = auction.type;
  12747. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12748. WFIFOB(fd,36+k) = auction.item.identify;
  12749. WFIFOB(fd,37+k) = auction.item.attribute;
  12750. WFIFOB(fd,38+k) = auction.item.refine;
  12751. WFIFOW(fd,39+k) = auction.item.card[0];
  12752. WFIFOW(fd,41+k) = auction.item.card[1];
  12753. WFIFOW(fd,43+k) = auction.item.card[2];
  12754. WFIFOW(fd,45+k) = auction.item.card[3];
  12755. WFIFOL(fd,47+k) = auction.price;
  12756. WFIFOL(fd,51+k) = auction.buynow;
  12757. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12758. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12759. }
  12760. WFIFOSET(fd,WFIFOW(fd,2));
  12761. }
  12762. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12763. /// 0256 <index>.W <result>.B
  12764. /// result:
  12765. /// 0 = success
  12766. /// 1 = failure
  12767. static void clif_Auction_setitem(int fd, int index, bool fail)
  12768. {
  12769. WFIFOHEAD(fd,packet_len(0x256));
  12770. WFIFOW(fd,0) = 0x256;
  12771. WFIFOW(fd,2) = index;
  12772. WFIFOB(fd,4) = fail;
  12773. WFIFOSET(fd,packet_len(0x256));
  12774. }
  12775. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12776. /// 024b <type>.W
  12777. /// type:
  12778. /// 0 = create (any other action in auction window)
  12779. /// 1 = cancel (cancel pressed on register tab)
  12780. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12781. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12782. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12783. if( sd->auction.amount > 0 )
  12784. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12785. sd->auction.amount = 0;
  12786. }
  12787. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12788. /// 024c <index>.W <count>.L
  12789. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12790. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12791. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12792. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12793. struct item_data *item;
  12794. if( !battle_config.feature_auction )
  12795. return;
  12796. if( sd->auction.amount > 0 )
  12797. sd->auction.amount = 0;
  12798. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12799. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12800. return;
  12801. }
  12802. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12803. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12804. return;
  12805. }
  12806. 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) )
  12807. { // Consumable or pets are not allowed
  12808. clif_Auction_setitem(sd->fd, idx, true);
  12809. return;
  12810. }
  12811. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12812. !sd->status.inventory[idx].identify ||
  12813. (sd->status.inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  12814. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12815. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) // Quest Item or something else
  12816. ) {
  12817. clif_Auction_setitem(sd->fd, idx, true);
  12818. return;
  12819. }
  12820. sd->auction.index = idx;
  12821. sd->auction.amount = amount;
  12822. clif_Auction_setitem(fd, idx + 2, false);
  12823. }
  12824. /// Result from an auction action (ZC_AUCTION_RESULT).
  12825. /// 0250 <result>.B
  12826. /// result:
  12827. /// 0 = You have failed to bid into the auction
  12828. /// 1 = You have successfully bid in the auction
  12829. /// 2 = The auction has been canceled
  12830. /// 3 = An auction with at least one bidder cannot be canceled
  12831. /// 4 = You cannot register more than 5 items in an auction at a time
  12832. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12833. /// 6 = You have won the auction
  12834. /// 7 = You have failed to win the auction
  12835. /// 8 = You do not have enough Zeny
  12836. /// 9 = You cannot place more than 5 bids at a time
  12837. void clif_Auction_message(int fd, unsigned char flag)
  12838. {
  12839. WFIFOHEAD(fd,packet_len(0x250));
  12840. WFIFOW(fd,0) = 0x250;
  12841. WFIFOB(fd,2) = flag;
  12842. WFIFOSET(fd,packet_len(0x250));
  12843. }
  12844. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12845. /// 025e <result>.W
  12846. /// result:
  12847. /// 0 = You have ended the auction
  12848. /// 1 = You cannot end the auction
  12849. /// 2 = Auction ID is incorrect
  12850. void clif_Auction_close(int fd, unsigned char flag)
  12851. {
  12852. WFIFOHEAD(fd,packet_len(0x25e));
  12853. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12854. WFIFOW(fd,2) = flag;
  12855. WFIFOSET(fd,packet_len(0x25e));
  12856. }
  12857. /// Request to add an auction (CZ_AUCTION_ADD).
  12858. /// 024d <now money>.L <max money>.L <delete hour>.W
  12859. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12860. {
  12861. struct auction_data auction;
  12862. struct item_data *item;
  12863. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12864. if( !battle_config.feature_auction )
  12865. return;
  12866. auction.price = RFIFOL(fd,info->pos[0]);
  12867. auction.buynow = RFIFOL(fd,info->pos[1]);
  12868. auction.hours = RFIFOW(fd,info->pos[2]);
  12869. // Invalid Situations...
  12870. if( sd->auction.amount < 1 ) {
  12871. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12872. return;
  12873. }
  12874. if( auction.price >= auction.buynow ) {
  12875. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12876. return;
  12877. }
  12878. if( auction.hours < 1 || auction.hours > 48 ) {
  12879. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12880. return;
  12881. }
  12882. // Auction checks...
  12883. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12884. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12885. clif_Auction_message(fd, 2); // The auction has been canceled
  12886. return;
  12887. }
  12888. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12889. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12890. return;
  12891. }
  12892. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12893. auction.buynow = battle_config.auction_maximumprice;
  12894. if( auction.price >= auction.buynow )
  12895. auction.price = auction.buynow - 1;
  12896. }
  12897. auction.auction_id = 0;
  12898. auction.seller_id = sd->status.char_id;
  12899. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12900. auction.buyer_id = 0;
  12901. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12902. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12903. {
  12904. clif_Auction_message(fd, 2); // The auction has been canceled
  12905. return;
  12906. }
  12907. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12908. { // Just in case
  12909. clif_Auction_message(fd, 2); // The auction has been canceled
  12910. return;
  12911. }
  12912. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12913. auction.type = item->type;
  12914. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12915. auction.item.amount = 1;
  12916. auction.timestamp = 0;
  12917. if( !intif_Auction_register(&auction) )
  12918. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12919. else
  12920. {
  12921. int zeny = auction.hours*battle_config.auction_feeperhour;
  12922. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12923. sd->auction.amount = 0;
  12924. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12925. }
  12926. }
  12927. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12928. /// 024e <auction id>.L
  12929. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12930. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12931. intif_Auction_cancel(sd->status.char_id, auction_id);
  12932. }
  12933. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12934. /// 025d <auction id>.L
  12935. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12936. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12937. intif_Auction_close(sd->status.char_id, auction_id);
  12938. }
  12939. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12940. /// 024f <auction id>.L <money>.L
  12941. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12942. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12943. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12944. int bid = RFIFOL(fd,info->pos[1]);
  12945. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12946. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12947. return;
  12948. }
  12949. if( bid <= 0 )
  12950. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12951. else if( bid > sd->status.zeny )
  12952. clif_Auction_message(fd, 8); // You do not have enough zeny
  12953. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12954. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12955. else {
  12956. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12957. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12958. }
  12959. }
  12960. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12961. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12962. /// search type:
  12963. /// 0 = armor
  12964. /// 1 = weapon
  12965. /// 2 = card
  12966. /// 3 = misc
  12967. /// 4 = name search
  12968. /// 5 = auction id search
  12969. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12970. char search_text[NAME_LENGTH];
  12971. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12972. short type = RFIFOW(fd,info->pos[0]);
  12973. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12974. int page = RFIFOW(fd,info->pos[3]);
  12975. if( !battle_config.feature_auction )
  12976. return;
  12977. clif_parse_Auction_cancelreg(fd, sd);
  12978. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  12979. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12980. }
  12981. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12982. /// 025c <type>.W
  12983. /// type:
  12984. /// 0 = sell (own auctions)
  12985. /// 1 = buy (own bids)
  12986. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12987. {
  12988. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12989. if( !battle_config.feature_auction )
  12990. return;
  12991. clif_parse_Auction_cancelreg(fd, sd);
  12992. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12993. }
  12994. /// CASH/POINT SHOP
  12995. ///
  12996. void clif_cashshop_open( struct map_session_data* sd ){
  12997. WFIFOHEAD( sd->fd, 10 );
  12998. WFIFOW( sd->fd, 0 ) = 0x845;
  12999. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13000. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13001. WFIFOSET( sd->fd, 10 );
  13002. }
  13003. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13004. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13005. clif_cashshop_open( sd );
  13006. }
  13007. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13008. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13009. // No need to do anything here
  13010. }
  13011. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13012. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13013. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13014. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13015. int j;
  13016. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  13017. return;
  13018. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13019. WFIFOW(fd, 0) = 0x8c0;
  13020. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13021. WFIFOL(fd, 4) = tab;
  13022. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13023. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13024. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13025. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13026. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13027. }
  13028. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13029. }
  13030. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13031. void clif_cashshop_list( int fd ){
  13032. int tab;
  13033. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13034. int length = 8 + cash_shop_items[tab].count * 6;
  13035. int i, offset;
  13036. WFIFOHEAD( fd, length );
  13037. WFIFOW( fd, 0 ) = 0x8ca;
  13038. WFIFOW( fd, 2 ) = length;
  13039. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13040. WFIFOW( fd, 6 ) = tab;
  13041. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13042. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13043. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13044. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13045. }
  13046. WFIFOSET( fd, length );
  13047. }
  13048. }
  13049. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13050. if( !sd->status.cashshop_sent ) {
  13051. clif_cashshop_list( fd );
  13052. sd->status.cashshop_sent = true;
  13053. }
  13054. }
  13055. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13056. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13057. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13058. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13059. {
  13060. int fd, i, cost[2] = { 0, 0 };
  13061. #if PACKETVER < 20070711
  13062. const int offset = 8;
  13063. #else
  13064. const int offset = 12;
  13065. #endif
  13066. nullpo_retv(sd);
  13067. nullpo_retv(nd);
  13068. npc_shop_currency_type(sd, nd, cost, true);
  13069. fd = sd->fd;
  13070. sd->npc_shopid = nd->bl.id;
  13071. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13072. WFIFOW(fd,0) = 0x287;
  13073. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13074. WFIFOL(fd,4) = cost[0];
  13075. #if PACKETVER >= 20070711
  13076. WFIFOL(fd,8) = cost[1];
  13077. #endif
  13078. for( i = 0; i < nd->u.shop.count; i++ ) {
  13079. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13080. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13081. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13082. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13083. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13084. }
  13085. WFIFOSET(fd,WFIFOW(fd,2));
  13086. }
  13087. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13088. /// 0289 <cash point>.L <error>.W
  13089. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13090. /// error:
  13091. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13092. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13093. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13094. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13095. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13096. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13097. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13098. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13099. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13100. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13101. {
  13102. int fd, cost[2] = { 0, 0 };
  13103. struct npc_data *nd;
  13104. nullpo_retv(sd);
  13105. fd = sd->fd;
  13106. nd = map_id2nd(sd->npc_shopid);
  13107. npc_shop_currency_type(sd, nd, cost, false);
  13108. WFIFOHEAD(fd, packet_len(0x289));
  13109. WFIFOW(fd,0) = 0x289;
  13110. WFIFOL(fd,2) = cost[0];
  13111. #if PACKETVER < 20070711
  13112. WFIFOW(fd,6) = TOW(error);
  13113. #else
  13114. WFIFOL(fd,6) = cost[1];
  13115. WFIFOW(fd,10) = TOW(error);
  13116. #endif
  13117. WFIFOSET(fd, packet_len(0x289));
  13118. }
  13119. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13120. WFIFOHEAD( sd->fd, 16 );
  13121. WFIFOW( sd->fd, 0 ) = 0x849;
  13122. WFIFOL( sd->fd, 2 ) = item_id;
  13123. WFIFOW( sd->fd, 6 ) = result;
  13124. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13125. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13126. WFIFOSET( sd->fd, 16 );
  13127. }
  13128. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13129. /// 0288 <name id>.W <amount>.W
  13130. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13131. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13132. /// 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)
  13133. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13134. struct s_packet_db* info;
  13135. int cmd = RFIFOW(fd,0);
  13136. nullpo_retv(sd);
  13137. info = &packet_db[sd->packet_ver][cmd];
  13138. if( sd->state.trading || !sd->npc_shopid ) {
  13139. clif_cashshop_ack(sd,1);
  13140. return;
  13141. }
  13142. else {
  13143. #if PACKETVER < 20101116
  13144. short nameid = RFIFOW(fd,info->pos[0]);
  13145. short amount = RFIFOW(fd,info->pos[1]);
  13146. int points = RFIFOL(fd,info->pos[2]);
  13147. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13148. #else
  13149. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13150. int len = RFIFOW(fd,info->pos[0]);
  13151. int points = RFIFOL(fd,info->pos[1]);
  13152. int count = RFIFOW(fd,info->pos[2]);
  13153. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13154. if( len < 10 || len != 10 + count * s_itl){
  13155. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13156. return;
  13157. }
  13158. if(cmd==0x848){
  13159. if (cashshop_buylist( sd, points, count, item_list))
  13160. clif_cashshop_ack(sd,0);
  13161. return;
  13162. } else {
  13163. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13164. return;
  13165. }
  13166. #endif
  13167. }
  13168. }
  13169. /// Adoption System
  13170. ///
  13171. /// Adoption message (ZC_BABYMSG).
  13172. /// 0216 <msg>.L
  13173. /// msg:
  13174. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13175. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13176. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13177. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13178. {
  13179. int fd = sd->fd;
  13180. WFIFOHEAD(fd,6);
  13181. WFIFOW(fd,0) = 0x216;
  13182. WFIFOL(fd,2) = type;
  13183. WFIFOSET(fd,6);
  13184. }
  13185. /// Adoption confirmation (ZC_REQ_BABY).
  13186. /// 01f6 <account id>.L <char id>.L <name>.B
  13187. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13188. {
  13189. int fd = sd->fd;
  13190. WFIFOHEAD(fd,34);
  13191. WFIFOW(fd,0) = 0x1f6;
  13192. WFIFOL(fd,2) = src->status.account_id;
  13193. WFIFOL(fd,6) = p_id;
  13194. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  13195. WFIFOSET(fd,34);
  13196. }
  13197. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13198. /// 01f9 <account id>.L
  13199. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13200. {
  13201. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  13202. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13203. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  13204. {
  13205. tsd->adopt_invite = sd->status.account_id;
  13206. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13207. }
  13208. }
  13209. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13210. /// 01f7 <account id>.L <char id>.L <answer>.L
  13211. /// answer:
  13212. /// 0 = rejected
  13213. /// 1 = accepted
  13214. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13215. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13216. int p1_id = RFIFOL(fd,info->pos[0]);
  13217. int p2_id = RFIFOL(fd,info->pos[1]);
  13218. int result = RFIFOL(fd,info->pos[2]);
  13219. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13220. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13221. int pid = sd->adopt_invite;
  13222. sd->adopt_invite = 0;
  13223. if( p1_sd == NULL || p2_sd == NULL )
  13224. return; // Both players need to be online
  13225. if( pid != p1_sd->status.account_id )
  13226. return; // Incorrect values
  13227. if( result == 0 )
  13228. return; // Rejected
  13229. pc_adoption(p1_sd, p2_sd, sd);
  13230. }
  13231. /// Convex Mirror (ZC_BOSS_INFO).
  13232. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13233. /// infoType:
  13234. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13235. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13236. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13237. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13238. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13239. {
  13240. WFIFOHEAD(fd,70);
  13241. memset(WFIFOP(fd,0),0,70);
  13242. WFIFOW(fd,0) = 0x293;
  13243. if( md != NULL ) {
  13244. if( md->bl.prev != NULL ) { // Boss on This Map
  13245. if( flag ) {
  13246. WFIFOB(fd,2) = 1;
  13247. WFIFOL(fd,3) = md->bl.x;
  13248. WFIFOL(fd,7) = md->bl.y;
  13249. } else
  13250. WFIFOB(fd,2) = 2; // First Time
  13251. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13252. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13253. unsigned int seconds;
  13254. int hours, minutes;
  13255. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13256. hours = seconds / (60 * 60);
  13257. seconds = seconds - (60 * 60 * hours);
  13258. minutes = seconds / 60;
  13259. WFIFOB(fd,2) = 3;
  13260. WFIFOW(fd,11) = hours; // Hours
  13261. WFIFOW(fd,13) = minutes; // Minutes
  13262. }
  13263. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  13264. }
  13265. WFIFOSET(fd,70);
  13266. }
  13267. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13268. /// 02d6 <account id>.L
  13269. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13270. {
  13271. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13272. struct map_session_data* tsd = map_id2sd(aid);
  13273. if (!tsd)
  13274. return;
  13275. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13276. clif_viewequip_ack(sd, tsd);
  13277. else
  13278. clif_msg(sd, VIEW_EQUIP_FAIL);
  13279. }
  13280. /// Request to change equip window tick (CZ_CONFIG).
  13281. /// 02d8 <type>.L <flag>.L
  13282. /// type:
  13283. /// 0 = open equip window
  13284. /// flag:
  13285. /// 0 = disabled
  13286. /// 1 = enabled
  13287. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13288. {
  13289. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  13290. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  13291. sd->status.show_equip = flag;
  13292. clif_equiptickack(sd, flag);
  13293. }
  13294. /// Request to change party invitation tick.
  13295. /// value:
  13296. /// 0 = disabled
  13297. /// 1 = enabled
  13298. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13299. {
  13300. bool flag = RFIFOB(fd,6) ? true : false;
  13301. sd->status.allow_party = flag;
  13302. clif_partytickack(sd, flag);
  13303. }
  13304. /// Questlog System [Kevin] [Inkfish]
  13305. ///
  13306. /**
  13307. * Safe check to init packet len & quest num for player.
  13308. * @param def_len
  13309. * @param info_len Length of each quest info.
  13310. * @param avail_quests Avail quests that player has.
  13311. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  13312. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  13313. **/
  13314. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  13315. (*limit_out) = (0xFFFF - def_len) / info_len;
  13316. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  13317. (*len_out) = ((*limit_out) * info_len) + def_len;
  13318. }
  13319. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13320. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13321. /// 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)
  13322. /// 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!
  13323. void clif_quest_send_list(struct map_session_data *sd)
  13324. {
  13325. int fd = sd->fd;
  13326. int i;
  13327. int offset = 8;
  13328. int limit = 0;
  13329. #if PACKETVER >= 20141022
  13330. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  13331. WFIFOHEAD(fd,i);
  13332. WFIFOW(fd, 0) = 0x97a;
  13333. WFIFOL(fd, 4) = limit;
  13334. for (i = 0; i < limit; i++) {
  13335. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13336. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13337. offset += 4;
  13338. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13339. offset++;
  13340. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  13341. offset += 4;
  13342. WFIFOL(fd, offset) = sd->quest_log[i].time;
  13343. offset += 4;
  13344. WFIFOW(fd, offset) = qi->objectives_count;
  13345. offset += 2;
  13346. if( qi->objectives_count > 0 ){
  13347. int j;
  13348. struct mob_db *mob;
  13349. for( j = 0; j < qi->objectives_count; j++ ){
  13350. mob = mob_db(qi->objectives[j].mob);
  13351. WFIFOL(fd, offset) = qi->objectives[j].mob;
  13352. offset += 4;
  13353. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  13354. offset += 2;
  13355. WFIFOW(fd, offset) = qi->objectives[j].count;
  13356. offset += 2;
  13357. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  13358. offset += NAME_LENGTH;
  13359. }
  13360. }
  13361. }
  13362. WFIFOW(fd, 2) = offset;
  13363. WFIFOSET(fd, offset);
  13364. #else
  13365. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  13366. WFIFOHEAD(fd,i);
  13367. WFIFOW(fd, 0) = 0x2b1;
  13368. WFIFOL(fd, 4) = limit;
  13369. for (i = 0; i < limit; i++) {
  13370. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  13371. offset += 4;
  13372. WFIFOB(fd, offset) = sd->quest_log[i].state;
  13373. offset += 1;
  13374. }
  13375. WFIFOW(fd, 2) = offset;
  13376. WFIFOSET(fd, offset);
  13377. #endif
  13378. }
  13379. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13380. /// 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
  13381. void clif_quest_send_mission(struct map_session_data *sd)
  13382. {
  13383. int fd = sd->fd;
  13384. int i, j, limit = 0;
  13385. int len = sd->avail_quests*104+8;
  13386. struct mob_db *mob;
  13387. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  13388. WFIFOHEAD(fd, len);
  13389. WFIFOW(fd, 0) = 0x2b2;
  13390. WFIFOW(fd, 2) = len;
  13391. WFIFOL(fd, 4) = limit;
  13392. for (i = 0; i < limit; i++) {
  13393. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  13394. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13395. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13396. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13397. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13398. for (j = 0 ; j < qi->objectives_count; j++) {
  13399. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13400. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13401. mob = mob_db(qi->objectives[j].mob);
  13402. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13403. }
  13404. }
  13405. WFIFOSET(fd, len);
  13406. }
  13407. /// Notification about a new quest (ZC_ADD_QUEST).
  13408. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13409. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13410. {
  13411. int fd = sd->fd;
  13412. int i;
  13413. struct quest_db *qi = quest_search(qd->quest_id);
  13414. WFIFOHEAD(fd, packet_len(0x2b3));
  13415. WFIFOW(fd, 0) = 0x2b3;
  13416. WFIFOL(fd, 2) = qd->quest_id;
  13417. WFIFOB(fd, 6) = qd->state;
  13418. WFIFOB(fd, 7) = qd->time - qi->time;
  13419. WFIFOL(fd, 11) = qd->time;
  13420. WFIFOW(fd, 15) = qi->objectives_count;
  13421. for (i = 0; i < qi->objectives_count; i++) {
  13422. struct mob_db *mob;
  13423. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13424. WFIFOW(fd, i*30+21) = qd->count[i];
  13425. mob = mob_db(qi->objectives[i].mob);
  13426. safestrncpy(WFIFOCP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13427. }
  13428. WFIFOSET(fd, packet_len(0x2b3));
  13429. }
  13430. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13431. /// 02b4 <quest id>.L
  13432. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  13433. {
  13434. int fd = sd->fd;
  13435. WFIFOHEAD(fd, packet_len(0x2b4));
  13436. WFIFOW(fd, 0) = 0x2b4;
  13437. WFIFOL(fd, 2) = quest_id;
  13438. WFIFOSET(fd, packet_len(0x2b4));
  13439. }
  13440. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13441. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13442. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  13443. {
  13444. int fd = sd->fd;
  13445. int i;
  13446. struct quest_db *qi = quest_search(qd->quest_id);
  13447. int len = qi->objectives_count * 12 + 6;
  13448. WFIFOHEAD(fd, len);
  13449. WFIFOW(fd, 0) = 0x2b5;
  13450. WFIFOW(fd, 2) = len;
  13451. WFIFOW(fd, 4) = qi->objectives_count;
  13452. for (i = 0; i < qi->objectives_count; i++) {
  13453. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  13454. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  13455. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  13456. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  13457. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  13458. }
  13459. }
  13460. WFIFOSET(fd, len);
  13461. }
  13462. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13463. /// 02b6 <quest id>.L <active>.B
  13464. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  13465. {
  13466. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13467. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13468. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13469. }
  13470. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13471. /// 02b7 <quest id>.L <active>.B
  13472. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  13473. {
  13474. int fd = sd->fd;
  13475. WFIFOHEAD(fd, packet_len(0x2b7));
  13476. WFIFOW(fd, 0) = 0x2b7;
  13477. WFIFOL(fd, 2) = quest_id;
  13478. WFIFOB(fd, 6) = active;
  13479. WFIFOSET(fd, packet_len(0x2b7));
  13480. }
  13481. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13482. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  13483. /// effect:
  13484. /// 0 = none
  13485. /// 1 = exclamation mark icon
  13486. /// 2 = question mark icon
  13487. /// color:
  13488. /// 0 = yellow
  13489. /// 1 = orange
  13490. /// 2 = green
  13491. /// 3 = purple
  13492. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  13493. {
  13494. #if PACKETVER >= 20090218
  13495. int fd = sd->fd;
  13496. WFIFOHEAD(fd, packet_len(0x446));
  13497. WFIFOW(fd, 0) = 0x446;
  13498. WFIFOL(fd, 2) = bl->id;
  13499. WFIFOW(fd, 6) = bl->x;
  13500. WFIFOW(fd, 8) = bl->y;
  13501. WFIFOW(fd, 10) = effect;
  13502. WFIFOW(fd, 12) = color;
  13503. WFIFOSET(fd, packet_len(0x446));
  13504. #endif
  13505. }
  13506. /// Mercenary System
  13507. ///
  13508. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13509. /// 02a2 <var id>.W <value>.L
  13510. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13511. {
  13512. struct mercenary_data *md;
  13513. struct status_data *status;
  13514. int fd;
  13515. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13516. return;
  13517. fd = sd->fd;
  13518. status = &md->battle_status;
  13519. WFIFOHEAD(fd,packet_len(0x2a2));
  13520. WFIFOW(fd,0) = 0x2a2;
  13521. WFIFOW(fd,2) = type;
  13522. switch( type ) {
  13523. case SP_ATK1:
  13524. {
  13525. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13526. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13527. }
  13528. break;
  13529. case SP_MATK1:
  13530. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  13531. break;
  13532. case SP_HIT:
  13533. WFIFOL(fd,4) = status->hit;
  13534. break;
  13535. case SP_CRITICAL:
  13536. WFIFOL(fd,4) = status->cri/10;
  13537. break;
  13538. case SP_DEF1:
  13539. WFIFOL(fd,4) = status->def;
  13540. break;
  13541. case SP_MDEF1:
  13542. WFIFOL(fd,4) = status->mdef;
  13543. break;
  13544. case SP_MERCFLEE:
  13545. WFIFOL(fd,4) = status->flee;
  13546. break;
  13547. case SP_ASPD:
  13548. WFIFOL(fd,4) = status->amotion;
  13549. break;
  13550. case SP_HP:
  13551. WFIFOL(fd,4) = status->hp;
  13552. break;
  13553. case SP_MAXHP:
  13554. WFIFOL(fd,4) = status->max_hp;
  13555. break;
  13556. case SP_SP:
  13557. WFIFOL(fd,4) = status->sp;
  13558. break;
  13559. case SP_MAXSP:
  13560. WFIFOL(fd,4) = status->max_sp;
  13561. break;
  13562. case SP_MERCKILLS:
  13563. WFIFOL(fd,4) = md->mercenary.kill_count;
  13564. break;
  13565. case SP_MERCFAITH:
  13566. WFIFOL(fd,4) = mercenary_get_faith(md);
  13567. break;
  13568. }
  13569. WFIFOSET(fd,packet_len(0x2a2));
  13570. }
  13571. /// Mercenary base status data (ZC_MER_INIT).
  13572. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13573. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13574. /// <calls>.L <kills>.L <atk range>.W
  13575. void clif_mercenary_info(struct map_session_data *sd)
  13576. {
  13577. int fd;
  13578. struct mercenary_data *md;
  13579. struct status_data *status;
  13580. int atk;
  13581. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  13582. return;
  13583. fd = sd->fd;
  13584. status = &md->battle_status;
  13585. WFIFOHEAD(fd,packet_len(0x29b));
  13586. WFIFOW(fd,0) = 0x29b;
  13587. WFIFOL(fd,2) = md->bl.id;
  13588. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13589. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13590. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13591. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  13592. WFIFOW(fd,10) = status->hit;
  13593. WFIFOW(fd,12) = status->cri/10;
  13594. WFIFOW(fd,14) = status->def;
  13595. WFIFOW(fd,16) = status->mdef;
  13596. WFIFOW(fd,18) = status->flee;
  13597. WFIFOW(fd,20) = status->amotion;
  13598. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  13599. WFIFOW(fd,46) = md->db->lv;
  13600. WFIFOL(fd,48) = status->hp;
  13601. WFIFOL(fd,52) = status->max_hp;
  13602. WFIFOL(fd,56) = status->sp;
  13603. WFIFOL(fd,60) = status->max_sp;
  13604. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13605. WFIFOW(fd,68) = mercenary_get_faith(md);
  13606. WFIFOL(fd,70) = mercenary_get_calls(md);
  13607. WFIFOL(fd,74) = md->mercenary.kill_count;
  13608. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13609. WFIFOSET(fd,packet_len(0x29b));
  13610. }
  13611. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13612. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13613. void clif_mercenary_skillblock(struct map_session_data *sd)
  13614. {
  13615. struct mercenary_data *md;
  13616. int fd, i, len = 4;
  13617. if( sd == NULL || (md = sd->md) == NULL )
  13618. return;
  13619. fd = sd->fd;
  13620. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13621. WFIFOW(fd,0) = 0x29d;
  13622. for( i = 0; i < MAX_MERCSKILL; i++ )
  13623. {
  13624. uint16 id;
  13625. short idx = -1;
  13626. if( (id = md->db->skill[i].id) == 0 )
  13627. continue;
  13628. if ((idx = mercenary_skill_get_index(id)) == -1)
  13629. continue;
  13630. WFIFOW(fd,len) = id;
  13631. WFIFOL(fd,len+2) = skill_get_inf(id);
  13632. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  13633. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  13634. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  13635. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13636. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13637. len += 37;
  13638. }
  13639. WFIFOW(fd,2) = len;
  13640. WFIFOSET(fd,len);
  13641. }
  13642. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13643. /// 029f <command>.B
  13644. /// 1 = mercenary information
  13645. /// 2 = delete
  13646. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13647. {
  13648. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13649. if( sd->md == NULL )
  13650. return;
  13651. if( option == 2 ) mercenary_delete(sd->md, 2);
  13652. }
  13653. /// Mercenary Message
  13654. /// message:
  13655. /// 0 = Mercenary soldier's duty hour is over.
  13656. /// 1 = Your mercenary soldier has been killed.
  13657. /// 2 = Your mercenary soldier has been fired.
  13658. /// 3 = Your mercenary soldier has ran away.
  13659. void clif_mercenary_message(struct map_session_data* sd, int message){
  13660. clif_msg(sd, MERC_MSG_BASE + message);
  13661. }
  13662. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13663. /// 0298 <name id>.W <seconds>.L
  13664. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13665. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13666. WFIFOHEAD(fd,packet_len(0x298));
  13667. WFIFOW(fd,0) = 0x298;
  13668. WFIFOW(fd,2) = nameid;
  13669. WFIFOL(fd,4) = seconds;
  13670. WFIFOSET(fd,packet_len(0x298));
  13671. }
  13672. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13673. /// 0299 <index>.W <name id>.W
  13674. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13675. { // '<ItemName>' item has been deleted from the Inventory
  13676. WFIFOHEAD(fd,packet_len(0x299));
  13677. WFIFOW(fd,0) = 0x299;
  13678. WFIFOW(fd,2) = index+2;
  13679. WFIFOW(fd,4) = nameid;
  13680. WFIFOSET(fd,packet_len(0x299));
  13681. }
  13682. /// Book Reading (ZC_READ_BOOK).
  13683. /// 0294 <book id>.L <page>.L
  13684. void clif_readbook(int fd, int book_id, int page)
  13685. {
  13686. WFIFOHEAD(fd,packet_len(0x294));
  13687. WFIFOW(fd,0) = 0x294;
  13688. WFIFOL(fd,2) = book_id;
  13689. WFIFOL(fd,6) = page;
  13690. WFIFOSET(fd,packet_len(0x294));
  13691. }
  13692. /// Battlegrounds
  13693. ///
  13694. /// Updates HP bar of a camp member.
  13695. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  13696. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  13697. void clif_bg_hp(struct map_session_data *sd) {
  13698. #if PACKETVER < 20140613
  13699. unsigned char buf[34];
  13700. const int cmd = 0x2e0;
  13701. #else
  13702. unsigned char buf[14];
  13703. const int cmd = 0xa0e;
  13704. #endif
  13705. nullpo_retv(sd);
  13706. WBUFW(buf,0) = cmd;
  13707. WBUFL(buf,2) = sd->status.account_id;
  13708. #if PACKETVER < 20140613
  13709. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  13710. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  13711. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13712. WBUFW(buf,32) = 100;
  13713. } else {
  13714. WBUFW(buf,30) = sd->battle_status.hp;
  13715. WBUFW(buf,32) = sd->battle_status.max_hp;
  13716. }
  13717. #else
  13718. if( sd->battle_status.max_hp > INT32_MAX ) {
  13719. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13720. WBUFL(buf,10) = 100;
  13721. } else {
  13722. WBUFL(buf,6) = sd->battle_status.hp;
  13723. WBUFL(buf,10) = sd->battle_status.max_hp;
  13724. }
  13725. #endif
  13726. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13727. }
  13728. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13729. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13730. void clif_bg_xy(struct map_session_data *sd)
  13731. {
  13732. unsigned char buf[36];
  13733. nullpo_retv(sd);
  13734. WBUFW(buf,0)=0x2df;
  13735. WBUFL(buf,2)=sd->status.account_id;
  13736. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  13737. WBUFW(buf,30)=sd->status.class_;
  13738. WBUFW(buf,32)=sd->bl.x;
  13739. WBUFW(buf,34)=sd->bl.y;
  13740. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13741. }
  13742. void clif_bg_xy_remove(struct map_session_data *sd)
  13743. {
  13744. unsigned char buf[36];
  13745. nullpo_retv(sd);
  13746. WBUFW(buf,0)=0x2df;
  13747. WBUFL(buf,2)=sd->status.account_id;
  13748. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13749. WBUFW(buf,30)=0;
  13750. WBUFW(buf,32)=-1;
  13751. WBUFW(buf,34)=-1;
  13752. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13753. }
  13754. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13755. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13756. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13757. {
  13758. struct map_session_data *sd;
  13759. unsigned char *buf;
  13760. if( (sd = bg_getavailablesd(bg)) == NULL )
  13761. return;
  13762. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13763. WBUFW(buf,0) = 0x2dc;
  13764. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13765. WBUFL(buf,4) = src_id;
  13766. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  13767. memcpy(WBUFP(buf,32), mes, len);
  13768. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13769. if( buf )
  13770. aFree(buf);
  13771. }
  13772. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13773. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13774. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13775. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  13776. if( !clif_process_message( sd, false, name, message, output ) )
  13777. return;
  13778. bg_send_message(sd, output, strlen(output) );
  13779. }
  13780. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13781. /// 02de <camp A points>.W <camp B points>.W
  13782. void clif_bg_updatescore(int16 m)
  13783. {
  13784. struct block_list bl;
  13785. unsigned char buf[6];
  13786. bl.id = 0;
  13787. bl.type = BL_NUL;
  13788. bl.m = m;
  13789. WBUFW(buf,0) = 0x2de;
  13790. WBUFW(buf,2) = map[m].bgscore_lion;
  13791. WBUFW(buf,4) = map[m].bgscore_eagle;
  13792. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13793. }
  13794. void clif_bg_updatescore_single(struct map_session_data *sd)
  13795. {
  13796. int fd;
  13797. nullpo_retv(sd);
  13798. fd = sd->fd;
  13799. WFIFOHEAD(fd,packet_len(0x2de));
  13800. WFIFOW(fd,0) = 0x2de;
  13801. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13802. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13803. WFIFOSET(fd,packet_len(0x2de));
  13804. }
  13805. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13806. /// 02dd <account id>.L <name>.24B <camp>.W
  13807. void clif_sendbgemblem_area(struct map_session_data *sd)
  13808. {
  13809. unsigned char buf[33];
  13810. nullpo_retv(sd);
  13811. WBUFW(buf, 0) = 0x2dd;
  13812. WBUFL(buf,2) = sd->bl.id;
  13813. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13814. WBUFW(buf,30) = sd->bg_id;
  13815. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13816. }
  13817. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13818. {
  13819. nullpo_retv(sd);
  13820. WFIFOHEAD(fd,32);
  13821. WFIFOW(fd,0) = 0x2dd;
  13822. WFIFOL(fd,2) = sd->bl.id;
  13823. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  13824. WFIFOW(fd,30) = sd->bg_id;
  13825. WFIFOSET(fd,packet_len(0x2dd));
  13826. }
  13827. /// Custom Fonts (ZC_NOTIFY_FONT).
  13828. /// 02ef <account_id>.L <font id>.W
  13829. void clif_font(struct map_session_data *sd)
  13830. {
  13831. #if PACKETVER >= 20080102
  13832. unsigned char buf[8];
  13833. nullpo_retv(sd);
  13834. WBUFW(buf,0) = 0x2ef;
  13835. WBUFL(buf,2) = sd->bl.id;
  13836. WBUFW(buf,6) = sd->status.font;
  13837. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13838. #endif
  13839. }
  13840. /// Required to start the instancing information window on Client
  13841. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  13842. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  13843. void clif_instance_create(unsigned short instance_id, int num)
  13844. {
  13845. #if PACKETVER >= 20071128
  13846. struct instance_db *db = NULL;
  13847. struct map_session_data *sd = NULL;
  13848. enum send_target target = PARTY;
  13849. unsigned char buf[65];
  13850. instance_getsd(instance_id, &sd, &target);
  13851. if (!sd)
  13852. return;
  13853. db = instance_searchtype_db(instance_data[instance_id].type);
  13854. if (!db)
  13855. return;
  13856. WBUFW(buf,0) = 0x2cb;
  13857. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  13858. WBUFW(buf,63) = num;
  13859. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  13860. #endif
  13861. return;
  13862. }
  13863. /// To announce Instancing queue creation if no maps available
  13864. /// S 0x2cc <Standby Position>.W
  13865. void clif_instance_changewait(unsigned short instance_id, int num)
  13866. {
  13867. #if PACKETVER >= 20071128
  13868. struct map_session_data *sd = NULL;
  13869. enum send_target target = PARTY;
  13870. unsigned char buf[4];
  13871. instance_getsd(instance_id, &sd, &target);
  13872. if (!sd)
  13873. return;
  13874. WBUFW(buf,0) = 0x2cc;
  13875. WBUFW(buf,2) = num;
  13876. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  13877. #endif
  13878. return;
  13879. }
  13880. /// Notify the current status to members
  13881. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  13882. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  13883. {
  13884. #if PACKETVER >= 20071128
  13885. struct instance_db *db = NULL;
  13886. struct map_session_data *sd = NULL;
  13887. enum send_target target = PARTY;
  13888. unsigned char buf[71];
  13889. instance_getsd(instance_id, &sd, &target);
  13890. if (!sd)
  13891. return;
  13892. db = instance_searchtype_db(instance_data[instance_id].type);
  13893. if (!db)
  13894. return;
  13895. WBUFW(buf,0) = 0x2cd;
  13896. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  13897. WBUFL(buf,63) = limit1;
  13898. WBUFL(buf,67) = limit2;
  13899. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  13900. #endif
  13901. return;
  13902. }
  13903. /// Notify a status change to members
  13904. /// S 0x2ce <Message ID>.L
  13905. /// 0 = Notification (EnterLimitDate update?)
  13906. /// 1 = The Memorial Dungeon expired; it has been destroyed
  13907. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  13908. /// 3 = The Memorial Dungeon has been removed.
  13909. /// 4 = Create failure (removes the instance window)
  13910. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  13911. {
  13912. #if PACKETVER >= 20071128
  13913. struct map_session_data *sd = NULL;
  13914. enum send_target target = PARTY;
  13915. unsigned char buf[10];
  13916. instance_getsd(instance_id, &sd, &target);
  13917. if (!sd)
  13918. return;
  13919. WBUFW(buf,0) = 0x2ce;
  13920. WBUFL(buf,2) = type;
  13921. WBUFL(buf,6) = limit;
  13922. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  13923. #endif
  13924. return;
  13925. }
  13926. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13927. /// 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
  13928. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13929. {
  13930. #if PACKETVER >= 20071002
  13931. unsigned char buf[22];
  13932. struct item_data* id = itemdb_search(item_data->nameid);
  13933. WBUFW(buf,0) = 0x2b8;
  13934. WBUFL(buf,2) = sd->status.account_id;
  13935. WBUFW(buf,6) = item_data->nameid;
  13936. WBUFB(buf,8) = item_data->identify;
  13937. WBUFB(buf,9) = item_data->attribute;
  13938. WBUFB(buf,10) = item_data->refine;
  13939. clif_addcards(WBUFP(buf,11), item_data);
  13940. WBUFW(buf,19) = id->equip; // equip location
  13941. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13942. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13943. #endif
  13944. }
  13945. /** Display gained exp (ZC_NOTIFY_EXP).
  13946. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13947. * amount: INT32_MIN ~ INT32_MAX
  13948. * var id:
  13949. * SP_BASEEXP, SP_JOBEXP
  13950. * exp type:
  13951. * 0 = normal exp gained/lost
  13952. * 1 = quest exp gained/lost
  13953. * @param sd Player
  13954. * @param exp EXP value gained/loss
  13955. * @param type SP_BASEEXP, SP_JOBEXP
  13956. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  13957. * @param lost True:if lossing EXP
  13958. */
  13959. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  13960. {
  13961. int fd;
  13962. nullpo_retv(sd);
  13963. fd = sd->fd;
  13964. WFIFOHEAD(fd, packet_len(0x7f6));
  13965. WFIFOW(fd,0) = 0x7f6;
  13966. WFIFOL(fd,2) = sd->bl.id;
  13967. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  13968. WFIFOW(fd,10) = type;
  13969. WFIFOW(fd,12) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  13970. WFIFOSET(fd,packet_len(0x7f6));
  13971. }
  13972. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13973. /// type:
  13974. /// 0 = Displays 'value' for 5 seconds.
  13975. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13976. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13977. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13978. /// value:
  13979. /// 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).
  13980. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13981. {
  13982. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13983. WFIFOW(sd->fd,0) = 0x1b1;
  13984. WFIFOB(sd->fd,2) = type;
  13985. WFIFOL(sd->fd,3) = value;
  13986. WFIFOSET(sd->fd, packet_len(0x1b1));
  13987. }
  13988. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13989. /// 021d <state>.L
  13990. /// state:
  13991. /// 0 = Full effects
  13992. /// 1 = Reduced effects
  13993. ///
  13994. /// NOTE: The state is used on Aegis for sending skill unit packet
  13995. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13996. /// whenever possible. Due to the way the decision check is
  13997. /// constructed, this state tracking was rendered useless,
  13998. /// as the only skill unit, that is sent with 0x1c9 is
  13999. /// Graffiti.
  14000. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14001. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14002. sd->state.lesseffect = ( isLess != 0 );
  14003. }
  14004. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14005. /// S 0945 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* RagexeRE 2012-04-10a)
  14006. /// S 0281 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_* Ragexe 2013-08-07)
  14007. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14008. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14009. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14010. int type = RFIFOL(fd,info->pos[1]);
  14011. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14012. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14013. if( sd->state.trading || sd->npc_shopid )
  14014. return;
  14015. if( flag == 0 || n == 0) {
  14016. clif_menuskill_clear(sd);
  14017. return; // Canceled by player.
  14018. }
  14019. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14020. clif_menuskill_clear(sd);
  14021. return; // Prevent hacking.
  14022. }
  14023. switch( type ) {
  14024. case 0: // Change Material
  14025. skill_changematerial(sd,n,item_list);
  14026. break;
  14027. case 1: // Level 1: Pure to Rough
  14028. case 2: // Level 2: Rough to Pure
  14029. skill_elementalanalysis(sd,n,type,item_list);
  14030. break;
  14031. }
  14032. clif_menuskill_clear(sd);
  14033. return;
  14034. }
  14035. /*==========================================
  14036. * Elemental System
  14037. *==========================================*/
  14038. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14039. struct elemental_data *ed;
  14040. struct status_data *status;
  14041. int fd;
  14042. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14043. return;
  14044. fd = sd->fd;
  14045. status = &ed->battle_status;
  14046. WFIFOHEAD(fd,8);
  14047. WFIFOW(fd,0) = 0x81e;
  14048. WFIFOW(fd,2) = type;
  14049. switch( type ) {
  14050. case SP_HP:
  14051. WFIFOL(fd,4) = status->hp;
  14052. break;
  14053. case SP_MAXHP:
  14054. WFIFOL(fd,4) = status->max_hp;
  14055. break;
  14056. case SP_SP:
  14057. WFIFOL(fd,4) = status->sp;
  14058. break;
  14059. case SP_MAXSP:
  14060. WFIFOL(fd,4) = status->max_sp;
  14061. break;
  14062. }
  14063. WFIFOSET(fd,8);
  14064. }
  14065. void clif_elemental_info(struct map_session_data *sd) {
  14066. int fd;
  14067. struct elemental_data *ed;
  14068. struct status_data *status;
  14069. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14070. return;
  14071. fd = sd->fd;
  14072. status = &ed->battle_status;
  14073. WFIFOHEAD(fd,22);
  14074. WFIFOW(fd, 0) = 0x81d;
  14075. WFIFOL(fd, 2) = ed->bl.id;
  14076. WFIFOL(fd, 6) = status->hp;
  14077. WFIFOL(fd,10) = status->max_hp;
  14078. WFIFOL(fd,14) = status->sp;
  14079. WFIFOL(fd,18) = status->max_sp;
  14080. WFIFOSET(fd,22);
  14081. }
  14082. /// Buying Store System
  14083. ///
  14084. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14085. /// 0810 <slots>.B
  14086. void clif_buyingstore_open(struct map_session_data* sd)
  14087. {
  14088. int fd = sd->fd;
  14089. WFIFOHEAD(fd,packet_len(0x810));
  14090. WFIFOW(fd,0) = 0x810;
  14091. WFIFOB(fd,2) = sd->buyingstore.slots;
  14092. WFIFOSET(fd,packet_len(0x810));
  14093. }
  14094. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14095. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14096. /// result:
  14097. /// 0 = cancel
  14098. /// 1 = open
  14099. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14100. {
  14101. const unsigned int blocksize = 8;
  14102. uint8* itemlist;
  14103. char storename[MESSAGE_SIZE];
  14104. unsigned char result;
  14105. int zenylimit;
  14106. unsigned int count, packet_len;
  14107. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14108. packet_len = RFIFOW(fd,info->pos[0]);
  14109. // TODO: Make this check global for all variable length packets.
  14110. if( packet_len < 89 )
  14111. {// minimum packet length
  14112. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14113. return;
  14114. }
  14115. zenylimit = RFIFOL(fd,info->pos[1]);
  14116. result = RFIFOL(fd,info->pos[2]);
  14117. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  14118. itemlist = RFIFOP(fd,info->pos[4]);
  14119. // so that buyingstore_create knows, how many elements it has access to
  14120. packet_len-= info->pos[4];
  14121. if( packet_len%blocksize )
  14122. {
  14123. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14124. return;
  14125. }
  14126. count = packet_len/blocksize;
  14127. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14128. }
  14129. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14130. /// 0812 <result>.W <total weight>.L
  14131. /// result:
  14132. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14133. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14134. /// 8 = "No sale (purchase) information available." (0x705)
  14135. /// ? = nothing
  14136. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14137. {
  14138. int fd = sd->fd;
  14139. WFIFOHEAD(fd,packet_len(0x812));
  14140. WFIFOW(fd,0) = 0x812;
  14141. WFIFOW(fd,2) = result;
  14142. WFIFOL(fd,4) = weight;
  14143. WFIFOSET(fd,packet_len(0x812));
  14144. }
  14145. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14146. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14147. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14148. {
  14149. int fd = sd->fd;
  14150. unsigned int i;
  14151. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14152. WFIFOW(fd,0) = 0x813;
  14153. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14154. WFIFOL(fd,4) = sd->bl.id;
  14155. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14156. for( i = 0; i < sd->buyingstore.slots; i++ )
  14157. {
  14158. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14159. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14160. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14161. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14162. }
  14163. WFIFOSET(fd,WFIFOW(fd,2));
  14164. }
  14165. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14166. /// 0814 <account id>.L <store name>.80B
  14167. void clif_buyingstore_entry(struct map_session_data* sd)
  14168. {
  14169. uint8 buf[MESSAGE_SIZE+6];
  14170. WBUFW(buf,0) = 0x814;
  14171. WBUFL(buf,2) = sd->bl.id;
  14172. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  14173. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14174. }
  14175. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14176. {
  14177. int fd = sd->fd;
  14178. WFIFOHEAD(fd,packet_len(0x814));
  14179. WFIFOW(fd,0) = 0x814;
  14180. WFIFOL(fd,2) = pl_sd->bl.id;
  14181. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14182. WFIFOSET(fd,packet_len(0x814));
  14183. }
  14184. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14185. /// 0815
  14186. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14187. {
  14188. buyingstore_close(sd);
  14189. }
  14190. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14191. /// 0816 <account id>.L
  14192. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14193. {
  14194. uint8 buf[6];
  14195. WBUFW(buf,0) = 0x816;
  14196. WBUFL(buf,2) = sd->bl.id;
  14197. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14198. }
  14199. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14200. {
  14201. int fd = sd->fd;
  14202. WFIFOHEAD(fd,packet_len(0x816));
  14203. WFIFOW(fd,0) = 0x816;
  14204. WFIFOL(fd,2) = pl_sd->bl.id;
  14205. WFIFOSET(fd,packet_len(0x816));
  14206. }
  14207. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14208. /// 0817 <account id>.L
  14209. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14210. {
  14211. uint32 account_id;
  14212. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  14213. buyingstore_open(sd, account_id);
  14214. }
  14215. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14216. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14217. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14218. {
  14219. int fd = sd->fd;
  14220. unsigned int i;
  14221. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14222. WFIFOW(fd,0) = 0x818;
  14223. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14224. WFIFOL(fd,4) = pl_sd->bl.id;
  14225. WFIFOL(fd,8) = pl_sd->buyer_id;
  14226. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14227. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14228. {
  14229. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14230. 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.
  14231. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14232. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14233. }
  14234. WFIFOSET(fd,WFIFOW(fd,2));
  14235. }
  14236. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14237. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14238. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14239. {
  14240. const unsigned int blocksize = 6;
  14241. uint8* itemlist;
  14242. uint32 account_id;
  14243. unsigned int count, packet_len, buyer_id;
  14244. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14245. packet_len = RFIFOW(fd,info->pos[0]);
  14246. if( packet_len < 12 )
  14247. {// minimum packet length
  14248. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14249. return;
  14250. }
  14251. account_id = RFIFOL(fd,info->pos[1]);
  14252. buyer_id = RFIFOL(fd,info->pos[2]);
  14253. itemlist = RFIFOP(fd,info->pos[3]);
  14254. // so that buyingstore_trade knows, how many elements it has access to
  14255. packet_len-= info->pos[3];
  14256. if( packet_len%blocksize )
  14257. {
  14258. 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);
  14259. return;
  14260. }
  14261. count = packet_len/blocksize;
  14262. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14263. }
  14264. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14265. /// 081a <result>.W
  14266. /// result:
  14267. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14268. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14269. /// ? = nothing
  14270. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14271. {
  14272. int fd = sd->fd;
  14273. WFIFOHEAD(fd,packet_len(0x81a));
  14274. WFIFOW(fd,0) = 0x81a;
  14275. WFIFOW(fd,2) = result;
  14276. WFIFOSET(fd,packet_len(0x81a));
  14277. }
  14278. /// Updates the zeny limit and an item in the buying store item list.
  14279. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  14280. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  14281. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  14282. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  14283. const int cmd = 0x81b;
  14284. #else
  14285. const int cmd = 0x9e6;
  14286. #endif
  14287. int offset = 0;
  14288. int fd = sd->fd;
  14289. WFIFOHEAD(fd,packet_len(cmd));
  14290. WFIFOW(fd,0) = cmd;
  14291. WFIFOW(fd,2) = nameid;
  14292. WFIFOW(fd,4) = amount; // amount of nameid received
  14293. #if PACKETVER >= 20141016
  14294. WFIFOL(fd,6) = zeny; // zeny
  14295. offset += 4;
  14296. #endif
  14297. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  14298. #if PACKETVER >= 20141016
  14299. WFIFOL(fd,10+offset) = char_id; // GID
  14300. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  14301. #endif
  14302. WFIFOSET(fd,packet_len(cmd));
  14303. }
  14304. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  14305. /// 081c <index>.W <amount>.W <price>.L
  14306. /// message:
  14307. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  14308. ///
  14309. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  14310. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  14311. {
  14312. int fd = sd->fd;
  14313. WFIFOHEAD(fd,packet_len(0x81c));
  14314. WFIFOW(fd,0) = 0x81c;
  14315. WFIFOW(fd,2) = index+2;
  14316. WFIFOW(fd,4) = amount;
  14317. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  14318. WFIFOSET(fd,packet_len(0x81c));
  14319. }
  14320. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  14321. /// 0824 <result>.W <name id>.W
  14322. /// result:
  14323. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  14324. /// 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)
  14325. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  14326. /// ? = nothing
  14327. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  14328. {
  14329. int fd = sd->fd;
  14330. WFIFOHEAD(fd,packet_len(0x824));
  14331. WFIFOW(fd,0) = 0x824;
  14332. WFIFOW(fd,2) = result;
  14333. WFIFOW(fd,4) = nameid;
  14334. WFIFOSET(fd,packet_len(0x824));
  14335. }
  14336. /// Search Store Info System
  14337. ///
  14338. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  14339. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  14340. /// type:
  14341. /// 0 = Vending
  14342. /// 1 = Buying Store
  14343. ///
  14344. /// NOTE: The client determines the item ids by specifying a name and optionally,
  14345. /// amount of card slots. If the client does not know about the item it
  14346. /// cannot be searched.
  14347. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  14348. {
  14349. const unsigned int blocksize = 2;
  14350. const uint8* itemlist;
  14351. const uint8* cardlist;
  14352. unsigned char type;
  14353. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  14354. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14355. packet_len = RFIFOW(fd,info->pos[0]);
  14356. if( packet_len < 15 )
  14357. {// minimum packet length
  14358. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  14359. return;
  14360. }
  14361. type = RFIFOB(fd,info->pos[1]);
  14362. max_price = RFIFOL(fd,info->pos[2]);
  14363. min_price = RFIFOL(fd,info->pos[3]);
  14364. item_count = RFIFOB(fd,info->pos[4]);
  14365. card_count = RFIFOB(fd,info->pos[5]);
  14366. itemlist = RFIFOP(fd,info->pos[6]);
  14367. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  14368. // check, if there is enough data for the claimed count of items
  14369. packet_len-= info->pos[6];
  14370. if( packet_len%blocksize )
  14371. {
  14372. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14373. return;
  14374. }
  14375. count = packet_len/blocksize;
  14376. if( count < item_count+card_count )
  14377. {
  14378. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  14379. return;
  14380. }
  14381. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  14382. }
  14383. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  14384. /// 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 }*
  14385. /// is first page:
  14386. /// 0 = appends to existing results
  14387. /// 1 = clears previous results before displaying this result set
  14388. /// is next page:
  14389. /// 0 = no "next" label
  14390. /// 1 = "next" label to retrieve more results
  14391. void clif_search_store_info_ack(struct map_session_data* sd)
  14392. {
  14393. #if PACKETVER >= 20150226
  14394. const unsigned int blocksize = MESSAGE_SIZE+26+5*MAX_ITEM_RDM_OPT;
  14395. #else
  14396. const unsigned int blocksize = MESSAGE_SIZE+26;
  14397. #endif
  14398. int fd = sd->fd;
  14399. unsigned int i, start, end;
  14400. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  14401. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  14402. WFIFOHEAD(fd,7+(end-start)*blocksize);
  14403. WFIFOW(fd,0) = 0x836;
  14404. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  14405. WFIFOB(fd,4) = !sd->searchstore.pages;
  14406. WFIFOB(fd,5) = searchstore_querynext(sd);
  14407. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14408. for( i = start; i < end; i++ ) {
  14409. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  14410. struct item it;
  14411. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  14412. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  14413. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  14414. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  14415. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  14416. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  14417. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  14418. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  14419. // make-up an item for clif_addcards
  14420. memset(&it, 0, sizeof(it));
  14421. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  14422. it.nameid = ssitem->nameid;
  14423. it.amount = ssitem->amount;
  14424. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  14425. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  14426. }
  14427. WFIFOSET(fd,WFIFOW(fd,2));
  14428. }
  14429. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  14430. /// 0837 <reason>.B
  14431. /// reason:
  14432. /// 0 = "No matching stores were found." (0x70b)
  14433. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  14434. /// 2 = "You cannot search anymore." (0x706)
  14435. /// 3 = "You cannot search yet." (0x708)
  14436. /// 4 = "No sale (purchase) information available." (0x705)
  14437. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  14438. {
  14439. int fd = sd->fd;
  14440. WFIFOHEAD(fd,packet_len(0x837));
  14441. WFIFOW(fd,0) = 0x837;
  14442. WFIFOB(fd,2) = reason;
  14443. WFIFOSET(fd,packet_len(0x837));
  14444. }
  14445. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14446. /// 0838
  14447. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14448. {
  14449. searchstore_next(sd);
  14450. }
  14451. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14452. /// 083a <type>.W <remaining uses>.B
  14453. /// type:
  14454. /// 0 = Search Stores
  14455. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14456. void clif_open_search_store_info(struct map_session_data* sd)
  14457. {
  14458. int fd = sd->fd;
  14459. WFIFOHEAD(fd,packet_len(0x83a));
  14460. WFIFOW(fd,0) = 0x83a;
  14461. WFIFOW(fd,2) = sd->searchstore.effect;
  14462. #if PACKETVER > 20100701
  14463. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  14464. #endif
  14465. WFIFOSET(fd,packet_len(0x83a));
  14466. }
  14467. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14468. /// 083b
  14469. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14470. {
  14471. searchstore_close(sd);
  14472. }
  14473. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14474. /// 083c <account id>.L <store id>.L <nameid>.W
  14475. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14476. {
  14477. unsigned short nameid;
  14478. uint32 account_id, store_id;
  14479. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14480. account_id = RFIFOL(fd,info->pos[0]);
  14481. store_id = RFIFOL(fd,info->pos[1]);
  14482. nameid = RFIFOW(fd,info->pos[2]);
  14483. searchstore_click(sd, account_id, store_id, nameid);
  14484. }
  14485. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14486. /// 083d <xPos>.W <yPos>.W
  14487. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14488. {
  14489. int fd = sd->fd;
  14490. WFIFOHEAD(fd,packet_len(0x83d));
  14491. WFIFOW(fd,0) = 0x83d;
  14492. WFIFOW(fd,2) = x;
  14493. WFIFOW(fd,4) = y;
  14494. WFIFOSET(fd,packet_len(0x83d));
  14495. }
  14496. /// Parse function for packet debugging.
  14497. void clif_parse_debug(int fd,struct map_session_data *sd)
  14498. {
  14499. int cmd, packet_len;
  14500. // clif_parse ensures, that there is at least 2 bytes of data
  14501. cmd = RFIFOW(fd,0);
  14502. if( sd ) {
  14503. packet_len = packet_db[sd->packet_ver][cmd].len;
  14504. if( packet_len == 0 )
  14505. {// unknown
  14506. packet_len = RFIFOREST(fd);
  14507. }
  14508. else if( packet_len == -1 )
  14509. {// variable length
  14510. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14511. }
  14512. 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);
  14513. }
  14514. else
  14515. {
  14516. packet_len = RFIFOREST(fd);
  14517. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14518. }
  14519. ShowDump(RFIFOP(fd,0), packet_len);
  14520. }
  14521. /*==========================================
  14522. * Server tells client to display a window similar to Magnifier (item) one
  14523. * Server populates the window with avilable elemental converter options according to player's inventory
  14524. *------------------------------------------*/
  14525. int clif_elementalconverter_list(struct map_session_data *sd) {
  14526. int i,c,view,fd;
  14527. nullpo_ret(sd);
  14528. /// Main client packet processing function
  14529. fd=sd->fd;
  14530. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14531. WFIFOW(fd, 0)=0x1ad;
  14532. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14533. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14534. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14535. WFIFOW(fd,c*2+ 4)= view;
  14536. else
  14537. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14538. c++;
  14539. }
  14540. }
  14541. WFIFOW(fd,2) = c*2+4;
  14542. WFIFOSET(fd, WFIFOW(fd,2));
  14543. if (c > 0) {
  14544. sd->menuskill_id = SA_CREATECON;
  14545. sd->menuskill_val = c;
  14546. }
  14547. return 0;
  14548. }
  14549. /**
  14550. * Rune Knight
  14551. **/
  14552. void clif_millenniumshield(struct block_list *bl, short shields) {
  14553. #if PACKETVER >= 20081217
  14554. unsigned char buf[10];
  14555. WBUFW(buf,0) = 0x440;
  14556. WBUFL(buf,2) = bl->id;
  14557. WBUFW(buf,6) = shields;
  14558. WBUFW(buf,8) = 0;
  14559. clif_send(buf,packet_len(0x440),bl,AREA);
  14560. #endif
  14561. }
  14562. /**
  14563. * Warlock
  14564. **/
  14565. /*==========================================
  14566. * Spellbook list [LimitLine/3CeAM]
  14567. *------------------------------------------*/
  14568. int clif_spellbook_list(struct map_session_data *sd)
  14569. {
  14570. int i, c;
  14571. int fd;
  14572. nullpo_ret(sd);
  14573. fd = sd->fd;
  14574. WFIFOHEAD(fd, 8 * 8 + 8);
  14575. WFIFOW(fd,0) = 0x1ad;
  14576. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14577. {
  14578. if( itemdb_is_spellbook2(sd->status.inventory[i].nameid) )
  14579. {
  14580. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14581. c++;
  14582. }
  14583. }
  14584. if( c > 0 )
  14585. {
  14586. WFIFOW(fd,2) = c * 2 + 4;
  14587. WFIFOSET(fd, WFIFOW(fd, 2));
  14588. sd->menuskill_id = WL_READING_SB;
  14589. sd->menuskill_val = c;
  14590. }
  14591. else{
  14592. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14593. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14594. }
  14595. return 1;
  14596. }
  14597. /**
  14598. * Mechanic
  14599. **/
  14600. /*==========================================
  14601. * Magic Decoy Material List
  14602. *------------------------------------------*/
  14603. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14604. int i, c;
  14605. int fd;
  14606. nullpo_ret(sd);
  14607. fd = sd->fd;
  14608. WFIFOHEAD(fd, 8 * 8 + 8);
  14609. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14610. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14611. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14612. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14613. c ++;
  14614. }
  14615. }
  14616. if( c > 0 ) {
  14617. sd->menuskill_id = NC_MAGICDECOY;
  14618. sd->menuskill_val = skill_lv;
  14619. sd->sc.comet_x = x;
  14620. sd->sc.comet_y = y;
  14621. WFIFOW(fd,2) = c * 2 + 4;
  14622. WFIFOSET(fd, WFIFOW(fd, 2));
  14623. } else {
  14624. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14625. return 0;
  14626. }
  14627. return 1;
  14628. }
  14629. /*==========================================
  14630. * Guillotine Cross Poisons List
  14631. *------------------------------------------*/
  14632. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14633. int i, c;
  14634. int fd;
  14635. nullpo_ret(sd);
  14636. fd = sd->fd;
  14637. WFIFOHEAD(fd, 8 * 8 + 8);
  14638. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14639. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14640. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14641. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14642. c ++;
  14643. }
  14644. }
  14645. if( c > 0 ) {
  14646. sd->menuskill_id = GC_POISONINGWEAPON;
  14647. sd->menuskill_val = skill_lv;
  14648. WFIFOW(fd,2) = c * 2 + 4;
  14649. WFIFOSET(fd, WFIFOW(fd, 2));
  14650. } else {
  14651. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14652. return 0;
  14653. }
  14654. return 1;
  14655. }
  14656. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  14657. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14658. int fd, i, c;
  14659. nullpo_ret(sd);
  14660. fd = sd->fd;
  14661. if( !fd )
  14662. return 0;
  14663. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14664. return 0;
  14665. WFIFOHEAD(fd, 2 * 6 + 4);
  14666. WFIFOW(fd,0) = 0x442;
  14667. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14668. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14669. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14670. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14671. {
  14672. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14673. c++;
  14674. }
  14675. if( c > 0 ) {
  14676. WFIFOW(fd,2) = 8 + c * 2;
  14677. WFIFOL(fd,4) = c;
  14678. WFIFOSET(fd,WFIFOW(fd,2));
  14679. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14680. sd->menuskill_val = c;
  14681. } else {
  14682. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14683. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14684. }
  14685. return 1;
  14686. }
  14687. /*===========================================
  14688. * Skill list for Four Elemental Analysis
  14689. * and Change Material skills.
  14690. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  14691. *------------------------------------------*/
  14692. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  14693. #if PACKETVER >= 20090922
  14694. int fd = sd->fd;
  14695. nullpo_ret(sd);
  14696. sd->menuskill_id = skill_id; // To prevent hacking.
  14697. sd->menuskill_val = skill_lv;
  14698. if( skill_id == GN_CHANGEMATERIAL )
  14699. skill_lv = 0; // Changematerial
  14700. WFIFOHEAD(fd, packet_len(0x7e3));
  14701. WFIFOW(fd,0) = 0x7e3;
  14702. WFIFOL(fd,2) = skill_lv;
  14703. WFIFOL(fd,4) = 0;
  14704. WFIFOSET(fd, packet_len(0x7e3));
  14705. #endif
  14706. return 1;
  14707. }
  14708. /*==========================================
  14709. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14710. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14711. * RFIFOL(fd,2) - type (currently not used)
  14712. *------------------------------------------*/
  14713. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14714. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14715. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14716. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14717. return;
  14718. if( pc_istrading(sd) ) {
  14719. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  14720. clif_menuskill_clear(sd);
  14721. return;
  14722. }
  14723. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14724. clif_menuskill_clear(sd);
  14725. }
  14726. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  14727. /// 08cf <id>.L <type>.W <num>.W
  14728. void clif_spiritcharm(struct map_session_data *sd) {
  14729. unsigned char buf[10];
  14730. nullpo_retv(sd);
  14731. WBUFW(buf,0) = 0x08cf;
  14732. WBUFL(buf,2) = sd->bl.id;
  14733. WBUFW(buf,6) = sd->spiritcharm_type;
  14734. WBUFW(buf,8) = sd->spiritcharm;
  14735. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  14736. }
  14737. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14738. /// 0907 <index>.W
  14739. ///
  14740. /// R 0908 <index>.w <type>.b
  14741. /// type:
  14742. /// 0 = move item to personal tab
  14743. /// 1 = move item to normal tab
  14744. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14745. #if PACKETVER >= 20111122
  14746. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14747. int index = RFIFOW(fd,info->pos[0]) - 2;
  14748. int type = RFIFOB(fd, info->pos[1]);
  14749. /* can't move while dead. */
  14750. if(pc_isdead(sd)) {
  14751. return;
  14752. }
  14753. if (index < 0 || index >= MAX_INVENTORY)
  14754. return;
  14755. if ( sd->status.inventory[index].favorite && type == 1 )
  14756. sd->status.inventory[index].favorite = 0;
  14757. else if( type == 0 )
  14758. sd->status.inventory[index].favorite = 1;
  14759. else
  14760. return;/* nothing to do. */
  14761. clif_favorite_item(sd, index);
  14762. #endif
  14763. }
  14764. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14765. /// 0900 <index>.W <favorite>.B
  14766. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14767. int fd = sd->fd;
  14768. WFIFOHEAD(fd,packet_len(0x908));
  14769. WFIFOW(fd,0) = 0x908;
  14770. WFIFOW(fd,2) = index+2;
  14771. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14772. WFIFOSET(fd,packet_len(0x908));
  14773. }
  14774. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  14775. void clif_snap( struct block_list *bl, short x, short y ) {
  14776. unsigned char buf[10];
  14777. WBUFW(buf,0) = 0x8d2;
  14778. WBUFL(buf,2) = bl->id;
  14779. WBUFW(buf,6) = x;
  14780. WBUFW(buf,8) = y;
  14781. if( disguised(bl) )
  14782. {
  14783. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  14784. WBUFL(buf,2) = -bl->id;
  14785. clif_send(buf, packet_len(0x8d2), bl, SELF);
  14786. } else
  14787. clif_send(buf,packet_len(0x8d2),bl, AREA);
  14788. }
  14789. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  14790. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14791. #if PACKETVER >= 20120404
  14792. WFIFOHEAD(fd,packet_len(0x977));
  14793. WFIFOW(fd,0) = 0x977;
  14794. WFIFOL(fd,2) = md->bl.id;
  14795. WFIFOL(fd,6) = md->status.hp;
  14796. WFIFOL(fd,10) = md->status.max_hp;
  14797. WFIFOSET(fd,packet_len(0x977));
  14798. #endif
  14799. }
  14800. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14801. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14802. return;
  14803. }
  14804. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14805. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14806. WFIFOW(sd->fd,0) = 0x2c9;
  14807. WFIFOB(sd->fd,2) = flag;
  14808. WFIFOSET(sd->fd, packet_len(0x2c9));
  14809. }
  14810. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14811. /// 0979 <world name>.24B <char name>.24B
  14812. void clif_ackworldinfo(struct map_session_data* sd) {
  14813. int fd;
  14814. nullpo_retv(sd);
  14815. fd = sd->fd;
  14816. WFIFOHEAD(fd,packet_len(0x979));
  14817. WFIFOW(fd,0)=0x979;
  14818. //AID -> world name ?
  14819. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  14820. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  14821. WFIFOSET(fd,packet_len(0x979));
  14822. }
  14823. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14824. /// 0978 <AID>.L
  14825. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  14826. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14827. if(sd)
  14828. clif_ackworldinfo(sd);
  14829. }
  14830. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14831. /// 0447
  14832. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  14833. //if(sd)
  14834. ;
  14835. }
  14836. /// req world info (CZ_CLIENT_VERSION)
  14837. /// 044A <version>.L
  14838. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14839. //if(sd)
  14840. ;
  14841. }
  14842. /// Ranking list
  14843. /// ranking pointlist { <name>.24B <point>.L }*10
  14844. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  14845. struct fame_list* list;
  14846. int i, size = MAX_FAME_LIST;
  14847. switch(rankingtype) {
  14848. case RANK_BLACKSMITH: list = smith_fame_list; break;
  14849. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  14850. case RANK_TAEKWON: list = taekwon_fame_list; break;
  14851. // PK currently unsupported
  14852. case RANK_KILLER: list = NULL; size = 0; break;
  14853. default:
  14854. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  14855. return;
  14856. }
  14857. //Packet size limits this list to 10 elements. [Skotlex]
  14858. for (i = 0; i < min(10,size); i++) {
  14859. if (list[i].id > 0) {
  14860. const char* name;
  14861. if (strcmp(list[i].name, "-") == 0 &&
  14862. (name = map_charid2nick(list[i].id)) != NULL)
  14863. {
  14864. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  14865. } else {
  14866. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  14867. }
  14868. } else {
  14869. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  14870. }
  14871. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  14872. }
  14873. for(;i < 10; i++) { //In case the MAX is less than 10.
  14874. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  14875. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  14876. }
  14877. }
  14878. /// Request for the blacksmith ranklist.
  14879. /// /blacksmith command sends this packet to the server.
  14880. /// 0217 (CZ_BLACKSMITH_RANK)
  14881. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  14882. clif_ranklist(sd,RANK_BLACKSMITH);
  14883. }
  14884. /// Request for the alchemist ranklist.
  14885. /// /alchemist command sends this packet to the server.
  14886. /// 0218 (CZ_ALCHEMIST_RANK)
  14887. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  14888. clif_ranklist(sd,RANK_ALCHEMIST);
  14889. }
  14890. /// Request for the taekwon ranklist.
  14891. /// /taekwon command sends this packet to the server.
  14892. /// 0225 (CZ_TAEKWON_RANK)
  14893. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  14894. clif_ranklist(sd,RANK_TAEKWON);
  14895. }
  14896. /// Request for the killer ranklist.
  14897. /// /pk command sends this packet to the server.
  14898. /// 0237 (CZ_KILLER_RANK)
  14899. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  14900. clif_ranklist(sd,RANK_KILLER);
  14901. }
  14902. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  14903. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  14904. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  14905. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  14906. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14907. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14908. enum e_rank rank;
  14909. #if PACKETVER < 20130710
  14910. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  14911. short cmd;
  14912. switch( rankingType ){
  14913. case RANK_BLACKSMITH: cmd = 0x219; break;
  14914. case RANK_ALCHEMIST: cmd = 0x21a; break;
  14915. case RANK_TAEKWON: cmd = 0x226; break;
  14916. case RANK_KILLER: cmd = 0x238; break;
  14917. default:
  14918. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  14919. return;
  14920. }
  14921. // Can be safely casted here, since we validated it before
  14922. rank = (enum e_rank)rankingType;
  14923. WBUFW(buf,0) = cmd;
  14924. clif_sub_ranklist(buf,2,sd,rank);
  14925. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  14926. #else
  14927. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  14928. int mypoint = 0;
  14929. switch( rankingType ){
  14930. case RANK_BLACKSMITH:
  14931. case RANK_ALCHEMIST:
  14932. case RANK_TAEKWON:
  14933. case RANK_KILLER:
  14934. break;
  14935. default:
  14936. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  14937. return;
  14938. }
  14939. // Can be safely casted here, since we validated it before
  14940. rank = (enum e_rank)rankingType;
  14941. WBUFW(buf,0) = 0x97d;
  14942. WBUFW(buf,2) = rank;
  14943. clif_sub_ranklist(buf,4,sd,rank);
  14944. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14945. case MAPID_BLACKSMITH:
  14946. case MAPID_ALCHEMIST:
  14947. case MAPID_TAEKWON:
  14948. mypoint = sd->status.fame;
  14949. }
  14950. WBUFL(buf,284) = mypoint; //mypoint
  14951. clif_send(buf, 288, &sd->bl, SELF);
  14952. #endif
  14953. }
  14954. /*
  14955. * 097c <type> (CZ_REQ_RANKING)
  14956. * type
  14957. * 0: /blacksmith
  14958. * 1: /alchemist
  14959. * 2: /taekwon
  14960. * 3: /pk
  14961. * */
  14962. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14963. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14964. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14965. clif_ranklist(sd,rankingtype);
  14966. }
  14967. /// Updates the fame rank points for the given ranking.
  14968. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  14969. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  14970. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  14971. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14972. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14973. int fd=sd->fd;
  14974. #if PACKETVER < 20130710
  14975. short cmd;
  14976. switch(rankingtype){
  14977. case RANK_BLACKSMITH: cmd = 0x21b; break;
  14978. case RANK_ALCHEMIST: cmd = 0x21c; break;
  14979. case RANK_TAEKWON: cmd = 0x224; break;
  14980. default:
  14981. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  14982. return;
  14983. }
  14984. WFIFOHEAD(fd,packet_len(cmd));
  14985. WFIFOW(fd,0) = cmd;
  14986. WFIFOL(fd,2) = point;
  14987. WFIFOL(fd,6) = sd->status.fame;
  14988. WFIFOSET(fd, packet_len(cmd));
  14989. #else
  14990. WFIFOHEAD(fd,packet_len(0x97e));
  14991. WFIFOW(fd,0) = 0x97e;
  14992. WFIFOW(fd,2) = rankingtype;
  14993. WFIFOL(fd,4) = point;
  14994. WFIFOL(fd,8) = sd->status.fame;
  14995. WFIFOSET(fd,packet_len(0x97e));
  14996. #endif
  14997. }
  14998. /**
  14999. * Transmit personal information to player. (rates)
  15000. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15001. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15002. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15003. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15004. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15005. * FIXME!
  15006. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15007. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15008. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15009. */
  15010. #ifdef VIP_ENABLE
  15011. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15012. if (sd) {
  15013. struct s_packet_db* info;
  15014. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15015. int cmd = 0, fd, i = 0;
  15016. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15017. int details_bexp[PINFO_MAX];
  15018. int details_drop[PINFO_MAX];
  15019. int details_penalty[PINFO_MAX];
  15020. /**
  15021. * Set for EXP
  15022. */
  15023. //0:PCRoom
  15024. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15025. if (details_bexp[0] == 100 || !details_bexp[0])
  15026. details_bexp[0] = 0;
  15027. else {
  15028. if (details_bexp[0] < 100) {
  15029. details_bexp[0] = 100 - details_bexp[0];
  15030. details_bexp[0] = 0 - details_bexp[0];
  15031. }
  15032. else
  15033. details_bexp[0] = details_bexp[0] - 100;
  15034. }
  15035. //1:Premium
  15036. if (pc_isvip(sd)) {
  15037. details_bexp[1] = battle_config.vip_base_exp_increase;
  15038. if (details_bexp[1] < 0)
  15039. details_bexp[1] = 0 - details_bexp[1];
  15040. }
  15041. else
  15042. details_bexp[1] = 0;
  15043. //2:Server
  15044. details_bexp[2] = battle_config.base_exp_rate;
  15045. if (details_bexp[2] == 100)
  15046. details_bexp[2] = 0;
  15047. else {
  15048. if (details_bexp[2] < 100) {
  15049. details_bexp[2] = 100 - details_bexp[2];
  15050. details_bexp[2] = 0 - details_bexp[2];
  15051. }
  15052. else
  15053. details_bexp[2] = details_bexp[2] - 100;
  15054. }
  15055. //3:TPLUS
  15056. details_bexp[3] = 0;
  15057. /* End - EXP set*/
  15058. /**
  15059. * Set for Drop rate
  15060. */
  15061. //0:PCRoom
  15062. details_drop[0] = 0;
  15063. //1:Premium
  15064. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15065. if (pc_isvip(sd)) {
  15066. if (details_drop[1] < 0)
  15067. details_drop[1] = 0 - details_drop[1];
  15068. }
  15069. else
  15070. details_drop[1] = 0;
  15071. //2:Server
  15072. details_drop[2] = battle_config.item_rate_common;
  15073. if (details_drop[2] == 100)
  15074. details_drop[2] = 0;
  15075. else {
  15076. if (details_drop[2] < 100) {
  15077. details_drop[2] = 100 - details_drop[2];
  15078. details_drop[2] = 0 - details_drop[2];
  15079. }
  15080. else
  15081. details_drop[2] = details_drop[2] - 100;
  15082. }
  15083. //3:TPLUS
  15084. details_drop[3] = 0;
  15085. /* End - Drop set*/
  15086. /**
  15087. * Set for Penalty rate
  15088. */
  15089. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  15090. //0:PCRoom
  15091. details_penalty[0] = 0;
  15092. //1:Premium
  15093. if (pc_isvip(sd)) {
  15094. details_penalty[1] = battle_config.vip_exp_penalty_base;
  15095. if (details_penalty[1] == 100)
  15096. details_penalty[1] = 0;
  15097. else {
  15098. if (details_penalty[1] < 100) {
  15099. details_penalty[1] = 100 - details_penalty[1];
  15100. details_penalty[1] = 0 - details_penalty[1];
  15101. }
  15102. else
  15103. details_penalty[1] = details_penalty[1] - 100;
  15104. }
  15105. }
  15106. else
  15107. details_penalty[1] = 0;
  15108. //2:Server
  15109. details_penalty[2] = battle_config.death_penalty_base;
  15110. if (details_penalty[2] == 100)
  15111. details_penalty[2] = 0;
  15112. else {
  15113. if (details_penalty[2] < 100) {
  15114. details_penalty[2] = 100 - details_penalty[2];
  15115. details_penalty[2] = 0 - details_penalty[2];
  15116. }
  15117. else
  15118. details_penalty[2] = details_penalty[2] - 100;
  15119. }
  15120. //3:TPLUS
  15121. details_penalty[3] = 0;
  15122. /* End - Penalty set*/
  15123. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  15124. info = &packet_db[sd->packet_ver][cmd];
  15125. len = info->len; //this is the base len without details
  15126. if(!len) return; //version as packet disable
  15127. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15128. szdetails = 7;
  15129. factor = 1;
  15130. }
  15131. else if (cmd == 0x097b) {
  15132. tot_baseexp *= factor;
  15133. tot_drop *= factor;
  15134. tot_penalty *= factor;
  15135. }
  15136. fd = sd->fd;
  15137. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15138. WFIFOW(fd,0) = cmd;
  15139. for (i = 0; i < maxinfotype; i++) {
  15140. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15141. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15142. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15143. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15144. tot_baseexp += details_bexp[i]*factor;
  15145. tot_drop += details_penalty[i]*factor;
  15146. tot_penalty += details_drop[i]*factor;
  15147. len += szdetails;
  15148. }
  15149. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15150. if (cmd == 0x08cb) { //0x08cb version
  15151. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15152. WFIFOW(fd,info->pos[2]) = tot_drop;
  15153. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15154. }
  15155. else { //2013-08-07aRagexe uses 0x097b
  15156. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15157. WFIFOL(fd,info->pos[2]) = tot_drop;
  15158. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15159. }
  15160. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15161. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15162. WFIFOSET(fd,len);
  15163. }
  15164. }
  15165. #endif
  15166. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15167. char cmd[30];
  15168. int t_aid = RFIFOL(fd,2);
  15169. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15170. is_atcommand(fd, sd, cmd, 1);
  15171. }
  15172. /**
  15173. * Marks Crimson Marker target on mini-map to the caster
  15174. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15175. * @param fd
  15176. * @param bl Crimson Marker target
  15177. **/
  15178. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15179. struct s_packet_db* info;
  15180. int cmd = 0;
  15181. int16 len;
  15182. unsigned char buf[11];
  15183. nullpo_retv(sd);
  15184. cmd = packet_db_ack[sd->packet_ver][ZC_C_MARKERINFO];
  15185. if (!cmd)
  15186. cmd = 0x09C1; //default
  15187. info = &packet_db[sd->packet_ver][cmd];
  15188. if (!(len = info->len))
  15189. return;
  15190. WBUFW(buf, 0) = cmd;
  15191. WBUFL(buf, info->pos[0]) = bl->id;
  15192. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15193. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15194. clif_send(buf, len, &sd->bl, SELF);
  15195. }
  15196. /**
  15197. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15198. **/
  15199. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15200. struct s_packet_db *info = NULL;
  15201. int cmd = 0;
  15202. nullpo_retv(sd);
  15203. cmd = packet_db_ack[sd->packet_ver][ZC_NOTIFY_BIND_ON_EQUIP];
  15204. info = &packet_db[sd->packet_ver][cmd];
  15205. if (!cmd || !info->len)
  15206. return;
  15207. WFIFOHEAD(sd->fd, info->len);
  15208. WFIFOW(sd->fd, 0) = cmd;
  15209. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15210. WFIFOSET(sd->fd, info->len);
  15211. }
  15212. /**
  15213. * [Ind/Hercules]
  15214. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  15215. **/
  15216. void clif_showscript(struct block_list* bl, const char* message) {
  15217. char buf[256];
  15218. size_t len;
  15219. nullpo_retv(bl);
  15220. if(!message)
  15221. return;
  15222. len = strlen(message)+1;
  15223. if( len > sizeof(buf)-8 ) {
  15224. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15225. len = sizeof(buf)-8;
  15226. }
  15227. WBUFW(buf,0) = 0x8b3;
  15228. WBUFW(buf,2) = (uint16)(len+8);
  15229. WBUFL(buf,4) = bl->id;
  15230. safestrncpy(WBUFCP(buf,8), message, len);
  15231. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, AREA);
  15232. }
  15233. /**
  15234. * [Ind/Hercules]
  15235. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  15236. **/
  15237. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15238. unsigned char buf[10];
  15239. nullpo_retv(sd);
  15240. WBUFW(buf,0) = 0x7fc;
  15241. WBUFL(buf,2) = prev_leader_aid;
  15242. WBUFL(buf,6) = new_leader_aid;
  15243. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  15244. }
  15245. /**
  15246. * Decrypt packet identifier for player
  15247. * @param fd
  15248. * @param sd
  15249. * @param packet_ver
  15250. * Orig author [Ind/Hercules]
  15251. **/
  15252. static unsigned short clif_parse_cmd(int fd, struct map_session_data *sd) {
  15253. #ifndef PACKET_OBFUSCATION
  15254. return RFIFOW(fd, 0);
  15255. #else
  15256. unsigned short cmd = RFIFOW(fd,0); // Check if it is a player that tries to connect to the map server.
  15257. if (sd)
  15258. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF)); // Decrypt the current packet ID with the last key stored in the session.
  15259. else
  15260. 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.
  15261. return cmd; // Return the decrypted packet ID.
  15262. #endif
  15263. }
  15264. #ifdef DUMP_UNKNOWN_PACKET
  15265. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  15266. {
  15267. const char* packet_txt = "save/packet.txt";
  15268. FILE* fp;
  15269. time_t time_server;
  15270. struct tm *datetime;
  15271. char datestr[512];
  15272. time(&time_server); // get time in seconds since 1/1/1970
  15273. datetime = localtime(&time_server); // convert seconds in structure
  15274. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  15275. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  15276. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  15277. if( sd ) {
  15278. 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);
  15279. } else {
  15280. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15281. }
  15282. WriteDump(fp, RFIFOP(fd,0), packet_len);
  15283. fprintf(fp, "\n");
  15284. fclose(fp);
  15285. } else {
  15286. ShowError("Failed to write '%s'.\n", packet_txt);
  15287. // Dump on console instead
  15288. if( sd ) {
  15289. 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);
  15290. } else {
  15291. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  15292. }
  15293. ShowDump(RFIFOP(fd,0), packet_len);
  15294. }
  15295. }
  15296. #endif
  15297. /// Roulette System
  15298. /// Author: Yommy
  15299. /**
  15300. * Opens Roulette window
  15301. * @param fd
  15302. * @param sd
  15303. */
  15304. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  15305. {
  15306. nullpo_retv(sd);
  15307. if (!battle_config.feature_roulette) {
  15308. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15309. return;
  15310. }
  15311. WFIFOHEAD(fd,packet_len(0xa1a));
  15312. WFIFOW(fd,0) = 0xa1a;
  15313. WFIFOB(fd,2) = 0; // result
  15314. WFIFOL(fd,3) = 0; // serial
  15315. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  15316. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  15317. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  15318. WFIFOL(fd,11) = sd->roulette_point.gold;
  15319. WFIFOL(fd,15) = sd->roulette_point.silver;
  15320. WFIFOL(fd,19) = sd->roulette_point.bronze;
  15321. WFIFOSET(fd,packet_len(0xa1a));
  15322. }
  15323. /**
  15324. * Generates information to be displayed
  15325. * @param fd
  15326. * @param sd
  15327. */
  15328. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  15329. {
  15330. unsigned short i, j, count = 0;
  15331. int len = 8 + (42 * 8);
  15332. nullpo_retv(sd);
  15333. if (!battle_config.feature_roulette) {
  15334. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15335. return;
  15336. }
  15337. WFIFOHEAD(fd,len);
  15338. WFIFOW(fd,0) = 0xa1c;
  15339. WFIFOW(fd,2) = len;
  15340. WFIFOL(fd,4) = 1; // serial
  15341. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  15342. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  15343. WFIFOW(fd,8 * count + 8) = i;
  15344. WFIFOW(fd,8 * count + 10) = j;
  15345. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  15346. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  15347. count++;
  15348. }
  15349. }
  15350. WFIFOSET(fd,len);
  15351. return;
  15352. }
  15353. /**
  15354. * Closes Roulette window
  15355. * @param fd
  15356. * @param sd
  15357. */
  15358. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  15359. {
  15360. nullpo_retv(sd);
  15361. if (!battle_config.feature_roulette) {
  15362. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15363. return;
  15364. }
  15365. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  15366. return;
  15367. }
  15368. /**
  15369. *
  15370. **/
  15371. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  15372. #if PACKETVER >= 20141016
  15373. uint16 cmd = 0xa22;
  15374. unsigned char buf[5];
  15375. nullpo_retv(sd);
  15376. if (packet_db[sd->packet_ver][cmd].len == 0)
  15377. return;
  15378. WBUFW(buf,0) = cmd;
  15379. WBUFB(buf,2) = type;
  15380. WBUFW(buf,3) = 0; //! TODO: Additional item
  15381. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  15382. #endif
  15383. }
  15384. /**
  15385. * Claim roulette reward
  15386. * @param sd Player
  15387. * @return 0:Success
  15388. **/
  15389. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  15390. struct item it;
  15391. uint8 res = 1;
  15392. nullpo_retr(1, sd);
  15393. if (sd->roulette.prizeIdx < 0)
  15394. return RECV_ITEM_FAILED;
  15395. memset(&it, 0, sizeof(it));
  15396. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  15397. it.identify = 1;
  15398. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  15399. ; // onSuccess
  15400. }
  15401. sd->roulette.claimPrize = false;
  15402. sd->roulette.prizeStage = 0;
  15403. sd->roulette.prizeIdx = -1;
  15404. sd->roulette.stage = 0;
  15405. return res;
  15406. }
  15407. /**
  15408. * Process the stage and attempt to give a prize
  15409. * @param fd
  15410. * @param sd
  15411. */
  15412. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  15413. {
  15414. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  15415. short stage = sd->roulette.stage;
  15416. nullpo_retv(sd);
  15417. if (!battle_config.feature_roulette) {
  15418. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15419. return;
  15420. }
  15421. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  15422. stage = sd->roulette.stage = 0;
  15423. if (!stage) {
  15424. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  15425. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  15426. }
  15427. if (result == GENERATE_ROULETTE_SUCCESS) {
  15428. if (!stage) {
  15429. if (sd->roulette_point.bronze > 0) {
  15430. sd->roulette_point.bronze -= 1;
  15431. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  15432. } else if (sd->roulette_point.silver > 9) {
  15433. sd->roulette_point.silver -= 10;
  15434. stage = sd->roulette.stage = 2;
  15435. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  15436. } else if (sd->roulette_point.gold > 9) {
  15437. sd->roulette_point.gold -= 10;
  15438. stage = sd->roulette.stage = 4;
  15439. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  15440. }
  15441. }
  15442. sd->roulette.prizeStage = stage;
  15443. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  15444. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  15445. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  15446. clif_roulette_getitem(sd);
  15447. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  15448. return;
  15449. }
  15450. else {
  15451. sd->roulette.claimPrize = true;
  15452. sd->roulette.stage++;
  15453. }
  15454. }
  15455. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  15456. }
  15457. /**
  15458. * Request to cash in prize
  15459. * @param fd
  15460. * @param sd
  15461. */
  15462. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  15463. {
  15464. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  15465. nullpo_retv(sd);
  15466. if (!battle_config.feature_roulette) {
  15467. clif_colormes(sd->fd,color_table[COLOR_RED],msg_txt(sd,1497)); //Roulette is disabled
  15468. return;
  15469. }
  15470. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  15471. switch (clif_roulette_getitem(sd)) {
  15472. case 0:
  15473. type = RECV_ITEM_SUCCESS;
  15474. break;
  15475. case 1:
  15476. case 4:
  15477. case 5:
  15478. type = RECV_ITEM_OVERCOUNT;
  15479. break;
  15480. case 2:
  15481. type = RECV_ITEM_OVERWEIGHT;
  15482. break;
  15483. case 7:
  15484. default:
  15485. type = RECV_ITEM_FAILED;
  15486. break;
  15487. }
  15488. }
  15489. clif_roulette_recvitem_ack(sd,type);
  15490. return;
  15491. }
  15492. /**
  15493. * Update Roulette window with current stats
  15494. * @param sd
  15495. * @param result
  15496. * @param stage
  15497. * @param prizeIdx
  15498. * @param bonusItemID
  15499. */
  15500. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  15501. {
  15502. int fd = sd->fd;
  15503. nullpo_retv(sd);
  15504. WFIFOHEAD(fd,packet_len(0xa20));
  15505. WFIFOW(fd,0) = 0xa20;
  15506. WFIFOB(fd,2) = result;
  15507. WFIFOW(fd,3) = stage;
  15508. WFIFOW(fd,5) = prizeIdx;
  15509. WFIFOW(fd,7) = bonusItemID;
  15510. WFIFOL(fd,9) = sd->roulette_point.gold;
  15511. WFIFOL(fd,13) = sd->roulette_point.silver;
  15512. WFIFOL(fd,17) = sd->roulette_point.bronze;
  15513. WFIFOSET(fd,packet_len(0xa20));
  15514. }
  15515. /// MERGE ITEM
  15516. /**
  15517. * Acknowledge the client about item merger result
  15518. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  15519. * @param fd
  15520. * @param sd
  15521. **/
  15522. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  15523. unsigned char buf[9];
  15524. struct s_packet_db *info = NULL;
  15525. short cmd = 0;
  15526. nullpo_retv(sd);
  15527. if (!clif_session_isValid(sd))
  15528. return;
  15529. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_ACK_MERGE_ITEM]))
  15530. return;
  15531. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15532. return;
  15533. WBUFW(buf, 0) = cmd;
  15534. WBUFW(buf, info->pos[0]) = index;
  15535. WBUFW(buf, info->pos[1]) = count;
  15536. WBUFB(buf, info->pos[2]) = type;
  15537. clif_send(buf, info->len, &sd->bl, SELF);
  15538. }
  15539. /**
  15540. * Check if item has the pair to be merged
  15541. * @param sd
  15542. * @param it Item
  15543. * @return True if has pair, False if not
  15544. **/
  15545. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  15546. struct item *it_;
  15547. unsigned short i;
  15548. nullpo_retr(false, sd);
  15549. 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);
  15550. if (i < MAX_INVENTORY)
  15551. return true;
  15552. return false;
  15553. }
  15554. /**
  15555. * Check if item can be merged
  15556. * @param id Item Data
  15557. * @param it Item
  15558. * @return True if can be merged, False if not
  15559. **/
  15560. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  15561. if (!id || !it)
  15562. return false;
  15563. if (id->type == IT_CASH)
  15564. return false;
  15565. if (!itemdb_isstackable2(id))
  15566. return false;
  15567. if (itemdb_isspecial(it->card[0]))
  15568. return false;
  15569. if (!it->unique_id)
  15570. return false;
  15571. return true;
  15572. }
  15573. /**
  15574. * Open available item to be merged.
  15575. * Only show 1 item in 1 process.
  15576. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  15577. * @param sd
  15578. **/
  15579. void clif_merge_item_open(struct map_session_data *sd) {
  15580. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  15581. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  15582. int len = 0;
  15583. struct s_packet_db *info = NULL;
  15584. struct item *it;
  15585. nullpo_retv(sd);
  15586. if (!clif_session_isValid(sd))
  15587. return;
  15588. if (!(cmd = packet_db_ack[sd->packet_ver][ZC_MERGE_ITEM_OPEN]))
  15589. return;
  15590. if (!(info = &packet_db[sd->packet_ver][cmd]) || info->len == 0)
  15591. return;
  15592. // Get entries
  15593. for (i = 0; i < MAX_INVENTORY; i++) {
  15594. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->status.inventory[i])))
  15595. continue;
  15596. if (clif_merge_item_has_pair(sd, it))
  15597. indexes[n++] = i;
  15598. }
  15599. if (n < 2) { // No item need to be merged
  15600. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15601. return;
  15602. }
  15603. WBUFW(buf, 0) = cmd;
  15604. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  15605. for (i = 0; i < n; i++) {
  15606. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  15607. }
  15608. clif_send(buf, len, &sd->bl, SELF);
  15609. }
  15610. /**
  15611. * Process item merger
  15612. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  15613. * @param fd
  15614. * @param sd
  15615. **/
  15616. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  15617. struct s_packet_db *info = NULL;
  15618. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  15619. unsigned int count = 0;
  15620. struct item_data *id = NULL;
  15621. nullpo_retv(sd);
  15622. if (!clif_session_isValid(sd))
  15623. return;
  15624. if (!(info = &packet_db[sd->packet_ver][RFIFOW(fd,0)]) || info->len == 0)
  15625. return;
  15626. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  15627. if (n < 2) { // No item need to be merged
  15628. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15629. return;
  15630. }
  15631. for (i = 0, j = 0; i < n; i++) {
  15632. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  15633. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->status.inventory[idx]))
  15634. continue;
  15635. indexes[j] = idx;
  15636. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  15637. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  15638. return;
  15639. }
  15640. count += sd->status.inventory[idx].amount;
  15641. j++;
  15642. }
  15643. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  15644. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  15645. return;
  15646. }
  15647. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  15648. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  15649. return;
  15650. }
  15651. // Merrrrge!!!!
  15652. for (i = 1; i < n; i++) {
  15653. unsigned short idx = indexes[i], amt = sd->status.inventory[idx].amount;
  15654. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->status.inventory[idx]);
  15655. memset(&sd->status.inventory[idx], 0, sizeof(sd->status.inventory[0]));
  15656. sd->inventory_data[idx] = NULL;
  15657. clif_delitem(sd, idx, amt, 0);
  15658. }
  15659. sd->status.inventory[indexes[0]].amount = count;
  15660. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  15661. }
  15662. /**
  15663. * Cancel item merge
  15664. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  15665. * @param fd
  15666. * @param sd
  15667. **/
  15668. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  15669. return; // Nothing todo yet
  15670. }
  15671. /**
  15672. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15673. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  15674. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  15675. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  15676. **/
  15677. 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) {
  15678. unsigned char buf[9 + NAME_LENGTH * 2];
  15679. unsigned short cmd = 0;
  15680. struct s_packet_db *info = NULL;
  15681. if (!(cmd = packet_db_ack[clif_config.packet_db_ver][ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  15682. return;
  15683. if (!(info = &packet_db[clif_config.packet_db_ver][cmd]) || info->len == 0)
  15684. return;
  15685. WBUFW(buf, 0) = 0x7fd;
  15686. WBUFB(buf, 4) = type;
  15687. WBUFW(buf, 5) = nameid;
  15688. WBUFB(buf, 7) = NAME_LENGTH;
  15689. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  15690. switch (type) {
  15691. case ITEMOBTAIN_TYPE_BOXITEM:
  15692. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  15693. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  15694. WBUFW(buf, 9 + NAME_LENGTH) = container;
  15695. break;
  15696. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  15697. {
  15698. struct mob_db *db = mob_db(container);
  15699. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  15700. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  15701. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  15702. }
  15703. break;
  15704. case ITEMOBTAIN_TYPE_NPC:
  15705. default:
  15706. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  15707. break;
  15708. }
  15709. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  15710. }
  15711. /// Show body view windows (ZC_DRESSROOM_OPEN).
  15712. /// 0A02 <view>.W
  15713. /// Value <flag> has the following effects:
  15714. /// 1: Open a Dress Room window.
  15715. void clif_dressing_room(struct map_session_data *sd, int flag) {
  15716. #if PACKETVER >= 20150513
  15717. int fd = sd->fd;
  15718. nullpo_retv(sd);
  15719. WFIFOHEAD(fd, packet_len(0xa02));
  15720. WFIFOW(fd,0) = 0xa02;
  15721. WFIFOW(fd,2) = flag;
  15722. WFIFOSET(fd, packet_len(0xa02));
  15723. #endif
  15724. }
  15725. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  15726. /// 0A35 <result>.W
  15727. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  15728. #if PACKETVER >= 20150513
  15729. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  15730. // Ignore the request
  15731. // - Invalid item index
  15732. // - Invalid item ID or item doesn't exist
  15733. // - Item is already identified
  15734. if (idx < 0 || idx >= MAX_INVENTORY ||
  15735. sd->status.inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  15736. sd->status.inventory[idx].identify)
  15737. return;
  15738. // Ignore the request - No magnifiers in inventory
  15739. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  15740. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  15741. return;
  15742. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  15743. return;
  15744. skill_identify(sd, idx);
  15745. #endif
  15746. }
  15747. /// Starts navigation to the given target on client side
  15748. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  15749. #if PACKETVER >= 20111010
  15750. int fd = sd->fd;
  15751. WFIFOHEAD(fd,27);
  15752. WFIFOW(fd,0) = 0x08e2;
  15753. // How detailed will our navigation be?
  15754. if( mob_id > 0 ){
  15755. x = 0;
  15756. y = 0;
  15757. WFIFOB(fd,2) = 3; // monster with destination field
  15758. }else if( x > 0 && y > 0 ){
  15759. WFIFOB(fd,2) = 0; // with coordinates
  15760. }else{
  15761. x = 0;
  15762. y = 0;
  15763. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  15764. }
  15765. // Which services can be used for transportation?
  15766. WFIFOB(fd,3) = flag;
  15767. // If this flag is set, the navigation window will not be opened up
  15768. WFIFOB(fd,4) = hideWindow;
  15769. // Target map
  15770. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  15771. // Target x
  15772. WFIFOW(fd,21) = x;
  15773. // Target y
  15774. WFIFOW(fd,23) = y;
  15775. // Target monster ID
  15776. WFIFOW(fd,25) = mob_id;
  15777. WFIFOSET(fd,27);
  15778. #endif
  15779. }
  15780. /// Send hat effects to the client (ZC_HAT_EFFECT).
  15781. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  15782. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  15783. #if PACKETVER >= 20150513
  15784. unsigned char* buf;
  15785. int len,i;
  15786. struct map_session_data *tsd;
  15787. struct block_list* tbl;
  15788. if( target == SELF ){
  15789. tsd = BL_CAST(BL_PC,bl);
  15790. tbl = &sd->bl;
  15791. }else{
  15792. tsd = sd;
  15793. tbl = bl;
  15794. }
  15795. if( !tsd->hatEffectCount )
  15796. return;
  15797. len = 9 + tsd->hatEffectCount * 2;
  15798. buf = (unsigned char*)aMalloc( len );
  15799. WBUFW(buf,0) = 0xa3b;
  15800. WBUFW(buf,2) = len;
  15801. WBUFL(buf,4) = tsd->bl.id;
  15802. WBUFB(buf,8) = 1;
  15803. for( i = 0; i < tsd->hatEffectCount; i++ ){
  15804. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  15805. }
  15806. clif_send(buf, len,tbl,target);
  15807. aFree(buf);
  15808. #endif
  15809. }
  15810. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  15811. #if PACKETVER >= 20150513
  15812. unsigned char buf[13];
  15813. WBUFW(buf,0) = 0xa3b;
  15814. WBUFW(buf,2) = 13;
  15815. WBUFL(buf,4) = sd->bl.id;
  15816. WBUFB(buf,8) = enable;
  15817. WBUFL(buf,9) = effectId;
  15818. clif_send(buf,13,&sd->bl,AREA);
  15819. #endif
  15820. }
  15821. /*==========================================
  15822. * Main client packet processing function
  15823. *------------------------------------------*/
  15824. static int clif_parse(int fd)
  15825. {
  15826. int cmd, packet_ver, packet_len, err;
  15827. TBL_PC* sd;
  15828. int pnum;
  15829. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  15830. // Note: "click masters" can do 80+ clicks in 10 seconds
  15831. 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]
  15832. { // begin main client packet processing loop
  15833. sd = (TBL_PC *)session[fd]->session_data;
  15834. if (session[fd]->flag.eof) {
  15835. if (sd) {
  15836. if (sd->state.autotrade) {
  15837. //Disassociate character from the socket connection.
  15838. session[fd]->session_data = NULL;
  15839. sd->fd = 0;
  15840. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  15841. } else
  15842. if (sd->state.active) {
  15843. // Player logout display [Valaris]
  15844. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  15845. clif_quitsave(fd, sd);
  15846. } else {
  15847. //Unusual logout (during log on/off/map-changer procedure)
  15848. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  15849. map_quit(sd);
  15850. }
  15851. } else {
  15852. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  15853. }
  15854. do_close(fd);
  15855. return 0;
  15856. }
  15857. if (RFIFOREST(fd) < 2)
  15858. return 0;
  15859. cmd = clif_parse_cmd(fd, sd);
  15860. // identify client's packet version
  15861. if (sd) {
  15862. packet_ver = sd->packet_ver;
  15863. } else {
  15864. // check authentification packet to know packet version
  15865. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  15866. if( err ) {// failed to identify packet version
  15867. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  15868. err == 1 ? "" :
  15869. err == 2 ? ", possibly for having an invalid account_id" :
  15870. err == 3 ? ", possibly for having an invalid char_id." :
  15871. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  15872. err == 4 ? ", possibly for having an invalid login_id1." :
  15873. err == 5 ? ", possibly for having an invalid client_tick." :
  15874. */
  15875. err == 6 ? ", possibly for having an invalid sex." :
  15876. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  15877. WFIFOHEAD(fd,packet_len(0x6a));
  15878. WFIFOW(fd,0) = 0x6a;
  15879. WFIFOB(fd,2) = 3; // Rejected from Server
  15880. WFIFOSET(fd,packet_len(0x6a));
  15881. #ifdef DUMP_INVALID_PACKET
  15882. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15883. #endif
  15884. RFIFOSKIP(fd, RFIFOREST(fd));
  15885. set_eof(fd);
  15886. return 0;
  15887. }
  15888. }
  15889. // filter out invalid / unsupported packets
  15890. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  15891. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  15892. #ifdef DUMP_INVALID_PACKET
  15893. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15894. #endif
  15895. set_eof(fd);
  15896. return 0;
  15897. }
  15898. // determine real packet length
  15899. packet_len = packet_db[packet_ver][cmd].len;
  15900. if (packet_len == -1) { // variable-length packet
  15901. if (RFIFOREST(fd) < 4)
  15902. return 0;
  15903. packet_len = RFIFOW(fd,2);
  15904. if (packet_len < 4 || packet_len > 32768) {
  15905. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  15906. #ifdef DUMP_INVALID_PACKET
  15907. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  15908. #endif
  15909. set_eof(fd);
  15910. return 0;
  15911. }
  15912. }
  15913. if ((int)RFIFOREST(fd) < packet_len)
  15914. return 0; // not enough data received to form the packet
  15915. #ifdef PACKET_OBFUSCATION
  15916. RFIFOW(fd, 0) = cmd;
  15917. if (sd)
  15918. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  15919. #endif
  15920. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  15921. packet_db[packet_ver][cmd].func(fd, sd);
  15922. else if( packet_db[packet_ver][cmd].func != NULL ) {
  15923. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  15924. ; //Only valid packet when there is no session
  15925. else
  15926. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  15927. ; //Only valid packet when player is not on a map
  15928. else
  15929. packet_db[packet_ver][cmd].func(fd, sd);
  15930. }
  15931. #ifdef DUMP_UNKNOWN_PACKET
  15932. else DumpUnknown(fd,sd,cmd,packet_len);
  15933. #endif
  15934. RFIFOSKIP(fd, packet_len);
  15935. }; // main loop end
  15936. return 0;
  15937. }
  15938. /*==========================================
  15939. * Reads packet_db.txt and setups its array reference
  15940. *------------------------------------------*/
  15941. void packetdb_readdb(bool reload)
  15942. {
  15943. char line[1024];
  15944. int cmd,i,j;
  15945. int max_cmd=-1;
  15946. bool skip_ver = false;
  15947. int warned = 0;
  15948. int packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15949. #ifdef PACKET_OBFUSCATION
  15950. bool key_defined = false;
  15951. int last_key_defined = -1;
  15952. #endif
  15953. int packet_len_table[MAX_PACKET_DB] = {
  15954. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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. //#0x0040
  15959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15961. #if PACKETVER <= 20081217
  15962. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  15963. #else
  15964. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  15965. #endif
  15966. #if PACKETVER < 2
  15967. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  15968. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  15969. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  15970. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  15971. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  15972. #else
  15973. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  15974. #endif
  15975. //#0x0080
  15976. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  15977. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  15978. #if PACKETVER <= 20100622
  15979. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  15980. #else
  15981. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  15982. #endif
  15983. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  15984. //#0x00C0
  15985. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  15986. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  15987. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  15988. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  15989. //#0x0100
  15990. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  15991. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  15992. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  15993. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  15994. //#0x0140
  15995. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  15996. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  15997. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  15998. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  15999. //#0x0180
  16000. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  16001. #if PACKETVER < 1
  16002. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16003. #else // 196 comodo icon status display for later
  16004. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  16005. #endif
  16006. #if PACKETVER < 20081126
  16007. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16008. #else // 0x1a2 changed (35->37)
  16009. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  16010. #endif
  16011. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  16012. //#0x01C0, Set 0x1d5=-1
  16013. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  16014. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  16015. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  16016. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  16017. //#0x0200
  16018. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  16019. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  16020. #if PACKETVER < 20071106
  16021. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  16022. #else // 0x22c changed
  16023. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  16024. #endif
  16025. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  16026. //#0x0240
  16027. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  16028. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  16029. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16030. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16031. //#0x0280
  16032. #if PACKETVER < 20070711
  16033. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  16034. #else
  16035. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  16036. #endif
  16037. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  16038. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16039. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  16040. //#0x02C0
  16041. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  16042. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  16043. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  16044. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16045. //#0x0300
  16046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16050. //#0x0340
  16051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16055. //#0x0380
  16056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16060. //#0x03C0
  16061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16065. //#0x0400
  16066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  16070. //#0x0440
  16071. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  16072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16075. //#0x0480
  16076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16080. //#0x04C0
  16081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16085. //#0x0500
  16086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16090. //#0x0540
  16091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16095. //#0x0580
  16096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16100. //#0x05C0
  16101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16105. //#0x0600
  16106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16110. //#0x0640
  16111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16115. //#0x0680
  16116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16120. //#0x06C0
  16121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16125. //#0x0700
  16126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  16130. //#0x0740
  16131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16135. //#0x0780
  16136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16140. //#0x07C0
  16141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16142. #if PACKETVER < 20090617
  16143. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  16144. #else // 0x7d9 changed
  16145. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  16146. #endif
  16147. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  16148. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 10, 0, 26, 0,
  16149. //#0x0800
  16150. #if PACKETVER < 20091229
  16151. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  16152. #else // for Party booking ( PACKETVER >= 20091229 )
  16153. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  16154. #endif
  16155. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  16156. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16157. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  16158. //#0x0840
  16159. #if PACKETVER < 20130000
  16160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16161. #else
  16162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  16163. #endif
  16164. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  16165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16167. //#0x0880
  16168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16171. 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16172. //#0x08C0
  16173. 0, 0, 0, 0, 0, 0, 0, 20, 34, 0, 0, 0, 0, 0, 0, 10,
  16174. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24,
  16177. //#0x0900
  16178. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, -1,
  16179. 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16182. //#0x0940
  16183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 7,
  16186. 0, 0, 0, 0, 2, 0, 0, 14, 6, 50, -1, 0, 0, 0, 12, -1,
  16187. //#0x0980
  16188. 7, 0, 0, 29, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16189. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 22,
  16190. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  16191. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  16192. //#0x09C0
  16193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 17, 0, 0,102, 0,
  16194. 0, 0, 0, 0, 2, 0, -1, -1, 2, 0, 0, -1, -1, -1, 0, 7,
  16195. 0, 0, 0, 0, 0, 18, 22, 3, 11, 0, 11, -1, 0, 3, 11, 0,
  16196. 0, 11, 12, 11, 0, 0, 0, 75, -1,143, 0, 0, 0, -1, -1, -1,
  16197. //#0x0A00
  16198. #if PACKETVER >= 20141022
  16199. 269, 3, 4, 2, 6, 49, 6, 9, 26, 45, 47, 47, 56, -1, 14, -1,
  16200. #else
  16201. 269, 0, 0, 2, 6, 48, 6, 9, 26, 45, 47, 47, 56, -1, 14, 0,
  16202. #endif
  16203. -1, 0, 0, 26, 0, 0, 0, 0, 14, 2, 23, 2, -1, 2, 3, 2,
  16204. 21, 3, 5, 0, 66, 0, 0, 8, 3, 0, 0, -1, 0, -1, 0, 0,
  16205. 106, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16206. };
  16207. struct {
  16208. void (*func)(int, struct map_session_data *);
  16209. char *name;
  16210. } clif_parse_func[]={
  16211. {clif_parse_WantToConnection,"wanttoconnection"},
  16212. {clif_parse_LoadEndAck,"loadendack"},
  16213. {clif_parse_TickSend,"ticksend"},
  16214. {clif_parse_WalkToXY,"walktoxy"},
  16215. {clif_parse_QuitGame,"quitgame"},
  16216. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  16217. {clif_parse_GlobalMessage,"globalmessage"},
  16218. {clif_parse_MapMove,"mapmove"},
  16219. {clif_parse_ChangeDir,"changedir"},
  16220. {clif_parse_Emotion,"emotion"},
  16221. {clif_parse_HowManyConnections,"howmanyconnections"},
  16222. {clif_parse_ActionRequest,"actionrequest"},
  16223. {clif_parse_Restart,"restart"},
  16224. {clif_parse_WisMessage,"wis"},
  16225. {clif_parse_Broadcast,"broadcast"},
  16226. {clif_parse_TakeItem,"takeitem"},
  16227. {clif_parse_DropItem,"dropitem"},
  16228. {clif_parse_UseItem,"useitem"},
  16229. {clif_parse_EquipItem,"equipitem"},
  16230. {clif_parse_UnequipItem,"unequipitem"},
  16231. {clif_parse_NpcClicked,"npcclicked"},
  16232. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  16233. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  16234. {clif_parse_NpcSellListSend,"npcselllistsend"},
  16235. {clif_parse_CreateChatRoom,"createchatroom"},
  16236. {clif_parse_ChatAddMember,"chataddmember"},
  16237. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  16238. {clif_parse_ChangeChatOwner,"changechatowner"},
  16239. {clif_parse_KickFromChat,"kickfromchat"},
  16240. {clif_parse_ChatLeave,"chatleave"},
  16241. {clif_parse_TradeRequest,"traderequest"},
  16242. {clif_parse_TradeAck,"tradeack"},
  16243. {clif_parse_TradeAddItem,"tradeadditem"},
  16244. {clif_parse_TradeOk,"tradeok"},
  16245. {clif_parse_TradeCancel,"tradecancel"},
  16246. {clif_parse_TradeCommit,"tradecommit"},
  16247. {clif_parse_StopAttack,"stopattack"},
  16248. {clif_parse_PutItemToCart,"putitemtocart"},
  16249. {clif_parse_GetItemFromCart,"getitemfromcart"},
  16250. {clif_parse_RemoveOption,"removeoption"},
  16251. {clif_parse_ChangeCart,"changecart"},
  16252. {clif_parse_StatusUp,"statusup"},
  16253. {clif_parse_SkillUp,"skillup"},
  16254. {clif_parse_UseSkillToId,"useskilltoid"},
  16255. {clif_parse_UseSkillToPos,"useskilltopos"},
  16256. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  16257. {clif_parse_UseSkillMap,"useskillmap"},
  16258. {clif_parse_RequestMemo,"requestmemo"},
  16259. {clif_parse_ProduceMix,"producemix"},
  16260. {clif_parse_Cooking,"cooking"},
  16261. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  16262. {clif_parse_NpcNextClicked,"npcnextclicked"},
  16263. {clif_parse_NpcAmountInput,"npcamountinput"},
  16264. {clif_parse_NpcStringInput,"npcstringinput"},
  16265. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  16266. {clif_parse_ItemIdentify,"itemidentify"},
  16267. {clif_parse_SelectArrow,"selectarrow"},
  16268. {clif_parse_AutoSpell,"autospell"},
  16269. {clif_parse_UseCard,"usecard"},
  16270. {clif_parse_InsertCard,"insertcard"},
  16271. {clif_parse_RepairItem,"repairitem"},
  16272. {clif_parse_WeaponRefine,"weaponrefine"},
  16273. {clif_parse_SolveCharName,"solvecharname"},
  16274. {clif_parse_ResetChar,"resetchar"},
  16275. {clif_parse_LocalBroadcast,"localbroadcast"},
  16276. {clif_parse_MoveToKafra,"movetokafra"},
  16277. {clif_parse_MoveFromKafra,"movefromkafra"},
  16278. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  16279. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  16280. {clif_parse_CloseKafra,"closekafra"},
  16281. {clif_parse_CreateParty,"createparty"},
  16282. {clif_parse_CreateParty2,"createparty2"},
  16283. {clif_parse_PartyInvite,"partyinvite"},
  16284. {clif_parse_PartyInvite2,"partyinvite2"},
  16285. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  16286. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  16287. {clif_parse_LeaveParty,"leaveparty"},
  16288. {clif_parse_RemovePartyMember,"removepartymember"},
  16289. {clif_parse_PartyChangeOption,"partychangeoption"},
  16290. {clif_parse_PartyMessage,"partymessage"},
  16291. {clif_parse_PartyChangeLeader,"partychangeleader"},
  16292. {clif_parse_CloseVending,"closevending"},
  16293. {clif_parse_VendingListReq,"vendinglistreq"},
  16294. {clif_parse_PurchaseReq,"purchasereq"},
  16295. {clif_parse_PurchaseReq2,"purchasereq2"},
  16296. {clif_parse_OpenVending,"openvending"},
  16297. {clif_parse_CreateGuild,"createguild"},
  16298. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  16299. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  16300. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  16301. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  16302. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  16303. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  16304. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  16305. {clif_parse_GuildInvite,"guildinvite"},
  16306. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  16307. {clif_parse_GuildLeave,"guildleave"},
  16308. {clif_parse_GuildExpulsion,"guildexpulsion"},
  16309. {clif_parse_GuildMessage,"guildmessage"},
  16310. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  16311. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  16312. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  16313. {clif_parse_GuildOpposition,"guildopposition"},
  16314. {clif_parse_GuildBreak,"guildbreak"},
  16315. {clif_parse_PetMenu,"petmenu"},
  16316. {clif_parse_CatchPet,"catchpet"},
  16317. {clif_parse_SelectEgg,"selectegg"},
  16318. {clif_parse_SendEmotion,"sendemotion"},
  16319. {clif_parse_ChangePetName,"changepetname"},
  16320. {clif_parse_GMKick,"gmkick"},
  16321. {clif_parse_GMHide,"gmhide"},
  16322. {clif_parse_GMReqNoChat,"gmreqnochat"},
  16323. {clif_parse_GMReqAccountName,"gmreqaccname"},
  16324. {clif_parse_GMKickAll,"killall"},
  16325. {clif_parse_GMRecall,"recall"},
  16326. {clif_parse_GMRecall,"summon"},
  16327. {clif_parse_GM_Item_Monster,"itemmonster"},
  16328. {clif_parse_GMShift,"remove"},
  16329. {clif_parse_GMShift,"shift"},
  16330. {clif_parse_GMChangeMapType,"changemaptype"},
  16331. {clif_parse_GMRc,"rc"},
  16332. {clif_parse_GMRecall2,"recall2"},
  16333. {clif_parse_GMRemove2,"remove2"},
  16334. {clif_parse_GMFullStrip,"gmfullstrip"},
  16335. {clif_parse_NoviceDoriDori,"sndoridori"},
  16336. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  16337. {clif_parse_PMIgnore,"wisexin"},
  16338. {clif_parse_PMIgnoreList,"wisexlist"},
  16339. {clif_parse_PMIgnoreAll,"wisall"},
  16340. {clif_parse_FriendsListAdd,"friendslistadd"},
  16341. {clif_parse_FriendsListRemove,"friendslistremove"},
  16342. {clif_parse_FriendsListReply,"friendslistreply"},
  16343. {clif_parse_Blacksmith,"blacksmith"},
  16344. {clif_parse_Alchemist,"alchemist"},
  16345. {clif_parse_Taekwon,"taekwon"},
  16346. {clif_parse_RankingPk,"rankingpk"},
  16347. {clif_parse_FeelSaveOk,"feelsaveok"},
  16348. {clif_parse_debug,"debug"},
  16349. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  16350. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  16351. {clif_parse_HomMoveTo,"hommoveto"},
  16352. {clif_parse_HomAttack,"homattack"},
  16353. {clif_parse_HomMenu,"hommenu"},
  16354. {clif_parse_StoragePassword,"storagepassword"},
  16355. {clif_parse_Hotkey,"hotkey"},
  16356. {clif_parse_AutoRevive,"autorevive"},
  16357. {clif_parse_Check,"check"},
  16358. {clif_parse_Adopt_request,"adoptrequest"},
  16359. {clif_parse_Adopt_reply,"adoptreply"},
  16360. // MAIL SYSTEM
  16361. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  16362. {clif_parse_Mail_read,"mailread"},
  16363. {clif_parse_Mail_getattach,"mailgetattach"},
  16364. {clif_parse_Mail_delete,"maildelete"},
  16365. {clif_parse_Mail_return,"mailreturn"},
  16366. {clif_parse_Mail_setattach,"mailsetattach"},
  16367. {clif_parse_Mail_winopen,"mailwinopen"},
  16368. {clif_parse_Mail_send,"mailsend"},
  16369. // AUCTION SYSTEM
  16370. {clif_parse_Auction_search,"auctionsearch"},
  16371. {clif_parse_Auction_buysell,"auctionbuysell"},
  16372. {clif_parse_Auction_setitem,"auctionsetitem"},
  16373. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  16374. {clif_parse_Auction_register,"auctionregister"},
  16375. {clif_parse_Auction_cancel,"auctioncancel"},
  16376. {clif_parse_Auction_close,"auctionclose"},
  16377. {clif_parse_Auction_bid,"auctionbid"},
  16378. // Quest Log System
  16379. {clif_parse_questStateAck,"queststate"},
  16380. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  16381. {clif_parse_EquipTick,"equiptickbox"},
  16382. {clif_parse_BattleChat,"battlechat"},
  16383. {clif_parse_mercenary_action,"mermenu"},
  16384. {clif_parse_progressbar,"progressbar"},
  16385. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  16386. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  16387. #if PACKETVER >= 20091229
  16388. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  16389. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  16390. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  16391. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  16392. #endif
  16393. {clif_parse_BankCheck,"bankcheck"},
  16394. {clif_parse_BankDeposit,"bankdeposit"},
  16395. {clif_parse_BankWithdraw,"bankwithdrawal"},
  16396. {clif_parse_BankOpen,"bankopen"},
  16397. {clif_parse_BankClose,"bankclose"},
  16398. {clif_parse_PVPInfo,"pvpinfo"},
  16399. {clif_parse_LessEffect,"lesseffect"},
  16400. // Buying Store
  16401. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  16402. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  16403. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  16404. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  16405. // Store Search
  16406. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  16407. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  16408. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  16409. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  16410. // Cashshop
  16411. { clif_parse_cashshop_open_request, "cashshopopen" },
  16412. { clif_parse_cashshop_close, "cashshopclose" },
  16413. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  16414. { clif_parse_cashshop_buy, "cashshopbuy" },
  16415. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  16416. /* */
  16417. { clif_parse_MoveItem , "moveitem" },
  16418. { clif_parse_PartyTick, "partytick" },
  16419. { clif_parse_dull, "dull" },
  16420. { clif_parse_GuildInvite2 , "guildinvite2" },
  16421. { clif_parse_reqworldinfo, "reqworldinfo"},
  16422. { clif_parse_client_version, "clientversion"},
  16423. { clif_parse_blocking_playcancel, "booking_playcancel"},
  16424. { clif_parse_ranklist, "ranklist"},
  16425. // Market NPC
  16426. { clif_parse_NPCShopClosed, "npcshopclosed" },
  16427. { clif_parse_NPCMarketClosed, "npcmarketclosed" },
  16428. { clif_parse_NPCMarketPurchase, "npcmarketpurchase" },
  16429. // Roulette
  16430. { clif_parse_RouletteOpen, "rouletteopen" },
  16431. { clif_parse_RouletteInfo, "rouletteinfo" },
  16432. { clif_parse_RouletteClose, "rouletteclose" },
  16433. { clif_parse_RouletteGenerate, "roulettegenerate" },
  16434. { clif_parse_RouletteRecvItem, "rouletterecvitem" },
  16435. // Merge Item
  16436. { clif_parse_merge_item_req, "mergeitem_req"},
  16437. { clif_parse_merge_item_cancel, "mergeitem_cancel"},
  16438. // HotkeyRowShift
  16439. { clif_parse_HotkeyRowShift, "hotkeyrowshift"},
  16440. // OneClick Item Identify
  16441. { clif_parse_Oneclick_Itemidentify, "oneclick_itemidentify" },
  16442. // NewChange Cart2
  16443. { clif_parse_SelectCart, "selectcart" },
  16444. {NULL,NULL}
  16445. };
  16446. struct {
  16447. char *name; //function name
  16448. int funcidx; //
  16449. } clif_ack_func[]={ //hash
  16450. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  16451. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  16452. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  16453. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16454. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  16455. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  16456. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  16457. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  16458. { "ZC_C_MARKERINFO", ZC_C_MARKERINFO},
  16459. { "ZC_NOTIFY_BIND_ON_EQUIP", ZC_NOTIFY_BIND_ON_EQUIP },
  16460. { "ZC_WEAR_EQUIP_ACK", ZC_WEAR_EQUIP_ACK },
  16461. { "ZC_MERGE_ITEM_OPEN", ZC_MERGE_ITEM_OPEN },
  16462. { "ZC_ACK_MERGE_ITEM", ZC_ACK_MERGE_ITEM },
  16463. { "ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN", ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN },
  16464. };
  16465. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  16466. int f;
  16467. memset(packet_db,0,sizeof(packet_db));
  16468. memset(packet_db_ack,0,sizeof(packet_db_ack));
  16469. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  16470. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  16471. packet_len(i) = packet_len_table[i];
  16472. clif_config.packet_db_ver = MAX_PACKET_VER;
  16473. for(f = 0; f < ARRAYLENGTH(filename); f++) {
  16474. FILE *fp;
  16475. int ln = 0;
  16476. int entries = 0;
  16477. char *str[64], *p, *str2[64], *p2;
  16478. sprintf(line, "%s/%s", db_path, filename[f]);
  16479. if( (fp = fopen(line,"r")) == NULL ) {
  16480. if (f == 0) {
  16481. ShowFatalError("Can't read %s\n", line);
  16482. exit(EXIT_FAILURE);
  16483. }
  16484. return;
  16485. }
  16486. while( fgets(line, sizeof(line), fp) ) {
  16487. char w1[256],w2[256];
  16488. ln++;
  16489. if(line[0]=='/' && line[1]=='/')
  16490. continue;
  16491. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2) {
  16492. if (strcmpi(w1,"packet_ver") == 0) {
  16493. int prev_ver = packet_ver;
  16494. skip_ver = false;
  16495. packet_ver = atoi(w2);
  16496. if ( packet_ver > MAX_PACKET_VER )
  16497. { //Check to avoid overflowing. [Skotlex]
  16498. if( (warned&1) == 0 )
  16499. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  16500. warned &= 1;
  16501. skip_ver = true;
  16502. }
  16503. else if( packet_ver < 0 )
  16504. {
  16505. if( (warned&2) == 0 )
  16506. ShowWarning("Negative packet versions are not supported.\n");
  16507. warned &= 2;
  16508. skip_ver = true;
  16509. }
  16510. else if( packet_ver == SERVER )
  16511. {
  16512. if( (warned&4) == 0 )
  16513. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  16514. warned &= 4;
  16515. skip_ver = true;
  16516. }
  16517. if( skip_ver )
  16518. {
  16519. ShowWarning("Skipping packet version %d.\n", packet_ver);
  16520. packet_ver = prev_ver;
  16521. continue;
  16522. }
  16523. // copy from previous version into new version and continue
  16524. // - indicating all following packets should be read into the newer version
  16525. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  16526. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  16527. continue;
  16528. } else if(strcmpi(w1,"packet_db_ver")==0) {
  16529. if (strcmpi(w2,"default") == 0) //This is the preferred version.
  16530. clif_config.packet_db_ver = MAX_PACKET_VER;
  16531. else // to manually set the packet DB version
  16532. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  16533. continue;
  16534. }
  16535. #ifdef PACKET_OBFUSCATION
  16536. else if (!reload && strcmpi(w1,"packet_keys") == 0) {
  16537. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16538. trim(w2);
  16539. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16540. if (!packet_keys[packet_ver])
  16541. CREATE(packet_keys[packet_ver], struct s_packet_keys, 1);
  16542. packet_keys[packet_ver]->keys[0] = strtol(key1, NULL, 0);
  16543. packet_keys[packet_ver]->keys[1] = strtol(key2, NULL, 0);
  16544. packet_keys[packet_ver]->keys[2] = strtol(key3, NULL, 0);
  16545. last_key_defined = packet_ver;
  16546. if (battle_config.etc_log)
  16547. 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]);
  16548. }
  16549. continue;
  16550. } else if (!reload && strcmpi(w1,"packet_keys_use") == 0) {
  16551. char key1[12] = { 0 }, key2[12] = { 0 }, key3[12] = { 0 };
  16552. trim(w2);
  16553. if (strcmpi(w2,"default") == 0)
  16554. continue;
  16555. if (sscanf(w2, "%11[^,],%11[^,],%11[^ \r\n/]", key1, key2, key3) == 3) {
  16556. clif_cryptKey[0] = strtol(key1, NULL, 0);
  16557. clif_cryptKey[1] = strtol(key2, NULL, 0);
  16558. clif_cryptKey[2] = strtol(key3, NULL, 0);
  16559. key_defined = true;
  16560. if (battle_config.etc_log)
  16561. ShowInfo("Defined keys: 0x%08X, 0x%08X, 0x%08X\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  16562. }
  16563. continue;
  16564. }
  16565. #endif
  16566. }
  16567. if( skip_ver )
  16568. continue; // Skipping current packet version
  16569. memset(str,0,sizeof(str));
  16570. for (j = 0, p = line; j < 4 && p; ++j) {
  16571. str[j] = p;
  16572. p = strchr(p,',');
  16573. if (p)
  16574. *p++=0;
  16575. }
  16576. if (str[0] == NULL)
  16577. continue;
  16578. cmd = strtol(str[0],(char **)NULL,0);
  16579. if(max_cmd < cmd)
  16580. max_cmd = cmd;
  16581. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  16582. continue;
  16583. if(str[1]==NULL){
  16584. ShowError("packet_db: packet len error\n");
  16585. continue;
  16586. }
  16587. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  16588. if(str[2]==NULL){
  16589. packet_db[packet_ver][cmd].func = NULL;
  16590. ln++;
  16591. continue;
  16592. }
  16593. // look up processing function by name
  16594. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  16595. if( j < ARRAYLENGTH(clif_parse_func) )
  16596. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  16597. else { //search if it's a mapped ack func
  16598. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  16599. if( j < ARRAYLENGTH(clif_ack_func)) {
  16600. int fidx = clif_ack_func[j].funcidx;
  16601. packet_db_ack[packet_ver][fidx] = cmd;
  16602. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  16603. }
  16604. }
  16605. // set the identifying cmd for the packet_db version
  16606. if (strcmp(str[2],"wanttoconnection")==0)
  16607. clif_config.connect_cmd[packet_ver] = cmd;
  16608. if(str[3]==NULL){
  16609. ShowError("packet_db: packet error\n");
  16610. exit(EXIT_FAILURE);
  16611. }
  16612. for(j = 0, p2 = str[3]; p2; j++){
  16613. short k;
  16614. str2[j] = p2;
  16615. p2 = strchr(p2,':');
  16616. if(p2)
  16617. *p2++=0;
  16618. k = atoi(str2[j]);
  16619. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  16620. if( j >= MAX_PACKET_POS )
  16621. {
  16622. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  16623. break;
  16624. }
  16625. packet_db[packet_ver][cmd].pos[j] = k;
  16626. }
  16627. entries++;
  16628. }
  16629. fclose(fp);
  16630. if(max_cmd > MAX_PACKET_DB) {
  16631. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  16632. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  16633. }
  16634. //Locate the nearest version that we still support. [Skotlex]
  16635. if (!clif_config.connect_cmd[clif_config.packet_db_ver]) {
  16636. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  16637. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  16638. }
  16639. sprintf(line, "%s/%s", db_path,filename[f]);
  16640. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  16641. }
  16642. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  16643. #ifdef PACKET_OBFUSCATION
  16644. if (!key_defined && !clif_cryptKey[0] && !clif_cryptKey[1] && !clif_cryptKey[2]) { // Not defined
  16645. int use_key = last_key_defined;
  16646. if (last_key_defined == -1)
  16647. ShowError("Can't find packet obfuscation keys!\n");
  16648. else {
  16649. if (packet_keys[clif_config.packet_db_ver])
  16650. use_key = clif_config.packet_db_ver;
  16651. ShowInfo("Using default packet obfuscation keys for packet_db_ver: %d\n", use_key);
  16652. memcpy(&clif_cryptKey, &packet_keys[use_key]->keys, sizeof(packet_keys[use_key]->keys));
  16653. }
  16654. }
  16655. 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]);
  16656. for (i = 0; i < ARRAYLENGTH(packet_keys); i++) {
  16657. if (packet_keys[i]) {
  16658. aFree(packet_keys[i]);
  16659. packet_keys[i] = NULL;
  16660. }
  16661. }
  16662. #endif
  16663. }
  16664. /*==========================================
  16665. *
  16666. *------------------------------------------*/
  16667. void do_init_clif(void) {
  16668. const char* colors[COLOR_MAX] = {
  16669. "0x00FF00",
  16670. "0xFF0000",
  16671. "0xFFFFFF",
  16672. "0xFFFF00",
  16673. "0x00FFFF",
  16674. };
  16675. int i;
  16676. /**
  16677. * Setup Color Table (saves unnecessary load of strtoul on every call)
  16678. **/
  16679. for(i = 0; i < COLOR_MAX; i++) {
  16680. color_table[i] = strtoul(colors[i],NULL,0);
  16681. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  16682. }
  16683. clif_config.packet_db_ver = -1; // the main packet version of the DB
  16684. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  16685. #ifdef PACKET_OBFUSCATION
  16686. memset(clif_cryptKey, 0, sizeof(clif_cryptKey));
  16687. #endif
  16688. //Using the packet_db file is the only way to set up packets now [Skotlex]
  16689. packetdb_readdb(false);
  16690. set_defaultparse(clif_parse);
  16691. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  16692. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  16693. exit(EXIT_FAILURE);
  16694. }
  16695. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  16696. add_timer_func_list(clif_delayquit, "clif_delayquit");
  16697. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  16698. }
  16699. void do_final_clif(void) {
  16700. ers_destroy(delay_clearunit_ers);
  16701. }