clif.c 520 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218
  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. /** Converts item type to display it on client if necessary.
  62. * @param nameid: Item ID
  63. * @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
  64. */
  65. static inline int itemtype(unsigned short nameid) {
  66. 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
  67. int type = id->type;
  68. if( type == IT_SHADOWGEAR ) {
  69. if( id->equip&EQP_SHADOW_WEAPON )
  70. return IT_WEAPON;
  71. else
  72. return IT_ARMOR;
  73. }
  74. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  75. }
  76. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  77. p += pos;
  78. p[0] = (uint8)(x>>2);
  79. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  80. p[2] = (uint8)((y<<4) | (dir&0xf));
  81. }
  82. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  83. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  84. p += pos;
  85. p[0] = (uint8)(x0>>2);
  86. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  87. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  88. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  89. p[4] = (uint8)y1;
  90. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  91. }
  92. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  93. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  94. }
  95. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  96. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  97. }
  98. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  99. p += pos;
  100. if( x ) {
  101. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  102. }
  103. if( y ) {
  104. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  105. }
  106. if( dir ) {
  107. dir[0] = ( p[2] & 0x0f );
  108. }
  109. }
  110. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  111. p += pos;
  112. if( x0 ) {
  113. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  114. }
  115. if( y0 ) {
  116. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  117. }
  118. if( x1 ) {
  119. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  120. }
  121. if( y1 ) {
  122. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  123. }
  124. if( sx0 ) {
  125. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  126. }
  127. if( sy0 ) {
  128. sy0[0] = ( p[5] & 0x0f ) >> 0;
  129. }
  130. }
  131. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  132. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  133. }
  134. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  135. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  136. }
  137. //To idenfity disguised characters.
  138. static inline bool disguised(struct block_list* bl) {
  139. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  140. }
  141. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  142. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  143. if( len > max )
  144. len = max;
  145. mes[len-1] = '\0';
  146. return len;
  147. }
  148. static char map_ip_str[128];
  149. static uint32 map_ip;
  150. static uint32 bind_ip = INADDR_ANY;
  151. static uint16 map_port = 5121;
  152. static bool clif_ally_only = false;
  153. int map_fd;
  154. static int clif_parse (int fd);
  155. /*==========================================
  156. * Ip setting of map-server
  157. *------------------------------------------*/
  158. int clif_setip(const char* ip) {
  159. char ip_str[16];
  160. map_ip = host2ip(ip);
  161. if (!map_ip) {
  162. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  163. return 0;
  164. }
  165. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  166. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  167. return 1;
  168. }
  169. void clif_setbindip(const char* ip)
  170. {
  171. bind_ip = host2ip(ip);
  172. if (bind_ip) {
  173. char ip_str[16];
  174. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  175. } else {
  176. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  177. }
  178. }
  179. /*==========================================
  180. * Sets map port to 'port'
  181. * is run from map.c upon loading map server configuration
  182. *------------------------------------------*/
  183. void clif_setport(uint16 port)
  184. {
  185. map_port = port;
  186. }
  187. /*==========================================
  188. * Returns map server IP
  189. *------------------------------------------*/
  190. uint32 clif_getip(void)
  191. {
  192. return map_ip;
  193. }
  194. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  195. uint32 clif_refresh_ip(void)
  196. {
  197. uint32 new_ip;
  198. new_ip = host2ip(map_ip_str);
  199. if (new_ip && new_ip != map_ip) {
  200. map_ip = new_ip;
  201. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  202. return map_ip;
  203. }
  204. return 0;
  205. }
  206. /*==========================================
  207. * Returns map port which is set by clif_setport()
  208. *------------------------------------------*/
  209. uint16 clif_getport(void)
  210. {
  211. return map_port;
  212. }
  213. #if PACKETVER >= 20071106
  214. static inline unsigned char clif_bl_type(struct block_list *bl) {
  215. switch (bl->type) {
  216. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  217. case BL_ITEM: return 0x2; //ITEM_TYPE
  218. case BL_SKILL: return 0x3; //SKILL_TYPE
  219. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  220. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  221. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  222. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  223. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  224. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  225. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  226. default: return 0x1; //NPC_TYPE
  227. }
  228. }
  229. #endif
  230. /*==========================================
  231. * sub process of clif_send
  232. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  233. * In order to send area-wise packets, such as:
  234. * - AREA : everyone nearby your area
  235. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  236. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  237. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  238. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  239. *------------------------------------------*/
  240. static int clif_send_sub(struct block_list *bl, va_list ap)
  241. {
  242. struct block_list *src_bl;
  243. struct map_session_data *sd;
  244. unsigned char *buf;
  245. int len, type, fd;
  246. nullpo_ret(bl);
  247. nullpo_ret(sd = (struct map_session_data *)bl);
  248. fd = sd->fd;
  249. if (!fd) //Don't send to disconnected clients.
  250. return 0;
  251. buf = va_arg(ap,unsigned char*);
  252. len = va_arg(ap,int);
  253. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  254. type = va_arg(ap,int);
  255. switch(type) {
  256. case AREA_WOS:
  257. if (bl == src_bl)
  258. return 0;
  259. break;
  260. case AREA_WOC:
  261. if (sd->chatID || bl == src_bl)
  262. return 0;
  263. break;
  264. case AREA_WOSC:
  265. {
  266. if(src_bl->type == BL_PC) {
  267. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  268. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  269. return 0;
  270. }
  271. else if(src_bl->type == BL_NPC) {
  272. struct npc_data *nd = (struct npc_data *)src_bl;
  273. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  274. return 0;
  275. }
  276. }
  277. break;
  278. }
  279. if (session[fd] == NULL)
  280. return 0;
  281. /* unless visible, hold it here */
  282. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  283. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  284. return 0;
  285. WFIFOHEAD(fd, len);
  286. if (WFIFOP(fd,0) == buf) {
  287. ShowError("WARNING: Invalid use of clif_send function\n");
  288. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  289. ShowError(" Please correct your code.\n");
  290. // don't send to not move the pointer of the packet for next sessions in the loop
  291. //WFIFOSET(fd,0);//## TODO is this ok?
  292. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  293. return 0;
  294. }
  295. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  296. memcpy(WFIFOP(fd,0), buf, len);
  297. WFIFOSET(fd,len);
  298. }
  299. return 0;
  300. }
  301. /*==========================================
  302. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  303. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  304. *------------------------------------------*/
  305. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  306. {
  307. int i;
  308. struct map_session_data *sd, *tsd;
  309. struct party_data *p = NULL;
  310. struct guild *g = NULL;
  311. struct battleground_data *bg = NULL;
  312. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  313. struct s_mapiterator* iter;
  314. if( type != ALL_CLIENT )
  315. nullpo_ret(bl);
  316. sd = BL_CAST(BL_PC, bl);
  317. switch(type) {
  318. case ALL_CLIENT: //All player clients.
  319. iter = mapit_getallusers();
  320. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  321. {
  322. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  323. { // packet must exist for the client version
  324. WFIFOHEAD(tsd->fd, len);
  325. memcpy(WFIFOP(tsd->fd,0), buf, len);
  326. WFIFOSET(tsd->fd,len);
  327. }
  328. }
  329. mapit_free(iter);
  330. break;
  331. case ALL_SAMEMAP: //All players on the same map
  332. iter = mapit_getallusers();
  333. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  334. {
  335. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  336. { // packet must exist for the client version
  337. WFIFOHEAD(tsd->fd, len);
  338. memcpy(WFIFOP(tsd->fd,0), buf, len);
  339. WFIFOSET(tsd->fd,len);
  340. }
  341. }
  342. mapit_free(iter);
  343. break;
  344. case AREA:
  345. case AREA_WOSC:
  346. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  347. clif_send (buf, len, bl, SELF);
  348. case AREA_WOC:
  349. case AREA_WOS:
  350. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  351. BL_PC, buf, len, bl, type);
  352. break;
  353. case AREA_CHAT_WOC:
  354. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  355. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  356. break;
  357. case CHAT:
  358. case CHAT_WOS:
  359. {
  360. struct chat_data *cd;
  361. if (sd) {
  362. cd = (struct chat_data*)map_id2bl(sd->chatID);
  363. } else if (bl->type == BL_CHAT) {
  364. cd = (struct chat_data*)bl;
  365. } else break;
  366. if (cd == NULL)
  367. break;
  368. for(i = 0; i < cd->users; i++) {
  369. if (type == CHAT_WOS && cd->usersd[i] == sd)
  370. continue;
  371. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  372. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  373. {
  374. WFIFOHEAD(fd,len);
  375. memcpy(WFIFOP(fd,0), buf, len);
  376. WFIFOSET(fd,len);
  377. }
  378. }
  379. }
  380. }
  381. break;
  382. case PARTY_AREA:
  383. case PARTY_AREA_WOS:
  384. x0 = bl->x - AREA_SIZE;
  385. y0 = bl->y - AREA_SIZE;
  386. x1 = bl->x + AREA_SIZE;
  387. y1 = bl->y + AREA_SIZE;
  388. case PARTY:
  389. case PARTY_WOS:
  390. case PARTY_SAMEMAP:
  391. case PARTY_SAMEMAP_WOS:
  392. if (sd && sd->status.party_id)
  393. p = party_search(sd->status.party_id);
  394. if (p) {
  395. for(i=0;i<MAX_PARTY;i++){
  396. if( (sd = p->data[i].sd) == NULL )
  397. continue;
  398. if( !(fd=sd->fd) )
  399. continue;
  400. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  401. continue;
  402. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  403. continue;
  404. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  405. continue;
  406. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  407. { // packet must exist for the client version
  408. WFIFOHEAD(fd,len);
  409. memcpy(WFIFOP(fd,0), buf, len);
  410. WFIFOSET(fd,len);
  411. }
  412. }
  413. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  414. break;
  415. iter = mapit_getallusers();
  416. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  417. {
  418. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  419. { // packet must exist for the client version
  420. WFIFOHEAD(tsd->fd, len);
  421. memcpy(WFIFOP(tsd->fd,0), buf, len);
  422. WFIFOSET(tsd->fd,len);
  423. }
  424. }
  425. mapit_free(iter);
  426. }
  427. break;
  428. case DUEL:
  429. case DUEL_WOS:
  430. if (!sd || !sd->duel_group) break; //Invalid usage.
  431. iter = mapit_getallusers();
  432. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  433. {
  434. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  435. continue;
  436. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  437. { // packet must exist for the client version
  438. WFIFOHEAD(tsd->fd, len);
  439. memcpy(WFIFOP(tsd->fd,0), buf, len);
  440. WFIFOSET(tsd->fd,len);
  441. }
  442. }
  443. mapit_free(iter);
  444. break;
  445. case SELF:
  446. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  447. WFIFOHEAD(fd,len);
  448. memcpy(WFIFOP(fd,0), buf, len);
  449. WFIFOSET(fd,len);
  450. }
  451. break;
  452. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  453. case GUILD_AREA:
  454. case GUILD_AREA_WOS:
  455. x0 = bl->x - AREA_SIZE;
  456. y0 = bl->y - AREA_SIZE;
  457. x1 = bl->x + AREA_SIZE;
  458. y1 = bl->y + AREA_SIZE;
  459. case GUILD_SAMEMAP:
  460. case GUILD_SAMEMAP_WOS:
  461. case GUILD:
  462. case GUILD_WOS:
  463. case GUILD_NOBG:
  464. if (sd && sd->status.guild_id)
  465. g = sd->guild;
  466. if (g) {
  467. for(i = 0; i < g->max_member; i++) {
  468. if( (sd = g->member[i].sd) != NULL )
  469. {
  470. if( !(fd=sd->fd) )
  471. continue;
  472. if( type == GUILD_NOBG && sd->bg_id )
  473. continue;
  474. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  475. continue;
  476. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  477. continue;
  478. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  479. continue;
  480. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  481. { // packet must exist for the client version
  482. WFIFOHEAD(fd,len);
  483. memcpy(WFIFOP(fd,0), buf, len);
  484. WFIFOSET(fd,len);
  485. }
  486. }
  487. }
  488. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  489. break;
  490. iter = mapit_getallusers();
  491. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  492. {
  493. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  494. { // packet must exist for the client version
  495. WFIFOHEAD(tsd->fd, len);
  496. memcpy(WFIFOP(tsd->fd,0), buf, len);
  497. WFIFOSET(tsd->fd,len);
  498. }
  499. }
  500. mapit_free(iter);
  501. }
  502. break;
  503. case BG_AREA:
  504. case BG_AREA_WOS:
  505. x0 = bl->x - AREA_SIZE;
  506. y0 = bl->y - AREA_SIZE;
  507. x1 = bl->x + AREA_SIZE;
  508. y1 = bl->y + AREA_SIZE;
  509. case BG_SAMEMAP:
  510. case BG_SAMEMAP_WOS:
  511. case BG:
  512. case BG_WOS:
  513. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  514. {
  515. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  516. {
  517. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  518. continue;
  519. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  520. continue;
  521. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  522. continue;
  523. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  524. continue;
  525. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  526. { // packet must exist for the client version
  527. WFIFOHEAD(fd,len);
  528. memcpy(WFIFOP(fd,0), buf, len);
  529. WFIFOSET(fd,len);
  530. }
  531. }
  532. }
  533. break;
  534. default:
  535. ShowError("clif_send: Unrecognized type %d\n",type);
  536. return -1;
  537. }
  538. return 0;
  539. }
  540. /// Notifies the client, that it's connection attempt was accepted.
  541. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  542. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  543. void clif_authok(struct map_session_data *sd)
  544. {
  545. #if PACKETVER < 20080102
  546. const int cmd = 0x73;
  547. #else
  548. const int cmd = 0x2eb;
  549. #endif
  550. int fd = sd->fd;
  551. WFIFOHEAD(fd,packet_len(cmd));
  552. WFIFOW(fd, 0) = cmd;
  553. WFIFOL(fd, 2) = gettick();
  554. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  555. WFIFOB(fd, 9) = 5; // ignored
  556. WFIFOB(fd,10) = 5; // ignored
  557. #if PACKETVER >= 20080102
  558. WFIFOW(fd,11) = sd->status.font;
  559. #endif
  560. WFIFOSET(fd,packet_len(cmd));
  561. }
  562. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  563. /// 0074 <error code>.B
  564. /// error code:
  565. /// 0 = client type mismatch
  566. /// 1 = ID mismatch
  567. /// 2 = mobile - out of available time
  568. /// 3 = mobile - already logged in
  569. /// 4 = mobile - waiting state
  570. void clif_authrefuse(int fd, uint8 error_code)
  571. {
  572. WFIFOHEAD(fd,packet_len(0x74));
  573. WFIFOW(fd,0) = 0x74;
  574. WFIFOB(fd,2) = error_code;
  575. WFIFOSET(fd,packet_len(0x74));
  576. }
  577. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  578. /// 0081 <error code>.B
  579. /// error code:
  580. /// 0 = BAN_UNFAIR
  581. /// 1 = server closed -> MsgStringTable[4]
  582. /// 2 = ID already logged in -> MsgStringTable[5]
  583. /// 3 = timeout/too much lag -> MsgStringTable[241]
  584. /// 4 = server full -> MsgStringTable[264]
  585. /// 5 = underaged -> MsgStringTable[305]
  586. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  587. /// 9 = too many connections from this ip -> MsgStringTable[529]
  588. /// 10 = out of available time paid for -> MsgStringTable[530]
  589. /// 11 = BAN_PAY_SUSPEND
  590. /// 12 = BAN_PAY_CHANGE
  591. /// 13 = BAN_PAY_WRONGIP
  592. /// 14 = BAN_PAY_PNGAMEROOM
  593. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  594. /// 16 = BAN_JAPAN_REFUSE1
  595. /// 17 = BAN_JAPAN_REFUSE2
  596. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  597. /// 100 = BAN_PC_IP_UNFAIR
  598. /// 101 = BAN_PC_IP_COUNT_ALL
  599. /// 102 = BAN_PC_IP_COUNT
  600. /// 103 = BAN_GRAVITY_MEM_AGREE
  601. /// 104 = BAN_GAME_MEM_AGREE
  602. /// 105 = BAN_HAN_VALID
  603. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  604. /// 107 = BAN_OVER_CHARACTER_LIST
  605. /// 108 = BAN_IP_BLOCK
  606. /// 109 = BAN_INVALID_PWD_CNT
  607. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  608. /// ? = disconnected -> MsgStringTable[3]
  609. void clif_authfail_fd(int fd, int type)
  610. {
  611. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  612. return;
  613. WFIFOHEAD(fd, packet_len(0x81));
  614. WFIFOW(fd,0) = 0x81;
  615. WFIFOB(fd,2) = type;
  616. WFIFOSET(fd,packet_len(0x81));
  617. set_eof(fd);
  618. }
  619. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  620. /// 00b3 <type>.B
  621. /// type:
  622. /// 1 = disconnect, char-select
  623. /// ? = nothing
  624. void clif_charselectok(int id, uint8 ok)
  625. {
  626. struct map_session_data* sd;
  627. int fd;
  628. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  629. return;
  630. fd = sd->fd;
  631. WFIFOHEAD(fd,packet_len(0xb3));
  632. WFIFOW(fd,0) = 0xb3;
  633. WFIFOB(fd,2) = ok;
  634. WFIFOSET(fd,packet_len(0xb3));
  635. }
  636. /// Makes an item appear on the ground.
  637. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  638. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  639. void clif_dropflooritem(struct flooritem_data* fitem)
  640. {
  641. #if PACKETVER >= 20130000
  642. uint8 buf[19];
  643. uint32 header=0x84b;
  644. #else
  645. uint8 buf[17];
  646. uint32 header=0x09e;
  647. #endif
  648. int view, offset=0;
  649. nullpo_retv(fitem);
  650. if (fitem->item_data.nameid == 0)
  651. return;
  652. WBUFW(buf, offset+0) = header;
  653. WBUFL(buf, offset+2) = fitem->bl.id;
  654. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  655. #if PACKETVER >= 20130000
  656. WBUFW(buf, offset+8) = itemtype(fitem->item_data.nameid);
  657. offset +=2;
  658. #endif
  659. WBUFB(buf, offset+8) = fitem->item_data.identify;
  660. WBUFW(buf, offset+9) = fitem->bl.x;
  661. WBUFW(buf, offset+11) = fitem->bl.y;
  662. WBUFB(buf, offset+13) = fitem->subx;
  663. WBUFB(buf, offset+14) = fitem->suby;
  664. WBUFW(buf, offset+15) = fitem->item_data.amount;
  665. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  666. }
  667. /// Makes an item disappear from the ground.
  668. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  669. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  670. {
  671. unsigned char buf[16];
  672. nullpo_retv(fitem);
  673. WBUFW(buf,0) = 0xa1;
  674. WBUFL(buf,2) = fitem->bl.id;
  675. if (fd == 0) {
  676. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  677. } else {
  678. WFIFOHEAD(fd,packet_len(0xa1));
  679. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  680. WFIFOSET(fd,packet_len(0xa1));
  681. }
  682. }
  683. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  684. /// 0080 <id>.L <type>.B
  685. /// type:
  686. /// 0 = out of sight
  687. /// 1 = died
  688. /// 2 = logged out
  689. /// 3 = teleport
  690. /// 4 = trickdead
  691. void clif_clearunit_single(int id, clr_type type, int fd)
  692. {
  693. WFIFOHEAD(fd, packet_len(0x80));
  694. WFIFOW(fd,0) = 0x80;
  695. WFIFOL(fd,2) = id;
  696. WFIFOB(fd,6) = type;
  697. WFIFOSET(fd, packet_len(0x80));
  698. }
  699. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  700. /// 0080 <id>.L <type>.B
  701. /// type:
  702. /// 0 = out of sight
  703. /// 1 = died
  704. /// 2 = logged out
  705. /// 3 = teleport
  706. /// 4 = trickdead
  707. void clif_clearunit_area(struct block_list* bl, clr_type type)
  708. {
  709. unsigned char buf[8];
  710. nullpo_retv(bl);
  711. WBUFW(buf,0) = 0x80;
  712. WBUFL(buf,2) = bl->id;
  713. WBUFB(buf,6) = type;
  714. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  715. if(disguised(bl)) {
  716. WBUFL(buf,2) = -bl->id;
  717. clif_send(buf, packet_len(0x80), bl, SELF);
  718. }
  719. }
  720. /// Used to make monsters with player-sprites disappear after dying
  721. /// like normal monsters, because the client does not remove those
  722. /// automatically.
  723. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  724. {
  725. struct block_list *bl = (struct block_list *)data;
  726. clif_clearunit_area(bl, (clr_type) id);
  727. ers_free(delay_clearunit_ers,bl);
  728. return 0;
  729. }
  730. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  731. {
  732. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  733. memcpy (tbl, bl, sizeof (struct block_list));
  734. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  735. }
  736. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  737. {
  738. if(sd->sc.option&OPTION_COSTUME)
  739. {
  740. *rhand = *lhand = 0;
  741. return;
  742. }
  743. #if PACKETVER < 4
  744. *rhand = sd->status.weapon;
  745. *lhand = sd->status.shield;
  746. #else
  747. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  748. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  749. {
  750. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  751. if (id->view_id > 0)
  752. *rhand = id->view_id;
  753. else
  754. *rhand = id->nameid;
  755. } else
  756. *rhand = 0;
  757. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  758. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  759. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  760. {
  761. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  762. if (id->view_id > 0)
  763. *lhand = id->view_id;
  764. else
  765. *lhand = id->nameid;
  766. } else
  767. *lhand = 0;
  768. #endif
  769. }
  770. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  771. static int clif_setlevel_sub(int lv) {
  772. if( lv < battle_config.max_lv ) {
  773. ;
  774. } else if( lv < battle_config.aura_lv ) {
  775. lv = battle_config.max_lv - 1;
  776. } else {
  777. lv = battle_config.max_lv;
  778. }
  779. return lv;
  780. }
  781. static int clif_setlevel(struct block_list* bl) {
  782. int lv = status_get_lv(bl);
  783. if( battle_config.client_limit_unit_lv&bl->type )
  784. return clif_setlevel_sub(lv);
  785. switch( bl->type ) {
  786. case BL_NPC:
  787. case BL_PET:
  788. // npcs and pets do not have level
  789. return 0;
  790. }
  791. return lv;
  792. }
  793. /*==========================================
  794. * Prepares 'unit standing/spawning' packet
  795. *------------------------------------------*/
  796. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  797. {
  798. struct map_session_data* sd;
  799. struct status_change* sc = status_get_sc(bl);
  800. struct view_data* vd = status_get_viewdata(bl);
  801. unsigned char *buf = WBUFP(buffer,0);
  802. #if PACKETVER < 20091103
  803. bool type = !pcdb_checkid(vd->class_);
  804. #endif
  805. unsigned short offset = 0;
  806. #if PACKETVER >= 20091103
  807. const char *name;
  808. #endif
  809. sd = BL_CAST(BL_PC, bl);
  810. #if PACKETVER < 20091103
  811. if(type)
  812. WBUFW(buf,0) = spawn?0x7c:0x78;
  813. else
  814. #endif
  815. #if PACKETVER < 4
  816. WBUFW(buf,0) = spawn?0x79:0x78;
  817. #elif PACKETVER < 7
  818. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  819. #elif PACKETVER < 20080102
  820. WBUFW(buf,0) = spawn?0x22b:0x22a;
  821. #elif PACKETVER < 20091103
  822. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  823. #elif PACKETVER < 20101124
  824. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  825. #else
  826. WBUFW(buf,0) = spawn?0x858:0x857;
  827. #endif
  828. #if PACKETVER >= 20091103
  829. name = status_get_name(bl);
  830. #if PACKETVER < 20110111
  831. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  832. #else
  833. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  834. #endif
  835. WBUFB(buf,4) = clif_bl_type(bl);
  836. offset+=3;
  837. buf = WBUFP(buffer,offset);
  838. #elif PACKETVER >= 20071106
  839. if (type) { //Non-player packets
  840. WBUFB(buf,2) = clif_bl_type(bl);
  841. offset++;
  842. buf = WBUFP(buffer,offset);
  843. }
  844. #endif
  845. WBUFL(buf, 2) = bl->id;
  846. WBUFW(buf, 6) = status_get_speed(bl);
  847. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  848. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  849. #if PACKETVER < 20091103
  850. if (type&&spawn) { //uses an older and different packet structure
  851. WBUFW(buf,12) = (sc)? sc->option : 0;
  852. WBUFW(buf,14) = vd->hair_style;
  853. WBUFW(buf,16) = vd->weapon;
  854. WBUFW(buf,18) = vd->head_bottom;
  855. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  856. WBUFW(buf,22) = vd->shield;
  857. } else {
  858. #endif
  859. #if PACKETVER >= 20091103
  860. WBUFL(buf,12) = (sc)? sc->option : 0;
  861. offset+=2;
  862. buf = WBUFP(buffer,offset);
  863. #elif PACKETVER >= 7
  864. if (!type) {
  865. WBUFL(buf,12) = (sc)? sc->option : 0;
  866. offset+=2;
  867. buf = WBUFP(buffer,offset);
  868. } else
  869. WBUFW(buf,12) = (sc)? sc->option : 0;
  870. #else
  871. WBUFW(buf,12) = (sc)? sc->option : 0;
  872. #endif
  873. WBUFW(buf,14) = vd->class_;
  874. WBUFW(buf,16) = vd->hair_style;
  875. WBUFW(buf,18) = vd->weapon;
  876. #if PACKETVER < 4
  877. WBUFW(buf,20) = vd->head_bottom;
  878. WBUFW(buf,22) = vd->shield;
  879. #else
  880. WBUFW(buf,20) = vd->shield;
  881. WBUFW(buf,22) = vd->head_bottom;
  882. #endif
  883. #if PACKETVER < 20091103
  884. }
  885. #endif
  886. WBUFW(buf,24) = vd->head_top;
  887. WBUFW(buf,26) = vd->head_mid;
  888. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  889. { //The hell, why flags work like this?
  890. WBUFW(buf,22) = status_get_emblem_id(bl);
  891. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  892. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  893. }
  894. WBUFW(buf,28) = vd->hair_color;
  895. WBUFW(buf,30) = vd->cloth_color;
  896. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  897. #if PACKETVER < 20091103
  898. if (type&&spawn) { //End of packet 0x7c
  899. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  900. WBUFB(buf,35) = vd->sex;
  901. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  902. WBUFB(buf,39) = 0;
  903. WBUFB(buf,40) = 0;
  904. return packet_len(0x7c);
  905. }
  906. #endif
  907. #if PACKETVER >= 20110111
  908. WBUFW(buf,34) = vd->robe;
  909. offset+= 2;
  910. buf = WBUFP(buffer,offset);
  911. #endif
  912. WBUFL(buf,34) = status_get_guild_id(bl);
  913. WBUFW(buf,38) = status_get_emblem_id(bl);
  914. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  915. #if PACKETVER >= 20091103
  916. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  917. offset+=2;
  918. buf = WBUFP(buffer,offset);
  919. #elif PACKETVER >= 7
  920. if (!type) {
  921. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  922. offset+=2;
  923. buf = WBUFP(buffer,offset);
  924. } else
  925. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  926. #else
  927. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  928. #endif
  929. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  930. WBUFB(buf,45) = vd->sex;
  931. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  932. WBUFB(buf,49) = (sd)? 5 : 0;
  933. WBUFB(buf,50) = (sd)? 5 : 0;
  934. if (!spawn) {
  935. WBUFB(buf,51) = vd->dead_sit;
  936. offset++;
  937. buf = WBUFP(buffer,offset);
  938. }
  939. WBUFW(buf,51) = clif_setlevel(bl);
  940. #if PACKETVER < 20091103
  941. if (type) //End for non-player packet
  942. return packet_len(WBUFW(buffer,0));
  943. #endif
  944. #if PACKETVER >= 20080102
  945. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  946. #endif
  947. #if PACKETVER >= 20091103
  948. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  949. return WBUFW(buffer,2);
  950. #else
  951. return packet_len(WBUFW(buffer,0));
  952. #endif
  953. }
  954. /*==========================================
  955. * Prepares 'unit walking' packet
  956. *------------------------------------------*/
  957. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  958. {
  959. struct map_session_data* sd;
  960. struct status_change* sc = status_get_sc(bl);
  961. struct view_data* vd = status_get_viewdata(bl);
  962. unsigned char* buf = WBUFP(buffer,0);
  963. #if PACKETVER >= 7
  964. unsigned short offset = 0;
  965. #endif
  966. #if PACKETVER >= 20091103
  967. const char *name;
  968. #endif
  969. sd = BL_CAST(BL_PC, bl);
  970. #if PACKETVER < 4
  971. WBUFW(buf, 0) = 0x7b;
  972. #elif PACKETVER < 7
  973. WBUFW(buf, 0) = 0x1da;
  974. #elif PACKETVER < 20080102
  975. WBUFW(buf, 0) = 0x22c;
  976. #elif PACKETVER < 20091103
  977. WBUFW(buf, 0) = 0x2ec;
  978. #elif PACKETVER < 20101124
  979. WBUFW(buf, 0) = 0x7f7;
  980. #else
  981. WBUFW(buf, 0) = 0x856;
  982. #endif
  983. #if PACKETVER >= 20091103
  984. name = status_get_name(bl);
  985. #if PACKETVER < 20110111
  986. WBUFW(buf, 2) = 69+strlen(name);
  987. #else
  988. WBUFW(buf, 2) = 71+strlen(name);
  989. #endif
  990. offset+=2;
  991. buf = WBUFP(buffer,offset);
  992. #endif
  993. #if PACKETVER >= 20071106
  994. WBUFB(buf, 2) = clif_bl_type(bl);
  995. offset++;
  996. buf = WBUFP(buffer,offset);
  997. #endif
  998. WBUFL(buf, 2) = bl->id;
  999. WBUFW(buf, 6) = status_get_speed(bl);
  1000. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1001. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1002. #if PACKETVER < 7
  1003. WBUFW(buf,12) = (sc)? sc->option : 0;
  1004. #else
  1005. WBUFL(buf,12) = (sc)? sc->option : 0;
  1006. offset+=2; //Shift the rest of elements by 2 bytes.
  1007. buf = WBUFP(buffer,offset);
  1008. #endif
  1009. WBUFW(buf,14) = vd->class_;
  1010. WBUFW(buf,16) = vd->hair_style;
  1011. WBUFW(buf,18) = vd->weapon;
  1012. #if PACKETVER < 4
  1013. WBUFW(buf,20) = vd->head_bottom;
  1014. WBUFL(buf,22) = gettick();
  1015. WBUFW(buf,26) = vd->shield;
  1016. #else
  1017. WBUFW(buf,20) = vd->shield;
  1018. WBUFW(buf,22) = vd->head_bottom;
  1019. WBUFL(buf,24) = gettick();
  1020. #endif
  1021. WBUFW(buf,28) = vd->head_top;
  1022. WBUFW(buf,30) = vd->head_mid;
  1023. WBUFW(buf,32) = vd->hair_color;
  1024. WBUFW(buf,34) = vd->cloth_color;
  1025. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1026. #if PACKETVER >= 20110111
  1027. WBUFW(buf,38) = vd->robe;
  1028. offset+= 2;
  1029. buf = WBUFP(buffer,offset);
  1030. #endif
  1031. WBUFL(buf,38) = status_get_guild_id(bl);
  1032. WBUFW(buf,42) = status_get_emblem_id(bl);
  1033. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1034. #if PACKETVER < 7
  1035. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1036. #else
  1037. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1038. offset+=2; //Shift the rest of elements by 2 bytes.
  1039. buf = WBUFP(buffer,offset);
  1040. #endif
  1041. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1042. WBUFB(buf,49) = vd->sex;
  1043. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1044. WBUFB(buf,56) = (sd)? 5 : 0;
  1045. WBUFB(buf,57) = (sd)? 5 : 0;
  1046. WBUFW(buf,58) = clif_setlevel(bl);
  1047. #if PACKETVER >= 20080102
  1048. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1049. #endif
  1050. #if PACKETVER >= 20091103
  1051. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1052. return WBUFW(buffer,2);
  1053. #else
  1054. return packet_len(WBUFW(buffer,0));
  1055. #endif
  1056. }
  1057. //Modifies the buffer for disguise characters and sends it to self.
  1058. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1059. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1060. {
  1061. #if PACKETVER >= 20091103
  1062. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1063. WBUFL(buf,5)=-bl->id;
  1064. #elif PACKETVER >= 20071106
  1065. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1066. WBUFL(buf,3)=-bl->id;
  1067. #else
  1068. WBUFL(buf,2)=-bl->id;
  1069. #endif
  1070. clif_send(buf, len, bl, SELF);
  1071. }
  1072. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1073. /// 01b0 <id>.L <type>.B <value>.L
  1074. /// type:
  1075. /// unused
  1076. void clif_class_change(struct block_list *bl,int class_,int type)
  1077. {
  1078. nullpo_retv(bl);
  1079. if(!pcdb_checkid(class_))
  1080. {// player classes yield missing sprites
  1081. unsigned char buf[16];
  1082. WBUFW(buf,0)=0x1b0;
  1083. WBUFL(buf,2)=bl->id;
  1084. WBUFB(buf,6)=type;
  1085. WBUFL(buf,7)=class_;
  1086. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1087. }
  1088. }
  1089. /// Notifies the client of an object's spirits.
  1090. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1091. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1092. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1093. {
  1094. WFIFOHEAD(fd, packet_len(0x1e1));
  1095. WFIFOW(fd,0)=0x1e1;
  1096. WFIFOL(fd,2)=sd->bl.id;
  1097. WFIFOW(fd,6)=sd->spiritball;
  1098. WFIFOSET(fd, packet_len(0x1e1));
  1099. }
  1100. /*==========================================
  1101. * Kagerou/Oboro amulet spirit
  1102. *------------------------------------------*/
  1103. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1104. {
  1105. WFIFOHEAD(fd, packet_len(0x08cf));
  1106. WFIFOW(fd,0)=0x08cf;
  1107. WFIFOL(fd,2)=sd->bl.id;
  1108. WFIFOW(fd,6)=type;
  1109. WFIFOW(fd,8)=sd->talisman[type];
  1110. WFIFOSET(fd, packet_len(0x08cf));
  1111. }
  1112. /*==========================================
  1113. * Run when player changes map / refreshes
  1114. * Tells its client to display all weather settings being used by this map
  1115. *------------------------------------------*/
  1116. static void clif_weather_check(struct map_session_data *sd)
  1117. {
  1118. int16 m = sd->bl.m;
  1119. int fd = sd->fd;
  1120. if (map[m].flag.snow
  1121. || map[m].flag.clouds
  1122. || map[m].flag.fog
  1123. || map[m].flag.fireworks
  1124. || map[m].flag.sakura
  1125. || map[m].flag.leaves
  1126. || map[m].flag.clouds2)
  1127. {
  1128. if (map[m].flag.snow)
  1129. clif_specialeffect_single(&sd->bl, 162, fd);
  1130. if (map[m].flag.clouds)
  1131. clif_specialeffect_single(&sd->bl, 233, fd);
  1132. if (map[m].flag.clouds2)
  1133. clif_specialeffect_single(&sd->bl, 516, fd);
  1134. if (map[m].flag.fog)
  1135. clif_specialeffect_single(&sd->bl, 515, fd);
  1136. if (map[m].flag.fireworks) {
  1137. clif_specialeffect_single(&sd->bl, 297, fd);
  1138. clif_specialeffect_single(&sd->bl, 299, fd);
  1139. clif_specialeffect_single(&sd->bl, 301, fd);
  1140. }
  1141. if (map[m].flag.sakura)
  1142. clif_specialeffect_single(&sd->bl, 163, fd);
  1143. if (map[m].flag.leaves)
  1144. clif_specialeffect_single(&sd->bl, 333, fd);
  1145. }
  1146. }
  1147. /**
  1148. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1149. **/
  1150. void clif_weather(int16 m)
  1151. {
  1152. struct s_mapiterator* iter;
  1153. struct map_session_data *sd=NULL;
  1154. iter = mapit_getallusers();
  1155. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1156. {
  1157. if( sd->bl.m == m )
  1158. clif_weather_check(sd);
  1159. }
  1160. mapit_free(iter);
  1161. }
  1162. /**
  1163. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1164. **/
  1165. int clif_spawn(struct block_list *bl)
  1166. {
  1167. unsigned char buf[128];
  1168. struct view_data *vd;
  1169. struct status_change *sc = status_get_sc(bl);
  1170. int len;
  1171. vd = status_get_viewdata(bl);
  1172. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1173. return 0;
  1174. /**
  1175. * Hide NPC from maya purple card.
  1176. **/
  1177. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1178. return 0;
  1179. len = clif_set_unit_idle(bl, buf,true);
  1180. clif_send(buf, len, bl, AREA_WOS);
  1181. if (disguised(bl))
  1182. clif_setdisguise(bl, buf, len);
  1183. if (vd->cloth_color)
  1184. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1185. switch (bl->type)
  1186. {
  1187. case BL_PC:
  1188. {
  1189. TBL_PC *sd = ((TBL_PC*)bl);
  1190. int i;
  1191. if (sd->spiritball > 0)
  1192. clif_spiritball(&sd->bl);
  1193. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1194. clif_specialeffect(bl,423,AREA);
  1195. else if(sd->state.size==SZ_MEDIUM)
  1196. clif_specialeffect(bl,421,AREA);
  1197. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1198. clif_sendbgemblem_area(sd);
  1199. for(i = 1; i < 5; i++){
  1200. if( sd->talisman[i] > 0 )
  1201. clif_talisman(sd, i);
  1202. }
  1203. for (i = 0; i < sd->sc_display_count; i++) {
  1204. if (sc && (sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK)))
  1205. clif_status_change2(&sd->bl,sd->bl.id,AREA,SI_BLANK,0,0,0);
  1206. else
  1207. clif_status_change2(&sd->bl,sd->bl.id,AREA,StatusIconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3);
  1208. }
  1209. if (sd->status.robe)
  1210. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1211. }
  1212. break;
  1213. case BL_MOB:
  1214. {
  1215. TBL_MOB *md = ((TBL_MOB*)bl);
  1216. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1217. clif_specialeffect(&md->bl,423,AREA);
  1218. else if(md->special_state.size==SZ_MEDIUM)
  1219. clif_specialeffect(&md->bl,421,AREA);
  1220. }
  1221. break;
  1222. case BL_NPC:
  1223. {
  1224. TBL_NPC *nd = ((TBL_NPC*)bl);
  1225. if( nd->size == SZ_BIG )
  1226. clif_specialeffect(&nd->bl,423,AREA);
  1227. else if( nd->size == SZ_MEDIUM )
  1228. clif_specialeffect(&nd->bl,421,AREA);
  1229. }
  1230. break;
  1231. case BL_PET:
  1232. if (vd->head_bottom)
  1233. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1234. break;
  1235. }
  1236. return 0;
  1237. }
  1238. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1239. /// 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
  1240. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1241. {
  1242. struct status_data *status;
  1243. unsigned char buf[128];
  1244. int htype;
  1245. nullpo_retv(hd);
  1246. status = &hd->battle_status;
  1247. htype = hom_class2type(hd->homunculus.class_);
  1248. memset(buf,0,packet_len(0x22e));
  1249. WBUFW(buf,0)=0x22e;
  1250. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1251. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1252. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1253. WBUFW(buf,27)=hd->homunculus.level;
  1254. WBUFW(buf,29)=hd->homunculus.hunger;
  1255. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1256. WBUFW(buf,33)=0; // equip id
  1257. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1258. WBUFW(buf,37)=min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1259. WBUFW(buf,39)=status->hit;
  1260. if (battle_config.hom_setting&0x10)
  1261. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1262. else
  1263. WBUFW(buf,41)=status->cri/10;
  1264. WBUFW(buf,43)=status->def + status->vit ;
  1265. WBUFW(buf,45)=status->mdef;
  1266. WBUFW(buf,47)=status->flee;
  1267. WBUFW(buf,49)=(flag)?0:status->amotion;
  1268. if (status->max_hp > INT16_MAX) {
  1269. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1270. WBUFW(buf,53) = 100;
  1271. } else {
  1272. WBUFW(buf,51)=status->hp;
  1273. WBUFW(buf,53)=status->max_hp;
  1274. }
  1275. if (status->max_sp > INT16_MAX) {
  1276. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1277. WBUFW(buf,57) = 100;
  1278. } else {
  1279. WBUFW(buf,55)=status->sp;
  1280. WBUFW(buf,57)=status->max_sp;
  1281. }
  1282. WBUFL(buf,59)=hd->homunculus.exp;
  1283. WBUFL(buf,63)=hd->exp_next;
  1284. switch( htype ) {
  1285. case HT_REG:
  1286. case HT_EVO:
  1287. if( hd->homunculus.level >= battle_config.hom_max_level )
  1288. WBUFL(buf,63)=0;
  1289. break;
  1290. case HT_S:
  1291. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1292. WBUFL(buf,63)=0;
  1293. break;
  1294. }
  1295. WBUFW(buf,67)=hd->homunculus.skillpts;
  1296. WBUFW(buf,69)=status_get_range(&hd->bl);
  1297. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1298. }
  1299. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1300. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1301. /// type:
  1302. /// unused
  1303. /// state:
  1304. /// 0 = pre-init
  1305. /// 1 = intimacy
  1306. /// 2 = hunger
  1307. /// 3 = accessory?
  1308. /// ? = ignored
  1309. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1310. { //[orn]
  1311. int fd = sd->fd;
  1312. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1313. hom_calc_skilltree(sd->hd, 0);
  1314. WFIFOHEAD(fd, packet_len(0x230));
  1315. WFIFOW(fd,0)=0x230;
  1316. WFIFOB(fd,2)=0;
  1317. WFIFOB(fd,3)=state;
  1318. WFIFOL(fd,4)=sd->hd->bl.id;
  1319. WFIFOL(fd,8)=param;
  1320. WFIFOSET(fd,packet_len(0x230));
  1321. }
  1322. int clif_homskillinfoblock(struct map_session_data *sd)
  1323. { //[orn]
  1324. struct homun_data *hd;
  1325. int fd = sd->fd;
  1326. int i,j,len=4;
  1327. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1328. hd = sd->hd;
  1329. if ( !hd )
  1330. return 0 ;
  1331. WFIFOW(fd,0)=0x235;
  1332. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1333. int id = hd->homunculus.hskill[i].id;
  1334. if( id != 0 ){
  1335. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1336. j = id - HM_SKILLBASE;
  1337. WFIFOW(fd,len ) = id;
  1338. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1339. WFIFOW(fd,len+4) = 0;
  1340. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1341. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1342. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1343. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1344. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < hom_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1345. len+=37;
  1346. }
  1347. }
  1348. WFIFOW(fd,2)=len;
  1349. WFIFOSET(fd,len);
  1350. return 0;
  1351. }
  1352. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1353. { //[orn]
  1354. struct homun_data *hd;
  1355. int fd, idx;
  1356. nullpo_retv(sd);
  1357. idx = skill_id - HM_SKILLBASE;
  1358. fd=sd->fd;
  1359. hd=sd->hd;
  1360. WFIFOHEAD(fd, packet_len(0x239));
  1361. WFIFOW(fd,0) = 0x239;
  1362. WFIFOW(fd,2) = skill_id;
  1363. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1364. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1365. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1366. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1367. WFIFOSET(fd,packet_len(0x239));
  1368. }
  1369. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1370. {
  1371. int fd=sd->fd;
  1372. WFIFOHEAD(fd,packet_len(0x22f));
  1373. WFIFOW(fd,0)=0x22f;
  1374. WFIFOB(fd,2)=fail;
  1375. WFIFOW(fd,3)=foodid;
  1376. WFIFOSET(fd,packet_len(0x22f));
  1377. return 0;
  1378. }
  1379. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1380. /// 0087 <walk start time>.L <walk data>.6B
  1381. void clif_walkok(struct map_session_data *sd)
  1382. {
  1383. int fd=sd->fd;
  1384. WFIFOHEAD(fd, packet_len(0x87));
  1385. WFIFOW(fd,0)=0x87;
  1386. WFIFOL(fd,2)=gettick();
  1387. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1388. WFIFOSET(fd,packet_len(0x87));
  1389. }
  1390. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1391. {
  1392. uint8 buf[128];
  1393. int len;
  1394. struct status_change *sc = NULL;
  1395. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1396. clif_ally_only = true;
  1397. len = clif_set_unit_walking(bl,ud,buf);
  1398. clif_send(buf,len,bl,AREA_WOS);
  1399. if (disguised(bl))
  1400. clif_setdisguise(bl, buf, len);
  1401. if(vd->cloth_color)
  1402. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1403. switch(bl->type) {
  1404. case BL_PC:
  1405. {
  1406. TBL_PC *sd = ((TBL_PC*)bl);
  1407. // clif_movepc(sd);
  1408. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1409. clif_specialeffect(&sd->bl,423,AREA);
  1410. else if(sd->state.size==SZ_MEDIUM)
  1411. clif_specialeffect(&sd->bl,421,AREA);
  1412. }
  1413. break;
  1414. case BL_MOB:
  1415. {
  1416. TBL_MOB *md = ((TBL_MOB*)bl);
  1417. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1418. clif_specialeffect(&md->bl,423,AREA);
  1419. else if(md->special_state.size==SZ_MEDIUM)
  1420. clif_specialeffect(&md->bl,421,AREA);
  1421. }
  1422. break;
  1423. case BL_PET:
  1424. if(vd->head_bottom) // needed to display pet equip properly
  1425. clif_pet_equip_area((TBL_PET*)bl);
  1426. break;
  1427. }
  1428. clif_ally_only = false;
  1429. }
  1430. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1431. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1432. /// Note: unit must not be self
  1433. void clif_move(struct unit_data *ud)
  1434. {
  1435. unsigned char buf[16];
  1436. struct view_data* vd;
  1437. struct block_list* bl = ud->bl;
  1438. struct status_change *sc = NULL;
  1439. vd = status_get_viewdata(bl);
  1440. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1441. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1442. /**
  1443. * Hide NPC from maya purple card.
  1444. **/
  1445. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1446. return;
  1447. if (ud->state.speed_changed) {
  1448. // Since we don't know how to update the speed of other objects,
  1449. // use the old walk packet to update the data.
  1450. ud->state.speed_changed = 0;
  1451. clif_move2(bl, vd, ud);
  1452. return;
  1453. }
  1454. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1455. clif_ally_only = true;
  1456. WBUFW(buf,0)=0x86;
  1457. WBUFL(buf,2)=bl->id;
  1458. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1459. WBUFL(buf,12)=gettick();
  1460. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1461. if (disguised(bl)) {
  1462. WBUFL(buf,2)=-bl->id;
  1463. clif_send(buf, packet_len(0x86), bl, SELF);
  1464. }
  1465. clif_ally_only = false;
  1466. }
  1467. /*==========================================
  1468. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1469. *------------------------------------------*/
  1470. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1471. {
  1472. struct map_session_data *sd = NULL;
  1473. //Remove player from map server
  1474. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1475. map_quit(sd);
  1476. return 0;
  1477. }
  1478. /*==========================================
  1479. *
  1480. *------------------------------------------*/
  1481. void clif_quitsave(int fd,struct map_session_data *sd) {
  1482. if (!battle_config.prevent_logout ||
  1483. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1484. map_quit(sd);
  1485. else if (sd->fd) {
  1486. //Disassociate session from player (session is deleted after this function was called)
  1487. //And set a timer to make him quit later.
  1488. session[sd->fd]->session_data = NULL;
  1489. sd->fd = 0;
  1490. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1491. }
  1492. }
  1493. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1494. /// 0091 <map name>.16B <x>.W <y>.W
  1495. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1496. {
  1497. int fd;
  1498. nullpo_retv(sd);
  1499. fd = sd->fd;
  1500. WFIFOHEAD(fd,packet_len(0x91));
  1501. WFIFOW(fd,0) = 0x91;
  1502. mapindex_getmapname_ext(map_mapid2mapname(m), (char*)WFIFOP(fd,2));
  1503. WFIFOW(fd,18) = x;
  1504. WFIFOW(fd,20) = y;
  1505. WFIFOSET(fd,packet_len(0x91));
  1506. }
  1507. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1508. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1509. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1510. {
  1511. int fd;
  1512. nullpo_retv(sd);
  1513. fd = sd->fd;
  1514. WFIFOHEAD(fd,packet_len(0x92));
  1515. WFIFOW(fd,0) = 0x92;
  1516. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1517. WFIFOW(fd,18) = x;
  1518. WFIFOW(fd,20) = y;
  1519. WFIFOL(fd,22) = htonl(ip);
  1520. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1521. WFIFOSET(fd,packet_len(0x92));
  1522. }
  1523. void clif_blown(struct block_list *bl)
  1524. {
  1525. clif_slide(bl, bl->x, bl->y);
  1526. //clif_fixpos(bl); //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1527. }
  1528. /// Visually moves(slides) a character to x,y. If the target cell
  1529. /// isn't walkable, the char doesn't move at all. If the char is
  1530. /// sitting it will stand up (ZC_STOPMOVE).
  1531. /// 0088 <id>.L <x>.W <y>.W
  1532. void clif_fixpos(struct block_list *bl)
  1533. {
  1534. unsigned char buf[10];
  1535. nullpo_retv(bl);
  1536. WBUFW(buf,0) = 0x88;
  1537. WBUFL(buf,2) = bl->id;
  1538. WBUFW(buf,6) = bl->x;
  1539. WBUFW(buf,8) = bl->y;
  1540. clif_send(buf, packet_len(0x88), bl, AREA);
  1541. if( disguised(bl) ) {
  1542. WBUFL(buf,2) = -bl->id;
  1543. clif_send(buf, packet_len(0x88), bl, SELF);
  1544. }
  1545. }
  1546. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1547. /// 00c4 <shop id>.L
  1548. void clif_npcbuysell(struct map_session_data* sd, int id)
  1549. {
  1550. int fd;
  1551. nullpo_retv(sd);
  1552. fd=sd->fd;
  1553. WFIFOHEAD(fd, packet_len(0xc4));
  1554. WFIFOW(fd,0)=0xc4;
  1555. WFIFOL(fd,2)=id;
  1556. WFIFOSET(fd,packet_len(0xc4));
  1557. }
  1558. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1559. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1560. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1561. {
  1562. int fd,i,c;
  1563. bool discount;
  1564. nullpo_retv(sd);
  1565. nullpo_retv(nd);
  1566. fd = sd->fd;
  1567. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1568. WFIFOW(fd,0) = 0xc6;
  1569. c = 0;
  1570. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1571. for( i = 0; i < nd->u.shop.count; i++ )
  1572. {
  1573. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1574. int val = nd->u.shop.shop_item[i].value;
  1575. if( id == NULL )
  1576. continue;
  1577. WFIFOL(fd, 4+c*11) = val;
  1578. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1579. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1580. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1581. c++;
  1582. }
  1583. WFIFOW(fd,2) = 4 + c*11;
  1584. WFIFOSET(fd,WFIFOW(fd,2));
  1585. }
  1586. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1587. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1588. void clif_selllist(struct map_session_data *sd)
  1589. {
  1590. int fd,i,c=0,val;
  1591. nullpo_retv(sd);
  1592. fd=sd->fd;
  1593. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1594. WFIFOW(fd,0)=0xc7;
  1595. for( i = 0; i < MAX_INVENTORY; i++ )
  1596. {
  1597. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1598. {
  1599. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1600. continue;
  1601. if( sd->status.inventory[i].expire_time || (sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd)) )
  1602. continue; // Cannot Sell Rental Items or Account Bounded Items
  1603. if( sd->status.inventory[i].bound && !pc_can_give_bounded_items(sd))
  1604. continue; // Don't allow sale of bound items
  1605. val=sd->inventory_data[i]->value_sell;
  1606. if( val < 0 )
  1607. continue;
  1608. WFIFOW(fd,4+c*10)=i+2;
  1609. WFIFOL(fd,6+c*10)=val;
  1610. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1611. c++;
  1612. }
  1613. }
  1614. WFIFOW(fd,2)=c*10+4;
  1615. WFIFOSET(fd,WFIFOW(fd,2));
  1616. }
  1617. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1618. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1619. /// Client behavior (dialog window):
  1620. /// - disable mouse targeting
  1621. /// - open the dialog window
  1622. /// - set npcid of dialog window (0 by default)
  1623. /// - if set to clear on next mes, clear contents
  1624. /// - append this text
  1625. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1626. {
  1627. int fd = sd->fd;
  1628. int slen = strlen(mes) + 9;
  1629. WFIFOHEAD(fd, slen);
  1630. WFIFOW(fd,0)=0xb4;
  1631. WFIFOW(fd,2)=slen;
  1632. WFIFOL(fd,4)=npcid;
  1633. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1634. WFIFOSET(fd,WFIFOW(fd,2));
  1635. }
  1636. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1637. /// 00b5 <npc id>.L
  1638. /// Client behavior (dialog window):
  1639. /// - disable mouse targeting
  1640. /// - open the dialog window
  1641. /// - add 'next' button
  1642. /// When 'next' is pressed:
  1643. /// - 00B9 <npcid of dialog window>.L
  1644. /// - set to clear on next mes
  1645. /// - remove 'next' button
  1646. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1647. {
  1648. int fd;
  1649. nullpo_retv(sd);
  1650. fd=sd->fd;
  1651. WFIFOHEAD(fd, packet_len(0xb5));
  1652. WFIFOW(fd,0)=0xb5;
  1653. WFIFOL(fd,2)=npcid;
  1654. WFIFOSET(fd,packet_len(0xb5));
  1655. }
  1656. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1657. /// 00b6 <npc id>.L
  1658. /// Client behavior:
  1659. /// - if dialog window is open:
  1660. /// - remove 'next' button
  1661. /// - add 'close' button
  1662. /// - else:
  1663. /// - enable mouse targeting
  1664. /// - close the dialog window
  1665. /// - close the menu window
  1666. /// When 'close' is pressed:
  1667. /// - enable mouse targeting
  1668. /// - close the dialog window
  1669. /// - close the menu window
  1670. /// - 0146 <npcid of dialog window>.L
  1671. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1672. {
  1673. int fd;
  1674. nullpo_retv(sd);
  1675. fd=sd->fd;
  1676. WFIFOHEAD(fd, packet_len(0xb6));
  1677. WFIFOW(fd,0)=0xb6;
  1678. WFIFOL(fd,2)=npcid;
  1679. WFIFOSET(fd,packet_len(0xb6));
  1680. }
  1681. /**
  1682. * Close script when player is idle
  1683. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1684. * @author [Ind/Hercules]
  1685. * @param sd : player pointer
  1686. * @param npcid : npc gid to close
  1687. */
  1688. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1689. {
  1690. struct s_packet_db* info;
  1691. int16 len;
  1692. int cmd = 0;
  1693. int fd;
  1694. nullpo_retv(sd);
  1695. cmd = packet_db_ack[sd->packet_ver][ZC_CLEAR_DIALOG];
  1696. if(!cmd) cmd = 0x8d6; //default
  1697. info = &packet_db[sd->packet_ver][cmd];
  1698. len = info->len;
  1699. fd = sd->fd;
  1700. WFIFOHEAD(fd, len);
  1701. WFIFOW(fd,0)=0x8d6;
  1702. WFIFOL(fd,info->pos[0])=npcid;
  1703. WFIFOSET(fd,len);
  1704. }
  1705. /*==========================================
  1706. *
  1707. *------------------------------------------*/
  1708. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1709. unsigned char *buf;
  1710. int fd = sd->fd;
  1711. sd->state.using_fake_npc = 1;
  1712. WFIFOHEAD(fd, packet_len(0x78));
  1713. buf = WFIFOP(fd,0);
  1714. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1715. WBUFW(buf,0)=0x78;
  1716. #if PACKETVER >= 20071106
  1717. WBUFB(buf,2) = 0; // object type
  1718. buf = WFIFOP(fd,1);
  1719. #endif
  1720. WBUFL(buf,2)=npcid;
  1721. WBUFW(buf,14)=111;
  1722. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1723. WBUFB(buf,49)=5;
  1724. WBUFB(buf,50)=5;
  1725. WFIFOSET(fd, packet_len(0x78));
  1726. }
  1727. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1728. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1729. /// Client behavior:
  1730. /// - disable mouse targeting
  1731. /// - close the menu window
  1732. /// - open the menu window
  1733. /// - add options to the menu (separated in the text by ":")
  1734. /// - set npcid of menu window
  1735. /// - if dialog window is open:
  1736. /// - remove 'next' button
  1737. /// When 'ok' is pressed:
  1738. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1739. /// - close the menu window
  1740. /// When 'cancel' is pressed:
  1741. /// - 00B8 <npcid of menu window>.L <-1>.B
  1742. /// - enable mouse targeting
  1743. /// - close a bunch of windows...
  1744. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1745. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1746. /// TODO investigate behavior of other windows [FlavioJS]
  1747. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1748. {
  1749. int fd = sd->fd;
  1750. int slen = strlen(mes) + 9;
  1751. struct block_list *bl = NULL;
  1752. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1753. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1754. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1755. clif_sendfakenpc(sd, npcid);
  1756. WFIFOHEAD(fd, slen);
  1757. WFIFOW(fd,0)=0xb7;
  1758. WFIFOW(fd,2)=slen;
  1759. WFIFOL(fd,4)=npcid;
  1760. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1761. WFIFOSET(fd,WFIFOW(fd,2));
  1762. }
  1763. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1764. /// 0142 <npc id>.L
  1765. /// Client behavior (inputnum window):
  1766. /// - if npcid exists in the client:
  1767. /// - open the inputnum window
  1768. /// - set npcid of inputnum window
  1769. /// When 'ok' is pressed:
  1770. /// - if inputnum window has text:
  1771. /// - if npcid exists in the client:
  1772. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1773. /// - close inputnum window
  1774. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1775. {
  1776. int fd;
  1777. struct block_list *bl = NULL;
  1778. nullpo_retv(sd);
  1779. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1780. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1781. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1782. clif_sendfakenpc(sd, npcid);
  1783. fd=sd->fd;
  1784. WFIFOHEAD(fd, packet_len(0x142));
  1785. WFIFOW(fd,0)=0x142;
  1786. WFIFOL(fd,2)=npcid;
  1787. WFIFOSET(fd,packet_len(0x142));
  1788. }
  1789. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1790. /// 01d4 <npc id>.L
  1791. /// Client behavior (inputstr window):
  1792. /// - if npcid is 0 or npcid exists in the client:
  1793. /// - open the inputstr window
  1794. /// - set npcid of inputstr window
  1795. /// When 'ok' is pressed:
  1796. /// - if inputstr window has text and isn't an insult(manner.txt):
  1797. /// - if npcid is 0 or npcid exists in the client:
  1798. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1799. /// - close inputstr window
  1800. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1801. {
  1802. int fd;
  1803. struct block_list *bl = NULL;
  1804. nullpo_retv(sd);
  1805. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1806. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1807. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1808. clif_sendfakenpc(sd, npcid);
  1809. fd=sd->fd;
  1810. WFIFOHEAD(fd, packet_len(0x1d4));
  1811. WFIFOW(fd,0)=0x1d4;
  1812. WFIFOL(fd,2)=npcid;
  1813. WFIFOSET(fd,packet_len(0x1d4));
  1814. }
  1815. /// Marks a position on client's minimap (ZC_COMPASS).
  1816. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1817. /// npc id:
  1818. /// is ignored in the client
  1819. /// type:
  1820. /// 0 = display mark for 15 seconds
  1821. /// 1 = display mark until dead or teleported
  1822. /// 2 = remove mark
  1823. /// color:
  1824. /// 0x00RRGGBB
  1825. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1826. {
  1827. int fd;
  1828. nullpo_retv(sd);
  1829. fd=sd->fd;
  1830. WFIFOHEAD(fd, packet_len(0x144));
  1831. WFIFOW(fd,0)=0x144;
  1832. WFIFOL(fd,2)=npc_id;
  1833. WFIFOL(fd,6)=type;
  1834. WFIFOL(fd,10)=x;
  1835. WFIFOL(fd,14)=y;
  1836. WFIFOB(fd,18)=id;
  1837. WFIFOL(fd,19)=color;
  1838. WFIFOSET(fd,packet_len(0x144));
  1839. }
  1840. /// Displays an illustration image.
  1841. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1842. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1843. /// type:
  1844. /// 0 = bottom left corner
  1845. /// 1 = bottom middle
  1846. /// 2 = bottom right corner
  1847. /// 3 = middle of screen, inside a movable window
  1848. /// 4 = middle of screen, movable with a close button, chrome-less
  1849. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1850. {
  1851. int fd;
  1852. nullpo_retv(sd);
  1853. fd=sd->fd;
  1854. WFIFOHEAD(fd, packet_len(0x1b3));
  1855. WFIFOW(fd,0)=0x1b3;
  1856. strncpy((char*)WFIFOP(fd,2),image,64);
  1857. WFIFOB(fd,66)=type;
  1858. WFIFOSET(fd,packet_len(0x1b3));
  1859. }
  1860. /*==========================================
  1861. * Fills in card data from the given item and into the buffer. [Skotlex]
  1862. *------------------------------------------*/
  1863. static void clif_addcards(unsigned char* buf, struct item* item)
  1864. {
  1865. int i=0,j;
  1866. if( item == NULL ) { //Blank data
  1867. WBUFW(buf,0) = 0;
  1868. WBUFW(buf,2) = 0;
  1869. WBUFW(buf,4) = 0;
  1870. WBUFW(buf,6) = 0;
  1871. return;
  1872. }
  1873. if( item->card[0] == CARD0_PET ) { //pet eggs
  1874. WBUFW(buf,0) = 0;
  1875. WBUFW(buf,2) = 0;
  1876. WBUFW(buf,4) = 0;
  1877. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1878. return;
  1879. }
  1880. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1881. WBUFW(buf,0) = item->card[0];
  1882. WBUFW(buf,2) = item->card[1];
  1883. WBUFW(buf,4) = item->card[2];
  1884. WBUFW(buf,6) = item->card[3];
  1885. return;
  1886. }
  1887. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1888. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1889. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1890. //Normal items.
  1891. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1892. WBUFW(buf,0) = j;
  1893. else
  1894. WBUFW(buf,0) = item->card[i];
  1895. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1896. WBUFW(buf,2) = j;
  1897. else
  1898. WBUFW(buf,2) = item->card[i];
  1899. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1900. WBUFW(buf,4) = j;
  1901. else
  1902. WBUFW(buf,4) = item->card[i];
  1903. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1904. WBUFW(buf,6) = j;
  1905. else
  1906. WBUFW(buf,6) = item->card[i];
  1907. }
  1908. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1909. /// 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)
  1910. /// 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)
  1911. /// 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)
  1912. /// 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)
  1913. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  1914. {
  1915. int fd, header, offs=0;
  1916. #if PACKETVER < 20061218
  1917. header = 0xa0;
  1918. #elif PACKETVER < 20071002
  1919. header = 0x29a;
  1920. #elif PACKETVER < 20120925
  1921. header = 0x2d4;
  1922. #else
  1923. header = 0x990;
  1924. #endif
  1925. nullpo_retv(sd);
  1926. fd = sd->fd;
  1927. if( !session_isActive(fd) ) //Sasuke-
  1928. return;
  1929. WFIFOHEAD(fd,packet_len(header));
  1930. if( fail )
  1931. {
  1932. WFIFOW(fd,offs+0)=header;
  1933. WFIFOW(fd,offs+2)=n+2;
  1934. WFIFOW(fd,offs+4)=amount;
  1935. WFIFOW(fd,offs+6)=0;
  1936. WFIFOB(fd,offs+8)=0;
  1937. WFIFOB(fd,offs+9)=0;
  1938. WFIFOB(fd,offs+10)=0;
  1939. WFIFOW(fd,offs+11)=0;
  1940. WFIFOW(fd,offs+13)=0;
  1941. WFIFOW(fd,offs+15)=0;
  1942. WFIFOW(fd,offs+17)=0;
  1943. #if PACKETVER < 20120925
  1944. WFIFOW(fd,offs+19)=0;
  1945. #else
  1946. WFIFOL(fd,offs+19)=0;
  1947. offs += 2;
  1948. #endif
  1949. WFIFOB(fd,offs+21)=0;
  1950. WFIFOB(fd,offs+22)=fail;
  1951. #if PACKETVER >= 20061218
  1952. WFIFOL(fd,offs+23)=0;
  1953. #endif
  1954. #if PACKETVER >= 20071002
  1955. WFIFOW(fd,offs+27)=0; // HireExpireDate
  1956. #endif
  1957. }
  1958. else
  1959. {
  1960. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1961. return;
  1962. WFIFOW(fd,offs+0)=header;
  1963. WFIFOW(fd,offs+2)=n+2;
  1964. WFIFOW(fd,offs+4)=amount;
  1965. if (sd->inventory_data[n]->view_id > 0)
  1966. WFIFOW(fd,offs+6)=sd->inventory_data[n]->view_id;
  1967. else
  1968. WFIFOW(fd,offs+6)=sd->status.inventory[n].nameid;
  1969. WFIFOB(fd,offs+8)=sd->status.inventory[n].identify;
  1970. WFIFOB(fd,offs+9)=sd->status.inventory[n].attribute;
  1971. WFIFOB(fd,offs+10)=sd->status.inventory[n].refine;
  1972. clif_addcards(WFIFOP(fd,offs+11), &sd->status.inventory[n]);
  1973. #if PACKETVER < 20120925
  1974. WFIFOW(fd,offs+19)=pc_equippoint(sd,n);
  1975. #else
  1976. WFIFOL(fd,offs+19)=pc_equippoint(sd,n);
  1977. offs += 2;
  1978. #endif
  1979. WFIFOB(fd,offs+21)=itemtype(sd->inventory_data[n]->nameid);
  1980. WFIFOB(fd,offs+22)=fail;
  1981. #if PACKETVER >= 20061218
  1982. WFIFOL(fd,offs+23)=sd->status.inventory[n].expire_time;
  1983. #endif
  1984. #if PACKETVER >= 20071002
  1985. WFIFOW(fd,offs+27)=sd->status.inventory[n].bound ? BOUND_GUILD : 0;
  1986. #endif
  1987. }
  1988. WFIFOSET(fd,packet_len(header));
  1989. }
  1990. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1991. /// 00af <index>.W <amount>.W
  1992. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1993. {
  1994. int fd;
  1995. nullpo_retv(sd);
  1996. fd=sd->fd;
  1997. WFIFOHEAD(fd, packet_len(0xaf));
  1998. WFIFOW(fd,0)=0xaf;
  1999. WFIFOW(fd,2)=n+2;
  2000. WFIFOW(fd,4)=amount;
  2001. WFIFOSET(fd,packet_len(0xaf));
  2002. }
  2003. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2004. /// 07fa <delete type>.W <index>.W <amount>.W
  2005. /// delete type:
  2006. /// 0 = Normal
  2007. /// 1 = Item used for a skill
  2008. /// 2 = Refine failed
  2009. /// 3 = Material changed
  2010. /// 4 = Moved to storage
  2011. /// 5 = Moved to cart
  2012. /// 6 = Item sold
  2013. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2014. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2015. {
  2016. #if PACKETVER < 20091117
  2017. clif_dropitem(sd,n,amount);
  2018. #else
  2019. int fd;
  2020. nullpo_retv(sd);
  2021. fd=sd->fd;
  2022. WFIFOHEAD(fd, packet_len(0x7fa));
  2023. WFIFOW(fd,0)=0x7fa;
  2024. WFIFOW(fd,2)=reason;
  2025. WFIFOW(fd,4)=n+2;
  2026. WFIFOW(fd,6)=amount;
  2027. WFIFOSET(fd,packet_len(0x7fa));
  2028. #endif
  2029. }
  2030. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2031. char normal = (equip < 0);
  2032. WBUFW(buf,n)=idx; //index
  2033. WBUFW(buf,n+2)= (id->view_id > 0)?id->view_id:i->nameid;
  2034. WBUFB(buf,n+4)=itemtype(id->nameid);
  2035. if(!normal){ //equip 31B
  2036. WBUFL(buf,n+5)= equip; //location
  2037. WBUFL(buf,n+9)= i->equip; //wear state
  2038. WBUFB(buf,n+13)= i->refine; //refine lvl
  2039. clif_addcards(WBUFP(buf, n+14), i); //EQUIPSLOTINFO 8B
  2040. WBUFL(buf,n+22) = i->expire_time;
  2041. WBUFW(buf,n+26)= 0; //bindOnEquipType
  2042. WBUFW(buf,n+28)= (id->equip&EQP_VISIBLE)?id->look:0;
  2043. //V5_ITEM_flag
  2044. WBUFB(buf,n+30)=i->identify; //0x1 IsIdentified
  2045. WBUFB(buf,n+30)|=(i->attribute)?0x2:0; //0x2 IsDamaged
  2046. WBUFB(buf,n+30)|= (i->favorite)?0x4:0; //0x4 PlaceETCTab
  2047. }
  2048. else { //normal 24B
  2049. WBUFW(buf,n+5)=i->amount;
  2050. WBUFL(buf,n+7)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2051. clif_addcards(WBUFP(buf, n+11), i); //EQUIPSLOTINFO 8B
  2052. WBUFL(buf,n+19) = i->expire_time;
  2053. //V5_ITEM_flag
  2054. WBUFB(buf,n+23)=i->identify; //0x1 IsIdentified
  2055. WBUFB(buf,n+23)|= (i->favorite)?0x2:0; //0x4,0x2 PlaceETCTab
  2056. }
  2057. }
  2058. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2059. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2060. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2061. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *i, struct item_data *id, int equip) {
  2062. #if PACKETVER >= 20120925
  2063. clif_item_sub_v5(buf, n, idx, i, id, equip);
  2064. #else
  2065. WBUFW(buf,n)=idx; //index
  2066. WBUFW(buf,n+2)=(id->view_id > 0)?id->view_id:i->nameid; //itid
  2067. WBUFB(buf,n+4)=itemtype(id->nameid);
  2068. WBUFB(buf,n+5)=i->identify;
  2069. if (equip >= 0) { //Equippable item 28.B
  2070. WBUFW(buf,n+6)=equip;
  2071. WBUFW(buf,n+8)=i->equip;
  2072. WBUFB(buf,n+10)=i->attribute;
  2073. WBUFB(buf,n+11)=i->refine;
  2074. clif_addcards(WBUFP(buf, n+12), i); //8B
  2075. #if PACKETVER >= 20071002
  2076. WBUFL(buf,n+20)=i->expire_time;
  2077. WBUFW(buf,n+24)=i->bound ? BOUND_GUILD : 0;
  2078. #endif
  2079. #if PACKETVER >= 20100629
  2080. WBUFW(buf,n+26)= (id->equip&EQP_VISIBLE)?id->look:0;
  2081. #endif
  2082. } else { //Stackable item. 22.B
  2083. WBUFW(buf,n+6)=i->amount;
  2084. WBUFW(buf,n+8)=(equip == -2 && id->equip == EQP_AMMO)?id->equip:0;
  2085. clif_addcards(WBUFP(buf, n+10), i); //8B
  2086. #if PACKETVER >= 20071002
  2087. WBUFL(buf,n+18)=i->expire_time;
  2088. #endif
  2089. }
  2090. #endif
  2091. }
  2092. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2093. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2094. void clif_inventorylist(struct map_session_data *sd) {
  2095. int i,n,ne,arrow=-1;
  2096. unsigned char *buf;
  2097. unsigned char *bufe;
  2098. #if PACKETVER < 5
  2099. const int s = 10; //Entry size
  2100. #elif PACKETVER < 20080102
  2101. const int s = 18;
  2102. #elif PACKETVER < 20120925
  2103. const int s = 22;
  2104. #else
  2105. const int s = 24;
  2106. #endif
  2107. #if PACKETVER < 20071002
  2108. const int se = 20;
  2109. #elif PACKETVER < 20100629
  2110. const int se = 26;
  2111. #elif PACKETVER < 20120925
  2112. const int se = 28;
  2113. #else
  2114. const int se = 31;
  2115. #endif
  2116. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2117. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2118. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2119. {
  2120. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2121. continue;
  2122. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2123. { //Non-stackable (Equippable)
  2124. clif_item_sub(bufe, ne*se+4, i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2125. ne++;
  2126. }
  2127. else { //Stackable.
  2128. clif_item_sub(buf, n*s+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2129. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2130. arrow=i;
  2131. n++;
  2132. }
  2133. }
  2134. if( n )
  2135. {
  2136. #if PACKETVER < 5
  2137. WBUFW(buf,0)=0xa3;
  2138. #elif PACKETVER < 20080102
  2139. WBUFW(buf,0)=0x1ee;
  2140. #elif PACKETVER < 20120925
  2141. WBUFW(buf,0)=0x2e8;
  2142. #else
  2143. WBUFW(buf,0)=0x991;
  2144. #endif
  2145. WBUFW(buf,2)=4+n*s;
  2146. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2147. }
  2148. if( arrow >= 0 )
  2149. clif_arrowequip(sd,arrow);
  2150. if( ne ) {
  2151. #if PACKETVER < 20071002
  2152. WBUFW(bufe,0)=0xa4;
  2153. #elif PACKETVER < 20120925
  2154. WBUFW(bufe,0)=0x2d0;
  2155. #else
  2156. WBUFW(bufe,0)=0x992;
  2157. #endif
  2158. WBUFW(bufe,2)=4+ne*se;
  2159. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2160. }
  2161. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2162. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2163. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2164. continue;
  2165. if ( sd->status.inventory[i].favorite )
  2166. clif_favorite_item(sd, i);
  2167. }
  2168. #endif
  2169. if( buf ) aFree(buf);
  2170. if( bufe ) aFree(bufe);
  2171. }
  2172. //Required when items break/get-repaired. Only sends equippable item list.
  2173. void clif_equiplist(struct map_session_data *sd)
  2174. {
  2175. int i,n,fd = sd->fd;
  2176. unsigned char *buf;
  2177. #if PACKETVER < 20071002
  2178. const int cmd = 20;
  2179. #elif PACKETVER < 20100629
  2180. const int cmd = 26;
  2181. #elif PACKETVER < 20120925
  2182. const int cmd = 28;
  2183. #else
  2184. const int cmd = 31;
  2185. #endif
  2186. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2187. buf = WFIFOP(fd,0);
  2188. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2189. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2190. continue;
  2191. if(itemdb_isstackable2(sd->inventory_data[i]))
  2192. continue;
  2193. //Equippable
  2194. clif_item_sub(buf, n*cmd+4,i+2, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2195. n++;
  2196. }
  2197. if (n) {
  2198. #if PACKETVER < 20071002
  2199. WBUFW(buf,0)=0xa4;
  2200. #elif PACKETVER < 20120925
  2201. WBUFW(buf,0)=0x2d0;
  2202. #else
  2203. WBUFW(buf,0)=0x992;
  2204. #endif
  2205. WBUFW(buf,2)=4+n*cmd;
  2206. WFIFOSET(fd,WFIFOW(fd,2));
  2207. }
  2208. }
  2209. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2210. {
  2211. static const int client_buf = 0x5000; // Max buffer to send
  2212. struct item_data *id;
  2213. int i,n,ne,nn;
  2214. unsigned char *buf;
  2215. unsigned char *bufe;
  2216. #if PACKETVER < 5
  2217. const int s = 10; //Entry size.normal item
  2218. const int sidx=4; //start itemlist idx
  2219. const int cmd = 0xa5;
  2220. #elif PACKETVER < 20080102
  2221. const int s = 18;
  2222. const int sidx=4;
  2223. const int cmd = 0x1f0;
  2224. #elif PACKETVER < 20120925
  2225. const int s = 22;
  2226. const int sidx=4;
  2227. const int cmd = 0x2ea;
  2228. #else
  2229. const int s = 24;
  2230. const int sidx = 4+24;
  2231. const int cmd = 0x995;
  2232. #endif
  2233. #if PACKETVER < 20071002
  2234. const int se = 20; //entry size equip
  2235. const int sidxe = 4; //start itemlist idx
  2236. const int cmde = 0xa6;
  2237. #elif PACKETVER < 20100629
  2238. const int se = 26;
  2239. const int sidxe = 4;
  2240. const int cmde = 0x2d1;
  2241. #elif PACKETVER < 20120925
  2242. const int se = 28;
  2243. const int sidxe = 4;
  2244. const int cmde = 0x2d1;
  2245. #else
  2246. const int se = 31;
  2247. const int sidxe = 4+24;
  2248. const int cmde = 0x996;
  2249. #endif
  2250. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2251. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2252. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2253. {
  2254. if( items[i].nameid <= 0 )
  2255. continue;
  2256. id = itemdb_search(items[i].nameid);
  2257. if( !itemdb_isstackable2(id) ) { //Equippable
  2258. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2259. ne++;
  2260. }
  2261. else { //Stackable
  2262. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2263. n++;
  2264. }
  2265. }
  2266. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2267. {
  2268. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2269. WFIFOHEAD(sd->fd,sidx+nn*s);
  2270. WFIFOW(sd->fd,0)=cmd;
  2271. WFIFOW(sd->fd,2)=sidx+nn*s;
  2272. #if PACKETVER >= 20120925
  2273. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2274. #endif
  2275. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2276. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2277. }
  2278. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2279. {
  2280. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2281. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2282. WFIFOW(sd->fd,0)=cmde;
  2283. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2284. #if PACKETVER >= 20120925
  2285. memset((char*)WFIFOP(sd->fd,4),0,24); //storename
  2286. #endif
  2287. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2288. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2289. }
  2290. if( buf ) aFree(buf);
  2291. if( bufe ) aFree(bufe);
  2292. }
  2293. void clif_cartlist(struct map_session_data *sd)
  2294. {
  2295. struct item_data *id;
  2296. int i,n,ne;
  2297. unsigned char *buf;
  2298. unsigned char *bufe;
  2299. #if PACKETVER < 5
  2300. const int s = 10; //Entry size.
  2301. #elif PACKETVER < 20080102
  2302. const int s = 18;
  2303. #elif PACKETVER < 20120925
  2304. const int s = 22;
  2305. #else
  2306. const int s = 24;
  2307. #endif
  2308. #if PACKETVER < 20071002
  2309. const int cmd = 20;
  2310. #elif PACKETVER < 20100629
  2311. const int cmd = 26;
  2312. #elif PACKETVER < 20120925
  2313. const int cmd = 28;
  2314. #else
  2315. const int cmd = 31;
  2316. #endif
  2317. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2318. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2319. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2320. {
  2321. if( sd->status.cart[i].nameid <= 0 )
  2322. continue;
  2323. id = itemdb_search(sd->status.cart[i].nameid);
  2324. if( !itemdb_isstackable2(id) ) { //Equippable
  2325. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->status.cart[i], id, id->equip);
  2326. ne++;
  2327. }
  2328. else { //Stackable
  2329. clif_item_sub(buf, n*s+4,i+2, &sd->status.cart[i], id,-1);
  2330. n++;
  2331. }
  2332. }
  2333. if( n )
  2334. {
  2335. #if PACKETVER < 5
  2336. WBUFW(buf,0)=0x123;
  2337. #elif PACKETVER < 20080102
  2338. WBUFW(buf,0)=0x1ef;
  2339. #elif PACKETVER < 20120925
  2340. WBUFW(buf,0)=0x2e9;
  2341. #else
  2342. WBUFW(buf,0)=0x993;
  2343. #endif
  2344. WBUFW(buf,2)=4+n*s;
  2345. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2346. }
  2347. if( ne )
  2348. {
  2349. #if PACKETVER < 20071002
  2350. WBUFW(bufe,0)=0x122;
  2351. #elif PACKETVER < 20120925
  2352. WBUFW(bufe,0)=0x2d2;
  2353. #else
  2354. WBUFW(bufe,0)=0x994;
  2355. #endif
  2356. WBUFW(bufe,2)=4+ne*cmd;
  2357. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2358. }
  2359. if( buf ) aFree(buf);
  2360. if( bufe ) aFree(bufe);
  2361. }
  2362. /// Removes cart (ZC_CARTOFF).
  2363. /// 012b
  2364. /// Client behaviour:
  2365. /// Closes the cart storage and removes all it's items from memory.
  2366. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2367. void clif_clearcart(int fd)
  2368. {
  2369. WFIFOHEAD(fd, packet_len(0x12b));
  2370. WFIFOW(fd,0) = 0x12b;
  2371. WFIFOSET(fd, packet_len(0x12b));
  2372. }
  2373. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2374. /// 01eb <account id>.L <x>.W <y>.W
  2375. void clif_guild_xy(struct map_session_data *sd)
  2376. {
  2377. unsigned char buf[10];
  2378. nullpo_retv(sd);
  2379. WBUFW(buf,0)=0x1eb;
  2380. WBUFL(buf,2)=sd->status.account_id;
  2381. WBUFW(buf,6)=sd->bl.x;
  2382. WBUFW(buf,8)=sd->bl.y;
  2383. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2384. }
  2385. /*==========================================
  2386. * Sends x/y dot to a single fd. [Skotlex]
  2387. *------------------------------------------*/
  2388. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2389. {
  2390. if( sd->bg_id )
  2391. return;
  2392. WFIFOHEAD(fd,packet_len(0x1eb));
  2393. WFIFOW(fd,0)=0x1eb;
  2394. WFIFOL(fd,2)=sd->status.account_id;
  2395. WFIFOW(fd,6)=sd->bl.x;
  2396. WFIFOW(fd,8)=sd->bl.y;
  2397. WFIFOSET(fd,packet_len(0x1eb));
  2398. }
  2399. // Guild XY locators [Valaris]
  2400. void clif_guild_xy_remove(struct map_session_data *sd)
  2401. {
  2402. unsigned char buf[10];
  2403. nullpo_retv(sd);
  2404. WBUFW(buf,0)=0x1eb;
  2405. WBUFL(buf,2)=sd->status.account_id;
  2406. WBUFW(buf,6)=-1;
  2407. WBUFW(buf,8)=-1;
  2408. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2409. }
  2410. /*==========================================
  2411. *
  2412. *------------------------------------------*/
  2413. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2414. {
  2415. struct map_session_data *sd, *tsd;
  2416. #if PACKETVER < 20100126
  2417. const int cmd = 0x106;
  2418. #else
  2419. const int cmd = 0x80e;
  2420. #endif
  2421. sd = va_arg(ap, struct map_session_data *);
  2422. tsd = (TBL_PC *)bl;
  2423. nullpo_ret(sd);
  2424. nullpo_ret(tsd);
  2425. if( !tsd->fd || tsd == sd )
  2426. return 0;
  2427. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2428. return 0;
  2429. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2430. WFIFOW(tsd->fd,0) = cmd;
  2431. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2432. #if PACKETVER < 20100126
  2433. if( sd->battle_status.max_hp > INT16_MAX )
  2434. { //To correctly display the %hp bar. [Skotlex]
  2435. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2436. WFIFOW(tsd->fd,8) = 100;
  2437. } else {
  2438. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2439. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2440. }
  2441. #else
  2442. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2443. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2444. #endif
  2445. WFIFOSET(tsd->fd,packet_len(cmd));
  2446. return 0;
  2447. }
  2448. /*==========================================
  2449. * Server tells all players that are allowed to view HP bars
  2450. * and are nearby 'sd' that 'sd' hp bar was updated.
  2451. *------------------------------------------*/
  2452. static int clif_hpmeter(struct map_session_data *sd)
  2453. {
  2454. nullpo_ret(sd);
  2455. 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);
  2456. return 0;
  2457. }
  2458. /// Notifies client of a character parameter change.
  2459. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2460. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2461. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2462. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2463. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2464. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2465. /// TODO: Extract individual packets.
  2466. /// FIXME: Packet lengths from packet_len(cmd)
  2467. void clif_updatestatus(struct map_session_data *sd,int type)
  2468. {
  2469. int fd,len=8;
  2470. nullpo_retv(sd);
  2471. fd=sd->fd;
  2472. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2473. return;
  2474. WFIFOHEAD(fd, 14);
  2475. WFIFOW(fd,0)=0xb0;
  2476. WFIFOW(fd,2)=type;
  2477. switch(type){
  2478. // 00b0
  2479. case SP_WEIGHT:
  2480. pc_updateweightstatus(sd);
  2481. WFIFOHEAD(fd,14);
  2482. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2483. WFIFOW(fd,2)=type;
  2484. WFIFOL(fd,4)=sd->weight;
  2485. break;
  2486. case SP_MAXWEIGHT:
  2487. WFIFOL(fd,4)=sd->max_weight;
  2488. break;
  2489. case SP_SPEED:
  2490. WFIFOL(fd,4)=sd->battle_status.speed;
  2491. break;
  2492. case SP_BASELEVEL:
  2493. WFIFOL(fd,4)=sd->status.base_level;
  2494. break;
  2495. case SP_JOBLEVEL:
  2496. WFIFOL(fd,4)=sd->status.job_level;
  2497. break;
  2498. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2499. WFIFOL(fd,4)=sd->status.karma;
  2500. break;
  2501. case SP_MANNER:
  2502. WFIFOL(fd,4)=sd->status.manner;
  2503. break;
  2504. case SP_STATUSPOINT:
  2505. WFIFOL(fd,4)=sd->status.status_point;
  2506. break;
  2507. case SP_SKILLPOINT:
  2508. WFIFOL(fd,4)=sd->status.skill_point;
  2509. break;
  2510. case SP_HIT:
  2511. WFIFOL(fd,4)=sd->battle_status.hit;
  2512. break;
  2513. case SP_FLEE1:
  2514. WFIFOL(fd,4)=sd->battle_status.flee;
  2515. break;
  2516. case SP_FLEE2:
  2517. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2518. break;
  2519. case SP_MAXHP:
  2520. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2521. break;
  2522. case SP_MAXSP:
  2523. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2524. break;
  2525. case SP_HP:
  2526. WFIFOL(fd,4)=sd->battle_status.hp;
  2527. // TODO: Won't these overwrite the current packet?
  2528. if( map[sd->bl.m].hpmeter_visible )
  2529. clif_hpmeter(sd);
  2530. if( !battle_config.party_hp_mode && sd->status.party_id )
  2531. clif_party_hp(sd);
  2532. if( sd->bg_id )
  2533. clif_bg_hp(sd);
  2534. break;
  2535. case SP_SP:
  2536. WFIFOL(fd,4)=sd->battle_status.sp;
  2537. break;
  2538. case SP_ASPD:
  2539. WFIFOL(fd,4)=sd->battle_status.amotion;
  2540. break;
  2541. case SP_ATK1:
  2542. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2543. break;
  2544. case SP_DEF1:
  2545. WFIFOL(fd,4)=pc_leftside_def(sd);
  2546. break;
  2547. case SP_MDEF1:
  2548. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2549. break;
  2550. case SP_ATK2:
  2551. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2552. break;
  2553. case SP_DEF2:
  2554. WFIFOL(fd,4)=pc_rightside_def(sd);
  2555. break;
  2556. case SP_MDEF2: {
  2557. //negative check (in case you have something like Berserk active)
  2558. int mdef2 = pc_rightside_mdef(sd);
  2559. WFIFOL(fd,4)=
  2560. #ifndef RENEWAL
  2561. ( mdef2 < 0 ) ? 0 :
  2562. #endif
  2563. mdef2;
  2564. }
  2565. break;
  2566. case SP_CRITICAL:
  2567. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2568. break;
  2569. case SP_MATK1:
  2570. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2571. break;
  2572. case SP_MATK2:
  2573. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2574. break;
  2575. case SP_ZENY:
  2576. WFIFOW(fd,0)=0xb1;
  2577. WFIFOL(fd,4)=sd->status.zeny;
  2578. break;
  2579. case SP_BASEEXP:
  2580. WFIFOW(fd,0)=0xb1;
  2581. WFIFOL(fd,4)=sd->status.base_exp;
  2582. break;
  2583. case SP_JOBEXP:
  2584. WFIFOW(fd,0)=0xb1;
  2585. WFIFOL(fd,4)=sd->status.job_exp;
  2586. break;
  2587. case SP_NEXTBASEEXP:
  2588. WFIFOW(fd,0)=0xb1;
  2589. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2590. break;
  2591. case SP_NEXTJOBEXP:
  2592. WFIFOW(fd,0)=0xb1;
  2593. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2594. break;
  2595. /**
  2596. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2597. **/
  2598. case SP_USTR:
  2599. case SP_UAGI:
  2600. case SP_UVIT:
  2601. case SP_UINT:
  2602. case SP_UDEX:
  2603. case SP_ULUK:
  2604. WFIFOW(fd,0)=0xbe;
  2605. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2606. len=5;
  2607. break;
  2608. /**
  2609. * Tells the client how far it is allowed to attack (weapon range)
  2610. **/
  2611. case SP_ATTACKRANGE:
  2612. WFIFOW(fd,0)=0x13a;
  2613. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2614. len=4;
  2615. break;
  2616. case SP_STR:
  2617. WFIFOW(fd,0)=0x141;
  2618. WFIFOL(fd,2)=type;
  2619. WFIFOL(fd,6)=sd->status.str;
  2620. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2621. len=14;
  2622. break;
  2623. case SP_AGI:
  2624. WFIFOW(fd,0)=0x141;
  2625. WFIFOL(fd,2)=type;
  2626. WFIFOL(fd,6)=sd->status.agi;
  2627. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2628. len=14;
  2629. break;
  2630. case SP_VIT:
  2631. WFIFOW(fd,0)=0x141;
  2632. WFIFOL(fd,2)=type;
  2633. WFIFOL(fd,6)=sd->status.vit;
  2634. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2635. len=14;
  2636. break;
  2637. case SP_INT:
  2638. WFIFOW(fd,0)=0x141;
  2639. WFIFOL(fd,2)=type;
  2640. WFIFOL(fd,6)=sd->status.int_;
  2641. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2642. len=14;
  2643. break;
  2644. case SP_DEX:
  2645. WFIFOW(fd,0)=0x141;
  2646. WFIFOL(fd,2)=type;
  2647. WFIFOL(fd,6)=sd->status.dex;
  2648. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2649. len=14;
  2650. break;
  2651. case SP_LUK:
  2652. WFIFOW(fd,0)=0x141;
  2653. WFIFOL(fd,2)=type;
  2654. WFIFOL(fd,6)=sd->status.luk;
  2655. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2656. len=14;
  2657. break;
  2658. case SP_CARTINFO:
  2659. WFIFOW(fd,0)=0x121;
  2660. WFIFOW(fd,2)=sd->cart_num;
  2661. WFIFOW(fd,4)=MAX_CART;
  2662. WFIFOL(fd,6)=sd->cart_weight;
  2663. WFIFOL(fd,10)=sd->cart_weight_max;
  2664. len=14;
  2665. break;
  2666. default:
  2667. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2668. return;
  2669. }
  2670. WFIFOSET(fd,len);
  2671. }
  2672. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2673. /// 01ab <account id>.L <var id>.W <value>.L
  2674. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2675. {
  2676. unsigned char buf[12];
  2677. nullpo_retv(sd);
  2678. WBUFW(buf,0)=0x1ab;
  2679. WBUFL(buf,2)=sd->bl.id;
  2680. WBUFW(buf,6)=type;
  2681. switch(type)
  2682. {
  2683. case SP_MANNER:
  2684. WBUFL(buf,8)=val;
  2685. break;
  2686. default:
  2687. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2688. return;
  2689. }
  2690. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2691. }
  2692. /// Updates sprite/style properties of an object.
  2693. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2694. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2695. void clif_changelook(struct block_list *bl,int type,int val)
  2696. {
  2697. unsigned char buf[16];
  2698. struct map_session_data* sd;
  2699. struct status_change* sc;
  2700. struct view_data* vd;
  2701. enum send_target target = AREA;
  2702. nullpo_retv(bl);
  2703. sd = BL_CAST(BL_PC, bl);
  2704. sc = status_get_sc(bl);
  2705. vd = status_get_viewdata(bl);
  2706. //nullpo_ret(vd);
  2707. if( vd ) //temp hack to let Warp Portal change appearance
  2708. switch(type)
  2709. {
  2710. case LOOK_WEAPON:
  2711. if (sd)
  2712. {
  2713. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2714. val = vd->weapon;
  2715. }
  2716. else vd->weapon = val;
  2717. break;
  2718. case LOOK_SHIELD:
  2719. if (sd)
  2720. {
  2721. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2722. val = vd->shield;
  2723. }
  2724. else vd->shield = val;
  2725. break;
  2726. case LOOK_BASE:
  2727. if (!sd) break;
  2728. if (sd->sc.option&OPTION_COSTUME)
  2729. vd->weapon = vd->shield = 0;
  2730. if (!vd->cloth_color)
  2731. break;
  2732. if (sd) {
  2733. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2734. vd->cloth_color = 0;
  2735. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2736. vd->cloth_color = 0;
  2737. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2738. vd->cloth_color = 0;
  2739. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2740. vd->cloth_color = 0;
  2741. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2742. vd->cloth_color = 0;
  2743. }
  2744. break;
  2745. case LOOK_HAIR:
  2746. vd->hair_style = val;
  2747. break;
  2748. case LOOK_HEAD_BOTTOM:
  2749. vd->head_bottom = val;
  2750. break;
  2751. case LOOK_HEAD_TOP:
  2752. vd->head_top = val;
  2753. break;
  2754. case LOOK_HEAD_MID:
  2755. vd->head_mid = val;
  2756. break;
  2757. case LOOK_HAIR_COLOR:
  2758. vd->hair_color = val;
  2759. break;
  2760. case LOOK_CLOTHES_COLOR:
  2761. if (val && sd) {
  2762. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2763. val = 0;
  2764. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2765. val = 0;
  2766. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2767. val = 0;
  2768. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2769. val = 0;
  2770. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  2771. val = 0;
  2772. }
  2773. vd->cloth_color = val;
  2774. break;
  2775. case LOOK_SHOES:
  2776. #if PACKETVER > 3
  2777. if (sd) {
  2778. int n;
  2779. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2780. if(sd->inventory_data[n]->view_id > 0)
  2781. val = sd->inventory_data[n]->view_id;
  2782. else
  2783. val = sd->status.inventory[n].nameid;
  2784. } else
  2785. val = 0;
  2786. }
  2787. #endif
  2788. //Shoes? No packet uses this....
  2789. break;
  2790. case LOOK_BODY:
  2791. // unknown purpose
  2792. break;
  2793. case LOOK_ROBE:
  2794. #if PACKETVER < 20110111
  2795. return;
  2796. #else
  2797. vd->robe = val;
  2798. #endif
  2799. break;
  2800. }
  2801. // prevent leaking the presence of GM-hidden objects
  2802. if( sc && sc->option&OPTION_INVISIBLE )
  2803. target = SELF;
  2804. #if PACKETVER < 4
  2805. WBUFW(buf,0)=0xc3;
  2806. WBUFL(buf,2)=bl->id;
  2807. WBUFB(buf,6)=type;
  2808. WBUFB(buf,7)=val;
  2809. clif_send(buf,packet_len(0xc3),bl,target);
  2810. #else
  2811. WBUFW(buf,0)=0x1d7;
  2812. WBUFL(buf,2)=bl->id;
  2813. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2814. WBUFB(buf,6)=LOOK_WEAPON;
  2815. WBUFW(buf,7)=vd->weapon;
  2816. WBUFW(buf,9)=vd->shield;
  2817. } else {
  2818. WBUFB(buf,6)=type;
  2819. WBUFL(buf,7)=val;
  2820. }
  2821. clif_send(buf,packet_len(0x1d7),bl,target);
  2822. #endif
  2823. }
  2824. //Sends a change-base-look packet required for traps as they are triggered.
  2825. void clif_changetraplook(struct block_list *bl,int val)
  2826. {
  2827. unsigned char buf[32];
  2828. #if PACKETVER < 4
  2829. WBUFW(buf,0)=0xc3;
  2830. WBUFL(buf,2)=bl->id;
  2831. WBUFB(buf,6)=LOOK_BASE;
  2832. WBUFB(buf,7)=val;
  2833. clif_send(buf,packet_len(0xc3),bl,AREA);
  2834. #else
  2835. WBUFW(buf,0)=0x1d7;
  2836. WBUFL(buf,2)=bl->id;
  2837. WBUFB(buf,6)=LOOK_BASE;
  2838. WBUFW(buf,7)=val;
  2839. WBUFW(buf,9)=0;
  2840. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2841. #endif
  2842. }
  2843. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2844. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2845. {
  2846. unsigned char buf[32];
  2847. #if PACKETVER < 4
  2848. WBUFW(buf,0)=0xc3;
  2849. WBUFL(buf,2)=id;
  2850. WBUFB(buf,6)=type;
  2851. WBUFB(buf,7)=val;
  2852. clif_send(buf,packet_len(0xc3),bl,target);
  2853. #else
  2854. WBUFW(buf,0)=0x1d7;
  2855. WBUFL(buf,2)=id;
  2856. WBUFB(buf,6)=type;
  2857. WBUFW(buf,7)=val;
  2858. WBUFW(buf,9)=0;
  2859. clif_send(buf,packet_len(0x1d7),bl,target);
  2860. #endif
  2861. }
  2862. /// Character status (ZC_STATUS).
  2863. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2864. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2865. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2866. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2867. void clif_initialstatus(struct map_session_data *sd) {
  2868. int fd, mdef2;
  2869. unsigned char *buf;
  2870. nullpo_retv(sd);
  2871. fd=sd->fd;
  2872. WFIFOHEAD(fd,packet_len(0xbd));
  2873. buf=WFIFOP(fd,0);
  2874. WBUFW(buf,0)=0xbd;
  2875. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2876. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2877. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2878. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2879. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2880. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2881. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2882. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2883. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2884. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2885. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2886. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2887. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2888. WBUFW(buf,16) = pc_leftside_atk(sd);
  2889. WBUFW(buf,18) = pc_rightside_atk(sd);
  2890. WBUFW(buf,20) = pc_rightside_matk(sd);
  2891. WBUFW(buf,22) = pc_leftside_matk(sd);
  2892. WBUFW(buf,24) = pc_leftside_def(sd);
  2893. WBUFW(buf,26) = pc_rightside_def(sd);
  2894. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2895. mdef2 = pc_rightside_mdef(sd);
  2896. WBUFW(buf,30) =
  2897. #ifndef RENEWAL
  2898. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2899. #endif
  2900. mdef2;
  2901. WBUFW(buf,32) = sd->battle_status.hit;
  2902. WBUFW(buf,34) = sd->battle_status.flee;
  2903. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2904. WBUFW(buf,38) = sd->battle_status.cri/10;
  2905. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2906. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2907. WFIFOSET(fd,packet_len(0xbd));
  2908. clif_updatestatus(sd,SP_STR);
  2909. clif_updatestatus(sd,SP_AGI);
  2910. clif_updatestatus(sd,SP_VIT);
  2911. clif_updatestatus(sd,SP_INT);
  2912. clif_updatestatus(sd,SP_DEX);
  2913. clif_updatestatus(sd,SP_LUK);
  2914. clif_updatestatus(sd,SP_ATTACKRANGE);
  2915. clif_updatestatus(sd,SP_ASPD);
  2916. }
  2917. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2918. /// 013c <index>.W
  2919. void clif_arrowequip(struct map_session_data *sd,int val)
  2920. {
  2921. int fd;
  2922. nullpo_retv(sd);
  2923. pc_stop_attack(sd); // [Valaris]
  2924. #if PACKETVER >= 20121128
  2925. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2926. #endif
  2927. fd=sd->fd;
  2928. WFIFOHEAD(fd, packet_len(0x013c));
  2929. WFIFOW(fd,0)=0x013c;
  2930. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2931. WFIFOSET(fd,packet_len(0x013c));
  2932. }
  2933. /// Ammunition action message (ZC_ACTION_FAILURE).
  2934. /// 013b <type>.W
  2935. /// type:
  2936. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2937. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2938. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2939. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2940. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2941. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2942. void clif_arrow_fail(struct map_session_data *sd,int type)
  2943. {
  2944. int fd;
  2945. nullpo_retv(sd);
  2946. fd=sd->fd;
  2947. WFIFOHEAD(fd, packet_len(0x013b));
  2948. WFIFOW(fd,0)=0x013b;
  2949. WFIFOW(fd,2)=type;
  2950. WFIFOSET(fd,packet_len(0x013b));
  2951. }
  2952. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2953. /// 01ad <packet len>.W { <name id>.W }*
  2954. void clif_arrow_create_list(struct map_session_data *sd)
  2955. {
  2956. int i, c, j;
  2957. int fd;
  2958. nullpo_retv(sd);
  2959. fd = sd->fd;
  2960. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2961. WFIFOW(fd,0) = 0x1ad;
  2962. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2963. if (skill_arrow_db[i].nameid > 0 &&
  2964. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2965. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2966. {
  2967. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2968. WFIFOW(fd,c*2+4) = j;
  2969. else
  2970. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2971. c++;
  2972. }
  2973. }
  2974. WFIFOW(fd,2) = c*2+4;
  2975. WFIFOSET(fd, WFIFOW(fd,2));
  2976. if (c > 0) {
  2977. sd->menuskill_id = AC_MAKINGARROW;
  2978. sd->menuskill_val = c;
  2979. }
  2980. }
  2981. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2982. /// 00bc <status id>.W <result>.B <value>.B
  2983. /// status id:
  2984. /// SP_STR ~ SP_LUK
  2985. /// result:
  2986. /// 0 = failure
  2987. /// 1 = success
  2988. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2989. {
  2990. int fd;
  2991. nullpo_retv(sd);
  2992. fd=sd->fd;
  2993. WFIFOHEAD(fd,packet_len(0xbc));
  2994. WFIFOW(fd,0)=0xbc;
  2995. WFIFOW(fd,2)=type;
  2996. WFIFOB(fd,4)=ok;
  2997. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2998. WFIFOSET(fd,packet_len(0xbc));
  2999. }
  3000. /// Notifies the client about the result of a request to equip an item.
  3001. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3002. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3003. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3004. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3005. /// @ok: //inversed forv2 v5
  3006. /// 0 = failure
  3007. /// 1 = success
  3008. /// 2 = failure due to low level
  3009. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3010. {
  3011. int fd,header,offs=0,success;
  3012. #if PACKETVER < 20110824
  3013. header = 0xaa;
  3014. success = (ok==1);
  3015. #elif PACKETVER < 20120925
  3016. header = 0x8d0;
  3017. success = ok ? 0:1;
  3018. #else
  3019. header = 0x999;
  3020. success = ok ? 0:1;
  3021. #endif
  3022. nullpo_retv(sd);
  3023. fd=sd->fd;
  3024. WFIFOHEAD(fd,packet_len(header));
  3025. WFIFOW(fd,offs+0)=header;
  3026. WFIFOW(fd,offs+2)=n+2;
  3027. #if PACKETVER >= 20120925
  3028. WFIFOL(fd,offs+4)=pos;
  3029. offs+=2;
  3030. #else
  3031. WFIFOW(fd,offs+4)=(int)pos;
  3032. #endif
  3033. #if PACKETVER < 20100629
  3034. WFIFOB(fd,offs+6)=success;
  3035. #else
  3036. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3037. WFIFOW(fd,offs+6)=sd->inventory_data[n]->look;
  3038. else
  3039. WFIFOW(fd,offs+6)=0;
  3040. WFIFOB(fd,offs+8)=success;
  3041. #endif
  3042. WFIFOSET(fd,packet_len(header));
  3043. }
  3044. /// Notifies the client about the result of a request to take off an item.
  3045. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3046. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3047. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3048. /// @ok : //inversed for v2 v5
  3049. /// 0 = failure
  3050. /// 1 = success
  3051. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3052. {
  3053. int fd,header,offs=0;
  3054. #if PACKETVER >= 20130000
  3055. header = 0x99a;
  3056. ok = ok ? 0:1;
  3057. #elif PACKETVER >= 20110824
  3058. header = 0x8d1;
  3059. ok = ok ? 0:1;
  3060. #else
  3061. header = 0xac;
  3062. #endif
  3063. nullpo_retv(sd);
  3064. fd=sd->fd;
  3065. WFIFOHEAD(fd,packet_len(header));
  3066. WFIFOW(fd,offs+0)=header;
  3067. WFIFOW(fd,offs+2)=n+2;
  3068. #if PACKETVER >= 20130000
  3069. WFIFOL(fd,offs+4)=pos;
  3070. offs +=2;
  3071. #else
  3072. WFIFOW(fd,offs+4)=pos;
  3073. #endif
  3074. WFIFOB(fd,offs+6)=ok;
  3075. WFIFOSET(fd,packet_len(header));
  3076. }
  3077. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3078. /// 019b <id>.L <effect id>.L
  3079. /// effect id:
  3080. /// 0 = base level up
  3081. /// 1 = job level up
  3082. /// 2 = refine failure
  3083. /// 3 = refine success
  3084. /// 4 = game over
  3085. /// 5 = pharmacy success
  3086. /// 6 = pharmacy failure
  3087. /// 7 = base level up (super novice)
  3088. /// 8 = job level up (super novice)
  3089. /// 9 = base level up (taekwon)
  3090. void clif_misceffect(struct block_list* bl,int type)
  3091. {
  3092. unsigned char buf[32];
  3093. nullpo_retv(bl);
  3094. WBUFW(buf,0) = 0x19b;
  3095. WBUFL(buf,2) = bl->id;
  3096. WBUFL(buf,6) = type;
  3097. clif_send(buf,packet_len(0x19b),bl,AREA);
  3098. }
  3099. /// Notifies clients in the area of a state change.
  3100. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3101. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3102. void clif_changeoption(struct block_list* bl)
  3103. {
  3104. unsigned char buf[32];
  3105. struct status_change *sc;
  3106. struct map_session_data* sd;
  3107. nullpo_retv(bl);
  3108. sc = status_get_sc(bl);
  3109. if (!sc) return; //How can an option change if there's no sc?
  3110. sd = BL_CAST(BL_PC, bl);
  3111. #if PACKETVER >= 7
  3112. WBUFW(buf,0) = 0x229;
  3113. WBUFL(buf,2) = bl->id;
  3114. WBUFW(buf,6) = sc->opt1;
  3115. WBUFW(buf,8) = sc->opt2;
  3116. WBUFL(buf,10) = sc->option;
  3117. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3118. if(disguised(bl)) {
  3119. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3120. WBUFL(buf,2) = -bl->id;
  3121. clif_send(buf,packet_len(0x229),bl,SELF);
  3122. WBUFL(buf,2) = bl->id;
  3123. WBUFL(buf,10) = OPTION_INVISIBLE;
  3124. clif_send(buf,packet_len(0x229),bl,SELF);
  3125. } else
  3126. clif_send(buf,packet_len(0x229),bl,AREA);
  3127. #else
  3128. WBUFW(buf,0) = 0x119;
  3129. WBUFL(buf,2) = bl->id;
  3130. WBUFW(buf,6) = sc->opt1;
  3131. WBUFW(buf,8) = sc->opt2;
  3132. WBUFW(buf,10) = sc->option;
  3133. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3134. if(disguised(bl)) {
  3135. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3136. WBUFL(buf,2) = -bl->id;
  3137. clif_send(buf,packet_len(0x119),bl,SELF);
  3138. WBUFL(buf,2) = bl->id;
  3139. WBUFW(buf,10) = OPTION_INVISIBLE;
  3140. clif_send(buf,packet_len(0x119),bl,SELF);
  3141. } else
  3142. clif_send(buf,packet_len(0x119),bl,AREA);
  3143. #endif
  3144. }
  3145. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3146. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3147. void clif_changeoption2(struct block_list* bl)
  3148. {
  3149. unsigned char buf[20];
  3150. struct status_change *sc;
  3151. sc = status_get_sc(bl);
  3152. if (!sc) return; //How can an option change if there's no sc?
  3153. WBUFW(buf,0) = 0x28a;
  3154. WBUFL(buf,2) = bl->id;
  3155. WBUFL(buf,6) = sc->option;
  3156. WBUFL(buf,10) = clif_setlevel(bl);
  3157. WBUFL(buf,14) = sc->opt3;
  3158. if(disguised(bl)) {
  3159. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3160. WBUFL(buf,2) = -bl->id;
  3161. clif_send(buf,packet_len(0x28a),bl,SELF);
  3162. WBUFL(buf,2) = bl->id;
  3163. WBUFL(buf,6) = OPTION_INVISIBLE;
  3164. clif_send(buf,packet_len(0x28a),bl,SELF);
  3165. } else
  3166. clif_send(buf,packet_len(0x28a),bl,AREA);
  3167. }
  3168. /// Notifies the client about the result of an item use request.
  3169. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3170. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3171. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3172. {
  3173. nullpo_retv(sd);
  3174. if(!ok) {
  3175. int fd=sd->fd;
  3176. WFIFOHEAD(fd,packet_len(0xa8));
  3177. WFIFOW(fd,0)=0xa8;
  3178. WFIFOW(fd,2)=index+2;
  3179. WFIFOW(fd,4)=amount;
  3180. WFIFOB(fd,6)=ok;
  3181. WFIFOSET(fd,packet_len(0xa8));
  3182. }
  3183. else {
  3184. #if PACKETVER < 3
  3185. int fd=sd->fd;
  3186. WFIFOHEAD(fd,packet_len(0xa8));
  3187. WFIFOW(fd,0)=0xa8;
  3188. WFIFOW(fd,2)=index+2;
  3189. WFIFOW(fd,4)=amount;
  3190. WFIFOB(fd,6)=ok;
  3191. WFIFOSET(fd,packet_len(0xa8));
  3192. #else
  3193. unsigned char buf[32];
  3194. WBUFW(buf,0)=0x1c8;
  3195. WBUFW(buf,2)=index+2;
  3196. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3197. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3198. else
  3199. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3200. WBUFL(buf,6)=sd->bl.id;
  3201. WBUFW(buf,10)=amount;
  3202. WBUFB(buf,12)=ok;
  3203. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3204. #endif
  3205. }
  3206. }
  3207. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3208. /// 00d6 <flag>.B
  3209. /// flag:
  3210. /// 0 = Room has been successfully created (opens chat room)
  3211. /// 1 = Room limit exceeded
  3212. /// 2 = Same room already exists
  3213. void clif_createchat(struct map_session_data* sd, int flag)
  3214. {
  3215. int fd;
  3216. nullpo_retv(sd);
  3217. fd = sd->fd;
  3218. WFIFOHEAD(fd,packet_len(0xd6));
  3219. WFIFOW(fd,0) = 0xd6;
  3220. WFIFOB(fd,2) = flag;
  3221. WFIFOSET(fd,packet_len(0xd6));
  3222. }
  3223. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3224. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3225. /// type:
  3226. /// 0 = private (password protected)
  3227. /// 1 = public
  3228. /// 2 = arena (npc waiting room)
  3229. /// 3 = PK zone (non-clickable)
  3230. void clif_dispchat(struct chat_data* cd, int fd)
  3231. {
  3232. unsigned char buf[128];
  3233. uint8 type;
  3234. if( cd == NULL || cd->owner == NULL )
  3235. return;
  3236. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3237. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3238. : 1;
  3239. WBUFW(buf, 0) = 0xd7;
  3240. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3241. WBUFL(buf, 4) = cd->owner->id;
  3242. WBUFL(buf, 8) = cd->bl.id;
  3243. WBUFW(buf,12) = cd->limit;
  3244. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3245. WBUFB(buf,16) = type;
  3246. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3247. if( fd ) {
  3248. WFIFOHEAD(fd,WBUFW(buf,2));
  3249. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3250. WFIFOSET(fd,WBUFW(buf,2));
  3251. } else {
  3252. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3253. }
  3254. }
  3255. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3256. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3257. /// type:
  3258. /// 0 = private (password protected)
  3259. /// 1 = public
  3260. /// 2 = arena (npc waiting room)
  3261. /// 3 = PK zone (non-clickable)
  3262. void clif_changechatstatus(struct chat_data* cd)
  3263. {
  3264. unsigned char buf[128];
  3265. uint8 type;
  3266. if( cd == NULL || cd->usersd[0] == NULL )
  3267. return;
  3268. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3269. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3270. : 1;
  3271. WBUFW(buf, 0) = 0xdf;
  3272. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3273. WBUFL(buf, 4) = cd->owner->id;
  3274. WBUFL(buf, 8) = cd->bl.id;
  3275. WBUFW(buf,12) = cd->limit;
  3276. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3277. WBUFB(buf,16) = type;
  3278. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3279. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3280. }
  3281. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3282. /// 00d8 <chat id>.L
  3283. void clif_clearchat(struct chat_data *cd,int fd)
  3284. {
  3285. unsigned char buf[32];
  3286. nullpo_retv(cd);
  3287. WBUFW(buf,0) = 0xd8;
  3288. WBUFL(buf,2) = cd->bl.id;
  3289. if( fd ) {
  3290. WFIFOHEAD(fd,packet_len(0xd8));
  3291. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3292. WFIFOSET(fd,packet_len(0xd8));
  3293. } else {
  3294. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3295. }
  3296. }
  3297. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3298. /// 00da <result>.B
  3299. /// result:
  3300. /// 0 = room full
  3301. /// 1 = wrong password
  3302. /// 2 = kicked
  3303. /// 3 = success (no message)
  3304. /// 4 = no enough zeny
  3305. /// 5 = too low level
  3306. /// 6 = too high level
  3307. /// 7 = unsuitable job class
  3308. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3309. {
  3310. int fd;
  3311. nullpo_retv(sd);
  3312. fd = sd->fd;
  3313. WFIFOHEAD(fd,packet_len(0xda));
  3314. WFIFOW(fd,0) = 0xda;
  3315. WFIFOB(fd,2) = flag;
  3316. WFIFOSET(fd,packet_len(0xda));
  3317. }
  3318. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3319. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3320. /// role:
  3321. /// 0 = owner (menu)
  3322. /// 1 = normal
  3323. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3324. {
  3325. int fd;
  3326. int i,t;
  3327. nullpo_retv(sd);
  3328. nullpo_retv(cd);
  3329. fd = sd->fd;
  3330. if (!session_isActive(fd))
  3331. return;
  3332. t = (int)(cd->owner->type == BL_NPC);
  3333. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3334. WFIFOW(fd, 0) = 0xdb;
  3335. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3336. WFIFOL(fd, 4) = cd->bl.id;
  3337. if(cd->owner->type == BL_NPC){
  3338. WFIFOL(fd, 30) = 1;
  3339. WFIFOL(fd, 8) = 0;
  3340. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3341. for (i = 0; i < cd->users; i++) {
  3342. WFIFOL(fd, 8+(i+1)*28) = 1;
  3343. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3344. }
  3345. } else
  3346. for (i = 0; i < cd->users; i++) {
  3347. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3348. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3349. }
  3350. WFIFOSET(fd, WFIFOW(fd, 2));
  3351. }
  3352. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3353. /// 00dc <users>.W <name>.24B
  3354. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3355. {
  3356. unsigned char buf[29];
  3357. nullpo_retv(sd);
  3358. nullpo_retv(cd);
  3359. WBUFW(buf, 0) = 0xdc;
  3360. WBUFW(buf, 2) = cd->users;
  3361. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3362. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3363. }
  3364. /// Announce the new owner (ZC_ROLE_CHANGE).
  3365. /// 00e1 <role>.L <nick>.24B
  3366. /// role:
  3367. /// 0 = owner (menu)
  3368. /// 1 = normal
  3369. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3370. {
  3371. unsigned char buf[64];
  3372. nullpo_retv(sd);
  3373. nullpo_retv(cd);
  3374. WBUFW(buf, 0) = 0xe1;
  3375. WBUFL(buf, 2) = 1;
  3376. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3377. WBUFW(buf,30) = 0xe1;
  3378. WBUFL(buf,32) = 0;
  3379. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3380. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3381. }
  3382. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3383. /// 00dd <users>.W <nick>.24B <flag>.B
  3384. /// flag:
  3385. /// 0 = left
  3386. /// 1 = kicked
  3387. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3388. {
  3389. unsigned char buf[32];
  3390. nullpo_retv(sd);
  3391. nullpo_retv(cd);
  3392. WBUFW(buf, 0) = 0xdd;
  3393. WBUFW(buf, 2) = cd->users-1;
  3394. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3395. WBUFB(buf,28) = flag;
  3396. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3397. }
  3398. /// Opens a trade request window from char 'name'.
  3399. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3400. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3401. void clif_traderequest(struct map_session_data* sd, const char* name)
  3402. {
  3403. int fd = sd->fd;
  3404. #if PACKETVER < 6
  3405. WFIFOHEAD(fd,packet_len(0xe5));
  3406. WFIFOW(fd,0) = 0xe5;
  3407. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3408. WFIFOSET(fd,packet_len(0xe5));
  3409. #else
  3410. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3411. if( !tsd ) return;
  3412. WFIFOHEAD(fd,packet_len(0x1f4));
  3413. WFIFOW(fd,0) = 0x1f4;
  3414. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3415. WFIFOL(fd,26) = tsd->status.char_id;
  3416. WFIFOW(fd,30) = tsd->status.base_level;
  3417. WFIFOSET(fd,packet_len(0x1f4));
  3418. #endif
  3419. }
  3420. /// Reply to a trade-request.
  3421. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3422. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3423. /// result:
  3424. /// 0 = Char is too far
  3425. /// 1 = Character does not exist
  3426. /// 2 = Trade failed
  3427. /// 3 = Accept
  3428. /// 4 = Cancel
  3429. /// 5 = Busy
  3430. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3431. {
  3432. int fd = sd->fd;
  3433. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3434. if( PACKETVER < 6 || !tsd ) {
  3435. WFIFOHEAD(fd,packet_len(0xe7));
  3436. WFIFOW(fd,0) = 0xe7;
  3437. WFIFOB(fd,2) = type;
  3438. WFIFOSET(fd,packet_len(0xe7));
  3439. } else {
  3440. WFIFOHEAD(fd,packet_len(0x1f5));
  3441. WFIFOW(fd,0) = 0x1f5;
  3442. WFIFOB(fd,2) = type;
  3443. WFIFOL(fd,3) = tsd->status.char_id;
  3444. WFIFOW(fd,7) = tsd->status.base_level;
  3445. WFIFOSET(fd,packet_len(0x1f5));
  3446. }
  3447. }
  3448. /// Notifies the client about an item from other player in current trade.
  3449. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3450. /// 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)
  3451. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3452. {
  3453. int fd;
  3454. unsigned char *buf;
  3455. #if PACKETVER < 20100223
  3456. const int cmd = 0xe9;
  3457. #else
  3458. const int cmd = 0x80f;
  3459. #endif
  3460. nullpo_retv(sd);
  3461. nullpo_retv(tsd);
  3462. fd = tsd->fd;
  3463. buf = WFIFOP(fd,0);
  3464. WFIFOHEAD(fd,packet_len(cmd));
  3465. WBUFW(buf,0) = cmd;
  3466. if( index == 0 )
  3467. {
  3468. #if PACKETVER < 20100223
  3469. WBUFL(buf,2) = amount; //amount
  3470. WBUFW(buf,6) = 0; // type id
  3471. #else
  3472. WBUFW(buf,2) = 0; // type id
  3473. WBUFB(buf,4) = 0; // item type
  3474. WBUFL(buf,5) = amount; // amount
  3475. buf = WBUFP(buf,1); //Advance 1B
  3476. #endif
  3477. WBUFB(buf,8) = 0; //identify flag
  3478. WBUFB(buf,9) = 0; // attribute
  3479. WBUFB(buf,10)= 0; //refine
  3480. WBUFW(buf,11)= 0; //card (4w)
  3481. WBUFW(buf,13)= 0; //card (4w)
  3482. WBUFW(buf,15)= 0; //card (4w)
  3483. WBUFW(buf,17)= 0; //card (4w)
  3484. }
  3485. else
  3486. {
  3487. index -= 2; //index fix
  3488. #if PACKETVER < 20100223
  3489. WBUFL(buf,2) = amount; //amount
  3490. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3491. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3492. else
  3493. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3494. #else
  3495. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3496. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3497. else
  3498. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3499. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3500. WBUFL(buf,5) = amount; // amount
  3501. buf = WBUFP(buf,1); //Advance 1B
  3502. #endif
  3503. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3504. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3505. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3506. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3507. }
  3508. WFIFOSET(fd,packet_len(cmd));
  3509. }
  3510. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3511. /// 00ea <index>.W <result>.B
  3512. /// result:
  3513. /// 0 = success
  3514. /// 1 = overweight
  3515. /// 2 = trade canceled
  3516. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3517. {
  3518. int fd;
  3519. nullpo_retv(sd);
  3520. fd = sd->fd;
  3521. WFIFOHEAD(fd,packet_len(0xea));
  3522. WFIFOW(fd,0) = 0xea;
  3523. WFIFOW(fd,2) = index;
  3524. WFIFOB(fd,4) = fail;
  3525. WFIFOSET(fd,packet_len(0xea));
  3526. }
  3527. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3528. /// 00ec <who>.B
  3529. /// who:
  3530. /// 0 = self
  3531. /// 1 = other player
  3532. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3533. {
  3534. int fd;
  3535. nullpo_retv(sd);
  3536. fd = sd->fd;
  3537. WFIFOHEAD(fd,packet_len(0xec));
  3538. WFIFOW(fd,0) = 0xec;
  3539. WFIFOB(fd,2) = fail;
  3540. WFIFOSET(fd,packet_len(0xec));
  3541. }
  3542. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3543. /// 00ee
  3544. void clif_tradecancelled(struct map_session_data* sd)
  3545. {
  3546. int fd;
  3547. nullpo_retv(sd);
  3548. fd = sd->fd;
  3549. WFIFOHEAD(fd,packet_len(0xee));
  3550. WFIFOW(fd,0) = 0xee;
  3551. WFIFOSET(fd,packet_len(0xee));
  3552. }
  3553. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3554. /// 00f0 <result>.B
  3555. /// result:
  3556. /// 0 = success
  3557. /// 1 = failure
  3558. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3559. {
  3560. int fd;
  3561. nullpo_retv(sd);
  3562. fd = sd->fd;
  3563. WFIFOHEAD(fd,packet_len(0xf0));
  3564. WFIFOW(fd,0) = 0xf0;
  3565. WFIFOB(fd,2) = fail;
  3566. WFIFOSET(fd,packet_len(0xf0));
  3567. }
  3568. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3569. /// 00f1
  3570. /// NOTE: Unknown purpose. Items are not removed until the window is
  3571. /// refreshed (ex. by putting another item in there).
  3572. void clif_tradeundo(struct map_session_data* sd)
  3573. {
  3574. int fd = sd->fd;
  3575. WFIFOHEAD(fd,packet_len(0xf1));
  3576. WFIFOW(fd,0) = 0xf1;
  3577. WFIFOSET(fd,packet_len(0xf1));
  3578. }
  3579. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3580. /// 00f2 <current count>.W <max count>.W
  3581. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3582. {
  3583. int fd;
  3584. nullpo_retv(sd);
  3585. fd=sd->fd;
  3586. WFIFOHEAD(fd,packet_len(0xf2));
  3587. WFIFOW(fd,0) = 0xf2;
  3588. WFIFOW(fd,2) = amount;
  3589. WFIFOW(fd,4) = max_amount;
  3590. WFIFOSET(fd,packet_len(0xf2));
  3591. }
  3592. /// Notifies the client of an item being added to the storage.
  3593. /// 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)
  3594. /// 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)
  3595. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3596. {
  3597. int view,fd;
  3598. nullpo_retv(sd);
  3599. nullpo_retv(i);
  3600. fd=sd->fd;
  3601. view = itemdb_viewid(i->nameid);
  3602. #if PACKETVER < 5
  3603. WFIFOHEAD(fd,packet_len(0xf4));
  3604. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3605. WFIFOW(fd, 2) = index+1; // index
  3606. WFIFOL(fd, 4) = amount; // amount
  3607. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3608. WFIFOB(fd,10) = i->identify; //identify flag
  3609. WFIFOB(fd,11) = i->attribute; // attribute
  3610. WFIFOB(fd,12) = i->refine; //refine
  3611. clif_addcards(WFIFOP(fd,13), i);
  3612. WFIFOSET(fd,packet_len(0xf4));
  3613. #else
  3614. WFIFOHEAD(fd,packet_len(0x1c4));
  3615. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3616. WFIFOW(fd, 2) = index+1; // index
  3617. WFIFOL(fd, 4) = amount; // amount
  3618. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3619. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3620. WFIFOB(fd,11) = i->identify; //identify flag
  3621. WFIFOB(fd,12) = i->attribute; // attribute
  3622. WFIFOB(fd,13) = i->refine; //refine
  3623. clif_addcards(WFIFOP(fd,14), i);
  3624. WFIFOSET(fd,packet_len(0x1c4));
  3625. #endif
  3626. }
  3627. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3628. /// 00f6 <index>.W <amount>.L
  3629. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3630. {
  3631. int fd;
  3632. nullpo_retv(sd);
  3633. fd=sd->fd;
  3634. WFIFOHEAD(fd,packet_len(0xf6));
  3635. WFIFOW(fd,0)=0xf6; // Storage item removed
  3636. WFIFOW(fd,2)=index+1;
  3637. WFIFOL(fd,4)=amount;
  3638. WFIFOSET(fd,packet_len(0xf6));
  3639. }
  3640. /// Closes storage (ZC_CLOSE_STORE).
  3641. /// 00f8
  3642. void clif_storageclose(struct map_session_data* sd)
  3643. {
  3644. int fd;
  3645. nullpo_retv(sd);
  3646. fd=sd->fd;
  3647. WFIFOHEAD(fd,packet_len(0xf8));
  3648. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3649. WFIFOSET(fd,packet_len(0xf8));
  3650. }
  3651. /*==========================================
  3652. * Server tells 'sd' player client the abouts of 'dstsd' player
  3653. *------------------------------------------*/
  3654. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3655. {
  3656. struct block_list *d_bl;
  3657. int i;
  3658. if( dstsd->chatID ) {
  3659. struct chat_data *cd = NULL;
  3660. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3661. clif_dispchat(cd,sd->fd);
  3662. } else if( dstsd->state.vending )
  3663. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3664. else if( dstsd->state.buyingstore )
  3665. clif_buyingstore_entry_single(sd, dstsd);
  3666. if(dstsd->spiritball > 0)
  3667. clif_spiritball_single(sd->fd, dstsd);
  3668. for(i = 1; i < 5; i++){
  3669. if( dstsd->talisman[i] > 0 )
  3670. clif_talisman_single(sd->fd, dstsd, i);
  3671. }
  3672. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3673. if (dstsd->sc.option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  3674. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, SI_BLANK, 0, 0, 0);
  3675. else
  3676. clif_status_change2(&sd->bl, dstsd->bl.id, SELF, StatusIconChangeTable[dstsd->sc_display[i]->type], dstsd->sc_display[i]->val1, dstsd->sc_display[i]->val2, dstsd->sc_display[i]->val3);
  3677. }
  3678. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3679. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3680. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3681. )
  3682. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3683. // display link (sd - dstsd) to sd
  3684. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3685. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3686. // display links (dstsd - devotees) to sd
  3687. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3688. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3689. // display link (dstsd - crusader) to sd
  3690. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3691. clif_devotion(d_bl, sd);
  3692. }
  3693. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3694. {
  3695. uint8 buf[128];
  3696. struct unit_data *ud;
  3697. struct view_data *vd;
  3698. int len;
  3699. vd = status_get_viewdata(bl);
  3700. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3701. return;
  3702. /**
  3703. * Hide NPC from maya purple card.
  3704. **/
  3705. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3706. return;
  3707. ud = unit_bl2ud(bl);
  3708. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3709. clif_send(buf,len,&sd->bl,SELF);
  3710. if (vd->cloth_color)
  3711. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3712. switch (bl->type)
  3713. {
  3714. case BL_PC:
  3715. {
  3716. TBL_PC* tsd = (TBL_PC*)bl;
  3717. clif_getareachar_pc(sd, tsd);
  3718. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3719. clif_specialeffect_single(bl,423,sd->fd);
  3720. else if(tsd->state.size==SZ_MEDIUM)
  3721. clif_specialeffect_single(bl,421,sd->fd);
  3722. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3723. clif_sendbgemblem_single(sd->fd,tsd);
  3724. if ( tsd->status.robe )
  3725. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3726. if (!&tsd->sc)
  3727. break;
  3728. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3729. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3730. if( tsd->sc.data[SC_MONSTER_TRANSFORM] )
  3731. clif_status_change(bl,SI_MONSTER_TRANSFORM,1,0,tsd->sc.data[SC_MONSTER_TRANSFORM]->val1,0,0);
  3732. if( tsd->sc.data[SC_MOONSTAR] )
  3733. clif_status_load(bl,SI_MOONSTAR,1);
  3734. if( tsd->sc.data[SC_SUPER_STAR] )
  3735. clif_status_load(bl,SI_SUPER_STAR,1);
  3736. if( tsd->sc.data[SC_ALL_RIDING] )
  3737. clif_status_load(bl,SI_ALL_RIDING,1);
  3738. }
  3739. break;
  3740. case BL_MER: // Devotion Effects
  3741. if( ((TBL_MER*)bl)->devotion_flag )
  3742. clif_devotion(bl, sd);
  3743. break;
  3744. case BL_NPC:
  3745. {
  3746. TBL_NPC* nd = (TBL_NPC*)bl;
  3747. if( nd->chat_id )
  3748. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3749. if( nd->size == SZ_BIG )
  3750. clif_specialeffect_single(bl,423,sd->fd);
  3751. else if( nd->size == SZ_MEDIUM )
  3752. clif_specialeffect_single(bl,421,sd->fd);
  3753. }
  3754. break;
  3755. case BL_MOB:
  3756. {
  3757. TBL_MOB* md = (TBL_MOB*)bl;
  3758. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3759. clif_specialeffect_single(bl,423,sd->fd);
  3760. else if(md->special_state.size==SZ_MEDIUM)
  3761. clif_specialeffect_single(bl,421,sd->fd);
  3762. #if PACKETVER >= 20120404
  3763. if( !(md->status.mode&MD_BOSS) ){
  3764. int i;
  3765. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3766. if( md->dmglog[i].id == sd->status.char_id )
  3767. clif_monster_hp_bar(md, sd->fd);
  3768. }
  3769. #endif
  3770. }
  3771. break;
  3772. case BL_PET:
  3773. if (vd->head_bottom)
  3774. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3775. break;
  3776. }
  3777. }
  3778. //Modifies the type of damage according to status changes [Skotlex]
  3779. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3780. static inline int clif_calc_delay(int type, int div, int64 damage, int delay)
  3781. {
  3782. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3783. }
  3784. /*==========================================
  3785. * Estimates walk delay based on the damage criteria. [Skotlex]
  3786. *------------------------------------------*/
  3787. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int64 damage, int div_)
  3788. {
  3789. if (type == 4 || type == 9 || damage <=0)
  3790. return 0;
  3791. if (bl->type == BL_PC) {
  3792. if (battle_config.pc_walk_delay_rate != 100)
  3793. delay = delay*battle_config.pc_walk_delay_rate/100;
  3794. } else
  3795. if (battle_config.walk_delay_rate != 100)
  3796. delay = delay*battle_config.walk_delay_rate/100;
  3797. if (div_ > 1) //Multi-hit skills mean higher delays.
  3798. delay += battle_config.multihit_delay*(div_-1);
  3799. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3800. }
  3801. /// Sends a 'damage' packet (src performs action on dst)
  3802. /// 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)
  3803. /// 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)
  3804. /// type:
  3805. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3806. /// 1 = pick up item
  3807. /// 2 = sit down
  3808. /// 3 = stand up
  3809. /// 4 = damage (endure)
  3810. /// 5 = (splash?)
  3811. /// 6 = (skill?)
  3812. /// 7 = (repeat damage?)
  3813. /// 8 = multi-hit damage
  3814. /// 9 = multi-hit damage (endure)
  3815. /// 10 = critical hit
  3816. /// 11 = lucky dodge
  3817. /// 12 = (touch skill?)
  3818. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, int type, int64 sdamage2)
  3819. {
  3820. unsigned char buf[33];
  3821. struct status_change *sc;
  3822. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  3823. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  3824. #if PACKETVER < 20071113
  3825. const int cmd = 0x8a;
  3826. #else
  3827. const int cmd = 0x2e1;
  3828. #endif
  3829. nullpo_ret(src);
  3830. nullpo_ret(dst);
  3831. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3832. sc = status_get_sc(dst);
  3833. if(sc && sc->count) {
  3834. if(sc->data[SC_HALLUCINATION]) {
  3835. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3836. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3837. }
  3838. }
  3839. WBUFW(buf,0)=cmd;
  3840. WBUFL(buf,2)=src->id;
  3841. WBUFL(buf,6)=dst->id;
  3842. WBUFL(buf,10)=tick;
  3843. WBUFL(buf,14)=sdelay;
  3844. WBUFL(buf,18)=ddelay;
  3845. #if PACKETVER < 20071113
  3846. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3847. WBUFW(buf,22)=damage?div:0;
  3848. WBUFW(buf,27)=damage2?div:0;
  3849. } else {
  3850. WBUFW(buf,22)=min(damage, INT16_MAX);
  3851. WBUFW(buf,27)=damage2;
  3852. }
  3853. WBUFW(buf,24)=div;
  3854. WBUFB(buf,26)=type;
  3855. #else
  3856. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3857. WBUFL(buf,22)=damage?div:0;
  3858. WBUFL(buf,29)=damage2?div:0;
  3859. } else {
  3860. WBUFL(buf,22)=damage;
  3861. WBUFL(buf,29)=damage2;
  3862. }
  3863. WBUFW(buf,26)=div;
  3864. WBUFB(buf,28)=type;
  3865. #endif
  3866. if(disguised(dst)) {
  3867. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3868. WBUFL(buf,6) = -dst->id;
  3869. clif_send(buf,packet_len(cmd),dst,SELF);
  3870. } else
  3871. clif_send(buf,packet_len(cmd),dst,AREA);
  3872. if(disguised(src)) {
  3873. WBUFL(buf,2) = -src->id;
  3874. if (disguised(dst))
  3875. WBUFL(buf,6) = dst->id;
  3876. #if PACKETVER < 20071113
  3877. if(damage > 0) WBUFW(buf,22) = -1;
  3878. if(damage2 > 0) WBUFW(buf,27) = -1;
  3879. #else
  3880. if(damage > 0) WBUFL(buf,22) = -1;
  3881. if(damage2 > 0) WBUFL(buf,29) = -1;
  3882. #endif
  3883. clif_send(buf,packet_len(cmd),src,SELF);
  3884. }
  3885. if(src == dst) {
  3886. unit_setdir(src,unit_getdir(src));
  3887. }
  3888. //Return adjusted can't walk delay for further processing.
  3889. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3890. }
  3891. /*==========================================
  3892. * src picks up dst
  3893. *------------------------------------------*/
  3894. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3895. {
  3896. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3897. unsigned char buf[32];
  3898. nullpo_retv(src);
  3899. nullpo_retv(dst);
  3900. WBUFW(buf, 0) = 0x8a;
  3901. WBUFL(buf, 2) = src->id;
  3902. WBUFL(buf, 6) = dst->id;
  3903. WBUFB(buf,26) = 1;
  3904. clif_send(buf, packet_len(0x8a), src, AREA);
  3905. }
  3906. /*==========================================
  3907. * inform clients in area that `bl` is sitting
  3908. *------------------------------------------*/
  3909. void clif_sitting(struct block_list* bl)
  3910. {
  3911. unsigned char buf[32];
  3912. nullpo_retv(bl);
  3913. WBUFW(buf, 0) = 0x8a;
  3914. WBUFL(buf, 2) = bl->id;
  3915. WBUFB(buf,26) = 2;
  3916. clif_send(buf, packet_len(0x8a), bl, AREA);
  3917. if(disguised(bl)) {
  3918. WBUFL(buf, 2) = - bl->id;
  3919. clif_send(buf, packet_len(0x8a), bl, SELF);
  3920. }
  3921. }
  3922. /*==========================================
  3923. * inform clients in area that `bl` is standing
  3924. *------------------------------------------*/
  3925. void clif_standing(struct block_list* bl)
  3926. {
  3927. unsigned char buf[32];
  3928. nullpo_retv(bl);
  3929. WBUFW(buf, 0) = 0x8a;
  3930. WBUFL(buf, 2) = bl->id;
  3931. WBUFB(buf,26) = 3;
  3932. clif_send(buf, packet_len(0x8a), bl, AREA);
  3933. if(disguised(bl)) {
  3934. WBUFL(buf, 2) = - bl->id;
  3935. clif_send(buf, packet_len(0x8a), bl, SELF);
  3936. }
  3937. }
  3938. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3939. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3940. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3941. {
  3942. unsigned char buf[32];
  3943. WBUFW(buf,0) = 0x192;
  3944. WBUFW(buf,2) = x;
  3945. WBUFW(buf,4) = y;
  3946. WBUFW(buf,6) = type;
  3947. mapindex_getmapname_ext(map_mapid2mapname(m),(char*)WBUFP(buf,8));
  3948. if( fd )
  3949. {
  3950. WFIFOHEAD(fd,packet_len(0x192));
  3951. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3952. WFIFOSET(fd,packet_len(0x192));
  3953. }
  3954. else
  3955. {
  3956. struct block_list dummy_bl;
  3957. dummy_bl.type = BL_NUL;
  3958. dummy_bl.x = x;
  3959. dummy_bl.y = y;
  3960. dummy_bl.m = m;
  3961. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3962. }
  3963. }
  3964. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3965. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3966. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3967. {
  3968. int view,fd;
  3969. fd=sd->fd;
  3970. WFIFOHEAD(fd,packet_len(0x9d));
  3971. WFIFOW(fd,0)=0x9d;
  3972. WFIFOL(fd,2)=fitem->bl.id;
  3973. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3974. WFIFOW(fd,6)=view;
  3975. else
  3976. WFIFOW(fd,6)=fitem->item_data.nameid;
  3977. WFIFOB(fd,8)=fitem->item_data.identify;
  3978. WFIFOW(fd,9)=fitem->bl.x;
  3979. WFIFOW(fd,11)=fitem->bl.y;
  3980. WFIFOW(fd,13)=fitem->item_data.amount;
  3981. WFIFOB(fd,15)=fitem->subx;
  3982. WFIFOB(fd,16)=fitem->suby;
  3983. WFIFOSET(fd,packet_len(0x9d));
  3984. }
  3985. /// Notifies the client of a skill unit.
  3986. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3987. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3988. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  3989. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  3990. static void clif_getareachar_skillunit(int type,struct map_session_data *sd, struct skill_unit *unit)
  3991. {
  3992. int fd = sd->fd;
  3993. int header=0, unit_id=0, pos=0;
  3994. if( unit->group->state.guildaura )
  3995. return;
  3996. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3997. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3998. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  3999. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  4000. else
  4001. unit_id=unit->group->unit_id;
  4002. #if PACKETVER >= 3
  4003. if(unit->group->unit_id==UNT_GRAFFITI) // Graffiti [Valaris]
  4004. type = 2;
  4005. #endif
  4006. switch(type){
  4007. case 2: header=0x1c9; break;
  4008. case 3: header=0x8c7; break;
  4009. case 4: header=0x99f; break;
  4010. default:
  4011. case 1: header=0x11f; break;
  4012. }
  4013. WFIFOHEAD(fd,packet_len(header));
  4014. WFIFOW(fd,pos)=header;
  4015. if(type==3 || type==4){
  4016. WFIFOW(fd, pos+2)=packet_len(header);
  4017. pos +=2;
  4018. }
  4019. WFIFOL(fd,pos+2)=unit->bl.id;
  4020. WFIFOL(fd,pos+6)=unit->group->src_id;
  4021. WFIFOW(fd,pos+10)=unit->bl.x;
  4022. WFIFOW(fd,pos+12)=unit->bl.y;
  4023. switch(type){
  4024. case 1: WFIFOB(fd,pos+14)=unit_id;
  4025. WFIFOB(fd,pos+15)=1;
  4026. break;
  4027. case 2: WFIFOB(fd,pos+14)=unit_id;
  4028. WFIFOB(fd,pos+15)=1;
  4029. WFIFOB(fd,pos+16)=1;
  4030. safestrncpy((char*)WFIFOP(fd,pos+17),unit->group->valstr,MESSAGE_SIZE);
  4031. break;
  4032. case 3: WFIFOB(fd,pos+14)=unit_id;
  4033. WFIFOW(fd,pos+15)=unit->range;
  4034. WFIFOB(fd,pos+17)=1; //visible
  4035. break;
  4036. case 4: WFIFOL(fd,pos+14)=unit_id; pos += 3;
  4037. WFIFOW(fd,pos+15)=unit->range;
  4038. WFIFOB(fd,pos+17)=1;
  4039. break;
  4040. }
  4041. WFIFOSET(fd,packet_len(header));
  4042. if(unit->group->skill_id == WZ_ICEWALL)
  4043. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  4044. }
  4045. /*==========================================
  4046. * Server tells client to remove unit of id 'unit->bl.id'
  4047. *------------------------------------------*/
  4048. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4049. {
  4050. nullpo_retv(unit);
  4051. WFIFOHEAD(fd,packet_len(0x120));
  4052. WFIFOW(fd, 0)=0x120;
  4053. WFIFOL(fd, 2)=unit->bl.id;
  4054. WFIFOSET(fd,packet_len(0x120));
  4055. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4056. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4057. }
  4058. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4059. /// 0120 <id>.L
  4060. void clif_skill_delunit(struct skill_unit *unit)
  4061. {
  4062. unsigned char buf[16];
  4063. nullpo_retv(unit);
  4064. WBUFW(buf, 0)=0x120;
  4065. WBUFL(buf, 2)=unit->bl.id;
  4066. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4067. }
  4068. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4069. /// 01ac <id>.L
  4070. /// Only affects units with class [139,153] client-side.
  4071. void clif_skillunit_update(struct block_list* bl)
  4072. {
  4073. unsigned char buf[6];
  4074. nullpo_retv(bl);
  4075. WBUFW(buf,0) = 0x1ac;
  4076. WBUFL(buf,2) = bl->id;
  4077. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4078. }
  4079. /*==========================================
  4080. *
  4081. *------------------------------------------*/
  4082. static int clif_getareachar(struct block_list* bl,va_list ap)
  4083. {
  4084. struct map_session_data *sd;
  4085. nullpo_ret(bl);
  4086. sd=va_arg(ap,struct map_session_data*);
  4087. if (sd == NULL || !sd->fd)
  4088. return 0;
  4089. switch(bl->type){
  4090. case BL_ITEM:
  4091. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4092. break;
  4093. case BL_SKILL:
  4094. clif_getareachar_skillunit(1,sd,(TBL_SKILL*)bl);
  4095. break;
  4096. default:
  4097. if(&sd->bl == bl)
  4098. break;
  4099. clif_getareachar_unit(sd,bl);
  4100. break;
  4101. }
  4102. return 0;
  4103. }
  4104. /*==========================================
  4105. * tbl has gone out of view-size of bl
  4106. *------------------------------------------*/
  4107. int clif_outsight(struct block_list *bl,va_list ap)
  4108. {
  4109. struct block_list *tbl;
  4110. struct view_data *vd;
  4111. TBL_PC *sd, *tsd;
  4112. tbl=va_arg(ap,struct block_list*);
  4113. if(bl == tbl) return 0;
  4114. sd = BL_CAST(BL_PC, bl);
  4115. tsd = BL_CAST(BL_PC, tbl);
  4116. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4117. switch(bl->type){
  4118. case BL_PC:
  4119. if (sd->vd.class_ != INVISIBLE_CLASS)
  4120. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4121. if(sd->chatID){
  4122. struct chat_data *cd;
  4123. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4124. if(cd->usersd[0]==sd)
  4125. clif_dispchat(cd,tsd->fd);
  4126. }
  4127. if( sd->state.vending )
  4128. clif_closevendingboard(bl,tsd->fd);
  4129. if( sd->state.buyingstore )
  4130. clif_buyingstore_disappear_entry_single(tsd, sd);
  4131. break;
  4132. case BL_ITEM:
  4133. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4134. break;
  4135. case BL_SKILL:
  4136. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4137. break;
  4138. case BL_NPC:
  4139. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4140. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4141. break;
  4142. default:
  4143. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4144. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4145. break;
  4146. }
  4147. }
  4148. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4149. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4150. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4151. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4152. }
  4153. return 0;
  4154. }
  4155. /*==========================================
  4156. * tbl has come into view of bl
  4157. *------------------------------------------*/
  4158. int clif_insight(struct block_list *bl,va_list ap)
  4159. {
  4160. struct block_list *tbl;
  4161. TBL_PC *sd, *tsd;
  4162. tbl=va_arg(ap,struct block_list*);
  4163. if (bl == tbl) return 0;
  4164. sd = BL_CAST(BL_PC, bl);
  4165. tsd = BL_CAST(BL_PC, tbl);
  4166. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4167. switch(bl->type){
  4168. case BL_ITEM:
  4169. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4170. break;
  4171. case BL_SKILL:
  4172. clif_getareachar_skillunit(1,tsd,(TBL_SKILL*)bl);
  4173. break;
  4174. default:
  4175. clif_getareachar_unit(tsd,bl);
  4176. break;
  4177. }
  4178. }
  4179. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4180. clif_getareachar_unit(sd,tbl);
  4181. }
  4182. return 0;
  4183. }
  4184. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4185. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4186. void clif_skillinfoblock(struct map_session_data *sd)
  4187. {
  4188. int fd;
  4189. int i,len,id;
  4190. nullpo_retv(sd);
  4191. fd=sd->fd;
  4192. if (!fd) return;
  4193. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4194. WFIFOW(fd,0) = 0x10f;
  4195. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4196. {
  4197. if( (id = sd->status.skill[i].id) != 0 )
  4198. {
  4199. // workaround for bugreport:5348
  4200. if (len + 37 > 8192)
  4201. break;
  4202. WFIFOW(fd,len) = id;
  4203. WFIFOL(fd,len+2) = skill_get_inf(id);
  4204. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4205. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4206. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4207. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4208. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4209. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4210. else
  4211. WFIFOB(fd,len+36) = 0;
  4212. len += 37;
  4213. }
  4214. }
  4215. WFIFOW(fd,2)=len;
  4216. WFIFOSET(fd,len);
  4217. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4218. for ( ; i < MAX_SKILL; i++)
  4219. {
  4220. if( (id = sd->status.skill[i].id) != 0 )
  4221. {
  4222. clif_addskill(sd, id);
  4223. clif_skillinfo(sd, id, 0);
  4224. }
  4225. }
  4226. }
  4227. /**
  4228. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4229. **/
  4230. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4231. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4232. void clif_addskill(struct map_session_data *sd, int id)
  4233. {
  4234. int fd;
  4235. nullpo_retv(sd);
  4236. fd = sd->fd;
  4237. if (!fd) return;
  4238. if( sd->status.skill[id].id <= 0 )
  4239. return;
  4240. WFIFOHEAD(fd, packet_len(0x111));
  4241. WFIFOW(fd,0) = 0x111;
  4242. WFIFOW(fd,2) = id;
  4243. WFIFOL(fd,4) = skill_get_inf(id);
  4244. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4245. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4246. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4247. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4248. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4249. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4250. else
  4251. WFIFOB(fd,38) = 0;
  4252. WFIFOSET(fd,packet_len(0x111));
  4253. }
  4254. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4255. /// 0441 <skill id>.W
  4256. void clif_deleteskill(struct map_session_data *sd, int id)
  4257. {
  4258. #if PACKETVER >= 20081217
  4259. int fd;
  4260. nullpo_retv(sd);
  4261. fd = sd->fd;
  4262. if( !fd ) return;
  4263. WFIFOHEAD(fd,packet_len(0x441));
  4264. WFIFOW(fd,0) = 0x441;
  4265. WFIFOW(fd,2) = id;
  4266. WFIFOSET(fd,packet_len(0x441));
  4267. #endif
  4268. clif_skillinfoblock(sd);
  4269. }
  4270. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4271. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4272. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4273. int fd;
  4274. nullpo_retv(sd);
  4275. fd = sd->fd;
  4276. WFIFOHEAD(fd, packet_len(0x10e));
  4277. WFIFOW(fd, 0) = 0x10e;
  4278. WFIFOW(fd, 2) = skill_id;
  4279. WFIFOW(fd, 4) = lv;
  4280. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4281. WFIFOW(fd, 8) = range;
  4282. WFIFOB(fd, 10) = upgradable;
  4283. WFIFOSET(fd, packet_len(0x10e));
  4284. }
  4285. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4286. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4287. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4288. {
  4289. const int fd = sd->fd;
  4290. WFIFOHEAD(fd,packet_len(0x7e1));
  4291. WFIFOW(fd,0) = 0x7e1;
  4292. WFIFOW(fd,2) = skill;
  4293. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4294. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4295. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4296. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4297. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4298. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4299. else
  4300. WFIFOB(fd,14) = 0;
  4301. WFIFOSET(fd,packet_len(0x7e1));
  4302. }
  4303. /// Notifies clients in area, that an object is about to use a skill.
  4304. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4305. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4306. /// property:
  4307. /// 0 = Yellow cast aura
  4308. /// 1 = Water elemental cast aura
  4309. /// 2 = Earth elemental cast aura
  4310. /// 3 = Fire elemental cast aura
  4311. /// 4 = Wind elemental cast aura
  4312. /// 5 = Poison elemental cast aura
  4313. /// 6 = Holy elemental cast aura
  4314. /// ? = like 0
  4315. /// is disposable:
  4316. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4317. /// 1 = no text
  4318. 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)
  4319. {
  4320. #if PACKETVER < 20091124
  4321. const int cmd = 0x13e;
  4322. #else
  4323. const int cmd = 0x7fb;
  4324. #endif
  4325. unsigned char buf[32];
  4326. WBUFW(buf,0) = cmd;
  4327. WBUFL(buf,2) = src_id;
  4328. WBUFL(buf,6) = dst_id;
  4329. WBUFW(buf,10) = dst_x;
  4330. WBUFW(buf,12) = dst_y;
  4331. WBUFW(buf,14) = skill_id;
  4332. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4333. WBUFL(buf,20) = casttime;
  4334. #if PACKETVER >= 20091124
  4335. WBUFB(buf,24) = 0; // isDisposable
  4336. #endif
  4337. if (disguised(bl)) {
  4338. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4339. WBUFL(buf,2) = -src_id;
  4340. clif_send(buf,packet_len(cmd), bl, SELF);
  4341. } else
  4342. clif_send(buf,packet_len(cmd), bl, AREA);
  4343. }
  4344. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4345. /// 01b9 <id>.L
  4346. void clif_skillcastcancel(struct block_list* bl)
  4347. {
  4348. unsigned char buf[16];
  4349. nullpo_retv(bl);
  4350. WBUFW(buf,0) = 0x1b9;
  4351. WBUFL(buf,2) = bl->id;
  4352. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4353. }
  4354. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4355. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4356. /// num (only used when skill id = NV_BASIC and cause = 0):
  4357. /// 0 = "skill failed" MsgStringTable[159]
  4358. /// 1 = "no emotions" MsgStringTable[160]
  4359. /// 2 = "no sit" MsgStringTable[161]
  4360. /// 3 = "no chat" MsgStringTable[162]
  4361. /// 4 = "no party" MsgStringTable[163]
  4362. /// 5 = "no shout" MsgStringTable[164]
  4363. /// 6 = "no PKing" MsgStringTable[165]
  4364. /// 7 = "no alligning" MsgStringTable[383]
  4365. /// ? = ignored
  4366. /// cause:
  4367. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4368. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4369. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4370. /// "skill failed" MsgStringTable[204] (otherwise)
  4371. /// ... = @see enum useskill_fail_cause
  4372. /// ? = ignored
  4373. ///
  4374. /// if(result!=0) doesn't display any of the previous messages
  4375. /// Note: when this packet is received an unknown flag is always set to 0,
  4376. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4377. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4378. {
  4379. int fd;
  4380. if (!sd) { //Since this is the most common nullpo....
  4381. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4382. return;
  4383. }
  4384. fd=sd->fd;
  4385. if (!fd) return;
  4386. if(battle_config.display_skill_fail&1)
  4387. return; //Disable all skill failed messages
  4388. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4389. return; //Disable delay failed messages
  4390. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4391. return;
  4392. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4393. return;
  4394. WFIFOHEAD(fd,packet_len(0x110));
  4395. WFIFOW(fd,0) = 0x110;
  4396. WFIFOW(fd,2) = skill_id;
  4397. WFIFOL(fd,4) = btype;
  4398. WFIFOB(fd,8) = 0;// success
  4399. WFIFOB(fd,9) = cause;
  4400. WFIFOSET(fd,packet_len(0x110));
  4401. }
  4402. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4403. /// 043d <skill ID>.W <tick>.L
  4404. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4405. {
  4406. #if PACKETVER>=20081112
  4407. int fd;
  4408. nullpo_retv(sd);
  4409. fd=sd->fd;
  4410. WFIFOHEAD(fd,packet_len(0x43d));
  4411. WFIFOW(fd,0) = 0x43d;
  4412. WFIFOW(fd,2) = skill_id;
  4413. WFIFOL(fd,4) = tick;
  4414. WFIFOSET(fd,packet_len(0x43d));
  4415. #endif
  4416. }
  4417. /// Skill attack effect and damage.
  4418. /// 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)
  4419. /// 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)
  4420. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4421. {
  4422. unsigned char buf[64];
  4423. struct status_change *sc;
  4424. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4425. nullpo_ret(src);
  4426. nullpo_ret(dst);
  4427. type = clif_calc_delay(type,div,damage,ddelay);
  4428. sc = status_get_sc(dst);
  4429. if(sc && sc->count) {
  4430. if(sc->data[SC_HALLUCINATION] && damage)
  4431. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4432. }
  4433. #if PACKETVER < 3
  4434. WBUFW(buf,0)=0x114;
  4435. WBUFW(buf,2)=skill_id;
  4436. WBUFL(buf,4)=src->id;
  4437. WBUFL(buf,8)=dst->id;
  4438. WBUFL(buf,12)=tick;
  4439. WBUFL(buf,16)=sdelay;
  4440. WBUFL(buf,20)=ddelay;
  4441. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4442. WBUFW(buf,24)=damage?div:0;
  4443. } else {
  4444. WBUFW(buf,24)=damage;
  4445. }
  4446. WBUFW(buf,26)=skill_lv;
  4447. WBUFW(buf,28)=div;
  4448. WBUFB(buf,30)=type;
  4449. if (disguised(dst)) {
  4450. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4451. WBUFL(buf,8)=-dst->id;
  4452. clif_send(buf,packet_len(0x114),dst,SELF);
  4453. } else
  4454. clif_send(buf,packet_len(0x114),dst,AREA);
  4455. if(disguised(src)) {
  4456. WBUFL(buf,4)=-src->id;
  4457. if (disguised(dst))
  4458. WBUFL(buf,8)=dst->id;
  4459. if(damage > 0)
  4460. WBUFW(buf,24)=-1;
  4461. clif_send(buf,packet_len(0x114),src,SELF);
  4462. }
  4463. #else
  4464. WBUFW(buf,0)=0x1de;
  4465. WBUFW(buf,2)=skill_id;
  4466. WBUFL(buf,4)=src->id;
  4467. WBUFL(buf,8)=dst->id;
  4468. WBUFL(buf,12)=tick;
  4469. WBUFL(buf,16)=sdelay;
  4470. WBUFL(buf,20)=ddelay;
  4471. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4472. WBUFL(buf,24)=damage?div:0;
  4473. } else {
  4474. WBUFL(buf,24)=damage;
  4475. }
  4476. WBUFW(buf,28)=skill_lv;
  4477. WBUFW(buf,30)=div;
  4478. WBUFB(buf,32)=type;
  4479. if (disguised(dst)) {
  4480. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4481. WBUFL(buf,8)=-dst->id;
  4482. clif_send(buf,packet_len(0x1de),dst,SELF);
  4483. } else
  4484. clif_send(buf,packet_len(0x1de),dst,AREA);
  4485. if(disguised(src)) {
  4486. WBUFL(buf,4)=-src->id;
  4487. if (disguised(dst))
  4488. WBUFL(buf,8)=dst->id;
  4489. if(damage > 0)
  4490. WBUFL(buf,24)=-1;
  4491. clif_send(buf,packet_len(0x1de),src,SELF);
  4492. }
  4493. #endif
  4494. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4495. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4496. }
  4497. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4498. /// 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
  4499. /*
  4500. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,int type)
  4501. {
  4502. unsigned char buf[64];
  4503. struct status_change *sc;
  4504. nullpo_ret(src);
  4505. nullpo_ret(dst);
  4506. type = (type>0)?type:skill_get_hit(skill_id);
  4507. type = clif_calc_delay(type,div,damage,ddelay);
  4508. sc = status_get_sc(dst);
  4509. if(sc && sc->count) {
  4510. if(sc->data[SC_HALLUCINATION] && damage)
  4511. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4512. }
  4513. WBUFW(buf,0)=0x115;
  4514. WBUFW(buf,2)=skill_id;
  4515. WBUFL(buf,4)=src->id;
  4516. WBUFL(buf,8)=dst->id;
  4517. WBUFL(buf,12)=tick;
  4518. WBUFL(buf,16)=sdelay;
  4519. WBUFL(buf,20)=ddelay;
  4520. WBUFW(buf,24)=dst->x;
  4521. WBUFW(buf,26)=dst->y;
  4522. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4523. WBUFW(buf,28)=damage?div:0;
  4524. } else {
  4525. WBUFW(buf,28)=damage;
  4526. }
  4527. WBUFW(buf,30)=skill_lv;
  4528. WBUFW(buf,32)=div;
  4529. WBUFB(buf,34)=type;
  4530. clif_send(buf,packet_len(0x115),src,AREA);
  4531. if(disguised(src)) {
  4532. WBUFL(buf,4)=-src->id;
  4533. if(damage > 0)
  4534. WBUFW(buf,28)=-1;
  4535. clif_send(buf,packet_len(0x115),src,SELF);
  4536. }
  4537. if (disguised(dst)) {
  4538. WBUFL(buf,8)=-dst->id;
  4539. if (disguised(src))
  4540. WBUFL(buf,4)=src->id;
  4541. else if(damage > 0)
  4542. WBUFW(buf,28)=-1;
  4543. clif_send(buf,packet_len(0x115),dst,SELF);
  4544. }
  4545. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4546. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4547. }
  4548. */
  4549. /// Non-damaging skill effect (ZC_USE_SKILL).
  4550. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4551. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4552. {
  4553. unsigned char buf[32];
  4554. nullpo_ret(dst);
  4555. WBUFW(buf,0)=0x11a;
  4556. WBUFW(buf,2)=skill_id;
  4557. WBUFW(buf,4)=min(heal, INT16_MAX);
  4558. WBUFL(buf,6)=dst->id;
  4559. WBUFL(buf,10)=src?src->id:0;
  4560. WBUFB(buf,14)=fail;
  4561. if (disguised(dst)) {
  4562. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4563. WBUFL(buf,6)=-dst->id;
  4564. clif_send(buf,packet_len(0x11a),dst,SELF);
  4565. } else
  4566. clif_send(buf,packet_len(0x11a),dst,AREA);
  4567. if(src && disguised(src)) {
  4568. WBUFL(buf,10)=-src->id;
  4569. if (disguised(dst))
  4570. WBUFL(buf,6)=dst->id;
  4571. clif_send(buf,packet_len(0x11a),src,SELF);
  4572. }
  4573. return fail;
  4574. }
  4575. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4576. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4577. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4578. {
  4579. unsigned char buf[32];
  4580. nullpo_retv(src);
  4581. WBUFW(buf,0)=0x117;
  4582. WBUFW(buf,2)=skill_id;
  4583. WBUFL(buf,4)=src->id;
  4584. WBUFW(buf,8)=val;
  4585. WBUFW(buf,10)=x;
  4586. WBUFW(buf,12)=y;
  4587. WBUFL(buf,14)=tick;
  4588. if(disguised(src)) {
  4589. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4590. WBUFL(buf,4)=-src->id;
  4591. clif_send(buf,packet_len(0x117),src,SELF);
  4592. } else
  4593. clif_send(buf,packet_len(0x117),src,AREA);
  4594. }
  4595. /*==========================================
  4596. * Tells all client's nearby 'unit' sight range that it spawned
  4597. *------------------------------------------*/
  4598. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4599. void clif_skill_setunit(struct skill_unit *unit)
  4600. {
  4601. unsigned char buf[128];
  4602. nullpo_retv(unit);
  4603. if( unit->group->state.guildaura )
  4604. return;
  4605. #if PACKETVER >= 3
  4606. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4607. WBUFW(buf, 0)=0x1c9;
  4608. WBUFL(buf, 2)=unit->bl.id;
  4609. WBUFL(buf, 6)=unit->group->src_id;
  4610. WBUFW(buf,10)=unit->bl.x;
  4611. WBUFW(buf,12)=unit->bl.y;
  4612. WBUFB(buf,14)=unit->group->unit_id;
  4613. WBUFB(buf,15)=1;
  4614. WBUFB(buf,16)=1;
  4615. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4616. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4617. return;
  4618. }
  4619. #endif
  4620. WBUFW(buf, 0)=0x11f;
  4621. WBUFL(buf, 2)=unit->bl.id;
  4622. WBUFL(buf, 6)=unit->group->src_id;
  4623. WBUFW(buf,10)=unit->bl.x;
  4624. WBUFW(buf,12)=unit->bl.y;
  4625. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4626. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4627. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4628. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4629. else
  4630. WBUFB(buf,14)=unit->group->unit_id;
  4631. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4632. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4633. }
  4634. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4635. /// 011c <skill id>.W { <map name>.16B }*4
  4636. 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)
  4637. {
  4638. int fd;
  4639. nullpo_retv(sd);
  4640. fd = sd->fd;
  4641. WFIFOHEAD(fd,packet_len(0x11c));
  4642. WFIFOW(fd,0) = 0x11c;
  4643. WFIFOW(fd,2) = skill_id;
  4644. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4645. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4646. else // normal map name
  4647. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4648. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4649. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4650. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4651. WFIFOSET(fd,packet_len(0x11c));
  4652. sd->menuskill_id = skill_id;
  4653. if (skill_id == AL_WARP)
  4654. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4655. else
  4656. sd->menuskill_val = skill_lv;
  4657. }
  4658. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4659. /// 011e <type>.B
  4660. /// type:
  4661. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4662. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4663. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4664. ///
  4665. /// @param sd Who receives the message
  4666. /// @param type What message
  4667. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4668. {
  4669. int fd;
  4670. nullpo_retv(sd);
  4671. fd=sd->fd;
  4672. WFIFOHEAD(fd,packet_len(0x11e));
  4673. WFIFOW(fd,0)=0x11e;
  4674. WFIFOB(fd,2)=type;
  4675. WFIFOSET(fd,packet_len(0x11e));
  4676. }
  4677. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4678. /// 0189 <type>.W
  4679. /// type:
  4680. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4681. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4682. ///
  4683. /// @param sd Who receives the message
  4684. /// @param type What message
  4685. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4686. {
  4687. int fd;
  4688. nullpo_retv(sd);
  4689. fd=sd->fd;
  4690. WFIFOHEAD(fd,packet_len(0x189));
  4691. WFIFOW(fd,0)=0x189;
  4692. WFIFOW(fd,2)=type;
  4693. WFIFOSET(fd,packet_len(0x189));
  4694. }
  4695. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4696. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4697. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4698. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4699. {
  4700. struct status_data *status;
  4701. unsigned char buf[64];
  4702. int i;//, fix;
  4703. nullpo_retv(sd);
  4704. nullpo_retv(dst);
  4705. if( dst->type != BL_MOB )
  4706. return;
  4707. status = status_get_status_data(dst);
  4708. WBUFW(buf, 0)=0x18c;
  4709. WBUFW(buf, 2)=status_get_class(dst);
  4710. WBUFW(buf, 4)=status_get_lv(dst);
  4711. WBUFW(buf, 6)=status->size;
  4712. WBUFL(buf, 8)=status->hp;
  4713. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4714. +(battle_config.estimation_type&2?status->def2:0);
  4715. WBUFW(buf,14)=status->race;
  4716. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4717. +(battle_config.estimation_type&2?status->mdef2:0);
  4718. WBUFW(buf,18)= status->def_ele;
  4719. for(i=0;i<9;i++)
  4720. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4721. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4722. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4723. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4724. }
  4725. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4726. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4727. /// material id:
  4728. /// unused by the client
  4729. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4730. {
  4731. int i,c,view,fd;
  4732. nullpo_retv(sd);
  4733. if(sd->menuskill_id == skill_id)
  4734. return; //Avoid resending the menu twice or more times...
  4735. if( skill_id == GC_CREATENEWPOISON )
  4736. skill_id = GC_RESEARCHNEWPOISON;
  4737. fd=sd->fd;
  4738. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4739. WFIFOW(fd, 0)=0x18d;
  4740. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4741. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4742. ( ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4743. ){
  4744. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4745. WFIFOW(fd,c*8+ 4)= view;
  4746. else
  4747. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4748. WFIFOW(fd,c*8+ 6)= 0;
  4749. WFIFOW(fd,c*8+ 8)= 0;
  4750. WFIFOW(fd,c*8+10)= 0;
  4751. c++;
  4752. }
  4753. }
  4754. WFIFOW(fd, 2)=c*8+8;
  4755. WFIFOSET(fd,WFIFOW(fd,2));
  4756. if(c > 0) {
  4757. sd->menuskill_id = skill_id;
  4758. sd->menuskill_val = trigger;
  4759. return;
  4760. }
  4761. }
  4762. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4763. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4764. /// mk type:
  4765. /// 1 = cooking
  4766. /// 2 = arrow
  4767. /// 3 = elemental
  4768. /// 4 = GN_MIX_COOKING
  4769. /// 5 = GN_MAKEBOMB
  4770. /// 6 = GN_S_PHARMACY
  4771. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4772. {
  4773. int fd;
  4774. int i, c;
  4775. int view;
  4776. nullpo_retv(sd);
  4777. fd = sd->fd;
  4778. if(sd->menuskill_id == skill_id)
  4779. return; //Avoid resending the menu twice or more times...
  4780. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4781. WFIFOW(fd,0) = 0x25a;
  4782. WFIFOW(fd,4) = list_type; // list type
  4783. c = 0;
  4784. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4785. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4786. continue;
  4787. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4788. WFIFOW(fd, 6 + 2 * c) = view;
  4789. else
  4790. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4791. c++;
  4792. }
  4793. if( c > 0 || skill_id == AM_PHARMACY) {
  4794. sd->menuskill_id = skill_id;
  4795. sd->menuskill_val = trigger;
  4796. sd->menuskill_val2 = qty; // amount.
  4797. WFIFOW(fd,2) = 6 + 2 * c;
  4798. WFIFOSET(fd,WFIFOW(fd,2));
  4799. } else {
  4800. clif_menuskill_clear(sd);
  4801. #if PACKETVER >= 20090922
  4802. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  4803. #else
  4804. WFIFOW(fd,2) = 6 + 2 * c;
  4805. WFIFOSET(fd,WFIFOW(fd,2));
  4806. #endif
  4807. }
  4808. }
  4809. /// Notifies clients of a status change.
  4810. /// 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)]
  4811. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4812. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4813. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4814. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4815. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4816. {
  4817. unsigned char buf[32];
  4818. struct map_session_data *sd;
  4819. if (type == SI_BLANK) //It shows nothing on the client...
  4820. return;
  4821. nullpo_retv(bl);
  4822. sd = BL_CAST(BL_PC, bl);
  4823. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4824. return;
  4825. #if PACKETVER >= 20120618
  4826. if(flag && battle_config.display_status_timers && sd)
  4827. WBUFW(buf,0)=0x983;
  4828. else
  4829. #elif PACKETVER >= 20090121
  4830. if(flag && battle_config.display_status_timers && sd)
  4831. WBUFW(buf,0)=0x43f;
  4832. else
  4833. #endif
  4834. WBUFW(buf,0)=0x196;
  4835. WBUFW(buf,2)=type;
  4836. WBUFL(buf,4)=bl->id;
  4837. WBUFB(buf,8)=flag;
  4838. #if PACKETVER >= 20120618
  4839. if(flag && battle_config.display_status_timers && sd) {
  4840. if (tick <= 0)
  4841. tick = 9999; // this is indeed what official servers do
  4842. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4843. WBUFL(buf,13)=tick;
  4844. WBUFL(buf,17) = val1;
  4845. WBUFL(buf,21) = val2;
  4846. WBUFL(buf,25) = val3;
  4847. }
  4848. #elif PACKETVER >= 20090121
  4849. if(flag && battle_config.display_status_timers && sd) {
  4850. if (tick <= 0)
  4851. tick = 9999; // this is indeed what official servers do
  4852. WBUFL(buf,9) = tick;
  4853. WBUFL(buf,13) = val1;
  4854. WBUFL(buf,17) = val2;
  4855. WBUFL(buf,21) = val3;
  4856. }
  4857. #endif
  4858. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4859. }
  4860. void clif_status_change2(struct block_list *bl, int tid, enum send_target target, int type, int val1, int val2, int val3) {
  4861. unsigned char buf[32];
  4862. if (type == SI_BLANK) //It shows nothing on the client
  4863. return;
  4864. nullpo_retv(bl);
  4865. WBUFW(buf,0) = 0x43f;
  4866. WBUFW(buf,2) = type;
  4867. WBUFL(buf,4) = tid;
  4868. WBUFB(buf,8) = 1;
  4869. WBUFL(buf,9) = 9999;
  4870. WBUFL(buf,13) = val1;
  4871. WBUFL(buf,17) = val2;
  4872. WBUFL(buf,21) = val3;
  4873. clif_send(buf,packet_len(0x43f),bl,target);
  4874. }
  4875. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4876. /// 008e <packet len>.W <message>.?B
  4877. void clif_displaymessage(const int fd, const char* mes)
  4878. {
  4879. nullpo_retv(mes);
  4880. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4881. if (fd == 0)
  4882. ;
  4883. else {
  4884. char *message, *line;
  4885. message = aStrdup(mes);
  4886. line = strtok(message, "\n");
  4887. while(line != NULL) {
  4888. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4889. int len = strnlen(line, 255);
  4890. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4891. WFIFOHEAD(fd, 5 + len);
  4892. WFIFOW(fd,0) = 0x8e;
  4893. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4894. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4895. WFIFOSET(fd, 5 + len);
  4896. }
  4897. line = strtok(NULL, "\n");
  4898. }
  4899. aFree(message);
  4900. }
  4901. }
  4902. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4903. /// 009a <packet len>.W <message>.?B
  4904. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4905. {
  4906. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  4907. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4908. WBUFW(buf,0) = 0x9a;
  4909. WBUFW(buf,2) = 4 + lp + len;
  4910. if (type&BC_BLUE)
  4911. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4912. else if (type&BC_WOE)
  4913. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4914. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4915. clif_send(buf, WBUFW(buf,2), bl, target);
  4916. if (buf)
  4917. aFree(buf);
  4918. }
  4919. /*==========================================
  4920. * Displays a message on a 'bl' to all it's nearby clients
  4921. * 008d <PacketLength>.W <GID> L (ZC_NOTIFY_CHAT)
  4922. *------------------------------------------*/
  4923. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  4924. char buf[100];
  4925. int len;
  4926. nullpo_retv(bl);
  4927. if(!message)
  4928. return;
  4929. len = strlen(message)+1;
  4930. if( len > sizeof(buf)-8 ) {
  4931. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4932. len = sizeof(buf)-8;
  4933. }
  4934. WBUFW(buf,0)=0x8d;
  4935. WBUFW(buf,2)=len+8;
  4936. WBUFL(buf,4)=bl->id;
  4937. safestrncpy((char *) WBUFP(buf,8),message,len);
  4938. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  4939. }
  4940. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4941. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4942. 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)
  4943. {
  4944. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4945. WBUFW(buf,0) = 0x1c3;
  4946. WBUFW(buf,2) = len + 16;
  4947. WBUFL(buf,4) = fontColor;
  4948. WBUFW(buf,8) = fontType;
  4949. WBUFW(buf,10) = fontSize;
  4950. WBUFW(buf,12) = fontAlign;
  4951. WBUFW(buf,14) = fontY;
  4952. memcpy(WBUFP(buf,16), mes, len);
  4953. clif_send(buf, WBUFW(buf,2), bl, target);
  4954. if (buf)
  4955. aFree(buf);
  4956. }
  4957. /*
  4958. * Display *msg from *sd to all *users in channel
  4959. */
  4960. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg, short color) {
  4961. DBIterator *iter;
  4962. struct map_session_data *user;
  4963. unsigned short msg_len = strlen(msg) + 1;
  4964. WFIFOHEAD(sd->fd,msg_len + 12);
  4965. WFIFOW(sd->fd,0) = 0x2C1;
  4966. WFIFOW(sd->fd,2) = msg_len + 12;
  4967. WFIFOL(sd->fd,4) = 0;
  4968. WFIFOL(sd->fd,8) = Channel_Config.colors[color];
  4969. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4970. iter = db_iterator(channel->users);
  4971. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4972. if( user->fd == sd->fd )
  4973. continue;
  4974. WFIFOHEAD(user->fd,msg_len + 12);
  4975. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4976. WFIFOSET(user->fd, msg_len + 12);
  4977. }
  4978. dbi_destroy(iter);
  4979. WFIFOSET(sd->fd, msg_len + 12);
  4980. }
  4981. /// Displays heal effect (ZC_RECOVERY).
  4982. /// 013d <var id>.W <amount>.W
  4983. /// var id:
  4984. /// 5 = HP (SP_HP)
  4985. /// 7 = SP (SP_SP)
  4986. /// ? = ignored
  4987. void clif_heal(int fd,int type,int val)
  4988. {
  4989. WFIFOHEAD(fd,packet_len(0x13d));
  4990. WFIFOW(fd,0)=0x13d;
  4991. WFIFOW(fd,2)=type;
  4992. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4993. WFIFOSET(fd,packet_len(0x13d));
  4994. }
  4995. /// Displays resurrection effect (ZC_RESURRECTION).
  4996. /// 0148 <id>.L <type>.W
  4997. /// type:
  4998. /// ignored
  4999. void clif_resurrection(struct block_list *bl,int type)
  5000. {
  5001. unsigned char buf[16];
  5002. nullpo_retv(bl);
  5003. WBUFW(buf,0)=0x148;
  5004. WBUFL(buf,2)=bl->id;
  5005. WBUFW(buf,6)=0;
  5006. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5007. if (disguised(bl))
  5008. clif_spawn(bl);
  5009. }
  5010. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5011. /// 0199 <type>.W
  5012. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5013. {
  5014. int fd;
  5015. nullpo_retv(sd);
  5016. fd=sd->fd;
  5017. WFIFOHEAD(fd,packet_len(0x199));
  5018. WFIFOW(fd,0)=0x199;
  5019. WFIFOW(fd,2)=property;
  5020. WFIFOSET(fd,packet_len(0x199));
  5021. }
  5022. void clif_maptypeproperty2(struct block_list *bl,enum send_target t) {
  5023. #if PACKETVER >= 20130000
  5024. uint8 buf[8];
  5025. WBUFW(buf,0)=0x99b; //2
  5026. WBUFW(buf,2)=0x28; //2
  5027. WBUFB(buf,4) = ((map_flag_vs(bl->m))?0x01:0); //tvt ?
  5028. WBUFB(buf,4) |= ((map_flag_gvg(bl->m))?0x02:0); //gvg
  5029. WBUFB(buf,4) |= ((map_flag_gvg2(bl->m))?0x04:0); //siege
  5030. WBUFB(buf,4) |= (map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m))?0:0x08; //disable mine effect on nomineeffect map and enable it on gvgmap by default
  5031. WBUFB(buf,4) |= ((map[bl->m].flag.nolockon)?0x10:0); //nolockon 0x10 @FIXME what this do
  5032. WBUFB(buf,4) |= ((map[bl->m].flag.pvp)?0x20:0); //countpk
  5033. WBUFB(buf,4) |= 0; //nopartyformation 0x40
  5034. WBUFB(buf,4) |= ((map[bl->m].flag.battleground)?0x80:0); //battleground
  5035. WBUFB(buf,5) = ((map[bl->m].flag.noitemconsumption)?0x01:0); //noitemconsumption
  5036. WBUFB(buf,5) |= ((map[bl->m].flag.nousecart)?0:0x02); // usecart
  5037. WBUFB(buf,5) |= ((map[bl->m].flag.nosumstarmiracle)?0:0x04); //summonstarmiracle
  5038. // WBUFB(buf,5) |= RBUFB(buf,5)&0xf8; //sparebit[0-4]
  5039. WBUFW(buf,6) = 0; //sparebit [5-15], + extra[4]
  5040. clif_send(buf,packet_len(0x99b),bl,t);
  5041. #endif
  5042. }
  5043. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5044. /// 01d6 <type>.W
  5045. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5046. {
  5047. int fd;
  5048. nullpo_retv(sd);
  5049. fd=sd->fd;
  5050. WFIFOHEAD(fd,packet_len(0x1D6));
  5051. WFIFOW(fd,0)=0x1D6;
  5052. WFIFOW(fd,2)=type;
  5053. WFIFOSET(fd,packet_len(0x1D6));
  5054. }
  5055. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5056. /// 019a <id>.L <ranking>.L <total>.L
  5057. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5058. {
  5059. if(type == 2) {
  5060. int fd = sd->fd;
  5061. WFIFOHEAD(fd,packet_len(0x19a));
  5062. WFIFOW(fd,0) = 0x19a;
  5063. WFIFOL(fd,2) = sd->bl.id;
  5064. WFIFOL(fd,6) = pvprank;
  5065. WFIFOL(fd,10) = pvpnum;
  5066. WFIFOSET(fd,packet_len(0x19a));
  5067. } else {
  5068. unsigned char buf[32];
  5069. WBUFW(buf,0) = 0x19a;
  5070. WBUFL(buf,2) = sd->bl.id;
  5071. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5072. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5073. else
  5074. WBUFL(buf,6) = pvprank;
  5075. WBUFL(buf,10) = pvpnum;
  5076. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5077. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5078. else if(!type)
  5079. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5080. else
  5081. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5082. }
  5083. }
  5084. /*==========================================
  5085. *
  5086. *------------------------------------------*/
  5087. void clif_map_property_mapall(int map_idx, enum map_property property)
  5088. {
  5089. struct block_list bl;
  5090. unsigned char buf[16];
  5091. bl.id = 0;
  5092. bl.type = BL_NUL;
  5093. bl.m = map_idx;
  5094. WBUFW(buf,0)=0x199;
  5095. WBUFW(buf,2)=property;
  5096. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5097. }
  5098. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5099. /// 0188 <result>.W <index>.W <refine>.W
  5100. /// result:
  5101. /// 0 = success
  5102. /// 1 = failure
  5103. /// 2 = downgrade
  5104. void clif_refine(int fd, int fail, int index, int val)
  5105. {
  5106. WFIFOHEAD(fd,packet_len(0x188));
  5107. WFIFOW(fd,0)=0x188;
  5108. WFIFOW(fd,2)=fail;
  5109. WFIFOW(fd,4)=index+2;
  5110. WFIFOW(fd,6)=val;
  5111. WFIFOSET(fd,packet_len(0x188));
  5112. }
  5113. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5114. /// 0223 <result>.L <nameid>.W
  5115. /// result:
  5116. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5117. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5118. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5119. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5120. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5121. {
  5122. WFIFOHEAD(fd,packet_len(0x223));
  5123. WFIFOW(fd,0)=0x223;
  5124. WFIFOL(fd,2)=result;
  5125. WFIFOW(fd,6)=item_id;
  5126. WFIFOSET(fd,packet_len(0x223));
  5127. }
  5128. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5129. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5130. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5131. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5132. {
  5133. #if PACKETVER < 20091104
  5134. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5135. WFIFOW(fd,0) = 0x97;
  5136. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5137. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5138. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5139. WFIFOSET(fd,WFIFOW(fd,2));
  5140. #else
  5141. struct map_session_data *ssd = map_nick2sd(nick);
  5142. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5143. WFIFOW(fd,0) = 0x97;
  5144. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5145. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5146. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5147. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5148. WFIFOSET(fd,WFIFOW(fd,2));
  5149. #endif
  5150. }
  5151. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5152. /// 0098 <result>.B
  5153. /// result:
  5154. /// 0 = success to send wisper
  5155. /// 1 = target character is not loged in
  5156. /// 2 = ignored by target
  5157. /// 3 = everyone ignored by target
  5158. void clif_wis_end(int fd, int result)
  5159. {
  5160. struct map_session_data *sd = (session_isValid(fd) ? session[fd]->session_data : NULL);
  5161. if (!sd)
  5162. return;
  5163. #if PACKETVER >= 20131223
  5164. WFIFOHEAD(fd,packet_len(0x9df));
  5165. WFIFOW(fd,0) = 0x9df;
  5166. WFIFOB(fd,2) = (char)result;
  5167. WFIFOL(fd,3) = 0;
  5168. WFIFOSET(fd,packet_len(0x9df));
  5169. #else
  5170. WFIFOHEAD(fd,packet_len(0x98));
  5171. WFIFOW(fd,0) = 0x98;
  5172. WFIFOB(fd,2) = (char)result;
  5173. WFIFOSET(fd,packet_len(0x98));
  5174. #endif
  5175. }
  5176. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5177. /// 0194 <char id>.L <name>.24B
  5178. void clif_solved_charname(int fd, int charid, const char* name)
  5179. {
  5180. WFIFOHEAD(fd,packet_len(0x194));
  5181. WFIFOW(fd,0)=0x194;
  5182. WFIFOL(fd,2)=charid;
  5183. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5184. WFIFOSET(fd,packet_len(0x194));
  5185. }
  5186. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5187. /// 017b <packet len>.W { <name id>.W }*
  5188. void clif_use_card(struct map_session_data *sd,int idx)
  5189. {
  5190. int i,c,ep;
  5191. int fd=sd->fd;
  5192. nullpo_retv(sd);
  5193. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5194. return;
  5195. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5196. return; //Avoid parsing invalid item indexes (no card/no item)
  5197. ep=sd->inventory_data[idx]->equip;
  5198. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5199. WFIFOW(fd,0)=0x17b;
  5200. for(i=c=0;i<MAX_INVENTORY;i++){
  5201. int j;
  5202. if(sd->inventory_data[i] == NULL)
  5203. continue;
  5204. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5205. continue;
  5206. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5207. continue;
  5208. if(sd->status.inventory[i].identify==0 ) //Not identified
  5209. continue;
  5210. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5211. continue;
  5212. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5213. continue;
  5214. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5215. if( j == sd->inventory_data[i]->slot ) // No room
  5216. continue;
  5217. if( sd->status.inventory[i].equip > 0 ) // Do not check items that are already equipped
  5218. continue;
  5219. WFIFOW(fd,4+c*2)=i+2;
  5220. c++;
  5221. }
  5222. if( !c ) return; // no item is available for card insertion
  5223. WFIFOW(fd,2)=4+c*2;
  5224. WFIFOSET(fd,WFIFOW(fd,2));
  5225. }
  5226. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5227. /// 017d <equip index>.W <card index>.W <result>.B
  5228. /// result:
  5229. /// 0 = success
  5230. /// 1 = failure
  5231. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5232. {
  5233. int fd;
  5234. nullpo_retv(sd);
  5235. fd=sd->fd;
  5236. WFIFOHEAD(fd,packet_len(0x17d));
  5237. WFIFOW(fd,0)=0x17d;
  5238. WFIFOW(fd,2)=idx_equip+2;
  5239. WFIFOW(fd,4)=idx_card+2;
  5240. WFIFOB(fd,6)=flag;
  5241. WFIFOSET(fd,packet_len(0x17d));
  5242. }
  5243. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5244. /// 0177 <packet len>.W { <name id>.W }*
  5245. void clif_item_identify_list(struct map_session_data *sd)
  5246. {
  5247. int i,c;
  5248. int fd;
  5249. nullpo_retv(sd);
  5250. fd=sd->fd;
  5251. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5252. WFIFOW(fd,0)=0x177;
  5253. for(i=c=0;i<MAX_INVENTORY;i++){
  5254. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5255. WFIFOW(fd,c*2+4)=i+2;
  5256. c++;
  5257. }
  5258. }
  5259. if(c > 0) {
  5260. WFIFOW(fd,2)=c*2+4;
  5261. WFIFOSET(fd,WFIFOW(fd,2));
  5262. sd->menuskill_id = MC_IDENTIFY;
  5263. sd->menuskill_val = c;
  5264. }
  5265. }
  5266. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5267. /// 0179 <index>.W <result>.B
  5268. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5269. {
  5270. int fd;
  5271. nullpo_retv(sd);
  5272. fd=sd->fd;
  5273. WFIFOHEAD(fd,packet_len(0x179));
  5274. WFIFOW(fd, 0)=0x179;
  5275. WFIFOW(fd, 2)=idx+2;
  5276. WFIFOB(fd, 4)=flag;
  5277. WFIFOSET(fd,packet_len(0x179));
  5278. }
  5279. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5280. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5281. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5282. {
  5283. int i,c;
  5284. int fd;
  5285. unsigned short nameid;
  5286. nullpo_retv(sd);
  5287. nullpo_retv(dstsd);
  5288. fd=sd->fd;
  5289. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5290. WFIFOW(fd,0)=0x1fc;
  5291. for(i=c=0;i<MAX_INVENTORY;i++){
  5292. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5293. WFIFOW(fd,c*13+4) = i;
  5294. WFIFOW(fd,c*13+6) = nameid;
  5295. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5296. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5297. c++;
  5298. }
  5299. }
  5300. if(c > 0) {
  5301. WFIFOW(fd,2)=c*13+4;
  5302. WFIFOSET(fd,WFIFOW(fd,2));
  5303. sd->menuskill_id = BS_REPAIRWEAPON;
  5304. sd->menuskill_val = dstsd->bl.id;
  5305. sd->menuskill_val2 = lv;
  5306. }else
  5307. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5308. }
  5309. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5310. /// 01fe <index>.W <result>.B
  5311. /// index:
  5312. /// ignored (inventory index)
  5313. /// result:
  5314. /// 0 = Item repair success.
  5315. /// 1 = Item repair failure.
  5316. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5317. {
  5318. int fd;
  5319. nullpo_retv(sd);
  5320. fd = sd->fd;
  5321. WFIFOHEAD(fd,packet_len(0x1fe));
  5322. WFIFOW(fd, 0)=0x1fe;
  5323. WFIFOW(fd, 2)=idx+2;
  5324. WFIFOB(fd, 4)=flag;
  5325. WFIFOSET(fd,packet_len(0x1fe));
  5326. }
  5327. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5328. /// 02bb <equip location>.W <account id>.L
  5329. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5330. {
  5331. int fd = sd->fd;
  5332. WFIFOHEAD(fd,packet_len(0x2bb));
  5333. WFIFOW(fd,0) = 0x2bb;
  5334. WFIFOW(fd,2) = position;
  5335. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5336. WFIFOSET(fd,packet_len(0x2bb));
  5337. }
  5338. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5339. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5340. void clif_item_refine_list(struct map_session_data *sd)
  5341. {
  5342. int i,c;
  5343. int fd;
  5344. uint16 skill_lv;
  5345. int wlv;
  5346. int refine_item[5];
  5347. nullpo_retv(sd);
  5348. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5349. fd=sd->fd;
  5350. refine_item[0] = -1;
  5351. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5352. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5353. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5354. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5355. WFIFOW(fd,0)=0x221;
  5356. for(i=c=0;i<MAX_INVENTORY;i++){
  5357. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5358. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5359. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5360. WFIFOW(fd,c*13+ 4)=i+2;
  5361. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5362. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5363. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5364. c++;
  5365. }
  5366. }
  5367. WFIFOW(fd,2)=c*13+4;
  5368. WFIFOSET(fd,WFIFOW(fd,2));
  5369. if (c > 0) {
  5370. sd->menuskill_id = WS_WEAPONREFINE;
  5371. sd->menuskill_val = skill_lv;
  5372. }
  5373. }
  5374. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5375. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5376. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5377. {
  5378. int fd;
  5379. nullpo_retv(sd);
  5380. fd=sd->fd;
  5381. WFIFOHEAD(fd,packet_len(0x147));
  5382. WFIFOW(fd, 0)=0x147;
  5383. WFIFOW(fd, 2)=skill_id;
  5384. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5385. WFIFOW(fd, 6)=0;
  5386. WFIFOW(fd, 8)=skill_lv;
  5387. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5388. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5389. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5390. WFIFOB(fd,38)=0;
  5391. WFIFOSET(fd,packet_len(0x147));
  5392. }
  5393. /// Adds an item to character's cart.
  5394. /// 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)
  5395. /// 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)
  5396. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5397. {
  5398. int view,fd;
  5399. unsigned char *buf;
  5400. nullpo_retv(sd);
  5401. fd=sd->fd;
  5402. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5403. return;
  5404. #if PACKETVER < 5
  5405. WFIFOHEAD(fd,packet_len(0x124));
  5406. buf=WFIFOP(fd,0);
  5407. WBUFW(buf,0)=0x124;
  5408. WBUFW(buf,2)=n+2;
  5409. WBUFL(buf,4)=amount;
  5410. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5411. WBUFW(buf,8)=view;
  5412. else
  5413. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5414. WBUFB(buf,10)=sd->status.cart[n].identify;
  5415. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5416. WBUFB(buf,12)=sd->status.cart[n].refine;
  5417. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5418. WFIFOSET(fd,packet_len(0x124));
  5419. #else
  5420. WFIFOHEAD(fd,packet_len(0x1c5));
  5421. buf=WFIFOP(fd,0);
  5422. WBUFW(buf,0)=0x1c5;
  5423. WBUFW(buf,2)=n+2;
  5424. WBUFL(buf,4)=amount;
  5425. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5426. WBUFW(buf,8)=view;
  5427. else
  5428. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5429. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5430. WBUFB(buf,11)=sd->status.cart[n].identify;
  5431. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5432. WBUFB(buf,13)=sd->status.cart[n].refine;
  5433. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5434. WFIFOSET(fd,packet_len(0x1c5));
  5435. #endif
  5436. }
  5437. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5438. /* Acknowledge an item have been added to cart
  5439. * 012c <result>B
  5440. * result :
  5441. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5442. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5443. */
  5444. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5445. {
  5446. int fd;
  5447. unsigned char *buf;
  5448. nullpo_retv(sd);
  5449. fd = sd->fd;
  5450. buf = WFIFOP(fd,0);
  5451. WBUFW(buf,0) = 0x12c;
  5452. WBUFB(buf,2) = flag;
  5453. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5454. }
  5455. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5456. void clif_bank_open(struct map_session_data *sd){
  5457. int fd;
  5458. nullpo_retv(sd);
  5459. fd = sd->fd;
  5460. WFIFOHEAD(fd,4);
  5461. WFIFOW(fd,0) = 0x09b7;
  5462. WFIFOW(fd,2) = 0;
  5463. WFIFOSET(fd,4);
  5464. }
  5465. /*
  5466. * Request to Open the banking system
  5467. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5468. */
  5469. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5470. //TODO check if preventing trade or stuff like that
  5471. //also mark something in case char ain't available for saving, should we check now ?
  5472. nullpo_retv(sd);
  5473. if( !battle_config.feature_banking ) {
  5474. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5475. return;
  5476. }
  5477. else {
  5478. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5479. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5480. if(sd->status.account_id == aid){
  5481. sd->state.banking = 1;
  5482. //request save ?
  5483. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5484. //on succes open bank ?
  5485. clif_bank_open(sd);
  5486. }
  5487. }
  5488. }
  5489. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5490. void clif_bank_close(struct map_session_data *sd){
  5491. int fd;
  5492. nullpo_retv(sd);
  5493. fd = sd->fd;
  5494. WFIFOHEAD(fd,4);
  5495. WFIFOW(fd,0) = 0x09B9;
  5496. WFIFOW(fd,2) = 0;
  5497. WFIFOSET(fd,4);
  5498. }
  5499. /*
  5500. * Request to close the banking system
  5501. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  5502. */
  5503. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  5504. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5505. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5506. nullpo_retv(sd);
  5507. if( !battle_config.feature_banking ) {
  5508. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5509. //still allow to go trough to not stuck player if we have disable it while they was in
  5510. }
  5511. if(sd->status.account_id == aid){
  5512. sd->state.banking = 0;
  5513. clif_bank_close(sd);
  5514. }
  5515. }
  5516. /*
  5517. * Display how much we got in bank (I suppose)
  5518. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  5519. */
  5520. void clif_Bank_Check(struct map_session_data* sd) {
  5521. unsigned char buf[13];
  5522. struct s_packet_db* info;
  5523. int16 len;
  5524. int cmd = 0;
  5525. nullpo_retv(sd);
  5526. cmd = packet_db_ack[sd->packet_ver][ZC_BANKING_CHECK];
  5527. if(!cmd) cmd = 0x09A6; //default
  5528. info = &packet_db[sd->packet_ver][cmd];
  5529. len = info->len;
  5530. if(!len) return; //version as packet disable
  5531. // sd->state.banking = 1; //mark opening and closing
  5532. WBUFW(buf,0) = cmd;
  5533. WBUFQ(buf,info->pos[0]) = sd->status.bank_vault; //testig value
  5534. WBUFW(buf,info->pos[1]) = 0; //reason
  5535. clif_send(buf,len,&sd->bl,SELF);
  5536. }
  5537. /*
  5538. * Requesting the data in bank
  5539. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  5540. */
  5541. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  5542. nullpo_retv(sd);
  5543. if( !battle_config.feature_banking ) {
  5544. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5545. return;
  5546. }
  5547. else {
  5548. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5549. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5550. if(sd->status.account_id == aid) //since we have it let check it for extra security
  5551. clif_Bank_Check(sd);
  5552. }
  5553. }
  5554. /*
  5555. * Acknowledge of deposit some money in bank
  5556. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  5557. */
  5558. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  5559. unsigned char buf[17];
  5560. struct s_packet_db* info;
  5561. int16 len;
  5562. int cmd =0;
  5563. nullpo_retv(sd);
  5564. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_DEPOSIT];
  5565. if(!cmd) cmd = 0x09A8;
  5566. info = &packet_db[sd->packet_ver][cmd];
  5567. len = info->len;
  5568. if(!len) return; //version as packet disable
  5569. WBUFW(buf,0) = cmd;
  5570. WBUFW(buf,info->pos[0]) = (short)reason;
  5571. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5572. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5573. clif_send(buf,len,&sd->bl,SELF);
  5574. }
  5575. /*
  5576. * Request saving some money in bank
  5577. * @author : original [Yommy/Hercules]
  5578. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  5579. */
  5580. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  5581. nullpo_retv(sd);
  5582. if( !battle_config.feature_banking ) {
  5583. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5584. return;
  5585. }
  5586. else {
  5587. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5588. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5589. int money = RFIFOL(fd,info->pos[1]);
  5590. if(sd->status.account_id == aid){
  5591. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  5592. clif_bank_deposit(sd,reason);
  5593. }
  5594. }
  5595. }
  5596. /*
  5597. * Acknowledge of withdrawing some money from bank
  5598. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  5599. */
  5600. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  5601. unsigned char buf[17];
  5602. struct s_packet_db* info;
  5603. int16 len;
  5604. int cmd;
  5605. nullpo_retv(sd);
  5606. cmd = packet_db_ack[sd->packet_ver][ZC_ACK_BANKING_WITHDRAW];
  5607. if(!cmd) cmd = 0x09AA;
  5608. info = &packet_db[sd->packet_ver][cmd];
  5609. len = info->len;
  5610. if(!len) return; //version as packet disable
  5611. WBUFW(buf,0) = cmd;
  5612. WBUFW(buf,info->pos[0]) = (short)reason;
  5613. WBUFQ(buf,info->pos[1]) = sd->status.bank_vault;/* money in the bank */
  5614. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  5615. clif_send(buf,len,&sd->bl,SELF);
  5616. }
  5617. /*
  5618. * Request Withdrawing some money from bank
  5619. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  5620. */
  5621. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  5622. nullpo_retv(sd);
  5623. if( !battle_config.feature_banking ) {
  5624. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,1496)); //Banking is disabled
  5625. return;
  5626. }
  5627. else {
  5628. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  5629. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5630. int money = RFIFOL(fd,info->pos[1]);
  5631. if(sd->status.account_id == aid){
  5632. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  5633. clif_bank_withdraw(sd,reason);
  5634. }
  5635. }
  5636. }
  5637. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5638. /// 0125 <index>.W <amount>.L
  5639. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5640. {
  5641. int fd;
  5642. nullpo_retv(sd);
  5643. fd=sd->fd;
  5644. WFIFOHEAD(fd,packet_len(0x125));
  5645. WFIFOW(fd,0)=0x125;
  5646. WFIFOW(fd,2)=n+2;
  5647. WFIFOL(fd,4)=amount;
  5648. WFIFOSET(fd,packet_len(0x125));
  5649. }
  5650. /// Opens the shop creation menu (ZC_OPENSTORE).
  5651. /// 012d <num>.W
  5652. /// num:
  5653. /// number of allowed item slots
  5654. void clif_openvendingreq(struct map_session_data* sd, int num)
  5655. {
  5656. int fd;
  5657. nullpo_retv(sd);
  5658. fd = sd->fd;
  5659. WFIFOHEAD(fd,packet_len(0x12d));
  5660. WFIFOW(fd,0) = 0x12d;
  5661. WFIFOW(fd,2) = num;
  5662. WFIFOSET(fd,packet_len(0x12d));
  5663. }
  5664. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5665. /// 0131 <owner id>.L <message>.80B
  5666. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5667. {
  5668. unsigned char buf[128];
  5669. nullpo_retv(bl);
  5670. WBUFW(buf,0) = 0x131;
  5671. WBUFL(buf,2) = bl->id;
  5672. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5673. if( fd ) {
  5674. WFIFOHEAD(fd,packet_len(0x131));
  5675. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5676. WFIFOSET(fd,packet_len(0x131));
  5677. } else {
  5678. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5679. }
  5680. }
  5681. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5682. /// 0132 <owner id>.L
  5683. void clif_closevendingboard(struct block_list* bl, int fd)
  5684. {
  5685. unsigned char buf[16];
  5686. nullpo_retv(bl);
  5687. WBUFW(buf,0) = 0x132;
  5688. WBUFL(buf,2) = bl->id;
  5689. if( fd ) {
  5690. WFIFOHEAD(fd,packet_len(0x132));
  5691. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5692. WFIFOSET(fd,packet_len(0x132));
  5693. } else {
  5694. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5695. }
  5696. }
  5697. /// Sends a list of items in a shop.
  5698. /// 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)
  5699. /// 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)
  5700. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5701. {
  5702. int i,fd;
  5703. int count;
  5704. struct map_session_data* vsd;
  5705. #if PACKETVER < 20100105
  5706. const int cmd = 0x133;
  5707. const int offset = 8;
  5708. #else
  5709. const int cmd = 0x800;
  5710. const int offset = 12;
  5711. #endif
  5712. nullpo_retv(sd);
  5713. nullpo_retv(vending);
  5714. nullpo_retv(vsd=map_id2sd(id));
  5715. fd = sd->fd;
  5716. count = vsd->vend_num;
  5717. WFIFOHEAD(fd, offset+count*22);
  5718. WFIFOW(fd,0) = cmd;
  5719. WFIFOW(fd,2) = offset+count*22;
  5720. WFIFOL(fd,4) = id;
  5721. #if PACKETVER >= 20100105
  5722. WFIFOL(fd,8) = vsd->vender_id;
  5723. #endif
  5724. for( i = 0; i < count; i++ )
  5725. {
  5726. int index = vending[i].index;
  5727. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5728. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5729. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5730. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5731. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->nameid);
  5732. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5733. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5734. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5735. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5736. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5737. }
  5738. WFIFOSET(fd,WFIFOW(fd,2));
  5739. }
  5740. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5741. /// 0135 <index>.W <amount>.W <result>.B
  5742. /// result:
  5743. /// 0 = success
  5744. /// 1 = not enough zeny
  5745. /// 2 = overweight
  5746. /// 4 = out of stock
  5747. /// 5 = "cannot use an npc shop while in a trade"
  5748. /// 6 = Because the store information was incorrect the item was not purchased.
  5749. /// 7 = No sales information.
  5750. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5751. {
  5752. int fd;
  5753. nullpo_retv(sd);
  5754. fd = sd->fd;
  5755. WFIFOHEAD(fd,packet_len(0x135));
  5756. WFIFOW(fd,0) = 0x135;
  5757. WFIFOW(fd,2) = index+2;
  5758. WFIFOW(fd,4) = amount;
  5759. WFIFOB(fd,6) = fail;
  5760. WFIFOSET(fd,packet_len(0x135));
  5761. }
  5762. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5763. /// 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 }*
  5764. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5765. {
  5766. int i,fd;
  5767. int count;
  5768. nullpo_retv(sd);
  5769. fd = sd->fd;
  5770. count = sd->vend_num;
  5771. WFIFOHEAD(fd, 8+count*22);
  5772. WFIFOW(fd,0) = 0x136;
  5773. WFIFOW(fd,2) = 8+count*22;
  5774. WFIFOL(fd,4) = id;
  5775. for( i = 0; i < count; i++ ) {
  5776. int index = vending[i].index;
  5777. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5778. WFIFOL(fd, 8+i*22) = vending[i].value;
  5779. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5780. WFIFOW(fd,14+i*22) = vending[i].amount;
  5781. WFIFOB(fd,16+i*22) = itemtype(data->nameid);
  5782. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5783. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5784. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5785. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5786. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5787. }
  5788. WFIFOSET(fd,WFIFOW(fd,2));
  5789. }
  5790. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5791. /// 0137 <index>.W <amount>.W
  5792. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5793. {
  5794. int fd;
  5795. nullpo_retv(sd);
  5796. fd = sd->fd;
  5797. WFIFOHEAD(fd,packet_len(0x137));
  5798. WFIFOW(fd,0) = 0x137;
  5799. WFIFOW(fd,2) = index+2;
  5800. WFIFOW(fd,4) = amount;
  5801. WFIFOSET(fd,packet_len(0x137));
  5802. }
  5803. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5804. /// 00fa <result>.B
  5805. /// result:
  5806. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5807. /// 1 = MsgStringTable[78]="party name already exists"
  5808. /// 2 = MsgStringTable[79]="already in a party"
  5809. /// 3 = cannot organize parties on this map
  5810. /// ? = nothing
  5811. void clif_party_created(struct map_session_data *sd,int result)
  5812. {
  5813. int fd;
  5814. nullpo_retv(sd);
  5815. fd=sd->fd;
  5816. WFIFOHEAD(fd,packet_len(0xfa));
  5817. WFIFOW(fd,0)=0xfa;
  5818. WFIFOB(fd,2)=result;
  5819. WFIFOSET(fd,packet_len(0xfa));
  5820. }
  5821. /// Adds new member to a party.
  5822. /// 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)
  5823. /// 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)
  5824. /// role:
  5825. /// 0 = leader
  5826. /// 1 = normal
  5827. /// state:
  5828. /// 0 = connected
  5829. /// 1 = disconnected
  5830. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5831. {
  5832. unsigned char buf[81];
  5833. int i;
  5834. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5835. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5836. } else {
  5837. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5838. }
  5839. if (i >= MAX_PARTY) return; //Should never happen...
  5840. sd = p->data[i].sd;
  5841. WBUFW(buf, 0) = 0x1e9;
  5842. WBUFL(buf, 2) = sd->status.account_id;
  5843. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5844. WBUFW(buf,10) = sd->bl.x;
  5845. WBUFW(buf,12) = sd->bl.y;
  5846. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5847. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5848. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5849. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
  5850. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5851. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5852. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5853. }
  5854. /// Sends party information (ZC_GROUP_LIST).
  5855. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5856. /// role:
  5857. /// 0 = leader
  5858. /// 1 = normal
  5859. /// state:
  5860. /// 0 = connected
  5861. /// 1 = disconnected
  5862. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5863. {
  5864. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5865. struct map_session_data* party_sd = NULL;
  5866. int i, c;
  5867. nullpo_retv(p);
  5868. WBUFW(buf,0) = 0xfb;
  5869. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5870. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5871. {
  5872. struct party_member* m = &p->party.member[i];
  5873. if(!m->account_id) continue;
  5874. if(party_sd == NULL) party_sd = p->data[i].sd;
  5875. WBUFL(buf,28+c*46) = m->account_id;
  5876. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5877. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5878. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5879. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5880. c++;
  5881. }
  5882. WBUFW(buf,2) = 28+c*46;
  5883. if(sd) { // send only to self
  5884. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5885. } else if (party_sd) { // send to whole party
  5886. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5887. }
  5888. }
  5889. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5890. /// 02c9 <flag>.B
  5891. /// flag:
  5892. /// 0 = allow party invites
  5893. /// 1 = auto-deny party invites
  5894. void clif_partyinvitationstate(struct map_session_data* sd)
  5895. {
  5896. int fd;
  5897. nullpo_retv(sd);
  5898. fd = sd->fd;
  5899. WFIFOHEAD(fd, packet_len(0x2c9));
  5900. WFIFOW(fd, 0) = 0x2c9;
  5901. WFIFOB(fd, 2) = 0; // not implemented
  5902. WFIFOSET(fd, packet_len(0x2c9));
  5903. }
  5904. /// Party invitation request.
  5905. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5906. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5907. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5908. {
  5909. #if PACKETVER < 20070821
  5910. const int cmd = 0xfe;
  5911. #else
  5912. const int cmd = 0x2c6;
  5913. #endif
  5914. int fd;
  5915. struct party_data *p;
  5916. nullpo_retv(sd);
  5917. nullpo_retv(tsd);
  5918. fd=tsd->fd;
  5919. if( (p=party_search(sd->status.party_id))==NULL )
  5920. return;
  5921. WFIFOHEAD(fd,packet_len(cmd));
  5922. WFIFOW(fd,0)=cmd;
  5923. WFIFOL(fd,2)=sd->status.party_id;
  5924. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5925. WFIFOSET(fd,packet_len(cmd));
  5926. }
  5927. /// Party invite result.
  5928. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5929. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5930. /// result=0 : char is already in a party -> MsgStringTable[80]
  5931. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5932. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5933. /// result=3 : party is full -> MsgStringTable[83]
  5934. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5935. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5936. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5937. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5938. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5939. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5940. {
  5941. int fd;
  5942. nullpo_retv(sd);
  5943. fd=sd->fd;
  5944. #if PACKETVER < 20070904
  5945. if( result == 7 ) {
  5946. clif_displaymessage(fd, msg_txt(sd,3));
  5947. return;
  5948. }
  5949. #endif
  5950. #if PACKETVER < 20070821
  5951. WFIFOHEAD(fd,packet_len(0xfd));
  5952. WFIFOW(fd,0) = 0xfd;
  5953. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5954. WFIFOB(fd,26) = result;
  5955. WFIFOSET(fd,packet_len(0xfd));
  5956. #else
  5957. WFIFOHEAD(fd,packet_len(0x2c5));
  5958. WFIFOW(fd,0) = 0x2c5;
  5959. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5960. WFIFOL(fd,26) = result;
  5961. WFIFOSET(fd,packet_len(0x2c5));
  5962. #endif
  5963. }
  5964. /// Updates party settings.
  5965. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5966. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5967. /// exp option:
  5968. /// 0 = exp sharing disabled
  5969. /// 1 = exp sharing enabled
  5970. /// 2 = cannot change exp sharing
  5971. ///
  5972. /// flag:
  5973. /// 0 = send to party
  5974. /// 1 = send to sd
  5975. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5976. {
  5977. unsigned char buf[16];
  5978. #if PACKETVER < 20090603
  5979. const int cmd = 0x101;
  5980. #else
  5981. const int cmd = 0x7d8;
  5982. #endif
  5983. nullpo_retv(p);
  5984. if(!sd && flag==0){
  5985. int i;
  5986. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5987. if (i < MAX_PARTY)
  5988. sd = p->data[i].sd;
  5989. }
  5990. if(!sd) return;
  5991. WBUFW(buf,0)=cmd;
  5992. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5993. #if PACKETVER >= 20090603
  5994. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5995. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5996. #endif
  5997. if(flag==0)
  5998. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5999. else
  6000. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6001. }
  6002. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6003. /// result:
  6004. /// 0 = leave
  6005. /// 1 = expel
  6006. /// 2 = cannot leave party on this map
  6007. /// 3 = cannot expel from party on this map
  6008. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  6009. {
  6010. unsigned char buf[64];
  6011. nullpo_retv(p);
  6012. if(!sd && (flag&0xf0)==0)
  6013. {
  6014. int i;
  6015. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6016. if (i < MAX_PARTY)
  6017. sd = p->data[i].sd;
  6018. }
  6019. if(!sd) return;
  6020. WBUFW(buf,0)=0x105;
  6021. WBUFL(buf,2)=account_id;
  6022. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  6023. WBUFB(buf,30)=flag&0x0f;
  6024. if((flag&0xf0)==0)
  6025. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  6026. else
  6027. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  6028. }
  6029. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6030. /// 0109 <packet len>.W <account id>.L <message>.?B
  6031. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  6032. {
  6033. struct map_session_data *sd;
  6034. int i;
  6035. nullpo_retv(p);
  6036. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6037. if(i < MAX_PARTY){
  6038. unsigned char buf[1024];
  6039. if( len > sizeof(buf)-8 )
  6040. {
  6041. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6042. len = sizeof(buf)-8;
  6043. }
  6044. sd = p->data[i].sd;
  6045. WBUFW(buf,0)=0x109;
  6046. WBUFW(buf,2)=len+8;
  6047. WBUFL(buf,4)=account_id;
  6048. safestrncpy((char *)WBUFP(buf,8), mes, len);
  6049. clif_send(buf,len+8,&sd->bl,PARTY);
  6050. }
  6051. }
  6052. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6053. /// 0107 <account id>.L <x>.W <y>.W
  6054. void clif_party_xy(struct map_session_data *sd)
  6055. {
  6056. unsigned char buf[16];
  6057. nullpo_retv(sd);
  6058. WBUFW(buf,0)=0x107;
  6059. WBUFL(buf,2)=sd->status.account_id;
  6060. WBUFW(buf,6)=sd->bl.x;
  6061. WBUFW(buf,8)=sd->bl.y;
  6062. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6063. }
  6064. /*==========================================
  6065. * Sends x/y dot to a single fd. [Skotlex]
  6066. *------------------------------------------*/
  6067. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6068. {
  6069. WFIFOHEAD(fd,packet_len(0x107));
  6070. WFIFOW(fd,0)=0x107;
  6071. WFIFOL(fd,2)=sd->status.account_id;
  6072. WFIFOW(fd,6)=sd->bl.x;
  6073. WFIFOW(fd,8)=sd->bl.y;
  6074. WFIFOSET(fd,packet_len(0x107));
  6075. }
  6076. /// Updates HP bar of a party member.
  6077. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6078. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6079. void clif_party_hp(struct map_session_data *sd)
  6080. {
  6081. unsigned char buf[16];
  6082. #if PACKETVER < 20100126
  6083. const int cmd = 0x106;
  6084. #else
  6085. const int cmd = 0x80e;
  6086. #endif
  6087. nullpo_retv(sd);
  6088. WBUFW(buf,0)=cmd;
  6089. WBUFL(buf,2)=sd->status.account_id;
  6090. #if PACKETVER < 20100126
  6091. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6092. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6093. WBUFW(buf,8) = 100;
  6094. } else {
  6095. WBUFW(buf,6) = sd->battle_status.hp;
  6096. WBUFW(buf,8) = sd->battle_status.max_hp;
  6097. }
  6098. #else
  6099. WBUFL(buf,6) = sd->battle_status.hp;
  6100. WBUFL(buf,10) = sd->battle_status.max_hp;
  6101. #endif
  6102. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6103. }
  6104. /*==========================================
  6105. * Sends HP bar to a single fd. [Skotlex]
  6106. *------------------------------------------*/
  6107. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6108. {
  6109. #if PACKETVER < 20100126
  6110. const int cmd = 0x106;
  6111. #else
  6112. const int cmd = 0x80e;
  6113. #endif
  6114. WFIFOHEAD(fd,packet_len(cmd));
  6115. WFIFOW(fd,0) = cmd;
  6116. WFIFOL(fd,2) = id;
  6117. #if PACKETVER < 20100126
  6118. if( maxhp > INT16_MAX )
  6119. {// To correctly display the %hp bar. [Skotlex]
  6120. WFIFOW(fd,6) = hp/(maxhp/100);
  6121. WFIFOW(fd,8) = 100;
  6122. } else {
  6123. WFIFOW(fd,6) = hp;
  6124. WFIFOW(fd,8) = maxhp;
  6125. }
  6126. #else
  6127. WFIFOL(fd,6) = hp;
  6128. WFIFOL(fd,10) = maxhp;
  6129. #endif
  6130. WFIFOSET(fd, packet_len(cmd));
  6131. }
  6132. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6133. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6134. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6135. {
  6136. int fd;
  6137. nullpo_retv(sd);
  6138. nullpo_retv(bl);
  6139. fd=sd->fd;
  6140. WFIFOHEAD(fd,packet_len(0x139));
  6141. WFIFOW(fd, 0)=0x139;
  6142. WFIFOL(fd, 2)=bl->id;
  6143. WFIFOW(fd, 6)=bl->x;
  6144. WFIFOW(fd, 8)=bl->y;
  6145. WFIFOW(fd,10)=sd->bl.x;
  6146. WFIFOW(fd,12)=sd->bl.y;
  6147. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6148. WFIFOSET(fd,packet_len(0x139));
  6149. }
  6150. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6151. /// 018f <result>.W <name id>.W
  6152. /// result:
  6153. /// 0 = success
  6154. /// 1 = failure
  6155. /// 2 = success (alchemist)
  6156. /// 3 = failure (alchemist)
  6157. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6158. {
  6159. int view,fd;
  6160. nullpo_retv(sd);
  6161. fd = sd->fd;
  6162. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6163. WFIFOHEAD(fd,packet_len(0x18f));
  6164. WFIFOW(fd, 0)=0x18f;
  6165. WFIFOW(fd, 2)=flag;
  6166. if((view = itemdb_viewid(nameid)) > 0)
  6167. WFIFOW(fd, 4)=view;
  6168. else
  6169. WFIFOW(fd, 4)=nameid;
  6170. WFIFOSET(fd,packet_len(0x18f));
  6171. }
  6172. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6173. /// 019e
  6174. void clif_catch_process(struct map_session_data *sd)
  6175. {
  6176. int fd;
  6177. nullpo_retv(sd);
  6178. fd=sd->fd;
  6179. WFIFOHEAD(fd,packet_len(0x19e));
  6180. WFIFOW(fd,0)=0x19e;
  6181. WFIFOSET(fd,packet_len(0x19e));
  6182. }
  6183. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6184. /// 01a0 <result>.B
  6185. /// 0 = failure
  6186. /// 1 = success
  6187. void clif_pet_roulette(struct map_session_data *sd,int data)
  6188. {
  6189. int fd;
  6190. nullpo_retv(sd);
  6191. fd=sd->fd;
  6192. WFIFOHEAD(fd,packet_len(0x1a0));
  6193. WFIFOW(fd,0)=0x1a0;
  6194. WFIFOB(fd,2)=data;
  6195. WFIFOSET(fd,packet_len(0x1a0));
  6196. }
  6197. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6198. /// 01a6 <packet len>.W { <index>.W }*
  6199. void clif_sendegg(struct map_session_data *sd)
  6200. {
  6201. int i,n=0,fd;
  6202. nullpo_retv(sd);
  6203. fd=sd->fd;
  6204. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6205. clif_displaymessage(fd, msg_txt(sd,666));
  6206. return;
  6207. }
  6208. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6209. WFIFOW(fd,0)=0x1a6;
  6210. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6211. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  6212. sd->inventory_data[i]->type!=IT_PETEGG ||
  6213. sd->status.inventory[i].amount<=0)
  6214. continue;
  6215. WFIFOW(fd,n*2+4)=i+2;
  6216. n++;
  6217. }
  6218. WFIFOW(fd,2)=4+n*2;
  6219. WFIFOSET(fd,WFIFOW(fd,2));
  6220. sd->menuskill_id = SA_TAMINGMONSTER;
  6221. sd->menuskill_val = -1;
  6222. }
  6223. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6224. /// 01a4 <type>.B <id>.L <data>.L
  6225. /// type:
  6226. /// 0 = pre-init (data = 0)
  6227. /// 1 = intimacy (data = 0~4)
  6228. /// 2 = hunger (data = 0~4)
  6229. /// 3 = accessory
  6230. /// 4 = performance (data = 1~3: normal, 4: special)
  6231. /// 5 = hairstyle
  6232. ///
  6233. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6234. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6235. {
  6236. uint8 buf[16];
  6237. nullpo_retv(pd);
  6238. WBUFW(buf,0) = 0x1a4;
  6239. WBUFB(buf,2) = type;
  6240. WBUFL(buf,3) = pd->bl.id;
  6241. WBUFL(buf,7) = param;
  6242. if (sd)
  6243. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6244. else
  6245. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6246. }
  6247. /// Pet's base data (ZC_PROPERTY_PET).
  6248. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6249. void clif_send_petstatus(struct map_session_data *sd)
  6250. {
  6251. int fd;
  6252. struct s_pet *pet;
  6253. nullpo_retv(sd);
  6254. nullpo_retv(sd->pd);
  6255. fd=sd->fd;
  6256. pet = &sd->pd->pet;
  6257. WFIFOHEAD(fd,packet_len(0x1a2));
  6258. WFIFOW(fd,0)=0x1a2;
  6259. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  6260. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6261. WFIFOW(fd,27)=pet->level;
  6262. WFIFOW(fd,29)=pet->hungry;
  6263. WFIFOW(fd,31)=pet->intimate;
  6264. WFIFOW(fd,33)=pet->equip;
  6265. #if PACKETVER >= 20081126
  6266. WFIFOW(fd,35)=pet->class_;
  6267. #endif
  6268. WFIFOSET(fd,packet_len(0x1a2));
  6269. }
  6270. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6271. /// 01aa <id>.L <data>.L
  6272. /// data:
  6273. /// @see CZ_PET_ACT.
  6274. void clif_pet_emotion(struct pet_data *pd,int param)
  6275. {
  6276. unsigned char buf[16];
  6277. nullpo_retv(pd);
  6278. memset(buf,0,packet_len(0x1aa));
  6279. WBUFW(buf,0)=0x1aa;
  6280. WBUFL(buf,2)=pd->bl.id;
  6281. if(param >= 100 && pd->petDB->talk_convert_class) {
  6282. if(pd->petDB->talk_convert_class < 0)
  6283. return;
  6284. else if(pd->petDB->talk_convert_class > 0) {
  6285. // replace mob_id component of talk/act data
  6286. param -= (pd->pet.class_ - 100)*100;
  6287. param += (pd->petDB->talk_convert_class - 100)*100;
  6288. }
  6289. }
  6290. WBUFL(buf,6)=param;
  6291. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6292. }
  6293. /// Result of request to feed a pet (ZC_FEED_PET).
  6294. /// 01a3 <result>.B <name id>.W
  6295. /// result:
  6296. /// 0 = failure
  6297. /// 1 = success
  6298. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6299. {
  6300. int fd;
  6301. nullpo_retv(sd);
  6302. fd=sd->fd;
  6303. WFIFOHEAD(fd,packet_len(0x1a3));
  6304. WFIFOW(fd,0)=0x1a3;
  6305. WFIFOB(fd,2)=fail;
  6306. WFIFOW(fd,3)=foodid;
  6307. WFIFOSET(fd,packet_len(0x1a3));
  6308. }
  6309. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6310. /// 01cd { <skill id>.L }*7
  6311. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6312. {
  6313. int fd;
  6314. nullpo_retv(sd);
  6315. fd=sd->fd;
  6316. WFIFOHEAD(fd,packet_len(0x1cd));
  6317. WFIFOW(fd, 0)=0x1cd;
  6318. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6319. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6320. else
  6321. WFIFOL(fd,2)= 0x00000000;
  6322. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6323. WFIFOL(fd,6)= MG_COLDBOLT;
  6324. else
  6325. WFIFOL(fd,6)= 0x00000000;
  6326. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6327. WFIFOL(fd,10)= MG_FIREBOLT;
  6328. else
  6329. WFIFOL(fd,10)= 0x00000000;
  6330. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6331. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6332. else
  6333. WFIFOL(fd,14)= 0x00000000;
  6334. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6335. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6336. else
  6337. WFIFOL(fd,18)= 0x00000000;
  6338. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6339. WFIFOL(fd,22)= MG_FIREBALL;
  6340. else
  6341. WFIFOL(fd,22)= 0x00000000;
  6342. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6343. WFIFOL(fd,26)= MG_FROSTDIVER;
  6344. else
  6345. WFIFOL(fd,26)= 0x00000000;
  6346. WFIFOSET(fd,packet_len(0x1cd));
  6347. sd->menuskill_id = SA_AUTOSPELL;
  6348. sd->menuskill_val = skill_lv;
  6349. }
  6350. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6351. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6352. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6353. {
  6354. unsigned char buf[56];
  6355. nullpo_retv(src);
  6356. memset(buf,0,packet_len(0x1cf));
  6357. WBUFW(buf,0) = 0x1cf;
  6358. WBUFL(buf,2) = src->id;
  6359. if( src->type == BL_MER )
  6360. {
  6361. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6362. if( md && md->master && md->devotion_flag )
  6363. WBUFL(buf,6) = md->master->bl.id;
  6364. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  6365. }
  6366. else
  6367. {
  6368. int i;
  6369. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6370. if( sd == NULL )
  6371. return;
  6372. for( i = 0; i < 5; i++ )
  6373. WBUFL(buf,6+4*i) = sd->devotion[i];
  6374. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  6375. }
  6376. if( tsd )
  6377. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6378. else
  6379. clif_send(buf, packet_len(0x1cf), src, AREA);
  6380. }
  6381. /*==========================================
  6382. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6383. * Notifies clients in an area of an object's spirits.
  6384. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6385. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6386. *------------------------------------------*/
  6387. void clif_spiritball(struct block_list *bl) {
  6388. unsigned char buf[16];
  6389. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6390. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6391. nullpo_retv(bl);
  6392. WBUFW(buf, 0) = 0x1d0;
  6393. WBUFL(buf, 2) = bl->id;
  6394. WBUFW(buf, 6) = 0; //init to 0
  6395. switch(bl->type){
  6396. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6397. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6398. }
  6399. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6400. }
  6401. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6402. /// 01d2 <account id>.L <delay>.L
  6403. void clif_combo_delay(struct block_list *bl,int wait)
  6404. {
  6405. unsigned char buf[32];
  6406. nullpo_retv(bl);
  6407. WBUFW(buf,0)=0x1d2;
  6408. WBUFL(buf,2)=bl->id;
  6409. WBUFL(buf,6)=wait;
  6410. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6411. }
  6412. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6413. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6414. /// flag:
  6415. /// 0 = inactive
  6416. /// 1 = active
  6417. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6418. {
  6419. unsigned char buf[32];
  6420. nullpo_retv(src);
  6421. WBUFW(buf,0)=0x1d1;
  6422. WBUFL(buf,2)=src->id;
  6423. WBUFL(buf,6)=dst_id;
  6424. WBUFL(buf,10)=active;
  6425. clif_send(buf,packet_len(0x1d1),src,AREA);
  6426. }
  6427. /// MVP effect (ZC_MVP).
  6428. /// 010c <account id>.L
  6429. void clif_mvp_effect(struct map_session_data *sd)
  6430. {
  6431. unsigned char buf[16];
  6432. nullpo_retv(sd);
  6433. WBUFW(buf,0)=0x10c;
  6434. WBUFL(buf,2)=sd->bl.id;
  6435. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6436. }
  6437. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6438. /// 010a <name id>.W
  6439. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  6440. {
  6441. int view,fd;
  6442. nullpo_retv(sd);
  6443. fd=sd->fd;
  6444. WFIFOHEAD(fd,packet_len(0x10a));
  6445. WFIFOW(fd,0)=0x10a;
  6446. if((view = itemdb_viewid(nameid)) > 0)
  6447. WFIFOW(fd,2)=view;
  6448. else
  6449. WFIFOW(fd,2)=nameid;
  6450. WFIFOSET(fd,packet_len(0x10a));
  6451. }
  6452. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6453. /// 010b <exp>.L
  6454. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6455. {
  6456. int fd;
  6457. nullpo_retv(sd);
  6458. fd=sd->fd;
  6459. WFIFOHEAD(fd,packet_len(0x10b));
  6460. WFIFOW(fd,0)=0x10b;
  6461. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6462. WFIFOSET(fd,packet_len(0x10b));
  6463. }
  6464. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6465. /// 010d
  6466. ///
  6467. /// "You are the MVP, but cannot obtain the reward because
  6468. /// you are overweight."
  6469. void clif_mvp_noitem(struct map_session_data* sd)
  6470. {
  6471. int fd = sd->fd;
  6472. WFIFOHEAD(fd,packet_len(0x10d));
  6473. WFIFOW(fd,0) = 0x10d;
  6474. WFIFOSET(fd,packet_len(0x10d));
  6475. }
  6476. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6477. /// 0167 <result>.B
  6478. /// result:
  6479. /// 0 = "Guild has been created."
  6480. /// 1 = "You are already in a Guild."
  6481. /// 2 = "That Guild Name already exists."
  6482. /// 3 = "You need the neccessary item to create a Guild."
  6483. void clif_guild_created(struct map_session_data *sd,int flag)
  6484. {
  6485. int fd;
  6486. nullpo_retv(sd);
  6487. fd=sd->fd;
  6488. WFIFOHEAD(fd,packet_len(0x167));
  6489. WFIFOW(fd,0)=0x167;
  6490. WFIFOB(fd,2)=flag;
  6491. WFIFOSET(fd,packet_len(0x167));
  6492. }
  6493. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6494. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6495. /// mode:
  6496. /// &0x01 = allow invite
  6497. /// &0x10 = allow expel
  6498. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6499. {
  6500. int ps,fd;
  6501. nullpo_retv(sd);
  6502. nullpo_retv(g);
  6503. fd=sd->fd;
  6504. ps=guild_getposition(g,sd);
  6505. WFIFOHEAD(fd,packet_len(0x16c));
  6506. WFIFOW(fd,0)=0x16c;
  6507. WFIFOL(fd,2)=g->guild_id;
  6508. WFIFOL(fd,6)=g->emblem_id;
  6509. WFIFOL(fd,10)=g->position[ps].mode;
  6510. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  6511. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6512. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6513. WFIFOSET(fd,packet_len(0x16c));
  6514. }
  6515. /// Guild member login notice.
  6516. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6517. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6518. /// status:
  6519. /// 0 = offline
  6520. /// 1 = online
  6521. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6522. {
  6523. unsigned char buf[64];
  6524. struct map_session_data* sd;
  6525. nullpo_retv(g);
  6526. WBUFW(buf, 0)=0x1f2;
  6527. WBUFL(buf, 2)=g->member[idx].account_id;
  6528. WBUFL(buf, 6)=g->member[idx].char_id;
  6529. WBUFL(buf,10)=flag;
  6530. if( ( sd = g->member[idx].sd ) != NULL )
  6531. {
  6532. WBUFW(buf,14) = sd->status.sex;
  6533. WBUFW(buf,16) = sd->status.hair;
  6534. WBUFW(buf,18) = sd->status.hair_color;
  6535. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6536. }
  6537. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6538. {
  6539. WBUFW(buf,14) = 0;
  6540. WBUFW(buf,16) = 0;
  6541. WBUFW(buf,18) = 0;
  6542. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6543. }
  6544. }
  6545. // Function `clif_guild_memberlogin_notice` sends info about
  6546. // logins and logouts of a guild member to the rest members.
  6547. // But at the 1st time (after a player login or map changing)
  6548. // the client won't show the message.
  6549. // So I suggest use this function for sending "first-time-info"
  6550. // to some player on entering the game or changing location.
  6551. // At next time the client would always show the message.
  6552. // The function sends all the statuses in the single packet
  6553. // to economize traffic. [LuzZza]
  6554. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6555. {
  6556. struct guild *g;
  6557. unsigned char buf[14*128];
  6558. int i, count=0, p_len;
  6559. nullpo_retv(sd);
  6560. p_len = packet_len(0x16d);
  6561. if(!(g = sd->guild))
  6562. return;
  6563. for(i=0; i<g->max_member; i++) {
  6564. if(g->member[i].account_id > 0 &&
  6565. g->member[i].account_id != sd->status.account_id) {
  6566. WBUFW(buf,count*p_len) = 0x16d;
  6567. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6568. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6569. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6570. count++;
  6571. }
  6572. }
  6573. clif_send(buf, p_len*count, &sd->bl, SELF);
  6574. }
  6575. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6576. /// 014e <menu flag>.L
  6577. /// menu flag:
  6578. /// 0x00 = Basic Info (always on)
  6579. /// &0x01 = Member manager
  6580. /// &0x02 = Positions
  6581. /// &0x04 = Skills
  6582. /// &0x10 = Expulsion list
  6583. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6584. /// &0x80 = Notice
  6585. void clif_guild_masterormember(struct map_session_data *sd)
  6586. {
  6587. int fd;
  6588. nullpo_retv(sd);
  6589. fd=sd->fd;
  6590. WFIFOHEAD(fd,packet_len(0x14e));
  6591. WFIFOW(fd,0) = 0x14e;
  6592. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6593. WFIFOSET(fd,packet_len(0x14e));
  6594. }
  6595. /// Guild basic information (Territories [Valaris])
  6596. /// 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)
  6597. /// 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)
  6598. void clif_guild_basicinfo(struct map_session_data *sd) {
  6599. int fd;
  6600. struct guild *g;
  6601. nullpo_retv(sd);
  6602. fd = sd->fd;
  6603. if( (g = sd->guild) == NULL )
  6604. return;
  6605. WFIFOHEAD(fd,packet_len(0x1b6));
  6606. WFIFOW(fd, 0)=0x1b6;//0x150;
  6607. WFIFOL(fd, 2)=g->guild_id;
  6608. WFIFOL(fd, 6)=g->guild_lv;
  6609. WFIFOL(fd,10)=g->connect_member;
  6610. WFIFOL(fd,14)=g->max_member;
  6611. WFIFOL(fd,18)=g->average_lv;
  6612. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6613. WFIFOL(fd,26)=g->next_exp;
  6614. WFIFOL(fd,30)=0; // Tax Points
  6615. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6616. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6617. WFIFOL(fd,42)=g->emblem_id;
  6618. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6619. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6620. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6621. WFIFOL(fd,110) = 0; // zeny
  6622. WFIFOSET(fd,packet_len(0x1b6));
  6623. }
  6624. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6625. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6626. void clif_guild_allianceinfo(struct map_session_data *sd)
  6627. {
  6628. int fd,i,c;
  6629. struct guild *g;
  6630. nullpo_retv(sd);
  6631. if( (g = sd->guild) == NULL )
  6632. return;
  6633. fd = sd->fd;
  6634. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6635. WFIFOW(fd, 0)=0x14c;
  6636. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6637. struct guild_alliance *a=&g->alliance[i];
  6638. if(a->guild_id>0){
  6639. WFIFOL(fd,c*32+4)=a->opposition;
  6640. WFIFOL(fd,c*32+8)=a->guild_id;
  6641. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6642. c++;
  6643. }
  6644. }
  6645. WFIFOW(fd, 2)=c*32+4;
  6646. WFIFOSET(fd,WFIFOW(fd,2));
  6647. }
  6648. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6649. /// 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 }*
  6650. /// state:
  6651. /// 0 = offline
  6652. /// 1 = online
  6653. /// memo:
  6654. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6655. void clif_guild_memberlist(struct map_session_data *sd)
  6656. {
  6657. int fd;
  6658. int i,c;
  6659. struct guild *g;
  6660. nullpo_retv(sd);
  6661. if( (fd = sd->fd) == 0 )
  6662. return;
  6663. if( (g = sd->guild) == NULL )
  6664. return;
  6665. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6666. WFIFOW(fd, 0)=0x154;
  6667. for(i=0,c=0;i<g->max_member;i++){
  6668. struct guild_member *m=&g->member[i];
  6669. if(m->account_id==0)
  6670. continue;
  6671. WFIFOL(fd,c*104+ 4)=m->account_id;
  6672. WFIFOL(fd,c*104+ 8)=m->char_id;
  6673. WFIFOW(fd,c*104+12)=m->hair;
  6674. WFIFOW(fd,c*104+14)=m->hair_color;
  6675. WFIFOW(fd,c*104+16)=m->gender;
  6676. WFIFOW(fd,c*104+18)=m->class_;
  6677. WFIFOW(fd,c*104+20)=m->lv;
  6678. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6679. WFIFOL(fd,c*104+26)=m->online;
  6680. WFIFOL(fd,c*104+30)=m->position;
  6681. 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.
  6682. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6683. c++;
  6684. }
  6685. WFIFOW(fd, 2)=c*104+4;
  6686. WFIFOSET(fd,WFIFOW(fd,2));
  6687. }
  6688. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6689. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6690. void clif_guild_positionnamelist(struct map_session_data *sd)
  6691. {
  6692. int i,fd;
  6693. struct guild *g;
  6694. nullpo_retv(sd);
  6695. if( (g = sd->guild) == NULL )
  6696. return;
  6697. fd = sd->fd;
  6698. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6699. WFIFOW(fd, 0)=0x166;
  6700. for(i=0;i<MAX_GUILDPOSITION;i++){
  6701. WFIFOL(fd,i*28+4)=i;
  6702. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6703. }
  6704. WFIFOW(fd,2)=i*28+4;
  6705. WFIFOSET(fd,WFIFOW(fd,2));
  6706. }
  6707. /// Guild position information (ZC_POSITION_INFO).
  6708. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6709. /// mode:
  6710. /// &0x01 = allow invite
  6711. /// &0x10 = allow expel
  6712. /// ranking:
  6713. /// TODO
  6714. void clif_guild_positioninfolist(struct map_session_data *sd)
  6715. {
  6716. int i,fd;
  6717. struct guild *g;
  6718. nullpo_retv(sd);
  6719. if( (g = sd->guild) == NULL )
  6720. return;
  6721. fd = sd->fd;
  6722. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6723. WFIFOW(fd, 0)=0x160;
  6724. for(i=0;i<MAX_GUILDPOSITION;i++){
  6725. struct guild_position *p=&g->position[i];
  6726. WFIFOL(fd,i*16+ 4)=i;
  6727. WFIFOL(fd,i*16+ 8)=p->mode;
  6728. WFIFOL(fd,i*16+12)=i;
  6729. WFIFOL(fd,i*16+16)=p->exp_mode;
  6730. }
  6731. WFIFOW(fd, 2)=i*16+4;
  6732. WFIFOSET(fd,WFIFOW(fd,2));
  6733. }
  6734. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6735. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6736. /// mode:
  6737. /// &0x01 = allow invite
  6738. /// &0x10 = allow expel
  6739. /// ranking:
  6740. /// TODO
  6741. void clif_guild_positionchanged(struct guild *g,int idx)
  6742. {
  6743. // FIXME: This packet is intended to update the clients after a
  6744. // commit of position info changes, not sending one packet per
  6745. // position.
  6746. struct map_session_data *sd;
  6747. unsigned char buf[128];
  6748. nullpo_retv(g);
  6749. WBUFW(buf, 0)=0x174;
  6750. WBUFW(buf, 2)=44; // packet len
  6751. // GUILD_REG_POSITION_INFO{
  6752. WBUFL(buf, 4)=idx;
  6753. WBUFL(buf, 8)=g->position[idx].mode;
  6754. WBUFL(buf,12)=idx;
  6755. WBUFL(buf,16)=g->position[idx].exp_mode;
  6756. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6757. // }*
  6758. if( (sd=guild_getavailablesd(g))!=NULL )
  6759. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6760. }
  6761. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6762. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6763. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6764. {
  6765. // FIXME: This packet is intended to update the clients after a
  6766. // commit of member position assignment changes, not sending one
  6767. // packet per position.
  6768. struct map_session_data *sd;
  6769. unsigned char buf[64];
  6770. nullpo_retv(g);
  6771. WBUFW(buf, 0)=0x156;
  6772. WBUFW(buf, 2)=16; // packet len
  6773. // MEMBER_POSITION_INFO{
  6774. WBUFL(buf, 4)=g->member[idx].account_id;
  6775. WBUFL(buf, 8)=g->member[idx].char_id;
  6776. WBUFL(buf,12)=g->member[idx].position;
  6777. // }*
  6778. if( (sd=guild_getavailablesd(g))!=NULL )
  6779. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6780. }
  6781. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6782. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6783. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6784. {
  6785. int fd;
  6786. nullpo_retv(sd);
  6787. nullpo_retv(g);
  6788. fd = sd->fd;
  6789. if( g->emblem_len <= 0 )
  6790. return;
  6791. WFIFOHEAD(fd,g->emblem_len+12);
  6792. WFIFOW(fd,0)=0x152;
  6793. WFIFOW(fd,2)=g->emblem_len+12;
  6794. WFIFOL(fd,4)=g->guild_id;
  6795. WFIFOL(fd,8)=g->emblem_id;
  6796. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6797. WFIFOSET(fd,WFIFOW(fd,2));
  6798. }
  6799. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6800. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6801. void clif_guild_emblem_area(struct block_list* bl)
  6802. {
  6803. uint8 buf[12];
  6804. nullpo_retv(bl);
  6805. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6806. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6807. WBUFW(buf,0) = 0x1b4;
  6808. WBUFL(buf,2) = bl->id;
  6809. WBUFL(buf,6) = status_get_guild_id(bl);
  6810. WBUFW(buf,10) = status_get_emblem_id(bl);
  6811. clif_send(buf, 12, bl, AREA_WOS);
  6812. }
  6813. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6814. /// 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 }*
  6815. void clif_guild_skillinfo(struct map_session_data* sd)
  6816. {
  6817. int fd;
  6818. struct guild* g;
  6819. int i,c;
  6820. nullpo_retv(sd);
  6821. if( (g = sd->guild) == NULL )
  6822. return;
  6823. fd = sd->fd;
  6824. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6825. WFIFOW(fd,0) = 0x0162;
  6826. WFIFOW(fd,4) = g->skill_point;
  6827. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6828. {
  6829. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6830. {
  6831. int id = g->skill[i].id;
  6832. int p = 6 + c*37;
  6833. WFIFOW(fd,p+0) = id;
  6834. WFIFOL(fd,p+2) = skill_get_inf(id);
  6835. WFIFOW(fd,p+6) = g->skill[i].lv;
  6836. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6837. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6838. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6839. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6840. c++;
  6841. }
  6842. }
  6843. WFIFOW(fd,2) = 6 + c*37;
  6844. WFIFOSET(fd,WFIFOW(fd,2));
  6845. }
  6846. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6847. /// 016f <subject>.60B <notice>.120B
  6848. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6849. {
  6850. int fd;
  6851. nullpo_retv(sd);
  6852. nullpo_retv(g);
  6853. fd = sd->fd;
  6854. if ( !session_isActive(fd) )
  6855. return;
  6856. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6857. return;
  6858. WFIFOHEAD(fd,packet_len(0x16f));
  6859. WFIFOW(fd,0) = 0x16f;
  6860. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6861. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6862. WFIFOSET(fd,packet_len(0x16f));
  6863. }
  6864. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6865. /// 016a <guild id>.L <guild name>.24B
  6866. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6867. {
  6868. int fd;
  6869. nullpo_retv(sd);
  6870. nullpo_retv(g);
  6871. fd=sd->fd;
  6872. WFIFOHEAD(fd,packet_len(0x16a));
  6873. WFIFOW(fd,0)=0x16a;
  6874. WFIFOL(fd,2)=g->guild_id;
  6875. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6876. WFIFOSET(fd,packet_len(0x16a));
  6877. }
  6878. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6879. /// 0169 <answer>.B
  6880. /// answer:
  6881. /// 0 = Already in guild.
  6882. /// 1 = Offer rejected.
  6883. /// 2 = Offer accepted.
  6884. /// 3 = Guild full.
  6885. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6886. {
  6887. int fd;
  6888. nullpo_retv(sd);
  6889. fd=sd->fd;
  6890. WFIFOHEAD(fd,packet_len(0x169));
  6891. WFIFOW(fd,0)=0x169;
  6892. WFIFOB(fd,2)=flag;
  6893. WFIFOSET(fd,packet_len(0x169));
  6894. }
  6895. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6896. /// 015a <char name>.24B <reason>.40B
  6897. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6898. {
  6899. unsigned char buf[128];
  6900. nullpo_retv(sd);
  6901. WBUFW(buf, 0)=0x15a;
  6902. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6903. memcpy(WBUFP(buf,26),mes,40);
  6904. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6905. }
  6906. /// Notifies clients of a guild of an expelled member.
  6907. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6908. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6909. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6910. {
  6911. unsigned char buf[128];
  6912. #if PACKETVER < 20100803
  6913. const unsigned short cmd = 0x15c;
  6914. #else
  6915. const unsigned short cmd = 0x839;
  6916. #endif
  6917. nullpo_retv(sd);
  6918. WBUFW(buf,0) = cmd;
  6919. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6920. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6921. #if PACKETVER < 20100803
  6922. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6923. #endif
  6924. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6925. }
  6926. /// Guild expulsion list (ZC_BAN_LIST).
  6927. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6928. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6929. void clif_guild_expulsionlist(struct map_session_data* sd)
  6930. {
  6931. #if PACKETVER < 20100803
  6932. const int offset = NAME_LENGTH*2+40;
  6933. #else
  6934. const int offset = NAME_LENGTH+40;
  6935. #endif
  6936. int fd, i, c = 0;
  6937. struct guild* g;
  6938. nullpo_retv(sd);
  6939. if( (g = sd->guild) == NULL )
  6940. return;
  6941. fd = sd->fd;
  6942. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6943. WFIFOW(fd,0) = 0x163;
  6944. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6945. {
  6946. struct guild_expulsion* e = &g->expulsion[i];
  6947. if( e->account_id > 0 )
  6948. {
  6949. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6950. #if PACKETVER < 20100803
  6951. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6952. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6953. #else
  6954. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6955. #endif
  6956. c++;
  6957. }
  6958. }
  6959. WFIFOW(fd,2) = 4 + c*offset;
  6960. WFIFOSET(fd,WFIFOW(fd,2));
  6961. }
  6962. /// Guild chat message (ZC_GUILD_CHAT).
  6963. /// 017f <packet len>.W <message>.?B
  6964. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6965. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6966. struct map_session_data *sd;
  6967. uint8 buf[256];
  6968. if( len == 0 )
  6969. {
  6970. return;
  6971. }
  6972. else if( len > sizeof(buf)-5 )
  6973. {
  6974. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6975. len = sizeof(buf)-5;
  6976. }
  6977. WBUFW(buf, 0) = 0x17f;
  6978. WBUFW(buf, 2) = len + 5;
  6979. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6980. if ((sd = guild_getavailablesd(g)) != NULL)
  6981. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6982. }
  6983. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6984. /// 0171 <inviter account id>.L <guild name>.24B
  6985. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6986. {
  6987. int fd;
  6988. nullpo_retv(sd);
  6989. fd=sd->fd;
  6990. WFIFOHEAD(fd,packet_len(0x171));
  6991. WFIFOW(fd,0)=0x171;
  6992. WFIFOL(fd,2)=account_id;
  6993. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6994. WFIFOSET(fd,packet_len(0x171));
  6995. }
  6996. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6997. /// 0173 <answer>.B
  6998. /// answer:
  6999. /// 0 = Already allied.
  7000. /// 1 = You rejected the offer.
  7001. /// 2 = You accepted the offer.
  7002. /// 3 = They have too any alliances.
  7003. /// 4 = You have too many alliances.
  7004. /// 5 = Alliances are disabled.
  7005. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7006. {
  7007. int fd;
  7008. nullpo_retv(sd);
  7009. fd=sd->fd;
  7010. WFIFOHEAD(fd,packet_len(0x173));
  7011. WFIFOW(fd,0)=0x173;
  7012. WFIFOL(fd,2)=flag;
  7013. WFIFOSET(fd,packet_len(0x173));
  7014. }
  7015. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7016. /// 0184 <other guild id>.L <relation>.L
  7017. /// relation:
  7018. /// 0 = Ally
  7019. /// 1 = Enemy
  7020. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7021. {
  7022. int fd;
  7023. nullpo_retv(sd);
  7024. fd = sd->fd;
  7025. if (fd <= 0)
  7026. return;
  7027. WFIFOHEAD(fd,packet_len(0x184));
  7028. WFIFOW(fd,0)=0x184;
  7029. WFIFOL(fd,2)=guild_id;
  7030. WFIFOL(fd,6)=flag;
  7031. WFIFOSET(fd,packet_len(0x184));
  7032. }
  7033. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7034. /// 0181 <result>.B
  7035. /// result:
  7036. /// 0 = Antagonist has been set.
  7037. /// 1 = Guild has too many Antagonists.
  7038. /// 2 = Already set as an Antagonist.
  7039. /// 3 = Antagonists are disabled.
  7040. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7041. {
  7042. int fd;
  7043. nullpo_retv(sd);
  7044. fd=sd->fd;
  7045. WFIFOHEAD(fd,packet_len(0x181));
  7046. WFIFOW(fd,0)=0x181;
  7047. WFIFOB(fd,2)=flag;
  7048. WFIFOSET(fd,packet_len(0x181));
  7049. }
  7050. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7051. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7052. /*
  7053. void clif_guild_allianceadded(struct guild *g,int idx)
  7054. {
  7055. unsigned char buf[64];
  7056. WBUFW(buf,0)=0x185;
  7057. WBUFL(buf,2)=g->alliance[idx].opposition;
  7058. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7059. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7060. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7061. }
  7062. */
  7063. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7064. /// 015e <reason>.L
  7065. /// 0 = success
  7066. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7067. /// 2 = there are still members in the guild
  7068. void clif_guild_broken(struct map_session_data *sd,int flag)
  7069. {
  7070. int fd;
  7071. nullpo_retv(sd);
  7072. fd=sd->fd;
  7073. WFIFOHEAD(fd,packet_len(0x15e));
  7074. WFIFOW(fd,0)=0x15e;
  7075. WFIFOL(fd,2)=flag;
  7076. WFIFOSET(fd,packet_len(0x15e));
  7077. }
  7078. /// Displays emotion on an object (ZC_EMOTION).
  7079. /// 00c0 <id>.L <type>.B
  7080. /// type:
  7081. /// enum emotion_type
  7082. void clif_emotion(struct block_list *bl,int type)
  7083. {
  7084. unsigned char buf[8];
  7085. nullpo_retv(bl);
  7086. WBUFW(buf,0)=0xc0;
  7087. WBUFL(buf,2)=bl->id;
  7088. WBUFB(buf,6)=type;
  7089. clif_send(buf,packet_len(0xc0),bl,AREA);
  7090. }
  7091. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7092. /// 0191 <id>.L <contents>.80B
  7093. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7094. {
  7095. unsigned char buf[MESSAGE_SIZE+6];
  7096. nullpo_retv(bl);
  7097. WBUFW(buf,0) = 0x191;
  7098. WBUFL(buf,2) = bl->id;
  7099. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  7100. clif_send(buf,packet_len(0x191),bl,AREA);
  7101. }
  7102. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7103. /// 01ea <id>.L
  7104. void clif_wedding_effect(struct block_list *bl)
  7105. {
  7106. unsigned char buf[6];
  7107. nullpo_retv(bl);
  7108. WBUFW(buf,0) = 0x1ea;
  7109. WBUFL(buf,2) = bl->id;
  7110. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7111. }
  7112. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7113. /// 01e6 <partner name>.24B
  7114. void clif_callpartner(struct map_session_data *sd)
  7115. {
  7116. unsigned char buf[26];
  7117. nullpo_retv(sd);
  7118. WBUFW(buf,0) = 0x1e6;
  7119. if( sd->status.partner_id ) {
  7120. const char *p = map_charid2nick(sd->status.partner_id);
  7121. struct map_session_data *p_sd = pc_get_partner(sd);
  7122. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7123. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  7124. else
  7125. WBUFB(buf,2) = 0;
  7126. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7127. WBUFB(buf,2) = 0;
  7128. }
  7129. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7130. }
  7131. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7132. /// 01e4
  7133. /// This packet while still implemented by the client is no longer being officially used.
  7134. /*
  7135. void clif_marriage_process(struct map_session_data *sd)
  7136. {
  7137. int fd;
  7138. nullpo_retv(sd);
  7139. fd=sd->fd;
  7140. WFIFOHEAD(fd,packet_len(0x1e4));
  7141. WFIFOW(fd,0)=0x1e4;
  7142. WFIFOSET(fd,packet_len(0x1e4));
  7143. }
  7144. */
  7145. /// Notice of divorce (ZC_DIVORCE).
  7146. /// 0205 <partner name>.24B
  7147. void clif_divorced(struct map_session_data* sd, const char* name)
  7148. {
  7149. int fd;
  7150. nullpo_retv(sd);
  7151. fd=sd->fd;
  7152. WFIFOHEAD(fd,packet_len(0x205));
  7153. WFIFOW(fd,0)=0x205;
  7154. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  7155. WFIFOSET(fd, packet_len(0x205));
  7156. }
  7157. /// Marriage proposal (ZC_REQ_COUPLE).
  7158. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7159. /// This packet while still implemented by the client is no longer being officially used.
  7160. /*
  7161. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7162. {
  7163. nullpo_retv(sd);
  7164. WFIFOHEAD(fd,packet_len(0x1e2));
  7165. WFIFOW(fd,0) = 0x1e2;
  7166. WFIFOL(fd,2) = ssd->status.account_id;
  7167. WFIFOL(fd,6) = ssd->status.char_id;
  7168. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  7169. WFIFOSET(fd, packet_len(0x1e2));
  7170. }
  7171. */
  7172. /*==========================================
  7173. *
  7174. *------------------------------------------*/
  7175. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  7176. {
  7177. clif_disp_message(&sd->bl, mes, len, SELF);
  7178. }
  7179. /*==========================================
  7180. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7181. *------------------------------------------*/
  7182. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7183. {
  7184. unsigned char buf[256];
  7185. if( len == 0 ) {
  7186. return;
  7187. } else if( len > sizeof(buf)-5 ) {
  7188. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7189. len = sizeof(buf)-5;
  7190. }
  7191. WBUFW(buf, 0) = 0x17f;
  7192. WBUFW(buf, 2) = len + 5;
  7193. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  7194. clif_send(buf, WBUFW(buf,2), src, target);
  7195. }
  7196. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7197. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7198. /// 00cd <result>.B
  7199. /// result:
  7200. /// 0 = failure
  7201. /// 1 = success
  7202. void clif_GM_kickack(struct map_session_data *sd, int id)
  7203. {
  7204. int fd;
  7205. nullpo_retv(sd);
  7206. fd = sd->fd;
  7207. WFIFOHEAD(fd,packet_len(0xcd));
  7208. WFIFOW(fd,0) = 0xcd;
  7209. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7210. WFIFOSET(fd, packet_len(0xcd));
  7211. }
  7212. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  7213. {
  7214. int fd = tsd->fd;
  7215. if( fd > 0 )
  7216. clif_authfail_fd(fd, 15);
  7217. else
  7218. map_quit(tsd);
  7219. if( sd )
  7220. clif_GM_kickack(sd,tsd->status.account_id);
  7221. }
  7222. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7223. /// 014a <result>.L
  7224. /// result:
  7225. /// 0 = "A manner point has been successfully aligned."
  7226. /// 1 = MP_FAILURE_EXHAUST
  7227. /// 2 = MP_FAILURE_ALREADY_GIVING
  7228. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7229. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7230. /// 5 = "You got a good point from %s."
  7231. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7232. {
  7233. int fd;
  7234. nullpo_retv(sd);
  7235. fd = sd->fd;
  7236. WFIFOHEAD(fd,packet_len(0x14a));
  7237. WFIFOW(fd,0) = 0x14a;
  7238. WFIFOL(fd,2) = type;
  7239. WFIFOSET(fd, packet_len(0x14a));
  7240. }
  7241. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7242. /// 014b <type>.B <GM name>.24B
  7243. /// type:
  7244. /// 0 = positive (unmute)
  7245. /// 1 = negative (mute)
  7246. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7247. {
  7248. int fd;
  7249. nullpo_retv(sd);
  7250. nullpo_retv(tsd);
  7251. fd = tsd->fd;
  7252. WFIFOHEAD(fd,packet_len(0x14b));
  7253. WFIFOW(fd,0) = 0x14b;
  7254. WFIFOB(fd,2) = type;
  7255. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7256. WFIFOSET(fd, packet_len(0x14b));
  7257. }
  7258. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7259. /// 00d1 <type>.B <result>.B
  7260. /// type:
  7261. /// 0 = /ex (deny)
  7262. /// 1 = /in (allow)
  7263. /// result:
  7264. /// 0 = success
  7265. /// 1 = failure
  7266. /// 2 = too many blocks
  7267. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7268. {
  7269. int fd;
  7270. nullpo_retv(sd);
  7271. fd=sd->fd;
  7272. WFIFOHEAD(fd,packet_len(0xd1));
  7273. WFIFOW(fd,0)=0xd1;
  7274. WFIFOB(fd,2)=type;
  7275. WFIFOB(fd,3)=flag;
  7276. WFIFOSET(fd,packet_len(0xd1));
  7277. }
  7278. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7279. /// 00d2 <type>.B <result>.B
  7280. /// type:
  7281. /// 0 = /exall (deny)
  7282. /// 1 = /inall (allow)
  7283. /// result:
  7284. /// 0 = success
  7285. /// 1 = failure
  7286. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7287. {
  7288. int fd;
  7289. nullpo_retv(sd);
  7290. fd=sd->fd;
  7291. WFIFOHEAD(fd,packet_len(0xd2));
  7292. WFIFOW(fd,0)=0xd2;
  7293. WFIFOB(fd,2)=type;
  7294. WFIFOB(fd,3)=flag;
  7295. WFIFOSET(fd,packet_len(0xd2));
  7296. }
  7297. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7298. /// 07fe <bgm>.24B
  7299. void clif_playBGM(struct map_session_data* sd, const char* name)
  7300. {
  7301. int fd;
  7302. nullpo_retv(sd);
  7303. fd = sd->fd;
  7304. WFIFOHEAD(fd,packet_len(0x7fe));
  7305. WFIFOW(fd,0) = 0x7fe;
  7306. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7307. WFIFOSET(fd,packet_len(0x7fe));
  7308. }
  7309. /// Plays/stops a wave sound (ZC_SOUND).
  7310. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7311. /// file name:
  7312. /// relative to data\wav
  7313. /// act:
  7314. /// 0 = play (once)
  7315. /// 1 = play (repeat, does not work)
  7316. /// 2 = stops all sound instances of file name (does not work)
  7317. /// term:
  7318. /// unknown purpose, only relevant to act = 1
  7319. /// npc id:
  7320. /// The accustic direction of the sound is determined by the
  7321. /// relative position of the NPC to the player (3D sound).
  7322. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7323. {
  7324. int fd;
  7325. nullpo_retv(sd);
  7326. nullpo_retv(bl);
  7327. fd = sd->fd;
  7328. WFIFOHEAD(fd,packet_len(0x1d3));
  7329. WFIFOW(fd,0) = 0x1d3;
  7330. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7331. WFIFOB(fd,26) = type;
  7332. WFIFOL(fd,27) = 0;
  7333. WFIFOL(fd,31) = bl->id;
  7334. WFIFOSET(fd,packet_len(0x1d3));
  7335. }
  7336. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7337. {
  7338. unsigned char buf[40];
  7339. nullpo_retv(bl);
  7340. WBUFW(buf,0) = 0x1d3;
  7341. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7342. WBUFB(buf,26) = type;
  7343. WBUFL(buf,27) = 0;
  7344. WBUFL(buf,31) = bl->id;
  7345. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7346. }
  7347. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7348. /// 01f3 <id>.L <effect id>.L
  7349. /// effect id:
  7350. /// @see doc/effect_list.txt
  7351. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7352. {
  7353. unsigned char buf[24];
  7354. nullpo_retv(bl);
  7355. memset(buf, 0, packet_len(0x1f3));
  7356. WBUFW(buf,0) = 0x1f3;
  7357. WBUFL(buf,2) = bl->id;
  7358. WBUFL(buf,6) = type;
  7359. clif_send(buf, packet_len(0x1f3), bl, target);
  7360. if (disguised(bl)) {
  7361. WBUFL(buf,2) = -bl->id;
  7362. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7363. }
  7364. }
  7365. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7366. {
  7367. WFIFOHEAD(fd,10);
  7368. WFIFOW(fd,0) = 0x1f3;
  7369. WFIFOL(fd,2) = bl->id;
  7370. WFIFOL(fd,6) = type;
  7371. WFIFOSET(fd,10);
  7372. }
  7373. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7374. /// 0284 <id>.L <effect id>.L <num data>.L
  7375. /// effect id:
  7376. /// @see doc/effect_list.txt
  7377. /// num data:
  7378. /// effect-dependent value
  7379. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7380. {
  7381. uint8 buf[14];
  7382. WBUFW(buf,0) = 0x284;
  7383. WBUFL(buf,2) = bl->id;
  7384. WBUFL(buf,6) = effect_id;
  7385. WBUFL(buf,10) = num;
  7386. clif_send(buf, packet_len(0x284), bl, target);
  7387. if( disguised(bl) )
  7388. {
  7389. WBUFL(buf,2) = -bl->id;
  7390. clif_send(buf, packet_len(0x284), bl, SELF);
  7391. }
  7392. }
  7393. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7394. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7395. int clif_colormes(struct map_session_data * sd, unsigned long color, const char* msg) {
  7396. unsigned short msg_len = strlen(msg) + 1;
  7397. WFIFOHEAD(sd->fd,msg_len + 12);
  7398. WFIFOW(sd->fd,0) = 0x2C1;
  7399. WFIFOW(sd->fd,2) = msg_len + 12;
  7400. WFIFOL(sd->fd,4) = 0;
  7401. WFIFOL(sd->fd,8) = color; //either color_table or channel_table
  7402. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7403. WFIFOSET(sd->fd, msg_len + 12);
  7404. return 0;
  7405. }
  7406. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7407. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7408. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7409. unsigned short msg_len = strlen(msg) + 1;
  7410. uint8 buf[256];
  7411. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7412. nullpo_retv(bl);
  7413. if( msg_len > sizeof(buf)-12 ) {
  7414. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7415. msg_len = sizeof(buf)-12;
  7416. }
  7417. WBUFW(buf,0) = 0x2C1;
  7418. WBUFW(buf,2) = msg_len + 12;
  7419. WBUFL(buf,4) = bl->id;
  7420. WBUFL(buf,8) = color;
  7421. memcpy(WBUFP(buf,12), msg, msg_len);
  7422. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7423. }
  7424. /**
  7425. * Notifies the client that the storage window is still open
  7426. *
  7427. * Should only be used in cases where the client closed the
  7428. * storage window without server's consent
  7429. */
  7430. void clif_refresh_storagewindow(struct map_session_data *sd) {
  7431. // Notify the client that the storage is open
  7432. if( sd->state.storage_flag == 1 ) {
  7433. storage_sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7434. clif_storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7435. clif_updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7436. }
  7437. // Notify the client that the gstorage is open otherwise it will
  7438. // remain locked forever and nobody will be able to access it
  7439. if( sd->state.storage_flag == 2 ) {
  7440. struct guild_storage *gstor = guild2storage2(sd->status.guild_id);
  7441. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  7442. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  7443. else {
  7444. storage_sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7445. clif_storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7446. clif_updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7447. }
  7448. }
  7449. }
  7450. // refresh the client's screen, getting rid of any effects
  7451. void clif_refresh(struct map_session_data *sd)
  7452. {
  7453. int i;
  7454. nullpo_retv(sd);
  7455. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7456. clif_inventorylist(sd);
  7457. if(pc_iscarton(sd)) {
  7458. clif_cartlist(sd);
  7459. clif_updatestatus(sd,SP_CARTINFO);
  7460. }
  7461. clif_updatestatus(sd,SP_WEIGHT);
  7462. clif_updatestatus(sd,SP_MAXWEIGHT);
  7463. clif_updatestatus(sd,SP_STR);
  7464. clif_updatestatus(sd,SP_AGI);
  7465. clif_updatestatus(sd,SP_VIT);
  7466. clif_updatestatus(sd,SP_INT);
  7467. clif_updatestatus(sd,SP_DEX);
  7468. clif_updatestatus(sd,SP_LUK);
  7469. if (sd->spiritball)
  7470. clif_spiritball_single(sd->fd, sd);
  7471. for(i = 1; i < 5; i++){
  7472. if( sd->talisman[i] > 0 )
  7473. clif_talisman_single(sd->fd, sd, i);
  7474. }
  7475. if (sd->vd.cloth_color)
  7476. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7477. if(hom_is_active(sd->hd))
  7478. clif_send_homdata(sd,SP_ACK,0);
  7479. if( sd->md ) {
  7480. clif_mercenary_info(sd);
  7481. clif_mercenary_skillblock(sd);
  7482. }
  7483. if( sd->ed )
  7484. clif_elemental_info(sd);
  7485. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7486. clif_weather_check(sd);
  7487. if( sd->chatID )
  7488. chat_leavechat(sd,0);
  7489. if( sd->state.vending )
  7490. clif_openvending(sd, sd->bl.id, sd->vending);
  7491. if( pc_issit(sd) )
  7492. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7493. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7494. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7495. else
  7496. clif_changed_dir(&sd->bl, SELF);
  7497. // unlike vending, resuming buyingstore crashes the client.
  7498. buyingstore_close(sd);
  7499. mail_clear(sd);
  7500. if( disguised(&sd->bl) ) {/* refresh-da */
  7501. short disguise = sd->disguise;
  7502. pc_disguise(sd, 0);
  7503. pc_disguise(sd, disguise);
  7504. }
  7505. clif_refresh_storagewindow(sd);
  7506. }
  7507. /// Updates the object's (bl) name on client.
  7508. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7509. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7510. void clif_charnameack (int fd, struct block_list *bl)
  7511. {
  7512. unsigned char buf[103];
  7513. int cmd = 0x95;
  7514. nullpo_retv(bl);
  7515. WBUFW(buf,0) = cmd;
  7516. WBUFL(buf,2) = bl->id;
  7517. switch( bl->type )
  7518. {
  7519. case BL_PC:
  7520. {
  7521. struct map_session_data *ssd = (struct map_session_data *)bl;
  7522. struct party_data *p = NULL;
  7523. struct guild *g = NULL;
  7524. int ps = -1;
  7525. //Requesting your own "shadow" name. [Skotlex]
  7526. if (ssd->fd == fd && ssd->disguise)
  7527. WBUFL(buf,2) = -bl->id;
  7528. if( ssd->fakename[0] ) {
  7529. WBUFW(buf, 0) = cmd = 0x195;
  7530. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7531. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7532. break;
  7533. }
  7534. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7535. if( ssd->status.party_id ) {
  7536. p = party_search(ssd->status.party_id);
  7537. }
  7538. if( ssd->status.guild_id ) {
  7539. if( ( g = ssd->guild ) != NULL ) {
  7540. int i;
  7541. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7542. if( i < g->max_member ) ps = g->member[i].position;
  7543. }
  7544. }
  7545. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7546. p = NULL;
  7547. }
  7548. if (p == NULL && g == NULL)
  7549. break;
  7550. WBUFW(buf, 0) = cmd = 0x195;
  7551. if (p)
  7552. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7553. else
  7554. WBUFB(buf,30) = 0;
  7555. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7556. {
  7557. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7558. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7559. } else { //Assume no guild.
  7560. WBUFB(buf,54) = 0;
  7561. WBUFB(buf,78) = 0;
  7562. }
  7563. }
  7564. break;
  7565. //[blackhole89]
  7566. case BL_HOM:
  7567. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7568. break;
  7569. case BL_MER:
  7570. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7571. break;
  7572. case BL_PET:
  7573. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7574. break;
  7575. case BL_NPC:
  7576. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7577. break;
  7578. case BL_MOB:
  7579. {
  7580. struct mob_data *md = (struct mob_data *)bl;
  7581. nullpo_retv(md);
  7582. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7583. if( md->guardian_data && md->guardian_data->guild_id )
  7584. {
  7585. WBUFW(buf, 0) = cmd = 0x195;
  7586. WBUFB(buf,30) = 0;
  7587. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7588. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7589. }
  7590. else if( battle_config.show_mob_info )
  7591. {
  7592. char mobhp[50], *str_p = mobhp;
  7593. WBUFW(buf, 0) = cmd = 0x195;
  7594. if( battle_config.show_mob_info&4 )
  7595. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7596. if( battle_config.show_mob_info&1 )
  7597. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7598. if( battle_config.show_mob_info&2 )
  7599. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7600. //Even thought mobhp ain't a name, we send it as one so the client
  7601. //can parse it. [Skotlex]
  7602. if( str_p != mobhp )
  7603. {
  7604. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7605. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7606. WBUFB(buf,54) = 0;
  7607. WBUFB(buf,78) = 0;
  7608. }
  7609. }
  7610. }
  7611. break;
  7612. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7613. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7614. // break;
  7615. return;
  7616. case BL_ELEM:
  7617. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7618. break;
  7619. default:
  7620. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7621. return;
  7622. }
  7623. // if no receipient specified just update nearby clients
  7624. if (fd == 0)
  7625. clif_send(buf, packet_len(cmd), bl, AREA);
  7626. else {
  7627. WFIFOHEAD(fd, packet_len(cmd));
  7628. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7629. WFIFOSET(fd, packet_len(cmd));
  7630. }
  7631. }
  7632. //Used to update when a char leaves a party/guild. [Skotlex]
  7633. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7634. void clif_charnameupdate (struct map_session_data *ssd)
  7635. {
  7636. unsigned char buf[103];
  7637. int cmd = 0x195, ps = -1;
  7638. struct party_data *p = NULL;
  7639. struct guild *g = NULL;
  7640. nullpo_retv(ssd);
  7641. if( ssd->fakename[0] )
  7642. return; //No need to update as the party/guild was not displayed anyway.
  7643. WBUFW(buf,0) = cmd;
  7644. WBUFL(buf,2) = ssd->bl.id;
  7645. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7646. if (!battle_config.display_party_name) {
  7647. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7648. p = party_search(ssd->status.party_id);
  7649. }else{
  7650. if (ssd->status.party_id > 0)
  7651. p = party_search(ssd->status.party_id);
  7652. }
  7653. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7654. {
  7655. int i;
  7656. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7657. if( i < g->max_member ) ps = g->member[i].position;
  7658. }
  7659. if( p )
  7660. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7661. else
  7662. WBUFB(buf,30) = 0;
  7663. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7664. {
  7665. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7666. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7667. }
  7668. else
  7669. {
  7670. WBUFB(buf,54) = 0;
  7671. WBUFB(buf,78) = 0;
  7672. }
  7673. // Update nearby clients
  7674. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7675. }
  7676. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7677. /// 01ff <id>.L <x>.W <y>.W
  7678. ///
  7679. /// Visually moves(instant) a character to x,y. The char moves even
  7680. /// when the target cell isn't walkable. If the char is sitting it
  7681. /// stays that way.
  7682. void clif_slide(struct block_list *bl, int x, int y)
  7683. {
  7684. unsigned char buf[10];
  7685. nullpo_retv(bl);
  7686. WBUFW(buf, 0) = 0x01ff;
  7687. WBUFL(buf, 2) = bl->id;
  7688. WBUFW(buf, 6) = x;
  7689. WBUFW(buf, 8) = y;
  7690. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7691. if( disguised(bl) )
  7692. {
  7693. WBUFL(buf,2) = -bl->id;
  7694. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7695. }
  7696. }
  7697. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7698. /// 008d <packet len>.W <id>.L <message>.?B
  7699. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7700. {
  7701. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7702. int len_mes = strlen(mes)+1; //Account for \0
  7703. if (len_mes > sizeof(buf)-8) {
  7704. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7705. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7706. }
  7707. // send message to others
  7708. WBUFW(buf,0) = 0x8d;
  7709. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7710. WBUFL(buf,4) = bl->id;
  7711. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7712. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7713. // send back message to the speaker
  7714. if( bl->type == BL_PC ) {
  7715. WBUFW(buf,0) = 0x8e;
  7716. WBUFW(buf, 2) = len_mes + 4;
  7717. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7718. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7719. }
  7720. }
  7721. /*==========================
  7722. * Minimap fix [Kevin]
  7723. * Remove dot from minimap
  7724. *--------------------------*/
  7725. void clif_party_xy_remove(struct map_session_data *sd)
  7726. {
  7727. unsigned char buf[16];
  7728. nullpo_retv(sd);
  7729. WBUFW(buf,0)=0x107;
  7730. WBUFL(buf,2)=sd->status.account_id;
  7731. WBUFW(buf,6)=-1;
  7732. WBUFW(buf,8)=-1;
  7733. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7734. }
  7735. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7736. /// 0215 <msg id>.L
  7737. /// msg id:
  7738. /// 0x15 = End all negative status (PA_GOSPEL)
  7739. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7740. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7741. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7742. /// 0x19 = All stats +20 (PA_GOSPEL)
  7743. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7744. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7745. /// 0x1e = DEF +25% (PA_GOSPEL)
  7746. /// 0x1f = ATK +100% (PA_GOSPEL)
  7747. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7748. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7749. /// ? = nothing
  7750. void clif_gospel_info(struct map_session_data *sd, int type)
  7751. {
  7752. int fd=sd->fd;
  7753. WFIFOHEAD(fd,packet_len(0x215));
  7754. WFIFOW(fd,0)=0x215;
  7755. WFIFOL(fd,2)=type;
  7756. WFIFOSET(fd, packet_len(0x215));
  7757. }
  7758. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7759. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7760. /// result:
  7761. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7762. /// star:
  7763. /// 0 = Place of the Sun
  7764. /// 1 = Place of the Moon
  7765. /// 2 = Place of the Stars
  7766. /// 1 = Star Gladiator %s's %s: <mapname>
  7767. /// star:
  7768. /// 0 = Place of the Sun
  7769. /// 1 = Place of the Moon
  7770. /// 2 = Place of the Stars
  7771. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7772. /// star:
  7773. /// 0 = Target of the Sun
  7774. /// 1 = Target of the Moon
  7775. /// 2 = Target of the Stars
  7776. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7777. /// star:
  7778. /// 0 = Monster of the Sun
  7779. /// 1 = Monster of the Moon
  7780. /// 2 = Monster of the Stars
  7781. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7782. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7783. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7784. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7785. /// 40 = Target HP : <monster_id used as HP>
  7786. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7787. {
  7788. int fd = sd->fd;
  7789. WFIFOHEAD(fd,packet_len(0x20e));
  7790. WFIFOW(fd,0) = 0x20e;
  7791. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7792. WFIFOL(fd,26) = monster_id;
  7793. WFIFOB(fd,30) = star;
  7794. WFIFOB(fd,31) = result;
  7795. WFIFOSET(fd,packet_len(0x20e));
  7796. }
  7797. /*==========================================
  7798. * Info about Star Glaldiator save map [Komurka]
  7799. * type: 1: Information, 0: Map registered
  7800. *------------------------------------------*/
  7801. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7802. {
  7803. char mapname[MAP_NAME_LENGTH_EXT];
  7804. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7805. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7806. }
  7807. /*==========================================
  7808. * Info about Star Glaldiator hate mob [Komurka]
  7809. * type: 1: Register mob, 0: Information.
  7810. *------------------------------------------*/
  7811. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7812. {
  7813. if( pcdb_checkid(class_) ) {
  7814. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7815. } else if( mobdb_checkid(class_) ) {
  7816. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7817. } else {
  7818. 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);
  7819. }
  7820. }
  7821. /*==========================================
  7822. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7823. *------------------------------------------*/
  7824. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7825. {
  7826. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7827. }
  7828. /*==========================================
  7829. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7830. *------------------------------------------*/
  7831. void clif_feel_hate_reset(struct map_session_data *sd)
  7832. {
  7833. clif_starskill(sd, "", 0, 0, 30);
  7834. }
  7835. /// Equip window (un)tick ack (ZC_CONFIG).
  7836. /// 02d9 <type>.L <value>.L
  7837. /// type:
  7838. /// 0 = open equip window
  7839. /// value:
  7840. /// 0 = disabled
  7841. /// 1 = enabled
  7842. void clif_equiptickack(struct map_session_data* sd, int flag)
  7843. {
  7844. int fd;
  7845. nullpo_retv(sd);
  7846. fd = sd->fd;
  7847. WFIFOHEAD(fd, packet_len(0x2d9));
  7848. WFIFOW(fd, 0) = 0x2d9;
  7849. WFIFOL(fd, 2) = 0;
  7850. WFIFOL(fd, 6) = flag;
  7851. WFIFOSET(fd, packet_len(0x2d9));
  7852. }
  7853. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7854. /// 02da <open equip window>.B
  7855. /// open equip window:
  7856. /// 0 = disabled
  7857. /// 1 = enabled
  7858. void clif_equipcheckbox(struct map_session_data* sd)
  7859. {
  7860. int fd;
  7861. nullpo_retv(sd);
  7862. fd = sd->fd;
  7863. WFIFOHEAD(fd, packet_len(0x2da));
  7864. WFIFOW(fd, 0) = 0x2da;
  7865. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7866. WFIFOSET(fd, packet_len(0x2da));
  7867. }
  7868. /// Sends info about a player's equipped items.
  7869. /// 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)
  7870. /// 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)
  7871. /// 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)
  7872. /// 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)
  7873. /// 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)
  7874. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7875. {
  7876. uint8* buf;
  7877. int i, n, fd, offset = 0;
  7878. #if PACKETVER < 20100629
  7879. const int s = 26;
  7880. #elif PACKETVER < 20120925
  7881. const int s = 28;
  7882. #else
  7883. const int s = 31;
  7884. #endif
  7885. nullpo_retv(sd);
  7886. nullpo_retv(tsd);
  7887. fd = sd->fd;
  7888. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  7889. buf = WFIFOP(fd,0);
  7890. #if PACKETVER < 20101124
  7891. WBUFW(buf, 0) = 0x2d7;
  7892. #elif PACKETVER < 20120925
  7893. WBUFW(buf, 0) = 0x859;
  7894. #else
  7895. WBUFW(buf, 0) = 0x997;
  7896. #endif
  7897. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7898. WBUFW(buf,28) = tsd->status.class_;
  7899. WBUFW(buf,30) = tsd->vd.hair_style;
  7900. WBUFW(buf,32) = tsd->vd.head_bottom;
  7901. WBUFW(buf,34) = tsd->vd.head_mid;
  7902. WBUFW(buf,36) = tsd->vd.head_top;
  7903. #if PACKETVER >= 20110111
  7904. WBUFW(buf,38) = tsd->vd.robe;
  7905. offset+= 2;
  7906. buf = WBUFP(buf,2);
  7907. #endif
  7908. WBUFW(buf,38) = tsd->vd.hair_color;
  7909. WBUFW(buf,40) = tsd->vd.cloth_color;
  7910. WBUFB(buf,42) = tsd->vd.sex;
  7911. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7912. {
  7913. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7914. continue;
  7915. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7916. continue;
  7917. // Add item info : refine, identify flag, element, etc.
  7918. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7919. n++;
  7920. }
  7921. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7922. WFIFOSET(fd, WFIFOW(fd, 2));
  7923. }
  7924. /// Display msgstringtable.txt string (ZC_MSG).
  7925. /// 0291 <message>.W
  7926. void clif_msg(struct map_session_data* sd, unsigned short id)
  7927. {
  7928. int fd;
  7929. nullpo_retv(sd);
  7930. fd = sd->fd;
  7931. WFIFOHEAD(fd, packet_len(0x291));
  7932. WFIFOW(fd, 0) = 0x291;
  7933. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7934. WFIFOSET(fd, packet_len(0x291));
  7935. }
  7936. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7937. /// 0x7e2 <message>.W <value>.L
  7938. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7939. {
  7940. int fd = sd->fd;
  7941. WFIFOHEAD(fd, packet_len(0x7e2));
  7942. WFIFOW(fd,0) = 0x7e2;
  7943. WFIFOW(fd,2) = id;
  7944. WFIFOL(fd,4) = value;
  7945. WFIFOSET(fd, packet_len(0x7e2));
  7946. }
  7947. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7948. /// 07e6 <skill id>.W <msg id>.L
  7949. ///
  7950. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7951. /// "[SkillName] Message"
  7952. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7953. {
  7954. int fd = sd->fd;
  7955. WFIFOHEAD(fd, packet_len(0x7e6));
  7956. WFIFOW(fd,0) = 0x7e6;
  7957. WFIFOW(fd,2) = skill_id;
  7958. WFIFOL(fd,4) = msg_id;
  7959. WFIFOSET(fd, packet_len(0x7e6));
  7960. }
  7961. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7962. /// Returns true if the packet was parsed successfully.
  7963. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7964. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7965. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7966. {
  7967. char *text, *name, *message;
  7968. unsigned int packetlen, textlen, namelen, messagelen;
  7969. int fd = sd->fd;
  7970. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  7971. *name_ = NULL;
  7972. *namelen_ = 0;
  7973. *message_ = NULL;
  7974. *messagelen_ = 0;
  7975. packetlen = RFIFOW(fd,info->pos[0]);
  7976. // basic structure checks
  7977. if( packetlen < 4 + 1 )
  7978. { // 4-byte header and at least an empty string is expected
  7979. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7980. return false;
  7981. }
  7982. text = (char*)RFIFOP(fd,info->pos[1]);
  7983. textlen = packetlen - 4;
  7984. // process <name> part of the packet
  7985. if( format == 0 )
  7986. {// name and message are separated by ' : '
  7987. // validate name
  7988. name = text;
  7989. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7990. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7991. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7992. {
  7993. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7994. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7995. set_eof(fd); // Just kick them out to correct it.
  7996. return false;
  7997. }
  7998. message = name + namelen + 3;
  7999. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  8000. }
  8001. else
  8002. {// name has fixed width
  8003. if( textlen < NAME_LENGTH + 1 )
  8004. {
  8005. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8006. return false;
  8007. }
  8008. // validate name
  8009. name = text;
  8010. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  8011. if( name[namelen] != '\0' )
  8012. { // only restriction is that the name must be zero-terminated
  8013. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8014. return false;
  8015. }
  8016. message = name + NAME_LENGTH;
  8017. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  8018. }
  8019. if( messagelen != strnlen(message, messagelen)+1 )
  8020. { // the declared length must match real length
  8021. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8022. return false;
  8023. }
  8024. // verify <message> part of the packet
  8025. if( message[messagelen-1] != '\0' )
  8026. { // message must be zero-terminated
  8027. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8028. return false;
  8029. }
  8030. if( messagelen > CHAT_SIZE_MAX-1 )
  8031. { // messages mustn't be too long
  8032. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8033. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8034. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8035. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8036. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8037. return false;
  8038. }
  8039. *name_ = name;
  8040. *namelen_ = namelen;
  8041. *message_ = message;
  8042. *messagelen_ = messagelen;
  8043. return true;
  8044. }
  8045. // ---------------------
  8046. // clif_guess_PacketVer
  8047. // ---------------------
  8048. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8049. // error codes:
  8050. // 0 - Success
  8051. // 1 - Unknown packet_ver
  8052. // 2 - Invalid account_id
  8053. // 3 - Invalid char_id
  8054. // 4 - Invalid login_id1 (reserved)
  8055. // 5 - Invalid client_tick (reserved)
  8056. // 6 - Invalid sex
  8057. // Only the first 'invalid' error that appears is used.
  8058. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  8059. {
  8060. static int err = 1;
  8061. static int packet_ver = -1;
  8062. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  8063. if (get_previous)
  8064. {//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]
  8065. if( error )
  8066. *error = err;
  8067. return packet_ver;
  8068. }
  8069. //By default, start searching on the default one.
  8070. err = 1;
  8071. packet_ver = clif_config.packet_db_ver;
  8072. cmd = RFIFOW(fd,0);
  8073. packet_len = RFIFOREST(fd);
  8074. #define SET_ERROR(n) \
  8075. if( err == 1 )\
  8076. err = n;\
  8077. //define SET_ERROR
  8078. // FIXME: If the packet is not received at once, this will FAIL.
  8079. // Figure out, when it happens, that only part of the packet is
  8080. // received, or fix the function to be able to deal with that
  8081. // case.
  8082. #define CHECK_PACKET_VER() \
  8083. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  8084. ;/* not wanttoconnection or wrong length */\
  8085. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  8086. { SET_ERROR(2); }/* invalid account_id */\
  8087. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  8088. { SET_ERROR(3); }/* invalid char_id */\
  8089. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  8090. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  8091. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  8092. { SET_ERROR(6); }/* invalid sex */\
  8093. else\
  8094. {\
  8095. err = 0;\
  8096. if( error )\
  8097. *error = 0;\
  8098. return packet_ver;\
  8099. }\
  8100. //define CHECK_PACKET_VER
  8101. CHECK_PACKET_VER();//Default packet version found.
  8102. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  8103. CHECK_PACKET_VER();
  8104. }
  8105. if( error )
  8106. *error = err;
  8107. packet_ver = -1;
  8108. return -1;
  8109. #undef SET_ERROR
  8110. #undef CHECK_PACKET_VER
  8111. }
  8112. // ------------
  8113. // clif_parse_*
  8114. // ------------
  8115. // Parses incoming (player) connection
  8116. /// Request to connect to map-server.
  8117. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8118. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8119. /// There are various variants of this packet, some of them have padding between fields.
  8120. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8121. {
  8122. struct block_list* bl;
  8123. struct auth_node* node;
  8124. int cmd, account_id, char_id, login_id1, sex;
  8125. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8126. 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])
  8127. if (sd) {
  8128. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8129. return;
  8130. }
  8131. // Only valid packet version get here
  8132. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  8133. cmd = RFIFOW(fd,0);
  8134. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  8135. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  8136. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  8137. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  8138. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  8139. if( packet_ver < 5 || // reject really old client versions
  8140. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  8141. (packet_ver > 9 && packet_ver <40 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) || // version not allowed
  8142. (packet_ver >= 40 && packet_ver <=72 && (battle_config.packet_ver_flag2 & 1<<(packet_ver-40)) == 0) )
  8143. {// packet version rejected
  8144. 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));
  8145. WFIFOHEAD(fd,packet_len(0x6a));
  8146. WFIFOW(fd,0) = 0x6a;
  8147. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  8148. WFIFOSET(fd,packet_len(0x6a));
  8149. set_eof(fd);
  8150. return;
  8151. }
  8152. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8153. clif_authfail_fd(fd,1);// server closed
  8154. return;
  8155. }
  8156. //Check for double login.
  8157. bl = map_id2bl(account_id);
  8158. if(bl && bl->type != BL_PC) {
  8159. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8160. WFIFOHEAD(fd,packet_len(0x6a));
  8161. WFIFOW(fd,0) = 0x6a;
  8162. WFIFOB(fd,2) = 3; // Rejected by server
  8163. WFIFOSET(fd,packet_len(0x6a));
  8164. set_eof(fd);
  8165. return;
  8166. }
  8167. if (bl ||
  8168. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8169. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8170. {
  8171. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8172. return;
  8173. }
  8174. CREATE(sd, TBL_PC, 1);
  8175. sd->fd = fd;
  8176. sd->packet_ver = packet_ver;
  8177. session[fd]->session_data = sd;
  8178. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8179. #if PACKETVER < 20070521
  8180. WFIFOHEAD(fd,4);
  8181. WFIFOL(fd,0) = sd->bl.id;
  8182. WFIFOSET(fd,4);
  8183. #else
  8184. WFIFOHEAD(fd,packet_len(0x283));
  8185. WFIFOW(fd,0) = 0x283;
  8186. WFIFOL(fd,2) = sd->bl.id;
  8187. WFIFOSET(fd,packet_len(0x283));
  8188. #endif
  8189. chrif_authreq(sd,false);
  8190. }
  8191. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8192. /// 007d
  8193. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8194. {
  8195. int i;
  8196. bool guild_notice = false;
  8197. if(sd->bl.prev != NULL)
  8198. return;
  8199. if (!sd->state.active) { //Character loading is not complete yet!
  8200. //Let pc_reg_received reinvoke this when ready.
  8201. sd->state.connect_new = 0;
  8202. return;
  8203. }
  8204. if (sd->state.rewarp) { //Rewarp player.
  8205. sd->state.rewarp = 0;
  8206. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8207. return;
  8208. }
  8209. sd->state.warping = 0;
  8210. // look
  8211. #if PACKETVER < 4
  8212. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8213. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8214. #else
  8215. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8216. #endif
  8217. if(sd->vd.cloth_color)
  8218. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8219. // item
  8220. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8221. pc_checkitem(sd);
  8222. // cart
  8223. if(pc_iscarton(sd)) {
  8224. clif_cartlist(sd);
  8225. clif_updatestatus(sd,SP_CARTINFO);
  8226. }
  8227. // weight
  8228. clif_updatestatus(sd,SP_WEIGHT);
  8229. clif_updatestatus(sd,SP_MAXWEIGHT);
  8230. // guild
  8231. // (needs to go before clif_spawn() to show guild emblems correctly)
  8232. if(sd->status.guild_id)
  8233. guild_send_memberinfoshort(sd,1);
  8234. if(battle_config.pc_invincible_time > 0) {
  8235. if(map_flag_gvg(sd->bl.m))
  8236. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8237. else
  8238. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8239. }
  8240. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8241. map_spawnmobs(sd->bl.m);
  8242. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  8243. map[sd->bl.m].users_pvp++;
  8244. }
  8245. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8246. // reset the callshop flag if the player changes map
  8247. sd->state.callshop = 0;
  8248. if(map_addblock(&sd->bl))
  8249. return;
  8250. clif_spawn(&sd->bl);
  8251. // Party
  8252. // (needs to go after clif_spawn() to show hp bars correctly)
  8253. if(sd->status.party_id) {
  8254. party_send_movemap(sd);
  8255. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8256. }
  8257. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8258. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  8259. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8260. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8261. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8262. sd->pvp_rank = 0;
  8263. sd->pvp_lastusers = 0;
  8264. sd->pvp_point = 5;
  8265. sd->pvp_won = 0;
  8266. sd->pvp_lost = 0;
  8267. }
  8268. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8269. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8270. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8271. if (map[sd->bl.m].flag.gvg_dungeon)
  8272. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8273. if( map_flag_gvg(sd->bl.m) )
  8274. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  8275. // info about nearby objects
  8276. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8277. 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);
  8278. // pet
  8279. if( sd->pd ) {
  8280. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8281. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8282. pet_menu(sd, 3); //Option 3 is return to egg.
  8283. } else {
  8284. if(map_addblock(&sd->pd->bl))
  8285. return;
  8286. clif_spawn(&sd->pd->bl);
  8287. clif_send_petdata(sd,sd->pd,0,0);
  8288. clif_send_petstatus(sd);
  8289. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8290. }
  8291. }
  8292. //homunculus [blackhole89]
  8293. if( hom_is_active(sd->hd) ) {
  8294. if(map_addblock(&sd->hd->bl))
  8295. return;
  8296. clif_spawn(&sd->hd->bl);
  8297. clif_send_homdata(sd,SP_ACK,0);
  8298. clif_hominfo(sd,sd->hd,1);
  8299. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8300. clif_homskillinfoblock(sd);
  8301. if( battle_config.hom_setting&0x8 )
  8302. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8303. if( !(battle_config.hom_setting&0x2) )
  8304. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8305. }
  8306. if( sd->md ) {
  8307. if(map_addblock(&sd->md->bl))
  8308. return;
  8309. clif_spawn(&sd->md->bl);
  8310. clif_mercenary_info(sd);
  8311. clif_mercenary_skillblock(sd);
  8312. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8313. }
  8314. if( sd->ed ) {
  8315. map_addblock(&sd->ed->bl);
  8316. clif_spawn(&sd->ed->bl);
  8317. clif_elemental_info(sd);
  8318. clif_elemental_updatestatus(sd,SP_HP);
  8319. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8320. clif_elemental_updatestatus(sd,SP_SP);
  8321. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8322. }
  8323. if(sd->state.connect_new) {
  8324. int lv;
  8325. guild_notice = true;
  8326. sd->state.connect_new = 0;
  8327. clif_skillinfoblock(sd);
  8328. clif_hotkeys_send(sd);
  8329. clif_updatestatus(sd,SP_BASEEXP);
  8330. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8331. clif_updatestatus(sd,SP_JOBEXP);
  8332. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8333. clif_updatestatus(sd,SP_SKILLPOINT);
  8334. clif_initialstatus(sd);
  8335. if (sd->sc.option&OPTION_FALCON)
  8336. clif_status_load(&sd->bl, SI_FALCON, 1);
  8337. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8338. clif_status_load(&sd->bl, SI_RIDING, 1);
  8339. else if (sd->sc.option&OPTION_WUGRIDER)
  8340. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8341. else if (sd->sc.data[SC_ALL_RIDING])
  8342. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8343. if(sd->status.manner < 0)
  8344. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8345. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8346. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8347. if(sd->bl.m == sd->feel_map[0].m
  8348. || sd->bl.m == sd->feel_map[1].m
  8349. || sd->bl.m == sd->feel_map[2].m)
  8350. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8351. }
  8352. if(sd->pd && sd->pd->pet.intimate > 900)
  8353. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8354. if(hom_is_active(sd->hd))
  8355. hom_init_timers(sd->hd);
  8356. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8357. sd->state.night = 1;
  8358. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8359. }
  8360. // Notify everyone that this char logged in [Skotlex].
  8361. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8362. // Set the initial idle time
  8363. sd->idletime = last_tick;
  8364. //Login Event
  8365. npc_script_event(sd, NPCE_LOGIN);
  8366. } else {
  8367. //For some reason the client "loses" these on warp/map-change.
  8368. clif_updatestatus(sd,SP_STR);
  8369. clif_updatestatus(sd,SP_AGI);
  8370. clif_updatestatus(sd,SP_VIT);
  8371. clif_updatestatus(sd,SP_INT);
  8372. clif_updatestatus(sd,SP_DEX);
  8373. clif_updatestatus(sd,SP_LUK);
  8374. // abort currently running script
  8375. sd->state.using_fake_npc = 0;
  8376. sd->state.menu_or_input = 0;
  8377. sd->npc_menu = 0;
  8378. if(sd->npc_id)
  8379. npc_event_dequeue(sd);
  8380. }
  8381. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8382. #if PACKETVER >= 20070918
  8383. clif_partyinvitationstate(sd);
  8384. clif_equipcheckbox(sd);
  8385. #endif
  8386. #ifdef VIP_ENABLE
  8387. if (!sd->disableshowrate) {
  8388. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  8389. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  8390. }
  8391. #endif
  8392. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8393. clif_guild_notice(sd, sd->guild); // Displays after VIP
  8394. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8395. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8396. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8397. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8398. { //Display night.
  8399. if( !sd->state.night )
  8400. {
  8401. sd->state.night = 1;
  8402. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8403. }
  8404. }
  8405. else if( sd->state.night )
  8406. { //Clear night display.
  8407. sd->state.night = 0;
  8408. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8409. }
  8410. if( map[sd->bl.m].flag.battleground )
  8411. {
  8412. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8413. if( map[sd->bl.m].flag.battleground == 2 )
  8414. clif_bg_updatescore_single(sd);
  8415. }
  8416. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8417. {
  8418. char output[128];
  8419. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8420. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8421. }
  8422. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8423. map[sd->bl.m].hpmeter_visible++;
  8424. sd->state.hpmeter_visible = 1;
  8425. }
  8426. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8427. status_calc_pc(sd, SCO_NONE); // Some conditions are map-dependent so we must recalculate
  8428. sd->state.changemap = false;
  8429. // Instances do not need their own channels
  8430. if( Channel_Config.map_enable && Channel_Config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  8431. channel_mjoin(sd); //join new map
  8432. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  8433. clif_guild_notice(sd, sd->guild); // Displays at end
  8434. mail_clear(sd);
  8435. clif_maptypeproperty2(&sd->bl,SELF);
  8436. /* Guild Aura Init */
  8437. if( sd->state.gmaster_flag ) {
  8438. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  8439. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  8440. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  8441. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  8442. }
  8443. if( sd->state.vending ) { /* show we have a vending */
  8444. clif_openvending(sd,sd->bl.id,sd->vending);
  8445. clif_showvendingboard(&sd->bl,sd->message,0);
  8446. }
  8447. if(map[sd->bl.m].flag.loadevent) // Lance
  8448. npc_script_event(sd, NPCE_LOADMAP);
  8449. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8450. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8451. if (sd->sc.opt2) //Client loses these on warp.
  8452. clif_changeoption(&sd->bl);
  8453. if (sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  8454. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8455. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  8456. }
  8457. clif_weather_check(sd);
  8458. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8459. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8460. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8461. else
  8462. sd->areanpc_id = 0;
  8463. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8464. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8465. pc_setdead(sd);
  8466. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8467. if(pc_isdead(sd))
  8468. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8469. else {
  8470. skill_usave_trigger(sd);
  8471. clif_changed_dir(&sd->bl, SELF);
  8472. }
  8473. // Trigger skill effects if you appear standing on them
  8474. if(!battle_config.pc_invincible_time)
  8475. skill_unit_move(&sd->bl,gettick(),1);
  8476. // NPC Quest / Event Icon Check [Kisuka]
  8477. #if PACKETVER >= 20090218
  8478. for(i = 0; i < map[sd->bl.m].qi_count; i++) {
  8479. struct questinfo *qi = &map[sd->bl.m].qi_data[i];
  8480. if( quest_check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8481. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8482. if( sd->class_ == qi->job )
  8483. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8484. } else {
  8485. clif_quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8486. }
  8487. }
  8488. }
  8489. #endif
  8490. }
  8491. /// Server's tick (ZC_NOTIFY_TIME).
  8492. /// 007f <time>.L
  8493. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8494. {
  8495. int fd = sd->fd;
  8496. WFIFOHEAD(fd,packet_len(0x7f));
  8497. WFIFOW(fd,0) = 0x7f;
  8498. WFIFOL(fd,2) = time;
  8499. WFIFOSET(fd,packet_len(0x7f));
  8500. }
  8501. /// Request for server's tick.
  8502. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8503. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8504. /// There are various variants of this packet, some of them have padding between fields.
  8505. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8506. {
  8507. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8508. clif_notify_time(sd, gettick());
  8509. }
  8510. /// Sends hotkey bar.
  8511. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8512. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8513. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8514. void clif_hotkeys_send(struct map_session_data *sd) {
  8515. #ifdef HOTKEY_SAVING
  8516. const int fd = sd->fd;
  8517. int i;
  8518. #if PACKETVER < 20090603
  8519. const int cmd = 0x2b9;
  8520. #else
  8521. const int cmd = 0x7d9;
  8522. #endif
  8523. if (!fd) return;
  8524. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8525. WFIFOW(fd, 0) = cmd;
  8526. for(i = 0; i < MAX_HOTKEYS; i++) {
  8527. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8528. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8529. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8530. }
  8531. WFIFOSET(fd, packet_len(cmd));
  8532. #endif
  8533. }
  8534. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8535. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8536. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8537. #ifdef HOTKEY_SAVING
  8538. unsigned short idx;
  8539. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8540. idx = RFIFOW(fd, info->pos[0]);
  8541. if (idx >= MAX_HOTKEYS) return;
  8542. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  8543. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  8544. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  8545. #endif
  8546. }
  8547. /// Displays cast-like progress bar (ZC_PROGRESS).
  8548. /// 02f0 <color>.L <time>.L
  8549. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8550. {
  8551. int fd = sd->fd;
  8552. WFIFOHEAD(fd,packet_len(0x2f0));
  8553. WFIFOW(fd,0) = 0x2f0;
  8554. WFIFOL(fd,2) = color;
  8555. WFIFOL(fd,6) = second;
  8556. WFIFOSET(fd,packet_len(0x2f0));
  8557. }
  8558. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8559. /// 02f2
  8560. void clif_progressbar_abort(struct map_session_data * sd)
  8561. {
  8562. int fd = sd->fd;
  8563. WFIFOHEAD(fd,packet_len(0x2f2));
  8564. WFIFOW(fd,0) = 0x2f2;
  8565. WFIFOSET(fd,packet_len(0x2f2));
  8566. }
  8567. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8568. /// 02f1
  8569. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8570. {
  8571. int npc_id = sd->progressbar.npc_id;
  8572. if( gettick() < sd->progressbar.timeout && sd->st )
  8573. sd->st->state = END;
  8574. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8575. npc_scriptcont(sd, npc_id, false);
  8576. }
  8577. /// Request to walk to a certain position on the current map.
  8578. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8579. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8580. /// There are various variants of this packet, some of them have padding between fields.
  8581. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8582. {
  8583. short x, y;
  8584. if (pc_isdead(sd)) {
  8585. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8586. return;
  8587. }
  8588. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8589. ; //You CAN walk on this OPT1 value.
  8590. else if( sd->progressbar.npc_id )
  8591. clif_progressbar_abort(sd);
  8592. else if (pc_cant_act(sd))
  8593. return;
  8594. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8595. return;
  8596. // Cloaking wall check is actually updated when you click to process next movement
  8597. // not when you move each cell. This is official behaviour.
  8598. if (sd->sc.data[SC_CLOAKING])
  8599. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  8600. pc_delinvincibletimer(sd);
  8601. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8602. //Set last idle time... [Skotlex]
  8603. sd->idletime = last_tick;
  8604. unit_walktoxy(&sd->bl, x, y, 4);
  8605. }
  8606. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8607. /// 018b <result>.W
  8608. /// result:
  8609. /// 0 = disconnect (quit)
  8610. /// 1 = cannot disconnect (wait 10 seconds)
  8611. /// ? = ignored
  8612. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8613. {
  8614. int fd = sd->fd;
  8615. WFIFOHEAD(fd,packet_len(0x18b));
  8616. WFIFOW(fd,0) = 0x18b;
  8617. WFIFOW(fd,2) = result;
  8618. WFIFOSET(fd,packet_len(0x18b));
  8619. }
  8620. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8621. /// 018a <type>.W
  8622. /// type:
  8623. /// 0 = quit
  8624. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8625. {
  8626. /* Rovert's prevent logout option fixed [Valaris] */
  8627. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8628. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8629. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8630. {
  8631. set_eof(fd);
  8632. pc_damage_log_clear(sd,0);
  8633. clif_disconnect_ack(sd, 0);
  8634. } else {
  8635. clif_disconnect_ack(sd, 1);
  8636. }
  8637. }
  8638. /// Requesting unit's name.
  8639. /// 0094 <id>.L (CZ_REQNAME)
  8640. /// 0368 <id>.L (CZ_REQNAME2)
  8641. /// There are various variants of this packet, some of them have padding between fields.
  8642. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8643. {
  8644. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8645. struct block_list* bl;
  8646. //struct status_change *sc;
  8647. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8648. id = sd->bl.id;
  8649. bl = map_id2bl(id);
  8650. if( bl == NULL )
  8651. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8652. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8653. return; // Block namerequests past view range
  8654. // 'see people in GM hide' cheat detection
  8655. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8656. sc = status_get_sc(bl);
  8657. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8658. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8659. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8660. ) {
  8661. char gm_msg[256];
  8662. 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);
  8663. ShowWarning(gm_msg);
  8664. // information is sent to all online GMs
  8665. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8666. return;
  8667. }
  8668. */
  8669. clif_charnameack(fd, bl);
  8670. }
  8671. /// Validates and processes global messages
  8672. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8673. /// There are various variants of this packet.
  8674. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8675. {
  8676. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8677. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  8678. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  8679. char *name, *message, *fakename = NULL;
  8680. int namelen, messagelen;
  8681. bool is_fake;
  8682. // validate packet and retrieve name and message
  8683. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8684. return;
  8685. if( is_atcommand(fd, sd, message, 1) )
  8686. return;
  8687. if (sd->sc.cant.chat)
  8688. return; //no "chatting" while muted.
  8689. if( battle_config.min_chat_delay ) { //[Skotlex]
  8690. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8691. return;
  8692. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8693. }
  8694. if( sd->gcbind ) {
  8695. channel_send(sd->gcbind,sd,message);
  8696. return;
  8697. }
  8698. /**
  8699. * Fake Name Design by FatalEror (bug report #9)
  8700. **/
  8701. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8702. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8703. strcpy(fakename, sd->fakename);
  8704. strcat(fakename, " : ");
  8705. strcat(fakename, message);
  8706. textlen = strlen(fakename) + 1;
  8707. }
  8708. // send message to others (using the send buffer for temp. storage)
  8709. clif_GlobalMessage(&sd->bl,is_fake ? fakename : text,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8710. // send back message to the speaker
  8711. if( is_fake ) {
  8712. WFIFOW(fd,0) = 0x8e;
  8713. WFIFOW(fd,2) = textlen + 4;
  8714. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8715. aFree(fakename);
  8716. } else {
  8717. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,info->pos[0]));
  8718. WFIFOW(fd,0) = 0x8e;
  8719. }
  8720. WFIFOSET(fd, WFIFOW(fd,2));
  8721. #ifdef PCRE_SUPPORT
  8722. // trigger listening npcs
  8723. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8724. #endif
  8725. // Reset idle time when using normal chat.
  8726. sd->idletime = last_tick;
  8727. // Chat logging type 'O' / Global Chat
  8728. 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);
  8729. }
  8730. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8731. /// Request to warp to a map on given coordinates.
  8732. /// 0140 <map name>.16B <x>.W <y>.W
  8733. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8734. {
  8735. char command[MAP_NAME_LENGTH_EXT+25];
  8736. char* map_name;
  8737. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8738. map_name = (char*)RFIFOP(fd,info->pos[0]);
  8739. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8740. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  8741. RFIFOW(fd,info->pos[1]), //x
  8742. RFIFOW(fd,info->pos[2])); //y
  8743. is_atcommand(fd, sd, command, 1);
  8744. }
  8745. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8746. /// 009c <id>.L <head dir>.W <dir>.B
  8747. /// head dir:
  8748. /// 0 = straight
  8749. /// 1 = turned CW
  8750. /// 2 = turned CCW
  8751. /// dir:
  8752. /// 0 = north
  8753. /// 1 = northwest
  8754. /// 2 = west
  8755. /// 3 = southwest
  8756. /// 4 = south
  8757. /// 5 = southeast
  8758. /// 6 = east
  8759. /// 7 = northeast
  8760. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8761. {
  8762. unsigned char buf[64];
  8763. WBUFW(buf,0) = 0x9c;
  8764. WBUFL(buf,2) = bl->id;
  8765. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8766. WBUFB(buf,8) = unit_getdir(bl);
  8767. clif_send(buf, packet_len(0x9c), bl, target);
  8768. if (disguised(bl)) {
  8769. WBUFL(buf,2) = -bl->id;
  8770. WBUFW(buf,6) = 0;
  8771. clif_send(buf, packet_len(0x9c), bl, SELF);
  8772. }
  8773. }
  8774. /// Request to change own body and head direction.
  8775. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8776. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8777. /// There are various variants of this packet, some of them have padding between fields.
  8778. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8779. {
  8780. unsigned char headdir, dir;
  8781. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8782. headdir = RFIFOB(fd,info->pos[0]);
  8783. dir = RFIFOB(fd,info->pos[1]);
  8784. pc_setdir(sd, dir, headdir);
  8785. clif_changed_dir(&sd->bl, AREA_WOS);
  8786. }
  8787. /// Request to show an emotion (CZ_REQ_EMOTION).
  8788. /// 00bf <type>.B
  8789. /// type:
  8790. /// @see enum emotion_type
  8791. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8792. {
  8793. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8794. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8795. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8796. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8797. return;
  8798. }
  8799. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8800. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8801. sd->emotionlasttime = time(NULL);
  8802. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8803. return;
  8804. }
  8805. sd->emotionlasttime = time(NULL);
  8806. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8807. emoticon = rnd()%6+E_DICE1;
  8808. }
  8809. clif_emotion(&sd->bl, emoticon);
  8810. } else
  8811. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8812. }
  8813. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8814. /// 00c2 <count>.L
  8815. void clif_user_count(struct map_session_data* sd, int count)
  8816. {
  8817. int fd = sd->fd;
  8818. WFIFOHEAD(fd,packet_len(0xc2));
  8819. WFIFOW(fd,0) = 0xc2;
  8820. WFIFOL(fd,2) = count;
  8821. WFIFOSET(fd,packet_len(0xc2));
  8822. }
  8823. /// /w /who (CZ_REQ_USER_COUNT).
  8824. /// Request to display amount of currently connected players.
  8825. /// 00c1
  8826. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8827. {
  8828. clif_user_count(sd, map_getusers());
  8829. }
  8830. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8831. {
  8832. if (pc_isdead(sd)) {
  8833. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8834. return;
  8835. }
  8836. if (sd->sc.count &&
  8837. (sd->sc.data[SC_TRICKDEAD] ||
  8838. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  8839. sd->sc.data[SC_BLADESTOP] ||
  8840. sd->sc.data[SC__MANHOLE] ||
  8841. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8842. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8843. return;
  8844. pc_stop_walking(sd, 1);
  8845. pc_stop_attack(sd);
  8846. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8847. target_id = sd->bl.id;
  8848. switch(action_type)
  8849. {
  8850. case 0x00: // once attack
  8851. case 0x07: // continuous attack
  8852. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8853. return;
  8854. if( sd->sc.option&OPTION_COSTUME )
  8855. return;
  8856. if( sd->sc.option&OPTION_COSTUME )
  8857. return;
  8858. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8859. return;
  8860. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8861. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8862. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8863. return;
  8864. }
  8865. }
  8866. pc_delinvincibletimer(sd);
  8867. sd->idletime = last_tick;
  8868. unit_attack(&sd->bl, target_id, action_type != 0);
  8869. break;
  8870. case 0x02: // sitdown
  8871. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8872. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8873. break;
  8874. }
  8875. if(pc_issit(sd)) {
  8876. //Bugged client? Just refresh them.
  8877. clif_sitting(&sd->bl);
  8878. return;
  8879. }
  8880. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8881. break;
  8882. if (sd->sc.count && (
  8883. sd->sc.data[SC_DANCING] ||
  8884. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8885. )) //No sitting during these states either.
  8886. break;
  8887. sd->idletime = last_tick;
  8888. skill_sit(sd, 1);
  8889. pc_setsit(sd);
  8890. clif_sitting(&sd->bl);
  8891. break;
  8892. case 0x03: // standup
  8893. if (!pc_issit(sd)) {
  8894. //Bugged client? Just refresh them.
  8895. clif_standing(&sd->bl);
  8896. return;
  8897. }
  8898. sd->idletime = last_tick;
  8899. pc_setstand(sd);
  8900. skill_sit(sd, 0);
  8901. clif_standing(&sd->bl);
  8902. break;
  8903. }
  8904. }
  8905. /// Request for an action.
  8906. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8907. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8908. /// action:
  8909. /// 0 = attack
  8910. /// 1 = pick up item
  8911. /// 2 = sit down
  8912. /// 3 = stand up
  8913. /// 7 = continous attack
  8914. /// 12 = (touch skill?)
  8915. /// There are various variants of this packet, some of them have padding between fields.
  8916. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8917. {
  8918. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  8919. clif_parse_ActionRequest_sub(sd,
  8920. RFIFOB(fd,info->pos[1]),
  8921. RFIFOL(fd,info->pos[0]),
  8922. gettick()
  8923. );
  8924. }
  8925. /// Response to the death/system menu (CZ_RESTART).
  8926. /// 00b2 <type>.B
  8927. /// type:
  8928. /// 0 = restart (respawn)
  8929. /// 1 = char-select (disconnect)
  8930. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8931. {
  8932. switch(RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])) {
  8933. case 0x00:
  8934. pc_respawn(sd,CLR_OUTSIGHT);
  8935. break;
  8936. case 0x01:
  8937. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8938. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8939. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8940. { //Send to char-server for character selection.
  8941. pc_damage_log_clear(sd,0);
  8942. chrif_charselectreq(sd, session[fd]->client_addr);
  8943. } else {
  8944. clif_disconnect_ack(sd, 1);
  8945. }
  8946. break;
  8947. }
  8948. }
  8949. /// Validates and processes whispered messages (CZ_WHISPER).
  8950. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8951. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8952. {
  8953. struct map_session_data* dstsd;
  8954. int i;
  8955. char *target, *message;
  8956. int namelen, messagelen;
  8957. // validate packet and retrieve name and message
  8958. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8959. return;
  8960. if ( is_atcommand(fd, sd, message, 1) )
  8961. return;
  8962. if (sd->sc.cant.chat)
  8963. return; //no "chatting" while muted.
  8964. if (battle_config.min_chat_delay) { //[Skotlex]
  8965. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8966. return;
  8967. }
  8968. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8969. }
  8970. // Reset idle time when using whisper/main chat.
  8971. sd->idletime = last_tick;
  8972. // Chat logging type 'W' / Whisper
  8973. 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);
  8974. //-------------------------------------------------------//
  8975. // Lordalfa - Paperboy - To whisper NPC commands //
  8976. //-------------------------------------------------------//
  8977. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8978. {
  8979. char* str = target+4; //Skip the NPC: string part.
  8980. struct npc_data* npc;
  8981. if ((npc = npc_name2id(str))) {
  8982. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8983. char *split;
  8984. char output[256];
  8985. str = message;
  8986. // skip codepage indicator, if detected
  8987. if( str[0] == '|' && strlen(str) >= 4 )
  8988. str += 3;
  8989. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8990. split = strchr(str,'#');
  8991. if( split == NULL ) { // use the remaining string
  8992. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8993. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8994. split_data[i][0] = '\0';
  8995. break;
  8996. }
  8997. *split = '\0';
  8998. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8999. str = split+1;
  9000. }
  9001. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9002. safesnprintf(output,sizeof(output),"@whispervar%d$", i);
  9003. set_var(sd,output,(char *) split_data[i]);
  9004. }
  9005. safesnprintf(output,sizeof(output),"%s::OnWhisperGlobal", npc->exname);
  9006. npc_event(sd,output,0); // Calls the NPC label
  9007. return;
  9008. }
  9009. } else if( target[0] == '#' ) {
  9010. struct Channel *channel = NULL;
  9011. char* chname = target;
  9012. channel = channel_name2channel(chname,sd,3);
  9013. if(channel){
  9014. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9015. channel_send(channel,sd,message);
  9016. }
  9017. else if( channel->pass[0] == '\0') { //no pass needed
  9018. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  9019. }
  9020. else {
  9021. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9022. }
  9023. return;
  9024. }
  9025. }
  9026. // searching destination character
  9027. dstsd = map_nick2sd(target);
  9028. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9029. // player is not on this map-server
  9030. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9031. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9032. // and if we ask for 'Test', we must not contact 'test' player
  9033. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9034. intif_wis_message(sd, target, message, messagelen);
  9035. return;
  9036. }
  9037. // if player ignores everyone
  9038. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9039. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9040. clif_wis_end(fd, 1); // 1: target character is not logged in
  9041. else
  9042. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9043. return;
  9044. }
  9045. // if player is autotrading
  9046. if (dstsd->state.autotrade == 1) {
  9047. char output[256];
  9048. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9049. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9050. return;
  9051. }
  9052. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9053. // if player ignores the source character
  9054. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9055. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9056. clif_wis_end(fd, 2); // 2: ignored by target
  9057. return;
  9058. }
  9059. }
  9060. // notify sender of success
  9061. clif_wis_end(fd, 0); // 0: success to send wisper
  9062. // Normal message
  9063. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  9064. }
  9065. /// /b /nb (CZ_BROADCAST).
  9066. /// Request to broadcast a message on whole server.
  9067. /// 0099 <packet len>.W <text>.?B 00
  9068. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9069. char command[CHAT_SIZE_MAX+11];
  9070. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9071. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9072. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  9073. // as the length varies depending on the command used, just block unreasonably long strings
  9074. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9075. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9076. is_atcommand(fd, sd, command, 1);
  9077. }
  9078. /// Request to pick up an item.
  9079. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9080. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9081. /// There are various variants of this packet, some of them have padding between fields.
  9082. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9083. {
  9084. struct flooritem_data *fitem;
  9085. int map_object_id;
  9086. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9087. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9088. do {
  9089. if (pc_isdead(sd)) {
  9090. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9091. break;
  9092. }
  9093. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9094. break;
  9095. if (pc_cant_act(sd))
  9096. break;
  9097. if (!pc_takeitem(sd, fitem))
  9098. break;
  9099. return;
  9100. } while (0);
  9101. // Client REQUIRES a fail packet or you can no longer pick items.
  9102. clif_additem(sd,0,0,6);
  9103. }
  9104. /// Request to drop an item.
  9105. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9106. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9107. /// There are various variants of this packet, some of them have padding between fields.
  9108. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9109. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9110. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9111. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9112. for(;;) {
  9113. if (pc_isdead(sd))
  9114. break;
  9115. if (pc_cant_act2(sd) || sd->npc_id)
  9116. break;
  9117. if (sd->sc.count && (
  9118. sd->sc.data[SC_AUTOCOUNTER] ||
  9119. sd->sc.data[SC_BLADESTOP] ||
  9120. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9121. ))
  9122. break;
  9123. if (!pc_dropitem(sd, item_index, item_amount))
  9124. break;
  9125. return;
  9126. }
  9127. //Because the client does not like being ignored.
  9128. clif_dropitem(sd, item_index,0);
  9129. }
  9130. /// Request to use an item.
  9131. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9132. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9133. /// There are various variants of this packet, some of them have padding between fields.
  9134. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9135. {
  9136. int n;
  9137. if (pc_isdead(sd)) {
  9138. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9139. return;
  9140. }
  9141. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9142. return;
  9143. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9144. sd->idletime = last_tick;
  9145. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9146. if(n <0 || n >= MAX_INVENTORY)
  9147. return;
  9148. if (!pc_useitem(sd,n))
  9149. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9150. }
  9151. /// Request to equip an item
  9152. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9153. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9154. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9155. {
  9156. int index;
  9157. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9158. if(pc_isdead(sd)) {
  9159. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9160. return;
  9161. }
  9162. index = RFIFOW(fd,info->pos[0])-2;
  9163. if (index < 0 || index >= MAX_INVENTORY)
  9164. return; //Out of bounds check.
  9165. if(sd->npc_id && !sd->npc_item_flag) {
  9166. return;
  9167. } else if (sd->state.storage_flag || sd->sc.opt1)
  9168. ; //You can equip/unequip stuff while storage is open/under status changes
  9169. else if (pc_cant_act2(sd))
  9170. return;
  9171. if(!sd->status.inventory[index].identify) {
  9172. clif_equipitemack(sd,index,0,0); // fail
  9173. return;
  9174. }
  9175. if(!sd->inventory_data[index])
  9176. return;
  9177. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9178. pet_equipitem(sd,index);
  9179. return;
  9180. }
  9181. //Client doesn't send the position for ammo.
  9182. if(sd->inventory_data[index]->type == IT_AMMO)
  9183. pc_equipitem(sd,index,EQP_AMMO);
  9184. else {
  9185. int req_pos;
  9186. #if PACKETVER >= 20120925
  9187. req_pos = RFIFOL(fd,info->pos[1]);
  9188. #else
  9189. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9190. #endif
  9191. pc_equipitem(sd,index,req_pos);
  9192. }
  9193. }
  9194. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9195. /// 00ab <index>.W
  9196. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9197. {
  9198. int index;
  9199. if(pc_isdead(sd)) {
  9200. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9201. return;
  9202. }
  9203. if (sd->npc_id && !sd->npc_item_flag) {
  9204. return;
  9205. } else if (sd->state.storage_flag || sd->sc.opt1)
  9206. ; //You can equip/unequip stuff while storage is open/under status changes
  9207. else if (pc_cant_act2(sd))
  9208. return;
  9209. index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9210. pc_unequipitem(sd,index,1);
  9211. }
  9212. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9213. /// 0090 <id>.L <type>.B
  9214. /// type:
  9215. /// 1 = click
  9216. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9217. {
  9218. struct block_list *bl;
  9219. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9220. if(pc_isdead(sd)) {
  9221. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9222. return;
  9223. }
  9224. if (pc_cant_act2(sd) || sd->npc_id)
  9225. return;
  9226. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9227. //type = RFIFOB(fd,info->pos[1]);
  9228. if (!bl) return;
  9229. switch (bl->type) {
  9230. case BL_MOB:
  9231. case BL_PC:
  9232. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9233. break;
  9234. case BL_NPC:
  9235. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9236. npc_click(sd,(TBL_NPC*)bl);
  9237. break;
  9238. }
  9239. }
  9240. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9241. /// 00c5 <id>.L <type>.B
  9242. /// type:
  9243. /// 0 = buy
  9244. /// 1 = sell
  9245. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9246. {
  9247. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9248. if (sd->state.trading)
  9249. return;
  9250. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9251. }
  9252. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9253. /// 00ca <result>.B
  9254. /// result:
  9255. /// 0 = "The deal has successfully completed."
  9256. /// 1 = "You do not have enough zeny."
  9257. /// 2 = "You are over your Weight Limit."
  9258. /// 3 = "Out of the maximum capacity, you have too many items."
  9259. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9260. {
  9261. int fd = sd->fd;
  9262. WFIFOHEAD(fd,packet_len(0xca));
  9263. WFIFOW(fd,0) = 0xca;
  9264. WFIFOB(fd,2) = result;
  9265. WFIFOSET(fd,packet_len(0xca));
  9266. }
  9267. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9268. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9269. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9270. {
  9271. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9272. int n = (RFIFOW(fd,info->pos[0])-4) /4;
  9273. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9274. int result;
  9275. if( sd->state.trading || !sd->npc_shopid )
  9276. result = 1;
  9277. else
  9278. result = npc_buylist(sd,n,item_list);
  9279. sd->npc_shopid = 0; //Clear shop data.
  9280. clif_npc_buy_result(sd, result);
  9281. }
  9282. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9283. /// 00cb <result>.B
  9284. /// result:
  9285. /// 0 = "The deal has successfully completed."
  9286. /// 1 = "The deal has failed."
  9287. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9288. {
  9289. int fd = sd->fd;
  9290. WFIFOHEAD(fd,packet_len(0xcb));
  9291. WFIFOW(fd,0) = 0xcb;
  9292. WFIFOB(fd,2) = result;
  9293. WFIFOSET(fd,packet_len(0xcb));
  9294. }
  9295. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9296. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9297. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9298. {
  9299. int fail=0,n;
  9300. unsigned short *item_list;
  9301. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9302. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9303. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9304. if (sd->state.trading || !sd->npc_shopid)
  9305. fail = 1;
  9306. else
  9307. fail = npc_selllist(sd,n,item_list);
  9308. sd->npc_shopid = 0; //Clear shop data.
  9309. clif_npc_sell_result(sd, fail);
  9310. }
  9311. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9312. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9313. /// type:
  9314. /// 0 = private
  9315. /// 1 = public
  9316. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9317. {
  9318. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9319. int len = RFIFOW(fd,info->pos[0])-15;
  9320. int limit = RFIFOW(fd,info->pos[1]);
  9321. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9322. const char* password = (char*)RFIFOP(fd,info->pos[3]); //not zero-terminated
  9323. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9324. char s_password[CHATROOM_PASS_SIZE];
  9325. char s_title[CHATROOM_TITLE_SIZE];
  9326. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9327. return;
  9328. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  9329. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9330. return;
  9331. }
  9332. if( npc_isnear(&sd->bl) ) {
  9333. // uncomment to send msg_txt.
  9334. //char output[150];
  9335. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9336. //clif_displaymessage(sd->fd, output);
  9337. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9338. return;
  9339. }
  9340. if( len <= 0 )
  9341. return; // invalid input
  9342. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9343. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9344. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9345. }
  9346. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9347. /// 00d9 <chat ID>.L <passwd>.8B
  9348. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9349. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9350. int chatid = RFIFOL(fd,info->pos[0]);
  9351. const char* password = (char*)RFIFOP(fd,info->pos[1]); // not zero-terminated
  9352. chat_joinchat(sd,chatid,password);
  9353. }
  9354. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9355. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9356. /// type:
  9357. /// 0 = private
  9358. /// 1 = public
  9359. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9360. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9361. int len = RFIFOW(fd,info->pos[0])-15;
  9362. int limit = RFIFOW(fd,info->pos[1]);
  9363. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9364. const char* password = (char*)RFIFOP(fd,info->pos[3]); // not zero-terminated
  9365. const char* title = (char*)RFIFOP(fd,info->pos[4]); // not zero-terminated
  9366. char s_password[CHATROOM_PASS_SIZE];
  9367. char s_title[CHATROOM_TITLE_SIZE];
  9368. if( len <= 0 )
  9369. return; // invalid input
  9370. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9371. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9372. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  9373. }
  9374. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9375. /// 00e0 <role>.L <nick>.24B
  9376. /// role:
  9377. /// 0 = owner
  9378. /// 1 = normal
  9379. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9380. {
  9381. //int role = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9382. chat_changechatowner(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]));
  9383. }
  9384. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9385. /// 00e2 <name>.24B
  9386. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9387. {
  9388. chat_kickchat(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9389. }
  9390. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9391. /// 00e3
  9392. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9393. {
  9394. chat_leavechat(sd,0);
  9395. }
  9396. //Handles notifying asker and rejecter of what has just ocurred.
  9397. //Type is used to determine the correct msg_txt to use:
  9398. //0:
  9399. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  9400. {
  9401. const char* msg;
  9402. char output[256];
  9403. // Your request has been rejected by autoreject option.
  9404. msg = msg_txt(sd,392);
  9405. clif_disp_onlyself(sd, msg, strlen(msg));
  9406. //Notice that a request was rejected.
  9407. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  9408. clif_disp_onlyself(tsd, output, strlen(output));
  9409. }
  9410. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9411. /// 00e4 <account id>.L
  9412. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  9413. {
  9414. struct map_session_data *t_sd;
  9415. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9416. if(!sd->chatID && pc_cant_act(sd))
  9417. return; //You can trade while in a chatroom.
  9418. // @noask [LuzZza]
  9419. if(t_sd && t_sd->state.noask) {
  9420. clif_noask_sub(sd, t_sd, 0);
  9421. return;
  9422. }
  9423. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  9424. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9425. return;
  9426. }
  9427. trade_traderequest(sd,t_sd);
  9428. }
  9429. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9430. /// 00e6 <result>.B
  9431. /// result:
  9432. /// 3 = accepted
  9433. /// 4 = rejected
  9434. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9435. {
  9436. trade_tradeack(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9437. }
  9438. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9439. /// 00e8 <index>.W <amount>.L
  9440. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9441. {
  9442. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9443. short index = RFIFOW(fd,info->pos[0]);
  9444. int amount = RFIFOL(fd,info->pos[1]);
  9445. if( index == 0 )
  9446. trade_tradeaddzeny(sd, amount);
  9447. else
  9448. trade_tradeadditem(sd, index, (short)amount);
  9449. }
  9450. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9451. /// 00eb
  9452. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9453. {
  9454. trade_tradeok(sd);
  9455. }
  9456. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9457. /// 00ed
  9458. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9459. {
  9460. trade_tradecancel(sd);
  9461. }
  9462. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9463. /// 00ef
  9464. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9465. {
  9466. trade_tradecommit(sd);
  9467. }
  9468. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9469. /// 0118
  9470. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9471. {
  9472. pc_stop_attack(sd);
  9473. }
  9474. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9475. /// 0126 <index>.W <amount>.L
  9476. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9477. {
  9478. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9479. if (pc_istrading(sd))
  9480. return;
  9481. if (!pc_iscarton(sd))
  9482. return;
  9483. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9484. }
  9485. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9486. /// 0127 <index>.W <amount>.L
  9487. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9488. {
  9489. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9490. if (!pc_iscarton(sd))
  9491. return;
  9492. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  9493. }
  9494. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  9495. /// 012a
  9496. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9497. {
  9498. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  9499. #ifdef NEW_CARTS
  9500. && sd->sc.data[SC_PUSH_CART] )
  9501. pc_setcart(sd,0);
  9502. #else
  9503. )
  9504. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  9505. #endif
  9506. else // priority to remove this option before we can clear cart
  9507. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9508. }
  9509. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9510. /// 01af <num>.W
  9511. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9512. {// TODO: State tracking?
  9513. int type;
  9514. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  9515. return;
  9516. type = (int)RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9517. #ifdef NEW_CARTS
  9518. if( (type == 9 && sd->status.base_level > 131) ||
  9519. (type == 8 && sd->status.base_level > 121) ||
  9520. (type == 7 && sd->status.base_level > 111) ||
  9521. (type == 6 && sd->status.base_level > 101) ||
  9522. (type == 5 && sd->status.base_level > 90) ||
  9523. (type == 4 && sd->status.base_level > 80) ||
  9524. (type == 3 && sd->status.base_level > 65) ||
  9525. (type == 2 && sd->status.base_level > 40) ||
  9526. (type == 1))
  9527. #else
  9528. if( (type == 5 && sd->status.base_level > 90) ||
  9529. (type == 4 && sd->status.base_level > 80) ||
  9530. (type == 3 && sd->status.base_level > 65) ||
  9531. (type == 2 && sd->status.base_level > 40) ||
  9532. (type == 1))
  9533. #endif
  9534. pc_setcart(sd,type);
  9535. }
  9536. /// Request to increase status (CZ_STATUS_CHANGE).
  9537. /// 00bb <status id>.W <amount>.B
  9538. /// status id:
  9539. /// SP_STR ~ SP_LUK
  9540. /// amount:
  9541. /// Old clients always send 1 for this, even when using /str+ and the like.
  9542. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9543. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9544. {
  9545. int increase_amount = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9546. if( increase_amount < 0 ) {
  9547. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9548. fd, increase_amount);
  9549. }
  9550. pc_statusup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),increase_amount);
  9551. }
  9552. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9553. /// 0112 <skill id>.W
  9554. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9555. {
  9556. pc_skillup(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9557. }
  9558. 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)
  9559. {
  9560. int lv;
  9561. if( !hd )
  9562. return;
  9563. if( skill_isNotOk_hom(skill_id, hd) )
  9564. return;
  9565. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9566. target_id = hd->bl.id;
  9567. if( hd->ud.skilltimer != INVALID_TIMER )
  9568. {
  9569. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9570. }
  9571. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9572. return;
  9573. lv = hom_checkskill(hd, skill_id);
  9574. if( skill_lv > lv )
  9575. skill_lv = lv;
  9576. if( skill_lv )
  9577. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9578. }
  9579. 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)
  9580. {
  9581. int lv;
  9582. if( !hd )
  9583. return;
  9584. if( skill_isNotOk_hom(skill_id, hd) )
  9585. return;
  9586. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9587. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9588. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9589. return;
  9590. if( hd->sc.data[SC_BASILICA] )
  9591. return;
  9592. lv = hom_checkskill(hd, skill_id);
  9593. if( skill_lv > lv )
  9594. skill_lv = lv;
  9595. if( skill_lv )
  9596. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9597. }
  9598. 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)
  9599. {
  9600. int lv;
  9601. if( !md )
  9602. return;
  9603. if( skill_isNotOk_mercenary(skill_id, md) )
  9604. return;
  9605. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9606. target_id = md->bl.id;
  9607. if( md->ud.skilltimer != INVALID_TIMER )
  9608. {
  9609. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9610. }
  9611. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9612. return;
  9613. lv = mercenary_checkskill(md, skill_id);
  9614. if( skill_lv > lv )
  9615. skill_lv = lv;
  9616. if( skill_lv )
  9617. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9618. }
  9619. 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)
  9620. {
  9621. int lv;
  9622. if( !md )
  9623. return;
  9624. if( skill_isNotOk_mercenary(skill_id, md) )
  9625. return;
  9626. if( md->ud.skilltimer != INVALID_TIMER )
  9627. return;
  9628. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9629. {
  9630. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9631. return;
  9632. }
  9633. if( md->sc.data[SC_BASILICA] )
  9634. return;
  9635. lv = mercenary_checkskill(md, skill_id);
  9636. if( skill_lv > lv )
  9637. skill_lv = lv;
  9638. if( skill_lv )
  9639. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9640. }
  9641. /// Request to use a targeted skill.
  9642. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9643. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9644. /// There are various variants of this packet, some of them have padding between fields.
  9645. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9646. {
  9647. uint16 skill_id, skill_lv;
  9648. int tmp, target_id;
  9649. unsigned int tick = gettick();
  9650. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9651. skill_lv = RFIFOW(fd,info->pos[0]);
  9652. skill_id = RFIFOW(fd,info->pos[1]);
  9653. target_id = RFIFOL(fd,info->pos[2]);
  9654. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9655. tmp = skill_get_inf(skill_id);
  9656. if (tmp&INF_GROUND_SKILL || !tmp)
  9657. return; //Using a ground/passive skill on a target? WRONG.
  9658. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9659. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9660. return;
  9661. }
  9662. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9663. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9664. return;
  9665. }
  9666. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9667. sd->idletime = last_tick;
  9668. if( sd->npc_id ){
  9669. #ifdef RENEWAL
  9670. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9671. return;
  9672. #else
  9673. if( !sd->npc_item_flag || !(tmp&INF_SELF_SKILL) )
  9674. return;
  9675. #endif
  9676. }
  9677. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  9678. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  9679. sd->state.storage_flag && !(tmp&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  9680. return;
  9681. if( pc_issit(sd) )
  9682. return;
  9683. if( skill_isNotOk(skill_id, sd) )
  9684. return;
  9685. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9686. target_id = sd->bl.id; // never trust the client
  9687. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9688. target_id = sd->bl.id;
  9689. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9690. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9691. return;
  9692. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9693. if( sd->skillitem != skill_id ) {
  9694. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9695. return;
  9696. }
  9697. }
  9698. if( sd->sc.option&OPTION_COSTUME )
  9699. return;
  9700. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9701. return; // On basilica only caster can use Basilica again to stop it.
  9702. if( sd->menuskill_id ) {
  9703. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9704. clif_menuskill_clear(sd); //Cancel pet capture.
  9705. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9706. return; //Can't use skills while a menu is open.
  9707. }
  9708. if( sd->skillitem == skill_id ) {
  9709. if( skill_lv != sd->skillitemlv )
  9710. skill_lv = sd->skillitemlv;
  9711. if( !(tmp&INF_SELF_SKILL) )
  9712. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9713. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9714. return;
  9715. }
  9716. sd->skillitem = sd->skillitemlv = 0;
  9717. if( skill_id >= GD_SKILLBASE ) {
  9718. if( sd->state.gmaster_flag )
  9719. skill_lv = guild_checkskill(sd->guild, skill_id);
  9720. else
  9721. skill_lv = 0;
  9722. } else {
  9723. tmp = pc_checkskill(sd, skill_id);
  9724. if( skill_lv > tmp )
  9725. skill_lv = tmp;
  9726. }
  9727. pc_delinvincibletimer(sd);
  9728. if( skill_lv )
  9729. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9730. }
  9731. /*==========================================
  9732. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9733. *------------------------------------------*/
  9734. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9735. {
  9736. unsigned int tick = gettick();
  9737. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9738. return; //Using a target skill on the ground? WRONG.
  9739. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9740. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9741. return;
  9742. }
  9743. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9744. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9745. return;
  9746. }
  9747. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9748. sd->idletime = last_tick;
  9749. if( skill_isNotOk(skill_id, sd) )
  9750. return;
  9751. if( skillmoreinfo != -1 ) {
  9752. if( pc_issit(sd) ) {
  9753. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9754. return;
  9755. }
  9756. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9757. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9758. }
  9759. if( sd->ud.skilltimer != INVALID_TIMER )
  9760. return;
  9761. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9762. if( sd->skillitem != skill_id ) {
  9763. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9764. return;
  9765. }
  9766. }
  9767. if( sd->sc.option&OPTION_COSTUME )
  9768. return;
  9769. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9770. return; // On basilica only caster can use Basilica again to stop it.
  9771. if( sd->menuskill_id ) {
  9772. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9773. clif_menuskill_clear(sd); //Cancel pet capture.
  9774. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9775. return; //Can't use skills while a menu is open.
  9776. }
  9777. pc_delinvincibletimer(sd);
  9778. if( sd->skillitem == skill_id ) {
  9779. if( skill_lv != sd->skillitemlv )
  9780. skill_lv = sd->skillitemlv;
  9781. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9782. } else {
  9783. int lv;
  9784. sd->skillitem = sd->skillitemlv = 0;
  9785. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9786. if( skill_lv > lv )
  9787. skill_lv = lv;
  9788. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9789. }
  9790. }
  9791. }
  9792. /// Request to use a ground skill.
  9793. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9794. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9795. /// There are various variants of this packet, some of them have padding between fields.
  9796. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9797. {
  9798. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9799. if (pc_cant_act(sd))
  9800. return;
  9801. if (pc_issit(sd))
  9802. return;
  9803. clif_parse_UseSkillToPosSub(fd, sd,
  9804. RFIFOW(fd,info->pos[0]), //skill lv
  9805. RFIFOW(fd,info->pos[1]), //skill num
  9806. RFIFOW(fd,info->pos[2]), //pos x
  9807. RFIFOW(fd,info->pos[3]), //pos y
  9808. -1 //Skill more info.
  9809. );
  9810. }
  9811. /// Request to use a ground skill with text.
  9812. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9813. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9814. /// There are various variants of this packet, some of them have padding between fields.
  9815. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9816. {
  9817. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9818. if (pc_cant_act(sd))
  9819. return;
  9820. if (pc_issit(sd))
  9821. return;
  9822. clif_parse_UseSkillToPosSub(fd, sd,
  9823. RFIFOW(fd,info->pos[0]), //Skill lv
  9824. RFIFOW(fd,info->pos[1]), //Skill num
  9825. RFIFOW(fd,info->pos[2]), //pos x
  9826. RFIFOW(fd,info->pos[3]), //pos y
  9827. info->pos[4] //skill more info
  9828. );
  9829. }
  9830. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9831. /// 011b <skill id>.W <map name>.16B
  9832. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9833. {
  9834. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9835. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  9836. char map_name[MAP_NAME_LENGTH];
  9837. mapindex_getmapname((char*)RFIFOP(fd,info->pos[1]), map_name);
  9838. if(skill_id != sd->menuskill_id)
  9839. return;
  9840. //It is possible to use teleport with the storage window open bugreport:8027
  9841. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  9842. clif_menuskill_clear(sd);
  9843. return;
  9844. }
  9845. pc_delinvincibletimer(sd);
  9846. skill_castend_map(sd,skill_id,map_name);
  9847. }
  9848. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9849. /// 011d
  9850. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9851. {
  9852. if (!pc_isdead(sd))
  9853. pc_memo(sd,-1);
  9854. }
  9855. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9856. /// 018e <name id>.W { <material id>.W }*3
  9857. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  9858. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9859. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  9860. int slot1 = RFIFOW(fd,info->pos[1]);
  9861. int slot2 = RFIFOW(fd,info->pos[2]);
  9862. int slot3 = RFIFOW(fd,info->pos[3]);
  9863. switch( sd->menuskill_id ) {
  9864. case -1:
  9865. case AM_PHARMACY:
  9866. case RK_RUNEMASTERY:
  9867. case GC_RESEARCHNEWPOISON:
  9868. break;
  9869. default:
  9870. return;
  9871. }
  9872. if (pc_istrading(sd)) {
  9873. //Make it fail to avoid shop exploits where you sell something different than you see.
  9874. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9875. clif_menuskill_clear(sd);
  9876. return;
  9877. }
  9878. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1) )
  9879. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3, 1);
  9880. clif_menuskill_clear(sd);
  9881. }
  9882. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9883. /// 025b <mk type>.W <name id>.W
  9884. /// mk type:
  9885. /// 1 = cooking
  9886. /// 2 = arrow
  9887. /// 3 = elemental
  9888. /// 4 = GN_MIX_COOKING
  9889. /// 5 = GN_MAKEBOMB
  9890. /// 6 = GN_S_PHARMACY
  9891. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9892. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9893. int type = RFIFOW(fd,info->pos[0]);
  9894. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  9895. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9896. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9897. return;
  9898. if (pc_istrading(sd)) {
  9899. //Make it fail to avoid shop exploits where you sell something different than you see.
  9900. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9901. clif_menuskill_clear(sd);
  9902. return;
  9903. }
  9904. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9905. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9906. clif_menuskill_clear(sd);
  9907. }
  9908. /// Answer to repair weapon item selection dialog
  9909. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  9910. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  9911. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9912. {
  9913. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9914. return;
  9915. if (pc_istrading(sd)) {
  9916. //Make it fail to avoid shop exploits where you sell something different than you see.
  9917. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9918. clif_menuskill_clear(sd);
  9919. return;
  9920. }
  9921. skill_repairweapon(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  9922. //nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9923. //refine = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9924. //for(i = 0; i<MAX_SLOTS; i++)
  9925. // card[i] = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3+i]);
  9926. clif_menuskill_clear(sd);
  9927. }
  9928. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9929. /// 0222 <index>.L
  9930. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9931. {
  9932. int idx;
  9933. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9934. return;
  9935. if (pc_istrading(sd)) {
  9936. //Make it fail to avoid shop exploits where you sell something different than you see.
  9937. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9938. clif_menuskill_clear(sd);
  9939. return;
  9940. }
  9941. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9942. skill_weaponrefine(sd, idx-2);
  9943. clif_menuskill_clear(sd);
  9944. }
  9945. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9946. /// 00b8 <npc id>.L <choice>.B
  9947. /// choice:
  9948. /// 1~254 = menu item
  9949. /// 255 = cancel
  9950. /// NOTE: If there were more than 254 items in the list, choice
  9951. /// overflows to choice%256.
  9952. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  9953. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9954. int npc_id = RFIFOL(fd,info->pos[0]);
  9955. uint8 select = RFIFOB(fd,info->pos[1]);
  9956. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9957. #ifdef SECURE_NPCTIMEOUT
  9958. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9959. #endif
  9960. TBL_NPC* nd = map_id2nd(npc_id);
  9961. 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);
  9962. clif_GM_kick(NULL,sd);
  9963. #ifdef SECURE_NPCTIMEOUT
  9964. }
  9965. #endif
  9966. return;
  9967. }
  9968. sd->npc_menu = select;
  9969. npc_scriptcont(sd,npc_id, false);
  9970. }
  9971. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9972. /// 00b9 <npc id>.L
  9973. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9974. {
  9975. npc_scriptcont(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), false);
  9976. }
  9977. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9978. /// 0143 <npc id>.L <value>.L
  9979. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  9980. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9981. int npcid = RFIFOL(fd,info->pos[0]);
  9982. int amount = (int)RFIFOL(fd,info->pos[1]);
  9983. sd->npc_amount = amount;
  9984. npc_scriptcont(sd, npcid, false);
  9985. }
  9986. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9987. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9988. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  9989. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  9990. int message_len = RFIFOW(fd,info->pos[0])-8;
  9991. int npcid = RFIFOL(fd,info->pos[1]);
  9992. const char* message = (char*)RFIFOP(fd,info->pos[2]);
  9993. if( message_len <= 0 )
  9994. return; // invalid input
  9995. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9996. npc_scriptcont(sd, npcid, false);
  9997. }
  9998. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9999. /// 0146 <npc id>.L
  10000. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10001. {
  10002. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10003. return;
  10004. npc_scriptcont(sd, RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), true);
  10005. }
  10006. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10007. /// 0178 <index>.W
  10008. /// index:
  10009. /// -1 = cancel
  10010. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  10011. {
  10012. short idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10013. if (sd->menuskill_id != MC_IDENTIFY)
  10014. return;
  10015. if( idx == -1 ) {// cancel pressed
  10016. clif_menuskill_clear(sd);
  10017. return;
  10018. }
  10019. skill_identify(sd,idx-2);
  10020. clif_menuskill_clear(sd);
  10021. }
  10022. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10023. /// 01ae <name id>.W
  10024. void clif_parse_SelectArrow(int fd,struct map_session_data *sd){
  10025. unsigned short nameid = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10026. if (pc_istrading(sd)) {
  10027. //Make it fail to avoid shop exploits where you sell something different than you see.
  10028. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10029. clif_menuskill_clear(sd);
  10030. return;
  10031. }
  10032. switch( sd->menuskill_id ) {
  10033. case AC_MAKINGARROW:
  10034. skill_arrow_create(sd,nameid);
  10035. break;
  10036. case SA_CREATECON:
  10037. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0, 1);
  10038. break;
  10039. case WL_READING_SB:
  10040. skill_spellbook(sd,nameid);
  10041. break;
  10042. case GC_POISONINGWEAPON:
  10043. skill_poisoningweapon(sd,nameid);
  10044. break;
  10045. case NC_MAGICDECOY:
  10046. skill_magicdecoy(sd,nameid);
  10047. break;
  10048. }
  10049. clif_menuskill_clear(sd);
  10050. }
  10051. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10052. /// 01ce <skill id>.L
  10053. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10054. {
  10055. if (sd->menuskill_id != SA_AUTOSPELL)
  10056. return;
  10057. skill_autospell(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10058. clif_menuskill_clear(sd);
  10059. }
  10060. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10061. /// 017a <card index>.W
  10062. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10063. {
  10064. if (sd->state.trading != 0)
  10065. return;
  10066. clif_use_card(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10067. }
  10068. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10069. /// 017c <card index>.W <equip index>.W
  10070. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10071. {
  10072. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10073. if (sd->state.trading != 0)
  10074. return;
  10075. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10076. }
  10077. /// Request of character's name by char ID.
  10078. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10079. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10080. /// There are various variants of this packet, some of them have padding between fields.
  10081. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10082. {
  10083. int charid;
  10084. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10085. map_reqnickdb(sd, charid);
  10086. }
  10087. /// /resetskill /resetstate (CZ_RESET).
  10088. /// Request to reset stats or skills.
  10089. /// 0197 <type>.W
  10090. /// type:
  10091. /// 0 = state
  10092. /// 1 = skill
  10093. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10094. char cmd[15];
  10095. if( RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) )
  10096. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10097. else
  10098. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10099. is_atcommand(fd, sd, cmd, 1);
  10100. }
  10101. /// /lb /nlb (CZ_LOCALBROADCAST).
  10102. /// Request to broadcast a message on current map.
  10103. /// 019c <packet len>.W <text>.?B
  10104. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10105. {
  10106. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10107. char command[CHAT_SIZE_MAX+16];
  10108. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10109. char* msg = (char*)RFIFOP(fd,info->pos[1]);
  10110. // as the length varies depending on the command used, just block unreasonably long strings
  10111. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10112. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10113. is_atcommand(fd, sd, command, 1);
  10114. }
  10115. /// Request to move an item from inventory to storage.
  10116. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10117. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10118. /// There are various variants of this packet, some of them have padding between fields.
  10119. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10120. {
  10121. int item_index, item_amount;
  10122. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10123. if (pc_istrading(sd))
  10124. return;
  10125. item_index = RFIFOW(fd,info->pos[0])-2;
  10126. item_amount = RFIFOL(fd,info->pos[1]);
  10127. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10128. return;
  10129. if (sd->state.storage_flag == 1)
  10130. storage_storageadd(sd, item_index, item_amount);
  10131. else
  10132. if (sd->state.storage_flag == 2)
  10133. storage_guild_storageadd(sd, item_index, item_amount);
  10134. }
  10135. /// Request to move an item from storage to inventory.
  10136. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10137. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10138. /// There are various variants of this packet, some of them have padding between fields.
  10139. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10140. {
  10141. int item_index, item_amount;
  10142. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10143. item_index = RFIFOW(fd,info->pos[0])-1;
  10144. item_amount = RFIFOL(fd,info->pos[1]);
  10145. if (sd->state.storage_flag == 1)
  10146. storage_storageget(sd, item_index, item_amount);
  10147. else if(sd->state.storage_flag == 2)
  10148. storage_guild_storageget(sd, item_index, item_amount);
  10149. }
  10150. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10151. /// 0129 <index>.W <amount>.L
  10152. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10153. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10154. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10155. int amount = RFIFOL(fd,info->pos[1]);
  10156. if( sd->state.vending )
  10157. return;
  10158. if (!pc_iscarton(sd))
  10159. return;
  10160. if (sd->state.storage_flag == 1)
  10161. storage_storageaddfromcart(sd, idx, amount);
  10162. else if (sd->state.storage_flag == 2)
  10163. storage_guild_storageaddfromcart(sd, idx, amount);
  10164. }
  10165. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10166. /// 0128 <index>.W <amount>.L
  10167. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10168. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10169. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10170. int amount = RFIFOL(fd,info->pos[1]);
  10171. if( sd->state.vending )
  10172. return;
  10173. if (!pc_iscarton(sd))
  10174. return;
  10175. if (sd->state.storage_flag == 1)
  10176. storage_storagegettocart(sd, idx, amount);
  10177. else
  10178. if (sd->state.storage_flag == 2)
  10179. storage_guild_storagegettocart(sd, idx, amount);
  10180. }
  10181. /// Request to close storage (CZ_CLOSE_STORE).
  10182. /// 00f7
  10183. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10184. {
  10185. if( sd->state.storage_flag == 1 )
  10186. storage_storageclose(sd);
  10187. else
  10188. if( sd->state.storage_flag == 2 )
  10189. storage_guild_storageclose(sd);
  10190. }
  10191. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10192. /// 023a <info>.W
  10193. /// info:
  10194. /// 0 = password has not been set yet
  10195. /// 1 = storage is password-protected
  10196. /// 8 = too many wrong passwords
  10197. /// ? = ignored
  10198. /// NOTE: This packet is only available on certain non-kRO clients.
  10199. void clif_storagepassword(struct map_session_data* sd, short info)
  10200. {
  10201. int fd = sd->fd;
  10202. WFIFOHEAD(fd,packet_len(0x23a));
  10203. WFIFOW(fd,0) = 0x23a;
  10204. WFIFOW(fd,2) = info;
  10205. WFIFOSET(fd,packet_len(0x23a));
  10206. }
  10207. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10208. /// 023b <type>.W <password>.16B <new password>.16B
  10209. /// type:
  10210. /// 2 = change password
  10211. /// 3 = check password
  10212. /// NOTE: This packet is only available on certain non-kRO clients.
  10213. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10214. // struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10215. // int type = RFIFOW(fd,info->pos[0]);
  10216. // char* password = RFIFOP(fd,info->pos[1]);
  10217. // char* new_password = RFIFOP(fd,info->pos[2]);
  10218. // storage_changepass(sd,password,new_password);
  10219. }
  10220. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10221. /// 023c <result>.W <error count>.W
  10222. /// result:
  10223. /// 4 = password change success
  10224. /// 5 = password change failure
  10225. /// 6 = password check success
  10226. /// 7 = password check failure
  10227. /// 8 = too many wrong passwords
  10228. /// ? = ignored
  10229. /// NOTE: This packet is only available on certain non-kRO clients.
  10230. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10231. {
  10232. int fd = sd->fd;
  10233. WFIFOHEAD(fd,packet_len(0x23c));
  10234. WFIFOW(fd,0) = 0x23c;
  10235. WFIFOW(fd,2) = result;
  10236. WFIFOW(fd,4) = error_count;
  10237. WFIFOSET(fd,packet_len(0x23c));
  10238. }
  10239. /// Party creation request
  10240. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10241. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10242. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10243. name[NAME_LENGTH-1] = '\0';
  10244. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10245. clif_displaymessage(fd, msg_txt(sd,227));
  10246. return;
  10247. }
  10248. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10249. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10250. return;
  10251. }
  10252. party_create(sd,name,0,0);
  10253. }
  10254. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10255. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10256. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10257. char* name = (char*)RFIFOP(fd,info->pos[0]);
  10258. int item1 = RFIFOB(fd,info->pos[1]);
  10259. int item2 = RFIFOB(fd,info->pos[2]);
  10260. name[NAME_LENGTH-1] = '\0';
  10261. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10262. clif_displaymessage(fd, msg_txt(sd,227));
  10263. return;
  10264. }
  10265. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  10266. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10267. return;
  10268. }
  10269. party_create(sd,name,item1,item2);
  10270. }
  10271. /// Party invitation request
  10272. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10273. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10274. {
  10275. struct map_session_data *t_sd;
  10276. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10277. clif_displaymessage(fd, msg_txt(sd,227));
  10278. return;
  10279. }
  10280. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10281. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10282. clif_noask_sub(sd, t_sd, 1);
  10283. return;
  10284. }
  10285. party_invite(sd, t_sd);
  10286. }
  10287. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10288. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  10289. struct map_session_data *t_sd;
  10290. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10291. name[NAME_LENGTH-1] = '\0';
  10292. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10293. clif_displaymessage(fd, msg_txt(sd,227));
  10294. return;
  10295. }
  10296. t_sd = map_nick2sd(name);
  10297. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10298. clif_noask_sub(sd, t_sd, 1);
  10299. return;
  10300. }
  10301. party_invite(sd, t_sd);
  10302. }
  10303. /// Party invitation reply
  10304. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10305. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10306. /// flag:
  10307. /// 0 = reject
  10308. /// 1 = accept
  10309. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10310. {
  10311. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10312. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10313. RFIFOL(fd,info->pos[1]));
  10314. }
  10315. //(CZ_PARTY_JOIN_REQ_ACK)
  10316. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10317. {
  10318. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10319. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10320. RFIFOB(fd,info->pos[1]));
  10321. }
  10322. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10323. /// 0100
  10324. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  10325. {
  10326. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10327. clif_displaymessage(fd, msg_txt(sd,227));
  10328. return;
  10329. }
  10330. party_leave(sd);
  10331. }
  10332. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10333. /// 0103 <account id>.L <char name>.24B
  10334. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  10335. {
  10336. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10337. if(map[sd->bl.m].flag.partylock) {// Party locked.
  10338. clif_displaymessage(fd, msg_txt(sd,227));
  10339. return;
  10340. }
  10341. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  10342. (char*)RFIFOP(fd,info->pos[1]));
  10343. }
  10344. /// Request to change party options.
  10345. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10346. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10347. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10348. {
  10349. struct party_data *p;
  10350. int i,expflag;
  10351. int cmd = RFIFOW(fd,0);
  10352. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10353. if( !sd->status.party_id )
  10354. return;
  10355. p = party_search(sd->status.party_id);
  10356. if( p == NULL )
  10357. return;
  10358. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10359. if( i == MAX_PARTY )
  10360. return; //Shouldn't happen
  10361. if( !p->party.member[i].leader )
  10362. return;
  10363. expflag = RFIFOL(fd,info->pos[0]);
  10364. if(cmd == 0x0102){ //Client can't change the item-field
  10365. party_changeoption(sd, expflag, p->party.item);
  10366. }
  10367. else {
  10368. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  10369. party_changeoption(sd, expflag, itemflag);
  10370. }
  10371. }
  10372. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10373. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10374. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  10375. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10376. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10377. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10378. char *name, *message;
  10379. int namelen, messagelen;
  10380. // validate packet and retrieve name and message
  10381. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10382. return;
  10383. if( is_atcommand(fd, sd, message, 1) )
  10384. return;
  10385. if (sd->sc.cant.chat)
  10386. return; //no "chatting" while muted.
  10387. if( battle_config.min_chat_delay )
  10388. { //[Skotlex]
  10389. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10390. return;
  10391. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10392. }
  10393. // Reset idle time when using party chat.
  10394. sd->idletime = last_tick;
  10395. party_send_message(sd, text, textlen);
  10396. }
  10397. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10398. /// 07da <account id>.L
  10399. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  10400. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])),NULL);
  10401. }
  10402. /// Party Booking in KRO [Spiria]
  10403. ///
  10404. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  10405. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10406. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  10407. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10408. short level = RFIFOW(fd,info->pos[0]);
  10409. short mapid = RFIFOW(fd,info->pos[1]);
  10410. int idxpbj = info->pos[2];
  10411. short job[PARTY_BOOKING_JOBS];
  10412. int i;
  10413. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10414. job[i] = RFIFOB(fd,idxpbj+i*2);
  10415. party_booking_register(sd, level, mapid, job);
  10416. }
  10417. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  10418. /// 0803 <result>.W
  10419. /// result:
  10420. /// 0 = success
  10421. /// 1 = failure
  10422. /// 2 = already registered
  10423. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10424. {
  10425. int fd = sd->fd;
  10426. WFIFOHEAD(fd,packet_len(0x803));
  10427. WFIFOW(fd,0) = 0x803;
  10428. WFIFOW(fd,2) = flag;
  10429. WFIFOSET(fd,packet_len(0x803));
  10430. }
  10431. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  10432. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10433. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  10434. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10435. short level = RFIFOW(fd,info->pos[0]);
  10436. short mapid = RFIFOW(fd,info->pos[1]);
  10437. short job = RFIFOW(fd,info->pos[2]);
  10438. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  10439. short resultcount = RFIFOW(fd,info->pos[4]);
  10440. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  10441. }
  10442. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10443. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10444. /// more results:
  10445. /// 0 = no
  10446. /// 1 = yes
  10447. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10448. {
  10449. int i, j;
  10450. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10451. struct party_booking_ad_info *pb_ad;
  10452. WFIFOHEAD(fd,size*count + 5);
  10453. WFIFOW(fd,0) = 0x805;
  10454. WFIFOW(fd,2) = size*count + 5;
  10455. WFIFOB(fd,4) = more_result;
  10456. for(i=0; i<count; i++)
  10457. {
  10458. pb_ad = results[i];
  10459. WFIFOL(fd,i*size+5) = pb_ad->index;
  10460. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10461. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  10462. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10463. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10464. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10465. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10466. }
  10467. WFIFOSET(fd,WFIFOW(fd,2));
  10468. }
  10469. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  10470. /// 0806
  10471. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10472. {
  10473. if(party_booking_delete(sd))
  10474. clif_PartyBookingDeleteAck(sd, 0);
  10475. }
  10476. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  10477. /// 0807 <result>.W
  10478. /// result:
  10479. /// 0 = success
  10480. /// 1 = success (auto-removed expired ad)
  10481. /// 2 = failure
  10482. /// 3 = nothing registered
  10483. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10484. {
  10485. int fd = sd->fd;
  10486. WFIFOHEAD(fd,packet_len(0x807));
  10487. WFIFOW(fd,0) = 0x807;
  10488. WFIFOW(fd,2) = flag;
  10489. WFIFOSET(fd,packet_len(0x807));
  10490. }
  10491. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  10492. /// 0808 { <job>.W }*6
  10493. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10494. {
  10495. short job[PARTY_BOOKING_JOBS];
  10496. int i;
  10497. int idxpbu = packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0];
  10498. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10499. job[i] = RFIFOW(fd,idxpbu+i*2);
  10500. party_booking_update(sd, job);
  10501. }
  10502. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10503. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10504. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10505. {
  10506. int i;
  10507. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10508. if(pb_ad == NULL) return;
  10509. WBUFW(buf,0) = 0x809;
  10510. WBUFL(buf,2) = pb_ad->index;
  10511. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10512. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10513. WBUFW(buf,34) = pb_ad->p_detail.level;
  10514. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10515. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10516. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10517. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10518. }
  10519. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10520. /// 080a <index>.L { <job>.W }*6
  10521. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10522. {
  10523. int i;
  10524. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10525. if(pb_ad == NULL) return;
  10526. WBUFW(buf,0) = 0x80a;
  10527. WBUFL(buf,2) = pb_ad->index;
  10528. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10529. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10530. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10531. }
  10532. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10533. /// 080b <index>.L
  10534. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10535. {
  10536. uint8 buf[6];
  10537. WBUFW(buf,0) = 0x80b;
  10538. WBUFL(buf,2) = index;
  10539. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10540. }
  10541. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10542. /// 012e
  10543. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10544. {
  10545. vending_closevending(sd);
  10546. }
  10547. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10548. /// 0130 <account id>.L
  10549. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10550. {
  10551. if( sd->npc_id ) {// using an NPC
  10552. return;
  10553. }
  10554. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10555. }
  10556. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10557. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10558. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  10559. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10560. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  10561. int id = (int)RFIFOL(fd,info->pos[1]);
  10562. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  10563. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10564. // whether it fails or not, the buy window is closed
  10565. sd->vended_id = 0;
  10566. }
  10567. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10568. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10569. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  10570. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10571. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  10572. int aid = (int)RFIFOL(fd,info->pos[1]);
  10573. int uid = (int)RFIFOL(fd,info->pos[2]);
  10574. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10575. vending_purchasereq(sd, aid, uid, data, len/4);
  10576. // whether it fails or not, the buy window is closed
  10577. sd->vended_id = 0;
  10578. }
  10579. /// Confirm or cancel the shop preparation window.
  10580. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10581. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10582. /// result:
  10583. /// 0 = canceled
  10584. /// 1 = open
  10585. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  10586. int cmd = RFIFOW(fd,0);
  10587. struct s_packet_db* info = &packet_db[sd->packet_ver][cmd];
  10588. short len = (short)RFIFOW(fd,info->pos[0]);
  10589. const char* message = (char*)RFIFOP(fd,info->pos[1]);
  10590. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  10591. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  10592. len -= 84;
  10593. }
  10594. else { //(CZ_REQ_OPENSTORE2)
  10595. bool flag;
  10596. len -= 85;
  10597. flag = (bool)RFIFOB(fd,info->pos[2]);
  10598. if( !flag )
  10599. sd->state.prevend = 0;
  10600. }
  10601. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10602. return;
  10603. if( map[sd->bl.m].flag.novending ) {
  10604. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10605. return;
  10606. }
  10607. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10608. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10609. return;
  10610. }
  10611. if( message[0] == '\0' ) // invalid input
  10612. return;
  10613. vending_openvending(sd, message, data, len/8);
  10614. }
  10615. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10616. /// 0165 <char id>.L <guild name>.24B
  10617. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  10618. //int charid = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  10619. char* name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10620. name[NAME_LENGTH-1] = '\0';
  10621. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10622. clif_displaymessage(fd, msg_txt(sd,228));
  10623. return;
  10624. }
  10625. guild_create(sd, name);
  10626. }
  10627. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10628. /// 014d
  10629. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10630. {
  10631. clif_guild_masterormember(sd);
  10632. }
  10633. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10634. /// 014f <type>.L
  10635. /// type:
  10636. /// 0 = basic info
  10637. /// 1 = member manager
  10638. /// 2 = positions
  10639. /// 3 = skills
  10640. /// 4 = expulsion list
  10641. /// 5 = unknown (GM_ALLGUILDLIST)
  10642. /// 6 = notice
  10643. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10644. {
  10645. int type = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10646. if( !sd->status.guild_id && !sd->bg_id )
  10647. return;
  10648. switch( type )
  10649. {
  10650. case 0: // Basic Information Guild, hostile alliance information
  10651. clif_guild_basicinfo(sd);
  10652. clif_guild_allianceinfo(sd);
  10653. break;
  10654. case 1: // Members list, list job title
  10655. clif_guild_positionnamelist(sd);
  10656. clif_guild_memberlist(sd);
  10657. break;
  10658. case 2: // List job title, title information list
  10659. clif_guild_positionnamelist(sd);
  10660. clif_guild_positioninfolist(sd);
  10661. break;
  10662. case 3: // Skill list
  10663. clif_guild_skillinfo(sd);
  10664. break;
  10665. case 4: // Expulsion list
  10666. clif_guild_expulsionlist(sd);
  10667. break;
  10668. default:
  10669. ShowError("clif: guild request info: unknown type %d\n", type);
  10670. break;
  10671. }
  10672. }
  10673. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10674. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10675. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10676. {
  10677. int i;
  10678. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10679. int len = RFIFOW(fd,info->pos[0]);
  10680. int idxgpos = info->pos[1];
  10681. if(!sd->state.gmaster_flag)
  10682. return;
  10683. for(i = idxgpos; i < len; i += 40 ){
  10684. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10685. }
  10686. }
  10687. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10688. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10689. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10690. {
  10691. int i;
  10692. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10693. int len = RFIFOW(fd,info->pos[0]);
  10694. int idxgpos = info->pos[1];
  10695. if(!sd->state.gmaster_flag)
  10696. return;
  10697. for(i=idxgpos;i<len;i+=12){
  10698. guild_change_memberposition(sd->status.guild_id,
  10699. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10700. }
  10701. }
  10702. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10703. /// 0151 <guild id>.L
  10704. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10705. {
  10706. struct guild* g;
  10707. int guild_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10708. if( (g = guild_search(guild_id)) != NULL )
  10709. clif_guild_emblem(sd,g);
  10710. }
  10711. /// Validates data of a guild emblem (compressed bitmap)
  10712. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10713. {
  10714. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10715. unsigned long buf_len = sizeof(buf);
  10716. int offset = 0;
  10717. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10718. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10719. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10720. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10721. ))
  10722. return -1;
  10723. if(battle_config.emblem_transparency_limit != 100) {
  10724. int i, j, transcount = 1, tmp[3];
  10725. for(i = offset; i < buf_len-1; i++) {
  10726. j = i%3;
  10727. tmp[j] = RBUFL(buf,i);
  10728. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  10729. transcount++;
  10730. }
  10731. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  10732. return -2;
  10733. }
  10734. return 0;
  10735. }
  10736. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10737. /// 0153 <packet len>.W <emblem data>.?B
  10738. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  10739. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10740. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  10741. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  10742. int emb_val=0;
  10743. if( !emblem_len || !sd->state.gmaster_flag )
  10744. return;
  10745. if(!(battle_config.emblem_woe_change) && (agit_flag || agit2_flag) ){
  10746. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,385)); //"You not allowed to change emblem during woe"
  10747. return;
  10748. }
  10749. emb_val = clif_validate_emblem(emblem, emblem_len);
  10750. if(emb_val ==-1 ){
  10751. 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);
  10752. clif_colormes(sd,color_table[COLOR_RED],msg_txt(sd,386)); //"The chosen emblem was detected invalid\n"
  10753. return;
  10754. } else if(emb_val == -2){
  10755. char output[128];
  10756. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  10757. clif_colormes(sd,color_table[COLOR_RED],output); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  10758. return;
  10759. }
  10760. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10761. }
  10762. /// Guild notice update request (CZ_GUILD_NOTICE).
  10763. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10764. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  10765. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10766. int guild_id = RFIFOL(fd,info->pos[0]);
  10767. char* msg1 = (char*)RFIFOP(fd,info->pos[1]);
  10768. char* msg2 = (char*)RFIFOP(fd,info->pos[2]);
  10769. if(!sd->state.gmaster_flag)
  10770. return;
  10771. // compensate for some client defects when using multilanguage mode
  10772. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10773. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10774. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10775. guild_change_notice(sd, guild_id, msg1, msg2);
  10776. }
  10777. // Helper function for guild invite functions
  10778. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  10779. {
  10780. if (t_sd == NULL) // not online or does not exist
  10781. return 1;
  10782. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  10783. clif_displaymessage(fd, msg_txt(sd,228));
  10784. return 1;
  10785. }
  10786. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10787. clif_noask_sub(sd, t_sd, 2);
  10788. return 1;
  10789. }
  10790. guild_invite(sd, t_sd);
  10791. return 0;
  10792. }
  10793. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10794. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10795. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  10796. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10797. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  10798. // int inv_aid = RFIFOL(fd,info->pos[1]);
  10799. // int inv_cid = RFIFOL(fd,info->pos[2]);
  10800. if (clif_sub_guild_invite(fd, sd, t_sd))
  10801. return;
  10802. }
  10803. /// Guild invite request (/guildinvite)
  10804. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  10805. void
  10806. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  10807. struct map_session_data *t_sd = map_nick2sd((char *)RFIFOP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10808. if (clif_sub_guild_invite(fd, sd, t_sd))
  10809. return;
  10810. }
  10811. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10812. /// 016b <guild id>.L <answer>.L
  10813. /// answer:
  10814. /// 0 = refuse
  10815. /// 1 = accept
  10816. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  10817. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10818. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  10819. RFIFOL(fd,info->pos[1]));
  10820. }
  10821. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10822. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10823. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  10824. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10825. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10826. clif_displaymessage(fd, msg_txt(sd,228));
  10827. return;
  10828. }
  10829. if( sd->bg_id ) {
  10830. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10831. return;
  10832. }
  10833. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  10834. RFIFOL(fd,info->pos[1]),
  10835. RFIFOL(fd,info->pos[2]),
  10836. (char*)RFIFOP(fd,info->pos[3]));
  10837. }
  10838. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10839. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10840. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  10841. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10842. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10843. { // Guild locked.
  10844. clif_displaymessage(fd, msg_txt(sd,228));
  10845. return;
  10846. }
  10847. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  10848. RFIFOL(fd,info->pos[1]),
  10849. RFIFOL(fd,info->pos[2]),
  10850. (char*)RFIFOP(fd,info->pos[3]));
  10851. }
  10852. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10853. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10854. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  10855. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10856. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  10857. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  10858. char *name, *message;
  10859. int namelen, messagelen;
  10860. // validate packet and retrieve name and message
  10861. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10862. return;
  10863. if( is_atcommand(fd, sd, message, 1) )
  10864. return;
  10865. if (sd->sc.cant.chat)
  10866. return; //no "chatting" while muted.
  10867. if( battle_config.min_chat_delay )
  10868. { //[Skotlex]
  10869. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10870. return;
  10871. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10872. }
  10873. // Reset idle time when using guild chat.
  10874. sd->idletime = last_tick;
  10875. if( sd->bg_id )
  10876. bg_send_message(sd, text, textlen);
  10877. else
  10878. guild_send_message(sd, text, textlen);
  10879. }
  10880. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10881. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10882. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10883. {
  10884. struct map_session_data *t_sd;
  10885. if(!sd->state.gmaster_flag)
  10886. return;
  10887. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10888. clif_displaymessage(fd, msg_txt(sd,228));
  10889. return;
  10890. }
  10891. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10892. //inv_aid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  10893. //inv_cid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  10894. // @noask [LuzZza]
  10895. if(t_sd && t_sd->state.noask) {
  10896. clif_noask_sub(sd, t_sd, 3);
  10897. return;
  10898. }
  10899. guild_reqalliance(sd,t_sd);
  10900. }
  10901. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10902. /// 0172 <inviter account id>.L <answer>.L
  10903. /// answer:
  10904. /// 0 = refuse
  10905. /// 1 = accept
  10906. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  10907. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10908. guild_reply_reqalliance(sd,
  10909. RFIFOL(fd,info->pos[0]),
  10910. RFIFOL(fd,info->pos[1]));
  10911. }
  10912. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10913. /// 0183 <opponent guild id>.L <relation>.L
  10914. /// relation:
  10915. /// 0 = Ally
  10916. /// 1 = Enemy
  10917. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  10918. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  10919. if(!sd->state.gmaster_flag)
  10920. return;
  10921. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10922. clif_displaymessage(fd, msg_txt(sd,228));
  10923. return;
  10924. }
  10925. guild_delalliance(sd,
  10926. RFIFOL(fd,info->pos[0]),
  10927. RFIFOL(fd,info->pos[1]));
  10928. }
  10929. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10930. /// 0180 <account id>.L
  10931. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10932. {
  10933. struct map_session_data *t_sd;
  10934. if(!sd->state.gmaster_flag)
  10935. return;
  10936. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10937. clif_displaymessage(fd, msg_txt(sd,228));
  10938. return;
  10939. }
  10940. t_sd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10941. // @noask [LuzZza]
  10942. if(t_sd && t_sd->state.noask) {
  10943. clif_noask_sub(sd, t_sd, 4);
  10944. return;
  10945. }
  10946. guild_opposition(sd,t_sd);
  10947. }
  10948. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10949. /// 015d <key>.40B
  10950. /// key:
  10951. /// now guild name; might have been (intended) email, since the
  10952. /// field name and size is same as the one in CH_DELETE_CHAR.
  10953. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10954. {
  10955. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10956. clif_displaymessage(fd, msg_txt(sd,228));
  10957. return;
  10958. }
  10959. guild_break(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10960. }
  10961. /// Pet
  10962. ///
  10963. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10964. /// 01a1 <type>.B
  10965. /// type:
  10966. /// 0 = pet information
  10967. /// 1 = feed
  10968. /// 2 = performance
  10969. /// 3 = return to egg
  10970. /// 4 = unequip accessory
  10971. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  10972. pet_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10973. }
  10974. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10975. /// 019f <id>.L
  10976. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  10977. pet_catch_process2(sd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  10978. }
  10979. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10980. /// 01a7 <index>.W
  10981. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  10982. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  10983. return;
  10984. pet_select_egg(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  10985. clif_menuskill_clear(sd);
  10986. }
  10987. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10988. /// 01a9 <data>.L
  10989. /// data:
  10990. /// is either emotion (@see enum emotion_type) or a compound value
  10991. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10992. /// entry (given in parentheses) in data\pettalktable.xml
  10993. /// act id:
  10994. /// 0 = feeding
  10995. /// 1 = hunting
  10996. /// 2 = danger
  10997. /// 3 = dead
  10998. /// 4 = normal (stand)
  10999. /// 5 = special performance (perfor_s)
  11000. /// 6 = level up (levelup)
  11001. /// 7 = performance 1 (perfor_1)
  11002. /// 8 = performance 2 (perfor_2)
  11003. /// 9 = performance 3 (perfor_3)
  11004. /// 10 = log-in greeting (connect)
  11005. /// hungry value:
  11006. /// 0 = very hungry (hungry)
  11007. /// 1 = hungry (bit_hungry)
  11008. /// 2 = satisfied (noting)
  11009. /// 3 = stuffed (full)
  11010. /// 4 = full (so_full)
  11011. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11012. {
  11013. if(sd->pd)
  11014. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11015. }
  11016. /// Request to change pet's name (CZ_RENAME_PET).
  11017. /// 01a5 <name>.24B
  11018. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11019. {
  11020. pet_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11021. }
  11022. /// /kill (CZ_DISCONNECT_CHARACTER).
  11023. /// Request to disconnect a character.
  11024. /// 00cc <account id>.L
  11025. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11026. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11027. {
  11028. struct block_list *target;
  11029. int tid;
  11030. tid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11031. target = map_id2bl(tid);
  11032. if (!target) {
  11033. clif_GM_kickack(sd, 0);
  11034. return;
  11035. }
  11036. switch (target->type) {
  11037. case BL_PC:
  11038. {
  11039. char command[NAME_LENGTH+6];
  11040. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11041. is_atcommand(fd, sd, command, 1);
  11042. }
  11043. break;
  11044. /**
  11045. * This one does not invoke any atcommand, so we need to check for permissions.
  11046. */
  11047. case BL_MOB:
  11048. {
  11049. char command[100];
  11050. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11051. clif_GM_kickack(sd, 0);
  11052. return;
  11053. }
  11054. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11055. log_atcommand(sd, command);
  11056. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11057. }
  11058. break;
  11059. case BL_NPC:
  11060. {
  11061. struct npc_data* nd = (struct npc_data *)target;
  11062. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11063. npc_unload_duplicates(nd);
  11064. npc_unload(nd,true);
  11065. npc_read_event_script();
  11066. }
  11067. }
  11068. break;
  11069. default:
  11070. clif_GM_kickack(sd, 0);
  11071. }
  11072. }
  11073. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11074. /// Request to disconnect all characters.
  11075. /// 00ce
  11076. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11077. char cmd[15];
  11078. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11079. is_atcommand(fd, sd, cmd, 1);
  11080. }
  11081. /// /remove (CZ_REMOVE_AID).
  11082. /// Request to warp to a character with given login ID.
  11083. /// 01ba <account name>.24B
  11084. /// /shift (CZ_SHIFT).
  11085. /// Request to warp to a character with given name.
  11086. /// 01bb <char name>.24B
  11087. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11088. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11089. char *player_name;
  11090. char command[NAME_LENGTH+8];
  11091. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11092. player_name[NAME_LENGTH-1] = '\0';
  11093. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11094. is_atcommand(fd, sd, command, 1);
  11095. }
  11096. /// /remove (CZ_REMOVE_AID_SSO).
  11097. /// Request to warp to a character with given account ID.
  11098. /// 0843 <account id>.L
  11099. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11100. {
  11101. int account_id;
  11102. struct map_session_data* pl_sd;
  11103. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11104. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11105. char command[NAME_LENGTH+8];
  11106. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11107. is_atcommand(fd, sd, command, 1);
  11108. }
  11109. }
  11110. /// /recall (CZ_RECALL).
  11111. /// Request to summon a player with given login ID to own position.
  11112. /// 01bc <account name>.24B
  11113. /// /summon (CZ_RECALL_GID).
  11114. /// Request to summon a player with given name to own position.
  11115. /// 01bd <char name>.24B
  11116. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11117. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11118. char *player_name;
  11119. char command [NAME_LENGTH+8];
  11120. player_name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11121. player_name[NAME_LENGTH-1] = '\0';
  11122. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11123. is_atcommand(fd, sd, command, 1);
  11124. }
  11125. /// /recall (CZ_RECALL_SSO).
  11126. /// Request to summon a player with given account ID to own position.
  11127. /// 0842 <account id>.L
  11128. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11129. {
  11130. int account_id;
  11131. struct map_session_data* pl_sd;
  11132. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11133. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11134. char command[NAME_LENGTH+8];
  11135. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11136. is_atcommand(fd, sd, command, 1);
  11137. }
  11138. }
  11139. /// /item /monster (CZ_ITEM_CREATE).
  11140. /// Request to execute GM commands.
  11141. /// Usage:
  11142. /// /item n - summon n monster or acquire n item/s
  11143. /// /item money - grants 2147483647 zenies
  11144. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11145. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11146. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11147. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11148. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11149. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11150. /// 013f <item/mob name>.24B
  11151. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11152. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11153. {
  11154. int i, count;
  11155. char *item_monster_name;
  11156. struct item_data *item_array[10];
  11157. struct mob_db *mob_array[10];
  11158. char command[256];
  11159. #if PACKETVER >= 20131218
  11160. char str[100];
  11161. #else
  11162. char str[24];
  11163. #endif
  11164. item_monster_name = str;
  11165. item_monster_name[(sizeof(str) - 2) - 1] = '\0';
  11166. if( (count = itemdb_searchname_array(item_array, 10, item_monster_name)) > 0 ) {
  11167. for( i = 0; i < count; i++ )
  11168. if( !item_array[i] )
  11169. continue;
  11170. if( i < count ) {
  11171. if( item_array[i]->type == IT_WEAPON || item_array[i]->type == IT_ARMOR ) //Nonstackable
  11172. safesnprintf(command, sizeof(command) - 1, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, item_array[i]->nameid);
  11173. else
  11174. safesnprintf(command, sizeof(command) - 1, "%citem %d 20", atcommand_symbol, item_array[i]->nameid);
  11175. is_atcommand(fd, sd, command, 1);
  11176. return;
  11177. }
  11178. }
  11179. if( strcmp(item_monster_name, "money") == 0 ) {
  11180. safesnprintf(command, sizeof(command) - 1, "%czeny %d", atcommand_symbol, INT_MAX);
  11181. is_atcommand(fd, sd, command, 1);
  11182. return;
  11183. }
  11184. if( (count = mobdb_searchname_array(mob_array, 10, item_monster_name)) > 0 ) {
  11185. for( i = 0; i < count; i++ )
  11186. if( !mob_array[i] )
  11187. continue;
  11188. if( i < count ) {
  11189. safesnprintf(command, sizeof(command) - 1, "%cmonster %s", atcommand_symbol, mob_array[i]->sprite);
  11190. is_atcommand(fd, sd, command, 1);
  11191. }
  11192. }
  11193. }
  11194. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11195. /// 019d <effect state>.L
  11196. /// effect state:
  11197. /// TODO: Any OPTION_* ?
  11198. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11199. char cmd[6];
  11200. //int eff_st = RFIFOL(packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11201. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11202. is_atcommand(fd, sd, cmd, 1);
  11203. }
  11204. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11205. /// 0149 <account id>.L <type>.B <value>.W
  11206. /// type:
  11207. /// 0 = positive points
  11208. /// 1 = negative points
  11209. /// 2 = self mute (+10 minutes)
  11210. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11211. {
  11212. int id, type, value;
  11213. struct map_session_data *dstsd;
  11214. char command[NAME_LENGTH+15];
  11215. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11216. id = RFIFOL(fd,info->pos[0]);
  11217. type = RFIFOB(fd,info->pos[1]);
  11218. value = RFIFOW(fd,info->pos[2]);
  11219. if( type == 0 )
  11220. value = -value;
  11221. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11222. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11223. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11224. return;
  11225. dstsd = map_id2sd(id);
  11226. if( dstsd == NULL )
  11227. return;
  11228. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11229. is_atcommand(fd, sd, command, 1);
  11230. }
  11231. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11232. /// GM adjustment of a player's manner value by -60.
  11233. /// 0212 <char name>.24B
  11234. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11235. {
  11236. char command[NAME_LENGTH+15];
  11237. char *name = (char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11238. name[NAME_LENGTH-1] = '\0';
  11239. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11240. is_atcommand(fd, sd, command, 1);
  11241. }
  11242. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11243. /// 01e0 <account id>.L <account name>.24B
  11244. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  11245. {
  11246. int fd = sd->fd;
  11247. WFIFOHEAD(fd,packet_len(0x1e0));
  11248. WFIFOW(fd,0) = 0x1e0;
  11249. WFIFOL(fd,2) = account_id;
  11250. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11251. WFIFOSET(fd,packet_len(0x1e0));
  11252. }
  11253. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11254. /// 01df <account id>.L
  11255. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11256. {
  11257. if (sd->bl.type&BL_PC) { // Only show for players
  11258. char command[30];
  11259. int account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11260. //tmp get all display
  11261. safesnprintf(command,sizeof(command),"%caccinfo %d", atcommand_symbol, account_id);
  11262. is_atcommand(fd, sd, command, 1);
  11263. //clif_account_name(sd, account_id, ""); //! TODO request to login-serv
  11264. }
  11265. }
  11266. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11267. /// GM single cell type change request.
  11268. /// 0198 <x>.W <y>.W <type>.W
  11269. /// type:
  11270. /// 0 = not walkable
  11271. /// 1 = walkable
  11272. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  11273. {
  11274. int x,y,type;
  11275. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11276. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  11277. return;
  11278. x = RFIFOW(fd,info->pos[0]);
  11279. y = RFIFOW(fd,info->pos[1]);
  11280. type = RFIFOW(fd,info->pos[2]);
  11281. map_setgatcell(sd->bl.m,x,y,type);
  11282. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11283. //FIXME: once players leave the map, the client 'forgets' this information.
  11284. }
  11285. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11286. /// Request to allow/deny whispers from a nick.
  11287. /// 00cf <nick>.24B <type>.B
  11288. /// type:
  11289. /// 0 = (/ex nick) deny speech from nick
  11290. /// 1 = (/in nick) allow speech from nick
  11291. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  11292. {
  11293. char* nick;
  11294. uint8 type;
  11295. int i;
  11296. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11297. nick = (char*)RFIFOP(fd,info->pos[0]);
  11298. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11299. type = RFIFOB(fd,info->pos[1]);
  11300. if( type == 0 ) { // Add name to ignore list (block)
  11301. if (strcmp(wisp_server_name, nick) == 0) {
  11302. clif_wisexin(sd, type, 1); // fail
  11303. return;
  11304. }
  11305. // try to find a free spot, while checking for duplicates at the same time
  11306. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11307. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11308. clif_wisexin(sd, type, 2); // too many blocks
  11309. return;
  11310. }
  11311. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  11312. clif_wisexin(sd, type, 0); // Aegis reports success.
  11313. return;
  11314. }
  11315. //Insert in position i
  11316. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11317. } else { // Remove name from ignore list (unblock)
  11318. // find entry
  11319. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11320. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11321. clif_wisexin(sd, type, 1); // fail
  11322. return;
  11323. }
  11324. // move everything one place down to overwrite removed entry
  11325. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  11326. // wipe last entry
  11327. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11328. }
  11329. clif_wisexin(sd, type, 0); // success
  11330. }
  11331. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11332. /// Request to allow/deny all whispers.
  11333. /// 00d0 <type>.B
  11334. /// type:
  11335. /// 0 = (/exall) deny all speech
  11336. /// 1 = (/inall) allow all speech
  11337. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11338. {
  11339. int type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), flag;
  11340. if( type == 0 ) {// Deny all
  11341. if( sd->state.ignoreAll ) {
  11342. flag = 1; // fail
  11343. } else {
  11344. sd->state.ignoreAll = 1;
  11345. flag = 0; // success
  11346. }
  11347. } else {//Unblock everyone
  11348. if( sd->state.ignoreAll ) {
  11349. sd->state.ignoreAll = 0;
  11350. flag = 0; // success
  11351. } else {
  11352. if (sd->ignore[0].name[0] != '\0')
  11353. { //Wipe the ignore list.
  11354. memset(sd->ignore, 0, sizeof(sd->ignore));
  11355. flag = 0; // success
  11356. } else {
  11357. flag = 1; // fail
  11358. }
  11359. }
  11360. }
  11361. clif_wisall(sd, type, flag);
  11362. }
  11363. /// Whisper ignore list (ZC_WHISPER_LIST).
  11364. /// 00d4 <packet len>.W { <char name>.24B }*
  11365. void clif_PMIgnoreList(struct map_session_data* sd)
  11366. {
  11367. int i, fd = sd->fd;
  11368. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11369. WFIFOW(fd,0) = 0xd4;
  11370. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11371. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11372. }
  11373. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11374. WFIFOSET(fd,WFIFOW(fd,2));
  11375. }
  11376. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11377. /// 00d3
  11378. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11379. {
  11380. clif_PMIgnoreList(sd);
  11381. }
  11382. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11383. /// 01e7
  11384. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11385. {
  11386. if (sd->state.doridori) return;
  11387. switch (sd->class_&MAPID_UPPERMASK) {
  11388. case MAPID_SOUL_LINKER:
  11389. case MAPID_STAR_GLADIATOR:
  11390. case MAPID_TAEKWON:
  11391. if (!sd->state.rest)
  11392. break;
  11393. case MAPID_SUPER_NOVICE:
  11394. sd->state.doridori=1;
  11395. break;
  11396. }
  11397. }
  11398. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11399. /// 01ed
  11400. /// Note: This packet is caused by 7 lines of any text, followed by
  11401. /// the prayer and an another line of any text. The prayer is
  11402. /// defined by lines 790~793 in data\msgstringtable.txt
  11403. /// "Dear angel, can you hear my voice?"
  11404. /// "I am" (space separated player name) "Super Novice~"
  11405. /// "Help me out~ Please~ T_T"
  11406. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11407. {
  11408. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  11409. unsigned int next = pc_nextbaseexp(sd);
  11410. if( next == 0 ) next = pc_thisbaseexp(sd);
  11411. if( next ) {
  11412. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11413. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11414. 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]
  11415. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11416. }
  11417. }
  11418. }
  11419. }
  11420. /// Friends List
  11421. ///
  11422. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11423. /// 0206 <account id>.L <char id>.L <state>.B
  11424. /// state:
  11425. /// 0 = online
  11426. /// 1 = offline
  11427. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  11428. {
  11429. int i, fd = sd->fd;
  11430. //Seek friend.
  11431. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11432. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11433. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11434. return; //Not found
  11435. WFIFOHEAD(fd,packet_len(0x206));
  11436. WFIFOW(fd, 0) = 0x206;
  11437. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11438. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11439. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11440. WFIFOSET(fd, packet_len(0x206));
  11441. }
  11442. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  11443. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11444. {
  11445. int account_id, char_id, online;
  11446. account_id = va_arg(ap, int);
  11447. char_id = va_arg(ap, int);
  11448. online = va_arg(ap, int);
  11449. clif_friendslist_toggle(sd, account_id, char_id, online);
  11450. return 0;
  11451. }
  11452. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11453. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11454. void clif_friendslist_send(struct map_session_data *sd)
  11455. {
  11456. int i = 0, n, fd = sd->fd;
  11457. // Send friends list
  11458. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11459. WFIFOW(fd, 0) = 0x201;
  11460. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11461. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11462. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11463. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11464. }
  11465. if (i) {
  11466. WFIFOW(fd,2) = 4 + 32 * i;
  11467. WFIFOSET(fd, WFIFOW(fd,2));
  11468. }
  11469. for (n = 0; n < i; n++) { //Sending the online players
  11470. if (map_charid2sd(sd->status.friends[n].char_id))
  11471. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11472. }
  11473. }
  11474. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11475. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11476. /// result:
  11477. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11478. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11479. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11480. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11481. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11482. {
  11483. int fd;
  11484. nullpo_retv(sd);
  11485. fd = sd->fd;
  11486. WFIFOHEAD(fd,packet_len(0x209));
  11487. WFIFOW(fd,0) = 0x209;
  11488. WFIFOW(fd,2) = type;
  11489. if (f_sd) {
  11490. WFIFOL(fd,4) = f_sd->status.account_id;
  11491. WFIFOL(fd,8) = f_sd->status.char_id;
  11492. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11493. }
  11494. WFIFOSET(fd, packet_len(0x209));
  11495. }
  11496. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11497. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11498. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  11499. {
  11500. int fd = sd->fd;
  11501. WFIFOHEAD(fd,packet_len(0x207));
  11502. WFIFOW(fd,0) = 0x207;
  11503. WFIFOL(fd,2) = account_id;
  11504. WFIFOL(fd,6) = char_id;
  11505. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11506. WFIFOSET(fd,packet_len(0x207));
  11507. }
  11508. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11509. /// 0202 <name>.24B
  11510. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  11511. {
  11512. struct map_session_data *f_sd;
  11513. int i;
  11514. f_sd = map_nick2sd((char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11515. // ensure that the request player's friend list is not full
  11516. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11517. if( i == MAX_FRIENDS ) {
  11518. clif_friendslist_reqack(sd, f_sd, 2);
  11519. return;
  11520. }
  11521. // Friend doesn't exist (no player with this name)
  11522. if (f_sd == NULL) {
  11523. clif_displaymessage(fd, msg_txt(sd,3));
  11524. return;
  11525. }
  11526. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  11527. return;
  11528. }
  11529. // @noask [LuzZza]
  11530. if(f_sd->state.noask) {
  11531. clif_noask_sub(sd, f_sd, 5);
  11532. return;
  11533. }
  11534. // Friend already exists
  11535. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  11536. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  11537. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  11538. return;
  11539. }
  11540. }
  11541. f_sd->friend_req = sd->status.char_id;
  11542. sd->friend_req = f_sd->status.char_id;
  11543. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  11544. }
  11545. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  11546. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  11547. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  11548. /// reply:
  11549. /// 0 = rejected
  11550. /// 1 = accepted
  11551. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  11552. {
  11553. struct map_session_data *f_sd;
  11554. int account_id;
  11555. char reply;
  11556. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11557. account_id = RFIFOL(fd,info->pos[0]);
  11558. //char_id = RFIFOL(fd,info->pos[1]);
  11559. if(sd->packet_ver < 6)
  11560. reply = RFIFOB(fd,info->pos[2]);
  11561. else
  11562. reply = RFIFOL(fd,info->pos[2]);
  11563. if( sd->bl.id == account_id ) {// adding oneself as friend
  11564. return;
  11565. }
  11566. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  11567. if (f_sd == NULL)
  11568. return;
  11569. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  11570. clif_friendslist_reqack(f_sd, sd, 1);
  11571. else {
  11572. int i;
  11573. // Find an empty slot
  11574. for (i = 0; i < MAX_FRIENDS; i++)
  11575. if (f_sd->status.friends[i].char_id == 0)
  11576. break;
  11577. if (i == MAX_FRIENDS) {
  11578. clif_friendslist_reqack(f_sd, sd, 2);
  11579. return;
  11580. }
  11581. f_sd->status.friends[i].account_id = sd->status.account_id;
  11582. f_sd->status.friends[i].char_id = sd->status.char_id;
  11583. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  11584. clif_friendslist_reqack(f_sd, sd, 0);
  11585. if (battle_config.friend_auto_add) {
  11586. // Also add f_sd to sd's friendlist.
  11587. for (i = 0; i < MAX_FRIENDS; i++) {
  11588. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  11589. return; //No need to add anything.
  11590. if (sd->status.friends[i].char_id == 0)
  11591. break;
  11592. }
  11593. if (i == MAX_FRIENDS) {
  11594. clif_friendslist_reqack(sd, f_sd, 2);
  11595. return;
  11596. }
  11597. sd->status.friends[i].account_id = f_sd->status.account_id;
  11598. sd->status.friends[i].char_id = f_sd->status.char_id;
  11599. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  11600. clif_friendslist_reqack(sd, f_sd, 0);
  11601. }
  11602. }
  11603. }
  11604. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11605. /// 0203 <account id>.L <char id>.L
  11606. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11607. {
  11608. struct map_session_data *f_sd = NULL;
  11609. int account_id, char_id;
  11610. int i, j;
  11611. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11612. account_id = RFIFOL(fd,info->pos[0]);
  11613. char_id = RFIFOL(fd,info->pos[1]);
  11614. // Search friend
  11615. for (i = 0; i < MAX_FRIENDS &&
  11616. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11617. if (i == MAX_FRIENDS) {
  11618. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11619. return;
  11620. }
  11621. //remove from friend's list first
  11622. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11623. for (i = 0; i < MAX_FRIENDS &&
  11624. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11625. if (i != MAX_FRIENDS) {
  11626. // move all chars up
  11627. for(j = i + 1; j < MAX_FRIENDS; j++)
  11628. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11629. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11630. //should the guy be notified of some message? we should add it here if so
  11631. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11632. WFIFOW(f_sd->fd,0) = 0x20a;
  11633. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11634. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11635. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11636. }
  11637. } else { //friend not online -- ask char server to delete from his friendlist
  11638. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11639. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11640. return;
  11641. }
  11642. }
  11643. // We can now delete from original requester
  11644. for (i = 0; i < MAX_FRIENDS &&
  11645. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11646. // move all chars up
  11647. for(j = i + 1; j < MAX_FRIENDS; j++)
  11648. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11649. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11650. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11651. WFIFOHEAD(fd,packet_len(0x20a));
  11652. WFIFOW(fd,0) = 0x20a;
  11653. WFIFOL(fd,2) = account_id;
  11654. WFIFOL(fd,6) = char_id;
  11655. WFIFOSET(fd, packet_len(0x20a));
  11656. }
  11657. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11658. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11659. void clif_PVPInfo(struct map_session_data* sd)
  11660. {
  11661. int fd = sd->fd;
  11662. WFIFOHEAD(fd,packet_len(0x210));
  11663. WFIFOW(fd,0) = 0x210;
  11664. WFIFOL(fd,2) = sd->status.char_id;
  11665. WFIFOL(fd,6) = sd->status.account_id;
  11666. WFIFOL(fd,10) = sd->pvp_won; // times won
  11667. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11668. WFIFOL(fd,18) = sd->pvp_point;
  11669. WFIFOSET(fd, packet_len(0x210));
  11670. }
  11671. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11672. /// 020f <char id>.L <account id>.L
  11673. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11674. {
  11675. // TODO: Is there a way to use this on an another player (char/acc id)?
  11676. //int cid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11677. //int aid = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  11678. clif_PVPInfo(sd);
  11679. }
  11680. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11681. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11682. void clif_blacksmith(struct map_session_data* sd)
  11683. {
  11684. int i, fd = sd->fd;
  11685. const char* name;
  11686. WFIFOHEAD(fd,packet_len(0x219));
  11687. WFIFOW(fd,0) = 0x219;
  11688. //Packet size limits this list to 10 elements. [Skotlex]
  11689. for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
  11690. if (smith_fame_list[i].id > 0) {
  11691. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11692. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11693. {
  11694. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11695. } else
  11696. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11697. } else
  11698. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11699. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11700. }
  11701. for(;i < 10; i++) { //In case the MAX is less than 10.
  11702. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11703. WFIFOL(fd, 242 + i * 4) = 0;
  11704. }
  11705. WFIFOSET(fd, packet_len(0x219));
  11706. }
  11707. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11708. /// 0217
  11709. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11710. {
  11711. clif_blacksmith(sd);
  11712. }
  11713. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11714. /// 021b <points>.L <total points>.L
  11715. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11716. {
  11717. int fd = sd->fd;
  11718. WFIFOHEAD(fd,packet_len(0x21b));
  11719. WFIFOW(fd,0) = 0x21b;
  11720. WFIFOL(fd,2) = points;
  11721. WFIFOL(fd,6) = sd->status.fame;
  11722. WFIFOSET(fd, packet_len(0x21b));
  11723. }
  11724. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11725. /// 021a { <name>.24B }*10 { <point>.L }*10
  11726. void clif_alchemist(struct map_session_data* sd)
  11727. {
  11728. int i, fd = sd->fd;
  11729. const char* name;
  11730. WFIFOHEAD(fd,packet_len(0x21a));
  11731. WFIFOW(fd,0) = 0x21a;
  11732. //Packet size limits this list to 10 elements. [Skotlex]
  11733. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11734. if (chemist_fame_list[i].id > 0) {
  11735. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11736. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11737. {
  11738. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11739. } else
  11740. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11741. } else
  11742. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11743. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11744. }
  11745. for(;i < 10; i++) { //In case the MAX is less than 10.
  11746. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11747. WFIFOL(fd, 242 + i * 4) = 0;
  11748. }
  11749. WFIFOSET(fd, packet_len(0x21a));
  11750. }
  11751. /// /alchemist (CZ_ALCHEMIST_RANK).
  11752. /// 0218
  11753. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11754. {
  11755. clif_alchemist(sd);
  11756. }
  11757. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11758. /// 021c <points>.L <total points>.L
  11759. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11760. {
  11761. int fd = sd->fd;
  11762. WFIFOHEAD(fd,packet_len(0x21c));
  11763. WFIFOW(fd,0) = 0x21c;
  11764. WFIFOL(fd,2) = points;
  11765. WFIFOL(fd,6) = sd->status.fame;
  11766. WFIFOSET(fd, packet_len(0x21c));
  11767. }
  11768. /// /taekwon list (ZC_TAEKWON_RANK).
  11769. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11770. void clif_taekwon(struct map_session_data* sd)
  11771. {
  11772. int i, fd = sd->fd;
  11773. const char* name;
  11774. WFIFOHEAD(fd,packet_len(0x226));
  11775. WFIFOW(fd,0) = 0x226;
  11776. //Packet size limits this list to 10 elements. [Skotlex]
  11777. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  11778. if (taekwon_fame_list[i].id > 0) {
  11779. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11780. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11781. {
  11782. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11783. } else
  11784. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11785. } else
  11786. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11787. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11788. }
  11789. for(;i < 10; i++) { //In case the MAX is less than 10.
  11790. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11791. WFIFOL(fd, 242 + i * 4) = 0;
  11792. }
  11793. WFIFOSET(fd, packet_len(0x226));
  11794. }
  11795. /// /taekwon (CZ_TAEKWON_RANK).
  11796. /// 0225
  11797. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11798. {
  11799. clif_taekwon(sd);
  11800. }
  11801. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11802. /// 0224 <points>.L <total points>.L
  11803. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11804. {
  11805. int fd = sd->fd;
  11806. WFIFOHEAD(fd,packet_len(0x224));
  11807. WFIFOW(fd,0) = 0x224;
  11808. WFIFOL(fd,2) = points;
  11809. WFIFOL(fd,6) = sd->status.fame;
  11810. WFIFOSET(fd, packet_len(0x224));
  11811. }
  11812. /// /pk list (ZC_KILLER_RANK).
  11813. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11814. void clif_ranking_pk(struct map_session_data* sd)
  11815. {
  11816. int i, fd = sd->fd;
  11817. WFIFOHEAD(fd,packet_len(0x238));
  11818. WFIFOW(fd,0) = 0x238;
  11819. for(i=0;i<10;i++){
  11820. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11821. WFIFOL(fd,i*4+242) = 0;
  11822. }
  11823. WFIFOSET(fd, packet_len(0x238));
  11824. }
  11825. /// /pk (CZ_KILLER_RANK).
  11826. /// 0237
  11827. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11828. {
  11829. clif_ranking_pk(sd);
  11830. }
  11831. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11832. /// 0254 <which>.B
  11833. /// which: (unused atm for security purpose)
  11834. /// 0 = sun
  11835. /// 1 = moon
  11836. /// 2 = star
  11837. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11838. {
  11839. int i;
  11840. //int wich = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  11841. if (sd->menuskill_id != SG_FEEL)
  11842. return;
  11843. i = sd->menuskill_val-1;
  11844. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11845. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11846. sd->feel_map[i].m = sd->bl.m;
  11847. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11848. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11849. // clif_misceffect2(&sd->bl, 0x1b0);
  11850. // clif_misceffect2(&sd->bl, 0x21f);
  11851. clif_feel_info(sd, i, 0);
  11852. clif_menuskill_clear(sd);
  11853. }
  11854. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11855. /// 0253 <which>.B
  11856. /// which:
  11857. /// 0 = sun
  11858. /// 1 = moon
  11859. /// 2 = star
  11860. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11861. {
  11862. WFIFOHEAD(fd,packet_len(0x253));
  11863. WFIFOW(fd,0)=0x253;
  11864. WFIFOB(fd,2)=TOB(skill_lv-1);
  11865. WFIFOSET(fd, packet_len(0x253));
  11866. sd->menuskill_id = SG_FEEL;
  11867. sd->menuskill_val = skill_lv;
  11868. }
  11869. /// Request to change homunculus' name (CZ_RENAME_MER).
  11870. /// 0231 <name>.24B
  11871. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  11872. hom_change_name(sd,(char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  11873. }
  11874. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11875. /// 0234 <id>.L
  11876. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  11877. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  11878. struct block_list *bl = NULL;
  11879. struct unit_data *ud = NULL;
  11880. if( sd->md && sd->md->bl.id == id )
  11881. bl = &sd->md->bl;
  11882. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11883. bl = &sd->hd->bl; // Moving Homunculus
  11884. else
  11885. return;
  11886. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11887. ud = unit_bl2ud(bl);
  11888. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11889. }
  11890. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11891. /// 0232 <id>.L <position data>.3B
  11892. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  11893. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11894. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  11895. struct block_list *bl = NULL;
  11896. short x, y;
  11897. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  11898. if( sd->md && sd->md->bl.id == id )
  11899. bl = &sd->md->bl; // Moving Mercenary
  11900. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11901. bl = &sd->hd->bl; // Moving Homunculus
  11902. else
  11903. return;
  11904. unit_walktoxy(bl, x, y, 4);
  11905. }
  11906. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11907. /// 0233 <id>.L <target id>.L <action>.B
  11908. /// action:
  11909. /// always 0
  11910. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11911. {
  11912. struct block_list *bl = NULL;
  11913. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  11914. int id = RFIFOL(fd,info->pos[0]);
  11915. int target_id = RFIFOL(fd,info->pos[1]);
  11916. int action_type = RFIFOB(fd,info->pos[2]);
  11917. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  11918. bl = &sd->hd->bl;
  11919. else if( sd->md && sd->md->bl.id == id )
  11920. bl = &sd->md->bl;
  11921. else return;
  11922. unit_stop_attack(bl);
  11923. unit_attack(bl, target_id, action_type != 0);
  11924. }
  11925. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11926. /// 022d <type>.W <command>.B
  11927. /// type:
  11928. /// always 0
  11929. /// command:
  11930. /// 0 = homunculus information
  11931. /// 1 = feed
  11932. /// 2 = delete
  11933. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11934. { //[orn]
  11935. int cmd = RFIFOW(fd,0);
  11936. //int type = RFIFOW(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  11937. if(!hom_is_active(sd->hd))
  11938. return;
  11939. hom_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11940. }
  11941. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11942. /// 0292
  11943. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11944. {
  11945. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11946. int hpsp = 100;
  11947. if (item_position < 0) {
  11948. if (sd->sc.data[SC_LIGHT_OF_REGENE])
  11949. hpsp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  11950. else
  11951. return;
  11952. }
  11953. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11954. return;
  11955. if (!status_revive(&sd->bl, hpsp, hpsp))
  11956. return;
  11957. if (item_position < 0)
  11958. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  11959. else
  11960. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11961. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  11962. }
  11963. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11964. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11965. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11966. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11967. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11968. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11969. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11970. void clif_check(int fd, struct map_session_data* pl_sd)
  11971. {
  11972. WFIFOHEAD(fd,packet_len(0x214));
  11973. WFIFOW(fd, 0) = 0x214;
  11974. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11975. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11976. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11977. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11978. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11979. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11980. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11981. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11982. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11983. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11984. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11985. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11986. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11987. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11988. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11989. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11990. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11991. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11992. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11993. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11994. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11995. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11996. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11997. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11998. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11999. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12000. WFIFOSET(fd,packet_len(0x214));
  12001. }
  12002. /// /check (CZ_REQ_STATUS_GM).
  12003. /// Request character's status values.
  12004. /// 0213 <char name>.24B
  12005. void clif_parse_Check(int fd, struct map_session_data *sd)
  12006. {
  12007. char charname[NAME_LENGTH];
  12008. struct map_session_data* pl_sd;
  12009. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12010. return;
  12011. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12012. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12013. {
  12014. return;
  12015. }
  12016. clif_check(fd, pl_sd);
  12017. }
  12018. /// MAIL SYSTEM
  12019. /// By Zephyrus
  12020. ///
  12021. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12022. /// 0255 <index>.W <result>.B
  12023. /// result:
  12024. /// 0 = success
  12025. /// 1 = failure
  12026. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12027. {
  12028. WFIFOHEAD(fd,packet_len(0x255));
  12029. WFIFOW(fd,0) = 0x255;
  12030. WFIFOW(fd,2) = index;
  12031. WFIFOB(fd,4) = flag;
  12032. WFIFOSET(fd,packet_len(0x255));
  12033. }
  12034. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12035. /// 0245 <result>.B
  12036. /// result:
  12037. /// 0 = success
  12038. /// 1 = failure
  12039. /// 2 = too many items
  12040. void clif_Mail_getattachment(int fd, uint8 flag)
  12041. {
  12042. WFIFOHEAD(fd,packet_len(0x245));
  12043. WFIFOW(fd,0) = 0x245;
  12044. WFIFOB(fd,2) = flag;
  12045. WFIFOSET(fd,packet_len(0x245));
  12046. }
  12047. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12048. /// 0249 <result>.B
  12049. /// result:
  12050. /// 0 = success
  12051. /// 1 = recipinent does not exist
  12052. void clif_Mail_send(int fd, bool fail)
  12053. {
  12054. WFIFOHEAD(fd,packet_len(0x249));
  12055. WFIFOW(fd,0) = 0x249;
  12056. WFIFOB(fd,2) = fail;
  12057. WFIFOSET(fd,packet_len(0x249));
  12058. }
  12059. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12060. /// 0257 <mail id>.L <result>.W
  12061. /// result:
  12062. /// 0 = success
  12063. /// 1 = failure
  12064. void clif_Mail_delete(int fd, int mail_id, short fail)
  12065. {
  12066. WFIFOHEAD(fd, packet_len(0x257));
  12067. WFIFOW(fd,0) = 0x257;
  12068. WFIFOL(fd,2) = mail_id;
  12069. WFIFOW(fd,6) = fail;
  12070. WFIFOSET(fd, packet_len(0x257));
  12071. }
  12072. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12073. /// 0274 <mail id>.L <result>.W
  12074. /// result:
  12075. /// 0 = success
  12076. /// 1 = failure
  12077. void clif_Mail_return(int fd, int mail_id, short fail)
  12078. {
  12079. WFIFOHEAD(fd,packet_len(0x274));
  12080. WFIFOW(fd,0) = 0x274;
  12081. WFIFOL(fd,2) = mail_id;
  12082. WFIFOW(fd,6) = fail;
  12083. WFIFOSET(fd,packet_len(0x274));
  12084. }
  12085. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12086. /// 024a <mail id>.L <title>.40B <sender>.24B
  12087. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12088. {
  12089. WFIFOHEAD(fd,packet_len(0x24a));
  12090. WFIFOW(fd,0) = 0x24a;
  12091. WFIFOL(fd,2) = mail_id;
  12092. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12093. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12094. WFIFOSET(fd,packet_len(0x24a));
  12095. }
  12096. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12097. /// 0260 <type>.L
  12098. /// type:
  12099. /// 0 = open
  12100. /// 1 = close
  12101. void clif_Mail_window(int fd, int flag)
  12102. {
  12103. WFIFOHEAD(fd,packet_len(0x260));
  12104. WFIFOW(fd,0) = 0x260;
  12105. WFIFOL(fd,2) = flag;
  12106. WFIFOSET(fd,packet_len(0x260));
  12107. }
  12108. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12109. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12110. /// read:
  12111. /// 0 = unread
  12112. /// 1 = read
  12113. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12114. {
  12115. int fd = sd->fd;
  12116. struct mail_data *md = &sd->mail.inbox;
  12117. struct mail_message *msg;
  12118. int len, i, j;
  12119. len = 8 + (73 * md->amount);
  12120. WFIFOHEAD(fd,len);
  12121. WFIFOW(fd,0) = 0x240;
  12122. WFIFOW(fd,2) = len;
  12123. WFIFOL(fd,4) = md->amount;
  12124. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12125. {
  12126. msg = &md->msg[i];
  12127. if (msg->id < 1)
  12128. continue;
  12129. WFIFOL(fd,8+73*j) = msg->id;
  12130. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12131. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12132. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12133. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12134. j++;
  12135. }
  12136. WFIFOSET(fd,len);
  12137. if( md->full ) {// TODO: is this official?
  12138. char output[100];
  12139. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12140. clif_disp_onlyself(sd, output, strlen(output));
  12141. }
  12142. }
  12143. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12144. /// 023f
  12145. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12146. {
  12147. struct mail_data* md = &sd->mail.inbox;
  12148. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12149. intif_Mail_requestinbox(sd->status.char_id, 1);
  12150. else
  12151. clif_Mail_refreshinbox(sd);
  12152. mail_removeitem(sd, 0);
  12153. mail_removezeny(sd, 0);
  12154. }
  12155. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12156. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12157. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12158. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12159. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12160. {
  12161. int i, fd = sd->fd;
  12162. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12163. if( i == MAIL_MAX_INBOX ) {
  12164. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12165. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12166. return;
  12167. } else {
  12168. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12169. struct item *item = &msg->item;
  12170. struct item_data *data;
  12171. int msg_len = strlen(msg->body), len;
  12172. if( msg_len == 0 ) {
  12173. strcpy(msg->body, "(no message)");
  12174. msg_len = strlen(msg->body);
  12175. }
  12176. len = 101 + msg_len;
  12177. WFIFOHEAD(fd,len);
  12178. WFIFOW(fd,0) = 0x242;
  12179. WFIFOW(fd,2) = len;
  12180. WFIFOL(fd,4) = msg->id;
  12181. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12182. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12183. WFIFOL(fd,72) = 0;
  12184. WFIFOL(fd,76) = msg->zeny;
  12185. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  12186. WFIFOL(fd,80) = item->amount;
  12187. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12188. WFIFOW(fd,86) = data->type;
  12189. WFIFOB(fd,88) = item->identify;
  12190. WFIFOB(fd,89) = item->attribute;
  12191. WFIFOB(fd,90) = item->refine;
  12192. WFIFOW(fd,91) = item->card[0];
  12193. WFIFOW(fd,93) = item->card[1];
  12194. WFIFOW(fd,95) = item->card[2];
  12195. WFIFOW(fd,97) = item->card[3];
  12196. } else // no item, set all to zero
  12197. memset(WFIFOP(fd,80), 0x00, 19);
  12198. WFIFOB(fd,99) = (unsigned char)msg_len;
  12199. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12200. WFIFOSET(fd,len);
  12201. if (msg->status == MAIL_UNREAD) {
  12202. msg->status = MAIL_READ;
  12203. intif_Mail_read(mail_id);
  12204. clif_parse_Mail_refreshinbox(fd, sd);
  12205. }
  12206. }
  12207. }
  12208. /// Request to open a mail (CZ_MAIL_OPEN).
  12209. /// 0241 <mail id>.L
  12210. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12211. {
  12212. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12213. if( mail_id <= 0 )
  12214. return;
  12215. if( mail_invalid_operation(sd) )
  12216. return;
  12217. clif_Mail_read(sd, mail_id);
  12218. }
  12219. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12220. /// 0244 <mail id>.L
  12221. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12222. {
  12223. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12224. int i;
  12225. bool fail = false;
  12226. if( !chrif_isconnected() )
  12227. return;
  12228. if( mail_id <= 0 )
  12229. return;
  12230. if( mail_invalid_operation(sd) )
  12231. return;
  12232. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12233. if( i == MAIL_MAX_INBOX )
  12234. return;
  12235. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12236. return;
  12237. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12238. clif_Mail_getattachment(fd, 1);
  12239. return;
  12240. }
  12241. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12242. struct item_data *data;
  12243. unsigned int weight;
  12244. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12245. return;
  12246. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12247. case CHKADDITEM_NEW:
  12248. fail = ( pc_inventoryblank(sd) == 0 );
  12249. break;
  12250. case CHKADDITEM_OVERAMOUNT:
  12251. fail = true;
  12252. }
  12253. if( fail ) {
  12254. clif_Mail_getattachment(fd, 1);
  12255. return;
  12256. }
  12257. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12258. if( sd->weight + weight > sd->max_weight ) {
  12259. clif_Mail_getattachment(fd, 2);
  12260. return;
  12261. }
  12262. }
  12263. sd->mail.inbox.msg[i].zeny = 0;
  12264. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12265. clif_Mail_read(sd, mail_id);
  12266. intif_Mail_getattach(sd->status.char_id, mail_id);
  12267. }
  12268. /// Request to delete a mail (CZ_MAIL_DELETE).
  12269. /// 0243 <mail id>.L
  12270. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  12271. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12272. int i;
  12273. if( !chrif_isconnected() )
  12274. return;
  12275. if( mail_id <= 0 )
  12276. return;
  12277. if( mail_invalid_operation(sd) )
  12278. return;
  12279. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12280. if (i < MAIL_MAX_INBOX) {
  12281. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12282. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12283. clif_Mail_delete(sd->fd, mail_id, 1);
  12284. return;
  12285. }
  12286. intif_Mail_delete(sd->status.char_id, mail_id);
  12287. }
  12288. }
  12289. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12290. /// 0273 <mail id>.L <receive name>.24B
  12291. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  12292. int mail_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12293. //char *rec_name = RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12294. int i;
  12295. if( mail_id <= 0 )
  12296. return;
  12297. if( mail_invalid_operation(sd) )
  12298. return;
  12299. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12300. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  12301. intif_Mail_return(sd->status.char_id, mail_id);
  12302. else
  12303. clif_Mail_return(sd->fd, mail_id, 1);
  12304. }
  12305. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12306. /// 0247 <index>.W <amount>.L
  12307. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  12308. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12309. int idx = RFIFOW(fd,info->pos[0]);
  12310. int amount = RFIFOL(fd,info->pos[1]);
  12311. unsigned char flag;
  12312. if( !chrif_isconnected() )
  12313. return;
  12314. if (idx < 0 || amount < 0)
  12315. return;
  12316. flag = mail_setitem(sd, idx, amount);
  12317. clif_Mail_setattachment(fd,idx,flag);
  12318. }
  12319. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12320. /// 0246 <type>.W
  12321. /// type:
  12322. /// 0 = reset all
  12323. /// 1 = remove item
  12324. /// 2 = remove zeny
  12325. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12326. {
  12327. int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12328. if (type == 0 || type == 1)
  12329. mail_removeitem(sd, 0);
  12330. if (type == 0 || type == 2)
  12331. mail_removezeny(sd, 0);
  12332. }
  12333. /// Request to send mail (CZ_MAIL_SEND).
  12334. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12335. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12336. {
  12337. struct mail_message msg;
  12338. int body_len;
  12339. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12340. if( !chrif_isconnected() )
  12341. return;
  12342. if( sd->state.trading )
  12343. return;
  12344. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  12345. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12346. return;
  12347. }
  12348. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 ) {
  12349. clif_displaymessage(sd->fd,msg_txt(sd,675)); //"Cannot send mails too fast!!."
  12350. clif_Mail_send(fd, true); // fail
  12351. return;
  12352. }
  12353. body_len = RFIFOB(fd,info->pos[3]);
  12354. if (body_len > MAIL_BODY_LENGTH)
  12355. body_len = MAIL_BODY_LENGTH;
  12356. if( !mail_setattachment(sd, &msg) ) { // Invalid Append condition
  12357. clif_Mail_send(sd->fd, true); // fail
  12358. mail_removeitem(sd,0);
  12359. mail_removezeny(sd,0);
  12360. return;
  12361. }
  12362. msg.id = 0; // id will be assigned by charserver
  12363. msg.send_id = sd->status.char_id;
  12364. msg.dest_id = 0; // will attempt to resolve name
  12365. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  12366. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,info->pos[1]), NAME_LENGTH);
  12367. safestrncpy(msg.title, (char*)RFIFOP(fd,info->pos[2]), MAIL_TITLE_LENGTH);
  12368. if (msg.title[0] == '\0') {
  12369. return; // Message has no length and somehow client verification was skipped.
  12370. }
  12371. if (body_len)
  12372. safestrncpy(msg.body, (char*)RFIFOP(fd,info->pos[4]), body_len + 1);
  12373. else
  12374. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  12375. msg.timestamp = time(NULL);
  12376. if( !intif_Mail_send(sd->status.account_id, &msg) )
  12377. mail_deliveryfail(sd, &msg);
  12378. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  12379. }
  12380. /// AUCTION SYSTEM
  12381. /// By Zephyrus
  12382. ///
  12383. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12384. /// 025f <type>.L
  12385. /// type:
  12386. /// 0 = open
  12387. /// 1 = close
  12388. void clif_Auction_openwindow(struct map_session_data *sd)
  12389. {
  12390. int fd = sd->fd;
  12391. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  12392. return;
  12393. if( !battle_config.feature_auction )
  12394. return;
  12395. WFIFOHEAD(fd,packet_len(0x25f));
  12396. WFIFOW(fd,0) = 0x25f;
  12397. WFIFOL(fd,2) = 0;
  12398. WFIFOSET(fd,packet_len(0x25f));
  12399. }
  12400. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12401. /// 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 }*
  12402. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12403. {
  12404. int i, fd = sd->fd, len = sizeof(struct auction_data);
  12405. struct auction_data auction;
  12406. struct item_data *item;
  12407. int k;
  12408. WFIFOHEAD(fd,12 + (count * 83));
  12409. WFIFOW(fd,0) = 0x252;
  12410. WFIFOW(fd,2) = 12 + (count * 83);
  12411. WFIFOL(fd,4) = pages;
  12412. WFIFOL(fd,8) = count;
  12413. for( i = 0; i < count; i++ ) {
  12414. memcpy(&auction, RBUFP(buf,i * len), len);
  12415. k = 12 + (i * 83);
  12416. WFIFOL(fd,k) = auction.auction_id;
  12417. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12418. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12419. WFIFOW(fd,28+k) = item->view_id;
  12420. else
  12421. WFIFOW(fd,28+k) = auction.item.nameid;
  12422. WFIFOL(fd,30+k) = auction.type;
  12423. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12424. WFIFOB(fd,36+k) = auction.item.identify;
  12425. WFIFOB(fd,37+k) = auction.item.attribute;
  12426. WFIFOB(fd,38+k) = auction.item.refine;
  12427. WFIFOW(fd,39+k) = auction.item.card[0];
  12428. WFIFOW(fd,41+k) = auction.item.card[1];
  12429. WFIFOW(fd,43+k) = auction.item.card[2];
  12430. WFIFOW(fd,45+k) = auction.item.card[3];
  12431. WFIFOL(fd,47+k) = auction.price;
  12432. WFIFOL(fd,51+k) = auction.buynow;
  12433. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12434. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12435. }
  12436. WFIFOSET(fd,WFIFOW(fd,2));
  12437. }
  12438. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12439. /// 0256 <index>.W <result>.B
  12440. /// result:
  12441. /// 0 = success
  12442. /// 1 = failure
  12443. static void clif_Auction_setitem(int fd, int index, bool fail)
  12444. {
  12445. WFIFOHEAD(fd,packet_len(0x256));
  12446. WFIFOW(fd,0) = 0x256;
  12447. WFIFOW(fd,2) = index;
  12448. WFIFOB(fd,4) = fail;
  12449. WFIFOSET(fd,packet_len(0x256));
  12450. }
  12451. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  12452. /// 024b <type>.W
  12453. /// type:
  12454. /// 0 = create (any other action in auction window)
  12455. /// 1 = cancel (cancel pressed on register tab)
  12456. /// ? = junk, uninitialized value (ex. when switching between list filters)
  12457. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  12458. //int type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12459. if( sd->auction.amount > 0 )
  12460. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  12461. sd->auction.amount = 0;
  12462. }
  12463. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  12464. /// 024c <index>.W <count>.L
  12465. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  12466. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12467. int idx = RFIFOW(fd,info->pos[0]) - 2;
  12468. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  12469. struct item_data *item;
  12470. if( !battle_config.feature_auction )
  12471. return;
  12472. if( sd->auction.amount > 0 )
  12473. sd->auction.amount = 0;
  12474. if( idx < 0 || idx >= MAX_INVENTORY ) {
  12475. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  12476. return;
  12477. }
  12478. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  12479. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  12480. return;
  12481. }
  12482. 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) )
  12483. { // Consumable or pets are not allowed
  12484. clif_Auction_setitem(sd->fd, idx, true);
  12485. return;
  12486. }
  12487. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  12488. !sd->status.inventory[idx].identify ||
  12489. !itemdb_available(sd->status.inventory[idx].nameid) ||
  12490. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  12491. clif_Auction_setitem(sd->fd, idx, true);
  12492. return;
  12493. }
  12494. sd->auction.index = idx;
  12495. sd->auction.amount = amount;
  12496. clif_Auction_setitem(fd, idx + 2, false);
  12497. }
  12498. /// Result from an auction action (ZC_AUCTION_RESULT).
  12499. /// 0250 <result>.B
  12500. /// result:
  12501. /// 0 = You have failed to bid into the auction
  12502. /// 1 = You have successfully bid in the auction
  12503. /// 2 = The auction has been canceled
  12504. /// 3 = An auction with at least one bidder cannot be canceled
  12505. /// 4 = You cannot register more than 5 items in an auction at a time
  12506. /// 5 = You do not have enough Zeny to pay the Auction Fee
  12507. /// 6 = You have won the auction
  12508. /// 7 = You have failed to win the auction
  12509. /// 8 = You do not have enough Zeny
  12510. /// 9 = You cannot place more than 5 bids at a time
  12511. void clif_Auction_message(int fd, unsigned char flag)
  12512. {
  12513. WFIFOHEAD(fd,packet_len(0x250));
  12514. WFIFOW(fd,0) = 0x250;
  12515. WFIFOB(fd,2) = flag;
  12516. WFIFOSET(fd,packet_len(0x250));
  12517. }
  12518. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  12519. /// 025e <result>.W
  12520. /// result:
  12521. /// 0 = You have ended the auction
  12522. /// 1 = You cannot end the auction
  12523. /// 2 = Auction ID is incorrect
  12524. void clif_Auction_close(int fd, unsigned char flag)
  12525. {
  12526. WFIFOHEAD(fd,packet_len(0x25e));
  12527. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  12528. WFIFOW(fd,2) = flag;
  12529. WFIFOSET(fd,packet_len(0x25e));
  12530. }
  12531. /// Request to add an auction (CZ_AUCTION_ADD).
  12532. /// 024d <now money>.L <max money>.L <delete hour>.W
  12533. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  12534. {
  12535. struct auction_data auction;
  12536. struct item_data *item;
  12537. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12538. if( !battle_config.feature_auction )
  12539. return;
  12540. auction.price = RFIFOL(fd,info->pos[0]);
  12541. auction.buynow = RFIFOL(fd,info->pos[1]);
  12542. auction.hours = RFIFOW(fd,info->pos[2]);
  12543. // Invalid Situations...
  12544. if( sd->auction.amount < 1 ) {
  12545. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  12546. return;
  12547. }
  12548. if( auction.price >= auction.buynow ) {
  12549. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  12550. return;
  12551. }
  12552. if( auction.hours < 1 || auction.hours > 48 ) {
  12553. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  12554. return;
  12555. }
  12556. // Auction checks...
  12557. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  12558. clif_displaymessage(sd->fd, msg_txt(sd,293));
  12559. clif_Auction_message(fd, 2); // The auction has been canceled
  12560. return;
  12561. }
  12562. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  12563. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  12564. return;
  12565. }
  12566. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  12567. auction.buynow = battle_config.auction_maximumprice;
  12568. if( auction.price >= auction.buynow )
  12569. auction.price = auction.buynow - 1;
  12570. }
  12571. auction.auction_id = 0;
  12572. auction.seller_id = sd->status.char_id;
  12573. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  12574. auction.buyer_id = 0;
  12575. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  12576. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  12577. {
  12578. clif_Auction_message(fd, 2); // The auction has been canceled
  12579. return;
  12580. }
  12581. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  12582. { // Just in case
  12583. clif_Auction_message(fd, 2); // The auction has been canceled
  12584. return;
  12585. }
  12586. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  12587. auction.type = item->type;
  12588. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  12589. auction.item.amount = 1;
  12590. auction.timestamp = 0;
  12591. if( !intif_Auction_register(&auction) )
  12592. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  12593. else
  12594. {
  12595. int zeny = auction.hours*battle_config.auction_feeperhour;
  12596. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  12597. sd->auction.amount = 0;
  12598. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  12599. }
  12600. }
  12601. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  12602. /// 024e <auction id>.L
  12603. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  12604. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12605. intif_Auction_cancel(sd->status.char_id, auction_id);
  12606. }
  12607. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  12608. /// 025d <auction id>.L
  12609. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  12610. unsigned int auction_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12611. intif_Auction_close(sd->status.char_id, auction_id);
  12612. }
  12613. /// Places a bid on an auction (CZ_AUCTION_BUY).
  12614. /// 024f <auction id>.L <money>.L
  12615. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  12616. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12617. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  12618. int bid = RFIFOL(fd,info->pos[1]);
  12619. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  12620. clif_displaymessage(sd->fd, msg_txt(sd,246));
  12621. return;
  12622. }
  12623. if( bid <= 0 )
  12624. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12625. else if( bid > sd->status.zeny )
  12626. clif_Auction_message(fd, 8); // You do not have enough zeny
  12627. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12628. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12629. else {
  12630. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12631. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12632. }
  12633. }
  12634. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12635. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12636. /// search type:
  12637. /// 0 = armor
  12638. /// 1 = weapon
  12639. /// 2 = card
  12640. /// 3 = misc
  12641. /// 4 = name search
  12642. /// 5 = auction id search
  12643. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  12644. char search_text[NAME_LENGTH];
  12645. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12646. short type = RFIFOW(fd,info->pos[0]);
  12647. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  12648. int page = RFIFOW(fd,info->pos[3]);
  12649. if( !battle_config.feature_auction )
  12650. return;
  12651. clif_parse_Auction_cancelreg(fd, sd);
  12652. safestrncpy(search_text, (char*)RFIFOP(fd,info->pos[2]), sizeof(search_text));
  12653. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12654. }
  12655. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12656. /// 025c <type>.W
  12657. /// type:
  12658. /// 0 = sell (own auctions)
  12659. /// 1 = buy (own bids)
  12660. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12661. {
  12662. short type = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]) + 6;
  12663. if( !battle_config.feature_auction )
  12664. return;
  12665. clif_parse_Auction_cancelreg(fd, sd);
  12666. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12667. }
  12668. /// CASH/POINT SHOP
  12669. ///
  12670. void clif_cashshop_open( struct map_session_data* sd ){
  12671. WFIFOHEAD( sd->fd, 10 );
  12672. WFIFOW( sd->fd, 0 ) = 0x845;
  12673. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  12674. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  12675. WFIFOSET( sd->fd, 10 );
  12676. }
  12677. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  12678. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12679. clif_cashshop_open( sd );
  12680. }
  12681. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  12682. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  12683. // No need to do anything here
  12684. }
  12685. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  12686. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  12687. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  12688. short tab = RFIFOW(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12689. int j;
  12690. if( tab < 0 || tab > CASHSHOP_TAB_SEARCH )
  12691. return;
  12692. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  12693. WFIFOW(fd, 0) = 0x8c0;
  12694. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  12695. WFIFOL(fd, 4) = tab;
  12696. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  12697. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  12698. WFIFOW(fd, 10 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->nameid;
  12699. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  12700. }
  12701. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  12702. }
  12703. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  12704. void clif_cashshop_list( int fd ){
  12705. int tab;
  12706. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  12707. int length = 8 + cash_shop_items[tab].count * 6;
  12708. int i, offset;
  12709. WFIFOHEAD( fd, length );
  12710. WFIFOW( fd, 0 ) = 0x8ca;
  12711. WFIFOW( fd, 2 ) = length;
  12712. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  12713. WFIFOW( fd, 6 ) = tab;
  12714. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  12715. WFIFOW( fd, offset ) = cash_shop_items[tab].item[i]->nameid;
  12716. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  12717. }
  12718. WFIFOSET( fd, length );
  12719. }
  12720. }
  12721. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  12722. if( !sd->status.cashshop_sent ) {
  12723. clif_cashshop_list( fd );
  12724. sd->status.cashshop_sent = true;
  12725. }
  12726. }
  12727. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12728. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12729. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12730. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12731. {
  12732. int fd,i;
  12733. #if PACKETVER < 20070711
  12734. const int offset = 8;
  12735. #else
  12736. const int offset = 12;
  12737. #endif
  12738. nullpo_retv(sd);
  12739. nullpo_retv(nd);
  12740. fd = sd->fd;
  12741. sd->npc_shopid = nd->bl.id;
  12742. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12743. WFIFOW(fd,0) = 0x287;
  12744. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12745. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12746. #if PACKETVER >= 20070711
  12747. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12748. #endif
  12749. for( i = 0; i < nd->u.shop.count; i++ ) {
  12750. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12751. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12752. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12753. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  12754. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12755. }
  12756. WFIFOSET(fd,WFIFOW(fd,2));
  12757. }
  12758. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12759. /// 0289 <cash point>.L <error>.W
  12760. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12761. /// error:
  12762. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12763. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12764. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12765. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12766. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12767. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12768. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12769. /// 7 = You can purchase up to 10 items.
  12770. /// 8 = Some items could not be purchased.
  12771. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12772. {
  12773. int fd = sd->fd;
  12774. WFIFOHEAD(fd, packet_len(0x289));
  12775. WFIFOW(fd,0) = 0x289;
  12776. WFIFOL(fd,2) = sd->cashPoints;
  12777. #if PACKETVER < 20070711
  12778. WFIFOW(fd,6) = TOW(error);
  12779. #else
  12780. WFIFOL(fd,6) = sd->kafraPoints;
  12781. WFIFOW(fd,10) = TOW(error);
  12782. #endif
  12783. WFIFOSET(fd, packet_len(0x289));
  12784. }
  12785. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  12786. WFIFOHEAD( sd->fd, 16 );
  12787. WFIFOW( sd->fd, 0 ) = 0x849;
  12788. WFIFOL( sd->fd, 2 ) = item_id;
  12789. WFIFOW( sd->fd, 6 ) = result;
  12790. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  12791. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  12792. WFIFOSET( sd->fd, 16 );
  12793. }
  12794. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12795. /// 0288 <name id>.W <amount>.W
  12796. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12797. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12798. /// 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)
  12799. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) {
  12800. struct s_packet_db* info;
  12801. int cmd = RFIFOW(fd,0);
  12802. nullpo_retv(sd);
  12803. info = &packet_db[sd->packet_ver][cmd];
  12804. if( sd->state.trading || !sd->npc_shopid ) {
  12805. clif_cashshop_ack(sd,1);
  12806. return;
  12807. } else {
  12808. #if PACKETVER < 20101116
  12809. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  12810. short amount = RFIFOW(fd,info->pos[1]);
  12811. int points = RFIFOL(fd,info->pos[2]);
  12812. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  12813. #else
  12814. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  12815. int len = RFIFOW(fd,info->pos[0]);
  12816. int points = RFIFOL(fd,info->pos[1]);
  12817. int count = RFIFOW(fd,info->pos[2]);
  12818. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  12819. if( len < 10 || len != 10 + count * s_itl) {
  12820. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  12821. return;
  12822. }
  12823. if(cmd == 0x848) {
  12824. if (cashshop_buylist( sd, points, count, item_list))
  12825. clif_cashshop_ack(sd,0);
  12826. return;
  12827. } else {
  12828. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  12829. return;
  12830. }
  12831. #endif
  12832. }
  12833. }
  12834. /// Adoption System
  12835. ///
  12836. /// Adoption message (ZC_BABYMSG).
  12837. /// 0216 <msg>.L
  12838. /// msg:
  12839. /// 0 = "You cannot adopt more than 1 child."
  12840. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12841. /// 2 = "You cannot adopt a married person."
  12842. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12843. {
  12844. int fd = sd->fd;
  12845. WFIFOHEAD(fd,6);
  12846. WFIFOW(fd,0) = 0x216;
  12847. WFIFOL(fd,2) = type;
  12848. WFIFOSET(fd,6);
  12849. }
  12850. /// Adoption confirmation (ZC_REQ_BABY).
  12851. /// 01f6 <account id>.L <char id>.L <name>.B
  12852. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12853. {
  12854. int fd = sd->fd;
  12855. WFIFOHEAD(fd,34);
  12856. WFIFOW(fd,0) = 0x1f6;
  12857. WFIFOL(fd,2) = src->status.account_id;
  12858. WFIFOL(fd,6) = p_id;
  12859. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12860. WFIFOSET(fd,34);
  12861. }
  12862. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12863. /// 01f9 <account id>.L
  12864. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12865. {
  12866. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
  12867. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  12868. if( pc_can_Adopt(sd, p_sd, tsd) )
  12869. {
  12870. tsd->adopt_invite = sd->status.account_id;
  12871. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12872. }
  12873. }
  12874. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12875. /// 01f7 <account id>.L <char id>.L <answer>.L
  12876. /// answer:
  12877. /// 0 = rejected
  12878. /// 1 = accepted
  12879. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  12880. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12881. int p1_id = RFIFOL(fd,info->pos[0]);
  12882. int p2_id = RFIFOL(fd,info->pos[1]);
  12883. int result = RFIFOL(fd,info->pos[2]);
  12884. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12885. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12886. int pid = sd->adopt_invite;
  12887. sd->adopt_invite = 0;
  12888. if( p1_sd == NULL || p2_sd == NULL )
  12889. return; // Both players need to be online
  12890. if( pid != p1_sd->status.account_id )
  12891. return; // Incorrect values
  12892. if( result == 0 )
  12893. return; // Rejected
  12894. pc_adoption(p1_sd, p2_sd, sd);
  12895. }
  12896. /// Convex Mirror (ZC_BOSS_INFO).
  12897. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12898. /// infoType:
  12899. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12900. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12901. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12902. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12903. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12904. {
  12905. WFIFOHEAD(fd,70);
  12906. memset(WFIFOP(fd,0),0,70);
  12907. WFIFOW(fd,0) = 0x293;
  12908. if( md != NULL ) {
  12909. if( md->bl.prev != NULL ) { // Boss on This Map
  12910. if( flag ) {
  12911. WFIFOB(fd,2) = 1;
  12912. WFIFOL(fd,3) = md->bl.x;
  12913. WFIFOL(fd,7) = md->bl.y;
  12914. } else
  12915. WFIFOB(fd,2) = 2; // First Time
  12916. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12917. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12918. unsigned int seconds;
  12919. int hours, minutes;
  12920. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12921. hours = seconds / (60 * 60);
  12922. seconds = seconds - (60 * 60 * hours);
  12923. minutes = seconds / 60;
  12924. WFIFOB(fd,2) = 3;
  12925. WFIFOW(fd,11) = hours; // Hours
  12926. WFIFOW(fd,13) = minutes; // Minutes
  12927. }
  12928. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12929. }
  12930. WFIFOSET(fd,70);
  12931. }
  12932. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12933. /// 02d6 <account id>.L
  12934. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12935. {
  12936. int aid = RFIFOL(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12937. struct map_session_data* tsd = map_id2sd(aid);
  12938. if (!tsd)
  12939. return;
  12940. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12941. clif_viewequip_ack(sd, tsd);
  12942. else
  12943. clif_msg(sd, VIEW_EQUIP_FAIL);
  12944. }
  12945. /// Request to change equip window tick (CZ_CONFIG).
  12946. /// 02d8 <type>.L <flag>.L
  12947. /// type:
  12948. /// 0 = open equip window
  12949. /// flag:
  12950. /// 0 = disabled
  12951. /// 1 = enabled
  12952. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12953. {
  12954. //int type = RFIFOL(fd,packet_db[sd->packet_ver][cmd].pos[0]);
  12955. bool flag = (bool)RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  12956. sd->status.show_equip = flag;
  12957. clif_equiptickack(sd, flag);
  12958. }
  12959. /// Request to change party invitation tick.
  12960. /// value:
  12961. /// 0 = disabled
  12962. /// 1 = enabled
  12963. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  12964. {
  12965. bool flag = RFIFOB(fd,6) ? true : false;
  12966. sd->status.allow_party = flag;
  12967. clif_partytickack(sd, flag);
  12968. }
  12969. /// Questlog System [Kevin] [Inkfish]
  12970. ///
  12971. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12972. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12973. void clif_quest_send_list(struct map_session_data * sd)
  12974. {
  12975. int fd = sd->fd;
  12976. int i;
  12977. int len = sd->avail_quests*5+8;
  12978. WFIFOHEAD(fd,len);
  12979. WFIFOW(fd, 0) = 0x2b1;
  12980. WFIFOW(fd, 2) = len;
  12981. WFIFOL(fd, 4) = sd->avail_quests;
  12982. for( i = 0; i < sd->avail_quests; i++ ) {
  12983. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12984. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12985. }
  12986. WFIFOSET(fd, len);
  12987. }
  12988. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12989. /// 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
  12990. void clif_quest_send_mission(struct map_session_data * sd)
  12991. {
  12992. int fd = sd->fd;
  12993. int i, j;
  12994. int len = sd->avail_quests*104+8;
  12995. struct mob_db *mob;
  12996. WFIFOHEAD(fd, len);
  12997. WFIFOW(fd, 0) = 0x2b2;
  12998. WFIFOW(fd, 2) = len;
  12999. WFIFOL(fd, 4) = sd->avail_quests;
  13000. for( i = 0; i < sd->avail_quests; i++ ) {
  13001. struct quest_db *qi = quest_db(sd->quest_log[i].quest_id);
  13002. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13003. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13004. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13005. WFIFOW(fd, i*104+20) = qi->num_objectives;
  13006. for( j = 0 ; j < qi->num_objectives; j++ ) {
  13007. WFIFOL(fd, i*104+22+j*30) = qi->mob[j];
  13008. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13009. mob = mob_db(qi->mob[j]);
  13010. memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  13011. }
  13012. }
  13013. WFIFOSET(fd, len);
  13014. }
  13015. /// Notification about a new quest (ZC_ADD_QUEST).
  13016. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13017. void clif_quest_add(struct map_session_data * sd, struct quest * qd)
  13018. {
  13019. int fd = sd->fd;
  13020. int i;
  13021. struct mob_db *mob;
  13022. struct quest_db *qi = quest_db(qd->quest_id);
  13023. WFIFOHEAD(fd, packet_len(0x2b3));
  13024. WFIFOW(fd, 0) = 0x2b3;
  13025. WFIFOL(fd, 2) = qd->quest_id;
  13026. WFIFOB(fd, 6) = qd->state;
  13027. WFIFOB(fd, 7) = qi->time;
  13028. WFIFOL(fd, 11) = qd->time;
  13029. WFIFOW(fd, 15) = qi->num_objectives;
  13030. for( i = 0; i < qi->num_objectives; i++ ) {
  13031. WFIFOL(fd, i*30+17) = qi->mob[i];
  13032. WFIFOW(fd, i*30+21) = qd->count[i];
  13033. mob = mob_db(qi->mob[i]);
  13034. memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
  13035. }
  13036. WFIFOSET(fd, packet_len(0x2b3));
  13037. }
  13038. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13039. /// 02b4 <quest id>.L
  13040. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  13041. {
  13042. int fd = sd->fd;
  13043. WFIFOHEAD(fd, packet_len(0x2b4));
  13044. WFIFOW(fd, 0) = 0x2b4;
  13045. WFIFOL(fd, 2) = quest_id;
  13046. WFIFOSET(fd, packet_len(0x2b4));
  13047. }
  13048. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13049. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13050. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd)
  13051. {
  13052. int fd = sd->fd;
  13053. int i;
  13054. struct quest_db *qi = quest_db(qd->quest_id);
  13055. int len = qi->num_objectives * 12 + 6;
  13056. WFIFOHEAD(fd, len);
  13057. WFIFOW(fd, 0) = 0x2b5;
  13058. WFIFOW(fd, 2) = len;
  13059. WFIFOW(fd, 4) = qi->num_objectives;
  13060. for( i = 0; i < qi->num_objectives; i++ ) {
  13061. WFIFOL(fd, i*12+6) = qd->quest_id;
  13062. WFIFOL(fd, i*12+10) = qi->mob[i];
  13063. WFIFOW(fd, i*12+14) = qi->count[i];
  13064. WFIFOW(fd, i*12+16) = qd->count[i];
  13065. }
  13066. WFIFOSET(fd, len);
  13067. }
  13068. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13069. /// 02b6 <quest id>.L <active>.B
  13070. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  13071. {
  13072. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13073. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  13074. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  13075. }
  13076. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13077. /// 02b7 <quest id>.L <active>.B
  13078. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  13079. {
  13080. int fd = sd->fd;
  13081. WFIFOHEAD(fd, packet_len(0x2b7));
  13082. WFIFOW(fd, 0) = 0x2b7;
  13083. WFIFOL(fd, 2) = quest_id;
  13084. WFIFOB(fd, 6) = active;
  13085. WFIFOSET(fd, packet_len(0x2b7));
  13086. }
  13087. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13088. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13089. /// effect:
  13090. /// 0 = none
  13091. /// 1 = exclamation mark icon
  13092. /// 2 = question mark icon
  13093. /// type:
  13094. /// 0 = yellow
  13095. /// 1 = orange
  13096. /// 2 = green
  13097. /// 3 = purple
  13098. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13099. {
  13100. #if PACKETVER >= 20090218
  13101. int fd = sd->fd;
  13102. WFIFOHEAD(fd, packet_len(0x446));
  13103. WFIFOW(fd, 0) = 0x446;
  13104. WFIFOL(fd, 2) = bl->id;
  13105. WFIFOW(fd, 6) = bl->x;
  13106. WFIFOW(fd, 8) = bl->y;
  13107. WFIFOW(fd, 10) = state;
  13108. WFIFOW(fd, 12) = color;
  13109. WFIFOSET(fd, packet_len(0x446));
  13110. #endif
  13111. }
  13112. /// Mercenary System
  13113. ///
  13114. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13115. /// 02a2 <var id>.W <value>.L
  13116. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  13117. {
  13118. struct mercenary_data *md;
  13119. struct status_data *status;
  13120. int fd;
  13121. if( sd == NULL || (md = sd->md) == NULL )
  13122. return;
  13123. fd = sd->fd;
  13124. status = &md->battle_status;
  13125. WFIFOHEAD(fd,packet_len(0x2a2));
  13126. WFIFOW(fd,0) = 0x2a2;
  13127. WFIFOW(fd,2) = type;
  13128. switch( type ) {
  13129. case SP_ATK1:
  13130. {
  13131. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13132. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13133. }
  13134. break;
  13135. case SP_MATK1:
  13136. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  13137. break;
  13138. case SP_HIT:
  13139. WFIFOL(fd,4) = status->hit;
  13140. break;
  13141. case SP_CRITICAL:
  13142. WFIFOL(fd,4) = status->cri/10;
  13143. break;
  13144. case SP_DEF1:
  13145. WFIFOL(fd,4) = status->def;
  13146. break;
  13147. case SP_MDEF1:
  13148. WFIFOL(fd,4) = status->mdef;
  13149. break;
  13150. case SP_MERCFLEE:
  13151. WFIFOL(fd,4) = status->flee;
  13152. break;
  13153. case SP_ASPD:
  13154. WFIFOL(fd,4) = status->amotion;
  13155. break;
  13156. case SP_HP:
  13157. WFIFOL(fd,4) = status->hp;
  13158. break;
  13159. case SP_MAXHP:
  13160. WFIFOL(fd,4) = status->max_hp;
  13161. break;
  13162. case SP_SP:
  13163. WFIFOL(fd,4) = status->sp;
  13164. break;
  13165. case SP_MAXSP:
  13166. WFIFOL(fd,4) = status->max_sp;
  13167. break;
  13168. case SP_MERCKILLS:
  13169. WFIFOL(fd,4) = md->mercenary.kill_count;
  13170. break;
  13171. case SP_MERCFAITH:
  13172. WFIFOL(fd,4) = mercenary_get_faith(md);
  13173. break;
  13174. }
  13175. WFIFOSET(fd,packet_len(0x2a2));
  13176. }
  13177. /// Mercenary base status data (ZC_MER_INIT).
  13178. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13179. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13180. /// <calls>.L <kills>.L <atk range>.W
  13181. void clif_mercenary_info(struct map_session_data *sd)
  13182. {
  13183. int fd;
  13184. struct mercenary_data *md;
  13185. struct status_data *status;
  13186. int atk;
  13187. if( sd == NULL || (md = sd->md) == NULL )
  13188. return;
  13189. fd = sd->fd;
  13190. status = &md->battle_status;
  13191. WFIFOHEAD(fd,packet_len(0x29b));
  13192. WFIFOW(fd,0) = 0x29b;
  13193. WFIFOL(fd,2) = md->bl.id;
  13194. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13195. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  13196. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  13197. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  13198. WFIFOW(fd,10) = status->hit;
  13199. WFIFOW(fd,12) = status->cri/10;
  13200. WFIFOW(fd,14) = status->def;
  13201. WFIFOW(fd,16) = status->mdef;
  13202. WFIFOW(fd,18) = status->flee;
  13203. WFIFOW(fd,20) = status->amotion;
  13204. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13205. WFIFOW(fd,46) = md->db->lv;
  13206. WFIFOL(fd,48) = status->hp;
  13207. WFIFOL(fd,52) = status->max_hp;
  13208. WFIFOL(fd,56) = status->sp;
  13209. WFIFOL(fd,60) = status->max_sp;
  13210. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  13211. WFIFOW(fd,68) = mercenary_get_faith(md);
  13212. WFIFOL(fd,70) = mercenary_get_calls(md);
  13213. WFIFOL(fd,74) = md->mercenary.kill_count;
  13214. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13215. WFIFOSET(fd,packet_len(0x29b));
  13216. }
  13217. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13218. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  13219. void clif_mercenary_skillblock(struct map_session_data *sd)
  13220. {
  13221. struct mercenary_data *md;
  13222. int fd, i, len = 4, id, j;
  13223. if( sd == NULL || (md = sd->md) == NULL )
  13224. return;
  13225. fd = sd->fd;
  13226. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13227. WFIFOW(fd,0) = 0x29d;
  13228. for( i = 0; i < MAX_MERCSKILL; i++ )
  13229. {
  13230. if( (id = md->db->skill[i].id) == 0 )
  13231. continue;
  13232. j = id - MC_SKILLBASE;
  13233. WFIFOW(fd,len) = id;
  13234. WFIFOL(fd,len+2) = skill_get_inf(id);
  13235. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13236. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  13237. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  13238. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  13239. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13240. len += 37;
  13241. }
  13242. WFIFOW(fd,2) = len;
  13243. WFIFOSET(fd,len);
  13244. }
  13245. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13246. /// 029f <command>.B
  13247. /// 1 = mercenary information
  13248. /// 2 = delete
  13249. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13250. {
  13251. int option = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13252. if( sd->md == NULL )
  13253. return;
  13254. if( option == 2 ) mercenary_delete(sd->md, 2);
  13255. }
  13256. /// Mercenary Message
  13257. /// message:
  13258. /// 0 = Mercenary soldier's duty hour is over.
  13259. /// 1 = Your mercenary soldier has been killed.
  13260. /// 2 = Your mercenary soldier has been fired.
  13261. /// 3 = Your mercenary soldier has ran away.
  13262. void clif_mercenary_message(struct map_session_data* sd, int message){
  13263. clif_msg(sd, MERC_MSG_BASE + message);
  13264. }
  13265. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13266. /// 0298 <name id>.W <seconds>.L
  13267. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  13268. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13269. WFIFOHEAD(fd,packet_len(0x298));
  13270. WFIFOW(fd,0) = 0x298;
  13271. WFIFOW(fd,2) = nameid;
  13272. WFIFOL(fd,4) = seconds;
  13273. WFIFOSET(fd,packet_len(0x298));
  13274. }
  13275. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13276. /// 0299 <index>.W <name id>.W
  13277. void clif_rental_expired(int fd, int index, unsigned short nameid)
  13278. { // '<ItemName>' item has been deleted from the Inventory
  13279. WFIFOHEAD(fd,packet_len(0x299));
  13280. WFIFOW(fd,0) = 0x299;
  13281. WFIFOW(fd,2) = index+2;
  13282. WFIFOW(fd,4) = nameid;
  13283. WFIFOSET(fd,packet_len(0x299));
  13284. }
  13285. /// Book Reading (ZC_READ_BOOK).
  13286. /// 0294 <book id>.L <page>.L
  13287. void clif_readbook(int fd, int book_id, int page)
  13288. {
  13289. WFIFOHEAD(fd,packet_len(0x294));
  13290. WFIFOW(fd,0) = 0x294;
  13291. WFIFOL(fd,2) = book_id;
  13292. WFIFOL(fd,6) = page;
  13293. WFIFOSET(fd,packet_len(0x294));
  13294. }
  13295. /// Battlegrounds
  13296. ///
  13297. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13298. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13299. void clif_bg_hp(struct map_session_data *sd)
  13300. {
  13301. unsigned char buf[34];
  13302. const int cmd = 0x2e0;
  13303. nullpo_retv(sd);
  13304. WBUFW(buf,0) = cmd;
  13305. WBUFL(buf,2) = sd->status.account_id;
  13306. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13307. if( sd->battle_status.max_hp > INT16_MAX )
  13308. { // To correctly display the %hp bar. [Skotlex]
  13309. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13310. WBUFW(buf,32) = 100;
  13311. }
  13312. else
  13313. {
  13314. WBUFW(buf,30) = sd->battle_status.hp;
  13315. WBUFW(buf,32) = sd->battle_status.max_hp;
  13316. }
  13317. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13318. }
  13319. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13320. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13321. void clif_bg_xy(struct map_session_data *sd)
  13322. {
  13323. unsigned char buf[36];
  13324. nullpo_retv(sd);
  13325. WBUFW(buf,0)=0x2df;
  13326. WBUFL(buf,2)=sd->status.account_id;
  13327. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13328. WBUFW(buf,30)=sd->status.class_;
  13329. WBUFW(buf,32)=sd->bl.x;
  13330. WBUFW(buf,34)=sd->bl.y;
  13331. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13332. }
  13333. void clif_bg_xy_remove(struct map_session_data *sd)
  13334. {
  13335. unsigned char buf[36];
  13336. nullpo_retv(sd);
  13337. WBUFW(buf,0)=0x2df;
  13338. WBUFL(buf,2)=sd->status.account_id;
  13339. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13340. WBUFW(buf,30)=0;
  13341. WBUFW(buf,32)=-1;
  13342. WBUFW(buf,34)=-1;
  13343. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13344. }
  13345. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13346. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13347. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  13348. {
  13349. struct map_session_data *sd;
  13350. unsigned char *buf;
  13351. if( (sd = bg_getavailablesd(bg)) == NULL )
  13352. return;
  13353. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13354. WBUFW(buf,0) = 0x2dc;
  13355. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13356. WBUFL(buf,4) = src_id;
  13357. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13358. memcpy(WBUFP(buf,32), mes, len);
  13359. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  13360. if( buf )
  13361. aFree(buf);
  13362. }
  13363. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13364. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13365. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  13366. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13367. int textlen = RFIFOW(fd,info->pos[0]) - 4;
  13368. const char* text = (char*)RFIFOP(fd,info->pos[1]);
  13369. char *name, *message;
  13370. int namelen, messagelen;
  13371. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13372. return;
  13373. if( is_atcommand(fd, sd, message, 1) )
  13374. return;
  13375. if (sd->sc.cant.chat)
  13376. return; //no "chatting" while muted.
  13377. if( battle_config.min_chat_delay ) {
  13378. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  13379. return;
  13380. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  13381. }
  13382. // Reset idle time when using battleground chat.
  13383. sd->idletime = last_tick;
  13384. bg_send_message(sd, text, textlen);
  13385. }
  13386. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13387. /// 02de <camp A points>.W <camp B points>.W
  13388. void clif_bg_updatescore(int16 m)
  13389. {
  13390. struct block_list bl;
  13391. unsigned char buf[6];
  13392. bl.id = 0;
  13393. bl.type = BL_NUL;
  13394. bl.m = m;
  13395. WBUFW(buf,0) = 0x2de;
  13396. WBUFW(buf,2) = map[m].bgscore_lion;
  13397. WBUFW(buf,4) = map[m].bgscore_eagle;
  13398. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13399. }
  13400. void clif_bg_updatescore_single(struct map_session_data *sd)
  13401. {
  13402. int fd;
  13403. nullpo_retv(sd);
  13404. fd = sd->fd;
  13405. WFIFOHEAD(fd,packet_len(0x2de));
  13406. WFIFOW(fd,0) = 0x2de;
  13407. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  13408. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  13409. WFIFOSET(fd,packet_len(0x2de));
  13410. }
  13411. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13412. /// 02dd <account id>.L <name>.24B <camp>.W
  13413. void clif_sendbgemblem_area(struct map_session_data *sd)
  13414. {
  13415. unsigned char buf[33];
  13416. nullpo_retv(sd);
  13417. WBUFW(buf, 0) = 0x2dd;
  13418. WBUFL(buf,2) = sd->bl.id;
  13419. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  13420. WBUFW(buf,30) = sd->bg_id;
  13421. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  13422. }
  13423. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  13424. {
  13425. nullpo_retv(sd);
  13426. WFIFOHEAD(fd,32);
  13427. WFIFOW(fd,0) = 0x2dd;
  13428. WFIFOL(fd,2) = sd->bl.id;
  13429. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  13430. WFIFOW(fd,30) = sd->bg_id;
  13431. WFIFOSET(fd,packet_len(0x2dd));
  13432. }
  13433. /// Custom Fonts (ZC_NOTIFY_FONT).
  13434. /// 02ef <account_id>.L <font id>.W
  13435. void clif_font(struct map_session_data *sd)
  13436. {
  13437. #if PACKETVER >= 20080102
  13438. unsigned char buf[8];
  13439. nullpo_retv(sd);
  13440. WBUFW(buf,0) = 0x2ef;
  13441. WBUFL(buf,2) = sd->bl.id;
  13442. WBUFW(buf,6) = sd->status.font;
  13443. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  13444. #endif
  13445. }
  13446. /*==========================================
  13447. * Notifies party members of instance change
  13448. *------------------------------------------*/
  13449. void clif_instance_create(struct map_session_data *sd, const char *name, int num, int flag)
  13450. {
  13451. #if PACKETVER >= 20071128
  13452. unsigned char buf[65];
  13453. if(!sd) return;
  13454. WBUFW(buf,0) = 0x2cb;
  13455. memcpy( WBUFP(buf,2), name, 62 );
  13456. WBUFW(buf,63) = num;
  13457. if(flag) // A timer has changed or been added
  13458. clif_send(buf,packet_len(0x2cb),&sd->bl,PARTY);
  13459. else // No notification
  13460. clif_send(buf,packet_len(0x2cb),&sd->bl,SELF);
  13461. #endif
  13462. return;
  13463. }
  13464. void clif_instance_changewait(struct map_session_data *sd, int num, int flag)
  13465. {
  13466. #if PACKETVER >= 20071128
  13467. unsigned char buf[4];
  13468. if(!sd) return;
  13469. WBUFW(buf,0) = 0x2cc;
  13470. WBUFW(buf,2) = num;
  13471. if(flag) // A timer has changed or been added
  13472. clif_send(buf,packet_len(0x2cc),&sd->bl,PARTY);
  13473. else // No notification
  13474. clif_send(buf,packet_len(0x2cc),&sd->bl,SELF);
  13475. #endif
  13476. return;
  13477. }
  13478. void clif_instance_status(struct map_session_data *sd, const char *name, unsigned int limit1, unsigned int limit2, int flag)
  13479. {
  13480. #if PACKETVER >= 20071128
  13481. unsigned char buf[71];
  13482. if(!sd) return; //party_getavailablesd can return NULL
  13483. WBUFW(buf,0) = 0x2cd;
  13484. memcpy( WBUFP(buf,2), name, 62 );
  13485. WBUFL(buf,63) = limit1;
  13486. WBUFL(buf,67) = limit2;
  13487. if(flag) // A timer has changed or been added
  13488. clif_send(buf,packet_len(0x2cd),&sd->bl,PARTY);
  13489. else // No notification
  13490. clif_send(buf,packet_len(0x2cd),&sd->bl,SELF);
  13491. #endif
  13492. return;
  13493. }
  13494. void clif_instance_changestatus(struct map_session_data *sd, int type, unsigned int limit, int flag)
  13495. {
  13496. #if PACKETVER >= 20071128
  13497. unsigned char buf[10];
  13498. if(!sd) return;
  13499. WBUFW(buf,0) = 0x2ce;
  13500. WBUFL(buf,2) = type;
  13501. WBUFL(buf,6) = limit;
  13502. if(flag) // A timer has changed or been added
  13503. clif_send(buf,packet_len(0x2ce),&sd->bl,PARTY);
  13504. else // No notification
  13505. clif_send(buf,packet_len(0x2ce),&sd->bl,SELF);
  13506. #endif
  13507. return;
  13508. }
  13509. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  13510. /// 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
  13511. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  13512. {
  13513. #if PACKETVER >= 20071002
  13514. unsigned char buf[22];
  13515. struct item_data* id = itemdb_search(item_data->nameid);
  13516. WBUFW(buf,0) = 0x2b8;
  13517. WBUFL(buf,2) = sd->status.account_id;
  13518. WBUFW(buf,6) = item_data->nameid;
  13519. WBUFB(buf,8) = item_data->identify;
  13520. WBUFB(buf,9) = item_data->attribute;
  13521. WBUFB(buf,10) = item_data->refine;
  13522. clif_addcards(WBUFP(buf,11), item_data);
  13523. WBUFW(buf,19) = id->equip; // equip location
  13524. WBUFB(buf,21) = itemtype(id->nameid); // item type
  13525. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  13526. #endif
  13527. }
  13528. /// Display gained exp (ZC_NOTIFY_EXP).
  13529. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  13530. /// var id:
  13531. /// SP_BASEEXP, SP_JOBEXP
  13532. /// exp type:
  13533. /// 0 = normal exp gain/loss
  13534. /// 1 = quest exp gain/loss
  13535. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  13536. {
  13537. int fd;
  13538. nullpo_retv(sd);
  13539. fd = sd->fd;
  13540. WFIFOHEAD(fd, packet_len(0x7f6));
  13541. WFIFOW(fd,0) = 0x7f6;
  13542. WFIFOL(fd,2) = sd->bl.id;
  13543. WFIFOL(fd,6) = exp;
  13544. WFIFOW(fd,10) = type;
  13545. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  13546. WFIFOSET(fd,packet_len(0x7f6));
  13547. }
  13548. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  13549. /// type:
  13550. /// 0 = Displays 'value' for 5 seconds.
  13551. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  13552. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  13553. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  13554. /// value:
  13555. /// 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).
  13556. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  13557. {
  13558. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  13559. WFIFOW(sd->fd,0) = 0x1b1;
  13560. WFIFOB(sd->fd,2) = type;
  13561. WFIFOL(sd->fd,3) = value;
  13562. WFIFOSET(sd->fd, packet_len(0x1b1));
  13563. }
  13564. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  13565. /// 021d <state>.L
  13566. /// state:
  13567. /// 0 = Full effects
  13568. /// 1 = Reduced effects
  13569. ///
  13570. /// NOTE: The state is used on Aegis for sending skill unit packet
  13571. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  13572. /// whenever possible. Due to the way the decision check is
  13573. /// constructed, this state tracking was rendered useless,
  13574. /// as the only skill unit, that is sent with 0x1c9 is
  13575. /// Graffiti.
  13576. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  13577. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13578. sd->state.lesseffect = ( isLess != 0 );
  13579. }
  13580. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  13581. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  13582. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13583. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  13584. int type = RFIFOL(fd,info->pos[1]);
  13585. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  13586. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13587. if( sd->state.trading || sd->npc_shopid )
  13588. return;
  13589. if( flag == 0 || n == 0) {
  13590. clif_menuskill_clear(sd);
  13591. return; // Canceled by player.
  13592. }
  13593. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  13594. clif_menuskill_clear(sd);
  13595. return; // Prevent hacking.
  13596. }
  13597. switch( type ) {
  13598. case 0: // Change Material
  13599. skill_changematerial(sd,n,item_list);
  13600. break;
  13601. case 1: // Level 1: Pure to Rough
  13602. case 2: // Level 2: Rough to Pure
  13603. skill_elementalanalysis(sd,n,type,item_list);
  13604. break;
  13605. }
  13606. clif_menuskill_clear(sd);
  13607. return;
  13608. }
  13609. /*==========================================
  13610. * Elemental System
  13611. *==========================================*/
  13612. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  13613. struct elemental_data *ed;
  13614. struct status_data *status;
  13615. int fd;
  13616. if( sd == NULL || (ed = sd->ed) == NULL )
  13617. return;
  13618. fd = sd->fd;
  13619. status = &ed->battle_status;
  13620. WFIFOHEAD(fd,8);
  13621. WFIFOW(fd,0) = 0x81e;
  13622. WFIFOW(fd,2) = type;
  13623. switch( type ) {
  13624. case SP_HP:
  13625. WFIFOL(fd,4) = status->hp;
  13626. break;
  13627. case SP_MAXHP:
  13628. WFIFOL(fd,4) = status->max_hp;
  13629. break;
  13630. case SP_SP:
  13631. WFIFOL(fd,4) = status->sp;
  13632. break;
  13633. case SP_MAXSP:
  13634. WFIFOL(fd,4) = status->max_sp;
  13635. break;
  13636. }
  13637. WFIFOSET(fd,8);
  13638. }
  13639. void clif_elemental_info(struct map_session_data *sd) {
  13640. int fd;
  13641. struct elemental_data *ed;
  13642. struct status_data *status;
  13643. if( sd == NULL || (ed = sd->ed) == NULL )
  13644. return;
  13645. fd = sd->fd;
  13646. status = &ed->battle_status;
  13647. WFIFOHEAD(fd,22);
  13648. WFIFOW(fd, 0) = 0x81d;
  13649. WFIFOL(fd, 2) = ed->bl.id;
  13650. WFIFOL(fd, 6) = status->hp;
  13651. WFIFOL(fd,10) = status->max_hp;
  13652. WFIFOL(fd,14) = status->sp;
  13653. WFIFOL(fd,18) = status->max_sp;
  13654. WFIFOSET(fd,22);
  13655. }
  13656. /// Buying Store System
  13657. ///
  13658. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  13659. /// 0810 <slots>.B
  13660. void clif_buyingstore_open(struct map_session_data* sd)
  13661. {
  13662. int fd = sd->fd;
  13663. WFIFOHEAD(fd,packet_len(0x810));
  13664. WFIFOW(fd,0) = 0x810;
  13665. WFIFOB(fd,2) = sd->buyingstore.slots;
  13666. WFIFOSET(fd,packet_len(0x810));
  13667. }
  13668. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  13669. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  13670. /// result:
  13671. /// 0 = cancel
  13672. /// 1 = open
  13673. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  13674. {
  13675. const unsigned int blocksize = 8;
  13676. uint8* itemlist;
  13677. char storename[MESSAGE_SIZE];
  13678. unsigned char result;
  13679. int zenylimit;
  13680. unsigned int count, packet_len;
  13681. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13682. packet_len = RFIFOW(fd,info->pos[0]);
  13683. // TODO: Make this check global for all variable length packets.
  13684. if( packet_len < 89 )
  13685. {// minimum packet length
  13686. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  13687. return;
  13688. }
  13689. zenylimit = RFIFOL(fd,info->pos[1]);
  13690. result = RFIFOL(fd,info->pos[2]);
  13691. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13692. itemlist = RFIFOP(fd,info->pos[4]);
  13693. // so that buyingstore_create knows, how many elements it has access to
  13694. packet_len-= info->pos[4];
  13695. if( packet_len%blocksize )
  13696. {
  13697. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13698. return;
  13699. }
  13700. count = packet_len/blocksize;
  13701. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13702. }
  13703. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13704. /// 0812 <result>.W <total weight>.L
  13705. /// result:
  13706. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13707. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13708. /// 8 = "No sale (purchase) information available." (0x705)
  13709. /// ? = nothing
  13710. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13711. {
  13712. int fd = sd->fd;
  13713. WFIFOHEAD(fd,packet_len(0x812));
  13714. WFIFOW(fd,0) = 0x812;
  13715. WFIFOW(fd,2) = result;
  13716. WFIFOL(fd,4) = weight;
  13717. WFIFOSET(fd,packet_len(0x812));
  13718. }
  13719. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13720. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13721. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13722. {
  13723. int fd = sd->fd;
  13724. unsigned int i;
  13725. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13726. WFIFOW(fd,0) = 0x813;
  13727. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13728. WFIFOL(fd,4) = sd->bl.id;
  13729. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13730. for( i = 0; i < sd->buyingstore.slots; i++ )
  13731. {
  13732. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13733. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13734. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  13735. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13736. }
  13737. WFIFOSET(fd,WFIFOW(fd,2));
  13738. }
  13739. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13740. /// 0814 <account id>.L <store name>.80B
  13741. void clif_buyingstore_entry(struct map_session_data* sd)
  13742. {
  13743. uint8 buf[86];
  13744. WBUFW(buf,0) = 0x814;
  13745. WBUFL(buf,2) = sd->bl.id;
  13746. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13747. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13748. }
  13749. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13750. {
  13751. int fd = sd->fd;
  13752. WFIFOHEAD(fd,packet_len(0x814));
  13753. WFIFOW(fd,0) = 0x814;
  13754. WFIFOL(fd,2) = pl_sd->bl.id;
  13755. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13756. WFIFOSET(fd,packet_len(0x814));
  13757. }
  13758. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13759. /// 0815
  13760. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13761. {
  13762. buyingstore_close(sd);
  13763. }
  13764. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13765. /// 0816 <account id>.L
  13766. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13767. {
  13768. uint8 buf[6];
  13769. WBUFW(buf,0) = 0x816;
  13770. WBUFL(buf,2) = sd->bl.id;
  13771. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13772. }
  13773. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13774. {
  13775. int fd = sd->fd;
  13776. WFIFOHEAD(fd,packet_len(0x816));
  13777. WFIFOW(fd,0) = 0x816;
  13778. WFIFOL(fd,2) = pl_sd->bl.id;
  13779. WFIFOSET(fd,packet_len(0x816));
  13780. }
  13781. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13782. /// 0817 <account id>.L
  13783. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13784. {
  13785. int account_id;
  13786. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13787. buyingstore_open(sd, account_id);
  13788. }
  13789. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13790. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13791. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13792. {
  13793. int fd = sd->fd;
  13794. unsigned int i;
  13795. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13796. WFIFOW(fd,0) = 0x818;
  13797. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13798. WFIFOL(fd,4) = pl_sd->bl.id;
  13799. WFIFOL(fd,8) = pl_sd->buyer_id;
  13800. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13801. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13802. {
  13803. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13804. 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.
  13805. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  13806. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13807. }
  13808. WFIFOSET(fd,WFIFOW(fd,2));
  13809. }
  13810. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13811. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13812. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13813. {
  13814. const unsigned int blocksize = 6;
  13815. uint8* itemlist;
  13816. int account_id;
  13817. unsigned int count, packet_len, buyer_id;
  13818. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13819. packet_len = RFIFOW(fd,info->pos[0]);
  13820. if( packet_len < 12 )
  13821. {// minimum packet length
  13822. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13823. return;
  13824. }
  13825. account_id = RFIFOL(fd,info->pos[1]);
  13826. buyer_id = RFIFOL(fd,info->pos[2]);
  13827. itemlist = RFIFOP(fd,info->pos[3]);
  13828. // so that buyingstore_trade knows, how many elements it has access to
  13829. packet_len-= info->pos[3];
  13830. if( packet_len%blocksize )
  13831. {
  13832. 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);
  13833. return;
  13834. }
  13835. count = packet_len/blocksize;
  13836. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13837. }
  13838. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13839. /// 081a <result>.W
  13840. /// result:
  13841. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13842. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13843. /// ? = nothing
  13844. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13845. {
  13846. int fd = sd->fd;
  13847. WFIFOHEAD(fd,packet_len(0x81a));
  13848. WFIFOW(fd,0) = 0x81a;
  13849. WFIFOW(fd,2) = result;
  13850. WFIFOSET(fd,packet_len(0x81a));
  13851. }
  13852. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13853. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13854. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13855. {
  13856. int fd = sd->fd;
  13857. WFIFOHEAD(fd,packet_len(0x81b));
  13858. WFIFOW(fd,0) = 0x81b;
  13859. WFIFOW(fd,2) = nameid;
  13860. WFIFOW(fd,4) = amount; // amount of nameid received
  13861. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13862. WFIFOSET(fd,packet_len(0x81b));
  13863. }
  13864. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13865. /// 081c <index>.W <amount>.W <price>.L
  13866. /// message:
  13867. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13868. ///
  13869. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13870. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13871. {
  13872. int fd = sd->fd;
  13873. WFIFOHEAD(fd,packet_len(0x81c));
  13874. WFIFOW(fd,0) = 0x81c;
  13875. WFIFOW(fd,2) = index+2;
  13876. WFIFOW(fd,4) = amount;
  13877. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13878. WFIFOSET(fd,packet_len(0x81c));
  13879. }
  13880. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13881. /// 0824 <result>.W <name id>.W
  13882. /// result:
  13883. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13884. /// 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)
  13885. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13886. /// ? = nothing
  13887. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13888. {
  13889. int fd = sd->fd;
  13890. WFIFOHEAD(fd,packet_len(0x824));
  13891. WFIFOW(fd,0) = 0x824;
  13892. WFIFOW(fd,2) = result;
  13893. WFIFOW(fd,4) = nameid;
  13894. WFIFOSET(fd,packet_len(0x824));
  13895. }
  13896. /// Search Store Info System
  13897. ///
  13898. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13899. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13900. /// type:
  13901. /// 0 = Vending
  13902. /// 1 = Buying Store
  13903. ///
  13904. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13905. /// amount of card slots. If the client does not know about the item it
  13906. /// cannot be searched.
  13907. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13908. {
  13909. const unsigned int blocksize = 2;
  13910. const uint8* itemlist;
  13911. const uint8* cardlist;
  13912. unsigned char type;
  13913. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13914. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13915. packet_len = RFIFOW(fd,info->pos[0]);
  13916. if( packet_len < 15 )
  13917. {// minimum packet length
  13918. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13919. return;
  13920. }
  13921. type = RFIFOB(fd,info->pos[1]);
  13922. max_price = RFIFOL(fd,info->pos[2]);
  13923. min_price = RFIFOL(fd,info->pos[3]);
  13924. item_count = RFIFOB(fd,info->pos[4]);
  13925. card_count = RFIFOB(fd,info->pos[5]);
  13926. itemlist = RFIFOP(fd,info->pos[6]);
  13927. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13928. // check, if there is enough data for the claimed count of items
  13929. packet_len-= info->pos[6];
  13930. if( packet_len%blocksize )
  13931. {
  13932. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13933. return;
  13934. }
  13935. count = packet_len/blocksize;
  13936. if( count < item_count+card_count )
  13937. {
  13938. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13939. return;
  13940. }
  13941. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13942. }
  13943. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13944. /// 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 }*
  13945. /// is first page:
  13946. /// 0 = appends to existing results
  13947. /// 1 = clears previous results before displaying this result set
  13948. /// is next page:
  13949. /// 0 = no "next" label
  13950. /// 1 = "next" label to retrieve more results
  13951. void clif_search_store_info_ack(struct map_session_data* sd)
  13952. {
  13953. const unsigned int blocksize = MESSAGE_SIZE+26;
  13954. int fd = sd->fd;
  13955. unsigned int i, start, end;
  13956. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13957. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13958. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13959. WFIFOW(fd,0) = 0x836;
  13960. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13961. WFIFOB(fd,4) = !sd->searchstore.pages;
  13962. WFIFOB(fd,5) = searchstore_querynext(sd);
  13963. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13964. for( i = start; i < end; i++ ) {
  13965. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13966. struct item it;
  13967. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13968. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13969. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13970. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13971. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  13972. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13973. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13974. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13975. // make-up an item for clif_addcards
  13976. memset(&it, 0, sizeof(it));
  13977. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13978. it.nameid = ssitem->nameid;
  13979. it.amount = ssitem->amount;
  13980. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13981. }
  13982. WFIFOSET(fd,WFIFOW(fd,2));
  13983. }
  13984. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13985. /// 0837 <reason>.B
  13986. /// reason:
  13987. /// 0 = "No matching stores were found." (0x70b)
  13988. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13989. /// 2 = "You cannot search anymore." (0x706)
  13990. /// 3 = "You cannot search yet." (0x708)
  13991. /// 4 = "No sale (purchase) information available." (0x705)
  13992. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13993. {
  13994. int fd = sd->fd;
  13995. WFIFOHEAD(fd,packet_len(0x837));
  13996. WFIFOW(fd,0) = 0x837;
  13997. WFIFOB(fd,2) = reason;
  13998. WFIFOSET(fd,packet_len(0x837));
  13999. }
  14000. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  14001. /// 0838
  14002. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  14003. {
  14004. searchstore_next(sd);
  14005. }
  14006. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  14007. /// 083a <type>.W <remaining uses>.B
  14008. /// type:
  14009. /// 0 = Search Stores
  14010. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  14011. void clif_open_search_store_info(struct map_session_data* sd)
  14012. {
  14013. int fd = sd->fd;
  14014. WFIFOHEAD(fd,packet_len(0x83a));
  14015. WFIFOW(fd,0) = 0x83a;
  14016. WFIFOW(fd,2) = sd->searchstore.effect;
  14017. #if PACKETVER > 20100701
  14018. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  14019. #endif
  14020. WFIFOSET(fd,packet_len(0x83a));
  14021. }
  14022. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  14023. /// 083b
  14024. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  14025. {
  14026. searchstore_close(sd);
  14027. }
  14028. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  14029. /// 083c <account id>.L <store id>.L <nameid>.W
  14030. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  14031. {
  14032. unsigned short nameid;
  14033. int account_id, store_id;
  14034. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14035. account_id = RFIFOL(fd,info->pos[0]);
  14036. store_id = RFIFOL(fd,info->pos[1]);
  14037. nameid = RFIFOW(fd,info->pos[2]);
  14038. searchstore_click(sd, account_id, store_id, nameid);
  14039. }
  14040. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  14041. /// 083d <xPos>.W <yPos>.W
  14042. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  14043. {
  14044. int fd = sd->fd;
  14045. WFIFOHEAD(fd,packet_len(0x83d));
  14046. WFIFOW(fd,0) = 0x83d;
  14047. WFIFOW(fd,2) = x;
  14048. WFIFOW(fd,4) = y;
  14049. WFIFOSET(fd,packet_len(0x83d));
  14050. }
  14051. /// Parse function for packet debugging.
  14052. void clif_parse_debug(int fd,struct map_session_data *sd)
  14053. {
  14054. int cmd, packet_len;
  14055. // clif_parse ensures, that there is at least 2 bytes of data
  14056. cmd = RFIFOW(fd,0);
  14057. if( sd ) {
  14058. packet_len = packet_db[sd->packet_ver][cmd].len;
  14059. if( packet_len == 0 )
  14060. {// unknown
  14061. packet_len = RFIFOREST(fd);
  14062. }
  14063. else if( packet_len == -1 )
  14064. {// variable length
  14065. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  14066. }
  14067. 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);
  14068. }
  14069. else
  14070. {
  14071. packet_len = RFIFOREST(fd);
  14072. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  14073. }
  14074. ShowDump(RFIFOP(fd,0), packet_len);
  14075. }
  14076. /*==========================================
  14077. * Server tells client to display a window similar to Magnifier (item) one
  14078. * Server populates the window with avilable elemental converter options according to player's inventory
  14079. *------------------------------------------*/
  14080. int clif_elementalconverter_list(struct map_session_data *sd) {
  14081. int i,c,view,fd;
  14082. nullpo_ret(sd);
  14083. /// Main client packet processing function
  14084. fd=sd->fd;
  14085. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  14086. WFIFOW(fd, 0)=0x1ad;
  14087. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  14088. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  14089. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  14090. WFIFOW(fd,c*2+ 4)= view;
  14091. else
  14092. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  14093. c++;
  14094. }
  14095. }
  14096. WFIFOW(fd,2) = c*2+4;
  14097. WFIFOSET(fd, WFIFOW(fd,2));
  14098. if (c > 0) {
  14099. sd->menuskill_id = SA_CREATECON;
  14100. sd->menuskill_val = c;
  14101. }
  14102. return 0;
  14103. }
  14104. /**
  14105. * Rune Knight
  14106. **/
  14107. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  14108. #if PACKETVER >= 20081217
  14109. unsigned char buf[10];
  14110. WBUFW(buf,0) = 0x440;
  14111. WBUFL(buf,2) = sd->bl.id;
  14112. WBUFW(buf,6) = shields;
  14113. WBUFW(buf,8) = 0;
  14114. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  14115. #endif
  14116. }
  14117. /**
  14118. * Warlock
  14119. **/
  14120. /*==========================================
  14121. * Spellbook list [LimitLine/3CeAM]
  14122. *------------------------------------------*/
  14123. int clif_spellbook_list(struct map_session_data *sd)
  14124. {
  14125. int i, c;
  14126. int fd;
  14127. nullpo_ret(sd);
  14128. fd = sd->fd;
  14129. WFIFOHEAD(fd, 8 * 8 + 8);
  14130. WFIFOW(fd,0) = 0x1ad;
  14131. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  14132. {
  14133. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  14134. {
  14135. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14136. c++;
  14137. }
  14138. }
  14139. if( c > 0 )
  14140. {
  14141. WFIFOW(fd,2) = c * 2 + 4;
  14142. WFIFOSET(fd, WFIFOW(fd, 2));
  14143. sd->menuskill_id = WL_READING_SB;
  14144. sd->menuskill_val = c;
  14145. }
  14146. else{
  14147. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14148. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  14149. }
  14150. return 1;
  14151. }
  14152. /**
  14153. * Mechanic
  14154. **/
  14155. /*==========================================
  14156. * Magic Decoy Material List
  14157. *------------------------------------------*/
  14158. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  14159. int i, c;
  14160. int fd;
  14161. nullpo_ret(sd);
  14162. fd = sd->fd;
  14163. WFIFOHEAD(fd, 8 * 8 + 8);
  14164. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14165. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14166. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  14167. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14168. c ++;
  14169. }
  14170. }
  14171. if( c > 0 ) {
  14172. sd->menuskill_id = NC_MAGICDECOY;
  14173. sd->menuskill_val = skill_lv;
  14174. sd->sc.comet_x = x;
  14175. sd->sc.comet_y = y;
  14176. WFIFOW(fd,2) = c * 2 + 4;
  14177. WFIFOSET(fd, WFIFOW(fd, 2));
  14178. } else {
  14179. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  14180. return 0;
  14181. }
  14182. return 1;
  14183. }
  14184. /*==========================================
  14185. * Guillotine Cross Poisons List
  14186. *------------------------------------------*/
  14187. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  14188. int i, c;
  14189. int fd;
  14190. nullpo_ret(sd);
  14191. fd = sd->fd;
  14192. WFIFOHEAD(fd, 8 * 8 + 8);
  14193. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  14194. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  14195. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  14196. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  14197. c ++;
  14198. }
  14199. }
  14200. if( c > 0 ) {
  14201. sd->menuskill_id = GC_POISONINGWEAPON;
  14202. sd->menuskill_val = skill_lv;
  14203. WFIFOW(fd,2) = c * 2 + 4;
  14204. WFIFOSET(fd, WFIFOW(fd, 2));
  14205. } else {
  14206. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  14207. return 0;
  14208. }
  14209. return 1;
  14210. }
  14211. int clif_autoshadowspell_list(struct map_session_data *sd) {
  14212. int fd, i, c;
  14213. nullpo_ret(sd);
  14214. fd = sd->fd;
  14215. if( !fd ) return 0;
  14216. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  14217. return 0;
  14218. WFIFOHEAD(fd, 2 * 6 + 4);
  14219. WFIFOW(fd,0) = 0x442;
  14220. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  14221. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  14222. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  14223. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  14224. {
  14225. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  14226. c++;
  14227. }
  14228. if( c > 0 ) {
  14229. WFIFOW(fd,2) = 8 + c * 2;
  14230. WFIFOL(fd,4) = c;
  14231. WFIFOSET(fd,WFIFOW(fd,2));
  14232. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  14233. sd->menuskill_val = c;
  14234. } else {
  14235. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  14236. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  14237. }
  14238. return 1;
  14239. }
  14240. /*===========================================
  14241. * Skill list for Four Elemental Analysis
  14242. * and Change Material skills.
  14243. *------------------------------------------*/
  14244. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  14245. {
  14246. #if PACKETVER >= 20090922
  14247. int fd;
  14248. nullpo_ret(sd);
  14249. sd->menuskill_id = skill_id; // To prevent hacking.
  14250. sd->menuskill_val = skill_lv;
  14251. if( skill_id == GN_CHANGEMATERIAL )
  14252. skill_lv = 0; // Changematerial
  14253. fd = sd->fd;
  14254. WFIFOHEAD(fd,packet_len(0x7e3));
  14255. WFIFOW(fd,0) = 0x7e3;
  14256. WFIFOL(fd,2) = skill_lv;
  14257. WFIFOL(fd,4) = 0;
  14258. WFIFOSET(fd,packet_len(0x7e3));
  14259. #endif
  14260. return 1;
  14261. }
  14262. // msgstringtable.txt
  14263. // 0x291 <line>.W
  14264. void clif_msgtable(int fd, int line) {
  14265. WFIFOHEAD(fd, packet_len(0x291));
  14266. WFIFOW(fd, 0) = 0x291;
  14267. WFIFOW(fd, 2) = line;
  14268. WFIFOSET(fd, packet_len(0x291));
  14269. }
  14270. // msgstringtable.txt
  14271. // 0x7e2 <line>.W <value>.L
  14272. void clif_msgtable_num(int fd, int line, int num) {
  14273. #if PACKETVER >= 20090805
  14274. WFIFOHEAD(fd, packet_len(0x7e2));
  14275. WFIFOW(fd, 0) = 0x7e2;
  14276. WFIFOW(fd, 2) = line;
  14277. WFIFOL(fd, 4) = num;
  14278. WFIFOSET(fd, packet_len(0x7e2));
  14279. #endif
  14280. }
  14281. /*==========================================
  14282. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  14283. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  14284. * RFIFOL(fd,2) - type (currently not used)
  14285. *------------------------------------------*/
  14286. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  14287. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14288. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  14289. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  14290. return;
  14291. if( pc_istrading(sd) ) {
  14292. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  14293. clif_menuskill_clear(sd);
  14294. return;
  14295. }
  14296. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  14297. clif_menuskill_clear(sd);
  14298. }
  14299. /*==========================================
  14300. * Kagerou/Oboro amulet spirit
  14301. *------------------------------------------*/
  14302. void clif_talisman(struct map_session_data *sd,short type)
  14303. {
  14304. unsigned char buf[10];
  14305. nullpo_retv(sd);
  14306. WBUFW(buf,0)=0x08cf;
  14307. WBUFL(buf,2)=sd->bl.id;
  14308. WBUFW(buf,6)=type;
  14309. WBUFW(buf,8)=sd->talisman[type];
  14310. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  14311. }
  14312. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  14313. /// 0907 <index>.W
  14314. ///
  14315. /// R 0908 <index>.w <type>.b
  14316. /// type:
  14317. /// 0 = move item to personal tab
  14318. /// 1 = move item to normal tab
  14319. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  14320. #if PACKETVER >= 20111122
  14321. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14322. int index = RFIFOW(fd,info->pos[0])-2;
  14323. int type = RFIFOB(fd, info->pos[1]);
  14324. /* can't move while dead. */
  14325. if(pc_isdead(sd)) {
  14326. return;
  14327. }
  14328. if (index < 0 || index >= MAX_INVENTORY)
  14329. return;
  14330. if ( sd->status.inventory[index].favorite && type == 1 )
  14331. sd->status.inventory[index].favorite = 0;
  14332. else if( type == 0 )
  14333. sd->status.inventory[index].favorite = 1;
  14334. else
  14335. return;/* nothing to do. */
  14336. clif_favorite_item(sd, index);
  14337. #endif
  14338. }
  14339. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  14340. /// 0900 <index>.W <favorite>.B
  14341. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  14342. int fd = sd->fd;
  14343. WFIFOHEAD(fd,packet_len(0x908));
  14344. WFIFOW(fd,0) = 0x908;
  14345. WFIFOW(fd,2) = index+2;
  14346. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  14347. WFIFOSET(fd,packet_len(0x908));
  14348. }
  14349. void clif_snap( struct block_list *bl, short x, short y ) {
  14350. unsigned char buf[10];
  14351. WBUFW(buf,0) = 0x8d2;
  14352. WBUFL(buf,2) = bl->id;
  14353. WBUFW(buf,6) = x;
  14354. WBUFW(buf,8) = y;
  14355. clif_send(buf,packet_len(0x8d2),bl,AREA);
  14356. }
  14357. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  14358. #if PACKETVER >= 20120404
  14359. WFIFOHEAD(fd,packet_len(0x977));
  14360. WFIFOW(fd,0) = 0x977;
  14361. WFIFOL(fd,2) = md->bl.id;
  14362. WFIFOL(fd,6) = md->status.hp;
  14363. WFIFOL(fd,10) = md->status.max_hp;
  14364. WFIFOSET(fd,packet_len(0x977));
  14365. #endif
  14366. }
  14367. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  14368. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  14369. return;
  14370. }
  14371. void clif_partytickack(struct map_session_data* sd, bool flag) {
  14372. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  14373. WFIFOW(sd->fd,0) = 0x2c9;
  14374. WFIFOB(sd->fd,2) = flag;
  14375. WFIFOSET(sd->fd, packet_len(0x2c9));
  14376. }
  14377. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  14378. /// 0979 <world name>.24B <char name>.24B
  14379. void clif_ackworldinfo(struct map_session_data* sd) {
  14380. int fd;
  14381. nullpo_retv(sd);
  14382. fd = sd->fd;
  14383. WFIFOHEAD(fd,packet_len(0x979));
  14384. WFIFOW(fd,0)=0x979;
  14385. //AID -> world name ?
  14386. safestrncpy((char*)WFIFOP(fd,2), "" /* World name */, 24);
  14387. safestrncpy((char*)WFIFOP(fd,26), sd->status.name, NAME_LENGTH);
  14388. WFIFOSET(fd,packet_len(0x979));
  14389. }
  14390. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  14391. /// 0978 <AID>.L
  14392. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd){
  14393. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  14394. if(sd) clif_ackworldinfo(sd);
  14395. }
  14396. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  14397. /// 0447
  14398. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd){
  14399. //if(sd)
  14400. ;
  14401. }
  14402. /// req world info (CZ_CLIENT_VERSION)
  14403. /// 044A <version>.L
  14404. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  14405. //if(sd)
  14406. ;
  14407. }
  14408. /// Ranking list
  14409. /// ranking pointlist { <name>.24B <point>.L }*10
  14410. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, int16 rankingtype){
  14411. const char* name;
  14412. struct fame_list* list;
  14413. int skip = 0;
  14414. switch(rankingtype+1) //to keep the same case as char.c
  14415. {
  14416. case 1: list = smith_fame_list; break;
  14417. case 2: list = chemist_fame_list; break;
  14418. case 3: list = taekwon_fame_list; break;
  14419. default: skip=1; break;
  14420. }
  14421. if(!skip) {
  14422. int i;
  14423. //Packet size limits this list to 10 elements. [Skotlex]
  14424. for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
  14425. if (list[i].id > 0) {
  14426. if (strcmp(list[i].name, "-") == 0 &&
  14427. (name = map_charid2nick(list[i].id)) != NULL)
  14428. {
  14429. strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
  14430. } else {
  14431. strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
  14432. }
  14433. } else {
  14434. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
  14435. }
  14436. WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
  14437. }
  14438. for(;i < 10; i++) { //In case the MAX is less than 10.
  14439. strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
  14440. WBUFL(buf, idx+24*10 + i * 4) = 0;
  14441. }
  14442. }
  14443. }
  14444. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  14445. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  14446. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)];
  14447. int mypoint = 0;
  14448. WBUFW(buf,0) = 0x97d;
  14449. WBUFW(buf,2) = rankingType;
  14450. clif_sub_ranklist(buf,4,sd,rankingType);
  14451. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  14452. case MAPID_BLACKSMITH:
  14453. case MAPID_ALCHEMIST:
  14454. case MAPID_TAEKWON:
  14455. mypoint = sd->status.fame;
  14456. }
  14457. WBUFL(buf,284) = mypoint; //mypoint
  14458. clif_send(buf, 288, &sd->bl, SELF);
  14459. }
  14460. /*
  14461. * 097c <type> (CZ_REQ_RANKING)
  14462. * type
  14463. * 0: /blacksmith
  14464. * 1: /alchemist
  14465. * 2: /taekwon
  14466. * 3: /pk
  14467. * */
  14468. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  14469. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  14470. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  14471. if(rankingtype != 3) clif_ranklist(sd,rankingtype); // pk_list unsuported atm
  14472. }
  14473. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  14474. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  14475. #if PACKETVER < 20130710
  14476. switch(rankingtype){
  14477. case 0: clif_fame_blacksmith(sd,point); break; // Blacksmith
  14478. case 1: clif_fame_alchemist(sd,point); break; //Alchemist
  14479. case 2: clif_fame_taekwon(sd,point); break; // Taekwon
  14480. }
  14481. #else
  14482. int fd=sd->fd;
  14483. WFIFOHEAD(fd,14);
  14484. WFIFOW(fd,0) = 0x97e;
  14485. WFIFOW(fd,2) = rankingtype;
  14486. WFIFOL(fd,4) = point;
  14487. WFIFOL(fd,8) = sd->status.fame;
  14488. WFIFOSET(fd,12);
  14489. #endif
  14490. }
  14491. /**
  14492. * Transmit personal information to player. (rates)
  14493. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  14494. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  14495. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  14496. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  14497. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  14498. * FIXME!
  14499. * - Find/decide for details of EXP, Drop, and Death penalty rates
  14500. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  14501. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  14502. */
  14503. #ifdef VIP_ENABLE
  14504. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  14505. if (sd) {
  14506. struct s_packet_db* info;
  14507. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  14508. int cmd = 0, fd, i = 0;
  14509. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  14510. int details_bexp[PINFO_MAX];
  14511. int details_drop[PINFO_MAX];
  14512. int details_penalty[PINFO_MAX];
  14513. int penalty_const;
  14514. /**
  14515. * Set for EXP
  14516. */
  14517. //0:PCRoom
  14518. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  14519. if (details_bexp[0] == 100 || details_bexp[0] == 0)
  14520. details_bexp[0] = 0;
  14521. else {
  14522. if (details_bexp[0] < 100) {
  14523. details_bexp[0] = 100 - details_bexp[0];
  14524. details_bexp[0] = 0 - details_bexp[0];
  14525. }
  14526. else
  14527. details_bexp[0] = details_bexp[0] - 100;
  14528. }
  14529. //1:Premium
  14530. if (pc_isvip(sd)) {
  14531. details_bexp[1] = battle_config.vip_base_exp_increase;
  14532. if (details_bexp[1] < 0)
  14533. details_bexp[1] = 0 - details_bexp[1];
  14534. }
  14535. else
  14536. details_bexp[1] = 0;
  14537. //2:Server
  14538. details_bexp[2] = battle_config.base_exp_rate;
  14539. if (details_bexp[2] == 100)
  14540. details_bexp[2] = 0;
  14541. else {
  14542. if (details_bexp[2] < 100) {
  14543. details_bexp[2] = 100 - details_bexp[2];
  14544. details_bexp[2] = 0 - details_bexp[2];
  14545. }
  14546. else
  14547. details_bexp[2] = details_bexp[2] - 100;
  14548. }
  14549. //3:TPLUS
  14550. details_bexp[3] = 0;
  14551. /* End - EXP set*/
  14552. /**
  14553. * Set for Drop rate
  14554. */
  14555. //0:PCRoom
  14556. details_drop[0] = 0;
  14557. //1:Premium
  14558. details_drop[1] = battle_config.vip_drop_increase;
  14559. if (pc_isvip(sd)) {
  14560. if (details_drop[1] < 0)
  14561. details_drop[1] = 0 - details_drop[1];
  14562. }
  14563. else
  14564. details_drop[1] = 0;
  14565. //2:Server
  14566. details_drop[2] = battle_config.item_rate_common;
  14567. if (details_drop[2] == 100)
  14568. details_drop[2] = 0;
  14569. else {
  14570. if (details_drop[2] < 100) {
  14571. details_drop[2] = 100 - details_drop[2];
  14572. details_drop[2] = 0 - details_drop[2];
  14573. }
  14574. else
  14575. details_drop[2] = details_drop[2] - 100;
  14576. }
  14577. //3:TPLUS
  14578. details_drop[3] = 0;
  14579. /* End - Drop set*/
  14580. /**
  14581. * Set for Penalty rate
  14582. */
  14583. //! FIXME: Current penalty system, makes this announcement hardly to gives info + or - rate
  14584. penalty_const = battle_config.death_penalty_base * battle_config.vip_exp_penalty_base_normal;
  14585. //0:PCRoom
  14586. details_penalty[0] = 0;
  14587. //1:Premium
  14588. if (pc_isvip(sd)) {
  14589. details_penalty[1] = battle_config.vip_exp_penalty_base * 10000 / penalty_const;
  14590. if (details_penalty[1] == 100)
  14591. details_penalty[1] = 0;
  14592. else {
  14593. if (details_penalty[1] < 100) {
  14594. details_penalty[1] = 100 - details_penalty[1];
  14595. details_penalty[1] = 0 - details_penalty[1];
  14596. }
  14597. else
  14598. details_penalty[1] = details_penalty[1] - 100;
  14599. }
  14600. }
  14601. else
  14602. details_penalty[1] = 0;
  14603. //2:Server
  14604. details_penalty[2] = battle_config.vip_exp_penalty_base_normal * 10000 / penalty_const;
  14605. if (details_penalty[2] == 100)
  14606. details_penalty[2] = 0;
  14607. else {
  14608. if (details_penalty[2] < 100) {
  14609. details_penalty[2] = 100 - details_penalty[2];
  14610. details_penalty[2] = 0 - details_penalty[2];
  14611. }
  14612. else
  14613. details_penalty[2] = details_penalty[2] - 100;
  14614. }
  14615. //3:TPLUS
  14616. details_penalty[3] = 0;
  14617. /* End - Penalty set*/
  14618. cmd = packet_db_ack[sd->packet_ver][cmdtype];
  14619. info = &packet_db[sd->packet_ver][cmd];
  14620. len = info->len; //this is the base len without details
  14621. if(!len) return; //version as packet disable
  14622. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  14623. szdetails = 7;
  14624. factor = 1;
  14625. }
  14626. else if (cmd == 0x097b) {
  14627. tot_baseexp *= factor;
  14628. tot_drop *= factor;
  14629. tot_penalty *= factor;
  14630. }
  14631. fd = sd->fd;
  14632. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  14633. WFIFOW(fd,0) = cmd;
  14634. for (i = 0; i < maxinfotype; i++) {
  14635. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  14636. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  14637. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  14638. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  14639. tot_baseexp += details_bexp[i]*factor;
  14640. tot_drop += details_penalty[i]*factor;
  14641. tot_penalty += details_drop[i]*factor;
  14642. len += szdetails;
  14643. }
  14644. WFIFOW(fd,info->pos[0]) = len; //packetlen
  14645. if (cmd == 0x08cb) { //0x08cb version
  14646. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  14647. WFIFOW(fd,info->pos[2]) = tot_drop;
  14648. WFIFOW(fd,info->pos[3]) = tot_penalty;
  14649. }
  14650. else { //2013-08-07aRagexe uses 0x097b
  14651. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  14652. WFIFOL(fd,info->pos[2]) = tot_drop;
  14653. WFIFOL(fd,info->pos[3]) = tot_penalty;
  14654. }
  14655. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  14656. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  14657. WFIFOSET(fd,len);
  14658. }
  14659. }
  14660. #endif
  14661. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  14662. char cmd[30];
  14663. int t_aid = RFIFOL(fd,2);
  14664. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  14665. is_atcommand(fd, sd, cmd, 1);
  14666. }
  14667. /**
  14668. * Marks Crimson Marker target on mini-map to the caster
  14669. * TODO: Please, check the proper packet for Crimson Marker [Cydh]
  14670. * @param fd
  14671. * @param bl Crimson Marker target
  14672. * @param remove True remove the marker from map, false therwise
  14673. **/
  14674. void clif_crimson_marker(int fd, struct block_list *bl, bool remove) {
  14675. WFIFOHEAD(fd,packet_len(0x107));
  14676. WFIFOW(fd,0) = 0x107;
  14677. WFIFOL(fd,2) = bl->id;
  14678. WFIFOW(fd,6) = (remove) ? -1 : bl->x;
  14679. WFIFOW(fd,8) = (remove) ? -1 : bl->y;
  14680. WFIFOSET(fd,packet_len(0x107));
  14681. }
  14682. ///TODO: Special item that obtained, must be broadcasted by this packet
  14683. //void clif_broadcast_obtain_special_item() {}
  14684. #ifdef DUMP_UNKNOWN_PACKET
  14685. void DumpUnknow(int fd,TBL_PC *sd,int cmd,int packet_len){
  14686. const char* packet_txt = "save/packet.txt";
  14687. FILE* fp;
  14688. time_t time_server;
  14689. struct tm *datetime;
  14690. char datestr[512];
  14691. time(&time_server); // get time in seconds since 1/1/1970
  14692. datetime = localtime(&time_server); // convert seconds in structure
  14693. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  14694. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  14695. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  14696. if( sd ) {
  14697. 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);
  14698. } else {
  14699. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14700. }
  14701. WriteDump(fp, RFIFOP(fd,0), packet_len);
  14702. fprintf(fp, "\n");
  14703. fclose(fp);
  14704. } else {
  14705. ShowError("Failed to write '%s'.\n", packet_txt);
  14706. // Dump on console instead
  14707. if( sd ) {
  14708. 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);
  14709. } else {
  14710. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  14711. }
  14712. ShowDump(RFIFOP(fd,0), packet_len);
  14713. }
  14714. }
  14715. #endif
  14716. /*==========================================
  14717. * Main client packet processing function
  14718. *------------------------------------------*/
  14719. static int clif_parse(int fd)
  14720. {
  14721. int cmd, packet_ver, packet_len, err;
  14722. TBL_PC* sd;
  14723. int pnum;
  14724. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  14725. // Note: "click masters" can do 80+ clicks in 10 seconds
  14726. 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]
  14727. { // begin main client packet processing loop
  14728. sd = (TBL_PC *)session[fd]->session_data;
  14729. if (session[fd]->flag.eof) {
  14730. if (sd) {
  14731. if (sd->state.autotrade) {
  14732. //Disassociate character from the socket connection.
  14733. session[fd]->session_data = NULL;
  14734. sd->fd = 0;
  14735. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  14736. } else
  14737. if (sd->state.active) {
  14738. // Player logout display [Valaris]
  14739. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  14740. clif_quitsave(fd, sd);
  14741. } else {
  14742. //Unusual logout (during log on/off/map-changer procedure)
  14743. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  14744. map_quit(sd);
  14745. }
  14746. } else {
  14747. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  14748. }
  14749. do_close(fd);
  14750. return 0;
  14751. }
  14752. if (RFIFOREST(fd) < 2)
  14753. return 0;
  14754. cmd = RFIFOW(fd,0);
  14755. // identify client's packet version
  14756. if (sd) {
  14757. packet_ver = sd->packet_ver;
  14758. } else {
  14759. // check authentification packet to know packet version
  14760. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  14761. if( err ) {// failed to identify packet version
  14762. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  14763. err == 1 ? "" :
  14764. err == 2 ? ", possibly for having an invalid account_id" :
  14765. err == 3 ? ", possibly for having an invalid char_id." :
  14766. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  14767. err == 4 ? ", possibly for having an invalid login_id1." :
  14768. err == 5 ? ", possibly for having an invalid client_tick." :
  14769. */
  14770. err == 6 ? ", possibly for having an invalid sex." :
  14771. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  14772. WFIFOHEAD(fd,packet_len(0x6a));
  14773. WFIFOW(fd,0) = 0x6a;
  14774. WFIFOB(fd,2) = 3; // Rejected from Server
  14775. WFIFOSET(fd,packet_len(0x6a));
  14776. #ifdef DUMP_INVALID_PACKET
  14777. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14778. #endif
  14779. RFIFOSKIP(fd, RFIFOREST(fd));
  14780. set_eof(fd);
  14781. return 0;
  14782. }
  14783. }
  14784. // filter out invalid / unsupported packets
  14785. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  14786. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  14787. #ifdef DUMP_INVALID_PACKET
  14788. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14789. #endif
  14790. set_eof(fd);
  14791. return 0;
  14792. }
  14793. // determine real packet length
  14794. packet_len = packet_db[packet_ver][cmd].len;
  14795. if (packet_len == -1) { // variable-length packet
  14796. if (RFIFOREST(fd) < 4)
  14797. return 0;
  14798. packet_len = RFIFOW(fd,2);
  14799. if (packet_len < 4 || packet_len > 32768) {
  14800. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  14801. #ifdef DUMP_INVALID_PACKET
  14802. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  14803. #endif
  14804. set_eof(fd);
  14805. return 0;
  14806. }
  14807. }
  14808. if ((int)RFIFOREST(fd) < packet_len)
  14809. return 0; // not enough data received to form the packet
  14810. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  14811. packet_db[packet_ver][cmd].func(fd, sd);
  14812. else if( packet_db[packet_ver][cmd].func != NULL ) {
  14813. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  14814. ; //Only valid packet when there is no session
  14815. else
  14816. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  14817. ; //Only valid packet when player is not on a map
  14818. else
  14819. packet_db[packet_ver][cmd].func(fd, sd);
  14820. }
  14821. #ifdef DUMP_UNKNOWN_PACKET
  14822. else DumpUnknow(fd,sd,cmd,packet_len);
  14823. #endif
  14824. RFIFOSKIP(fd, packet_len);
  14825. }; // main loop end
  14826. return 0;
  14827. }
  14828. /*==========================================
  14829. * Reads packet_db.txt and setups its array reference
  14830. *------------------------------------------*/
  14831. void packetdb_readdb(void)
  14832. {
  14833. FILE *fp;
  14834. char line[1024];
  14835. int ln=0, entries=0;
  14836. int cmd,i,j,packet_ver;
  14837. int max_cmd=-1;
  14838. bool skip_ver = false;
  14839. int warned = 0;
  14840. char *str[64],*p,*str2[64],*p2,w1[256],w2[256];
  14841. int packet_len_table[MAX_PACKET_DB] = {
  14842. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14846. //#0x0040
  14847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14849. #if PACKETVER <= 20081217
  14850. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  14851. #else
  14852. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  14853. #endif
  14854. #if PACKETVER < 2
  14855. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  14856. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  14857. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  14858. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  14859. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  14860. #else
  14861. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  14862. #endif
  14863. //#0x0080
  14864. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  14865. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  14866. #if PACKETVER <= 20100622
  14867. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  14868. #else
  14869. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  14870. #endif
  14871. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  14872. //#0x00C0
  14873. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  14874. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  14875. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  14876. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  14877. //#0x0100
  14878. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  14879. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  14880. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  14881. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  14882. //#0x0140
  14883. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  14884. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  14885. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  14886. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  14887. //#0x0180
  14888. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  14889. #if PACKETVER < 1
  14890. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14891. #else // 196 comodo icon status display for later
  14892. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  14893. #endif
  14894. #if PACKETVER < 20081126
  14895. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14896. #else // 0x1a2 changed (35->37)
  14897. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  14898. #endif
  14899. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  14900. //#0x01C0, Set 0x1d5=-1
  14901. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  14902. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  14903. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  14904. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  14905. //#0x0200
  14906. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  14907. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  14908. #if PACKETVER < 20071106
  14909. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  14910. #else // 0x22c changed
  14911. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  14912. #endif
  14913. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  14914. //#0x0240
  14915. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  14916. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  14917. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14918. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14919. //#0x0280
  14920. #if PACKETVER < 20070711
  14921. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  14922. #else
  14923. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  14924. #endif
  14925. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  14926. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14927. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  14928. //#0x02C0
  14929. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  14930. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  14931. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  14932. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14933. //#0x0300
  14934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14938. //#0x0340
  14939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14943. //#0x0380
  14944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14948. //#0x03C0
  14949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14953. //#0x0400
  14954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14958. //#0x0440
  14959. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14963. //#0x0480
  14964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14968. //#0x04C0
  14969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14973. //#0x0500
  14974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14978. //#0x0540
  14979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14983. //#0x0580
  14984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14988. //#0x05C0
  14989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14993. //#0x0600
  14994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14998. //#0x0640
  14999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15003. //#0x0680
  15004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15008. //#0x06C0
  15009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15013. //#0x0700
  15014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  15018. //#0x0740
  15019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15023. //#0x0780
  15024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15028. //#0x07C0
  15029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15030. #if PACKETVER < 20090617
  15031. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  15032. #else // 0x7d9 changed
  15033. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  15034. #endif
  15035. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  15036. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  15037. //#0x0800
  15038. #if PACKETVER < 20091229
  15039. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  15040. #else // for Party booking ( PACKETVER >= 20091229 )
  15041. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  15042. #endif
  15043. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  15044. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15045. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  15046. //#0x0840
  15047. #if PACKETVER < 20130000
  15048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15049. #else
  15050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 19, 0, 0, 0, 0,
  15051. #endif
  15052. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  15053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15055. //#0x0880
  15056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15060. //#0x08C0
  15061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  15062. 9, 7, 10, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15065. //#0x0900
  15066. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  15067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15070. //#0x0940
  15071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15074. 0, 0, 0, 0, 0, 0, 0, 14, 6, 50, 0, 0, 0, 0, 0, 0,
  15075. //#0x0980
  15076. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15077. 31, 0, 0, 0, 0, 0, 0, -1, 8, 11, 9, 8, 0, 0, 0, 0,
  15078. 0, 0, 0, 0, 0, 0, 12, 10, 14, 10, 14, 6, 0, 0, 0, 0,
  15079. 0, 0, 0, 0, 0, 0, 6, 4, 6, 4, 0, 0, 0, 0, 0, 0,
  15080. //#0x09C0
  15081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,102, 0,
  15082. 0, 0, 0, 0, 2, 0, -1, 0, 2, 0, 0, 0, 0, 0, 0, 7,
  15083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15085. };
  15086. struct {
  15087. void (*func)(int, struct map_session_data *);
  15088. char *name;
  15089. } clif_parse_func[]={
  15090. {clif_parse_WantToConnection,"wanttoconnection"},
  15091. {clif_parse_LoadEndAck,"loadendack"},
  15092. {clif_parse_TickSend,"ticksend"},
  15093. {clif_parse_WalkToXY,"walktoxy"},
  15094. {clif_parse_QuitGame,"quitgame"},
  15095. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  15096. {clif_parse_GlobalMessage,"globalmessage"},
  15097. {clif_parse_MapMove,"mapmove"},
  15098. {clif_parse_ChangeDir,"changedir"},
  15099. {clif_parse_Emotion,"emotion"},
  15100. {clif_parse_HowManyConnections,"howmanyconnections"},
  15101. {clif_parse_ActionRequest,"actionrequest"},
  15102. {clif_parse_Restart,"restart"},
  15103. {clif_parse_WisMessage,"wis"},
  15104. {clif_parse_Broadcast,"broadcast"},
  15105. {clif_parse_TakeItem,"takeitem"},
  15106. {clif_parse_DropItem,"dropitem"},
  15107. {clif_parse_UseItem,"useitem"},
  15108. {clif_parse_EquipItem,"equipitem"},
  15109. {clif_parse_UnequipItem,"unequipitem"},
  15110. {clif_parse_NpcClicked,"npcclicked"},
  15111. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  15112. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  15113. {clif_parse_NpcSellListSend,"npcselllistsend"},
  15114. {clif_parse_CreateChatRoom,"createchatroom"},
  15115. {clif_parse_ChatAddMember,"chataddmember"},
  15116. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  15117. {clif_parse_ChangeChatOwner,"changechatowner"},
  15118. {clif_parse_KickFromChat,"kickfromchat"},
  15119. {clif_parse_ChatLeave,"chatleave"},
  15120. {clif_parse_TradeRequest,"traderequest"},
  15121. {clif_parse_TradeAck,"tradeack"},
  15122. {clif_parse_TradeAddItem,"tradeadditem"},
  15123. {clif_parse_TradeOk,"tradeok"},
  15124. {clif_parse_TradeCancel,"tradecancel"},
  15125. {clif_parse_TradeCommit,"tradecommit"},
  15126. {clif_parse_StopAttack,"stopattack"},
  15127. {clif_parse_PutItemToCart,"putitemtocart"},
  15128. {clif_parse_GetItemFromCart,"getitemfromcart"},
  15129. {clif_parse_RemoveOption,"removeoption"},
  15130. {clif_parse_ChangeCart,"changecart"},
  15131. {clif_parse_StatusUp,"statusup"},
  15132. {clif_parse_SkillUp,"skillup"},
  15133. {clif_parse_UseSkillToId,"useskilltoid"},
  15134. {clif_parse_UseSkillToPos,"useskilltopos"},
  15135. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  15136. {clif_parse_UseSkillMap,"useskillmap"},
  15137. {clif_parse_RequestMemo,"requestmemo"},
  15138. {clif_parse_ProduceMix,"producemix"},
  15139. {clif_parse_Cooking,"cooking"},
  15140. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  15141. {clif_parse_NpcNextClicked,"npcnextclicked"},
  15142. {clif_parse_NpcAmountInput,"npcamountinput"},
  15143. {clif_parse_NpcStringInput,"npcstringinput"},
  15144. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  15145. {clif_parse_ItemIdentify,"itemidentify"},
  15146. {clif_parse_SelectArrow,"selectarrow"},
  15147. {clif_parse_AutoSpell,"autospell"},
  15148. {clif_parse_UseCard,"usecard"},
  15149. {clif_parse_InsertCard,"insertcard"},
  15150. {clif_parse_RepairItem,"repairitem"},
  15151. {clif_parse_WeaponRefine,"weaponrefine"},
  15152. {clif_parse_SolveCharName,"solvecharname"},
  15153. {clif_parse_ResetChar,"resetchar"},
  15154. {clif_parse_LocalBroadcast,"localbroadcast"},
  15155. {clif_parse_MoveToKafra,"movetokafra"},
  15156. {clif_parse_MoveFromKafra,"movefromkafra"},
  15157. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  15158. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  15159. {clif_parse_CloseKafra,"closekafra"},
  15160. {clif_parse_CreateParty,"createparty"},
  15161. {clif_parse_CreateParty2,"createparty2"},
  15162. {clif_parse_PartyInvite,"partyinvite"},
  15163. {clif_parse_PartyInvite2,"partyinvite2"},
  15164. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  15165. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  15166. {clif_parse_LeaveParty,"leaveparty"},
  15167. {clif_parse_RemovePartyMember,"removepartymember"},
  15168. {clif_parse_PartyChangeOption,"partychangeoption"},
  15169. {clif_parse_PartyMessage,"partymessage"},
  15170. {clif_parse_PartyChangeLeader,"partychangeleader"},
  15171. {clif_parse_CloseVending,"closevending"},
  15172. {clif_parse_VendingListReq,"vendinglistreq"},
  15173. {clif_parse_PurchaseReq,"purchasereq"},
  15174. {clif_parse_PurchaseReq2,"purchasereq2"},
  15175. {clif_parse_OpenVending,"openvending"},
  15176. {clif_parse_CreateGuild,"createguild"},
  15177. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  15178. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  15179. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  15180. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  15181. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  15182. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  15183. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  15184. {clif_parse_GuildInvite,"guildinvite"},
  15185. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  15186. {clif_parse_GuildLeave,"guildleave"},
  15187. {clif_parse_GuildExpulsion,"guildexpulsion"},
  15188. {clif_parse_GuildMessage,"guildmessage"},
  15189. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  15190. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  15191. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  15192. {clif_parse_GuildOpposition,"guildopposition"},
  15193. {clif_parse_GuildBreak,"guildbreak"},
  15194. {clif_parse_PetMenu,"petmenu"},
  15195. {clif_parse_CatchPet,"catchpet"},
  15196. {clif_parse_SelectEgg,"selectegg"},
  15197. {clif_parse_SendEmotion,"sendemotion"},
  15198. {clif_parse_ChangePetName,"changepetname"},
  15199. {clif_parse_GMKick,"gmkick"},
  15200. {clif_parse_GMHide,"gmhide"},
  15201. {clif_parse_GMReqNoChat,"gmreqnochat"},
  15202. {clif_parse_GMReqAccountName,"gmreqaccname"},
  15203. {clif_parse_GMKickAll,"killall"},
  15204. {clif_parse_GMRecall,"recall"},
  15205. {clif_parse_GMRecall,"summon"},
  15206. {clif_parse_GM_Item_Monster,"itemmonster"},
  15207. {clif_parse_GMShift,"remove"},
  15208. {clif_parse_GMShift,"shift"},
  15209. {clif_parse_GMChangeMapType,"changemaptype"},
  15210. {clif_parse_GMRc,"rc"},
  15211. {clif_parse_GMRecall2,"recall2"},
  15212. {clif_parse_GMRemove2,"remove2"},
  15213. {clif_parse_GMFullStrip,"gmfullstrip"},
  15214. {clif_parse_NoviceDoriDori,"sndoridori"},
  15215. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  15216. {clif_parse_PMIgnore,"wisexin"},
  15217. {clif_parse_PMIgnoreList,"wisexlist"},
  15218. {clif_parse_PMIgnoreAll,"wisall"},
  15219. {clif_parse_FriendsListAdd,"friendslistadd"},
  15220. {clif_parse_FriendsListRemove,"friendslistremove"},
  15221. {clif_parse_FriendsListReply,"friendslistreply"},
  15222. {clif_parse_Blacksmith,"blacksmith"},
  15223. {clif_parse_Alchemist,"alchemist"},
  15224. {clif_parse_Taekwon,"taekwon"},
  15225. {clif_parse_RankingPk,"rankingpk"},
  15226. {clif_parse_FeelSaveOk,"feelsaveok"},
  15227. {clif_parse_debug,"debug"},
  15228. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  15229. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  15230. {clif_parse_HomMoveTo,"hommoveto"},
  15231. {clif_parse_HomAttack,"homattack"},
  15232. {clif_parse_HomMenu,"hommenu"},
  15233. {clif_parse_StoragePassword,"storagepassword"},
  15234. {clif_parse_Hotkey,"hotkey"},
  15235. {clif_parse_AutoRevive,"autorevive"},
  15236. {clif_parse_Check,"check"},
  15237. {clif_parse_Adopt_request,"adoptrequest"},
  15238. {clif_parse_Adopt_reply,"adoptreply"},
  15239. // MAIL SYSTEM
  15240. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  15241. {clif_parse_Mail_read,"mailread"},
  15242. {clif_parse_Mail_getattach,"mailgetattach"},
  15243. {clif_parse_Mail_delete,"maildelete"},
  15244. {clif_parse_Mail_return,"mailreturn"},
  15245. {clif_parse_Mail_setattach,"mailsetattach"},
  15246. {clif_parse_Mail_winopen,"mailwinopen"},
  15247. {clif_parse_Mail_send,"mailsend"},
  15248. // AUCTION SYSTEM
  15249. {clif_parse_Auction_search,"auctionsearch"},
  15250. {clif_parse_Auction_buysell,"auctionbuysell"},
  15251. {clif_parse_Auction_setitem,"auctionsetitem"},
  15252. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  15253. {clif_parse_Auction_register,"auctionregister"},
  15254. {clif_parse_Auction_cancel,"auctioncancel"},
  15255. {clif_parse_Auction_close,"auctionclose"},
  15256. {clif_parse_Auction_bid,"auctionbid"},
  15257. // Quest Log System
  15258. {clif_parse_questStateAck,"queststate"},
  15259. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  15260. {clif_parse_EquipTick,"equiptickbox"},
  15261. {clif_parse_BattleChat,"battlechat"},
  15262. {clif_parse_mercenary_action,"mermenu"},
  15263. {clif_parse_progressbar,"progressbar"},
  15264. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  15265. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  15266. #if PACKETVER >= 20091229
  15267. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  15268. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  15269. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  15270. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  15271. #endif
  15272. {clif_parse_BankCheck,"bankcheck"},
  15273. {clif_parse_BankDeposit,"bankdeposit"},
  15274. {clif_parse_BankWithdraw,"bankwithdrawal"},
  15275. {clif_parse_BankOpen,"bankopen"},
  15276. {clif_parse_BankClose,"bankclose"},
  15277. {clif_parse_PVPInfo,"pvpinfo"},
  15278. {clif_parse_LessEffect,"lesseffect"},
  15279. // Buying Store
  15280. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  15281. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  15282. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  15283. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  15284. // Store Search
  15285. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  15286. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  15287. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  15288. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  15289. // Cashshop
  15290. { clif_parse_cashshop_open_request, "cashshopopen" },
  15291. { clif_parse_cashshop_close, "cashshopclose" },
  15292. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  15293. { clif_parse_cashshop_buy, "cashshopbuy" },
  15294. { clif_parse_CashShopReqTab, "cashshopreqtab"},
  15295. /* */
  15296. { clif_parse_MoveItem , "moveitem" },
  15297. { clif_parse_PartyTick, "partytick" },
  15298. { clif_parse_dull, "dull" },
  15299. { clif_parse_GuildInvite2 , "guildinvite2" },
  15300. { clif_parse_reqworldinfo, "reqworldinfo"},
  15301. { clif_parse_client_version, "clientversion"},
  15302. { clif_parse_blocking_playcancel, "booking_playcancel"},
  15303. { clif_parse_ranklist, "ranklist"},
  15304. {NULL,NULL}
  15305. };
  15306. struct {
  15307. char *name; //function name
  15308. int funcidx; //
  15309. } clif_ack_func[]={ //hash
  15310. { "ZC_ACK_OPEN_BANKING", ZC_ACK_OPEN_BANKING},
  15311. { "ZC_ACK_BANKING_DEPOSIT", ZC_ACK_BANKING_DEPOSIT},
  15312. { "ZC_ACK_BANKING_WITHDRAW", ZC_ACK_BANKING_WITHDRAW},
  15313. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15314. { "ZC_BANKING_CHECK", ZC_BANKING_CHECK},
  15315. { "ZC_PERSONAL_INFOMATION", ZC_PERSONAL_INFOMATION},
  15316. { "ZC_PERSONAL_INFOMATION_CHN", ZC_PERSONAL_INFOMATION_CHN},
  15317. { "ZC_CLEAR_DIALOG", ZC_CLEAR_DIALOG},
  15318. };
  15319. const char *filename[] = { "packet_db.txt", DBIMPORT"/packet_db.txt"};
  15320. int f;
  15321. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  15322. memset(packet_db,0,sizeof(packet_db));
  15323. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  15324. packet_len(i) = packet_len_table[i];
  15325. clif_config.packet_db_ver = MAX_PACKET_VER;
  15326. for(f = 0; f<ARRAYLENGTH(filename); f++){
  15327. entries = 0;
  15328. sprintf(line, "%s/%s", db_path,filename[f]);
  15329. if( (fp=fopen(line,"r"))==NULL ){
  15330. if(f==0) {
  15331. ShowFatalError("Can't read %s\n", line);
  15332. exit(EXIT_FAILURE);
  15333. }
  15334. return;
  15335. }
  15336. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  15337. while( fgets(line, sizeof(line), fp) )
  15338. {
  15339. ln++;
  15340. if(line[0]=='/' && line[1]=='/')
  15341. continue;
  15342. if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2)
  15343. {
  15344. if(strcmpi(w1,"packet_ver")==0) {
  15345. int prev_ver = packet_ver;
  15346. skip_ver = false;
  15347. packet_ver = atoi(w2);
  15348. if ( packet_ver > MAX_PACKET_VER )
  15349. { //Check to avoid overflowing. [Skotlex]
  15350. if( (warned&1) == 0 )
  15351. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  15352. warned &= 1;
  15353. skip_ver = true;
  15354. }
  15355. else if( packet_ver < 0 )
  15356. {
  15357. if( (warned&2) == 0 )
  15358. ShowWarning("Negative packet versions are not supported.\n");
  15359. warned &= 2;
  15360. skip_ver = true;
  15361. }
  15362. else if( packet_ver == SERVER )
  15363. {
  15364. if( (warned&4) == 0 )
  15365. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  15366. warned &= 4;
  15367. skip_ver = true;
  15368. }
  15369. if( skip_ver )
  15370. {
  15371. ShowWarning("Skipping packet version %d.\n", packet_ver);
  15372. packet_ver = prev_ver;
  15373. continue;
  15374. }
  15375. // copy from previous version into new version and continue
  15376. // - indicating all following packets should be read into the newer version
  15377. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  15378. memcpy(&packet_db_ack[packet_ver], &packet_db_ack[prev_ver], sizeof(packet_db_ack[0]));
  15379. continue;
  15380. } else if(strcmpi(w1,"packet_db_ver")==0) {
  15381. if(strcmpi(w2,"default")==0) //This is the preferred version.
  15382. clif_config.packet_db_ver = MAX_PACKET_VER;
  15383. else // to manually set the packet DB version
  15384. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  15385. continue;
  15386. }
  15387. }
  15388. if( skip_ver )
  15389. continue; // Skipping current packet version
  15390. memset(str,0,sizeof(str));
  15391. for(j=0,p=line;j<4 && p; ++j)
  15392. {
  15393. str[j]=p;
  15394. p=strchr(p,',');
  15395. if(p) *p++=0;
  15396. }
  15397. if(str[0]==NULL)
  15398. continue;
  15399. cmd=strtol(str[0],(char **)NULL,0);
  15400. if(max_cmd < cmd)
  15401. max_cmd = cmd;
  15402. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  15403. continue;
  15404. if(str[1]==NULL){
  15405. ShowError("packet_db: packet len error\n");
  15406. continue;
  15407. }
  15408. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  15409. if(str[2]==NULL){
  15410. packet_db[packet_ver][cmd].func = NULL;
  15411. ln++;
  15412. continue;
  15413. }
  15414. // look up processing function by name
  15415. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  15416. if( j < ARRAYLENGTH(clif_parse_func) )
  15417. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  15418. else { //search if it's a mapped ack func
  15419. ARR_FIND( 0, ARRAYLENGTH(clif_ack_func), j, clif_ack_func[j].name != NULL && strcmp(str[2],clif_ack_func[j].name)==0 );
  15420. if( j < ARRAYLENGTH(clif_ack_func)) {
  15421. int fidx = clif_ack_func[j].funcidx;
  15422. packet_db_ack[packet_ver][fidx] = cmd;
  15423. //ShowInfo("Added %s, <=> %X i=%d for v=%d\n",clif_ack_func[j].name,cmd,fidx,packet_ver);
  15424. }
  15425. }
  15426. // set the identifying cmd for the packet_db version
  15427. if (strcmp(str[2],"wanttoconnection")==0)
  15428. clif_config.connect_cmd[packet_ver] = cmd;
  15429. if(str[3]==NULL){
  15430. ShowError("packet_db: packet error\n");
  15431. exit(EXIT_FAILURE);
  15432. }
  15433. for(j=0,p2=str[3];p2;j++){
  15434. short k;
  15435. str2[j]=p2;
  15436. p2=strchr(p2,':');
  15437. if(p2) *p2++=0;
  15438. k = atoi(str2[j]);
  15439. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  15440. if( j >= MAX_PACKET_POS )
  15441. {
  15442. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  15443. break;
  15444. }
  15445. packet_db[packet_ver][cmd].pos[j] = k;
  15446. }
  15447. entries++;
  15448. }
  15449. fclose(fp);
  15450. if(max_cmd > MAX_PACKET_DB)
  15451. {
  15452. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  15453. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  15454. }
  15455. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  15456. { //Locate the nearest version that we still support. [Skotlex]
  15457. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  15458. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  15459. }
  15460. sprintf(line, "%s/%s", db_path,filename[f]);
  15461. ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, line);
  15462. }
  15463. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  15464. }
  15465. /*==========================================
  15466. *
  15467. *------------------------------------------*/
  15468. void do_init_clif(void) {
  15469. const char* colors[COLOR_MAX] = {
  15470. "0xFF0000",
  15471. "0xFFFFFF",
  15472. "0xFFFF00",
  15473. };
  15474. int i;
  15475. /**
  15476. * Setup Color Table (saves unnecessary load of strtoul on every call)
  15477. **/
  15478. for(i = 0; i < COLOR_MAX; i++) {
  15479. color_table[i] = strtoul(colors[i],NULL,0);
  15480. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  15481. }
  15482. clif_config.packet_db_ver = -1; // the main packet version of the DB
  15483. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  15484. //Using the packet_db file is the only way to set up packets now [Skotlex]
  15485. packetdb_readdb();
  15486. set_defaultparse(clif_parse);
  15487. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  15488. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  15489. exit(EXIT_FAILURE);
  15490. }
  15491. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  15492. add_timer_func_list(clif_delayquit, "clif_delayquit");
  15493. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  15494. }
  15495. void do_final_clif(void) {
  15496. ers_destroy(delay_clearunit_ers);
  15497. }