clif.c 475 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098
  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. //Converts item type in case of pet eggs.
  61. static inline int itemtype(int type)
  62. {
  63. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  64. }
  65. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir)
  66. {
  67. p += pos;
  68. p[0] = (uint8)(x>>2);
  69. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  70. p[2] = (uint8)((y<<4) | (dir&0xf));
  71. }
  72. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  73. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  74. {
  75. p += pos;
  76. p[0] = (uint8)(x0>>2);
  77. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  78. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  79. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  80. p[4] = (uint8)y1;
  81. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  82. }
  83. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir)
  84. {
  85. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  86. }
  87. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0)
  88. {
  89. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  90. }
  91. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir)
  92. {
  93. p += pos;
  94. if( x ) {
  95. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  96. }
  97. if( y ) {
  98. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  99. }
  100. if( dir ) {
  101. dir[0] = ( p[2] & 0x0f );
  102. }
  103. }
  104. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  105. {
  106. p += pos;
  107. if( x0 ) {
  108. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  109. }
  110. if( y0 ) {
  111. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  112. }
  113. if( x1 ) {
  114. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  115. }
  116. if( y1 ) {
  117. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  118. }
  119. if( sx0 ) {
  120. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  121. }
  122. if( sy0 ) {
  123. sy0[0] = ( p[5] & 0x0f ) >> 0;
  124. }
  125. }
  126. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir)
  127. {
  128. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  129. }
  130. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0)
  131. {
  132. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  133. }
  134. //To idenfity disguised characters.
  135. static inline bool disguised(struct block_list* bl)
  136. {
  137. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  138. }
  139. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  140. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max)
  141. {
  142. if( len > max )
  143. len = max;
  144. mes[len-1] = '\0';
  145. return len;
  146. }
  147. static char map_ip_str[128];
  148. static uint32 map_ip;
  149. static uint32 bind_ip = INADDR_ANY;
  150. static uint16 map_port = 5121;
  151. int map_fd;
  152. static int clif_parse (int fd);
  153. /*==========================================
  154. * Ip setting of map-server
  155. *------------------------------------------*/
  156. int clif_setip(const char* ip)
  157. {
  158. char ip_str[16];
  159. map_ip = host2ip(ip);
  160. if (!map_ip) {
  161. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  162. return 0;
  163. }
  164. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  165. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  166. return 1;
  167. }
  168. void clif_setbindip(const char* ip)
  169. {
  170. bind_ip = host2ip(ip);
  171. if (bind_ip) {
  172. char ip_str[16];
  173. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  174. } else {
  175. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  176. }
  177. }
  178. /*==========================================
  179. * Sets map port to 'port'
  180. * is run from map.c upon loading map server configuration
  181. *------------------------------------------*/
  182. void clif_setport(uint16 port)
  183. {
  184. map_port = port;
  185. }
  186. /*==========================================
  187. * Returns map server IP
  188. *------------------------------------------*/
  189. uint32 clif_getip(void)
  190. {
  191. return map_ip;
  192. }
  193. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  194. uint32 clif_refresh_ip(void)
  195. {
  196. uint32 new_ip;
  197. new_ip = host2ip(map_ip_str);
  198. if (new_ip && new_ip != map_ip) {
  199. map_ip = new_ip;
  200. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  201. return map_ip;
  202. }
  203. return 0;
  204. }
  205. /*==========================================
  206. * Returns map port which is set by clif_setport()
  207. *------------------------------------------*/
  208. uint16 clif_getport(void)
  209. {
  210. return map_port;
  211. }
  212. #if PACKETVER >= 20071106
  213. static inline unsigned char clif_bl_type(struct block_list *bl) {
  214. switch (bl->type) {
  215. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  216. case BL_ITEM: return 0x2; //ITEM_TYPE
  217. case BL_SKILL: return 0x3; //SKILL_TYPE
  218. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  219. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  220. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  221. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  222. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  223. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  224. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  225. default: return 0x1; //NPC_TYPE
  226. }
  227. }
  228. #endif
  229. /*==========================================
  230. * sub process of clif_send
  231. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  232. * In order to send area-wise packets, such as:
  233. * - AREA : everyone nearby your area
  234. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  235. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  236. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  237. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  238. *------------------------------------------*/
  239. static int clif_send_sub(struct block_list *bl, va_list ap)
  240. {
  241. struct block_list *src_bl;
  242. struct map_session_data *sd;
  243. unsigned char *buf;
  244. int len, type, fd;
  245. nullpo_ret(bl);
  246. nullpo_ret(sd = (struct map_session_data *)bl);
  247. fd = sd->fd;
  248. if (!fd) //Don't send to disconnected clients.
  249. return 0;
  250. buf = va_arg(ap,unsigned char*);
  251. len = va_arg(ap,int);
  252. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  253. type = va_arg(ap,int);
  254. switch(type)
  255. {
  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. WFIFOHEAD(fd, len);
  282. if (WFIFOP(fd,0) == buf) {
  283. ShowError("WARNING: Invalid use of clif_send function\n");
  284. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  285. ShowError(" Please correct your code.\n");
  286. // don't send to not move the pointer of the packet for next sessions in the loop
  287. //WFIFOSET(fd,0);//## TODO is this ok?
  288. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  289. return 0;
  290. }
  291. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  292. memcpy(WFIFOP(fd,0), buf, len);
  293. WFIFOSET(fd,len);
  294. }
  295. return 0;
  296. }
  297. /*==========================================
  298. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  299. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  300. *------------------------------------------*/
  301. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  302. {
  303. int i;
  304. struct map_session_data *sd, *tsd;
  305. struct party_data *p = NULL;
  306. struct guild *g = NULL;
  307. struct battleground_data *bg = NULL;
  308. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  309. struct s_mapiterator* iter;
  310. if( type != ALL_CLIENT )
  311. nullpo_ret(bl);
  312. sd = BL_CAST(BL_PC, bl);
  313. switch(type) {
  314. case ALL_CLIENT: //All player clients.
  315. iter = mapit_getallusers();
  316. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  317. {
  318. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  319. { // packet must exist for the client version
  320. WFIFOHEAD(tsd->fd, len);
  321. memcpy(WFIFOP(tsd->fd,0), buf, len);
  322. WFIFOSET(tsd->fd,len);
  323. }
  324. }
  325. mapit_free(iter);
  326. break;
  327. case ALL_SAMEMAP: //All players on the same map
  328. iter = mapit_getallusers();
  329. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  330. {
  331. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  332. { // packet must exist for the client version
  333. WFIFOHEAD(tsd->fd, len);
  334. memcpy(WFIFOP(tsd->fd,0), buf, len);
  335. WFIFOSET(tsd->fd,len);
  336. }
  337. }
  338. mapit_free(iter);
  339. break;
  340. case AREA:
  341. case AREA_WOSC:
  342. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  343. clif_send (buf, len, bl, SELF);
  344. case AREA_WOC:
  345. case AREA_WOS:
  346. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  347. BL_PC, buf, len, bl, type);
  348. break;
  349. case AREA_CHAT_WOC:
  350. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  351. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  352. break;
  353. case CHAT:
  354. case CHAT_WOS:
  355. {
  356. struct chat_data *cd;
  357. if (sd) {
  358. cd = (struct chat_data*)map_id2bl(sd->chatID);
  359. } else if (bl->type == BL_CHAT) {
  360. cd = (struct chat_data*)bl;
  361. } else break;
  362. if (cd == NULL)
  363. break;
  364. for(i = 0; i < cd->users; i++) {
  365. if (type == CHAT_WOS && cd->usersd[i] == sd)
  366. continue;
  367. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  368. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  369. {
  370. WFIFOHEAD(fd,len);
  371. memcpy(WFIFOP(fd,0), buf, len);
  372. WFIFOSET(fd,len);
  373. }
  374. }
  375. }
  376. }
  377. break;
  378. case PARTY_AREA:
  379. case PARTY_AREA_WOS:
  380. x0 = bl->x - AREA_SIZE;
  381. y0 = bl->y - AREA_SIZE;
  382. x1 = bl->x + AREA_SIZE;
  383. y1 = bl->y + AREA_SIZE;
  384. case PARTY:
  385. case PARTY_WOS:
  386. case PARTY_SAMEMAP:
  387. case PARTY_SAMEMAP_WOS:
  388. if (sd && sd->status.party_id)
  389. p = party_search(sd->status.party_id);
  390. if (p) {
  391. for(i=0;i<MAX_PARTY;i++){
  392. if( (sd = p->data[i].sd) == NULL )
  393. continue;
  394. if( !(fd=sd->fd) )
  395. continue;
  396. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  397. continue;
  398. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  399. continue;
  400. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  401. continue;
  402. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  403. { // packet must exist for the client version
  404. WFIFOHEAD(fd,len);
  405. memcpy(WFIFOP(fd,0), buf, len);
  406. WFIFOSET(fd,len);
  407. }
  408. }
  409. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  410. break;
  411. iter = mapit_getallusers();
  412. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  413. {
  414. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  415. { // packet must exist for the client version
  416. WFIFOHEAD(tsd->fd, len);
  417. memcpy(WFIFOP(tsd->fd,0), buf, len);
  418. WFIFOSET(tsd->fd,len);
  419. }
  420. }
  421. mapit_free(iter);
  422. }
  423. break;
  424. case DUEL:
  425. case DUEL_WOS:
  426. if (!sd || !sd->duel_group) break; //Invalid usage.
  427. iter = mapit_getallusers();
  428. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  429. {
  430. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  431. continue;
  432. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  433. { // packet must exist for the client version
  434. WFIFOHEAD(tsd->fd, len);
  435. memcpy(WFIFOP(tsd->fd,0), buf, len);
  436. WFIFOSET(tsd->fd,len);
  437. }
  438. }
  439. mapit_free(iter);
  440. break;
  441. case SELF:
  442. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  443. WFIFOHEAD(fd,len);
  444. memcpy(WFIFOP(fd,0), buf, len);
  445. WFIFOSET(fd,len);
  446. }
  447. break;
  448. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  449. case GUILD_AREA:
  450. case GUILD_AREA_WOS:
  451. x0 = bl->x - AREA_SIZE;
  452. y0 = bl->y - AREA_SIZE;
  453. x1 = bl->x + AREA_SIZE;
  454. y1 = bl->y + AREA_SIZE;
  455. case GUILD_SAMEMAP:
  456. case GUILD_SAMEMAP_WOS:
  457. case GUILD:
  458. case GUILD_WOS:
  459. case GUILD_NOBG:
  460. if (sd && sd->status.guild_id)
  461. g = sd->guild;
  462. if (g) {
  463. for(i = 0; i < g->max_member; i++) {
  464. if( (sd = g->member[i].sd) != NULL )
  465. {
  466. if( !(fd=sd->fd) )
  467. continue;
  468. if( type == GUILD_NOBG && sd->bg_id )
  469. continue;
  470. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  471. continue;
  472. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  473. continue;
  474. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  475. continue;
  476. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  477. { // packet must exist for the client version
  478. WFIFOHEAD(fd,len);
  479. memcpy(WFIFOP(fd,0), buf, len);
  480. WFIFOSET(fd,len);
  481. }
  482. }
  483. }
  484. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  485. break;
  486. iter = mapit_getallusers();
  487. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  488. {
  489. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  490. { // packet must exist for the client version
  491. WFIFOHEAD(tsd->fd, len);
  492. memcpy(WFIFOP(tsd->fd,0), buf, len);
  493. WFIFOSET(tsd->fd,len);
  494. }
  495. }
  496. mapit_free(iter);
  497. }
  498. break;
  499. case BG_AREA:
  500. case BG_AREA_WOS:
  501. x0 = bl->x - AREA_SIZE;
  502. y0 = bl->y - AREA_SIZE;
  503. x1 = bl->x + AREA_SIZE;
  504. y1 = bl->y + AREA_SIZE;
  505. case BG_SAMEMAP:
  506. case BG_SAMEMAP_WOS:
  507. case BG:
  508. case BG_WOS:
  509. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  510. {
  511. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  512. {
  513. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  514. continue;
  515. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  516. continue;
  517. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  518. continue;
  519. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  520. continue;
  521. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  522. { // packet must exist for the client version
  523. WFIFOHEAD(fd,len);
  524. memcpy(WFIFOP(fd,0), buf, len);
  525. WFIFOSET(fd,len);
  526. }
  527. }
  528. }
  529. break;
  530. default:
  531. ShowError("clif_send: Unrecognized type %d\n",type);
  532. return -1;
  533. }
  534. return 0;
  535. }
  536. /// Notifies the client, that it's connection attempt was accepted.
  537. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  538. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  539. void clif_authok(struct map_session_data *sd)
  540. {
  541. #if PACKETVER < 20080102
  542. const int cmd = 0x73;
  543. #else
  544. const int cmd = 0x2eb;
  545. #endif
  546. int fd = sd->fd;
  547. WFIFOHEAD(fd,packet_len(cmd));
  548. WFIFOW(fd, 0) = cmd;
  549. WFIFOL(fd, 2) = gettick();
  550. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  551. WFIFOB(fd, 9) = 5; // ignored
  552. WFIFOB(fd,10) = 5; // ignored
  553. #if PACKETVER >= 20080102
  554. WFIFOW(fd,11) = sd->user_font; // FIXME: Font is currently not saved.
  555. #endif
  556. WFIFOSET(fd,packet_len(cmd));
  557. }
  558. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  559. /// 0074 <error code>.B
  560. /// error code:
  561. /// 0 = client type mismatch
  562. /// 1 = ID mismatch
  563. /// 2 = mobile - out of available time
  564. /// 3 = mobile - already logged in
  565. /// 4 = mobile - waiting state
  566. void clif_authrefuse(int fd, uint8 error_code)
  567. {
  568. WFIFOHEAD(fd,packet_len(0x74));
  569. WFIFOW(fd,0) = 0x74;
  570. WFIFOB(fd,2) = error_code;
  571. WFIFOSET(fd,packet_len(0x74));
  572. }
  573. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  574. /// 0081 <error code>.B
  575. /// error code:
  576. /// 0 = BAN_UNFAIR
  577. /// 1 = server closed -> MsgStringTable[4]
  578. /// 2 = ID already logged in -> MsgStringTable[5]
  579. /// 3 = timeout/too much lag -> MsgStringTable[241]
  580. /// 4 = server full -> MsgStringTable[264]
  581. /// 5 = underaged -> MsgStringTable[305]
  582. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  583. /// 9 = too many connections from this ip -> MsgStringTable[529]
  584. /// 10 = out of available time paid for -> MsgStringTable[530]
  585. /// 11 = BAN_PAY_SUSPEND
  586. /// 12 = BAN_PAY_CHANGE
  587. /// 13 = BAN_PAY_WRONGIP
  588. /// 14 = BAN_PAY_PNGAMEROOM
  589. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  590. /// 16 = BAN_JAPAN_REFUSE1
  591. /// 17 = BAN_JAPAN_REFUSE2
  592. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  593. /// 100 = BAN_PC_IP_UNFAIR
  594. /// 101 = BAN_PC_IP_COUNT_ALL
  595. /// 102 = BAN_PC_IP_COUNT
  596. /// 103 = BAN_GRAVITY_MEM_AGREE
  597. /// 104 = BAN_GAME_MEM_AGREE
  598. /// 105 = BAN_HAN_VALID
  599. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  600. /// 107 = BAN_OVER_CHARACTER_LIST
  601. /// 108 = BAN_IP_BLOCK
  602. /// 109 = BAN_INVALID_PWD_CNT
  603. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  604. /// ? = disconnected -> MsgStringTable[3]
  605. void clif_authfail_fd(int fd, int type)
  606. {
  607. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  608. return;
  609. WFIFOHEAD(fd, packet_len(0x81));
  610. WFIFOW(fd,0) = 0x81;
  611. WFIFOB(fd,2) = type;
  612. WFIFOSET(fd,packet_len(0x81));
  613. set_eof(fd);
  614. }
  615. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  616. /// 00b3 <type>.B
  617. /// type:
  618. /// 1 = disconnect, char-select
  619. /// ? = nothing
  620. void clif_charselectok(int id, uint8 ok)
  621. {
  622. struct map_session_data* sd;
  623. int fd;
  624. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  625. return;
  626. fd = sd->fd;
  627. WFIFOHEAD(fd,packet_len(0xb3));
  628. WFIFOW(fd,0) = 0xb3;
  629. WFIFOB(fd,2) = ok;
  630. WFIFOSET(fd,packet_len(0xb3));
  631. }
  632. /// Makes an item appear on the ground.
  633. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  634. /// 084b (ZC_ITEM_FALL_ENTRY4)
  635. void clif_dropflooritem(struct flooritem_data* fitem)
  636. {
  637. uint8 buf[17];
  638. int view;
  639. nullpo_retv(fitem);
  640. if (fitem->item_data.nameid <= 0)
  641. return;
  642. WBUFW(buf, 0) = 0x9e;
  643. WBUFL(buf, 2) = fitem->bl.id;
  644. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  645. WBUFB(buf, 8) = fitem->item_data.identify;
  646. WBUFW(buf, 9) = fitem->bl.x;
  647. WBUFW(buf,11) = fitem->bl.y;
  648. WBUFB(buf,13) = fitem->subx;
  649. WBUFB(buf,14) = fitem->suby;
  650. WBUFW(buf,15) = fitem->item_data.amount;
  651. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  652. }
  653. /// Makes an item disappear from the ground.
  654. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  655. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  656. {
  657. unsigned char buf[16];
  658. nullpo_retv(fitem);
  659. WBUFW(buf,0) = 0xa1;
  660. WBUFL(buf,2) = fitem->bl.id;
  661. if (fd == 0) {
  662. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  663. } else {
  664. WFIFOHEAD(fd,packet_len(0xa1));
  665. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  666. WFIFOSET(fd,packet_len(0xa1));
  667. }
  668. }
  669. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  670. /// 0080 <id>.L <type>.B
  671. /// type:
  672. /// 0 = out of sight
  673. /// 1 = died
  674. /// 2 = logged out
  675. /// 3 = teleport
  676. /// 4 = trickdead
  677. void clif_clearunit_single(int id, clr_type type, int fd)
  678. {
  679. WFIFOHEAD(fd, packet_len(0x80));
  680. WFIFOW(fd,0) = 0x80;
  681. WFIFOL(fd,2) = id;
  682. WFIFOB(fd,6) = type;
  683. WFIFOSET(fd, packet_len(0x80));
  684. }
  685. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  686. /// 0080 <id>.L <type>.B
  687. /// type:
  688. /// 0 = out of sight
  689. /// 1 = died
  690. /// 2 = logged out
  691. /// 3 = teleport
  692. /// 4 = trickdead
  693. void clif_clearunit_area(struct block_list* bl, clr_type type)
  694. {
  695. unsigned char buf[8];
  696. nullpo_retv(bl);
  697. WBUFW(buf,0) = 0x80;
  698. WBUFL(buf,2) = bl->id;
  699. WBUFB(buf,6) = type;
  700. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  701. if(disguised(bl)) {
  702. WBUFL(buf,2) = -bl->id;
  703. clif_send(buf, packet_len(0x80), bl, SELF);
  704. }
  705. }
  706. /// Used to make monsters with player-sprites disappear after dying
  707. /// like normal monsters, because the client does not remove those
  708. /// automatically.
  709. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  710. {
  711. struct block_list *bl = (struct block_list *)data;
  712. clif_clearunit_area(bl, (clr_type) id);
  713. ers_free(delay_clearunit_ers,bl);
  714. return 0;
  715. }
  716. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  717. {
  718. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  719. memcpy (tbl, bl, sizeof (struct block_list));
  720. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  721. }
  722. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  723. {
  724. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  725. {
  726. *rhand = *lhand = 0;
  727. return;
  728. }
  729. #if PACKETVER < 4
  730. *rhand = sd->status.weapon;
  731. *lhand = sd->status.shield;
  732. #else
  733. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  734. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  735. {
  736. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  737. if (id->view_id > 0)
  738. *rhand = id->view_id;
  739. else
  740. *rhand = id->nameid;
  741. } else
  742. *rhand = 0;
  743. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  744. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  745. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  746. {
  747. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  748. if (id->view_id > 0)
  749. *lhand = id->view_id;
  750. else
  751. *lhand = id->nameid;
  752. } else
  753. *lhand = 0;
  754. #endif
  755. }
  756. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  757. static int clif_setlevel_sub(int lv)
  758. {
  759. if( lv < battle_config.max_lv ) {
  760. ;
  761. } else if( lv < battle_config.aura_lv ) {
  762. lv = battle_config.max_lv - 1;
  763. } else {
  764. lv = battle_config.max_lv;
  765. }
  766. return lv;
  767. }
  768. static int clif_setlevel(struct block_list* bl)
  769. {
  770. int lv = status_get_lv(bl);
  771. if( battle_config.client_limit_unit_lv&bl->type )
  772. return clif_setlevel_sub(lv);
  773. switch( bl->type ) {
  774. case BL_NPC:
  775. case BL_PET:
  776. // npcs and pets do not have level
  777. return 0;
  778. }
  779. return lv;
  780. }
  781. /*==========================================
  782. * Prepares 'unit standing/spawning' packet
  783. *------------------------------------------*/
  784. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  785. {
  786. struct map_session_data* sd;
  787. struct status_change* sc = status_get_sc(bl);
  788. struct view_data* vd = status_get_viewdata(bl);
  789. unsigned char *buf = WBUFP(buffer,0);
  790. #if PACKETVER < 20091103
  791. bool type = !pcdb_checkid(vd->class_);
  792. #endif
  793. unsigned short offset = 0;
  794. #if PACKETVER >= 20091103
  795. const char *name;
  796. #endif
  797. sd = BL_CAST(BL_PC, bl);
  798. #if PACKETVER < 20091103
  799. if(type)
  800. WBUFW(buf,0) = spawn?0x7c:0x78;
  801. else
  802. #endif
  803. #if PACKETVER < 4
  804. WBUFW(buf,0) = spawn?0x79:0x78;
  805. #elif PACKETVER < 7
  806. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  807. #elif PACKETVER < 20080102
  808. WBUFW(buf,0) = spawn?0x22b:0x22a;
  809. #elif PACKETVER < 20091103
  810. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  811. #elif PACKETVER < 20101124
  812. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  813. #else
  814. WBUFW(buf,0) = spawn?0x858:0x857;
  815. #endif
  816. #if PACKETVER >= 20091103
  817. name = status_get_name(bl);
  818. #if PACKETVER < 20110111
  819. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  820. #else
  821. WBUFW(buf,2) = (spawn?64:65)+strlen(name);
  822. #endif
  823. WBUFB(buf,4) = clif_bl_type(bl);
  824. offset+=3;
  825. buf = WBUFP(buffer,offset);
  826. #elif PACKETVER >= 20071106
  827. if (type) { //Non-player packets
  828. WBUFB(buf,2) = clif_bl_type(bl);
  829. offset++;
  830. buf = WBUFP(buffer,offset);
  831. }
  832. #endif
  833. WBUFL(buf, 2) = bl->id;
  834. WBUFW(buf, 6) = status_get_speed(bl);
  835. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  836. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  837. #if PACKETVER < 20091103
  838. if (type&&spawn) { //uses an older and different packet structure
  839. WBUFW(buf,12) = (sc)? sc->option : 0;
  840. WBUFW(buf,14) = vd->hair_style;
  841. WBUFW(buf,16) = vd->weapon;
  842. WBUFW(buf,18) = vd->head_bottom;
  843. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  844. WBUFW(buf,22) = vd->shield;
  845. } else {
  846. #endif
  847. #if PACKETVER >= 20091103
  848. WBUFL(buf,12) = (sc)? sc->option : 0;
  849. offset+=2;
  850. buf = WBUFP(buffer,offset);
  851. #elif PACKETVER >= 7
  852. if (!type) {
  853. WBUFL(buf,12) = (sc)? sc->option : 0;
  854. offset+=2;
  855. buf = WBUFP(buffer,offset);
  856. } else
  857. WBUFW(buf,12) = (sc)? sc->option : 0;
  858. #else
  859. WBUFW(buf,12) = (sc)? sc->option : 0;
  860. #endif
  861. WBUFW(buf,14) = vd->class_;
  862. WBUFW(buf,16) = vd->hair_style;
  863. WBUFW(buf,18) = vd->weapon;
  864. #if PACKETVER < 4
  865. WBUFW(buf,20) = vd->head_bottom;
  866. WBUFW(buf,22) = vd->shield;
  867. #else
  868. WBUFW(buf,20) = vd->shield;
  869. WBUFW(buf,22) = vd->head_bottom;
  870. #endif
  871. #if PACKETVER < 20091103
  872. }
  873. #endif
  874. WBUFW(buf,24) = vd->head_top;
  875. WBUFW(buf,26) = vd->head_mid;
  876. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  877. { //The hell, why flags work like this?
  878. WBUFW(buf,22) = status_get_emblem_id(bl);
  879. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  880. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  881. }
  882. WBUFW(buf,28) = vd->hair_color;
  883. WBUFW(buf,30) = vd->cloth_color;
  884. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  885. #if PACKETVER < 20091103
  886. if (type&&spawn) { //End of packet 0x7c
  887. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  888. WBUFB(buf,35) = vd->sex;
  889. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  890. WBUFB(buf,39) = 0;
  891. WBUFB(buf,40) = 0;
  892. return packet_len(0x7c);
  893. }
  894. #endif
  895. #if PACKETVER >= 20110111
  896. WBUFW(buf,34) = vd->robe;
  897. offset+= 2;
  898. buf = WBUFP(buffer,offset);
  899. #endif
  900. WBUFL(buf,34) = status_get_guild_id(bl);
  901. WBUFW(buf,38) = status_get_emblem_id(bl);
  902. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  903. #if PACKETVER >= 20091103
  904. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  905. offset+=2;
  906. buf = WBUFP(buffer,offset);
  907. #elif PACKETVER >= 7
  908. if (!type) {
  909. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  910. offset+=2;
  911. buf = WBUFP(buffer,offset);
  912. } else
  913. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  914. #else
  915. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  916. #endif
  917. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  918. WBUFB(buf,45) = vd->sex;
  919. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  920. WBUFB(buf,49) = (sd)? 5 : 0;
  921. WBUFB(buf,50) = (sd)? 5 : 0;
  922. if (!spawn) {
  923. WBUFB(buf,51) = vd->dead_sit;
  924. offset++;
  925. buf = WBUFP(buffer,offset);
  926. }
  927. WBUFW(buf,51) = clif_setlevel(bl);
  928. #if PACKETVER < 20091103
  929. if (type) //End for non-player packet
  930. return packet_len(WBUFW(buffer,0));
  931. #endif
  932. #if PACKETVER >= 20080102
  933. WBUFW(buf,53) = sd?sd->user_font:0;
  934. #endif
  935. #if PACKETVER >= 20091103
  936. memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
  937. return WBUFW(buffer,2);
  938. #else
  939. return packet_len(WBUFW(buffer,0));
  940. #endif
  941. }
  942. /*==========================================
  943. * Prepares 'unit walking' packet
  944. *------------------------------------------*/
  945. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  946. {
  947. struct map_session_data* sd;
  948. struct status_change* sc = status_get_sc(bl);
  949. struct view_data* vd = status_get_viewdata(bl);
  950. unsigned char* buf = WBUFP(buffer,0);
  951. #if PACKETVER >= 7
  952. unsigned short offset = 0;
  953. #endif
  954. #if PACKETVER >= 20091103
  955. const char *name;
  956. #endif
  957. sd = BL_CAST(BL_PC, bl);
  958. #if PACKETVER < 4
  959. WBUFW(buf, 0) = 0x7b;
  960. #elif PACKETVER < 7
  961. WBUFW(buf, 0) = 0x1da;
  962. #elif PACKETVER < 20080102
  963. WBUFW(buf, 0) = 0x22c;
  964. #elif PACKETVER < 20091103
  965. WBUFW(buf, 0) = 0x2ec;
  966. #elif PACKETVER < 20101124
  967. WBUFW(buf, 0) = 0x7f7;
  968. #else
  969. WBUFW(buf, 0) = 0x856;
  970. #endif
  971. #if PACKETVER >= 20091103
  972. name = status_get_name(bl);
  973. #if PACKETVER < 20110111
  974. WBUFW(buf, 2) = 69+strlen(name);
  975. #else
  976. WBUFW(buf, 2) = 71+strlen(name);
  977. #endif
  978. offset+=2;
  979. buf = WBUFP(buffer,offset);
  980. #endif
  981. #if PACKETVER >= 20071106
  982. WBUFB(buf, 2) = clif_bl_type(bl);
  983. offset++;
  984. buf = WBUFP(buffer,offset);
  985. #endif
  986. WBUFL(buf, 2) = bl->id;
  987. WBUFW(buf, 6) = status_get_speed(bl);
  988. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  989. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  990. #if PACKETVER < 7
  991. WBUFW(buf,12) = (sc)? sc->option : 0;
  992. #else
  993. WBUFL(buf,12) = (sc)? sc->option : 0;
  994. offset+=2; //Shift the rest of elements by 2 bytes.
  995. buf = WBUFP(buffer,offset);
  996. #endif
  997. WBUFW(buf,14) = vd->class_;
  998. WBUFW(buf,16) = vd->hair_style;
  999. WBUFW(buf,18) = vd->weapon;
  1000. #if PACKETVER < 4
  1001. WBUFW(buf,20) = vd->head_bottom;
  1002. WBUFL(buf,22) = gettick();
  1003. WBUFW(buf,26) = vd->shield;
  1004. #else
  1005. WBUFW(buf,20) = vd->shield;
  1006. WBUFW(buf,22) = vd->head_bottom;
  1007. WBUFL(buf,24) = gettick();
  1008. #endif
  1009. WBUFW(buf,28) = vd->head_top;
  1010. WBUFW(buf,30) = vd->head_mid;
  1011. WBUFW(buf,32) = vd->hair_color;
  1012. WBUFW(buf,34) = vd->cloth_color;
  1013. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1014. #if PACKETVER >= 20110111
  1015. WBUFW(buf,38) = vd->robe;
  1016. offset+= 2;
  1017. buf = WBUFP(buffer,offset);
  1018. #endif
  1019. WBUFL(buf,38) = status_get_guild_id(bl);
  1020. WBUFW(buf,42) = status_get_emblem_id(bl);
  1021. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1022. #if PACKETVER < 7
  1023. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1024. #else
  1025. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1026. offset+=2; //Shift the rest of elements by 2 bytes.
  1027. buf = WBUFP(buffer,offset);
  1028. #endif
  1029. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1030. WBUFB(buf,49) = vd->sex;
  1031. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1032. WBUFB(buf,56) = (sd)? 5 : 0;
  1033. WBUFB(buf,57) = (sd)? 5 : 0;
  1034. WBUFW(buf,58) = clif_setlevel(bl);
  1035. #if PACKETVER >= 20080102
  1036. WBUFW(buf,60) = sd?sd->user_font:0;
  1037. #endif
  1038. #if PACKETVER >= 20091103
  1039. memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
  1040. return WBUFW(buffer,2);
  1041. #else
  1042. return packet_len(WBUFW(buffer,0));
  1043. #endif
  1044. }
  1045. //Modifies the buffer for disguise characters and sends it to self.
  1046. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1047. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1048. {
  1049. #if PACKETVER >= 20091103
  1050. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1051. WBUFL(buf,5)=-bl->id;
  1052. #elif PACKETVER >= 20071106
  1053. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1054. WBUFL(buf,3)=-bl->id;
  1055. #else
  1056. WBUFL(buf,2)=-bl->id;
  1057. #endif
  1058. clif_send(buf, len, bl, SELF);
  1059. }
  1060. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1061. /// 01b0 <id>.L <type>.B <value>.L
  1062. /// type:
  1063. /// unused
  1064. void clif_class_change(struct block_list *bl,int class_,int type)
  1065. {
  1066. nullpo_retv(bl);
  1067. if(!pcdb_checkid(class_))
  1068. {// player classes yield missing sprites
  1069. unsigned char buf[16];
  1070. WBUFW(buf,0)=0x1b0;
  1071. WBUFL(buf,2)=bl->id;
  1072. WBUFB(buf,6)=type;
  1073. WBUFL(buf,7)=class_;
  1074. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1075. }
  1076. }
  1077. /// Notifies the client of an object's spirits.
  1078. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1079. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1080. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1081. {
  1082. WFIFOHEAD(fd, packet_len(0x1e1));
  1083. WFIFOW(fd,0)=0x1e1;
  1084. WFIFOL(fd,2)=sd->bl.id;
  1085. WFIFOW(fd,6)=sd->spiritball;
  1086. WFIFOSET(fd, packet_len(0x1e1));
  1087. }
  1088. /*==========================================
  1089. * Kagerou/Oboro amulet spirit
  1090. *------------------------------------------*/
  1091. static void clif_talisman_single(int fd, struct map_session_data *sd, short type)
  1092. {
  1093. WFIFOHEAD(fd, packet_len(0x08cf));
  1094. WFIFOW(fd,0)=0x08cf;
  1095. WFIFOL(fd,2)=sd->bl.id;
  1096. WFIFOW(fd,6)=type;
  1097. WFIFOW(fd,8)=sd->talisman[type];
  1098. WFIFOSET(fd, packet_len(0x08cf));
  1099. }
  1100. /*==========================================
  1101. * Run when player changes map / refreshes
  1102. * Tells its client to display all weather settings being used by this map
  1103. *------------------------------------------*/
  1104. static void clif_weather_check(struct map_session_data *sd)
  1105. {
  1106. int16 m = sd->bl.m;
  1107. int fd = sd->fd;
  1108. if (map[m].flag.snow
  1109. || map[m].flag.clouds
  1110. || map[m].flag.fog
  1111. || map[m].flag.fireworks
  1112. || map[m].flag.sakura
  1113. || map[m].flag.leaves
  1114. || map[m].flag.clouds2)
  1115. {
  1116. if (map[m].flag.snow)
  1117. clif_specialeffect_single(&sd->bl, 162, fd);
  1118. if (map[m].flag.clouds)
  1119. clif_specialeffect_single(&sd->bl, 233, fd);
  1120. if (map[m].flag.clouds2)
  1121. clif_specialeffect_single(&sd->bl, 516, fd);
  1122. if (map[m].flag.fog)
  1123. clif_specialeffect_single(&sd->bl, 515, fd);
  1124. if (map[m].flag.fireworks) {
  1125. clif_specialeffect_single(&sd->bl, 297, fd);
  1126. clif_specialeffect_single(&sd->bl, 299, fd);
  1127. clif_specialeffect_single(&sd->bl, 301, fd);
  1128. }
  1129. if (map[m].flag.sakura)
  1130. clif_specialeffect_single(&sd->bl, 163, fd);
  1131. if (map[m].flag.leaves)
  1132. clif_specialeffect_single(&sd->bl, 333, fd);
  1133. /**
  1134. * No longer available, keeping here just in case it's back someday. [Ind]
  1135. **/
  1136. //if (map[m].flag.rain)
  1137. // clif_specialeffect_single(&sd->bl, 161, fd);
  1138. }
  1139. }
  1140. /**
  1141. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1142. **/
  1143. void clif_weather(int16 m)
  1144. {
  1145. struct s_mapiterator* iter;
  1146. struct map_session_data *sd=NULL;
  1147. iter = mapit_getallusers();
  1148. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1149. {
  1150. if( sd->bl.m == m )
  1151. clif_weather_check(sd);
  1152. }
  1153. mapit_free(iter);
  1154. }
  1155. /**
  1156. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1157. **/
  1158. int clif_spawn(struct block_list *bl)
  1159. {
  1160. unsigned char buf[128];
  1161. struct view_data *vd;
  1162. int len;
  1163. vd = status_get_viewdata(bl);
  1164. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1165. return 0;
  1166. /**
  1167. * Hide NPC from maya purple card.
  1168. **/
  1169. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1170. return 0;
  1171. len = clif_set_unit_idle(bl, buf,true);
  1172. clif_send(buf, len, bl, AREA_WOS);
  1173. if (disguised(bl))
  1174. clif_setdisguise(bl, buf, len);
  1175. if (vd->cloth_color)
  1176. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1177. switch (bl->type)
  1178. {
  1179. case BL_PC:
  1180. {
  1181. TBL_PC *sd = ((TBL_PC*)bl);
  1182. int i;
  1183. if (sd->spiritball > 0)
  1184. clif_spiritball(&sd->bl);
  1185. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1186. clif_specialeffect(bl,423,AREA);
  1187. else if(sd->state.size==SZ_MEDIUM)
  1188. clif_specialeffect(bl,421,AREA);
  1189. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1190. clif_sendbgemblem_area(sd);
  1191. if( sd->sc.option&OPTION_MOUNTING ) {
  1192. //New Mounts are not complaint to the original method, so we gotta tell this guy that he is mounting.
  1193. clif_status_load_notick(&sd->bl,SI_ALL_RIDING,2,1,0,0);
  1194. }
  1195. for(i = 1; i < 5; i++){
  1196. if( sd->talisman[i] > 0 )
  1197. clif_talisman(sd, i);
  1198. }
  1199. #ifdef NEW_CARTS
  1200. if( sd->sc.data[SC_PUSH_CART] )
  1201. clif_status_load_notick(&sd->bl, SI_ON_PUSH_CART, 2, sd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  1202. #endif
  1203. if (sd->status.robe)
  1204. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1205. }
  1206. break;
  1207. case BL_MOB:
  1208. {
  1209. TBL_MOB *md = ((TBL_MOB*)bl);
  1210. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1211. clif_specialeffect(&md->bl,423,AREA);
  1212. else if(md->special_state.size==SZ_MEDIUM)
  1213. clif_specialeffect(&md->bl,421,AREA);
  1214. }
  1215. break;
  1216. case BL_NPC:
  1217. {
  1218. TBL_NPC *nd = ((TBL_NPC*)bl);
  1219. if( nd->size == SZ_BIG )
  1220. clif_specialeffect(&nd->bl,423,AREA);
  1221. else if( nd->size == SZ_MEDIUM )
  1222. clif_specialeffect(&nd->bl,421,AREA);
  1223. }
  1224. break;
  1225. case BL_PET:
  1226. if (vd->head_bottom)
  1227. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1228. break;
  1229. }
  1230. return 0;
  1231. }
  1232. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1233. /// 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
  1234. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1235. {
  1236. struct status_data *status;
  1237. unsigned char buf[128];
  1238. int m_class;
  1239. nullpo_retv(hd);
  1240. status = &hd->battle_status;
  1241. m_class = hom_class2mapid(hd->homunculus.class_);
  1242. memset(buf,0,packet_len(0x22e));
  1243. WBUFW(buf,0)=0x22e;
  1244. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1245. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1246. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1247. WBUFW(buf,27)=hd->homunculus.level;
  1248. WBUFW(buf,29)=hd->homunculus.hunger;
  1249. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1250. WBUFW(buf,33)=0; // equip id
  1251. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1252. WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
  1253. WBUFW(buf,39)=status->hit;
  1254. if (battle_config.hom_setting&0x10)
  1255. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1256. else
  1257. WBUFW(buf,41)=status->cri/10;
  1258. WBUFW(buf,43)=status->def + status->vit ;
  1259. WBUFW(buf,45)=status->mdef;
  1260. WBUFW(buf,47)=status->flee;
  1261. WBUFW(buf,49)=(flag)?0:status->amotion;
  1262. if (status->max_hp > INT16_MAX) {
  1263. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1264. WBUFW(buf,53) = 100;
  1265. } else {
  1266. WBUFW(buf,51)=status->hp;
  1267. WBUFW(buf,53)=status->max_hp;
  1268. }
  1269. if (status->max_sp > INT16_MAX) {
  1270. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1271. WBUFW(buf,57) = 100;
  1272. } else {
  1273. WBUFW(buf,55)=status->sp;
  1274. WBUFW(buf,57)=status->max_sp;
  1275. }
  1276. WBUFL(buf,59)=hd->homunculus.exp;
  1277. if( ((m_class&HOM_REG) && hd->homunculus.level >= battle_config.hom_max_level) || ((m_class&HOM_S) && hd->homunculus.level >= battle_config.hom_S_max_level) )
  1278. WBUFL(buf,63)=0;
  1279. else
  1280. WBUFL(buf,63)=hd->exp_next;
  1281. WBUFW(buf,67)=hd->homunculus.skillpts;
  1282. WBUFW(buf,69)=status_get_range(&hd->bl);
  1283. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1284. }
  1285. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1286. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1287. /// type:
  1288. /// unused
  1289. /// state:
  1290. /// 0 = pre-init
  1291. /// 1 = intimacy
  1292. /// 2 = hunger
  1293. /// 3 = accessory?
  1294. /// ? = ignored
  1295. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1296. { //[orn]
  1297. int fd = sd->fd;
  1298. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1299. merc_hom_calc_skilltree(sd->hd, 0);
  1300. WFIFOHEAD(fd, packet_len(0x230));
  1301. WFIFOW(fd,0)=0x230;
  1302. WFIFOB(fd,2)=0;
  1303. WFIFOB(fd,3)=state;
  1304. WFIFOL(fd,4)=sd->hd->bl.id;
  1305. WFIFOL(fd,8)=param;
  1306. WFIFOSET(fd,packet_len(0x230));
  1307. }
  1308. int clif_homskillinfoblock(struct map_session_data *sd)
  1309. { //[orn]
  1310. struct homun_data *hd;
  1311. int fd = sd->fd;
  1312. int i,j,len=4,id;
  1313. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1314. hd = sd->hd;
  1315. if ( !hd )
  1316. return 0 ;
  1317. WFIFOW(fd,0)=0x235;
  1318. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1319. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1320. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1321. j = id - HM_SKILLBASE;
  1322. WFIFOW(fd,len ) = id;
  1323. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1324. WFIFOW(fd,len+4) = 0;
  1325. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1326. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1327. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1328. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1329. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1330. len+=37;
  1331. }
  1332. }
  1333. WFIFOW(fd,2)=len;
  1334. WFIFOSET(fd,len);
  1335. return 0;
  1336. }
  1337. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1338. { //[orn]
  1339. struct homun_data *hd;
  1340. int fd, idx;
  1341. nullpo_retv(sd);
  1342. idx = skill_id - HM_SKILLBASE;
  1343. fd=sd->fd;
  1344. hd=sd->hd;
  1345. WFIFOHEAD(fd, packet_len(0x239));
  1346. WFIFOW(fd,0) = 0x239;
  1347. WFIFOW(fd,2) = skill_id;
  1348. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1349. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1350. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1351. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill_get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1352. WFIFOSET(fd,packet_len(0x239));
  1353. }
  1354. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1355. {
  1356. int fd=sd->fd;
  1357. WFIFOHEAD(fd,packet_len(0x22f));
  1358. WFIFOW(fd,0)=0x22f;
  1359. WFIFOB(fd,2)=fail;
  1360. WFIFOW(fd,3)=foodid;
  1361. WFIFOSET(fd,packet_len(0x22f));
  1362. return 0;
  1363. }
  1364. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1365. /// 0087 <walk start time>.L <walk data>.6B
  1366. void clif_walkok(struct map_session_data *sd)
  1367. {
  1368. int fd=sd->fd;
  1369. WFIFOHEAD(fd, packet_len(0x87));
  1370. WFIFOW(fd,0)=0x87;
  1371. WFIFOL(fd,2)=gettick();
  1372. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1373. WFIFOSET(fd,packet_len(0x87));
  1374. }
  1375. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1376. {
  1377. uint8 buf[128];
  1378. int len;
  1379. len = clif_set_unit_walking(bl,ud,buf);
  1380. clif_send(buf,len,bl,AREA_WOS);
  1381. if (disguised(bl))
  1382. clif_setdisguise(bl, buf, len);
  1383. if(vd->cloth_color)
  1384. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1385. switch(bl->type)
  1386. {
  1387. case BL_PC:
  1388. {
  1389. TBL_PC *sd = ((TBL_PC*)bl);
  1390. // clif_movepc(sd);
  1391. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1392. clif_specialeffect(&sd->bl,423,AREA);
  1393. else if(sd->state.size==SZ_MEDIUM)
  1394. clif_specialeffect(&sd->bl,421,AREA);
  1395. }
  1396. break;
  1397. case BL_MOB:
  1398. {
  1399. TBL_MOB *md = ((TBL_MOB*)bl);
  1400. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1401. clif_specialeffect(&md->bl,423,AREA);
  1402. else if(md->special_state.size==SZ_MEDIUM)
  1403. clif_specialeffect(&md->bl,421,AREA);
  1404. }
  1405. break;
  1406. case BL_PET:
  1407. if( vd->head_bottom )
  1408. {// needed to display pet equip properly
  1409. clif_pet_equip_area((TBL_PET*)bl);
  1410. }
  1411. break;
  1412. }
  1413. }
  1414. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1415. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1416. /// Note: unit must not be self
  1417. void clif_move(struct unit_data *ud)
  1418. {
  1419. unsigned char buf[16];
  1420. struct view_data* vd;
  1421. struct block_list* bl = ud->bl;
  1422. vd = status_get_viewdata(bl);
  1423. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1424. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1425. /**
  1426. * Hide NPC from maya purple card.
  1427. **/
  1428. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1429. return;
  1430. if (ud->state.speed_changed) {
  1431. // Since we don't know how to update the speed of other objects,
  1432. // use the old walk packet to update the data.
  1433. ud->state.speed_changed = 0;
  1434. clif_move2(bl, vd, ud);
  1435. return;
  1436. }
  1437. WBUFW(buf,0)=0x86;
  1438. WBUFL(buf,2)=bl->id;
  1439. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1440. WBUFL(buf,12)=gettick();
  1441. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1442. if (disguised(bl))
  1443. {
  1444. WBUFL(buf,2)=-bl->id;
  1445. clif_send(buf, packet_len(0x86), bl, SELF);
  1446. }
  1447. }
  1448. /*==========================================
  1449. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1450. *------------------------------------------*/
  1451. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1452. {
  1453. struct map_session_data *sd = NULL;
  1454. //Remove player from map server
  1455. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1456. map_quit(sd);
  1457. return 0;
  1458. }
  1459. /*==========================================
  1460. *
  1461. *------------------------------------------*/
  1462. void clif_quitsave(int fd,struct map_session_data *sd)
  1463. {
  1464. if (!battle_config.prevent_logout ||
  1465. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1466. map_quit(sd);
  1467. else if (sd->fd)
  1468. { //Disassociate session from player (session is deleted after this function was called)
  1469. //And set a timer to make him quit later.
  1470. session[sd->fd]->session_data = NULL;
  1471. sd->fd = 0;
  1472. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1473. }
  1474. }
  1475. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1476. /// 0091 <map name>.16B <x>.W <y>.W
  1477. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1478. {
  1479. int fd;
  1480. nullpo_retv(sd);
  1481. fd = sd->fd;
  1482. WFIFOHEAD(fd,packet_len(0x91));
  1483. WFIFOW(fd,0) = 0x91;
  1484. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1485. WFIFOW(fd,18) = x;
  1486. WFIFOW(fd,20) = y;
  1487. WFIFOSET(fd,packet_len(0x91));
  1488. }
  1489. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1490. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1491. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1492. {
  1493. int fd;
  1494. nullpo_retv(sd);
  1495. fd = sd->fd;
  1496. WFIFOHEAD(fd,packet_len(0x92));
  1497. WFIFOW(fd,0) = 0x92;
  1498. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1499. WFIFOW(fd,18) = x;
  1500. WFIFOW(fd,20) = y;
  1501. WFIFOL(fd,22) = htonl(ip);
  1502. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1503. WFIFOSET(fd,packet_len(0x92));
  1504. }
  1505. void clif_blown(struct block_list *bl)
  1506. {
  1507. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1508. // clif_fixpos(bl);
  1509. clif_slide(bl, bl->x, bl->y);
  1510. }
  1511. /// Visually moves(slides) a character to x,y. If the target cell
  1512. /// isn't walkable, the char doesn't move at all. If the char is
  1513. /// sitting it will stand up (ZC_STOPMOVE).
  1514. /// 0088 <id>.L <x>.W <y>.W
  1515. void clif_fixpos(struct block_list *bl)
  1516. {
  1517. unsigned char buf[10];
  1518. nullpo_retv(bl);
  1519. WBUFW(buf,0) = 0x88;
  1520. WBUFL(buf,2) = bl->id;
  1521. WBUFW(buf,6) = bl->x;
  1522. WBUFW(buf,8) = bl->y;
  1523. clif_send(buf, packet_len(0x88), bl, AREA);
  1524. if( disguised(bl) )
  1525. {
  1526. WBUFL(buf,2) = -bl->id;
  1527. clif_send(buf, packet_len(0x88), bl, SELF);
  1528. }
  1529. }
  1530. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1531. /// 00c4 <shop id>.L
  1532. void clif_npcbuysell(struct map_session_data* sd, int id)
  1533. {
  1534. int fd;
  1535. nullpo_retv(sd);
  1536. fd=sd->fd;
  1537. WFIFOHEAD(fd, packet_len(0xc4));
  1538. WFIFOW(fd,0)=0xc4;
  1539. WFIFOL(fd,2)=id;
  1540. WFIFOSET(fd,packet_len(0xc4));
  1541. }
  1542. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1543. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1544. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1545. {
  1546. int fd,i,c;
  1547. nullpo_retv(sd);
  1548. nullpo_retv(nd);
  1549. fd = sd->fd;
  1550. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1551. WFIFOW(fd,0) = 0xc6;
  1552. c = 0;
  1553. for( i = 0; i < nd->u.shop.count; i++ )
  1554. {
  1555. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1556. int val = nd->u.shop.shop_item[i].value;
  1557. if( id == NULL )
  1558. continue;
  1559. WFIFOL(fd, 4+c*11) = val;
  1560. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1561. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1562. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1563. c++;
  1564. }
  1565. WFIFOW(fd,2) = 4 + c*11;
  1566. WFIFOSET(fd,WFIFOW(fd,2));
  1567. }
  1568. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1569. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1570. void clif_selllist(struct map_session_data *sd)
  1571. {
  1572. int fd,i,c=0,val;
  1573. nullpo_retv(sd);
  1574. fd=sd->fd;
  1575. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1576. WFIFOW(fd,0)=0xc7;
  1577. for( i = 0; i < MAX_INVENTORY; i++ )
  1578. {
  1579. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1580. {
  1581. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1582. continue;
  1583. if( sd->status.inventory[i].expire_time )
  1584. continue; // Cannot Sell Rental Items
  1585. val=sd->inventory_data[i]->value_sell;
  1586. if( val < 0 )
  1587. continue;
  1588. WFIFOW(fd,4+c*10)=i+2;
  1589. WFIFOL(fd,6+c*10)=val;
  1590. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1591. c++;
  1592. }
  1593. }
  1594. WFIFOW(fd,2)=c*10+4;
  1595. WFIFOSET(fd,WFIFOW(fd,2));
  1596. }
  1597. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1598. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1599. /// Client behavior (dialog window):
  1600. /// - disable mouse targeting
  1601. /// - open the dialog window
  1602. /// - set npcid of dialog window (0 by default)
  1603. /// - if set to clear on next mes, clear contents
  1604. /// - append this text
  1605. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1606. {
  1607. int fd = sd->fd;
  1608. int slen = strlen(mes) + 9;
  1609. WFIFOHEAD(fd, slen);
  1610. WFIFOW(fd,0)=0xb4;
  1611. WFIFOW(fd,2)=slen;
  1612. WFIFOL(fd,4)=npcid;
  1613. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1614. WFIFOSET(fd,WFIFOW(fd,2));
  1615. }
  1616. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1617. /// 00b5 <npc id>.L
  1618. /// Client behavior (dialog window):
  1619. /// - disable mouse targeting
  1620. /// - open the dialog window
  1621. /// - add 'next' button
  1622. /// When 'next' is pressed:
  1623. /// - 00B9 <npcid of dialog window>.L
  1624. /// - set to clear on next mes
  1625. /// - remove 'next' button
  1626. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1627. {
  1628. int fd;
  1629. nullpo_retv(sd);
  1630. fd=sd->fd;
  1631. WFIFOHEAD(fd, packet_len(0xb5));
  1632. WFIFOW(fd,0)=0xb5;
  1633. WFIFOL(fd,2)=npcid;
  1634. WFIFOSET(fd,packet_len(0xb5));
  1635. }
  1636. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1637. /// 00b6 <npc id>.L
  1638. /// Client behavior:
  1639. /// - if dialog window is open:
  1640. /// - remove 'next' button
  1641. /// - add 'close' button
  1642. /// - else:
  1643. /// - enable mouse targeting
  1644. /// - close the dialog window
  1645. /// - close the menu window
  1646. /// When 'close' is pressed:
  1647. /// - enable mouse targeting
  1648. /// - close the dialog window
  1649. /// - close the menu window
  1650. /// - 0146 <npcid of dialog window>.L
  1651. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1652. {
  1653. int fd;
  1654. nullpo_retv(sd);
  1655. fd=sd->fd;
  1656. WFIFOHEAD(fd, packet_len(0xb6));
  1657. WFIFOW(fd,0)=0xb6;
  1658. WFIFOL(fd,2)=npcid;
  1659. WFIFOSET(fd,packet_len(0xb6));
  1660. }
  1661. /*==========================================
  1662. *
  1663. *------------------------------------------*/
  1664. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1665. {
  1666. unsigned char *buf;
  1667. int fd = sd->fd;
  1668. sd->state.using_fake_npc = 1;
  1669. WFIFOHEAD(fd, packet_len(0x78));
  1670. buf = WFIFOP(fd,0);
  1671. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1672. WBUFW(buf,0)=0x78;
  1673. #if PACKETVER >= 20071106
  1674. WBUFB(buf,2) = 0; // object type
  1675. buf = WFIFOP(fd,1);
  1676. #endif
  1677. WBUFL(buf,2)=npcid;
  1678. WBUFW(buf,14)=111;
  1679. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1680. WBUFB(buf,49)=5;
  1681. WBUFB(buf,50)=5;
  1682. WFIFOSET(fd, packet_len(0x78));
  1683. }
  1684. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1685. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1686. /// Client behavior:
  1687. /// - disable mouse targeting
  1688. /// - close the menu window
  1689. /// - open the menu window
  1690. /// - add options to the menu (separated in the text by ":")
  1691. /// - set npcid of menu window
  1692. /// - if dialog window is open:
  1693. /// - remove 'next' button
  1694. /// When 'ok' is pressed:
  1695. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1696. /// - close the menu window
  1697. /// When 'cancel' is pressed:
  1698. /// - 00B8 <npcid of menu window>.L <-1>.B
  1699. /// - enable mouse targeting
  1700. /// - close a bunch of windows...
  1701. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1702. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1703. /// TODO investigate behavior of other windows [FlavioJS]
  1704. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1705. {
  1706. int fd = sd->fd;
  1707. int slen = strlen(mes) + 9;
  1708. struct block_list *bl = NULL;
  1709. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1710. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1711. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1712. clif_sendfakenpc(sd, npcid);
  1713. WFIFOHEAD(fd, slen);
  1714. WFIFOW(fd,0)=0xb7;
  1715. WFIFOW(fd,2)=slen;
  1716. WFIFOL(fd,4)=npcid;
  1717. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1718. WFIFOSET(fd,WFIFOW(fd,2));
  1719. }
  1720. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1721. /// 0142 <npc id>.L
  1722. /// Client behavior (inputnum window):
  1723. /// - if npcid exists in the client:
  1724. /// - open the inputnum window
  1725. /// - set npcid of inputnum window
  1726. /// When 'ok' is pressed:
  1727. /// - if inputnum window has text:
  1728. /// - if npcid exists in the client:
  1729. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1730. /// - close inputnum window
  1731. void clif_scriptinput(struct map_session_data *sd, int npcid)
  1732. {
  1733. int fd;
  1734. struct block_list *bl = NULL;
  1735. nullpo_retv(sd);
  1736. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1737. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1738. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1739. clif_sendfakenpc(sd, npcid);
  1740. fd=sd->fd;
  1741. WFIFOHEAD(fd, packet_len(0x142));
  1742. WFIFOW(fd,0)=0x142;
  1743. WFIFOL(fd,2)=npcid;
  1744. WFIFOSET(fd,packet_len(0x142));
  1745. }
  1746. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1747. /// 01d4 <npc id>.L
  1748. /// Client behavior (inputstr window):
  1749. /// - if npcid is 0 or npcid exists in the client:
  1750. /// - open the inputstr window
  1751. /// - set npcid of inputstr window
  1752. /// When 'ok' is pressed:
  1753. /// - if inputstr window has text and isn't an insult(manner.txt):
  1754. /// - if npcid is 0 or npcid exists in the client:
  1755. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1756. /// - close inputstr window
  1757. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1758. {
  1759. int fd;
  1760. struct block_list *bl = NULL;
  1761. nullpo_retv(sd);
  1762. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1763. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1764. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1765. clif_sendfakenpc(sd, npcid);
  1766. fd=sd->fd;
  1767. WFIFOHEAD(fd, packet_len(0x1d4));
  1768. WFIFOW(fd,0)=0x1d4;
  1769. WFIFOL(fd,2)=npcid;
  1770. WFIFOSET(fd,packet_len(0x1d4));
  1771. }
  1772. /// Marks a position on client's minimap (ZC_COMPASS).
  1773. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1774. /// npc id:
  1775. /// is ignored in the client
  1776. /// type:
  1777. /// 0 = display mark for 15 seconds
  1778. /// 1 = display mark until dead or teleported
  1779. /// 2 = remove mark
  1780. /// color:
  1781. /// 0x00RRGGBB
  1782. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1783. {
  1784. int fd;
  1785. nullpo_retv(sd);
  1786. fd=sd->fd;
  1787. WFIFOHEAD(fd, packet_len(0x144));
  1788. WFIFOW(fd,0)=0x144;
  1789. WFIFOL(fd,2)=npc_id;
  1790. WFIFOL(fd,6)=type;
  1791. WFIFOL(fd,10)=x;
  1792. WFIFOL(fd,14)=y;
  1793. WFIFOB(fd,18)=id;
  1794. WFIFOL(fd,19)=color;
  1795. WFIFOSET(fd,packet_len(0x144));
  1796. }
  1797. /// Displays an illustration image.
  1798. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1799. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1800. /// type:
  1801. /// 0 = bottom left corner
  1802. /// 1 = bottom middle
  1803. /// 2 = bottom right corner
  1804. /// 3 = middle of screen, inside a movable window
  1805. /// 4 = middle of screen, movable with a close button, chrome-less
  1806. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1807. {
  1808. int fd;
  1809. nullpo_retv(sd);
  1810. fd=sd->fd;
  1811. WFIFOHEAD(fd, packet_len(0x1b3));
  1812. WFIFOW(fd,0)=0x1b3;
  1813. strncpy((char*)WFIFOP(fd,2),image,64);
  1814. WFIFOB(fd,66)=type;
  1815. WFIFOSET(fd,packet_len(0x1b3));
  1816. }
  1817. /*==========================================
  1818. * Fills in card data from the given item and into the buffer. [Skotlex]
  1819. *------------------------------------------*/
  1820. static void clif_addcards(unsigned char* buf, struct item* item)
  1821. {
  1822. int i=0,j;
  1823. if( item == NULL ) { //Blank data
  1824. WBUFW(buf,0) = 0;
  1825. WBUFW(buf,2) = 0;
  1826. WBUFW(buf,4) = 0;
  1827. WBUFW(buf,6) = 0;
  1828. return;
  1829. }
  1830. if( item->card[0] == CARD0_PET ) { //pet eggs
  1831. WBUFW(buf,0) = 0;
  1832. WBUFW(buf,2) = 0;
  1833. WBUFW(buf,4) = 0;
  1834. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1835. return;
  1836. }
  1837. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1838. WBUFW(buf,0) = item->card[0];
  1839. WBUFW(buf,2) = item->card[1];
  1840. WBUFW(buf,4) = item->card[2];
  1841. WBUFW(buf,6) = item->card[3];
  1842. return;
  1843. }
  1844. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1845. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1846. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  1847. //Normal items.
  1848. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1849. WBUFW(buf,0) = j;
  1850. else
  1851. WBUFW(buf,0) = item->card[i];
  1852. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1853. WBUFW(buf,2) = j;
  1854. else
  1855. WBUFW(buf,2) = item->card[i];
  1856. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1857. WBUFW(buf,4) = j;
  1858. else
  1859. WBUFW(buf,4) = item->card[i];
  1860. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1861. WBUFW(buf,6) = j;
  1862. else
  1863. WBUFW(buf,6) = item->card[i];
  1864. }
  1865. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  1866. /// 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)
  1867. /// 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)
  1868. /// 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)
  1869. void clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1870. {
  1871. int fd;
  1872. #if PACKETVER < 20061218
  1873. const int cmd = 0xa0;
  1874. #elif PACKETVER < 20071002
  1875. const int cmd = 0x29a;
  1876. #else
  1877. const int cmd = 0x2d4;
  1878. #endif
  1879. nullpo_retv(sd);
  1880. fd = sd->fd;
  1881. if( !session_isActive(fd) ) //Sasuke-
  1882. return;
  1883. WFIFOHEAD(fd,packet_len(cmd));
  1884. if( fail )
  1885. {
  1886. WFIFOW(fd,0)=cmd;
  1887. WFIFOW(fd,2)=n+2;
  1888. WFIFOW(fd,4)=amount;
  1889. WFIFOW(fd,6)=0;
  1890. WFIFOB(fd,8)=0;
  1891. WFIFOB(fd,9)=0;
  1892. WFIFOB(fd,10)=0;
  1893. WFIFOW(fd,11)=0;
  1894. WFIFOW(fd,13)=0;
  1895. WFIFOW(fd,15)=0;
  1896. WFIFOW(fd,17)=0;
  1897. WFIFOW(fd,19)=0;
  1898. WFIFOB(fd,21)=0;
  1899. WFIFOB(fd,22)=fail;
  1900. #if PACKETVER >= 20061218
  1901. WFIFOL(fd,23)=0;
  1902. #endif
  1903. #if PACKETVER >= 20071002
  1904. WFIFOW(fd,27)=0; // unknown
  1905. #endif
  1906. }
  1907. else
  1908. {
  1909. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1910. return;
  1911. WFIFOW(fd,0)=cmd;
  1912. WFIFOW(fd,2)=n+2;
  1913. WFIFOW(fd,4)=amount;
  1914. if (sd->inventory_data[n]->view_id > 0)
  1915. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1916. else
  1917. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1918. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1919. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1920. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1921. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1922. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1923. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1924. WFIFOB(fd,22)=fail;
  1925. #if PACKETVER >= 20061218
  1926. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1927. #endif
  1928. #if PACKETVER >= 20071002
  1929. WFIFOW(fd,27)=0; // unknown
  1930. #endif
  1931. }
  1932. WFIFOSET(fd,packet_len(cmd));
  1933. }
  1934. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  1935. /// 00af <index>.W <amount>.W
  1936. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  1937. {
  1938. int fd;
  1939. nullpo_retv(sd);
  1940. fd=sd->fd;
  1941. WFIFOHEAD(fd, packet_len(0xaf));
  1942. WFIFOW(fd,0)=0xaf;
  1943. WFIFOW(fd,2)=n+2;
  1944. WFIFOW(fd,4)=amount;
  1945. WFIFOSET(fd,packet_len(0xaf));
  1946. }
  1947. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  1948. /// 07fa <delete type>.W <index>.W <amount>.W
  1949. /// delete type:
  1950. /// 0 = Normal
  1951. /// 1 = Item used for a skill
  1952. /// 2 = Refine failed
  1953. /// 3 = Material changed
  1954. /// 4 = Moved to storage
  1955. /// 5 = Moved to cart
  1956. /// 6 = Item sold
  1957. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  1958. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1959. {
  1960. #if PACKETVER < 20091117
  1961. clif_dropitem(sd,n,amount);
  1962. #else
  1963. int fd;
  1964. nullpo_retv(sd);
  1965. fd=sd->fd;
  1966. WFIFOHEAD(fd, packet_len(0x7fa));
  1967. WFIFOW(fd,0)=0x7fa;
  1968. WFIFOW(fd,2)=reason;
  1969. WFIFOW(fd,4)=n+2;
  1970. WFIFOW(fd,6)=amount;
  1971. WFIFOSET(fd,packet_len(0x7fa));
  1972. #endif
  1973. }
  1974. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1975. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1976. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1977. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1978. {
  1979. if (id->view_id > 0)
  1980. WBUFW(buf,n)=id->view_id;
  1981. else
  1982. WBUFW(buf,n)=i->nameid;
  1983. WBUFB(buf,n+2)=itemtype(id->type);
  1984. WBUFB(buf,n+3)=i->identify;
  1985. if (equip >= 0) { //Equippable item
  1986. WBUFW(buf,n+4)=equip;
  1987. WBUFW(buf,n+6)=i->equip;
  1988. WBUFB(buf,n+8)=i->attribute;
  1989. WBUFB(buf,n+9)=i->refine;
  1990. } else { //Stackable item.
  1991. WBUFW(buf,n+4)=i->amount;
  1992. if (equip == -2 && id->equip == EQP_AMMO)
  1993. WBUFW(buf,n+6)=EQP_AMMO;
  1994. else
  1995. WBUFW(buf,n+6)=0;
  1996. }
  1997. }
  1998. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  1999. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2000. void clif_inventorylist(struct map_session_data *sd)
  2001. {
  2002. int i,n,ne,arrow=-1;
  2003. unsigned char *buf;
  2004. unsigned char *bufe;
  2005. #if PACKETVER < 5
  2006. const int s = 10; //Entry size.
  2007. #elif PACKETVER < 20080102
  2008. const int s = 18;
  2009. #else
  2010. const int s = 22;
  2011. #endif
  2012. #if PACKETVER < 20071002
  2013. const int se = 20;
  2014. #elif PACKETVER < 20100629
  2015. const int se = 26;
  2016. #else
  2017. const int se = 28;
  2018. #endif
  2019. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2020. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2021. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2022. {
  2023. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2024. continue;
  2025. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2026. { //Non-stackable (Equippable)
  2027. WBUFW(bufe,ne*se+4)=i+2;
  2028. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2029. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  2030. #if PACKETVER >= 20071002
  2031. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  2032. WBUFW(bufe,ne*se+28)=0; //Unknown
  2033. #endif
  2034. #if PACKETVER >= 20100629
  2035. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2036. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  2037. else
  2038. WBUFW(bufe,ne*se+30)=0;
  2039. #endif
  2040. ne++;
  2041. }
  2042. else
  2043. { //Stackable.
  2044. WBUFW(buf,n*s+4)=i+2;
  2045. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  2046. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  2047. arrow=i;
  2048. #if PACKETVER >= 5
  2049. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  2050. #endif
  2051. #if PACKETVER >= 20080102
  2052. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  2053. #endif
  2054. n++;
  2055. }
  2056. }
  2057. if( n )
  2058. {
  2059. #if PACKETVER < 5
  2060. WBUFW(buf,0)=0xa3;
  2061. #elif PACKETVER < 20080102
  2062. WBUFW(buf,0)=0x1ee;
  2063. #else
  2064. WBUFW(buf,0)=0x2e8;
  2065. #endif
  2066. WBUFW(buf,2)=4+n*s;
  2067. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2068. }
  2069. if( arrow >= 0 )
  2070. clif_arrowequip(sd,arrow);
  2071. if( ne )
  2072. {
  2073. #if PACKETVER < 20071002
  2074. WBUFW(bufe,0)=0xa4;
  2075. #else
  2076. WBUFW(bufe,0)=0x2d0;
  2077. #endif
  2078. WBUFW(bufe,2)=4+ne*se;
  2079. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2080. }
  2081. #if PACKETVER >= 20111122
  2082. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2083. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2084. continue;
  2085. if ( sd->status.inventory[i].favorite )
  2086. clif_favorite_item(sd, i);
  2087. }
  2088. #endif
  2089. if( buf ) aFree(buf);
  2090. if( bufe ) aFree(bufe);
  2091. }
  2092. //Required when items break/get-repaired. Only sends equippable item list.
  2093. void clif_equiplist(struct map_session_data *sd)
  2094. {
  2095. int i,n,fd = sd->fd;
  2096. unsigned char *buf;
  2097. #if PACKETVER < 20071002
  2098. const int cmd = 20;
  2099. #elif PACKETVER < 20100629
  2100. const int cmd = 26;
  2101. #else
  2102. const int cmd = 28;
  2103. #endif
  2104. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2105. buf = WFIFOP(fd,0);
  2106. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2107. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2108. continue;
  2109. if(itemdb_isstackable2(sd->inventory_data[i]))
  2110. continue;
  2111. //Equippable
  2112. WBUFW(buf,n*cmd+4)=i+2;
  2113. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2114. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  2115. #if PACKETVER >= 20071002
  2116. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  2117. WBUFW(buf,n*cmd+28)=0; //Unknown
  2118. #endif
  2119. #if PACKETVER >= 20100629
  2120. if (sd->inventory_data[i]->equip&EQP_VISIBLE)
  2121. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  2122. else
  2123. WBUFW(buf,n*cmd+30)=0;
  2124. #endif
  2125. n++;
  2126. }
  2127. if (n) {
  2128. #if PACKETVER < 20071002
  2129. WBUFW(buf,0)=0xa4;
  2130. #else
  2131. WBUFW(buf,0)=0x2d0;
  2132. #endif
  2133. WBUFW(buf,2)=4+n*cmd;
  2134. WFIFOSET(fd,WFIFOW(fd,2));
  2135. }
  2136. }
  2137. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  2138. {
  2139. struct item_data *id;
  2140. int i,n,ne;
  2141. unsigned char *buf;
  2142. unsigned char *bufe;
  2143. #if PACKETVER < 5
  2144. const int s = 10; //Entry size.
  2145. #elif PACKETVER < 20080102
  2146. const int s = 18;
  2147. #else
  2148. const int s = 22;
  2149. #endif
  2150. #if PACKETVER < 20071002
  2151. const int cmd = 20;
  2152. #elif PACKETVER < 20100629
  2153. const int cmd = 26;
  2154. #else
  2155. const int cmd = 28;
  2156. #endif
  2157. buf = (unsigned char*)aMalloc(items_length * s + 4);
  2158. bufe = (unsigned char*)aMalloc(items_length * cmd + 4);
  2159. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2160. {
  2161. if( items[i].nameid <= 0 )
  2162. continue;
  2163. id = itemdb_search(items[i].nameid);
  2164. if( !itemdb_isstackable2(id) )
  2165. { //Equippable
  2166. WBUFW(bufe,ne*cmd+4)=i+1;
  2167. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  2168. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  2169. #if PACKETVER >= 20071002
  2170. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  2171. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2172. #endif
  2173. ne++;
  2174. }
  2175. else
  2176. { //Stackable
  2177. WBUFW(buf,n*s+4)=i+1;
  2178. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  2179. #if PACKETVER >= 5
  2180. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  2181. #endif
  2182. #if PACKETVER >= 20080102
  2183. WBUFL(buf,n*s+22)=items[i].expire_time;
  2184. #endif
  2185. n++;
  2186. }
  2187. }
  2188. if( n )
  2189. {
  2190. #if PACKETVER < 5
  2191. WBUFW(buf,0)=0xa5;
  2192. #elif PACKETVER < 20080102
  2193. WBUFW(buf,0)=0x1f0;
  2194. #else
  2195. WBUFW(buf,0)=0x2ea;
  2196. #endif
  2197. WBUFW(buf,2)=4+n*s;
  2198. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2199. }
  2200. if( ne )
  2201. {
  2202. #if PACKETVER < 20071002
  2203. WBUFW(bufe,0)=0xa6;
  2204. #else
  2205. WBUFW(bufe,0)=0x2d1;
  2206. #endif
  2207. WBUFW(bufe,2)=4+ne*cmd;
  2208. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2209. }
  2210. if( buf ) aFree(buf);
  2211. if( bufe ) aFree(bufe);
  2212. }
  2213. void clif_cartlist(struct map_session_data *sd)
  2214. {
  2215. struct item_data *id;
  2216. int i,n,ne;
  2217. unsigned char *buf;
  2218. unsigned char *bufe;
  2219. #if PACKETVER < 5
  2220. const int s = 10; //Entry size.
  2221. #elif PACKETVER < 20080102
  2222. const int s = 18;
  2223. #else
  2224. const int s = 22;
  2225. #endif
  2226. #if PACKETVER < 20071002
  2227. const int cmd = 20;
  2228. #elif PACKETVER < 20100629
  2229. const int cmd = 26;
  2230. #else
  2231. const int cmd = 28;
  2232. #endif
  2233. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2234. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2235. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2236. {
  2237. if( sd->status.cart[i].nameid <= 0 )
  2238. continue;
  2239. id = itemdb_search(sd->status.cart[i].nameid);
  2240. if( !itemdb_isstackable2(id) )
  2241. { //Equippable
  2242. WBUFW(bufe,ne*cmd+4)=i+2;
  2243. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2244. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2245. #if PACKETVER >= 20071002
  2246. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2247. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2248. #endif
  2249. ne++;
  2250. }
  2251. else
  2252. { //Stackable
  2253. WBUFW(buf,n*s+4)=i+2;
  2254. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2255. #if PACKETVER >= 5
  2256. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2257. #endif
  2258. #if PACKETVER >= 20080102
  2259. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2260. #endif
  2261. n++;
  2262. }
  2263. }
  2264. if( n )
  2265. {
  2266. #if PACKETVER < 5
  2267. WBUFW(buf,0)=0x123;
  2268. #elif PACKETVER < 20080102
  2269. WBUFW(buf,0)=0x1ef;
  2270. #else
  2271. WBUFW(buf,0)=0x2e9;
  2272. #endif
  2273. WBUFW(buf,2)=4+n*s;
  2274. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2275. }
  2276. if( ne )
  2277. {
  2278. #if PACKETVER < 20071002
  2279. WBUFW(bufe,0)=0x122;
  2280. #else
  2281. WBUFW(bufe,0)=0x2d2;
  2282. #endif
  2283. WBUFW(bufe,2)=4+ne*cmd;
  2284. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2285. }
  2286. if( buf ) aFree(buf);
  2287. if( bufe ) aFree(bufe);
  2288. }
  2289. /// Removes cart (ZC_CARTOFF).
  2290. /// 012b
  2291. /// Client behaviour:
  2292. /// Closes the cart storage and removes all it's items from memory.
  2293. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2294. void clif_clearcart(int fd)
  2295. {
  2296. WFIFOHEAD(fd, packet_len(0x12b));
  2297. WFIFOW(fd,0) = 0x12b;
  2298. WFIFOSET(fd, packet_len(0x12b));
  2299. }
  2300. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2301. /// 01eb <account id>.L <x>.W <y>.W
  2302. void clif_guild_xy(struct map_session_data *sd)
  2303. {
  2304. unsigned char buf[10];
  2305. nullpo_retv(sd);
  2306. WBUFW(buf,0)=0x1eb;
  2307. WBUFL(buf,2)=sd->status.account_id;
  2308. WBUFW(buf,6)=sd->bl.x;
  2309. WBUFW(buf,8)=sd->bl.y;
  2310. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2311. }
  2312. /*==========================================
  2313. * Sends x/y dot to a single fd. [Skotlex]
  2314. *------------------------------------------*/
  2315. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2316. {
  2317. if( sd->bg_id )
  2318. return;
  2319. WFIFOHEAD(fd,packet_len(0x1eb));
  2320. WFIFOW(fd,0)=0x1eb;
  2321. WFIFOL(fd,2)=sd->status.account_id;
  2322. WFIFOW(fd,6)=sd->bl.x;
  2323. WFIFOW(fd,8)=sd->bl.y;
  2324. WFIFOSET(fd,packet_len(0x1eb));
  2325. }
  2326. // Guild XY locators [Valaris]
  2327. void clif_guild_xy_remove(struct map_session_data *sd)
  2328. {
  2329. unsigned char buf[10];
  2330. nullpo_retv(sd);
  2331. WBUFW(buf,0)=0x1eb;
  2332. WBUFL(buf,2)=sd->status.account_id;
  2333. WBUFW(buf,6)=-1;
  2334. WBUFW(buf,8)=-1;
  2335. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2336. }
  2337. /*==========================================
  2338. *
  2339. *------------------------------------------*/
  2340. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2341. {
  2342. struct map_session_data *sd, *tsd;
  2343. #if PACKETVER < 20100126
  2344. const int cmd = 0x106;
  2345. #else
  2346. const int cmd = 0x80e;
  2347. #endif
  2348. sd = va_arg(ap, struct map_session_data *);
  2349. tsd = (TBL_PC *)bl;
  2350. nullpo_ret(sd);
  2351. nullpo_ret(tsd);
  2352. if( !tsd->fd || tsd == sd )
  2353. return 0;
  2354. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2355. return 0;
  2356. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2357. WFIFOW(tsd->fd,0) = cmd;
  2358. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2359. #if PACKETVER < 20100126
  2360. if( sd->battle_status.max_hp > INT16_MAX )
  2361. { //To correctly display the %hp bar. [Skotlex]
  2362. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2363. WFIFOW(tsd->fd,8) = 100;
  2364. } else {
  2365. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2366. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2367. }
  2368. #else
  2369. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2370. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2371. #endif
  2372. WFIFOSET(tsd->fd,packet_len(cmd));
  2373. return 0;
  2374. }
  2375. /*==========================================
  2376. * Server tells all players that are allowed to view HP bars
  2377. * and are nearby 'sd' that 'sd' hp bar was updated.
  2378. *------------------------------------------*/
  2379. static int clif_hpmeter(struct map_session_data *sd)
  2380. {
  2381. nullpo_ret(sd);
  2382. 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);
  2383. return 0;
  2384. }
  2385. /// Notifies client of a character parameter change.
  2386. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2387. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2388. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2389. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2390. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2391. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2392. /// TODO: Extract individual packets.
  2393. /// FIXME: Packet lengths from packet_len(cmd)
  2394. void clif_updatestatus(struct map_session_data *sd,int type)
  2395. {
  2396. int fd,len=8;
  2397. nullpo_retv(sd);
  2398. fd=sd->fd;
  2399. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2400. return;
  2401. WFIFOHEAD(fd, 14);
  2402. WFIFOW(fd,0)=0xb0;
  2403. WFIFOW(fd,2)=type;
  2404. switch(type){
  2405. // 00b0
  2406. case SP_WEIGHT:
  2407. pc_updateweightstatus(sd);
  2408. WFIFOHEAD(fd,14);
  2409. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2410. WFIFOW(fd,2)=type;
  2411. WFIFOL(fd,4)=sd->weight;
  2412. break;
  2413. case SP_MAXWEIGHT:
  2414. WFIFOL(fd,4)=sd->max_weight;
  2415. break;
  2416. case SP_SPEED:
  2417. WFIFOL(fd,4)=sd->battle_status.speed;
  2418. break;
  2419. case SP_BASELEVEL:
  2420. WFIFOL(fd,4)=sd->status.base_level;
  2421. break;
  2422. case SP_JOBLEVEL:
  2423. WFIFOL(fd,4)=sd->status.job_level;
  2424. break;
  2425. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2426. WFIFOL(fd,4)=sd->status.karma;
  2427. break;
  2428. case SP_MANNER:
  2429. WFIFOL(fd,4)=sd->status.manner;
  2430. break;
  2431. case SP_STATUSPOINT:
  2432. WFIFOL(fd,4)=sd->status.status_point;
  2433. break;
  2434. case SP_SKILLPOINT:
  2435. WFIFOL(fd,4)=sd->status.skill_point;
  2436. break;
  2437. case SP_HIT:
  2438. WFIFOL(fd,4)=sd->battle_status.hit;
  2439. break;
  2440. case SP_FLEE1:
  2441. WFIFOL(fd,4)=sd->battle_status.flee;
  2442. break;
  2443. case SP_FLEE2:
  2444. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2445. break;
  2446. case SP_MAXHP:
  2447. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2448. break;
  2449. case SP_MAXSP:
  2450. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2451. break;
  2452. case SP_HP:
  2453. WFIFOL(fd,4)=sd->battle_status.hp;
  2454. // TODO: Won't these overwrite the current packet?
  2455. clif_hpmeter(sd);
  2456. if( !battle_config.party_hp_mode && sd->status.party_id )
  2457. clif_party_hp(sd);
  2458. if( sd->bg_id )
  2459. clif_bg_hp(sd);
  2460. break;
  2461. case SP_SP:
  2462. WFIFOL(fd,4)=sd->battle_status.sp;
  2463. break;
  2464. case SP_ASPD:
  2465. WFIFOL(fd,4)=sd->battle_status.amotion;
  2466. break;
  2467. case SP_ATK1:
  2468. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2469. break;
  2470. case SP_DEF1:
  2471. WFIFOL(fd,4)=pc_leftside_def(sd);
  2472. break;
  2473. case SP_MDEF1:
  2474. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2475. break;
  2476. case SP_ATK2:
  2477. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2478. break;
  2479. case SP_DEF2:
  2480. WFIFOL(fd,4)=pc_rightside_def(sd);
  2481. break;
  2482. case SP_MDEF2: {
  2483. //negative check (in case you have something like Berserk active)
  2484. int mdef2 = pc_rightside_mdef(sd);
  2485. WFIFOL(fd,4)=
  2486. #ifndef RENEWAL
  2487. ( mdef2 < 0 ) ? 0 :
  2488. #endif
  2489. mdef2;
  2490. }
  2491. break;
  2492. case SP_CRITICAL:
  2493. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2494. break;
  2495. case SP_MATK1:
  2496. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2497. break;
  2498. case SP_MATK2:
  2499. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2500. break;
  2501. case SP_ZENY:
  2502. WFIFOW(fd,0)=0xb1;
  2503. WFIFOL(fd,4)=sd->status.zeny;
  2504. break;
  2505. case SP_BASEEXP:
  2506. WFIFOW(fd,0)=0xb1;
  2507. WFIFOL(fd,4)=sd->status.base_exp;
  2508. break;
  2509. case SP_JOBEXP:
  2510. WFIFOW(fd,0)=0xb1;
  2511. WFIFOL(fd,4)=sd->status.job_exp;
  2512. break;
  2513. case SP_NEXTBASEEXP:
  2514. WFIFOW(fd,0)=0xb1;
  2515. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2516. break;
  2517. case SP_NEXTJOBEXP:
  2518. WFIFOW(fd,0)=0xb1;
  2519. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2520. break;
  2521. /**
  2522. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2523. **/
  2524. case SP_USTR:
  2525. case SP_UAGI:
  2526. case SP_UVIT:
  2527. case SP_UINT:
  2528. case SP_UDEX:
  2529. case SP_ULUK:
  2530. WFIFOW(fd,0)=0xbe;
  2531. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2532. len=5;
  2533. break;
  2534. /**
  2535. * Tells the client how far it is allowed to attack (weapon range)
  2536. **/
  2537. case SP_ATTACKRANGE:
  2538. WFIFOW(fd,0)=0x13a;
  2539. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2540. len=4;
  2541. break;
  2542. case SP_STR:
  2543. WFIFOW(fd,0)=0x141;
  2544. WFIFOL(fd,2)=type;
  2545. WFIFOL(fd,6)=sd->status.str;
  2546. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2547. len=14;
  2548. break;
  2549. case SP_AGI:
  2550. WFIFOW(fd,0)=0x141;
  2551. WFIFOL(fd,2)=type;
  2552. WFIFOL(fd,6)=sd->status.agi;
  2553. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2554. len=14;
  2555. break;
  2556. case SP_VIT:
  2557. WFIFOW(fd,0)=0x141;
  2558. WFIFOL(fd,2)=type;
  2559. WFIFOL(fd,6)=sd->status.vit;
  2560. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2561. len=14;
  2562. break;
  2563. case SP_INT:
  2564. WFIFOW(fd,0)=0x141;
  2565. WFIFOL(fd,2)=type;
  2566. WFIFOL(fd,6)=sd->status.int_;
  2567. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2568. len=14;
  2569. break;
  2570. case SP_DEX:
  2571. WFIFOW(fd,0)=0x141;
  2572. WFIFOL(fd,2)=type;
  2573. WFIFOL(fd,6)=sd->status.dex;
  2574. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2575. len=14;
  2576. break;
  2577. case SP_LUK:
  2578. WFIFOW(fd,0)=0x141;
  2579. WFIFOL(fd,2)=type;
  2580. WFIFOL(fd,6)=sd->status.luk;
  2581. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2582. len=14;
  2583. break;
  2584. case SP_CARTINFO:
  2585. WFIFOW(fd,0)=0x121;
  2586. WFIFOW(fd,2)=sd->cart_num;
  2587. WFIFOW(fd,4)=MAX_CART;
  2588. WFIFOL(fd,6)=sd->cart_weight;
  2589. WFIFOL(fd,10)=sd->cart_weight_max;
  2590. len=14;
  2591. break;
  2592. default:
  2593. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2594. return;
  2595. }
  2596. WFIFOSET(fd,len);
  2597. }
  2598. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2599. /// 01ab <account id>.L <var id>.W <value>.L
  2600. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2601. {
  2602. unsigned char buf[12];
  2603. nullpo_retv(sd);
  2604. WBUFW(buf,0)=0x1ab;
  2605. WBUFL(buf,2)=sd->bl.id;
  2606. WBUFW(buf,6)=type;
  2607. switch(type)
  2608. {
  2609. case SP_MANNER:
  2610. WBUFL(buf,8)=val;
  2611. break;
  2612. default:
  2613. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2614. return;
  2615. }
  2616. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2617. }
  2618. /// Updates sprite/style properties of an object.
  2619. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2620. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2621. void clif_changelook(struct block_list *bl,int type,int val)
  2622. {
  2623. unsigned char buf[16];
  2624. struct map_session_data* sd;
  2625. struct status_change* sc;
  2626. struct view_data* vd;
  2627. enum send_target target = AREA;
  2628. nullpo_retv(bl);
  2629. sd = BL_CAST(BL_PC, bl);
  2630. sc = status_get_sc(bl);
  2631. vd = status_get_viewdata(bl);
  2632. //nullpo_ret(vd);
  2633. if( vd ) //temp hack to let Warp Portal change appearance
  2634. switch(type)
  2635. {
  2636. case LOOK_WEAPON:
  2637. if (sd)
  2638. {
  2639. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2640. val = vd->weapon;
  2641. }
  2642. else vd->weapon = val;
  2643. break;
  2644. case LOOK_SHIELD:
  2645. if (sd)
  2646. {
  2647. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2648. val = vd->shield;
  2649. }
  2650. else vd->shield = val;
  2651. break;
  2652. case LOOK_BASE:
  2653. vd->class_ = val;
  2654. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2655. vd->weapon = vd->shield = 0;
  2656. if (vd->cloth_color && (
  2657. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2658. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2659. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2660. ))
  2661. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2662. break;
  2663. case LOOK_HAIR:
  2664. vd->hair_style = val;
  2665. break;
  2666. case LOOK_HEAD_BOTTOM:
  2667. vd->head_bottom = val;
  2668. break;
  2669. case LOOK_HEAD_TOP:
  2670. vd->head_top = val;
  2671. break;
  2672. case LOOK_HEAD_MID:
  2673. vd->head_mid = val;
  2674. break;
  2675. case LOOK_HAIR_COLOR:
  2676. vd->hair_color = val;
  2677. break;
  2678. case LOOK_CLOTHES_COLOR:
  2679. if (val && (
  2680. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2681. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2682. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2683. ))
  2684. val = 0;
  2685. vd->cloth_color = val;
  2686. break;
  2687. case LOOK_SHOES:
  2688. #if PACKETVER > 3
  2689. if (sd) {
  2690. int n;
  2691. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2692. if(sd->inventory_data[n]->view_id > 0)
  2693. val = sd->inventory_data[n]->view_id;
  2694. else
  2695. val = sd->status.inventory[n].nameid;
  2696. } else
  2697. val = 0;
  2698. }
  2699. #endif
  2700. //Shoes? No packet uses this....
  2701. break;
  2702. case LOOK_BODY:
  2703. // unknown purpose
  2704. break;
  2705. case LOOK_ROBE:
  2706. #if PACKETVER < 20110111
  2707. return;
  2708. #else
  2709. vd->robe = val;
  2710. #endif
  2711. break;
  2712. }
  2713. // prevent leaking the presence of GM-hidden objects
  2714. if( sc && sc->option&OPTION_INVISIBLE )
  2715. target = SELF;
  2716. #if PACKETVER < 4
  2717. WBUFW(buf,0)=0xc3;
  2718. WBUFL(buf,2)=bl->id;
  2719. WBUFB(buf,6)=type;
  2720. WBUFB(buf,7)=val;
  2721. clif_send(buf,packet_len(0xc3),bl,target);
  2722. #else
  2723. WBUFW(buf,0)=0x1d7;
  2724. WBUFL(buf,2)=bl->id;
  2725. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2726. WBUFB(buf,6)=LOOK_WEAPON;
  2727. WBUFW(buf,7)=vd->weapon;
  2728. WBUFW(buf,9)=vd->shield;
  2729. } else {
  2730. WBUFB(buf,6)=type;
  2731. WBUFL(buf,7)=val;
  2732. }
  2733. clif_send(buf,packet_len(0x1d7),bl,target);
  2734. #endif
  2735. }
  2736. //Sends a change-base-look packet required for traps as they are triggered.
  2737. void clif_changetraplook(struct block_list *bl,int val)
  2738. {
  2739. unsigned char buf[32];
  2740. #if PACKETVER < 4
  2741. WBUFW(buf,0)=0xc3;
  2742. WBUFL(buf,2)=bl->id;
  2743. WBUFB(buf,6)=LOOK_BASE;
  2744. WBUFB(buf,7)=val;
  2745. clif_send(buf,packet_len(0xc3),bl,AREA);
  2746. #else
  2747. WBUFW(buf,0)=0x1d7;
  2748. WBUFL(buf,2)=bl->id;
  2749. WBUFB(buf,6)=LOOK_BASE;
  2750. WBUFW(buf,7)=val;
  2751. WBUFW(buf,9)=0;
  2752. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2753. #endif
  2754. }
  2755. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2756. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2757. {
  2758. unsigned char buf[32];
  2759. #if PACKETVER < 4
  2760. WBUFW(buf,0)=0xc3;
  2761. WBUFL(buf,2)=id;
  2762. WBUFB(buf,6)=type;
  2763. WBUFB(buf,7)=val;
  2764. clif_send(buf,packet_len(0xc3),bl,target);
  2765. #else
  2766. WBUFW(buf,0)=0x1d7;
  2767. WBUFL(buf,2)=id;
  2768. WBUFB(buf,6)=type;
  2769. WBUFW(buf,7)=val;
  2770. WBUFW(buf,9)=0;
  2771. clif_send(buf,packet_len(0x1d7),bl,target);
  2772. #endif
  2773. }
  2774. /// Character status (ZC_STATUS).
  2775. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2776. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2777. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2778. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2779. void clif_initialstatus(struct map_session_data *sd)
  2780. {
  2781. int fd, mdef2;
  2782. unsigned char *buf;
  2783. nullpo_retv(sd);
  2784. fd=sd->fd;
  2785. WFIFOHEAD(fd,packet_len(0xbd));
  2786. buf=WFIFOP(fd,0);
  2787. WBUFW(buf,0)=0xbd;
  2788. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2789. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2790. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR,1);
  2791. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2792. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI,1);
  2793. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2794. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT,1);
  2795. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2796. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT,1);
  2797. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2798. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX,1);
  2799. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2800. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK,1);
  2801. WBUFW(buf,16) = pc_leftside_atk(sd);
  2802. WBUFW(buf,18) = pc_rightside_atk(sd);
  2803. WBUFW(buf,20) = pc_rightside_matk(sd);
  2804. WBUFW(buf,22) = pc_leftside_matk(sd);
  2805. WBUFW(buf,24) = pc_leftside_def(sd);
  2806. WBUFW(buf,26) = pc_rightside_def(sd);
  2807. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2808. mdef2 = pc_rightside_mdef(sd);
  2809. WBUFW(buf,30) =
  2810. #ifndef RENEWAL
  2811. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2812. #endif
  2813. mdef2;
  2814. WBUFW(buf,32) = sd->battle_status.hit;
  2815. WBUFW(buf,34) = sd->battle_status.flee;
  2816. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2817. WBUFW(buf,38) = sd->battle_status.cri/10;
  2818. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2819. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2820. WFIFOSET(fd,packet_len(0xbd));
  2821. clif_updatestatus(sd,SP_STR);
  2822. clif_updatestatus(sd,SP_AGI);
  2823. clif_updatestatus(sd,SP_VIT);
  2824. clif_updatestatus(sd,SP_INT);
  2825. clif_updatestatus(sd,SP_DEX);
  2826. clif_updatestatus(sd,SP_LUK);
  2827. clif_updatestatus(sd,SP_ATTACKRANGE);
  2828. clif_updatestatus(sd,SP_ASPD);
  2829. }
  2830. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2831. /// 013c <index>.W
  2832. void clif_arrowequip(struct map_session_data *sd,int val)
  2833. {
  2834. int fd;
  2835. nullpo_retv(sd);
  2836. pc_stop_attack(sd); // [Valaris]
  2837. fd=sd->fd;
  2838. WFIFOHEAD(fd, packet_len(0x013c));
  2839. WFIFOW(fd,0)=0x013c;
  2840. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2841. WFIFOSET(fd,packet_len(0x013c));
  2842. }
  2843. /// Ammunition action message (ZC_ACTION_FAILURE).
  2844. /// 013b <type>.W
  2845. /// type:
  2846. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2847. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2848. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2849. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2850. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2851. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2852. void clif_arrow_fail(struct map_session_data *sd,int type)
  2853. {
  2854. int fd;
  2855. nullpo_retv(sd);
  2856. fd=sd->fd;
  2857. WFIFOHEAD(fd, packet_len(0x013b));
  2858. WFIFOW(fd,0)=0x013b;
  2859. WFIFOW(fd,2)=type;
  2860. WFIFOSET(fd,packet_len(0x013b));
  2861. }
  2862. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2863. /// 01ad <packet len>.W { <name id>.W }*
  2864. void clif_arrow_create_list(struct map_session_data *sd)
  2865. {
  2866. int i, c, j;
  2867. int fd;
  2868. nullpo_retv(sd);
  2869. fd = sd->fd;
  2870. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2871. WFIFOW(fd,0) = 0x1ad;
  2872. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2873. if (skill_arrow_db[i].nameid > 0 &&
  2874. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2875. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2876. {
  2877. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2878. WFIFOW(fd,c*2+4) = j;
  2879. else
  2880. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2881. c++;
  2882. }
  2883. }
  2884. WFIFOW(fd,2) = c*2+4;
  2885. WFIFOSET(fd, WFIFOW(fd,2));
  2886. if (c > 0) {
  2887. sd->menuskill_id = AC_MAKINGARROW;
  2888. sd->menuskill_val = c;
  2889. }
  2890. }
  2891. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  2892. /// 00bc <status id>.W <result>.B <value>.B
  2893. /// status id:
  2894. /// SP_STR ~ SP_LUK
  2895. /// result:
  2896. /// 0 = failure
  2897. /// 1 = success
  2898. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2899. {
  2900. int fd;
  2901. nullpo_retv(sd);
  2902. fd=sd->fd;
  2903. WFIFOHEAD(fd,packet_len(0xbc));
  2904. WFIFOW(fd,0)=0xbc;
  2905. WFIFOW(fd,2)=type;
  2906. WFIFOB(fd,4)=ok;
  2907. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  2908. WFIFOSET(fd,packet_len(0xbc));
  2909. }
  2910. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  2911. /// 00aa <index>.W <equip location>.W <result>.B
  2912. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  2913. /// result:
  2914. /// 0 = failure
  2915. /// 1 = success
  2916. /// 2 = failure due to low level
  2917. void clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2918. {
  2919. int fd;
  2920. nullpo_retv(sd);
  2921. fd=sd->fd;
  2922. WFIFOHEAD(fd,packet_len(0xaa));
  2923. WFIFOW(fd,0)=0xaa;
  2924. WFIFOW(fd,2)=n+2;
  2925. WFIFOW(fd,4)=pos;
  2926. #if PACKETVER < 20100629
  2927. WFIFOB(fd,6)=ok;
  2928. #else
  2929. if (ok && sd->inventory_data[n]->equip&EQP_VISIBLE)
  2930. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2931. else
  2932. WFIFOW(fd,6)=0;
  2933. WFIFOB(fd,8)=ok;
  2934. #endif
  2935. WFIFOSET(fd,packet_len(0xaa));
  2936. }
  2937. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  2938. /// 00ac <index>.W <equip location>.W <result>.B
  2939. /// result:
  2940. /// 0 = failure
  2941. /// 1 = success
  2942. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2943. {
  2944. int fd;
  2945. nullpo_retv(sd);
  2946. fd=sd->fd;
  2947. WFIFOHEAD(fd,packet_len(0xac));
  2948. WFIFOW(fd,0)=0xac;
  2949. WFIFOW(fd,2)=n+2;
  2950. WFIFOW(fd,4)=pos;
  2951. WFIFOB(fd,6)=ok;
  2952. WFIFOSET(fd,packet_len(0xac));
  2953. }
  2954. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  2955. /// 019b <id>.L <effect id>.L
  2956. /// effect id:
  2957. /// 0 = base level up
  2958. /// 1 = job level up
  2959. /// 2 = refine failure
  2960. /// 3 = refine success
  2961. /// 4 = game over
  2962. /// 5 = pharmacy success
  2963. /// 6 = pharmacy failure
  2964. /// 7 = base level up (super novice)
  2965. /// 8 = job level up (super novice)
  2966. /// 9 = base level up (taekwon)
  2967. void clif_misceffect(struct block_list* bl,int type)
  2968. {
  2969. unsigned char buf[32];
  2970. nullpo_retv(bl);
  2971. WBUFW(buf,0) = 0x19b;
  2972. WBUFL(buf,2) = bl->id;
  2973. WBUFL(buf,6) = type;
  2974. clif_send(buf,packet_len(0x19b),bl,AREA);
  2975. }
  2976. /// Notifies clients in the area of a state change.
  2977. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  2978. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  2979. void clif_changeoption(struct block_list* bl)
  2980. {
  2981. unsigned char buf[32];
  2982. struct status_change *sc;
  2983. struct map_session_data* sd;
  2984. nullpo_retv(bl);
  2985. sc = status_get_sc(bl);
  2986. if (!sc) return; //How can an option change if there's no sc?
  2987. sd = BL_CAST(BL_PC, bl);
  2988. #if PACKETVER >= 7
  2989. WBUFW(buf,0) = 0x229;
  2990. WBUFL(buf,2) = bl->id;
  2991. WBUFW(buf,6) = sc->opt1;
  2992. WBUFW(buf,8) = sc->opt2;
  2993. WBUFL(buf,10) = sc->option;
  2994. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2995. if(disguised(bl)) {
  2996. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2997. WBUFL(buf,2) = -bl->id;
  2998. clif_send(buf,packet_len(0x229),bl,SELF);
  2999. WBUFL(buf,2) = bl->id;
  3000. WBUFL(buf,10) = OPTION_INVISIBLE;
  3001. clif_send(buf,packet_len(0x229),bl,SELF);
  3002. } else
  3003. clif_send(buf,packet_len(0x229),bl,AREA);
  3004. #else
  3005. WBUFW(buf,0) = 0x119;
  3006. WBUFL(buf,2) = bl->id;
  3007. WBUFW(buf,6) = sc->opt1;
  3008. WBUFW(buf,8) = sc->opt2;
  3009. WBUFW(buf,10) = sc->option;
  3010. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3011. if(disguised(bl)) {
  3012. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3013. WBUFL(buf,2) = -bl->id;
  3014. clif_send(buf,packet_len(0x119),bl,SELF);
  3015. WBUFL(buf,2) = bl->id;
  3016. WBUFW(buf,10) = OPTION_INVISIBLE;
  3017. clif_send(buf,packet_len(0x119),bl,SELF);
  3018. } else
  3019. clif_send(buf,packet_len(0x119),bl,AREA);
  3020. #endif
  3021. }
  3022. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3023. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3024. void clif_changeoption2(struct block_list* bl)
  3025. {
  3026. unsigned char buf[20];
  3027. struct status_change *sc;
  3028. sc = status_get_sc(bl);
  3029. if (!sc) return; //How can an option change if there's no sc?
  3030. WBUFW(buf,0) = 0x28a;
  3031. WBUFL(buf,2) = bl->id;
  3032. WBUFL(buf,6) = sc->option;
  3033. WBUFL(buf,10) = clif_setlevel(bl);
  3034. WBUFL(buf,14) = sc->opt3;
  3035. if(disguised(bl)) {
  3036. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3037. WBUFL(buf,2) = -bl->id;
  3038. clif_send(buf,packet_len(0x28a),bl,SELF);
  3039. WBUFL(buf,2) = bl->id;
  3040. WBUFL(buf,6) = OPTION_INVISIBLE;
  3041. clif_send(buf,packet_len(0x28a),bl,SELF);
  3042. } else
  3043. clif_send(buf,packet_len(0x28a),bl,AREA);
  3044. }
  3045. /// Notifies the client about the result of an item use request.
  3046. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3047. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3048. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3049. {
  3050. nullpo_retv(sd);
  3051. if(!ok) {
  3052. int fd=sd->fd;
  3053. WFIFOHEAD(fd,packet_len(0xa8));
  3054. WFIFOW(fd,0)=0xa8;
  3055. WFIFOW(fd,2)=index+2;
  3056. WFIFOW(fd,4)=amount;
  3057. WFIFOB(fd,6)=ok;
  3058. WFIFOSET(fd,packet_len(0xa8));
  3059. }
  3060. else {
  3061. #if PACKETVER < 3
  3062. int fd=sd->fd;
  3063. WFIFOHEAD(fd,packet_len(0xa8));
  3064. WFIFOW(fd,0)=0xa8;
  3065. WFIFOW(fd,2)=index+2;
  3066. WFIFOW(fd,4)=amount;
  3067. WFIFOB(fd,6)=ok;
  3068. WFIFOSET(fd,packet_len(0xa8));
  3069. #else
  3070. unsigned char buf[32];
  3071. WBUFW(buf,0)=0x1c8;
  3072. WBUFW(buf,2)=index+2;
  3073. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3074. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3075. else
  3076. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3077. WBUFL(buf,6)=sd->bl.id;
  3078. WBUFW(buf,10)=amount;
  3079. WBUFB(buf,12)=ok;
  3080. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3081. #endif
  3082. }
  3083. }
  3084. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3085. /// 00d6 <flag>.B
  3086. /// flag:
  3087. /// 0 = Room has been successfully created (opens chat room)
  3088. /// 1 = Room limit exceeded
  3089. /// 2 = Same room already exists
  3090. void clif_createchat(struct map_session_data* sd, int flag)
  3091. {
  3092. int fd;
  3093. nullpo_retv(sd);
  3094. fd = sd->fd;
  3095. WFIFOHEAD(fd,packet_len(0xd6));
  3096. WFIFOW(fd,0) = 0xd6;
  3097. WFIFOB(fd,2) = flag;
  3098. WFIFOSET(fd,packet_len(0xd6));
  3099. }
  3100. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3101. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3102. /// type:
  3103. /// 0 = private (password protected)
  3104. /// 1 = public
  3105. /// 2 = arena (npc waiting room)
  3106. /// 3 = PK zone (non-clickable)
  3107. void clif_dispchat(struct chat_data* cd, int fd)
  3108. {
  3109. unsigned char buf[128];
  3110. uint8 type;
  3111. if( cd == NULL || cd->owner == NULL )
  3112. return;
  3113. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3114. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3115. : 1;
  3116. WBUFW(buf, 0) = 0xd7;
  3117. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3118. WBUFL(buf, 4) = cd->owner->id;
  3119. WBUFL(buf, 8) = cd->bl.id;
  3120. WBUFW(buf,12) = cd->limit;
  3121. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3122. WBUFB(buf,16) = type;
  3123. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3124. if( fd ) {
  3125. WFIFOHEAD(fd,WBUFW(buf,2));
  3126. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3127. WFIFOSET(fd,WBUFW(buf,2));
  3128. } else {
  3129. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3130. }
  3131. }
  3132. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3133. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3134. /// type:
  3135. /// 0 = private (password protected)
  3136. /// 1 = public
  3137. /// 2 = arena (npc waiting room)
  3138. /// 3 = PK zone (non-clickable)
  3139. void clif_changechatstatus(struct chat_data* cd)
  3140. {
  3141. unsigned char buf[128];
  3142. uint8 type;
  3143. if( cd == NULL || cd->usersd[0] == NULL )
  3144. return;
  3145. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3146. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3147. : 1;
  3148. WBUFW(buf, 0) = 0xdf;
  3149. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3150. WBUFL(buf, 4) = cd->owner->id;
  3151. WBUFL(buf, 8) = cd->bl.id;
  3152. WBUFW(buf,12) = cd->limit;
  3153. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3154. WBUFB(buf,16) = type;
  3155. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3156. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3157. }
  3158. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3159. /// 00d8 <chat id>.L
  3160. void clif_clearchat(struct chat_data *cd,int fd)
  3161. {
  3162. unsigned char buf[32];
  3163. nullpo_retv(cd);
  3164. WBUFW(buf,0) = 0xd8;
  3165. WBUFL(buf,2) = cd->bl.id;
  3166. if( fd ) {
  3167. WFIFOHEAD(fd,packet_len(0xd8));
  3168. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3169. WFIFOSET(fd,packet_len(0xd8));
  3170. } else {
  3171. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3172. }
  3173. }
  3174. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3175. /// 00da <result>.B
  3176. /// result:
  3177. /// 0 = room full
  3178. /// 1 = wrong password
  3179. /// 2 = kicked
  3180. /// 3 = success (no message)
  3181. /// 4 = no enough zeny
  3182. /// 5 = too low level
  3183. /// 6 = too high level
  3184. /// 7 = unsuitable job class
  3185. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3186. {
  3187. int fd;
  3188. nullpo_retv(sd);
  3189. fd = sd->fd;
  3190. WFIFOHEAD(fd,packet_len(0xda));
  3191. WFIFOW(fd,0) = 0xda;
  3192. WFIFOB(fd,2) = flag;
  3193. WFIFOSET(fd,packet_len(0xda));
  3194. }
  3195. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3196. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3197. /// role:
  3198. /// 0 = owner (menu)
  3199. /// 1 = normal
  3200. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3201. {
  3202. int fd;
  3203. int i,t;
  3204. nullpo_retv(sd);
  3205. nullpo_retv(cd);
  3206. fd = sd->fd;
  3207. if (!session_isActive(fd))
  3208. return;
  3209. t = (int)(cd->owner->type == BL_NPC);
  3210. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3211. WFIFOW(fd, 0) = 0xdb;
  3212. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3213. WFIFOL(fd, 4) = cd->bl.id;
  3214. if(cd->owner->type == BL_NPC){
  3215. WFIFOL(fd, 30) = 1;
  3216. WFIFOL(fd, 8) = 0;
  3217. memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3218. for (i = 0; i < cd->users; i++) {
  3219. WFIFOL(fd, 8+(i+1)*28) = 1;
  3220. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3221. }
  3222. } else
  3223. for (i = 0; i < cd->users; i++) {
  3224. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3225. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3226. }
  3227. WFIFOSET(fd, WFIFOW(fd, 2));
  3228. }
  3229. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3230. /// 00dc <users>.W <name>.24B
  3231. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3232. {
  3233. unsigned char buf[32];
  3234. nullpo_retv(sd);
  3235. nullpo_retv(cd);
  3236. WBUFW(buf, 0) = 0xdc;
  3237. WBUFW(buf, 2) = cd->users;
  3238. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3239. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3240. }
  3241. /// Announce the new owner (ZC_ROLE_CHANGE).
  3242. /// 00e1 <role>.L <nick>.24B
  3243. /// role:
  3244. /// 0 = owner (menu)
  3245. /// 1 = normal
  3246. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3247. {
  3248. unsigned char buf[64];
  3249. nullpo_retv(sd);
  3250. nullpo_retv(cd);
  3251. WBUFW(buf, 0) = 0xe1;
  3252. WBUFL(buf, 2) = 1;
  3253. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3254. WBUFW(buf,30) = 0xe1;
  3255. WBUFL(buf,32) = 0;
  3256. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3257. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3258. }
  3259. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3260. /// 00dd <users>.W <nick>.24B <flag>.B
  3261. /// flag:
  3262. /// 0 = left
  3263. /// 1 = kicked
  3264. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3265. {
  3266. unsigned char buf[32];
  3267. nullpo_retv(sd);
  3268. nullpo_retv(cd);
  3269. WBUFW(buf, 0) = 0xdd;
  3270. WBUFW(buf, 2) = cd->users-1;
  3271. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3272. WBUFB(buf,28) = flag;
  3273. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3274. }
  3275. /// Opens a trade request window from char 'name'.
  3276. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3277. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3278. void clif_traderequest(struct map_session_data* sd, const char* name)
  3279. {
  3280. int fd = sd->fd;
  3281. #if PACKETVER < 6
  3282. WFIFOHEAD(fd,packet_len(0xe5));
  3283. WFIFOW(fd,0) = 0xe5;
  3284. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3285. WFIFOSET(fd,packet_len(0xe5));
  3286. #else
  3287. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3288. if( !tsd ) return;
  3289. WFIFOHEAD(fd,packet_len(0x1f4));
  3290. WFIFOW(fd,0) = 0x1f4;
  3291. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3292. WFIFOL(fd,26) = tsd->status.char_id;
  3293. WFIFOW(fd,30) = tsd->status.base_level;
  3294. WFIFOSET(fd,packet_len(0x1f4));
  3295. #endif
  3296. }
  3297. /// Reply to a trade-request.
  3298. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3299. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3300. /// result:
  3301. /// 0 = Char is too far
  3302. /// 1 = Character does not exist
  3303. /// 2 = Trade failed
  3304. /// 3 = Accept
  3305. /// 4 = Cancel
  3306. /// 5 = Busy
  3307. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3308. {
  3309. int fd = sd->fd;
  3310. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3311. if( PACKETVER < 6 || !tsd ) {
  3312. WFIFOHEAD(fd,packet_len(0xe7));
  3313. WFIFOW(fd,0) = 0xe7;
  3314. WFIFOB(fd,2) = type;
  3315. WFIFOSET(fd,packet_len(0xe7));
  3316. } else {
  3317. WFIFOHEAD(fd,packet_len(0x1f5));
  3318. WFIFOW(fd,0) = 0x1f5;
  3319. WFIFOB(fd,2) = type;
  3320. WFIFOL(fd,3) = tsd->status.char_id;
  3321. WFIFOW(fd,7) = tsd->status.base_level;
  3322. WFIFOSET(fd,packet_len(0x1f5));
  3323. }
  3324. }
  3325. /// Notifies the client about an item from other player in current trade.
  3326. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3327. /// 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)
  3328. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3329. {
  3330. int fd;
  3331. unsigned char *buf;
  3332. #if PACKETVER < 20100223
  3333. const int cmd = 0xe9;
  3334. #else
  3335. const int cmd = 0x80f;
  3336. #endif
  3337. nullpo_retv(sd);
  3338. nullpo_retv(tsd);
  3339. fd = tsd->fd;
  3340. buf = WFIFOP(fd,0);
  3341. WFIFOHEAD(fd,packet_len(cmd));
  3342. WBUFW(buf,0) = cmd;
  3343. if( index == 0 )
  3344. {
  3345. #if PACKETVER < 20100223
  3346. WBUFL(buf,2) = amount; //amount
  3347. WBUFW(buf,6) = 0; // type id
  3348. #else
  3349. WBUFW(buf,2) = 0; // type id
  3350. WBUFB(buf,4) = 0; // item type
  3351. WBUFL(buf,5) = amount; // amount
  3352. buf = WBUFP(buf,1); //Advance 1B
  3353. #endif
  3354. WBUFB(buf,8) = 0; //identify flag
  3355. WBUFB(buf,9) = 0; // attribute
  3356. WBUFB(buf,10)= 0; //refine
  3357. WBUFW(buf,11)= 0; //card (4w)
  3358. WBUFW(buf,13)= 0; //card (4w)
  3359. WBUFW(buf,15)= 0; //card (4w)
  3360. WBUFW(buf,17)= 0; //card (4w)
  3361. }
  3362. else
  3363. {
  3364. index -= 2; //index fix
  3365. #if PACKETVER < 20100223
  3366. WBUFL(buf,2) = amount; //amount
  3367. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3368. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3369. else
  3370. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3371. #else
  3372. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3373. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3374. else
  3375. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3376. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3377. WBUFL(buf,5) = amount; // amount
  3378. buf = WBUFP(buf,1); //Advance 1B
  3379. #endif
  3380. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3381. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3382. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3383. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3384. }
  3385. WFIFOSET(fd,packet_len(cmd));
  3386. }
  3387. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3388. /// 00ea <index>.W <result>.B
  3389. /// result:
  3390. /// 0 = success
  3391. /// 1 = overweight
  3392. /// 2 = trade canceled
  3393. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3394. {
  3395. int fd;
  3396. nullpo_retv(sd);
  3397. fd = sd->fd;
  3398. WFIFOHEAD(fd,packet_len(0xea));
  3399. WFIFOW(fd,0) = 0xea;
  3400. WFIFOW(fd,2) = index;
  3401. WFIFOB(fd,4) = fail;
  3402. WFIFOSET(fd,packet_len(0xea));
  3403. }
  3404. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3405. /// 00ec <who>.B
  3406. /// who:
  3407. /// 0 = self
  3408. /// 1 = other player
  3409. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3410. {
  3411. int fd;
  3412. nullpo_retv(sd);
  3413. fd = sd->fd;
  3414. WFIFOHEAD(fd,packet_len(0xec));
  3415. WFIFOW(fd,0) = 0xec;
  3416. WFIFOB(fd,2) = fail;
  3417. WFIFOSET(fd,packet_len(0xec));
  3418. }
  3419. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3420. /// 00ee
  3421. void clif_tradecancelled(struct map_session_data* sd)
  3422. {
  3423. int fd;
  3424. nullpo_retv(sd);
  3425. fd = sd->fd;
  3426. WFIFOHEAD(fd,packet_len(0xee));
  3427. WFIFOW(fd,0) = 0xee;
  3428. WFIFOSET(fd,packet_len(0xee));
  3429. }
  3430. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3431. /// 00f0 <result>.B
  3432. /// result:
  3433. /// 0 = success
  3434. /// 1 = failure
  3435. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3436. {
  3437. int fd;
  3438. nullpo_retv(sd);
  3439. fd = sd->fd;
  3440. WFIFOHEAD(fd,packet_len(0xf0));
  3441. WFIFOW(fd,0) = 0xf0;
  3442. WFIFOB(fd,2) = fail;
  3443. WFIFOSET(fd,packet_len(0xf0));
  3444. }
  3445. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3446. /// 00f1
  3447. /// NOTE: Unknown purpose. Items are not removed until the window is
  3448. /// refreshed (ex. by putting another item in there).
  3449. void clif_tradeundo(struct map_session_data* sd)
  3450. {
  3451. int fd = sd->fd;
  3452. WFIFOHEAD(fd,packet_len(0xf1));
  3453. WFIFOW(fd,0) = 0xf1;
  3454. WFIFOSET(fd,packet_len(0xf1));
  3455. }
  3456. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3457. /// 00f2 <current count>.W <max count>.W
  3458. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3459. {
  3460. int fd;
  3461. nullpo_retv(sd);
  3462. fd=sd->fd;
  3463. WFIFOHEAD(fd,packet_len(0xf2));
  3464. WFIFOW(fd,0) = 0xf2;
  3465. WFIFOW(fd,2) = amount;
  3466. WFIFOW(fd,4) = max_amount;
  3467. WFIFOSET(fd,packet_len(0xf2));
  3468. }
  3469. /// Notifies the client of an item being added to the storage.
  3470. /// 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)
  3471. /// 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)
  3472. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3473. {
  3474. int view,fd;
  3475. nullpo_retv(sd);
  3476. nullpo_retv(i);
  3477. fd=sd->fd;
  3478. view = itemdb_viewid(i->nameid);
  3479. #if PACKETVER < 5
  3480. WFIFOHEAD(fd,packet_len(0xf4));
  3481. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3482. WFIFOW(fd, 2) = index+1; // index
  3483. WFIFOL(fd, 4) = amount; // amount
  3484. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3485. WFIFOB(fd,10) = i->identify; //identify flag
  3486. WFIFOB(fd,11) = i->attribute; // attribute
  3487. WFIFOB(fd,12) = i->refine; //refine
  3488. clif_addcards(WFIFOP(fd,13), i);
  3489. WFIFOSET(fd,packet_len(0xf4));
  3490. #else
  3491. WFIFOHEAD(fd,packet_len(0x1c4));
  3492. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3493. WFIFOW(fd, 2) = index+1; // index
  3494. WFIFOL(fd, 4) = amount; // amount
  3495. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3496. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3497. WFIFOB(fd,11) = i->identify; //identify flag
  3498. WFIFOB(fd,12) = i->attribute; // attribute
  3499. WFIFOB(fd,13) = i->refine; //refine
  3500. clif_addcards(WFIFOP(fd,14), i);
  3501. WFIFOSET(fd,packet_len(0x1c4));
  3502. #endif
  3503. }
  3504. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3505. /// 00f6 <index>.W <amount>.L
  3506. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3507. {
  3508. int fd;
  3509. nullpo_retv(sd);
  3510. fd=sd->fd;
  3511. WFIFOHEAD(fd,packet_len(0xf6));
  3512. WFIFOW(fd,0)=0xf6; // Storage item removed
  3513. WFIFOW(fd,2)=index+1;
  3514. WFIFOL(fd,4)=amount;
  3515. WFIFOSET(fd,packet_len(0xf6));
  3516. }
  3517. /// Closes storage (ZC_CLOSE_STORE).
  3518. /// 00f8
  3519. void clif_storageclose(struct map_session_data* sd)
  3520. {
  3521. int fd;
  3522. nullpo_retv(sd);
  3523. fd=sd->fd;
  3524. WFIFOHEAD(fd,packet_len(0xf8));
  3525. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3526. WFIFOSET(fd,packet_len(0xf8));
  3527. }
  3528. /*==========================================
  3529. * Server tells 'sd' player client the abouts of 'dstsd' player
  3530. *------------------------------------------*/
  3531. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3532. {
  3533. struct block_list *d_bl;
  3534. int i;
  3535. if( dstsd->chatID ) {
  3536. struct chat_data *cd = NULL;
  3537. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  3538. clif_dispchat(cd,sd->fd);
  3539. } else if( dstsd->state.vending )
  3540. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3541. else if( dstsd->state.buyingstore )
  3542. clif_buyingstore_entry_single(sd, dstsd);
  3543. if(dstsd->spiritball > 0)
  3544. clif_spiritball_single(sd->fd, dstsd);
  3545. for(i = 1; i < 5; i++){
  3546. if( dstsd->talisman[i] > 0 )
  3547. clif_talisman_single(sd->fd, dstsd, i);
  3548. }
  3549. if( dstsd->sc.option&OPTION_MOUNTING ) {
  3550. //New Mounts are not complaint to the original method, so we gotta tell this guy that I'm mounting.
  3551. clif_status_load_single(sd->fd,dstsd->bl.id,SI_ALL_RIDING,2,1,0,0);
  3552. }
  3553. #ifdef NEW_CARTS
  3554. if( dstsd->sc.data[SC_PUSH_CART] )
  3555. clif_status_load_single(sd->fd, dstsd->bl.id, SI_ON_PUSH_CART, 2, dstsd->sc.data[SC_PUSH_CART]->val1, 0, 0);
  3556. #endif
  3557. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3558. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3559. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3560. )
  3561. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3562. // display link (sd - dstsd) to sd
  3563. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3564. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3565. // display links (dstsd - devotees) to sd
  3566. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3567. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3568. // display link (dstsd - crusader) to sd
  3569. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3570. clif_devotion(d_bl, sd);
  3571. }
  3572. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3573. {
  3574. uint8 buf[128];
  3575. struct unit_data *ud;
  3576. struct view_data *vd;
  3577. int len;
  3578. vd = status_get_viewdata(bl);
  3579. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3580. return;
  3581. /**
  3582. * Hide NPC from maya purple card.
  3583. **/
  3584. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  3585. return;
  3586. ud = unit_bl2ud(bl);
  3587. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3588. clif_send(buf,len,&sd->bl,SELF);
  3589. if (vd->cloth_color)
  3590. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3591. switch (bl->type)
  3592. {
  3593. case BL_PC:
  3594. {
  3595. TBL_PC* tsd = (TBL_PC*)bl;
  3596. clif_getareachar_pc(sd, tsd);
  3597. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  3598. clif_specialeffect_single(bl,423,sd->fd);
  3599. else if(tsd->state.size==SZ_MEDIUM)
  3600. clif_specialeffect_single(bl,421,sd->fd);
  3601. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  3602. clif_sendbgemblem_single(sd->fd,tsd);
  3603. if( tsd->sc.data[SC_CAMOUFLAGE] )
  3604. clif_status_load(bl,SI_CAMOUFLAGE,1);
  3605. if ( tsd->status.robe )
  3606. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3607. }
  3608. break;
  3609. case BL_MER: // Devotion Effects
  3610. if( ((TBL_MER*)bl)->devotion_flag )
  3611. clif_devotion(bl, sd);
  3612. break;
  3613. case BL_NPC:
  3614. {
  3615. TBL_NPC* nd = (TBL_NPC*)bl;
  3616. if( nd->chat_id )
  3617. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3618. if( nd->size == SZ_BIG )
  3619. clif_specialeffect_single(bl,423,sd->fd);
  3620. else if( nd->size == SZ_MEDIUM )
  3621. clif_specialeffect_single(bl,421,sd->fd);
  3622. }
  3623. break;
  3624. case BL_MOB:
  3625. {
  3626. TBL_MOB* md = (TBL_MOB*)bl;
  3627. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  3628. clif_specialeffect_single(bl,423,sd->fd);
  3629. else if(md->special_state.size==SZ_MEDIUM)
  3630. clif_specialeffect_single(bl,421,sd->fd);
  3631. #if PACKETVER >= 20120404
  3632. if( !(md->status.mode&MD_BOSS) ){
  3633. int i;
  3634. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  3635. if( md->dmglog[i].id == sd->status.char_id )
  3636. clif_monster_hp_bar(md, sd->fd);
  3637. }
  3638. #endif
  3639. }
  3640. break;
  3641. case BL_PET:
  3642. if (vd->head_bottom)
  3643. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3644. break;
  3645. }
  3646. }
  3647. //Modifies the type of damage according to status changes [Skotlex]
  3648. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3649. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3650. {
  3651. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3652. }
  3653. /*==========================================
  3654. * Estimates walk delay based on the damage criteria. [Skotlex]
  3655. *------------------------------------------*/
  3656. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3657. {
  3658. if (type == 4 || type == 9 || damage <=0)
  3659. return 0;
  3660. if (bl->type == BL_PC) {
  3661. if (battle_config.pc_walk_delay_rate != 100)
  3662. delay = delay*battle_config.pc_walk_delay_rate/100;
  3663. } else
  3664. if (battle_config.walk_delay_rate != 100)
  3665. delay = delay*battle_config.walk_delay_rate/100;
  3666. if (div_ > 1) //Multi-hit skills mean higher delays.
  3667. delay += battle_config.multihit_delay*(div_-1);
  3668. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3669. }
  3670. /// Sends a 'damage' packet (src performs action on dst)
  3671. /// 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)
  3672. /// 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)
  3673. /// type:
  3674. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3675. /// 1 = pick up item
  3676. /// 2 = sit down
  3677. /// 3 = stand up
  3678. /// 4 = damage (endure)
  3679. /// 5 = (splash?)
  3680. /// 6 = (skill?)
  3681. /// 7 = (repeat damage?)
  3682. /// 8 = multi-hit damage
  3683. /// 9 = multi-hit damage (endure)
  3684. /// 10 = critical hit
  3685. /// 11 = lucky dodge
  3686. /// 12 = (touch skill?)
  3687. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
  3688. {
  3689. unsigned char buf[33];
  3690. struct status_change *sc;
  3691. #if PACKETVER < 20071113
  3692. const int cmd = 0x8a;
  3693. #else
  3694. const int cmd = 0x2e1;
  3695. #endif
  3696. nullpo_ret(src);
  3697. nullpo_ret(dst);
  3698. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3699. sc = status_get_sc(dst);
  3700. if(sc && sc->count) {
  3701. if(sc->data[SC_HALLUCINATION]) {
  3702. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3703. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  3704. }
  3705. }
  3706. WBUFW(buf,0)=cmd;
  3707. WBUFL(buf,2)=src->id;
  3708. WBUFL(buf,6)=dst->id;
  3709. WBUFL(buf,10)=tick;
  3710. WBUFL(buf,14)=sdelay;
  3711. WBUFL(buf,18)=ddelay;
  3712. #if PACKETVER < 20071113
  3713. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3714. WBUFW(buf,22)=damage?div:0;
  3715. WBUFW(buf,27)=damage2?div:0;
  3716. } else {
  3717. WBUFW(buf,22)=min(damage, INT16_MAX);
  3718. WBUFW(buf,27)=damage2;
  3719. }
  3720. WBUFW(buf,24)=div;
  3721. WBUFB(buf,26)=type;
  3722. #else
  3723. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3724. WBUFL(buf,22)=damage?div:0;
  3725. WBUFL(buf,29)=damage2?div:0;
  3726. } else {
  3727. WBUFL(buf,22)=damage;
  3728. WBUFL(buf,29)=damage2;
  3729. }
  3730. WBUFW(buf,26)=div;
  3731. WBUFB(buf,28)=type;
  3732. #endif
  3733. if(disguised(dst)) {
  3734. clif_send(buf,packet_len(cmd),dst,AREA_WOS);
  3735. WBUFL(buf,6) = -dst->id;
  3736. clif_send(buf,packet_len(cmd),dst,SELF);
  3737. } else
  3738. clif_send(buf,packet_len(cmd),dst,AREA);
  3739. if(disguised(src)) {
  3740. WBUFL(buf,2) = -src->id;
  3741. if (disguised(dst))
  3742. WBUFL(buf,6) = dst->id;
  3743. #if PACKETVER < 20071113
  3744. if(damage > 0) WBUFW(buf,22) = -1;
  3745. if(damage2 > 0) WBUFW(buf,27) = -1;
  3746. #else
  3747. if(damage > 0) WBUFL(buf,22) = -1;
  3748. if(damage2 > 0) WBUFL(buf,29) = -1;
  3749. #endif
  3750. clif_send(buf,packet_len(cmd),src,SELF);
  3751. }
  3752. if(src == dst) {
  3753. unit_setdir(src,unit_getdir(src));
  3754. }
  3755. //Return adjusted can't walk delay for further processing.
  3756. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3757. }
  3758. /*==========================================
  3759. * src picks up dst
  3760. *------------------------------------------*/
  3761. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3762. {
  3763. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3764. unsigned char buf[32];
  3765. nullpo_retv(src);
  3766. nullpo_retv(dst);
  3767. WBUFW(buf, 0) = 0x8a;
  3768. WBUFL(buf, 2) = src->id;
  3769. WBUFL(buf, 6) = dst->id;
  3770. WBUFB(buf,26) = 1;
  3771. clif_send(buf, packet_len(0x8a), src, AREA);
  3772. }
  3773. /*==========================================
  3774. * inform clients in area that `bl` is sitting
  3775. *------------------------------------------*/
  3776. void clif_sitting(struct block_list* bl)
  3777. {
  3778. unsigned char buf[32];
  3779. nullpo_retv(bl);
  3780. WBUFW(buf, 0) = 0x8a;
  3781. WBUFL(buf, 2) = bl->id;
  3782. WBUFB(buf,26) = 2;
  3783. clif_send(buf, packet_len(0x8a), bl, AREA);
  3784. if(disguised(bl)) {
  3785. WBUFL(buf, 2) = - bl->id;
  3786. clif_send(buf, packet_len(0x8a), bl, SELF);
  3787. }
  3788. }
  3789. /*==========================================
  3790. * inform clients in area that `bl` is standing
  3791. *------------------------------------------*/
  3792. void clif_standing(struct block_list* bl)
  3793. {
  3794. unsigned char buf[32];
  3795. nullpo_retv(bl);
  3796. WBUFW(buf, 0) = 0x8a;
  3797. WBUFL(buf, 2) = bl->id;
  3798. WBUFB(buf,26) = 3;
  3799. clif_send(buf, packet_len(0x8a), bl, AREA);
  3800. if(disguised(bl)) {
  3801. WBUFL(buf, 2) = - bl->id;
  3802. clif_send(buf, packet_len(0x8a), bl, SELF);
  3803. }
  3804. }
  3805. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3806. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3807. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  3808. {
  3809. unsigned char buf[32];
  3810. WBUFW(buf,0) = 0x192;
  3811. WBUFW(buf,2) = x;
  3812. WBUFW(buf,4) = y;
  3813. WBUFW(buf,6) = type;
  3814. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3815. if( fd )
  3816. {
  3817. WFIFOHEAD(fd,packet_len(0x192));
  3818. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3819. WFIFOSET(fd,packet_len(0x192));
  3820. }
  3821. else
  3822. {
  3823. struct block_list dummy_bl;
  3824. dummy_bl.type = BL_NUL;
  3825. dummy_bl.x = x;
  3826. dummy_bl.y = y;
  3827. dummy_bl.m = m;
  3828. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3829. }
  3830. }
  3831. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3832. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3833. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3834. {
  3835. int view,fd;
  3836. fd=sd->fd;
  3837. WFIFOHEAD(fd,packet_len(0x9d));
  3838. WFIFOW(fd,0)=0x9d;
  3839. WFIFOL(fd,2)=fitem->bl.id;
  3840. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3841. WFIFOW(fd,6)=view;
  3842. else
  3843. WFIFOW(fd,6)=fitem->item_data.nameid;
  3844. WFIFOB(fd,8)=fitem->item_data.identify;
  3845. WFIFOW(fd,9)=fitem->bl.x;
  3846. WFIFOW(fd,11)=fitem->bl.y;
  3847. WFIFOW(fd,13)=fitem->item_data.amount;
  3848. WFIFOB(fd,15)=fitem->subx;
  3849. WFIFOB(fd,16)=fitem->suby;
  3850. WFIFOSET(fd,packet_len(0x9d));
  3851. }
  3852. /// Notifies the client of a skill unit.
  3853. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3854. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3855. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  3856. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  3857. static void clif_getareachar_skillunit(int type,struct map_session_data *sd, struct skill_unit *unit)
  3858. {
  3859. int fd = sd->fd;
  3860. int header=0, unit_id=0, pos=0;
  3861. if( unit->group->state.guildaura )
  3862. return;
  3863. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3864. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3865. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  3866. unit_id=UNT_DUMMYSKILL; //Use invisible unit id for other case of rangedsingle unit
  3867. else
  3868. unit_id=unit->group->unit_id;
  3869. #if PACKETVER >= 3
  3870. if(unit->group->unit_id==UNT_GRAFFITI) // Graffiti [Valaris]
  3871. type = 2;
  3872. #endif
  3873. switch(type){
  3874. case 2: header=0x1c9; break;
  3875. case 3: header=0x8c7; break;
  3876. case 4: header=0x99f; break;
  3877. default:
  3878. case 1: header=0x11f; break;
  3879. }
  3880. WFIFOHEAD(fd,packet_len(header));
  3881. WFIFOW(fd,pos)=header;
  3882. if(type==3 || type==4){
  3883. WFIFOW(fd, pos+2)=packet_len(header);
  3884. pos +=2;
  3885. }
  3886. WFIFOL(fd,pos+2)=unit->bl.id;
  3887. WFIFOL(fd,pos+6)=unit->group->src_id;
  3888. WFIFOW(fd,pos+10)=unit->bl.x;
  3889. WFIFOW(fd,pos+12)=unit->bl.y;
  3890. switch(type){
  3891. case 1: WFIFOB(fd,pos+14)=unit_id;
  3892. WFIFOB(fd,pos+15)=1;
  3893. break;
  3894. case 2: WFIFOB(fd,pos+14)=unit_id;
  3895. WFIFOB(fd,pos+15)=1;
  3896. WFIFOB(fd,pos+16)=1;
  3897. safestrncpy((char*)WFIFOP(fd,pos+17),unit->group->valstr,MESSAGE_SIZE);
  3898. break;
  3899. case 3: WFIFOB(fd,pos+14)=unit_id;
  3900. WFIFOW(fd,pos+15)=unit->range;
  3901. WFIFOB(fd,pos+17)=1; //visible
  3902. break;
  3903. case 4: WFIFOL(fd,pos+14)=unit_id; pos += 3;
  3904. WFIFOW(fd,pos+15)=unit->range;
  3905. WFIFOB(fd,pos+17)=1;
  3906. break;
  3907. }
  3908. WFIFOSET(fd,packet_len(header));
  3909. if(unit->group->skill_id == WZ_ICEWALL)
  3910. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3911. }
  3912. /*==========================================
  3913. * Server tells client to remove unit of id 'unit->bl.id'
  3914. *------------------------------------------*/
  3915. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3916. {
  3917. nullpo_retv(unit);
  3918. WFIFOHEAD(fd,packet_len(0x120));
  3919. WFIFOW(fd, 0)=0x120;
  3920. WFIFOL(fd, 2)=unit->bl.id;
  3921. WFIFOSET(fd,packet_len(0x120));
  3922. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3923. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3924. }
  3925. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  3926. /// 0120 <id>.L
  3927. void clif_skill_delunit(struct skill_unit *unit)
  3928. {
  3929. unsigned char buf[16];
  3930. nullpo_retv(unit);
  3931. WBUFW(buf, 0)=0x120;
  3932. WBUFL(buf, 2)=unit->bl.id;
  3933. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3934. }
  3935. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  3936. /// 01ac <id>.L
  3937. /// Only affects units with class [139,153] client-side.
  3938. void clif_skillunit_update(struct block_list* bl)
  3939. {
  3940. unsigned char buf[6];
  3941. nullpo_retv(bl);
  3942. WBUFW(buf,0) = 0x1ac;
  3943. WBUFL(buf,2) = bl->id;
  3944. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3945. }
  3946. /*==========================================
  3947. *
  3948. *------------------------------------------*/
  3949. static int clif_getareachar(struct block_list* bl,va_list ap)
  3950. {
  3951. struct map_session_data *sd;
  3952. nullpo_ret(bl);
  3953. sd=va_arg(ap,struct map_session_data*);
  3954. if (sd == NULL || !sd->fd)
  3955. return 0;
  3956. switch(bl->type){
  3957. case BL_ITEM:
  3958. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3959. break;
  3960. case BL_SKILL:
  3961. clif_getareachar_skillunit(1,sd,(TBL_SKILL*)bl);
  3962. break;
  3963. default:
  3964. if(&sd->bl == bl)
  3965. break;
  3966. clif_getareachar_unit(sd,bl);
  3967. break;
  3968. }
  3969. return 0;
  3970. }
  3971. /*==========================================
  3972. * tbl has gone out of view-size of bl
  3973. *------------------------------------------*/
  3974. int clif_outsight(struct block_list *bl,va_list ap)
  3975. {
  3976. struct block_list *tbl;
  3977. struct view_data *vd;
  3978. TBL_PC *sd, *tsd;
  3979. tbl=va_arg(ap,struct block_list*);
  3980. if(bl == tbl) return 0;
  3981. sd = BL_CAST(BL_PC, bl);
  3982. tsd = BL_CAST(BL_PC, tbl);
  3983. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  3984. switch(bl->type){
  3985. case BL_PC:
  3986. if (sd->vd.class_ != INVISIBLE_CLASS)
  3987. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3988. if(sd->chatID){
  3989. struct chat_data *cd;
  3990. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3991. if(cd->usersd[0]==sd)
  3992. clif_dispchat(cd,tsd->fd);
  3993. }
  3994. if( sd->state.vending )
  3995. clif_closevendingboard(bl,tsd->fd);
  3996. if( sd->state.buyingstore )
  3997. clif_buyingstore_disappear_entry_single(tsd, sd);
  3998. break;
  3999. case BL_ITEM:
  4000. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4001. break;
  4002. case BL_SKILL:
  4003. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4004. break;
  4005. case BL_NPC:
  4006. if( !(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE) )
  4007. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4008. break;
  4009. default:
  4010. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4011. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4012. break;
  4013. }
  4014. }
  4015. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4016. if (((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4017. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4018. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4019. }
  4020. return 0;
  4021. }
  4022. /*==========================================
  4023. * tbl has come into view of bl
  4024. *------------------------------------------*/
  4025. int clif_insight(struct block_list *bl,va_list ap)
  4026. {
  4027. struct block_list *tbl;
  4028. TBL_PC *sd, *tsd;
  4029. tbl=va_arg(ap,struct block_list*);
  4030. if (bl == tbl) return 0;
  4031. sd = BL_CAST(BL_PC, bl);
  4032. tsd = BL_CAST(BL_PC, tbl);
  4033. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4034. switch(bl->type){
  4035. case BL_ITEM:
  4036. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4037. break;
  4038. case BL_SKILL:
  4039. clif_getareachar_skillunit(1,tsd,(TBL_SKILL*)bl);
  4040. break;
  4041. default:
  4042. clif_getareachar_unit(tsd,bl);
  4043. break;
  4044. }
  4045. }
  4046. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4047. clif_getareachar_unit(sd,tbl);
  4048. }
  4049. return 0;
  4050. }
  4051. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4052. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4053. void clif_skillinfoblock(struct map_session_data *sd)
  4054. {
  4055. int fd;
  4056. int i,len,id;
  4057. nullpo_retv(sd);
  4058. fd=sd->fd;
  4059. if (!fd) return;
  4060. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4061. WFIFOW(fd,0) = 0x10f;
  4062. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4063. {
  4064. if( (id = sd->status.skill[i].id) != 0 )
  4065. {
  4066. // workaround for bugreport:5348
  4067. if (len + 37 > 8192)
  4068. break;
  4069. WFIFOW(fd,len) = id;
  4070. WFIFOL(fd,len+2) = skill_get_inf(id);
  4071. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4072. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4073. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4074. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4075. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4076. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4077. else
  4078. WFIFOB(fd,len+36) = 0;
  4079. len += 37;
  4080. }
  4081. }
  4082. WFIFOW(fd,2)=len;
  4083. WFIFOSET(fd,len);
  4084. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4085. for ( ; i < MAX_SKILL; i++)
  4086. {
  4087. if( (id = sd->status.skill[i].id) != 0 )
  4088. {
  4089. clif_addskill(sd, id);
  4090. clif_skillinfo(sd, id, 0);
  4091. }
  4092. }
  4093. }
  4094. /**
  4095. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4096. **/
  4097. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4098. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4099. void clif_addskill(struct map_session_data *sd, int id)
  4100. {
  4101. int fd;
  4102. nullpo_retv(sd);
  4103. fd = sd->fd;
  4104. if (!fd) return;
  4105. if( sd->status.skill[id].id <= 0 )
  4106. return;
  4107. WFIFOHEAD(fd, packet_len(0x111));
  4108. WFIFOW(fd,0) = 0x111;
  4109. WFIFOW(fd,2) = id;
  4110. WFIFOL(fd,4) = skill_get_inf(id);
  4111. WFIFOW(fd,8) = sd->status.skill[id].lv;
  4112. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  4113. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  4114. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4115. if( sd->status.skill[id].flag == SKILL_FLAG_PERMANENT )
  4116. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4117. else
  4118. WFIFOB(fd,38) = 0;
  4119. WFIFOSET(fd,packet_len(0x111));
  4120. }
  4121. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4122. /// 0441 <skill id>.W
  4123. void clif_deleteskill(struct map_session_data *sd, int id)
  4124. {
  4125. #if PACKETVER >= 20081217
  4126. int fd;
  4127. nullpo_retv(sd);
  4128. fd = sd->fd;
  4129. if( !fd ) return;
  4130. WFIFOHEAD(fd,packet_len(0x441));
  4131. WFIFOW(fd,0) = 0x441;
  4132. WFIFOW(fd,2) = id;
  4133. WFIFOSET(fd,packet_len(0x441));
  4134. #endif
  4135. clif_skillinfoblock(sd);
  4136. }
  4137. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4138. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4139. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4140. int fd;
  4141. nullpo_retv(sd);
  4142. fd = sd->fd;
  4143. WFIFOHEAD(fd, packet_len(0x10e));
  4144. WFIFOW(fd, 0) = 0x10e;
  4145. WFIFOW(fd, 2) = skill_id;
  4146. WFIFOW(fd, 4) = lv;
  4147. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4148. WFIFOW(fd, 8) = range;
  4149. WFIFOB(fd, 10) = upgradable;
  4150. WFIFOSET(fd, packet_len(0x10e));
  4151. }
  4152. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4153. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4154. void clif_skillinfo(struct map_session_data *sd,int skill, int inf)
  4155. {
  4156. const int fd = sd->fd;
  4157. WFIFOHEAD(fd,packet_len(0x7e1));
  4158. WFIFOW(fd,0) = 0x7e1;
  4159. WFIFOW(fd,2) = skill;
  4160. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill);
  4161. WFIFOW(fd,8) = sd->status.skill[skill].lv;
  4162. WFIFOW(fd,10) = skill_get_sp(skill,sd->status.skill[skill].lv);
  4163. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill,sd->status.skill[skill].lv);
  4164. if( sd->status.skill[skill].flag == SKILL_FLAG_PERMANENT )
  4165. WFIFOB(fd,14) = (sd->status.skill[skill].lv < skill_tree_get_max(skill, sd->status.class_))? 1:0;
  4166. else
  4167. WFIFOB(fd,14) = 0;
  4168. WFIFOSET(fd,packet_len(0x7e1));
  4169. }
  4170. /// Notifies clients in area, that an object is about to use a skill.
  4171. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4172. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4173. /// property:
  4174. /// 0 = Yellow cast aura
  4175. /// 1 = Water elemental cast aura
  4176. /// 2 = Earth elemental cast aura
  4177. /// 3 = Fire elemental cast aura
  4178. /// 4 = Wind elemental cast aura
  4179. /// 5 = Poison elemental cast aura
  4180. /// 6 = Holy elemental cast aura
  4181. /// ? = like 0
  4182. /// is disposable:
  4183. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4184. /// 1 = no text
  4185. 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)
  4186. {
  4187. #if PACKETVER < 20091124
  4188. const int cmd = 0x13e;
  4189. #else
  4190. const int cmd = 0x7fb;
  4191. #endif
  4192. unsigned char buf[32];
  4193. WBUFW(buf,0) = cmd;
  4194. WBUFL(buf,2) = src_id;
  4195. WBUFL(buf,6) = dst_id;
  4196. WBUFW(buf,10) = dst_x;
  4197. WBUFW(buf,12) = dst_y;
  4198. WBUFW(buf,14) = skill_id;
  4199. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4200. WBUFL(buf,20) = casttime;
  4201. #if PACKETVER >= 20091124
  4202. WBUFB(buf,24) = 0; // isDisposable
  4203. #endif
  4204. if (disguised(bl)) {
  4205. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4206. WBUFL(buf,2) = -src_id;
  4207. clif_send(buf,packet_len(cmd), bl, SELF);
  4208. } else
  4209. clif_send(buf,packet_len(cmd), bl, AREA);
  4210. }
  4211. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4212. /// 01b9 <id>.L
  4213. void clif_skillcastcancel(struct block_list* bl)
  4214. {
  4215. unsigned char buf[16];
  4216. nullpo_retv(bl);
  4217. WBUFW(buf,0) = 0x1b9;
  4218. WBUFL(buf,2) = bl->id;
  4219. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4220. }
  4221. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4222. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4223. /// num (only used when skill id = NV_BASIC and cause = 0):
  4224. /// 0 = "skill failed" MsgStringTable[159]
  4225. /// 1 = "no emotions" MsgStringTable[160]
  4226. /// 2 = "no sit" MsgStringTable[161]
  4227. /// 3 = "no chat" MsgStringTable[162]
  4228. /// 4 = "no party" MsgStringTable[163]
  4229. /// 5 = "no shout" MsgStringTable[164]
  4230. /// 6 = "no PKing" MsgStringTable[165]
  4231. /// 7 = "no alligning" MsgStringTable[383]
  4232. /// ? = ignored
  4233. /// cause:
  4234. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4235. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4236. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4237. /// "skill failed" MsgStringTable[204] (otherwise)
  4238. /// ... = @see enum useskill_fail_cause
  4239. /// ? = ignored
  4240. ///
  4241. /// if(result!=0) doesn't display any of the previous messages
  4242. /// Note: when this packet is received an unknown flag is always set to 0,
  4243. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4244. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4245. {
  4246. int fd;
  4247. if (!sd) { //Since this is the most common nullpo....
  4248. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4249. return;
  4250. }
  4251. fd=sd->fd;
  4252. if (!fd) return;
  4253. if(battle_config.display_skill_fail&1)
  4254. return; //Disable all skill failed messages
  4255. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4256. return; //Disable delay failed messages
  4257. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4258. return;
  4259. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4260. return;
  4261. WFIFOHEAD(fd,packet_len(0x110));
  4262. WFIFOW(fd,0) = 0x110;
  4263. WFIFOW(fd,2) = skill_id;
  4264. WFIFOL(fd,4) = btype;
  4265. WFIFOB(fd,8) = 0;// success
  4266. WFIFOB(fd,9) = cause;
  4267. WFIFOSET(fd,packet_len(0x110));
  4268. }
  4269. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4270. /// 043d <skill ID>.W <tick>.L
  4271. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4272. {
  4273. #if PACKETVER>=20081112
  4274. int fd;
  4275. nullpo_retv(sd);
  4276. fd=sd->fd;
  4277. WFIFOHEAD(fd,packet_len(0x43d));
  4278. WFIFOW(fd,0) = 0x43d;
  4279. WFIFOW(fd,2) = skill_id;
  4280. WFIFOL(fd,4) = tick;
  4281. WFIFOSET(fd,packet_len(0x43d));
  4282. #endif
  4283. }
  4284. /// Skill attack effect and damage.
  4285. /// 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)
  4286. /// 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)
  4287. int clif_skill_damage(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)
  4288. {
  4289. unsigned char buf[64];
  4290. struct status_change *sc;
  4291. nullpo_ret(src);
  4292. nullpo_ret(dst);
  4293. type = clif_calc_delay(type,div,damage,ddelay);
  4294. sc = status_get_sc(dst);
  4295. if(sc && sc->count) {
  4296. if(sc->data[SC_HALLUCINATION] && damage)
  4297. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4298. }
  4299. #if PACKETVER < 3
  4300. WBUFW(buf,0)=0x114;
  4301. WBUFW(buf,2)=skill_id;
  4302. WBUFL(buf,4)=src->id;
  4303. WBUFL(buf,8)=dst->id;
  4304. WBUFL(buf,12)=tick;
  4305. WBUFL(buf,16)=sdelay;
  4306. WBUFL(buf,20)=ddelay;
  4307. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4308. WBUFW(buf,24)=damage?div:0;
  4309. } else {
  4310. WBUFW(buf,24)=damage;
  4311. }
  4312. WBUFW(buf,26)=skill_lv;
  4313. WBUFW(buf,28)=div;
  4314. WBUFB(buf,30)=type;
  4315. if (disguised(dst)) {
  4316. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4317. WBUFL(buf,8)=-dst->id;
  4318. clif_send(buf,packet_len(0x114),dst,SELF);
  4319. } else
  4320. clif_send(buf,packet_len(0x114),dst,AREA);
  4321. if(disguised(src)) {
  4322. WBUFL(buf,4)=-src->id;
  4323. if (disguised(dst))
  4324. WBUFL(buf,8)=dst->id;
  4325. if(damage > 0)
  4326. WBUFW(buf,24)=-1;
  4327. clif_send(buf,packet_len(0x114),src,SELF);
  4328. }
  4329. #else
  4330. WBUFW(buf,0)=0x1de;
  4331. WBUFW(buf,2)=skill_id;
  4332. WBUFL(buf,4)=src->id;
  4333. WBUFL(buf,8)=dst->id;
  4334. WBUFL(buf,12)=tick;
  4335. WBUFL(buf,16)=sdelay;
  4336. WBUFL(buf,20)=ddelay;
  4337. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4338. WBUFL(buf,24)=damage?div:0;
  4339. } else {
  4340. WBUFL(buf,24)=damage;
  4341. }
  4342. WBUFW(buf,28)=skill_lv;
  4343. WBUFW(buf,30)=div;
  4344. WBUFB(buf,32)=type;
  4345. if (disguised(dst)) {
  4346. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4347. WBUFL(buf,8)=-dst->id;
  4348. clif_send(buf,packet_len(0x1de),dst,SELF);
  4349. } else
  4350. clif_send(buf,packet_len(0x1de),dst,AREA);
  4351. if(disguised(src)) {
  4352. WBUFL(buf,4)=-src->id;
  4353. if (disguised(dst))
  4354. WBUFL(buf,8)=dst->id;
  4355. if(damage > 0)
  4356. WBUFL(buf,24)=-1;
  4357. clif_send(buf,packet_len(0x1de),src,SELF);
  4358. }
  4359. #endif
  4360. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4361. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4362. }
  4363. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4364. /// 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
  4365. /*
  4366. 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)
  4367. {
  4368. unsigned char buf[64];
  4369. struct status_change *sc;
  4370. nullpo_ret(src);
  4371. nullpo_ret(dst);
  4372. type = (type>0)?type:skill_get_hit(skill_id);
  4373. type = clif_calc_delay(type,div,damage,ddelay);
  4374. sc = status_get_sc(dst);
  4375. if(sc && sc->count) {
  4376. if(sc->data[SC_HALLUCINATION] && damage)
  4377. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rnd()%100;
  4378. }
  4379. WBUFW(buf,0)=0x115;
  4380. WBUFW(buf,2)=skill_id;
  4381. WBUFL(buf,4)=src->id;
  4382. WBUFL(buf,8)=dst->id;
  4383. WBUFL(buf,12)=tick;
  4384. WBUFL(buf,16)=sdelay;
  4385. WBUFL(buf,20)=ddelay;
  4386. WBUFW(buf,24)=dst->x;
  4387. WBUFW(buf,26)=dst->y;
  4388. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4389. WBUFW(buf,28)=damage?div:0;
  4390. } else {
  4391. WBUFW(buf,28)=damage;
  4392. }
  4393. WBUFW(buf,30)=skill_lv;
  4394. WBUFW(buf,32)=div;
  4395. WBUFB(buf,34)=type;
  4396. clif_send(buf,packet_len(0x115),src,AREA);
  4397. if(disguised(src)) {
  4398. WBUFL(buf,4)=-src->id;
  4399. if(damage > 0)
  4400. WBUFW(buf,28)=-1;
  4401. clif_send(buf,packet_len(0x115),src,SELF);
  4402. }
  4403. if (disguised(dst)) {
  4404. WBUFL(buf,8)=-dst->id;
  4405. if (disguised(src))
  4406. WBUFL(buf,4)=src->id;
  4407. else if(damage > 0)
  4408. WBUFW(buf,28)=-1;
  4409. clif_send(buf,packet_len(0x115),dst,SELF);
  4410. }
  4411. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4412. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4413. }
  4414. */
  4415. /// Non-damaging skill effect (ZC_USE_SKILL).
  4416. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4417. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4418. {
  4419. unsigned char buf[32];
  4420. nullpo_ret(dst);
  4421. WBUFW(buf,0)=0x11a;
  4422. WBUFW(buf,2)=skill_id;
  4423. WBUFW(buf,4)=min(heal, INT16_MAX);
  4424. WBUFL(buf,6)=dst->id;
  4425. WBUFL(buf,10)=src?src->id:0;
  4426. WBUFB(buf,14)=fail;
  4427. if (disguised(dst)) {
  4428. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4429. WBUFL(buf,6)=-dst->id;
  4430. clif_send(buf,packet_len(0x11a),dst,SELF);
  4431. } else
  4432. clif_send(buf,packet_len(0x11a),dst,AREA);
  4433. if(src && disguised(src)) {
  4434. WBUFL(buf,10)=-src->id;
  4435. if (disguised(dst))
  4436. WBUFL(buf,6)=dst->id;
  4437. clif_send(buf,packet_len(0x11a),src,SELF);
  4438. }
  4439. return fail;
  4440. }
  4441. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4442. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4443. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  4444. {
  4445. unsigned char buf[32];
  4446. nullpo_retv(src);
  4447. WBUFW(buf,0)=0x117;
  4448. WBUFW(buf,2)=skill_id;
  4449. WBUFL(buf,4)=src->id;
  4450. WBUFW(buf,8)=val;
  4451. WBUFW(buf,10)=x;
  4452. WBUFW(buf,12)=y;
  4453. WBUFL(buf,14)=tick;
  4454. if(disguised(src)) {
  4455. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4456. WBUFL(buf,4)=-src->id;
  4457. clif_send(buf,packet_len(0x117),src,SELF);
  4458. } else
  4459. clif_send(buf,packet_len(0x117),src,AREA);
  4460. }
  4461. /*==========================================
  4462. * Tells all client's nearby 'unit' sight range that it spawned
  4463. *------------------------------------------*/
  4464. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4465. void clif_skill_setunit(struct skill_unit *unit)
  4466. {
  4467. unsigned char buf[128];
  4468. nullpo_retv(unit);
  4469. if( unit->group->state.guildaura )
  4470. return;
  4471. #if PACKETVER >= 3
  4472. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4473. WBUFW(buf, 0)=0x1c9;
  4474. WBUFL(buf, 2)=unit->bl.id;
  4475. WBUFL(buf, 6)=unit->group->src_id;
  4476. WBUFW(buf,10)=unit->bl.x;
  4477. WBUFW(buf,12)=unit->bl.y;
  4478. WBUFB(buf,14)=unit->group->unit_id;
  4479. WBUFB(buf,15)=1;
  4480. WBUFB(buf,16)=1;
  4481. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4482. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4483. return;
  4484. }
  4485. #endif
  4486. WBUFW(buf, 0)=0x11f;
  4487. WBUFL(buf, 2)=unit->bl.id;
  4488. WBUFL(buf, 6)=unit->group->src_id;
  4489. WBUFW(buf,10)=unit->bl.x;
  4490. WBUFW(buf,12)=unit->bl.y;
  4491. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4492. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4493. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4494. WBUFB(buf, 14) = UNT_DUMMYSKILL; // Only display the unit at center.
  4495. else
  4496. WBUFB(buf,14)=unit->group->unit_id;
  4497. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4498. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4499. }
  4500. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4501. /// 011c <skill id>.W { <map name>.16B }*4
  4502. 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)
  4503. {
  4504. int fd;
  4505. nullpo_retv(sd);
  4506. fd = sd->fd;
  4507. WFIFOHEAD(fd,packet_len(0x11c));
  4508. WFIFOW(fd,0) = 0x11c;
  4509. WFIFOW(fd,2) = skill_id;
  4510. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4511. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4512. else // normal map name
  4513. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4514. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4515. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4516. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4517. WFIFOSET(fd,packet_len(0x11c));
  4518. sd->menuskill_id = skill_id;
  4519. if (skill_id == AL_WARP)
  4520. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4521. else
  4522. sd->menuskill_val = skill_lv;
  4523. }
  4524. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4525. /// 011e <type>.B
  4526. /// type:
  4527. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4528. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4529. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4530. ///
  4531. /// @param sd Who receives the message
  4532. /// @param type What message
  4533. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4534. {
  4535. int fd;
  4536. nullpo_retv(sd);
  4537. fd=sd->fd;
  4538. WFIFOHEAD(fd,packet_len(0x11e));
  4539. WFIFOW(fd,0)=0x11e;
  4540. WFIFOB(fd,2)=type;
  4541. WFIFOSET(fd,packet_len(0x11e));
  4542. }
  4543. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4544. /// 0189 <type>.W
  4545. /// type:
  4546. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4547. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4548. ///
  4549. /// @param sd Who receives the message
  4550. /// @param type What message
  4551. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4552. {
  4553. int fd;
  4554. nullpo_retv(sd);
  4555. fd=sd->fd;
  4556. WFIFOHEAD(fd,packet_len(0x189));
  4557. WFIFOW(fd,0)=0x189;
  4558. WFIFOW(fd,2)=type;
  4559. WFIFOSET(fd,packet_len(0x189));
  4560. }
  4561. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4562. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4563. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4564. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4565. {
  4566. struct status_data *status;
  4567. unsigned char buf[64];
  4568. int i;//, fix;
  4569. nullpo_retv(sd);
  4570. nullpo_retv(dst);
  4571. if( dst->type != BL_MOB )
  4572. return;
  4573. status = status_get_status_data(dst);
  4574. WBUFW(buf, 0)=0x18c;
  4575. WBUFW(buf, 2)=status_get_class(dst);
  4576. WBUFW(buf, 4)=status_get_lv(dst);
  4577. WBUFW(buf, 6)=status->size;
  4578. WBUFL(buf, 8)=status->hp;
  4579. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4580. +(battle_config.estimation_type&2?status->def2:0);
  4581. WBUFW(buf,14)=status->race;
  4582. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4583. +(battle_config.estimation_type&2?status->mdef2:0);
  4584. WBUFW(buf,18)= status->def_ele;
  4585. for(i=0;i<9;i++)
  4586. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4587. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4588. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4589. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4590. }
  4591. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  4592. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4593. /// material id:
  4594. /// unused by the client
  4595. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4596. {
  4597. int i,c,view,fd;
  4598. nullpo_retv(sd);
  4599. if(sd->menuskill_id == skill_id)
  4600. return; //Avoid resending the menu twice or more times...
  4601. if( skill_id == GC_CREATENEWPOISON )
  4602. skill_id = GC_RESEARCHNEWPOISON;
  4603. fd=sd->fd;
  4604. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4605. WFIFOW(fd, 0)=0x18d;
  4606. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4607. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  4608. ( ( skill_id > 0 && skill_produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4609. ){
  4610. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4611. WFIFOW(fd,c*8+ 4)= view;
  4612. else
  4613. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4614. WFIFOW(fd,c*8+ 6)= 0;
  4615. WFIFOW(fd,c*8+ 8)= 0;
  4616. WFIFOW(fd,c*8+10)= 0;
  4617. c++;
  4618. }
  4619. }
  4620. WFIFOW(fd, 2)=c*8+8;
  4621. WFIFOSET(fd,WFIFOW(fd,2));
  4622. if(c > 0) {
  4623. sd->menuskill_id = skill_id;
  4624. sd->menuskill_val = trigger;
  4625. return;
  4626. }
  4627. }
  4628. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  4629. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4630. /// mk type:
  4631. /// 1 = cooking
  4632. /// 2 = arrow
  4633. /// 3 = elemental
  4634. /// 4 = GN_MIX_COOKING
  4635. /// 5 = GN_MAKEBOMB
  4636. /// 6 = GN_S_PHARMACY
  4637. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4638. {
  4639. int fd;
  4640. int i, c;
  4641. int view;
  4642. nullpo_retv(sd);
  4643. fd = sd->fd;
  4644. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4645. WFIFOW(fd,0) = 0x25a;
  4646. WFIFOW(fd,4) = list_type; // list type
  4647. c = 0;
  4648. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4649. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  4650. continue;
  4651. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4652. WFIFOW(fd, 6 + 2 * c) = view;
  4653. else
  4654. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  4655. c++;
  4656. }
  4657. if( skill_id == AM_PHARMACY ) { // Only send it while Cooking else check for c.
  4658. WFIFOW(fd,2) = 6 + 2 * c;
  4659. WFIFOSET(fd,WFIFOW(fd,2));
  4660. }
  4661. if( c > 0 ) {
  4662. sd->menuskill_id = skill_id;
  4663. sd->menuskill_val = trigger;
  4664. if( skill_id != AM_PHARMACY ) {
  4665. sd->menuskill_val2 = qty; // amount.
  4666. WFIFOW(fd,2) = 6 + 2 * c;
  4667. WFIFOSET(fd,WFIFOW(fd,2));
  4668. }
  4669. } else {
  4670. clif_menuskill_clear(sd);
  4671. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4672. // It fails.
  4673. #if PACKETVER >= 20090922
  4674. clif_msg_skill(sd,skill_id,0x625);
  4675. #else
  4676. WFIFOW(fd,2) = 6 + 2 * c;
  4677. WFIFOSET(fd,WFIFOW(fd,2));
  4678. #endif
  4679. }
  4680. }
  4681. }
  4682. /// Notifies clients of a status change.
  4683. /// 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)]
  4684. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4685. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4686. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4687. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4688. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3)
  4689. {
  4690. unsigned char buf[32];
  4691. struct map_session_data *sd;
  4692. if (type == SI_BLANK) //It shows nothing on the client...
  4693. return;
  4694. nullpo_retv(bl);
  4695. sd = BL_CAST(BL_PC, bl);
  4696. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4697. return;
  4698. #if PACKETVER >= 20120618
  4699. if(flag && battle_config.display_status_timers && sd)
  4700. WBUFW(buf,0)=0x983;
  4701. else
  4702. #elif PACKETVER >= 20090121
  4703. if(flag && battle_config.display_status_timers && sd)
  4704. WBUFW(buf,0)=0x43f;
  4705. else
  4706. #endif
  4707. WBUFW(buf,0)=0x196;
  4708. WBUFW(buf,2)=type;
  4709. WBUFL(buf,4)=bl->id;
  4710. WBUFB(buf,8)=flag;
  4711. #if PACKETVER >= 20120618
  4712. if(flag && battle_config.display_status_timers && sd) {
  4713. if (tick <= 0)
  4714. tick = 9999; // this is indeed what official servers do
  4715. WBUFL(buf,9)=tick;/* at this stage remain and total are the same value I believe */
  4716. WBUFL(buf,13)=tick;
  4717. WBUFL(buf,17) = val1;
  4718. WBUFL(buf,21) = val2;
  4719. WBUFL(buf,25) = val3;
  4720. }
  4721. #elif PACKETVER >= 20090121
  4722. if(flag && battle_config.display_status_timers && sd) {
  4723. if (tick <= 0)
  4724. tick = 9999; // this is indeed what official servers do
  4725. WBUFL(buf,9) = tick;
  4726. WBUFL(buf,13) = val1;
  4727. WBUFL(buf,17) = val2;
  4728. WBUFL(buf,21) = val3;
  4729. }
  4730. #endif
  4731. clif_send(buf,packet_len(WBUFW(buf,0)),bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4732. }
  4733. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4734. /// 008e <packet len>.W <message>.?B
  4735. void clif_displaymessage(const int fd, const char* mes)
  4736. {
  4737. nullpo_retv(mes);
  4738. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4739. if (fd == 0)
  4740. ;
  4741. else {
  4742. char *message, *line;
  4743. message = aStrdup(mes);
  4744. line = strtok(message, "\n");
  4745. while(line != NULL) {
  4746. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4747. int len = strnlen(line, 255);
  4748. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4749. WFIFOHEAD(fd, 5 + len);
  4750. WFIFOW(fd,0) = 0x8e;
  4751. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  4752. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4753. WFIFOSET(fd, 5 + len);
  4754. }
  4755. line = strtok(NULL, "\n");
  4756. }
  4757. aFree(message);
  4758. }
  4759. }
  4760. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4761. /// 009a <packet len>.W <message>.?B
  4762. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4763. {
  4764. int lp = type ? 4 : 0;
  4765. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  4766. WBUFW(buf,0) = 0x9a;
  4767. WBUFW(buf,2) = 4 + lp + len;
  4768. if (type == 0x10) // bc_blue
  4769. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4770. else if (type == 0x20) // bc_woe
  4771. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4772. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4773. clif_send(buf, WBUFW(buf,2), bl, target);
  4774. if (buf)
  4775. aFree(buf);
  4776. }
  4777. /*==========================================
  4778. * Displays a message on a 'bl' to all it's nearby clients
  4779. * Used by npc_globalmessage
  4780. *------------------------------------------*/
  4781. void clif_GlobalMessage(struct block_list* bl, const char* message) {
  4782. char buf[100];
  4783. int len;
  4784. nullpo_retv(bl);
  4785. if(!message)
  4786. return;
  4787. len = strlen(message)+1;
  4788. if( len > sizeof(buf)-8 ) {
  4789. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  4790. len = sizeof(buf)-8;
  4791. }
  4792. WBUFW(buf,0)=0x8d;
  4793. WBUFW(buf,2)=len+8;
  4794. WBUFL(buf,4)=bl->id;
  4795. safestrncpy((char *) WBUFP(buf,8),message,len);
  4796. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4797. }
  4798. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4799. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4800. 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)
  4801. {
  4802. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4803. WBUFW(buf,0) = 0x1c3;
  4804. WBUFW(buf,2) = len + 16;
  4805. WBUFL(buf,4) = fontColor;
  4806. WBUFW(buf,8) = fontType;
  4807. WBUFW(buf,10) = fontSize;
  4808. WBUFW(buf,12) = fontAlign;
  4809. WBUFW(buf,14) = fontY;
  4810. memcpy(WBUFP(buf,16), mes, len);
  4811. clif_send(buf, WBUFW(buf,2), bl, target);
  4812. if (buf)
  4813. aFree(buf);
  4814. }
  4815. /*
  4816. * Display *msg from *sd to all *users in channel
  4817. */
  4818. void clif_channel_msg(struct Channel *channel, struct map_session_data *sd, char *msg) {
  4819. DBIterator *iter;
  4820. struct map_session_data *user;
  4821. unsigned short msg_len = strlen(msg) + 1;
  4822. WFIFOHEAD(sd->fd,msg_len + 12);
  4823. WFIFOW(sd->fd,0) = 0x2C1;
  4824. WFIFOW(sd->fd,2) = msg_len + 12;
  4825. WFIFOL(sd->fd,4) = 0;
  4826. WFIFOL(sd->fd,8) = Channel_Config.colors[channel->color];
  4827. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  4828. iter = db_iterator(channel->users);
  4829. for( user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter) ) {
  4830. if( user->fd == sd->fd )
  4831. continue;
  4832. WFIFOHEAD(user->fd,msg_len + 12);
  4833. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  4834. WFIFOSET(user->fd, msg_len + 12);
  4835. }
  4836. dbi_destroy(iter);
  4837. WFIFOSET(sd->fd, msg_len + 12);
  4838. }
  4839. /// Displays heal effect (ZC_RECOVERY).
  4840. /// 013d <var id>.W <amount>.W
  4841. /// var id:
  4842. /// 5 = HP (SP_HP)
  4843. /// 7 = SP (SP_SP)
  4844. /// ? = ignored
  4845. void clif_heal(int fd,int type,int val)
  4846. {
  4847. WFIFOHEAD(fd,packet_len(0x13d));
  4848. WFIFOW(fd,0)=0x13d;
  4849. WFIFOW(fd,2)=type;
  4850. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4851. WFIFOSET(fd,packet_len(0x13d));
  4852. }
  4853. /// Displays resurrection effect (ZC_RESURRECTION).
  4854. /// 0148 <id>.L <type>.W
  4855. /// type:
  4856. /// ignored
  4857. void clif_resurrection(struct block_list *bl,int type)
  4858. {
  4859. unsigned char buf[16];
  4860. nullpo_retv(bl);
  4861. WBUFW(buf,0)=0x148;
  4862. WBUFL(buf,2)=bl->id;
  4863. WBUFW(buf,6)=0;
  4864. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4865. if (disguised(bl))
  4866. clif_spawn(bl);
  4867. }
  4868. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  4869. /// 0199 <type>.W
  4870. void clif_map_property(struct map_session_data* sd, enum map_property property)
  4871. {
  4872. int fd;
  4873. nullpo_retv(sd);
  4874. fd=sd->fd;
  4875. WFIFOHEAD(fd,packet_len(0x199));
  4876. WFIFOW(fd,0)=0x199;
  4877. WFIFOW(fd,2)=property;
  4878. WFIFOSET(fd,packet_len(0x199));
  4879. }
  4880. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  4881. /// 01d6 <type>.W
  4882. void clif_map_type(struct map_session_data* sd, enum map_type type)
  4883. {
  4884. int fd;
  4885. nullpo_retv(sd);
  4886. fd=sd->fd;
  4887. WFIFOHEAD(fd,packet_len(0x1D6));
  4888. WFIFOW(fd,0)=0x1D6;
  4889. WFIFOW(fd,2)=type;
  4890. WFIFOSET(fd,packet_len(0x1D6));
  4891. }
  4892. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  4893. /// 019a <id>.L <ranking>.L <total>.L
  4894. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4895. {
  4896. if(type == 2) {
  4897. int fd = sd->fd;
  4898. WFIFOHEAD(fd,packet_len(0x19a));
  4899. WFIFOW(fd,0) = 0x19a;
  4900. WFIFOL(fd,2) = sd->bl.id;
  4901. WFIFOL(fd,6) = pvprank;
  4902. WFIFOL(fd,10) = pvpnum;
  4903. WFIFOSET(fd,packet_len(0x19a));
  4904. } else {
  4905. unsigned char buf[32];
  4906. WBUFW(buf,0) = 0x19a;
  4907. WBUFL(buf,2) = sd->bl.id;
  4908. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4909. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  4910. else
  4911. WBUFL(buf,6) = pvprank;
  4912. WBUFL(buf,10) = pvpnum;
  4913. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4914. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4915. else if(!type)
  4916. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4917. else
  4918. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4919. }
  4920. }
  4921. /*==========================================
  4922. *
  4923. *------------------------------------------*/
  4924. void clif_map_property_mapall(int map, enum map_property property)
  4925. {
  4926. struct block_list bl;
  4927. unsigned char buf[16];
  4928. bl.id = 0;
  4929. bl.type = BL_NUL;
  4930. bl.m = map;
  4931. WBUFW(buf,0)=0x199;
  4932. WBUFW(buf,2)=property;
  4933. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4934. }
  4935. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  4936. /// 0188 <result>.W <index>.W <refine>.W
  4937. /// result:
  4938. /// 0 = success
  4939. /// 1 = failure
  4940. /// 2 = downgrade
  4941. void clif_refine(int fd, int fail, int index, int val)
  4942. {
  4943. WFIFOHEAD(fd,packet_len(0x188));
  4944. WFIFOW(fd,0)=0x188;
  4945. WFIFOW(fd,2)=fail;
  4946. WFIFOW(fd,4)=index+2;
  4947. WFIFOW(fd,6)=val;
  4948. WFIFOSET(fd,packet_len(0x188));
  4949. }
  4950. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  4951. /// 0223 <result>.L <nameid>.W
  4952. /// result:
  4953. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  4954. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  4955. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4956. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4957. void clif_upgrademessage(int fd, int result, int item_id)
  4958. {
  4959. WFIFOHEAD(fd,packet_len(0x223));
  4960. WFIFOW(fd,0)=0x223;
  4961. WFIFOL(fd,2)=result;
  4962. WFIFOW(fd,6)=item_id;
  4963. WFIFOSET(fd,packet_len(0x223));
  4964. }
  4965. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  4966. /// 0097 <packet len>.W <nick>.24B <message>.?B
  4967. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  4968. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4969. {
  4970. #if PACKETVER < 20091104
  4971. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4972. WFIFOW(fd,0) = 0x97;
  4973. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4974. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4975. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4976. WFIFOSET(fd,WFIFOW(fd,2));
  4977. #else
  4978. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4979. WFIFOW(fd,0) = 0x97;
  4980. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4981. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4982. WFIFOL(fd,28) = 0; // isAdmin; if nonzero, also displays text above char
  4983. // TODO: WFIFOL(fd,28) = pc_get_group_level(ssd);
  4984. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4985. WFIFOSET(fd,WFIFOW(fd,2));
  4986. #endif
  4987. }
  4988. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  4989. /// 0098 <result>.B
  4990. /// result:
  4991. /// 0 = success to send wisper
  4992. /// 1 = target character is not loged in
  4993. /// 2 = ignored by target
  4994. /// 3 = everyone ignored by target
  4995. void clif_wis_end(int fd, int flag)
  4996. {
  4997. WFIFOHEAD(fd,packet_len(0x98));
  4998. WFIFOW(fd,0) = 0x98;
  4999. WFIFOW(fd,2) = flag;
  5000. WFIFOSET(fd,packet_len(0x98));
  5001. }
  5002. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5003. /// 0194 <char id>.L <name>.24B
  5004. void clif_solved_charname(int fd, int charid, const char* name)
  5005. {
  5006. WFIFOHEAD(fd,packet_len(0x194));
  5007. WFIFOW(fd,0)=0x194;
  5008. WFIFOL(fd,2)=charid;
  5009. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5010. WFIFOSET(fd,packet_len(0x194));
  5011. }
  5012. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5013. /// 017b <packet len>.W { <name id>.W }*
  5014. void clif_use_card(struct map_session_data *sd,int idx)
  5015. {
  5016. int i,c,ep;
  5017. int fd=sd->fd;
  5018. nullpo_retv(sd);
  5019. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5020. return;
  5021. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5022. return; //Avoid parsing invalid item indexes (no card/no item)
  5023. ep=sd->inventory_data[idx]->equip;
  5024. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5025. WFIFOW(fd,0)=0x17b;
  5026. for(i=c=0;i<MAX_INVENTORY;i++){
  5027. int j;
  5028. if(sd->inventory_data[i] == NULL)
  5029. continue;
  5030. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5031. continue;
  5032. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  5033. continue;
  5034. if(sd->status.inventory[i].identify==0 ) //Not identified
  5035. continue;
  5036. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5037. continue;
  5038. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5039. continue;
  5040. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  5041. if( j == sd->inventory_data[i]->slot ) // No room
  5042. continue;
  5043. WFIFOW(fd,4+c*2)=i+2;
  5044. c++;
  5045. }
  5046. WFIFOW(fd,2)=4+c*2;
  5047. WFIFOSET(fd,WFIFOW(fd,2));
  5048. }
  5049. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5050. /// 017d <equip index>.W <card index>.W <result>.B
  5051. /// result:
  5052. /// 0 = success
  5053. /// 1 = failure
  5054. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5055. {
  5056. int fd;
  5057. nullpo_retv(sd);
  5058. fd=sd->fd;
  5059. WFIFOHEAD(fd,packet_len(0x17d));
  5060. WFIFOW(fd,0)=0x17d;
  5061. WFIFOW(fd,2)=idx_equip+2;
  5062. WFIFOW(fd,4)=idx_card+2;
  5063. WFIFOB(fd,6)=flag;
  5064. WFIFOSET(fd,packet_len(0x17d));
  5065. }
  5066. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5067. /// 0177 <packet len>.W { <name id>.W }*
  5068. void clif_item_identify_list(struct map_session_data *sd)
  5069. {
  5070. int i,c;
  5071. int fd;
  5072. nullpo_retv(sd);
  5073. fd=sd->fd;
  5074. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5075. WFIFOW(fd,0)=0x177;
  5076. for(i=c=0;i<MAX_INVENTORY;i++){
  5077. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5078. WFIFOW(fd,c*2+4)=i+2;
  5079. c++;
  5080. }
  5081. }
  5082. if(c > 0) {
  5083. WFIFOW(fd,2)=c*2+4;
  5084. WFIFOSET(fd,WFIFOW(fd,2));
  5085. sd->menuskill_id = MC_IDENTIFY;
  5086. sd->menuskill_val = c;
  5087. }
  5088. }
  5089. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5090. /// 0179 <index>.W <result>.B
  5091. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5092. {
  5093. int fd;
  5094. nullpo_retv(sd);
  5095. fd=sd->fd;
  5096. WFIFOHEAD(fd,packet_len(0x179));
  5097. WFIFOW(fd, 0)=0x179;
  5098. WFIFOW(fd, 2)=idx+2;
  5099. WFIFOB(fd, 4)=flag;
  5100. WFIFOSET(fd,packet_len(0x179));
  5101. }
  5102. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5103. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5104. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5105. {
  5106. int i,c;
  5107. int fd;
  5108. int nameid;
  5109. nullpo_retv(sd);
  5110. nullpo_retv(dstsd);
  5111. fd=sd->fd;
  5112. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5113. WFIFOW(fd,0)=0x1fc;
  5114. for(i=c=0;i<MAX_INVENTORY;i++){
  5115. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5116. WFIFOW(fd,c*13+4) = i;
  5117. WFIFOW(fd,c*13+6) = nameid;
  5118. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5119. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5120. c++;
  5121. }
  5122. }
  5123. if(c > 0) {
  5124. WFIFOW(fd,2)=c*13+4;
  5125. WFIFOSET(fd,WFIFOW(fd,2));
  5126. sd->menuskill_id = BS_REPAIRWEAPON;
  5127. sd->menuskill_val = dstsd->bl.id;
  5128. sd->menuskill_val2 = lv;
  5129. }else
  5130. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5131. }
  5132. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5133. /// 01fe <index>.W <result>.B
  5134. /// index:
  5135. /// ignored (inventory index)
  5136. /// result:
  5137. /// 0 = Item repair success.
  5138. /// 1 = Item repair failure.
  5139. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5140. {
  5141. int fd;
  5142. nullpo_retv(sd);
  5143. fd = sd->fd;
  5144. WFIFOHEAD(fd,packet_len(0x1fe));
  5145. WFIFOW(fd, 0)=0x1fe;
  5146. WFIFOW(fd, 2)=idx+2;
  5147. WFIFOB(fd, 4)=flag;
  5148. WFIFOSET(fd,packet_len(0x1fe));
  5149. }
  5150. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5151. /// 02bb <equip location>.W <account id>.L
  5152. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5153. {
  5154. int fd = sd->fd;
  5155. WFIFOHEAD(fd,packet_len(0x2bb));
  5156. WFIFOW(fd,0) = 0x2bb;
  5157. WFIFOW(fd,2) = position;
  5158. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5159. WFIFOSET(fd,packet_len(0x2bb));
  5160. }
  5161. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5162. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5163. void clif_item_refine_list(struct map_session_data *sd)
  5164. {
  5165. int i,c;
  5166. int fd;
  5167. uint16 skill_lv;
  5168. int wlv;
  5169. int refine_item[5];
  5170. nullpo_retv(sd);
  5171. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5172. fd=sd->fd;
  5173. refine_item[0] = -1;
  5174. refine_item[1] = pc_search_inventory(sd,1010);
  5175. refine_item[2] = pc_search_inventory(sd,1011);
  5176. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5177. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5178. WFIFOW(fd,0)=0x221;
  5179. for(i=c=0;i<MAX_INVENTORY;i++){
  5180. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skill_lv &&
  5181. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5182. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5183. WFIFOW(fd,c*13+ 4)=i+2;
  5184. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5185. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5186. clif_addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5187. c++;
  5188. }
  5189. }
  5190. WFIFOW(fd,2)=c*13+4;
  5191. WFIFOSET(fd,WFIFOW(fd,2));
  5192. if (c > 0) {
  5193. sd->menuskill_id = WS_WEAPONREFINE;
  5194. sd->menuskill_val = skill_lv;
  5195. }
  5196. }
  5197. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5198. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5199. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5200. {
  5201. int fd;
  5202. nullpo_retv(sd);
  5203. fd=sd->fd;
  5204. WFIFOHEAD(fd,packet_len(0x147));
  5205. WFIFOW(fd, 0)=0x147;
  5206. WFIFOW(fd, 2)=skill_id;
  5207. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5208. WFIFOW(fd, 6)=0;
  5209. WFIFOW(fd, 8)=skill_lv;
  5210. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5211. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skill_id,skill_lv);
  5212. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5213. WFIFOB(fd,38)=0;
  5214. WFIFOSET(fd,packet_len(0x147));
  5215. }
  5216. /// Adds an item to character's cart.
  5217. /// 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)
  5218. /// 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)
  5219. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5220. {
  5221. int view,fd;
  5222. unsigned char *buf;
  5223. nullpo_retv(sd);
  5224. fd=sd->fd;
  5225. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5226. return;
  5227. #if PACKETVER < 5
  5228. WFIFOHEAD(fd,packet_len(0x124));
  5229. buf=WFIFOP(fd,0);
  5230. WBUFW(buf,0)=0x124;
  5231. WBUFW(buf,2)=n+2;
  5232. WBUFL(buf,4)=amount;
  5233. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5234. WBUFW(buf,8)=view;
  5235. else
  5236. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5237. WBUFB(buf,10)=sd->status.cart[n].identify;
  5238. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5239. WBUFB(buf,12)=sd->status.cart[n].refine;
  5240. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5241. WFIFOSET(fd,packet_len(0x124));
  5242. #else
  5243. WFIFOHEAD(fd,packet_len(0x1c5));
  5244. buf=WFIFOP(fd,0);
  5245. WBUFW(buf,0)=0x1c5;
  5246. WBUFW(buf,2)=n+2;
  5247. WBUFL(buf,4)=amount;
  5248. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5249. WBUFW(buf,8)=view;
  5250. else
  5251. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5252. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5253. WBUFB(buf,11)=sd->status.cart[n].identify;
  5254. WBUFB(buf,12)=sd->status.cart[n].attribute;
  5255. WBUFB(buf,13)=sd->status.cart[n].refine;
  5256. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  5257. WFIFOSET(fd,packet_len(0x1c5));
  5258. #endif
  5259. }
  5260. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5261. /// 0125 <index>.W <amount>.L
  5262. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5263. {
  5264. int fd;
  5265. nullpo_retv(sd);
  5266. fd=sd->fd;
  5267. WFIFOHEAD(fd,packet_len(0x125));
  5268. WFIFOW(fd,0)=0x125;
  5269. WFIFOW(fd,2)=n+2;
  5270. WFIFOL(fd,4)=amount;
  5271. WFIFOSET(fd,packet_len(0x125));
  5272. }
  5273. /// Opens the shop creation menu (ZC_OPENSTORE).
  5274. /// 012d <num>.W
  5275. /// num:
  5276. /// number of allowed item slots
  5277. void clif_openvendingreq(struct map_session_data* sd, int num)
  5278. {
  5279. int fd;
  5280. nullpo_retv(sd);
  5281. fd = sd->fd;
  5282. WFIFOHEAD(fd,packet_len(0x12d));
  5283. WFIFOW(fd,0) = 0x12d;
  5284. WFIFOW(fd,2) = num;
  5285. WFIFOSET(fd,packet_len(0x12d));
  5286. }
  5287. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5288. /// 0131 <owner id>.L <message>.80B
  5289. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5290. {
  5291. unsigned char buf[128];
  5292. nullpo_retv(bl);
  5293. WBUFW(buf,0) = 0x131;
  5294. WBUFL(buf,2) = bl->id;
  5295. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5296. if( fd ) {
  5297. WFIFOHEAD(fd,packet_len(0x131));
  5298. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5299. WFIFOSET(fd,packet_len(0x131));
  5300. } else {
  5301. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  5302. }
  5303. }
  5304. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5305. /// 0132 <owner id>.L
  5306. void clif_closevendingboard(struct block_list* bl, int fd)
  5307. {
  5308. unsigned char buf[16];
  5309. nullpo_retv(bl);
  5310. WBUFW(buf,0) = 0x132;
  5311. WBUFL(buf,2) = bl->id;
  5312. if( fd ) {
  5313. WFIFOHEAD(fd,packet_len(0x132));
  5314. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5315. WFIFOSET(fd,packet_len(0x132));
  5316. } else {
  5317. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  5318. }
  5319. }
  5320. /// Sends a list of items in a shop.
  5321. /// 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)
  5322. /// 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)
  5323. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  5324. {
  5325. int i,fd;
  5326. int count;
  5327. struct map_session_data* vsd;
  5328. #if PACKETVER < 20100105
  5329. const int cmd = 0x133;
  5330. const int offset = 8;
  5331. #else
  5332. const int cmd = 0x800;
  5333. const int offset = 12;
  5334. #endif
  5335. nullpo_retv(sd);
  5336. nullpo_retv(vending);
  5337. nullpo_retv(vsd=map_id2sd(id));
  5338. fd = sd->fd;
  5339. count = vsd->vend_num;
  5340. WFIFOHEAD(fd, offset+count*22);
  5341. WFIFOW(fd,0) = cmd;
  5342. WFIFOW(fd,2) = offset+count*22;
  5343. WFIFOL(fd,4) = id;
  5344. #if PACKETVER >= 20100105
  5345. WFIFOL(fd,8) = vsd->vender_id;
  5346. #endif
  5347. for( i = 0; i < count; i++ )
  5348. {
  5349. int index = vending[i].index;
  5350. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  5351. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  5352. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  5353. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  5354. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  5355. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5356. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  5357. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  5358. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  5359. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  5360. }
  5361. WFIFOSET(fd,WFIFOW(fd,2));
  5362. }
  5363. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5364. /// 0135 <index>.W <amount>.W <result>.B
  5365. /// result:
  5366. /// 0 = success
  5367. /// 1 = not enough zeny
  5368. /// 2 = overweight
  5369. /// 4 = out of stock
  5370. /// 5 = "cannot use an npc shop while in a trade"
  5371. /// 6 = Because the store information was incorrect the item was not purchased.
  5372. /// 7 = No sales information.
  5373. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5374. {
  5375. int fd;
  5376. nullpo_retv(sd);
  5377. fd = sd->fd;
  5378. WFIFOHEAD(fd,packet_len(0x135));
  5379. WFIFOW(fd,0) = 0x135;
  5380. WFIFOW(fd,2) = index+2;
  5381. WFIFOW(fd,4) = amount;
  5382. WFIFOB(fd,6) = fail;
  5383. WFIFOSET(fd,packet_len(0x135));
  5384. }
  5385. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5386. /// 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 }*
  5387. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5388. {
  5389. int i,fd;
  5390. int count;
  5391. nullpo_retv(sd);
  5392. fd = sd->fd;
  5393. count = sd->vend_num;
  5394. WFIFOHEAD(fd, 8+count*22);
  5395. WFIFOW(fd,0) = 0x136;
  5396. WFIFOW(fd,2) = 8+count*22;
  5397. WFIFOL(fd,4) = id;
  5398. for( i = 0; i < count; i++ ) {
  5399. int index = vending[i].index;
  5400. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5401. WFIFOL(fd, 8+i*22) = vending[i].value;
  5402. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5403. WFIFOW(fd,14+i*22) = vending[i].amount;
  5404. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5405. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5406. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5407. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5408. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5409. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5410. }
  5411. WFIFOSET(fd,WFIFOW(fd,2));
  5412. }
  5413. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5414. /// 0137 <index>.W <amount>.W
  5415. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5416. {
  5417. int fd;
  5418. nullpo_retv(sd);
  5419. fd = sd->fd;
  5420. WFIFOHEAD(fd,packet_len(0x137));
  5421. WFIFOW(fd,0) = 0x137;
  5422. WFIFOW(fd,2) = index+2;
  5423. WFIFOW(fd,4) = amount;
  5424. WFIFOSET(fd,packet_len(0x137));
  5425. }
  5426. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5427. /// 00fa <result>.B
  5428. /// result:
  5429. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5430. /// 1 = MsgStringTable[78]="party name already exists"
  5431. /// 2 = MsgStringTable[79]="already in a party"
  5432. /// 3 = cannot organize parties on this map
  5433. /// ? = nothing
  5434. void clif_party_created(struct map_session_data *sd,int result)
  5435. {
  5436. int fd;
  5437. nullpo_retv(sd);
  5438. fd=sd->fd;
  5439. WFIFOHEAD(fd,packet_len(0xfa));
  5440. WFIFOW(fd,0)=0xfa;
  5441. WFIFOB(fd,2)=result;
  5442. WFIFOSET(fd,packet_len(0xfa));
  5443. }
  5444. /// Adds new member to a party.
  5445. /// 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)
  5446. /// 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)
  5447. /// role:
  5448. /// 0 = leader
  5449. /// 1 = normal
  5450. /// state:
  5451. /// 0 = connected
  5452. /// 1 = disconnected
  5453. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5454. {
  5455. unsigned char buf[81];
  5456. int i;
  5457. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5458. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5459. } else {
  5460. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5461. }
  5462. if (i >= MAX_PARTY) return; //Should never happen...
  5463. sd = p->data[i].sd;
  5464. WBUFW(buf, 0) = 0x1e9;
  5465. WBUFL(buf, 2) = sd->status.account_id;
  5466. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5467. WBUFW(buf,10) = sd->bl.x;
  5468. WBUFW(buf,12) = sd->bl.y;
  5469. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5470. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5471. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5472. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5473. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5474. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5475. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5476. }
  5477. /// Sends party information (ZC_GROUP_LIST).
  5478. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5479. /// role:
  5480. /// 0 = leader
  5481. /// 1 = normal
  5482. /// state:
  5483. /// 0 = connected
  5484. /// 1 = disconnected
  5485. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5486. {
  5487. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5488. struct map_session_data* party_sd = NULL;
  5489. int i, c;
  5490. nullpo_retv(p);
  5491. WBUFW(buf,0) = 0xfb;
  5492. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5493. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5494. {
  5495. struct party_member* m = &p->party.member[i];
  5496. if(!m->account_id) continue;
  5497. if(party_sd == NULL) party_sd = p->data[i].sd;
  5498. WBUFL(buf,28+c*46) = m->account_id;
  5499. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5500. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5501. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5502. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5503. c++;
  5504. }
  5505. WBUFW(buf,2) = 28+c*46;
  5506. if(sd) { // send only to self
  5507. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5508. } else if (party_sd) { // send to whole party
  5509. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5510. }
  5511. }
  5512. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5513. /// 02c9 <flag>.B
  5514. /// flag:
  5515. /// 0 = allow party invites
  5516. /// 1 = auto-deny party invites
  5517. void clif_partyinvitationstate(struct map_session_data* sd)
  5518. {
  5519. int fd;
  5520. nullpo_retv(sd);
  5521. fd = sd->fd;
  5522. WFIFOHEAD(fd, packet_len(0x2c9));
  5523. WFIFOW(fd, 0) = 0x2c9;
  5524. WFIFOB(fd, 2) = 0; // not implemented
  5525. WFIFOSET(fd, packet_len(0x2c9));
  5526. }
  5527. /// Party invitation request.
  5528. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5529. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5530. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5531. {
  5532. #if PACKETVER < 20070821
  5533. const int cmd = 0xfe;
  5534. #else
  5535. const int cmd = 0x2c6;
  5536. #endif
  5537. int fd;
  5538. struct party_data *p;
  5539. nullpo_retv(sd);
  5540. nullpo_retv(tsd);
  5541. fd=tsd->fd;
  5542. if( (p=party_search(sd->status.party_id))==NULL )
  5543. return;
  5544. WFIFOHEAD(fd,packet_len(cmd));
  5545. WFIFOW(fd,0)=cmd;
  5546. WFIFOL(fd,2)=sd->status.party_id;
  5547. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5548. WFIFOSET(fd,packet_len(cmd));
  5549. }
  5550. /// Party invite result.
  5551. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5552. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5553. /// result=0 : char is already in a party -> MsgStringTable[80]
  5554. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5555. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5556. /// result=3 : party is full -> MsgStringTable[83]
  5557. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5558. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5559. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5560. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5561. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5562. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5563. {
  5564. int fd;
  5565. nullpo_retv(sd);
  5566. fd=sd->fd;
  5567. #if PACKETVER < 20070904
  5568. if( result == 7 ) {
  5569. clif_displaymessage(fd, msg_txt(sd,3));
  5570. return;
  5571. }
  5572. #endif
  5573. #if PACKETVER < 20070821
  5574. WFIFOHEAD(fd,packet_len(0xfd));
  5575. WFIFOW(fd,0) = 0xfd;
  5576. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5577. WFIFOB(fd,26) = result;
  5578. WFIFOSET(fd,packet_len(0xfd));
  5579. #else
  5580. WFIFOHEAD(fd,packet_len(0x2c5));
  5581. WFIFOW(fd,0) = 0x2c5;
  5582. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5583. WFIFOL(fd,26) = result;
  5584. WFIFOSET(fd,packet_len(0x2c5));
  5585. #endif
  5586. }
  5587. /// Updates party settings.
  5588. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5589. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5590. /// exp option:
  5591. /// 0 = exp sharing disabled
  5592. /// 1 = exp sharing enabled
  5593. /// 2 = cannot change exp sharing
  5594. ///
  5595. /// flag:
  5596. /// 0 = send to party
  5597. /// 1 = send to sd
  5598. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5599. {
  5600. unsigned char buf[16];
  5601. #if PACKETVER < 20090603
  5602. const int cmd = 0x101;
  5603. #else
  5604. const int cmd = 0x7d8;
  5605. #endif
  5606. nullpo_retv(p);
  5607. if(!sd && flag==0){
  5608. int i;
  5609. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5610. if (i < MAX_PARTY)
  5611. sd = p->data[i].sd;
  5612. }
  5613. if(!sd) return;
  5614. WBUFW(buf,0)=cmd;
  5615. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5616. #if PACKETVER >= 20090603
  5617. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5618. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5619. #endif
  5620. if(flag==0)
  5621. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5622. else
  5623. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5624. }
  5625. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5626. /// result:
  5627. /// 0 = leave
  5628. /// 1 = expel
  5629. /// 2 = cannot leave party on this map
  5630. /// 3 = cannot expel from party on this map
  5631. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5632. {
  5633. unsigned char buf[64];
  5634. nullpo_retv(p);
  5635. if(!sd && (flag&0xf0)==0)
  5636. {
  5637. int i;
  5638. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5639. if (i < MAX_PARTY)
  5640. sd = p->data[i].sd;
  5641. }
  5642. if(!sd) return;
  5643. WBUFW(buf,0)=0x105;
  5644. WBUFL(buf,2)=account_id;
  5645. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5646. WBUFB(buf,30)=flag&0x0f;
  5647. if((flag&0xf0)==0)
  5648. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5649. else
  5650. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5651. }
  5652. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5653. /// 0109 <packet len>.W <account id>.L <message>.?B
  5654. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5655. {
  5656. struct map_session_data *sd;
  5657. int i;
  5658. nullpo_retv(p);
  5659. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  5660. if(i < MAX_PARTY){
  5661. unsigned char buf[1024];
  5662. if( len > sizeof(buf)-8 )
  5663. {
  5664. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  5665. len = sizeof(buf)-8;
  5666. }
  5667. sd = p->data[i].sd;
  5668. WBUFW(buf,0)=0x109;
  5669. WBUFW(buf,2)=len+8;
  5670. WBUFL(buf,4)=account_id;
  5671. safestrncpy((char *)WBUFP(buf,8), mes, len);
  5672. clif_send(buf,len+8,&sd->bl,PARTY);
  5673. }
  5674. }
  5675. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5676. /// 0107 <account id>.L <x>.W <y>.W
  5677. void clif_party_xy(struct map_session_data *sd)
  5678. {
  5679. unsigned char buf[16];
  5680. nullpo_retv(sd);
  5681. WBUFW(buf,0)=0x107;
  5682. WBUFL(buf,2)=sd->status.account_id;
  5683. WBUFW(buf,6)=sd->bl.x;
  5684. WBUFW(buf,8)=sd->bl.y;
  5685. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5686. }
  5687. /*==========================================
  5688. * Sends x/y dot to a single fd. [Skotlex]
  5689. *------------------------------------------*/
  5690. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5691. {
  5692. WFIFOHEAD(fd,packet_len(0x107));
  5693. WFIFOW(fd,0)=0x107;
  5694. WFIFOL(fd,2)=sd->status.account_id;
  5695. WFIFOW(fd,6)=sd->bl.x;
  5696. WFIFOW(fd,8)=sd->bl.y;
  5697. WFIFOSET(fd,packet_len(0x107));
  5698. }
  5699. /// Updates HP bar of a party member.
  5700. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5701. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5702. void clif_party_hp(struct map_session_data *sd)
  5703. {
  5704. unsigned char buf[16];
  5705. #if PACKETVER < 20100126
  5706. const int cmd = 0x106;
  5707. #else
  5708. const int cmd = 0x80e;
  5709. #endif
  5710. nullpo_retv(sd);
  5711. WBUFW(buf,0)=cmd;
  5712. WBUFL(buf,2)=sd->status.account_id;
  5713. #if PACKETVER < 20100126
  5714. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5715. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5716. WBUFW(buf,8) = 100;
  5717. } else {
  5718. WBUFW(buf,6) = sd->battle_status.hp;
  5719. WBUFW(buf,8) = sd->battle_status.max_hp;
  5720. }
  5721. #else
  5722. WBUFL(buf,6) = sd->battle_status.hp;
  5723. WBUFL(buf,10) = sd->battle_status.max_hp;
  5724. #endif
  5725. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5726. }
  5727. /*==========================================
  5728. * Sends HP bar to a single fd. [Skotlex]
  5729. *------------------------------------------*/
  5730. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5731. {
  5732. #if PACKETVER < 20100126
  5733. const int cmd = 0x106;
  5734. #else
  5735. const int cmd = 0x80e;
  5736. #endif
  5737. WFIFOHEAD(fd,packet_len(cmd));
  5738. WFIFOW(fd,0) = cmd;
  5739. WFIFOL(fd,2) = id;
  5740. #if PACKETVER < 20100126
  5741. if( maxhp > INT16_MAX )
  5742. {// To correctly display the %hp bar. [Skotlex]
  5743. WFIFOW(fd,6) = hp/(maxhp/100);
  5744. WFIFOW(fd,8) = 100;
  5745. } else {
  5746. WFIFOW(fd,6) = hp;
  5747. WFIFOW(fd,8) = maxhp;
  5748. }
  5749. #else
  5750. WFIFOL(fd,6) = hp;
  5751. WFIFOL(fd,10) = maxhp;
  5752. #endif
  5753. WFIFOSET(fd, packet_len(cmd));
  5754. }
  5755. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5756. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5757. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5758. {
  5759. int fd;
  5760. nullpo_retv(sd);
  5761. nullpo_retv(bl);
  5762. fd=sd->fd;
  5763. WFIFOHEAD(fd,packet_len(0x139));
  5764. WFIFOW(fd, 0)=0x139;
  5765. WFIFOL(fd, 2)=bl->id;
  5766. WFIFOW(fd, 6)=bl->x;
  5767. WFIFOW(fd, 8)=bl->y;
  5768. WFIFOW(fd,10)=sd->bl.x;
  5769. WFIFOW(fd,12)=sd->bl.y;
  5770. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5771. WFIFOSET(fd,packet_len(0x139));
  5772. }
  5773. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5774. /// 018f <result>.W <name id>.W
  5775. /// result:
  5776. /// 0 = success
  5777. /// 1 = failure
  5778. /// 2 = success (alchemist)
  5779. /// 3 = failure (alchemist)
  5780. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5781. {
  5782. int view,fd;
  5783. nullpo_retv(sd);
  5784. fd = sd->fd;
  5785. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5786. WFIFOHEAD(fd,packet_len(0x18f));
  5787. WFIFOW(fd, 0)=0x18f;
  5788. WFIFOW(fd, 2)=flag;
  5789. if((view = itemdb_viewid(nameid)) > 0)
  5790. WFIFOW(fd, 4)=view;
  5791. else
  5792. WFIFOW(fd, 4)=nameid;
  5793. WFIFOSET(fd,packet_len(0x18f));
  5794. }
  5795. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5796. /// 019e
  5797. void clif_catch_process(struct map_session_data *sd)
  5798. {
  5799. int fd;
  5800. nullpo_retv(sd);
  5801. fd=sd->fd;
  5802. WFIFOHEAD(fd,packet_len(0x19e));
  5803. WFIFOW(fd,0)=0x19e;
  5804. WFIFOSET(fd,packet_len(0x19e));
  5805. }
  5806. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5807. /// 01a0 <result>.B
  5808. /// 0 = failure
  5809. /// 1 = success
  5810. void clif_pet_roulette(struct map_session_data *sd,int data)
  5811. {
  5812. int fd;
  5813. nullpo_retv(sd);
  5814. fd=sd->fd;
  5815. WFIFOHEAD(fd,packet_len(0x1a0));
  5816. WFIFOW(fd,0)=0x1a0;
  5817. WFIFOB(fd,2)=data;
  5818. WFIFOSET(fd,packet_len(0x1a0));
  5819. }
  5820. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5821. /// 01a6 <packet len>.W { <index>.W }*
  5822. void clif_sendegg(struct map_session_data *sd)
  5823. {
  5824. int i,n=0,fd;
  5825. nullpo_retv(sd);
  5826. fd=sd->fd;
  5827. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5828. clif_displaymessage(fd, msg_txt(sd,666));
  5829. return;
  5830. }
  5831. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5832. WFIFOW(fd,0)=0x1a6;
  5833. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5834. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5835. sd->inventory_data[i]->type!=IT_PETEGG ||
  5836. sd->status.inventory[i].amount<=0)
  5837. continue;
  5838. WFIFOW(fd,n*2+4)=i+2;
  5839. n++;
  5840. }
  5841. WFIFOW(fd,2)=4+n*2;
  5842. WFIFOSET(fd,WFIFOW(fd,2));
  5843. sd->menuskill_id = SA_TAMINGMONSTER;
  5844. sd->menuskill_val = -1;
  5845. }
  5846. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5847. /// 01a4 <type>.B <id>.L <data>.L
  5848. /// type:
  5849. /// 0 = pre-init (data = 0)
  5850. /// 1 = intimacy (data = 0~4)
  5851. /// 2 = hunger (data = 0~4)
  5852. /// 3 = accessory
  5853. /// 4 = performance (data = 1~3: normal, 4: special)
  5854. /// 5 = hairstyle
  5855. ///
  5856. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5857. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5858. {
  5859. uint8 buf[16];
  5860. nullpo_retv(pd);
  5861. WBUFW(buf,0) = 0x1a4;
  5862. WBUFB(buf,2) = type;
  5863. WBUFL(buf,3) = pd->bl.id;
  5864. WBUFL(buf,7) = param;
  5865. if (sd)
  5866. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5867. else
  5868. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5869. }
  5870. /// Pet's base data (ZC_PROPERTY_PET).
  5871. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  5872. void clif_send_petstatus(struct map_session_data *sd)
  5873. {
  5874. int fd;
  5875. struct s_pet *pet;
  5876. nullpo_retv(sd);
  5877. nullpo_retv(sd->pd);
  5878. fd=sd->fd;
  5879. pet = &sd->pd->pet;
  5880. WFIFOHEAD(fd,packet_len(0x1a2));
  5881. WFIFOW(fd,0)=0x1a2;
  5882. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5883. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5884. WFIFOW(fd,27)=pet->level;
  5885. WFIFOW(fd,29)=pet->hungry;
  5886. WFIFOW(fd,31)=pet->intimate;
  5887. WFIFOW(fd,33)=pet->equip;
  5888. #if PACKETVER >= 20081126
  5889. WFIFOW(fd,35)=pet->class_;
  5890. #endif
  5891. WFIFOSET(fd,packet_len(0x1a2));
  5892. }
  5893. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  5894. /// 01aa <id>.L <data>.L
  5895. /// data:
  5896. /// @see CZ_PET_ACT.
  5897. void clif_pet_emotion(struct pet_data *pd,int param)
  5898. {
  5899. unsigned char buf[16];
  5900. nullpo_retv(pd);
  5901. memset(buf,0,packet_len(0x1aa));
  5902. WBUFW(buf,0)=0x1aa;
  5903. WBUFL(buf,2)=pd->bl.id;
  5904. if(param >= 100 && pd->petDB->talk_convert_class) {
  5905. if(pd->petDB->talk_convert_class < 0)
  5906. return;
  5907. else if(pd->petDB->talk_convert_class > 0) {
  5908. // replace mob_id component of talk/act data
  5909. param -= (pd->pet.class_ - 100)*100;
  5910. param += (pd->petDB->talk_convert_class - 100)*100;
  5911. }
  5912. }
  5913. WBUFL(buf,6)=param;
  5914. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5915. }
  5916. /// Result of request to feed a pet (ZC_FEED_PET).
  5917. /// 01a3 <result>.B <name id>.W
  5918. /// result:
  5919. /// 0 = failure
  5920. /// 1 = success
  5921. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5922. {
  5923. int fd;
  5924. nullpo_retv(sd);
  5925. fd=sd->fd;
  5926. WFIFOHEAD(fd,packet_len(0x1a3));
  5927. WFIFOW(fd,0)=0x1a3;
  5928. WFIFOB(fd,2)=fail;
  5929. WFIFOW(fd,3)=foodid;
  5930. WFIFOSET(fd,packet_len(0x1a3));
  5931. }
  5932. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  5933. /// 01cd { <skill id>.L }*7
  5934. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  5935. {
  5936. int fd;
  5937. nullpo_retv(sd);
  5938. fd=sd->fd;
  5939. WFIFOHEAD(fd,packet_len(0x1cd));
  5940. WFIFOW(fd, 0)=0x1cd;
  5941. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5942. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5943. else
  5944. WFIFOL(fd,2)= 0x00000000;
  5945. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5946. WFIFOL(fd,6)= MG_COLDBOLT;
  5947. else
  5948. WFIFOL(fd,6)= 0x00000000;
  5949. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5950. WFIFOL(fd,10)= MG_FIREBOLT;
  5951. else
  5952. WFIFOL(fd,10)= 0x00000000;
  5953. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5954. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5955. else
  5956. WFIFOL(fd,14)= 0x00000000;
  5957. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5958. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5959. else
  5960. WFIFOL(fd,18)= 0x00000000;
  5961. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5962. WFIFOL(fd,22)= MG_FIREBALL;
  5963. else
  5964. WFIFOL(fd,22)= 0x00000000;
  5965. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5966. WFIFOL(fd,26)= MG_FROSTDIVER;
  5967. else
  5968. WFIFOL(fd,26)= 0x00000000;
  5969. WFIFOSET(fd,packet_len(0x1cd));
  5970. sd->menuskill_id = SA_AUTOSPELL;
  5971. sd->menuskill_val = skill_lv;
  5972. }
  5973. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  5974. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  5975. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5976. {
  5977. unsigned char buf[56];
  5978. nullpo_retv(src);
  5979. memset(buf,0,packet_len(0x1cf));
  5980. WBUFW(buf,0) = 0x1cf;
  5981. WBUFL(buf,2) = src->id;
  5982. if( src->type == BL_MER )
  5983. {
  5984. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5985. if( md && md->master && md->devotion_flag )
  5986. WBUFL(buf,6) = md->master->bl.id;
  5987. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5988. }
  5989. else
  5990. {
  5991. int i;
  5992. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5993. if( sd == NULL )
  5994. return;
  5995. for( i = 0; i < 5; i++ )
  5996. WBUFL(buf,6+4*i) = sd->devotion[i];
  5997. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5998. }
  5999. if( tsd )
  6000. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6001. else
  6002. clif_send(buf, packet_len(0x1cf), src, AREA);
  6003. }
  6004. /*==========================================
  6005. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6006. * Notifies clients in an area of an object's spirits.
  6007. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6008. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6009. *------------------------------------------*/
  6010. void clif_spiritball(struct block_list *bl) {
  6011. unsigned char buf[16];
  6012. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6013. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6014. nullpo_retv(bl);
  6015. WBUFW(buf, 0) = 0x1d0;
  6016. WBUFL(buf, 2) = bl->id;
  6017. WBUFW(buf, 6) = 0; //init to 0
  6018. switch(bl->type){
  6019. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6020. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6021. }
  6022. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6023. }
  6024. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6025. /// 01d2 <account id>.L <delay>.L
  6026. void clif_combo_delay(struct block_list *bl,int wait)
  6027. {
  6028. unsigned char buf[32];
  6029. nullpo_retv(bl);
  6030. WBUFW(buf,0)=0x1d2;
  6031. WBUFL(buf,2)=bl->id;
  6032. WBUFL(buf,6)=wait;
  6033. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6034. }
  6035. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6036. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6037. /// flag:
  6038. /// 0 = inactive
  6039. /// 1 = active
  6040. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6041. {
  6042. unsigned char buf[32];
  6043. nullpo_retv(src);
  6044. WBUFW(buf,0)=0x1d1;
  6045. WBUFL(buf,2)=src->id;
  6046. WBUFL(buf,6)=dst_id;
  6047. WBUFL(buf,10)=active;
  6048. clif_send(buf,packet_len(0x1d1),src,AREA);
  6049. }
  6050. /// MVP effect (ZC_MVP).
  6051. /// 010c <account id>.L
  6052. void clif_mvp_effect(struct map_session_data *sd)
  6053. {
  6054. unsigned char buf[16];
  6055. nullpo_retv(sd);
  6056. WBUFW(buf,0)=0x10c;
  6057. WBUFL(buf,2)=sd->bl.id;
  6058. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  6059. }
  6060. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6061. /// 010a <name id>.W
  6062. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6063. {
  6064. int view,fd;
  6065. nullpo_retv(sd);
  6066. fd=sd->fd;
  6067. WFIFOHEAD(fd,packet_len(0x10a));
  6068. WFIFOW(fd,0)=0x10a;
  6069. if((view = itemdb_viewid(nameid)) > 0)
  6070. WFIFOW(fd,2)=view;
  6071. else
  6072. WFIFOW(fd,2)=nameid;
  6073. WFIFOSET(fd,packet_len(0x10a));
  6074. }
  6075. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6076. /// 010b <exp>.L
  6077. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6078. {
  6079. int fd;
  6080. nullpo_retv(sd);
  6081. fd=sd->fd;
  6082. WFIFOHEAD(fd,packet_len(0x10b));
  6083. WFIFOW(fd,0)=0x10b;
  6084. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6085. WFIFOSET(fd,packet_len(0x10b));
  6086. }
  6087. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6088. /// 010d
  6089. ///
  6090. /// "You are the MVP, but cannot obtain the reward because
  6091. /// you are overweight."
  6092. void clif_mvp_noitem(struct map_session_data* sd)
  6093. {
  6094. int fd = sd->fd;
  6095. WFIFOHEAD(fd,packet_len(0x10d));
  6096. WFIFOW(fd,0) = 0x10d;
  6097. WFIFOSET(fd,packet_len(0x10d));
  6098. }
  6099. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6100. /// 0167 <result>.B
  6101. /// result:
  6102. /// 0 = "Guild has been created."
  6103. /// 1 = "You are already in a Guild."
  6104. /// 2 = "That Guild Name already exists."
  6105. /// 3 = "You need the neccessary item to create a Guild."
  6106. void clif_guild_created(struct map_session_data *sd,int flag)
  6107. {
  6108. int fd;
  6109. nullpo_retv(sd);
  6110. fd=sd->fd;
  6111. WFIFOHEAD(fd,packet_len(0x167));
  6112. WFIFOW(fd,0)=0x167;
  6113. WFIFOB(fd,2)=flag;
  6114. WFIFOSET(fd,packet_len(0x167));
  6115. }
  6116. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6117. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6118. /// mode:
  6119. /// &0x01 = allow invite
  6120. /// &0x10 = allow expel
  6121. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6122. {
  6123. int ps,fd;
  6124. nullpo_retv(sd);
  6125. nullpo_retv(g);
  6126. fd=sd->fd;
  6127. ps=guild_getposition(g,sd);
  6128. WFIFOHEAD(fd,packet_len(0x16c));
  6129. WFIFOW(fd,0)=0x16c;
  6130. WFIFOL(fd,2)=g->guild_id;
  6131. WFIFOL(fd,6)=g->emblem_id;
  6132. WFIFOL(fd,10)=g->position[ps].mode;
  6133. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==g);
  6134. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6135. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6136. WFIFOSET(fd,packet_len(0x16c));
  6137. }
  6138. /// Guild member login notice.
  6139. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6140. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6141. /// status:
  6142. /// 0 = offline
  6143. /// 1 = online
  6144. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6145. {
  6146. unsigned char buf[64];
  6147. struct map_session_data* sd;
  6148. nullpo_retv(g);
  6149. WBUFW(buf, 0)=0x1f2;
  6150. WBUFL(buf, 2)=g->member[idx].account_id;
  6151. WBUFL(buf, 6)=g->member[idx].char_id;
  6152. WBUFL(buf,10)=flag;
  6153. if( ( sd = g->member[idx].sd ) != NULL )
  6154. {
  6155. WBUFW(buf,14) = sd->status.sex;
  6156. WBUFW(buf,16) = sd->status.hair;
  6157. WBUFW(buf,18) = sd->status.hair_color;
  6158. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6159. }
  6160. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  6161. {
  6162. WBUFW(buf,14) = 0;
  6163. WBUFW(buf,16) = 0;
  6164. WBUFW(buf,18) = 0;
  6165. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6166. }
  6167. }
  6168. // Function `clif_guild_memberlogin_notice` sends info about
  6169. // logins and logouts of a guild member to the rest members.
  6170. // But at the 1st time (after a player login or map changing)
  6171. // the client won't show the message.
  6172. // So I suggest use this function for sending "first-time-info"
  6173. // to some player on entering the game or changing location.
  6174. // At next time the client would always show the message.
  6175. // The function sends all the statuses in the single packet
  6176. // to economize traffic. [LuzZza]
  6177. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6178. {
  6179. struct guild *g;
  6180. unsigned char buf[14*128];
  6181. int i, count=0, p_len;
  6182. nullpo_retv(sd);
  6183. p_len = packet_len(0x16d);
  6184. if(!(g = sd->guild))
  6185. return;
  6186. for(i=0; i<g->max_member; i++) {
  6187. if(g->member[i].account_id > 0 &&
  6188. g->member[i].account_id != sd->status.account_id) {
  6189. WBUFW(buf,count*p_len) = 0x16d;
  6190. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6191. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6192. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6193. count++;
  6194. }
  6195. }
  6196. clif_send(buf, p_len*count, &sd->bl, SELF);
  6197. }
  6198. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6199. /// 014e <menu flag>.L
  6200. /// menu flag:
  6201. /// 0x00 = Basic Info (always on)
  6202. /// &0x01 = Member manager
  6203. /// &0x02 = Positions
  6204. /// &0x04 = Skills
  6205. /// &0x10 = Expulsion list
  6206. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6207. /// &0x80 = Notice
  6208. void clif_guild_masterormember(struct map_session_data *sd)
  6209. {
  6210. int fd;
  6211. nullpo_retv(sd);
  6212. fd=sd->fd;
  6213. WFIFOHEAD(fd,packet_len(0x14e));
  6214. WFIFOW(fd,0) = 0x14e;
  6215. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6216. WFIFOSET(fd,packet_len(0x14e));
  6217. }
  6218. /// Guild basic information (Territories [Valaris])
  6219. /// 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)
  6220. /// 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)
  6221. void clif_guild_basicinfo(struct map_session_data *sd) {
  6222. int fd;
  6223. struct guild *g;
  6224. nullpo_retv(sd);
  6225. fd = sd->fd;
  6226. if( (g = sd->guild) == NULL )
  6227. return;
  6228. WFIFOHEAD(fd,packet_len(0x1b6));
  6229. WFIFOW(fd, 0)=0x1b6;//0x150;
  6230. WFIFOL(fd, 2)=g->guild_id;
  6231. WFIFOL(fd, 6)=g->guild_lv;
  6232. WFIFOL(fd,10)=g->connect_member;
  6233. WFIFOL(fd,14)=g->max_member;
  6234. WFIFOL(fd,18)=g->average_lv;
  6235. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6236. WFIFOL(fd,26)=g->next_exp;
  6237. WFIFOL(fd,30)=0; // Tax Points
  6238. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6239. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6240. WFIFOL(fd,42)=g->emblem_id;
  6241. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6242. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6243. safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  6244. WFIFOL(fd,110) = 0; // zeny
  6245. WFIFOSET(fd,packet_len(0x1b6));
  6246. }
  6247. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6248. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6249. void clif_guild_allianceinfo(struct map_session_data *sd)
  6250. {
  6251. int fd,i,c;
  6252. struct guild *g;
  6253. nullpo_retv(sd);
  6254. if( (g = sd->guild) == NULL )
  6255. return;
  6256. fd = sd->fd;
  6257. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6258. WFIFOW(fd, 0)=0x14c;
  6259. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6260. struct guild_alliance *a=&g->alliance[i];
  6261. if(a->guild_id>0){
  6262. WFIFOL(fd,c*32+4)=a->opposition;
  6263. WFIFOL(fd,c*32+8)=a->guild_id;
  6264. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6265. c++;
  6266. }
  6267. }
  6268. WFIFOW(fd, 2)=c*32+4;
  6269. WFIFOSET(fd,WFIFOW(fd,2));
  6270. }
  6271. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6272. /// 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 }*
  6273. /// state:
  6274. /// 0 = offline
  6275. /// 1 = online
  6276. /// memo:
  6277. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6278. void clif_guild_memberlist(struct map_session_data *sd)
  6279. {
  6280. int fd;
  6281. int i,c;
  6282. struct guild *g;
  6283. nullpo_retv(sd);
  6284. if( (fd = sd->fd) == 0 )
  6285. return;
  6286. if( (g = sd->guild) == NULL )
  6287. return;
  6288. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6289. WFIFOW(fd, 0)=0x154;
  6290. for(i=0,c=0;i<g->max_member;i++){
  6291. struct guild_member *m=&g->member[i];
  6292. if(m->account_id==0)
  6293. continue;
  6294. WFIFOL(fd,c*104+ 4)=m->account_id;
  6295. WFIFOL(fd,c*104+ 8)=m->char_id;
  6296. WFIFOW(fd,c*104+12)=m->hair;
  6297. WFIFOW(fd,c*104+14)=m->hair_color;
  6298. WFIFOW(fd,c*104+16)=m->gender;
  6299. WFIFOW(fd,c*104+18)=m->class_;
  6300. WFIFOW(fd,c*104+20)=m->lv;
  6301. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6302. WFIFOL(fd,c*104+26)=m->online;
  6303. WFIFOL(fd,c*104+30)=m->position;
  6304. 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.
  6305. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6306. c++;
  6307. }
  6308. WFIFOW(fd, 2)=c*104+4;
  6309. WFIFOSET(fd,WFIFOW(fd,2));
  6310. }
  6311. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6312. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6313. void clif_guild_positionnamelist(struct map_session_data *sd)
  6314. {
  6315. int i,fd;
  6316. struct guild *g;
  6317. nullpo_retv(sd);
  6318. if( (g = sd->guild) == NULL )
  6319. return;
  6320. fd = sd->fd;
  6321. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6322. WFIFOW(fd, 0)=0x166;
  6323. for(i=0;i<MAX_GUILDPOSITION;i++){
  6324. WFIFOL(fd,i*28+4)=i;
  6325. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6326. }
  6327. WFIFOW(fd,2)=i*28+4;
  6328. WFIFOSET(fd,WFIFOW(fd,2));
  6329. }
  6330. /// Guild position information (ZC_POSITION_INFO).
  6331. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6332. /// mode:
  6333. /// &0x01 = allow invite
  6334. /// &0x10 = allow expel
  6335. /// ranking:
  6336. /// TODO
  6337. void clif_guild_positioninfolist(struct map_session_data *sd)
  6338. {
  6339. int i,fd;
  6340. struct guild *g;
  6341. nullpo_retv(sd);
  6342. if( (g = sd->guild) == NULL )
  6343. return;
  6344. fd = sd->fd;
  6345. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6346. WFIFOW(fd, 0)=0x160;
  6347. for(i=0;i<MAX_GUILDPOSITION;i++){
  6348. struct guild_position *p=&g->position[i];
  6349. WFIFOL(fd,i*16+ 4)=i;
  6350. WFIFOL(fd,i*16+ 8)=p->mode;
  6351. WFIFOL(fd,i*16+12)=i;
  6352. WFIFOL(fd,i*16+16)=p->exp_mode;
  6353. }
  6354. WFIFOW(fd, 2)=i*16+4;
  6355. WFIFOSET(fd,WFIFOW(fd,2));
  6356. }
  6357. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6358. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6359. /// mode:
  6360. /// &0x01 = allow invite
  6361. /// &0x10 = allow expel
  6362. /// ranking:
  6363. /// TODO
  6364. void clif_guild_positionchanged(struct guild *g,int idx)
  6365. {
  6366. // FIXME: This packet is intended to update the clients after a
  6367. // commit of position info changes, not sending one packet per
  6368. // position.
  6369. struct map_session_data *sd;
  6370. unsigned char buf[128];
  6371. nullpo_retv(g);
  6372. WBUFW(buf, 0)=0x174;
  6373. WBUFW(buf, 2)=44; // packet len
  6374. // GUILD_REG_POSITION_INFO{
  6375. WBUFL(buf, 4)=idx;
  6376. WBUFL(buf, 8)=g->position[idx].mode;
  6377. WBUFL(buf,12)=idx;
  6378. WBUFL(buf,16)=g->position[idx].exp_mode;
  6379. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6380. // }*
  6381. if( (sd=guild_getavailablesd(g))!=NULL )
  6382. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6383. }
  6384. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6385. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6386. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6387. {
  6388. // FIXME: This packet is intended to update the clients after a
  6389. // commit of member position assignment changes, not sending one
  6390. // packet per position.
  6391. struct map_session_data *sd;
  6392. unsigned char buf[64];
  6393. nullpo_retv(g);
  6394. WBUFW(buf, 0)=0x156;
  6395. WBUFW(buf, 2)=16; // packet len
  6396. // MEMBER_POSITION_INFO{
  6397. WBUFL(buf, 4)=g->member[idx].account_id;
  6398. WBUFL(buf, 8)=g->member[idx].char_id;
  6399. WBUFL(buf,12)=g->member[idx].position;
  6400. // }*
  6401. if( (sd=guild_getavailablesd(g))!=NULL )
  6402. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6403. }
  6404. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6405. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6406. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6407. {
  6408. int fd;
  6409. nullpo_retv(sd);
  6410. nullpo_retv(g);
  6411. fd = sd->fd;
  6412. if( g->emblem_len <= 0 )
  6413. return;
  6414. WFIFOHEAD(fd,g->emblem_len+12);
  6415. WFIFOW(fd,0)=0x152;
  6416. WFIFOW(fd,2)=g->emblem_len+12;
  6417. WFIFOL(fd,4)=g->guild_id;
  6418. WFIFOL(fd,8)=g->emblem_id;
  6419. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6420. WFIFOSET(fd,WFIFOW(fd,2));
  6421. }
  6422. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6423. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6424. void clif_guild_emblem_area(struct block_list* bl)
  6425. {
  6426. uint8 buf[12];
  6427. nullpo_retv(bl);
  6428. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6429. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6430. WBUFW(buf,0) = 0x1b4;
  6431. WBUFL(buf,2) = bl->id;
  6432. WBUFL(buf,6) = status_get_guild_id(bl);
  6433. WBUFW(buf,10) = status_get_emblem_id(bl);
  6434. clif_send(buf, 12, bl, AREA_WOS);
  6435. }
  6436. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6437. /// 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 }*
  6438. void clif_guild_skillinfo(struct map_session_data* sd)
  6439. {
  6440. int fd;
  6441. struct guild* g;
  6442. int i,c;
  6443. nullpo_retv(sd);
  6444. if( (g = sd->guild) == NULL )
  6445. return;
  6446. fd = sd->fd;
  6447. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6448. WFIFOW(fd,0) = 0x0162;
  6449. WFIFOW(fd,4) = g->skill_point;
  6450. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6451. {
  6452. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6453. {
  6454. int id = g->skill[i].id;
  6455. int p = 6 + c*37;
  6456. WFIFOW(fd,p+0) = id;
  6457. WFIFOL(fd,p+2) = skill_get_inf(id);
  6458. WFIFOW(fd,p+6) = g->skill[i].lv;
  6459. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6460. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6461. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6462. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6463. c++;
  6464. }
  6465. }
  6466. WFIFOW(fd,2) = 6 + c*37;
  6467. WFIFOSET(fd,WFIFOW(fd,2));
  6468. }
  6469. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6470. /// 016f <subject>.60B <notice>.120B
  6471. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6472. {
  6473. int fd;
  6474. nullpo_retv(sd);
  6475. nullpo_retv(g);
  6476. fd = sd->fd;
  6477. if ( !session_isActive(fd) )
  6478. return;
  6479. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6480. return;
  6481. WFIFOHEAD(fd,packet_len(0x16f));
  6482. WFIFOW(fd,0) = 0x16f;
  6483. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6484. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6485. WFIFOSET(fd,packet_len(0x16f));
  6486. }
  6487. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6488. /// 016a <guild id>.L <guild name>.24B
  6489. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6490. {
  6491. int fd;
  6492. nullpo_retv(sd);
  6493. nullpo_retv(g);
  6494. fd=sd->fd;
  6495. WFIFOHEAD(fd,packet_len(0x16a));
  6496. WFIFOW(fd,0)=0x16a;
  6497. WFIFOL(fd,2)=g->guild_id;
  6498. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6499. WFIFOSET(fd,packet_len(0x16a));
  6500. }
  6501. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6502. /// 0169 <answer>.B
  6503. /// answer:
  6504. /// 0 = Already in guild.
  6505. /// 1 = Offer rejected.
  6506. /// 2 = Offer accepted.
  6507. /// 3 = Guild full.
  6508. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6509. {
  6510. int fd;
  6511. nullpo_retv(sd);
  6512. fd=sd->fd;
  6513. WFIFOHEAD(fd,packet_len(0x169));
  6514. WFIFOW(fd,0)=0x169;
  6515. WFIFOB(fd,2)=flag;
  6516. WFIFOSET(fd,packet_len(0x169));
  6517. }
  6518. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6519. /// 015a <char name>.24B <reason>.40B
  6520. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6521. {
  6522. unsigned char buf[128];
  6523. nullpo_retv(sd);
  6524. WBUFW(buf, 0)=0x15a;
  6525. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6526. memcpy(WBUFP(buf,26),mes,40);
  6527. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6528. }
  6529. /// Notifies clients of a guild of an expelled member.
  6530. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6531. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6532. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6533. {
  6534. unsigned char buf[128];
  6535. #if PACKETVER < 20100803
  6536. const unsigned short cmd = 0x15c;
  6537. #else
  6538. const unsigned short cmd = 0x839;
  6539. #endif
  6540. nullpo_retv(sd);
  6541. WBUFW(buf,0) = cmd;
  6542. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6543. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6544. #if PACKETVER < 20100803
  6545. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6546. #endif
  6547. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6548. }
  6549. /// Guild expulsion list (ZC_BAN_LIST).
  6550. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6551. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6552. void clif_guild_expulsionlist(struct map_session_data* sd)
  6553. {
  6554. #if PACKETVER < 20100803
  6555. const int offset = NAME_LENGTH*2+40;
  6556. #else
  6557. const int offset = NAME_LENGTH+40;
  6558. #endif
  6559. int fd, i, c = 0;
  6560. struct guild* g;
  6561. nullpo_retv(sd);
  6562. if( (g = sd->guild) == NULL )
  6563. return;
  6564. fd = sd->fd;
  6565. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6566. WFIFOW(fd,0) = 0x163;
  6567. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6568. {
  6569. struct guild_expulsion* e = &g->expulsion[i];
  6570. if( e->account_id > 0 )
  6571. {
  6572. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6573. #if PACKETVER < 20100803
  6574. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6575. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6576. #else
  6577. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6578. #endif
  6579. c++;
  6580. }
  6581. }
  6582. WFIFOW(fd,2) = 4 + c*offset;
  6583. WFIFOSET(fd,WFIFOW(fd,2));
  6584. }
  6585. /// Guild chat message (ZC_GUILD_CHAT).
  6586. /// 017f <packet len>.W <message>.?B
  6587. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6588. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6589. struct map_session_data *sd;
  6590. uint8 buf[256];
  6591. if( len == 0 )
  6592. {
  6593. return;
  6594. }
  6595. else if( len > sizeof(buf)-5 )
  6596. {
  6597. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6598. len = sizeof(buf)-5;
  6599. }
  6600. WBUFW(buf, 0) = 0x17f;
  6601. WBUFW(buf, 2) = len + 5;
  6602. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6603. if ((sd = guild_getavailablesd(g)) != NULL)
  6604. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6605. }
  6606. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6607. /// 0171 <inviter account id>.L <guild name>.24B
  6608. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6609. {
  6610. int fd;
  6611. nullpo_retv(sd);
  6612. fd=sd->fd;
  6613. WFIFOHEAD(fd,packet_len(0x171));
  6614. WFIFOW(fd,0)=0x171;
  6615. WFIFOL(fd,2)=account_id;
  6616. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6617. WFIFOSET(fd,packet_len(0x171));
  6618. }
  6619. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6620. /// 0173 <answer>.B
  6621. /// answer:
  6622. /// 0 = Already allied.
  6623. /// 1 = You rejected the offer.
  6624. /// 2 = You accepted the offer.
  6625. /// 3 = They have too any alliances.
  6626. /// 4 = You have too many alliances.
  6627. /// 5 = Alliances are disabled.
  6628. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6629. {
  6630. int fd;
  6631. nullpo_retv(sd);
  6632. fd=sd->fd;
  6633. WFIFOHEAD(fd,packet_len(0x173));
  6634. WFIFOW(fd,0)=0x173;
  6635. WFIFOL(fd,2)=flag;
  6636. WFIFOSET(fd,packet_len(0x173));
  6637. }
  6638. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6639. /// 0184 <other guild id>.L <relation>.L
  6640. /// relation:
  6641. /// 0 = Ally
  6642. /// 1 = Enemy
  6643. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6644. {
  6645. int fd;
  6646. nullpo_retv(sd);
  6647. fd = sd->fd;
  6648. if (fd <= 0)
  6649. return;
  6650. WFIFOHEAD(fd,packet_len(0x184));
  6651. WFIFOW(fd,0)=0x184;
  6652. WFIFOL(fd,2)=guild_id;
  6653. WFIFOL(fd,6)=flag;
  6654. WFIFOSET(fd,packet_len(0x184));
  6655. }
  6656. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6657. /// 0181 <result>.B
  6658. /// result:
  6659. /// 0 = Antagonist has been set.
  6660. /// 1 = Guild has too many Antagonists.
  6661. /// 2 = Already set as an Antagonist.
  6662. /// 3 = Antagonists are disabled.
  6663. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6664. {
  6665. int fd;
  6666. nullpo_retv(sd);
  6667. fd=sd->fd;
  6668. WFIFOHEAD(fd,packet_len(0x181));
  6669. WFIFOW(fd,0)=0x181;
  6670. WFIFOB(fd,2)=flag;
  6671. WFIFOSET(fd,packet_len(0x181));
  6672. }
  6673. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6674. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6675. /*
  6676. void clif_guild_allianceadded(struct guild *g,int idx)
  6677. {
  6678. unsigned char buf[64];
  6679. WBUFW(buf,0)=0x185;
  6680. WBUFL(buf,2)=g->alliance[idx].opposition;
  6681. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6682. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6683. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6684. }
  6685. */
  6686. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6687. /// 015e <reason>.L
  6688. /// 0 = success
  6689. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6690. /// 2 = there are still members in the guild
  6691. void clif_guild_broken(struct map_session_data *sd,int flag)
  6692. {
  6693. int fd;
  6694. nullpo_retv(sd);
  6695. fd=sd->fd;
  6696. WFIFOHEAD(fd,packet_len(0x15e));
  6697. WFIFOW(fd,0)=0x15e;
  6698. WFIFOL(fd,2)=flag;
  6699. WFIFOSET(fd,packet_len(0x15e));
  6700. }
  6701. /// Displays emotion on an object (ZC_EMOTION).
  6702. /// 00c0 <id>.L <type>.B
  6703. /// type:
  6704. /// enum emotion_type
  6705. void clif_emotion(struct block_list *bl,int type)
  6706. {
  6707. unsigned char buf[8];
  6708. nullpo_retv(bl);
  6709. WBUFW(buf,0)=0xc0;
  6710. WBUFL(buf,2)=bl->id;
  6711. WBUFB(buf,6)=type;
  6712. clif_send(buf,packet_len(0xc0),bl,AREA);
  6713. }
  6714. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6715. /// 0191 <id>.L <contents>.80B
  6716. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6717. {
  6718. unsigned char buf[MESSAGE_SIZE+6];
  6719. nullpo_retv(bl);
  6720. WBUFW(buf,0) = 0x191;
  6721. WBUFL(buf,2) = bl->id;
  6722. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6723. clif_send(buf,packet_len(0x191),bl,AREA);
  6724. }
  6725. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6726. /// 01ea <id>.L
  6727. void clif_wedding_effect(struct block_list *bl)
  6728. {
  6729. unsigned char buf[6];
  6730. nullpo_retv(bl);
  6731. WBUFW(buf,0) = 0x1ea;
  6732. WBUFL(buf,2) = bl->id;
  6733. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6734. }
  6735. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6736. /// 01e6 <partner name>.24B
  6737. void clif_callpartner(struct map_session_data *sd)
  6738. {
  6739. unsigned char buf[26];
  6740. nullpo_retv(sd);
  6741. WBUFW(buf,0) = 0x1e6;
  6742. if( sd->status.partner_id )
  6743. {
  6744. const char *p;
  6745. if( ( p = map_charid2nick(sd->status.partner_id) ) != NULL )
  6746. {
  6747. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  6748. }
  6749. else
  6750. {
  6751. WBUFB(buf,2) = 0;
  6752. }
  6753. }
  6754. else
  6755. {// Send zero-length name if no partner, to initialize the client buffer.
  6756. WBUFB(buf,2) = 0;
  6757. }
  6758. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  6759. }
  6760. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6761. /// 01e4
  6762. /// This packet while still implemented by the client is no longer being officially used.
  6763. /*
  6764. void clif_marriage_process(struct map_session_data *sd)
  6765. {
  6766. int fd;
  6767. nullpo_retv(sd);
  6768. fd=sd->fd;
  6769. WFIFOHEAD(fd,packet_len(0x1e4));
  6770. WFIFOW(fd,0)=0x1e4;
  6771. WFIFOSET(fd,packet_len(0x1e4));
  6772. }
  6773. */
  6774. /// Notice of divorce (ZC_DIVORCE).
  6775. /// 0205 <partner name>.24B
  6776. void clif_divorced(struct map_session_data* sd, const char* name)
  6777. {
  6778. int fd;
  6779. nullpo_retv(sd);
  6780. fd=sd->fd;
  6781. WFIFOHEAD(fd,packet_len(0x205));
  6782. WFIFOW(fd,0)=0x205;
  6783. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6784. WFIFOSET(fd, packet_len(0x205));
  6785. }
  6786. /// Marriage proposal (ZC_REQ_COUPLE).
  6787. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6788. /// This packet while still implemented by the client is no longer being officially used.
  6789. /*
  6790. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6791. {
  6792. nullpo_retv(sd);
  6793. WFIFOHEAD(fd,packet_len(0x1e2));
  6794. WFIFOW(fd,0) = 0x1e2;
  6795. WFIFOL(fd,2) = ssd->status.account_id;
  6796. WFIFOL(fd,6) = ssd->status.char_id;
  6797. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6798. WFIFOSET(fd, packet_len(0x1e2));
  6799. }
  6800. */
  6801. /*==========================================
  6802. *
  6803. *------------------------------------------*/
  6804. void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6805. {
  6806. clif_disp_message(&sd->bl, mes, len, SELF);
  6807. }
  6808. /*==========================================
  6809. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6810. *------------------------------------------*/
  6811. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6812. {
  6813. unsigned char buf[256];
  6814. if( len == 0 ) {
  6815. return;
  6816. } else if( len > sizeof(buf)-5 ) {
  6817. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6818. len = sizeof(buf)-5;
  6819. }
  6820. WBUFW(buf, 0) = 0x17f;
  6821. WBUFW(buf, 2) = len + 5;
  6822. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6823. clif_send(buf, WBUFW(buf,2), src, target);
  6824. }
  6825. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6826. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6827. /// 00cd <result>.B
  6828. /// result:
  6829. /// 0 = failure
  6830. /// 1 = success
  6831. void clif_GM_kickack(struct map_session_data *sd, int id)
  6832. {
  6833. int fd;
  6834. nullpo_retv(sd);
  6835. fd = sd->fd;
  6836. WFIFOHEAD(fd,packet_len(0xcd));
  6837. WFIFOW(fd,0) = 0xcd;
  6838. WFIFOB(fd,2) = id; // FIXME: this is not account id
  6839. WFIFOSET(fd, packet_len(0xcd));
  6840. }
  6841. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6842. {
  6843. int fd = tsd->fd;
  6844. if( fd > 0 )
  6845. clif_authfail_fd(fd, 15);
  6846. else
  6847. map_quit(tsd);
  6848. if( sd )
  6849. clif_GM_kickack(sd,tsd->status.account_id);
  6850. }
  6851. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6852. /// 014a <result>.L
  6853. /// result:
  6854. /// 0 = "A manner point has been successfully aligned."
  6855. /// 1 = MP_FAILURE_EXHAUST
  6856. /// 2 = MP_FAILURE_ALREADY_GIVING
  6857. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6858. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6859. /// 5 = "You got a good point from %s."
  6860. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6861. {
  6862. int fd;
  6863. nullpo_retv(sd);
  6864. fd = sd->fd;
  6865. WFIFOHEAD(fd,packet_len(0x14a));
  6866. WFIFOW(fd,0) = 0x14a;
  6867. WFIFOL(fd,2) = type;
  6868. WFIFOSET(fd, packet_len(0x14a));
  6869. }
  6870. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  6871. /// 014b <type>.B <GM name>.24B
  6872. /// type:
  6873. /// 0 = positive (unmute)
  6874. /// 1 = negative (mute)
  6875. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6876. {
  6877. int fd;
  6878. nullpo_retv(sd);
  6879. nullpo_retv(tsd);
  6880. fd = tsd->fd;
  6881. WFIFOHEAD(fd,packet_len(0x14b));
  6882. WFIFOW(fd,0) = 0x14b;
  6883. WFIFOB(fd,2) = type;
  6884. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6885. WFIFOSET(fd, packet_len(0x14b));
  6886. }
  6887. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  6888. /// 00d1 <type>.B <result>.B
  6889. /// type:
  6890. /// 0 = /ex (deny)
  6891. /// 1 = /in (allow)
  6892. /// result:
  6893. /// 0 = success
  6894. /// 1 = failure
  6895. /// 2 = too many blocks
  6896. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  6897. {
  6898. int fd;
  6899. nullpo_retv(sd);
  6900. fd=sd->fd;
  6901. WFIFOHEAD(fd,packet_len(0xd1));
  6902. WFIFOW(fd,0)=0xd1;
  6903. WFIFOB(fd,2)=type;
  6904. WFIFOB(fd,3)=flag;
  6905. WFIFOSET(fd,packet_len(0xd1));
  6906. }
  6907. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  6908. /// 00d2 <type>.B <result>.B
  6909. /// type:
  6910. /// 0 = /exall (deny)
  6911. /// 1 = /inall (allow)
  6912. /// result:
  6913. /// 0 = success
  6914. /// 1 = failure
  6915. void clif_wisall(struct map_session_data *sd,int type,int flag)
  6916. {
  6917. int fd;
  6918. nullpo_retv(sd);
  6919. fd=sd->fd;
  6920. WFIFOHEAD(fd,packet_len(0xd2));
  6921. WFIFOW(fd,0)=0xd2;
  6922. WFIFOB(fd,2)=type;
  6923. WFIFOB(fd,3)=flag;
  6924. WFIFOSET(fd,packet_len(0xd2));
  6925. }
  6926. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  6927. /// 07fe <bgm>.24B
  6928. void clif_playBGM(struct map_session_data* sd, const char* name)
  6929. {
  6930. int fd;
  6931. nullpo_retv(sd);
  6932. fd = sd->fd;
  6933. WFIFOHEAD(fd,packet_len(0x7fe));
  6934. WFIFOW(fd,0) = 0x7fe;
  6935. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6936. WFIFOSET(fd,packet_len(0x7fe));
  6937. }
  6938. /// Plays/stops a wave sound (ZC_SOUND).
  6939. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  6940. /// file name:
  6941. /// relative to data\wav
  6942. /// act:
  6943. /// 0 = play (once)
  6944. /// 1 = play (repeat, does not work)
  6945. /// 2 = stops all sound instances of file name (does not work)
  6946. /// term:
  6947. /// unknown purpose, only relevant to act = 1
  6948. /// npc id:
  6949. /// The accustic direction of the sound is determined by the
  6950. /// relative position of the NPC to the player (3D sound).
  6951. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6952. {
  6953. int fd;
  6954. nullpo_retv(sd);
  6955. nullpo_retv(bl);
  6956. fd = sd->fd;
  6957. WFIFOHEAD(fd,packet_len(0x1d3));
  6958. WFIFOW(fd,0) = 0x1d3;
  6959. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6960. WFIFOB(fd,26) = type;
  6961. WFIFOL(fd,27) = 0;
  6962. WFIFOL(fd,31) = bl->id;
  6963. WFIFOSET(fd,packet_len(0x1d3));
  6964. }
  6965. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6966. {
  6967. unsigned char buf[40];
  6968. nullpo_retv(bl);
  6969. WBUFW(buf,0) = 0x1d3;
  6970. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6971. WBUFB(buf,26) = type;
  6972. WBUFL(buf,27) = 0;
  6973. WBUFL(buf,31) = bl->id;
  6974. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6975. }
  6976. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  6977. /// 01f3 <id>.L <effect id>.L
  6978. /// effect id:
  6979. /// @see doc/effect_list.txt
  6980. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6981. {
  6982. unsigned char buf[24];
  6983. nullpo_retv(bl);
  6984. memset(buf, 0, packet_len(0x1f3));
  6985. WBUFW(buf,0) = 0x1f3;
  6986. WBUFL(buf,2) = bl->id;
  6987. WBUFL(buf,6) = type;
  6988. clif_send(buf, packet_len(0x1f3), bl, target);
  6989. if (disguised(bl)) {
  6990. WBUFL(buf,2) = -bl->id;
  6991. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6992. }
  6993. }
  6994. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6995. {
  6996. WFIFOHEAD(fd,10);
  6997. WFIFOW(fd,0) = 0x1f3;
  6998. WFIFOL(fd,2) = bl->id;
  6999. WFIFOL(fd,6) = type;
  7000. WFIFOSET(fd,10);
  7001. }
  7002. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7003. /// 0284 <id>.L <effect id>.L <num data>.L
  7004. /// effect id:
  7005. /// @see doc/effect_list.txt
  7006. /// num data:
  7007. /// effect-dependent value
  7008. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7009. {
  7010. uint8 buf[14];
  7011. WBUFW(buf,0) = 0x284;
  7012. WBUFL(buf,2) = bl->id;
  7013. WBUFL(buf,6) = effect_id;
  7014. WBUFL(buf,10) = num;
  7015. clif_send(buf, packet_len(0x284), bl, target);
  7016. if( disguised(bl) )
  7017. {
  7018. WBUFL(buf,2) = -bl->id;
  7019. clif_send(buf, packet_len(0x284), bl, SELF);
  7020. }
  7021. }
  7022. // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead)
  7023. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7024. int clif_colormes(struct map_session_data * sd, enum clif_colors color, const char* msg) {
  7025. unsigned short msg_len = strlen(msg) + 1;
  7026. WFIFOHEAD(sd->fd,msg_len + 12);
  7027. WFIFOW(sd->fd,0) = 0x2C1;
  7028. WFIFOW(sd->fd,2) = msg_len + 12;
  7029. WFIFOL(sd->fd,4) = 0;
  7030. WFIFOL(sd->fd,8) = color_table[color];
  7031. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7032. WFIFOSET(sd->fd, msg_len + 12);
  7033. return 0;
  7034. }
  7035. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7036. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7037. void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) {
  7038. unsigned short msg_len = strlen(msg) + 1;
  7039. uint8 buf[256];
  7040. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  7041. nullpo_retv(bl);
  7042. if( msg_len > sizeof(buf)-12 ) {
  7043. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  7044. msg_len = sizeof(buf)-12;
  7045. }
  7046. WBUFW(buf,0) = 0x2C1;
  7047. WBUFW(buf,2) = msg_len + 12;
  7048. WBUFL(buf,4) = bl->id;
  7049. WBUFL(buf,8) = color;
  7050. memcpy(WBUFP(buf,12), msg, msg_len);
  7051. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7052. }
  7053. // refresh the client's screen, getting rid of any effects
  7054. void clif_refresh(struct map_session_data *sd)
  7055. {
  7056. int i;
  7057. nullpo_retv(sd);
  7058. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7059. clif_inventorylist(sd);
  7060. if(pc_iscarton(sd)) {
  7061. clif_cartlist(sd);
  7062. clif_updatestatus(sd,SP_CARTINFO);
  7063. }
  7064. clif_updatestatus(sd,SP_WEIGHT);
  7065. clif_updatestatus(sd,SP_MAXWEIGHT);
  7066. clif_updatestatus(sd,SP_STR);
  7067. clif_updatestatus(sd,SP_AGI);
  7068. clif_updatestatus(sd,SP_VIT);
  7069. clif_updatestatus(sd,SP_INT);
  7070. clif_updatestatus(sd,SP_DEX);
  7071. clif_updatestatus(sd,SP_LUK);
  7072. if (sd->spiritball)
  7073. clif_spiritball_single(sd->fd, sd);
  7074. for(i = 1; i < 5; i++){
  7075. if( sd->talisman[i] > 0 )
  7076. clif_talisman_single(sd->fd, sd, i);
  7077. }
  7078. if (sd->vd.cloth_color)
  7079. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7080. if(merc_is_hom_active(sd->hd))
  7081. clif_send_homdata(sd,SP_ACK,0);
  7082. if( sd->md ) {
  7083. clif_mercenary_info(sd);
  7084. clif_mercenary_skillblock(sd);
  7085. }
  7086. if( sd->ed )
  7087. clif_elemental_info(sd);
  7088. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7089. clif_weather_check(sd);
  7090. if( sd->chatID )
  7091. chat_leavechat(sd,0);
  7092. if( sd->state.vending )
  7093. clif_openvending(sd, sd->bl.id, sd->vending);
  7094. if( pc_issit(sd) )
  7095. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  7096. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7097. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7098. else
  7099. clif_changed_dir(&sd->bl, SELF);
  7100. // unlike vending, resuming buyingstore crashes the client.
  7101. buyingstore_close(sd);
  7102. mail_clear(sd);
  7103. if( disguised(&sd->bl) ) {/* refresh-da */
  7104. short disguise = sd->disguise;
  7105. pc_disguise(sd, 0);
  7106. pc_disguise(sd, disguise);
  7107. }
  7108. }
  7109. /// Updates the object's (bl) name on client.
  7110. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7111. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7112. void clif_charnameack (int fd, struct block_list *bl)
  7113. {
  7114. unsigned char buf[103];
  7115. int cmd = 0x95, i, ps = -1;
  7116. nullpo_retv(bl);
  7117. WBUFW(buf,0) = cmd;
  7118. WBUFL(buf,2) = bl->id;
  7119. switch( bl->type )
  7120. {
  7121. case BL_PC:
  7122. {
  7123. struct map_session_data *ssd = (struct map_session_data *)bl;
  7124. struct party_data *p = NULL;
  7125. struct guild *g = NULL;
  7126. //Requesting your own "shadow" name. [Skotlex]
  7127. if (ssd->fd == fd && ssd->disguise)
  7128. WBUFL(buf,2) = -bl->id;
  7129. if( ssd->fakename[0] ) {
  7130. WBUFW(buf, 0) = cmd = 0x195;
  7131. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7132. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7133. break;
  7134. }
  7135. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7136. if( ssd->status.party_id ) {
  7137. p = party_search(ssd->status.party_id);
  7138. }
  7139. if( ssd->status.guild_id ) {
  7140. if( ( g = ssd->guild ) != NULL ) {
  7141. 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);
  7142. if( i < g->max_member ) ps = g->member[i].position;
  7143. }
  7144. }
  7145. if( !battle_config.display_party_name && g == NULL ) {// do not display party unless the player is also in a guild
  7146. p = NULL;
  7147. }
  7148. if (p == NULL && g == NULL)
  7149. break;
  7150. WBUFW(buf, 0) = cmd = 0x195;
  7151. if (p)
  7152. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7153. else
  7154. WBUFB(buf,30) = 0;
  7155. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  7156. {
  7157. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7158. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7159. } else { //Assume no guild.
  7160. WBUFB(buf,54) = 0;
  7161. WBUFB(buf,78) = 0;
  7162. }
  7163. }
  7164. break;
  7165. //[blackhole89]
  7166. case BL_HOM:
  7167. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  7168. break;
  7169. case BL_MER:
  7170. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  7171. break;
  7172. case BL_PET:
  7173. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  7174. break;
  7175. case BL_NPC:
  7176. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  7177. break;
  7178. case BL_MOB:
  7179. {
  7180. struct mob_data *md = (struct mob_data *)bl;
  7181. nullpo_retv(md);
  7182. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7183. if( md->guardian_data && md->guardian_data->guild_id )
  7184. {
  7185. WBUFW(buf, 0) = cmd = 0x195;
  7186. WBUFB(buf,30) = 0;
  7187. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7188. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7189. }
  7190. else if( battle_config.show_mob_info )
  7191. {
  7192. char mobhp[50], *str_p = mobhp;
  7193. WBUFW(buf, 0) = cmd = 0x195;
  7194. if( battle_config.show_mob_info&4 )
  7195. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7196. if( battle_config.show_mob_info&1 )
  7197. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7198. if( battle_config.show_mob_info&2 )
  7199. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7200. //Even thought mobhp ain't a name, we send it as one so the client
  7201. //can parse it. [Skotlex]
  7202. if( str_p != mobhp )
  7203. {
  7204. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7205. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7206. WBUFB(buf,54) = 0;
  7207. WBUFB(buf,78) = 0;
  7208. }
  7209. }
  7210. }
  7211. break;
  7212. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7213. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7214. // break;
  7215. return;
  7216. case BL_ELEM:
  7217. memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  7218. break;
  7219. default:
  7220. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7221. return;
  7222. }
  7223. // if no receipient specified just update nearby clients
  7224. if (fd == 0)
  7225. clif_send(buf, packet_len(cmd), bl, AREA);
  7226. else {
  7227. WFIFOHEAD(fd, packet_len(cmd));
  7228. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7229. WFIFOSET(fd, packet_len(cmd));
  7230. }
  7231. }
  7232. //Used to update when a char leaves a party/guild. [Skotlex]
  7233. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7234. void clif_charnameupdate (struct map_session_data *ssd)
  7235. {
  7236. unsigned char buf[103];
  7237. int cmd = 0x195, ps = -1;
  7238. struct party_data *p = NULL;
  7239. struct guild *g = NULL;
  7240. nullpo_retv(ssd);
  7241. if( ssd->fakename[0] )
  7242. return; //No need to update as the party/guild was not displayed anyway.
  7243. WBUFW(buf,0) = cmd;
  7244. WBUFL(buf,2) = ssd->bl.id;
  7245. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7246. if (!battle_config.display_party_name) {
  7247. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7248. p = party_search(ssd->status.party_id);
  7249. }else{
  7250. if (ssd->status.party_id > 0)
  7251. p = party_search(ssd->status.party_id);
  7252. }
  7253. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7254. {
  7255. int i;
  7256. 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);
  7257. if( i < g->max_member ) ps = g->member[i].position;
  7258. }
  7259. if( p )
  7260. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7261. else
  7262. WBUFB(buf,30) = 0;
  7263. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7264. {
  7265. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7266. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7267. }
  7268. else
  7269. {
  7270. WBUFB(buf,54) = 0;
  7271. WBUFB(buf,78) = 0;
  7272. }
  7273. // Update nearby clients
  7274. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  7275. }
  7276. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7277. /// 01ff <id>.L <x>.W <y>.W
  7278. ///
  7279. /// Visually moves(instant) a character to x,y. The char moves even
  7280. /// when the target cell isn't walkable. If the char is sitting it
  7281. /// stays that way.
  7282. void clif_slide(struct block_list *bl, int x, int y)
  7283. {
  7284. unsigned char buf[10];
  7285. nullpo_retv(bl);
  7286. WBUFW(buf, 0) = 0x01ff;
  7287. WBUFL(buf, 2) = bl->id;
  7288. WBUFW(buf, 6) = x;
  7289. WBUFW(buf, 8) = y;
  7290. clif_send(buf, packet_len(0x1ff), bl, AREA);
  7291. if( disguised(bl) )
  7292. {
  7293. WBUFL(buf,2) = -bl->id;
  7294. clif_send(buf, packet_len(0x1ff), bl, SELF);
  7295. }
  7296. }
  7297. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7298. /// 008d <packet len>.W <id>.L <message>.?B
  7299. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7300. {
  7301. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7302. int len_mes = strlen(mes)+1; //Account for \0
  7303. if (len_mes > sizeof(buf)-8) {
  7304. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7305. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7306. }
  7307. // send message to others
  7308. WBUFW(buf,0) = 0x8d;
  7309. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7310. WBUFL(buf,4) = bl->id;
  7311. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7312. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7313. // send back message to the speaker
  7314. if( bl->type == BL_PC ) {
  7315. WBUFW(buf,0) = 0x8e;
  7316. WBUFW(buf, 2) = len_mes + 4;
  7317. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7318. clif_send(buf, WBUFW(buf,2), bl, SELF);
  7319. }
  7320. }
  7321. /*==========================
  7322. * Minimap fix [Kevin]
  7323. * Remove dot from minimap
  7324. *--------------------------*/
  7325. void clif_party_xy_remove(struct map_session_data *sd)
  7326. {
  7327. unsigned char buf[16];
  7328. nullpo_retv(sd);
  7329. WBUFW(buf,0)=0x107;
  7330. WBUFL(buf,2)=sd->status.account_id;
  7331. WBUFW(buf,6)=-1;
  7332. WBUFW(buf,8)=-1;
  7333. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7334. }
  7335. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7336. /// 0215 <msg id>.L
  7337. /// msg id:
  7338. /// 0x15 = End all negative status (PA_GOSPEL)
  7339. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7340. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7341. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7342. /// 0x19 = All stats +20 (PA_GOSPEL)
  7343. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7344. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7345. /// 0x1e = DEF +25% (PA_GOSPEL)
  7346. /// 0x1f = ATK +100% (PA_GOSPEL)
  7347. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7348. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7349. /// ? = nothing
  7350. void clif_gospel_info(struct map_session_data *sd, int type)
  7351. {
  7352. int fd=sd->fd;
  7353. WFIFOHEAD(fd,packet_len(0x215));
  7354. WFIFOW(fd,0)=0x215;
  7355. WFIFOL(fd,2)=type;
  7356. WFIFOSET(fd, packet_len(0x215));
  7357. }
  7358. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7359. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7360. /// result:
  7361. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7362. /// star:
  7363. /// 0 = Place of the Sun
  7364. /// 1 = Place of the Moon
  7365. /// 2 = Place of the Stars
  7366. /// 1 = Star Gladiator %s's %s: <mapname>
  7367. /// star:
  7368. /// 0 = Place of the Sun
  7369. /// 1 = Place of the Moon
  7370. /// 2 = Place of the Stars
  7371. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7372. /// star:
  7373. /// 0 = Target of the Sun
  7374. /// 1 = Target of the Moon
  7375. /// 2 = Target of the Stars
  7376. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7377. /// star:
  7378. /// 0 = Monster of the Sun
  7379. /// 1 = Monster of the Moon
  7380. /// 2 = Monster of the Stars
  7381. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7382. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7383. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7384. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7385. /// 40 = Target HP : <monster_id used as HP>
  7386. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7387. {
  7388. int fd = sd->fd;
  7389. WFIFOHEAD(fd,packet_len(0x20e));
  7390. WFIFOW(fd,0) = 0x20e;
  7391. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7392. WFIFOL(fd,26) = monster_id;
  7393. WFIFOB(fd,30) = star;
  7394. WFIFOB(fd,31) = result;
  7395. WFIFOSET(fd,packet_len(0x20e));
  7396. }
  7397. /*==========================================
  7398. * Info about Star Glaldiator save map [Komurka]
  7399. * type: 1: Information, 0: Map registered
  7400. *------------------------------------------*/
  7401. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7402. {
  7403. char mapname[MAP_NAME_LENGTH_EXT];
  7404. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7405. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7406. }
  7407. /*==========================================
  7408. * Info about Star Glaldiator hate mob [Komurka]
  7409. * type: 1: Register mob, 0: Information.
  7410. *------------------------------------------*/
  7411. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7412. {
  7413. if( pcdb_checkid(class_) ) {
  7414. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  7415. } else if( mobdb_checkid(class_) ) {
  7416. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7417. } else {
  7418. 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);
  7419. }
  7420. }
  7421. /*==========================================
  7422. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7423. *------------------------------------------*/
  7424. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7425. {
  7426. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  7427. }
  7428. /*==========================================
  7429. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7430. *------------------------------------------*/
  7431. void clif_feel_hate_reset(struct map_session_data *sd)
  7432. {
  7433. clif_starskill(sd, "", 0, 0, 30);
  7434. }
  7435. /// Equip window (un)tick ack (ZC_CONFIG).
  7436. /// 02d9 <type>.L <value>.L
  7437. /// type:
  7438. /// 0 = open equip window
  7439. /// value:
  7440. /// 0 = disabled
  7441. /// 1 = enabled
  7442. void clif_equiptickack(struct map_session_data* sd, int flag)
  7443. {
  7444. int fd;
  7445. nullpo_retv(sd);
  7446. fd = sd->fd;
  7447. WFIFOHEAD(fd, packet_len(0x2d9));
  7448. WFIFOW(fd, 0) = 0x2d9;
  7449. WFIFOL(fd, 2) = 0;
  7450. WFIFOL(fd, 6) = flag;
  7451. WFIFOSET(fd, packet_len(0x2d9));
  7452. }
  7453. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7454. /// 02da <open equip window>.B
  7455. /// open equip window:
  7456. /// 0 = disabled
  7457. /// 1 = enabled
  7458. void clif_equipcheckbox(struct map_session_data* sd)
  7459. {
  7460. int fd;
  7461. nullpo_retv(sd);
  7462. fd = sd->fd;
  7463. WFIFOHEAD(fd, packet_len(0x2da));
  7464. WFIFOW(fd, 0) = 0x2da;
  7465. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7466. WFIFOSET(fd, packet_len(0x2da));
  7467. }
  7468. /// Sends info about a player's equipped items.
  7469. /// 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)
  7470. /// 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)
  7471. /// 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)
  7472. /// 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)
  7473. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7474. {
  7475. uint8* buf;
  7476. int i, n, fd, offset = 0;
  7477. #if PACKETVER < 20100629
  7478. const int s = 26;
  7479. #else
  7480. const int s = 28;
  7481. #endif
  7482. nullpo_retv(sd);
  7483. nullpo_retv(tsd);
  7484. fd = sd->fd;
  7485. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7486. buf = WFIFOP(fd,0);
  7487. #if PACKETVER < 20101124
  7488. WBUFW(buf, 0) = 0x2d7;
  7489. #else
  7490. WBUFW(buf, 0) = 0x859;
  7491. #endif
  7492. safestrncpy((char*)WBUFP(buf, 4), tsd->status.name, NAME_LENGTH);
  7493. WBUFW(buf,28) = tsd->status.class_;
  7494. WBUFW(buf,30) = tsd->vd.hair_style;
  7495. WBUFW(buf,32) = tsd->vd.head_bottom;
  7496. WBUFW(buf,34) = tsd->vd.head_mid;
  7497. WBUFW(buf,36) = tsd->vd.head_top;
  7498. #if PACKETVER >= 20110111
  7499. WBUFW(buf,38) = tsd->vd.robe;
  7500. offset+= 2;
  7501. buf = WBUFP(buf,2);
  7502. #endif
  7503. WBUFW(buf,38) = tsd->vd.hair_color;
  7504. WBUFW(buf,40) = tsd->vd.cloth_color;
  7505. WBUFB(buf,42) = tsd->vd.sex;
  7506. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7507. {
  7508. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7509. continue;
  7510. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7511. continue;
  7512. // Inventory position
  7513. WBUFW(buf, n*s+43) = i + 2;
  7514. // Add refine, identify flag, element, etc.
  7515. clif_item_sub(WBUFP(buf,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7516. // Add cards
  7517. clif_addcards(WBUFP(buf, n*s+55), &tsd->status.inventory[i]);
  7518. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7519. WBUFL(buf, n*s+63) = tsd->status.inventory[i].expire_time;
  7520. WBUFW(buf, n*s+67) = 0;
  7521. #if PACKETVER >= 20100629
  7522. if (tsd->inventory_data[i]->equip&EQP_VISIBLE)
  7523. WBUFW(buf, n*s+69) = tsd->inventory_data[i]->look;
  7524. else
  7525. WBUFW(buf, n*s+69) = 0;
  7526. #endif
  7527. n++;
  7528. }
  7529. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  7530. WFIFOSET(fd, WFIFOW(fd, 2));
  7531. }
  7532. /// Display msgstringtable.txt string (ZC_MSG).
  7533. /// 0291 <message>.W
  7534. void clif_msg(struct map_session_data* sd, unsigned short id)
  7535. {
  7536. int fd;
  7537. nullpo_retv(sd);
  7538. fd = sd->fd;
  7539. WFIFOHEAD(fd, packet_len(0x291));
  7540. WFIFOW(fd, 0) = 0x291;
  7541. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7542. WFIFOSET(fd, packet_len(0x291));
  7543. }
  7544. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  7545. /// 0x7e2 <message>.W <value>.L
  7546. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  7547. {
  7548. int fd = sd->fd;
  7549. WFIFOHEAD(fd, packet_len(0x7e2));
  7550. WFIFOW(fd,0) = 0x7e2;
  7551. WFIFOW(fd,2) = id;
  7552. WFIFOL(fd,4) = value;
  7553. WFIFOSET(fd, packet_len(0x7e2));
  7554. }
  7555. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  7556. /// 07e6 <skill id>.W <msg id>.L
  7557. ///
  7558. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7559. /// "[SkillName] Message"
  7560. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7561. {
  7562. int fd = sd->fd;
  7563. WFIFOHEAD(fd, packet_len(0x7e6));
  7564. WFIFOW(fd,0) = 0x7e6;
  7565. WFIFOW(fd,2) = skill_id;
  7566. WFIFOL(fd,4) = msg_id;
  7567. WFIFOSET(fd, packet_len(0x7e6));
  7568. }
  7569. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7570. /// Returns true if the packet was parsed successfully.
  7571. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7572. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7573. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7574. {
  7575. char *text, *name, *message;
  7576. unsigned int packetlen, textlen, namelen, messagelen;
  7577. int fd = sd->fd;
  7578. *name_ = NULL;
  7579. *namelen_ = 0;
  7580. *message_ = NULL;
  7581. *messagelen_ = 0;
  7582. packetlen = RFIFOW(fd,2);
  7583. // basic structure checks
  7584. if( packetlen < 4 + 1 )
  7585. { // 4-byte header and at least an empty string is expected
  7586. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7587. return false;
  7588. }
  7589. text = (char*)RFIFOP(fd,4);
  7590. textlen = packetlen - 4;
  7591. // process <name> part of the packet
  7592. if( format == 0 )
  7593. {// name and message are separated by ' : '
  7594. // validate name
  7595. name = text;
  7596. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7597. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7598. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7599. {
  7600. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7601. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7602. set_eof(fd); // Just kick them out to correct it.
  7603. return false;
  7604. }
  7605. message = name + namelen + 3;
  7606. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7607. }
  7608. else
  7609. {// name has fixed width
  7610. if( textlen < NAME_LENGTH + 1 )
  7611. {
  7612. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7613. return false;
  7614. }
  7615. // validate name
  7616. name = text;
  7617. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7618. if( name[namelen] != '\0' )
  7619. { // only restriction is that the name must be zero-terminated
  7620. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7621. return false;
  7622. }
  7623. message = name + NAME_LENGTH;
  7624. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7625. }
  7626. if( messagelen != strnlen(message, messagelen)+1 )
  7627. { // the declared length must match real length
  7628. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7629. return false;
  7630. }
  7631. // verify <message> part of the packet
  7632. if( message[messagelen-1] != '\0' )
  7633. { // message must be zero-terminated
  7634. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7635. return false;
  7636. }
  7637. if( messagelen > CHAT_SIZE_MAX-1 )
  7638. { // messages mustn't be too long
  7639. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7640. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7641. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7642. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7643. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7644. return false;
  7645. }
  7646. *name_ = name;
  7647. *namelen_ = namelen;
  7648. *message_ = message;
  7649. *messagelen_ = messagelen;
  7650. return true;
  7651. }
  7652. // ---------------------
  7653. // clif_guess_PacketVer
  7654. // ---------------------
  7655. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7656. // error codes:
  7657. // 0 - Success
  7658. // 1 - Unknown packet_ver
  7659. // 2 - Invalid account_id
  7660. // 3 - Invalid char_id
  7661. // 4 - Invalid login_id1 (reserved)
  7662. // 5 - Invalid client_tick (reserved)
  7663. // 6 - Invalid sex
  7664. // Only the first 'invalid' error that appears is used.
  7665. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7666. {
  7667. static int err = 1;
  7668. static int packet_ver = -1;
  7669. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7670. if (get_previous)
  7671. {//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]
  7672. if( error )
  7673. *error = err;
  7674. return packet_ver;
  7675. }
  7676. //By default, start searching on the default one.
  7677. err = 1;
  7678. packet_ver = clif_config.packet_db_ver;
  7679. cmd = RFIFOW(fd,0);
  7680. packet_len = RFIFOREST(fd);
  7681. #define SET_ERROR(n) \
  7682. if( err == 1 )\
  7683. err = n;\
  7684. //define SET_ERROR
  7685. // FIXME: If the packet is not received at once, this will FAIL.
  7686. // Figure out, when it happens, that only part of the packet is
  7687. // received, or fix the function to be able to deal with that
  7688. // case.
  7689. #define CHECK_PACKET_VER() \
  7690. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7691. ;/* not wanttoconnection or wrong length */\
  7692. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7693. { SET_ERROR(2); }/* invalid account_id */\
  7694. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7695. { SET_ERROR(3); }/* invalid char_id */\
  7696. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7697. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7698. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7699. { SET_ERROR(6); }/* invalid sex */\
  7700. else\
  7701. {\
  7702. err = 0;\
  7703. if( error )\
  7704. *error = 0;\
  7705. return packet_ver;\
  7706. }\
  7707. //define CHECK_PACKET_VER
  7708. CHECK_PACKET_VER();//Default packet version found.
  7709. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--) { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7710. CHECK_PACKET_VER();
  7711. }
  7712. if( error )
  7713. *error = err;
  7714. packet_ver = -1;
  7715. return -1;
  7716. #undef SET_ERROR
  7717. #undef CHECK_PACKET_VER
  7718. }
  7719. // ------------
  7720. // clif_parse_*
  7721. // ------------
  7722. // Parses incoming (player) connection
  7723. /// Request to connect to map-server.
  7724. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7725. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7726. /// There are various variants of this packet, some of them have padding between fields.
  7727. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  7728. {
  7729. struct block_list* bl;
  7730. struct auth_node* node;
  7731. int cmd, account_id, char_id, login_id1, sex;
  7732. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7733. 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])
  7734. if (sd) {
  7735. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7736. return;
  7737. }
  7738. // Only valid packet version get here
  7739. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7740. cmd = RFIFOW(fd,0);
  7741. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7742. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7743. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7744. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7745. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7746. if( packet_ver < 5 || // reject really old client versions
  7747. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7748. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7749. {// packet version rejected
  7750. 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));
  7751. WFIFOHEAD(fd,packet_len(0x6a));
  7752. WFIFOW(fd,0) = 0x6a;
  7753. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7754. WFIFOSET(fd,packet_len(0x6a));
  7755. set_eof(fd);
  7756. return;
  7757. }
  7758. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  7759. clif_authfail_fd(fd,1);// server closed
  7760. return;
  7761. }
  7762. //Check for double login.
  7763. bl = map_id2bl(account_id);
  7764. if(bl && bl->type != BL_PC) {
  7765. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7766. WFIFOHEAD(fd,packet_len(0x6a));
  7767. WFIFOW(fd,0) = 0x6a;
  7768. WFIFOB(fd,2) = 3; // Rejected by server
  7769. WFIFOSET(fd,packet_len(0x6a));
  7770. set_eof(fd);
  7771. return;
  7772. }
  7773. if (bl ||
  7774. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7775. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7776. {
  7777. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7778. return;
  7779. }
  7780. CREATE(sd, TBL_PC, 1);
  7781. sd->fd = fd;
  7782. sd->packet_ver = packet_ver;
  7783. session[fd]->session_data = sd;
  7784. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7785. #if PACKETVER < 20070521
  7786. WFIFOHEAD(fd,4);
  7787. WFIFOL(fd,0) = sd->bl.id;
  7788. WFIFOSET(fd,4);
  7789. #else
  7790. WFIFOHEAD(fd,packet_len(0x283));
  7791. WFIFOW(fd,0) = 0x283;
  7792. WFIFOL(fd,2) = sd->bl.id;
  7793. WFIFOSET(fd,packet_len(0x283));
  7794. #endif
  7795. chrif_authreq(sd);
  7796. }
  7797. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7798. /// 007d
  7799. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7800. {
  7801. if(sd->bl.prev != NULL)
  7802. return;
  7803. if (!sd->state.active) { //Character loading is not complete yet!
  7804. //Let pc_reg_received reinvoke this when ready.
  7805. sd->state.connect_new = 0;
  7806. return;
  7807. }
  7808. if (sd->state.rewarp) { //Rewarp player.
  7809. sd->state.rewarp = 0;
  7810. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7811. return;
  7812. }
  7813. sd->state.warping = 0;
  7814. // look
  7815. #if PACKETVER < 4
  7816. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7817. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7818. #else
  7819. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7820. #endif
  7821. if(sd->vd.cloth_color)
  7822. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7823. // item
  7824. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  7825. pc_checkitem(sd);
  7826. // cart
  7827. if(pc_iscarton(sd)) {
  7828. clif_cartlist(sd);
  7829. clif_updatestatus(sd,SP_CARTINFO);
  7830. }
  7831. // weight
  7832. clif_updatestatus(sd,SP_WEIGHT);
  7833. clif_updatestatus(sd,SP_MAXWEIGHT);
  7834. // guild
  7835. // (needs to go before clif_spawn() to show guild emblems correctly)
  7836. if(sd->status.guild_id)
  7837. guild_send_memberinfoshort(sd,1);
  7838. if(battle_config.pc_invincible_time > 0) {
  7839. if(map_flag_gvg(sd->bl.m))
  7840. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7841. else
  7842. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7843. }
  7844. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7845. map_spawnmobs(sd->bl.m);
  7846. if( !(sd->sc.option&OPTION_INVISIBLE) ) { // increment the number of pvp players on the map
  7847. map[sd->bl.m].users_pvp++;
  7848. }
  7849. if( map[sd->bl.m].instance_id ) {
  7850. instance[map[sd->bl.m].instance_id].users++;
  7851. instance_check_idle(map[sd->bl.m].instance_id);
  7852. }
  7853. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7854. // reset the callshop flag if the player changes map
  7855. sd->state.callshop = 0;
  7856. map_addblock(&sd->bl);
  7857. clif_spawn(&sd->bl);
  7858. // Party
  7859. // (needs to go after clif_spawn() to show hp bars correctly)
  7860. if(sd->status.party_id) {
  7861. party_send_movemap(sd);
  7862. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7863. }
  7864. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  7865. if(map[sd->bl.m].flag.pvp && !(sd->sc.option&OPTION_INVISIBLE)) {
  7866. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7867. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7868. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7869. sd->pvp_rank = 0;
  7870. sd->pvp_lastusers = 0;
  7871. sd->pvp_point = 5;
  7872. sd->pvp_won = 0;
  7873. sd->pvp_lost = 0;
  7874. }
  7875. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7876. } else
  7877. // set flag, if it's a duel [LuzZza]
  7878. if(sd->duel_group)
  7879. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE);
  7880. if (map[sd->bl.m].flag.gvg_dungeon)
  7881. clif_map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  7882. if( map_flag_gvg(sd->bl.m) )
  7883. clif_map_property(sd, MAPPROPERTY_AGITZONE);
  7884. // info about nearby objects
  7885. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7886. 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);
  7887. // pet
  7888. if( sd->pd ) {
  7889. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  7890. clif_displaymessage(sd->fd, msg_txt(sd,666));
  7891. pet_menu(sd, 3); //Option 3 is return to egg.
  7892. } else {
  7893. map_addblock(&sd->pd->bl);
  7894. clif_spawn(&sd->pd->bl);
  7895. clif_send_petdata(sd,sd->pd,0,0);
  7896. clif_send_petstatus(sd);
  7897. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7898. }
  7899. }
  7900. //homunculus [blackhole89]
  7901. if( merc_is_hom_active(sd->hd) ) {
  7902. map_addblock(&sd->hd->bl);
  7903. clif_spawn(&sd->hd->bl);
  7904. clif_send_homdata(sd,SP_ACK,0);
  7905. clif_hominfo(sd,sd->hd,1);
  7906. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7907. clif_homskillinfoblock(sd);
  7908. if( battle_config.hom_setting&0x8 )
  7909. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7910. if( !(battle_config.hom_setting&0x2) )
  7911. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7912. }
  7913. if( sd->md ) {
  7914. map_addblock(&sd->md->bl);
  7915. clif_spawn(&sd->md->bl);
  7916. clif_mercenary_info(sd);
  7917. clif_mercenary_skillblock(sd);
  7918. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  7919. }
  7920. if( sd->ed ) {
  7921. map_addblock(&sd->ed->bl);
  7922. clif_spawn(&sd->ed->bl);
  7923. clif_elemental_info(sd);
  7924. clif_elemental_updatestatus(sd,SP_HP);
  7925. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  7926. clif_elemental_updatestatus(sd,SP_SP);
  7927. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  7928. }
  7929. if(sd->state.connect_new) {
  7930. int lv;
  7931. sd->state.connect_new = 0;
  7932. clif_skillinfoblock(sd);
  7933. clif_hotkeys_send(sd);
  7934. clif_updatestatus(sd,SP_BASEEXP);
  7935. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7936. clif_updatestatus(sd,SP_JOBEXP);
  7937. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7938. clif_updatestatus(sd,SP_SKILLPOINT);
  7939. clif_initialstatus(sd);
  7940. if (sd->sc.option&OPTION_FALCON)
  7941. clif_status_load(&sd->bl, SI_FALCON, 1);
  7942. if (sd->sc.option&OPTION_RIDING)
  7943. clif_status_load(&sd->bl, SI_RIDING, 1);
  7944. else if (sd->sc.option&OPTION_WUGRIDER)
  7945. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  7946. if(sd->status.manner < 0)
  7947. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  7948. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7949. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7950. if(sd->bl.m == sd->feel_map[0].m
  7951. || sd->bl.m == sd->feel_map[1].m
  7952. || sd->bl.m == sd->feel_map[2].m)
  7953. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7954. }
  7955. if(sd->pd && sd->pd->pet.intimate > 900)
  7956. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7957. if(merc_is_hom_active(sd->hd))
  7958. merc_hom_init_timers(sd->hd);
  7959. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  7960. sd->state.night = 1;
  7961. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7962. }
  7963. // Notify everyone that this char logged in [Skotlex].
  7964. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7965. //Login Event
  7966. npc_script_event(sd, NPCE_LOGIN);
  7967. } else {
  7968. //For some reason the client "loses" these on warp/map-change.
  7969. clif_updatestatus(sd,SP_STR);
  7970. clif_updatestatus(sd,SP_AGI);
  7971. clif_updatestatus(sd,SP_VIT);
  7972. clif_updatestatus(sd,SP_INT);
  7973. clif_updatestatus(sd,SP_DEX);
  7974. clif_updatestatus(sd,SP_LUK);
  7975. // abort currently running script
  7976. sd->state.using_fake_npc = 0;
  7977. sd->state.menu_or_input = 0;
  7978. sd->npc_menu = 0;
  7979. if(sd->npc_id)
  7980. npc_event_dequeue(sd);
  7981. }
  7982. if( sd->state.changemap ) {// restore information that gets lost on map-change
  7983. #if PACKETVER >= 20070918
  7984. clif_partyinvitationstate(sd);
  7985. clif_equipcheckbox(sd);
  7986. #endif
  7987. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7988. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7989. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7990. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7991. { //Display night.
  7992. if( !sd->state.night )
  7993. {
  7994. sd->state.night = 1;
  7995. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7996. }
  7997. }
  7998. else if( sd->state.night )
  7999. { //Clear night display.
  8000. sd->state.night = 0;
  8001. clif_status_load(&sd->bl, SI_NIGHT, 0);
  8002. }
  8003. if( map[sd->bl.m].flag.battleground )
  8004. {
  8005. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8006. if( map[sd->bl.m].flag.battleground == 2 )
  8007. clif_bg_updatescore_single(sd);
  8008. }
  8009. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  8010. {
  8011. char output[128];
  8012. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  8013. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  8014. }
  8015. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  8016. status_calc_pc(sd, false); // Some conditions are map-dependent so we must recalculate
  8017. sd->state.changemap = false;
  8018. if( Channel_Config.map_enable && Channel_Config.map_autojoin && !map[sd->bl.m].flag.chmautojoin) {
  8019. channel_mjoin(sd); //join new map
  8020. }
  8021. }
  8022. mail_clear(sd);
  8023. /* Guild Aura Init */
  8024. if( sd->state.gmaster_flag ) {
  8025. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->state.gmaster_flag,GD_LEADERSHIP));
  8026. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->state.gmaster_flag,GD_GLORYWOUNDS));
  8027. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->state.gmaster_flag,GD_SOULCOLD));
  8028. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->state.gmaster_flag,GD_HAWKEYES));
  8029. }
  8030. if( sd->state.vending ) { /* show we have a vending */
  8031. clif_openvending(sd,sd->bl.id,sd->vending);
  8032. clif_showvendingboard(&sd->bl,sd->message,0);
  8033. }
  8034. if(map[sd->bl.m].flag.loadevent) // Lance
  8035. npc_script_event(sd, NPCE_LOADMAP);
  8036. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  8037. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  8038. if (sd->sc.opt2) //Client loses these on warp.
  8039. clif_changeoption(&sd->bl);
  8040. clif_weather_check(sd);
  8041. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8042. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  8043. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8044. else
  8045. sd->areanpc_id = 0;
  8046. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8047. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  8048. pc_setdead(sd);
  8049. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8050. if(pc_isdead(sd))
  8051. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8052. else {
  8053. skill_usave_trigger(sd);
  8054. clif_changed_dir(&sd->bl, SELF);
  8055. }
  8056. // Trigger skill effects if you appear standing on them
  8057. if(!battle_config.pc_invincible_time)
  8058. skill_unit_move(&sd->bl,gettick(),1);
  8059. }
  8060. /// Server's tick (ZC_NOTIFY_TIME).
  8061. /// 007f <time>.L
  8062. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  8063. {
  8064. int fd = sd->fd;
  8065. WFIFOHEAD(fd,packet_len(0x7f));
  8066. WFIFOW(fd,0) = 0x7f;
  8067. WFIFOL(fd,2) = time;
  8068. WFIFOSET(fd,packet_len(0x7f));
  8069. }
  8070. /// Request for server's tick.
  8071. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8072. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8073. /// There are various variants of this packet, some of them have padding between fields.
  8074. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8075. {
  8076. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8077. clif_notify_time(sd, gettick());
  8078. }
  8079. /// Sends hotkey bar.
  8080. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8081. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8082. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8083. void clif_hotkeys_send(struct map_session_data *sd) {
  8084. #ifdef HOTKEY_SAVING
  8085. const int fd = sd->fd;
  8086. int i;
  8087. #if PACKETVER < 20090603
  8088. const int cmd = 0x2b9;
  8089. #else
  8090. const int cmd = 0x7d9;
  8091. #endif
  8092. if (!fd) return;
  8093. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  8094. WFIFOW(fd, 0) = cmd;
  8095. for(i = 0; i < MAX_HOTKEYS; i++) {
  8096. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  8097. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  8098. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  8099. }
  8100. WFIFOSET(fd, packet_len(cmd));
  8101. #endif
  8102. }
  8103. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8104. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8105. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8106. #ifdef HOTKEY_SAVING
  8107. unsigned short idx;
  8108. int cmd;
  8109. cmd = RFIFOW(fd, 0);
  8110. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  8111. if (idx >= MAX_HOTKEYS) return;
  8112. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  8113. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  8114. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  8115. #endif
  8116. }
  8117. /// Displays cast-like progress bar (ZC_PROGRESS).
  8118. /// 02f0 <color>.L <time>.L
  8119. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  8120. {
  8121. int fd = sd->fd;
  8122. WFIFOHEAD(fd,packet_len(0x2f0));
  8123. WFIFOW(fd,0) = 0x2f0;
  8124. WFIFOL(fd,2) = color;
  8125. WFIFOL(fd,6) = second;
  8126. WFIFOSET(fd,packet_len(0x2f0));
  8127. }
  8128. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8129. /// 02f2
  8130. void clif_progressbar_abort(struct map_session_data * sd)
  8131. {
  8132. int fd = sd->fd;
  8133. WFIFOHEAD(fd,packet_len(0x2f2));
  8134. WFIFOW(fd,0) = 0x2f2;
  8135. WFIFOSET(fd,packet_len(0x2f2));
  8136. }
  8137. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8138. /// 02f1
  8139. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8140. {
  8141. int npc_id = sd->progressbar.npc_id;
  8142. if( gettick() < sd->progressbar.timeout && sd->st )
  8143. sd->st->state = END;
  8144. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  8145. npc_scriptcont(sd, npc_id, false);
  8146. }
  8147. /// Request to walk to a certain position on the current map.
  8148. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8149. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8150. /// There are various variants of this packet, some of them have padding between fields.
  8151. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8152. {
  8153. short x, y;
  8154. if (pc_isdead(sd)) {
  8155. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8156. return;
  8157. }
  8158. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8159. ; //You CAN walk on this OPT1 value.
  8160. else if( sd->progressbar.npc_id )
  8161. clif_progressbar_abort(sd);
  8162. else if (pc_cant_act(sd))
  8163. return;
  8164. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8165. return;
  8166. pc_delinvincibletimer(sd);
  8167. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8168. //Set last idle time... [Skotlex]
  8169. sd->idletime = last_tick;
  8170. unit_walktoxy(&sd->bl, x, y, 4);
  8171. }
  8172. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8173. /// 018b <result>.W
  8174. /// result:
  8175. /// 0 = disconnect (quit)
  8176. /// 1 = cannot disconnect (wait 10 seconds)
  8177. /// ? = ignored
  8178. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8179. {
  8180. int fd = sd->fd;
  8181. WFIFOHEAD(fd,packet_len(0x18b));
  8182. WFIFOW(fd,0) = 0x18b;
  8183. WFIFOW(fd,2) = result;
  8184. WFIFOSET(fd,packet_len(0x18b));
  8185. }
  8186. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8187. /// 018a <type>.W
  8188. /// type:
  8189. /// 0 = quit
  8190. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8191. {
  8192. /* Rovert's prevent logout option fixed [Valaris] */
  8193. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8194. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8195. {
  8196. set_eof(fd);
  8197. clif_disconnect_ack(sd, 0);
  8198. } else {
  8199. clif_disconnect_ack(sd, 1);
  8200. }
  8201. }
  8202. /// Requesting unit's name.
  8203. /// 0094 <id>.L (CZ_REQNAME)
  8204. /// 0368 <id>.L (CZ_REQNAME2)
  8205. /// There are various variants of this packet, some of them have padding between fields.
  8206. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  8207. {
  8208. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8209. struct block_list* bl;
  8210. //struct status_change *sc;
  8211. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8212. id = sd->bl.id;
  8213. bl = map_id2bl(id);
  8214. if( bl == NULL )
  8215. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8216. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8217. return; // Block namerequests past view range
  8218. // 'see people in GM hide' cheat detection
  8219. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  8220. sc = status_get_sc(bl);
  8221. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8222. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8223. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8224. ) {
  8225. char gm_msg[256];
  8226. 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);
  8227. ShowWarning(gm_msg);
  8228. // information is sent to all online GMs
  8229. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8230. return;
  8231. }
  8232. */
  8233. clif_charnameack(fd, bl);
  8234. }
  8235. /// Validates and processes global messages
  8236. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8237. /// There are various variants of this packet.
  8238. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8239. {
  8240. const char* text = (char*)RFIFOP(fd,4);
  8241. int textlen = RFIFOW(fd,2) - 4;
  8242. char *name, *message, *fakename = NULL;
  8243. int namelen, messagelen;
  8244. bool is_fake;
  8245. // validate packet and retrieve name and message
  8246. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8247. return;
  8248. if( is_atcommand(fd, sd, message, 1) )
  8249. return;
  8250. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8251. return;
  8252. if( battle_config.min_chat_delay ) { //[Skotlex]
  8253. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8254. return;
  8255. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8256. }
  8257. if( sd->gcbind ) {
  8258. channel_send(sd->gcbind,sd,message);
  8259. return;
  8260. } else if ( sd->fontcolor && !sd->chatID ) {
  8261. char mout[200];
  8262. snprintf(mout, 200, "%s : %s",sd->fakename[0]?sd->fakename:sd->status.name,message);
  8263. clif_colormes(sd,sd->fontcolor-1,mout);
  8264. return;
  8265. }
  8266. /**
  8267. * Fake Name Design by FatalEror (bug report #9)
  8268. **/
  8269. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8270. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8271. strcpy(fakename, sd->fakename);
  8272. strcat(fakename, " : ");
  8273. strcat(fakename, message);
  8274. textlen = strlen(fakename) + 1;
  8275. }
  8276. // send message to others (using the send buffer for temp. storage)
  8277. WFIFOHEAD(fd, 8 + textlen);
  8278. WFIFOW(fd,0) = 0x8d;
  8279. WFIFOW(fd,2) = 8 + textlen;
  8280. WFIFOL(fd,4) = sd->bl.id;
  8281. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8282. //FIXME: chat has range of 9 only
  8283. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8284. // send back message to the speaker
  8285. if( is_fake ) {
  8286. WFIFOW(fd,0) = 0x8e;
  8287. WFIFOW(fd,2) = textlen + 4;
  8288. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8289. aFree(fakename);
  8290. } else {
  8291. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8292. WFIFOW(fd,0) = 0x8e;
  8293. }
  8294. WFIFOSET(fd, WFIFOW(fd,2));
  8295. #ifdef PCRE_SUPPORT
  8296. // trigger listening npcs
  8297. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8298. #endif
  8299. // Reset idle time when using normal chat.
  8300. sd->idletime = last_tick;
  8301. // Chat logging type 'O' / Global Chat
  8302. 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);
  8303. }
  8304. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8305. /// Request to warp to a map on given coordinates.
  8306. /// 0140 <map name>.16B <x>.W <y>.W
  8307. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8308. {
  8309. char command[MAP_NAME_LENGTH_EXT+25];
  8310. char* map_name;
  8311. map_name = (char*)RFIFOP(fd,2);
  8312. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8313. sprintf(command, "%cmapmove %s %d %d", atcommand_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8314. is_atcommand(fd, sd, command, 1);
  8315. }
  8316. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8317. /// 009c <id>.L <head dir>.W <dir>.B
  8318. /// head dir:
  8319. /// 0 = straight
  8320. /// 1 = turned CW
  8321. /// 2 = turned CCW
  8322. /// dir:
  8323. /// 0 = north
  8324. /// 1 = northwest
  8325. /// 2 = west
  8326. /// 3 = southwest
  8327. /// 4 = south
  8328. /// 5 = southeast
  8329. /// 6 = east
  8330. /// 7 = northeast
  8331. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8332. {
  8333. unsigned char buf[64];
  8334. WBUFW(buf,0) = 0x9c;
  8335. WBUFL(buf,2) = bl->id;
  8336. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  8337. WBUFB(buf,8) = unit_getdir(bl);
  8338. clif_send(buf, packet_len(0x9c), bl, target);
  8339. if (disguised(bl)) {
  8340. WBUFL(buf,2) = -bl->id;
  8341. WBUFW(buf,6) = 0;
  8342. clif_send(buf, packet_len(0x9c), bl, SELF);
  8343. }
  8344. }
  8345. /// Request to change own body and head direction.
  8346. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8347. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8348. /// There are various variants of this packet, some of them have padding between fields.
  8349. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8350. {
  8351. unsigned char headdir, dir;
  8352. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8353. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8354. pc_setdir(sd, dir, headdir);
  8355. clif_changed_dir(&sd->bl, AREA_WOS);
  8356. }
  8357. /// Request to show an emotion (CZ_REQ_EMOTION).
  8358. /// 00bf <type>.B
  8359. /// type:
  8360. /// @see enum emotion_type
  8361. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8362. {
  8363. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8364. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  8365. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8366. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8367. return;
  8368. }
  8369. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8370. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8371. sd->emotionlasttime = time(NULL);
  8372. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8373. return;
  8374. }
  8375. sd->emotionlasttime = time(NULL);
  8376. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8377. emoticon = rnd()%6+E_DICE1;
  8378. }
  8379. clif_emotion(&sd->bl, emoticon);
  8380. } else
  8381. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8382. }
  8383. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8384. /// 00c2 <count>.L
  8385. void clif_user_count(struct map_session_data* sd, int count)
  8386. {
  8387. int fd = sd->fd;
  8388. WFIFOHEAD(fd,packet_len(0xc2));
  8389. WFIFOW(fd,0) = 0xc2;
  8390. WFIFOL(fd,2) = count;
  8391. WFIFOSET(fd,packet_len(0xc2));
  8392. }
  8393. /// /w /who (CZ_REQ_USER_COUNT).
  8394. /// Request to display amount of currently connected players.
  8395. /// 00c1
  8396. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  8397. {
  8398. clif_user_count(sd, map_getusers());
  8399. }
  8400. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  8401. {
  8402. if (pc_isdead(sd)) {
  8403. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8404. return;
  8405. }
  8406. if (sd->sc.count &&
  8407. (sd->sc.data[SC_TRICKDEAD] ||
  8408. sd->sc.data[SC_AUTOCOUNTER] ||
  8409. sd->sc.data[SC_BLADESTOP] ||
  8410. sd->sc.data[SC__MANHOLE] ||
  8411. sd->sc.data[SC_CURSEDCIRCLE_ATKER] ||
  8412. sd->sc.data[SC_CURSEDCIRCLE_TARGET] ))
  8413. return;
  8414. pc_stop_walking(sd, 1);
  8415. pc_stop_attack(sd);
  8416. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8417. target_id = sd->bl.id;
  8418. switch(action_type)
  8419. {
  8420. case 0x00: // once attack
  8421. case 0x07: // continuous attack
  8422. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  8423. return;
  8424. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8425. return;
  8426. if( sd->sc.data[SC_BASILICA] || sd->sc.data[SC__SHADOWFORM] )
  8427. return;
  8428. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8429. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8430. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8431. return;
  8432. }
  8433. }
  8434. pc_delinvincibletimer(sd);
  8435. sd->idletime = last_tick;
  8436. unit_attack(&sd->bl, target_id, action_type != 0);
  8437. break;
  8438. case 0x02: // sitdown
  8439. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  8440. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8441. break;
  8442. }
  8443. if(pc_issit(sd)) {
  8444. //Bugged client? Just refresh them.
  8445. clif_sitting(&sd->bl);
  8446. return;
  8447. }
  8448. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8449. break;
  8450. if (sd->sc.count && (
  8451. sd->sc.data[SC_DANCING] ||
  8452. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8453. )) //No sitting during these states either.
  8454. break;
  8455. sd->idletime = last_tick;
  8456. pc_setsit(sd);
  8457. skill_sit(sd,1);
  8458. clif_sitting(&sd->bl);
  8459. break;
  8460. case 0x03: // standup
  8461. if (!pc_issit(sd)) {
  8462. //Bugged client? Just refresh them.
  8463. clif_standing(&sd->bl);
  8464. return;
  8465. }
  8466. sd->idletime = last_tick;
  8467. pc_setstand(sd);
  8468. skill_sit(sd,0);
  8469. clif_standing(&sd->bl);
  8470. break;
  8471. }
  8472. }
  8473. /// Request for an action.
  8474. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8475. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8476. /// action:
  8477. /// 0 = attack
  8478. /// 1 = pick up item
  8479. /// 2 = sit down
  8480. /// 3 = stand up
  8481. /// 7 = continous attack
  8482. /// 12 = (touch skill?)
  8483. /// There are various variants of this packet, some of them have padding between fields.
  8484. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8485. {
  8486. clif_parse_ActionRequest_sub(sd,
  8487. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  8488. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  8489. gettick()
  8490. );
  8491. }
  8492. /// Response to the death/system menu (CZ_RESTART).
  8493. /// 00b2 <type>.B
  8494. /// type:
  8495. /// 0 = restart (respawn)
  8496. /// 1 = char-select (disconnect)
  8497. void clif_parse_Restart(int fd, struct map_session_data *sd)
  8498. {
  8499. switch(RFIFOB(fd,2)) {
  8500. case 0x00:
  8501. pc_respawn(sd,CLR_RESPAWN);
  8502. break;
  8503. case 0x01:
  8504. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8505. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] &&
  8506. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8507. { //Send to char-server for character selection.
  8508. chrif_charselectreq(sd, session[fd]->client_addr);
  8509. } else {
  8510. clif_disconnect_ack(sd, 1);
  8511. }
  8512. break;
  8513. }
  8514. }
  8515. /// Validates and processes whispered messages (CZ_WHISPER).
  8516. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8517. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8518. {
  8519. struct map_session_data* dstsd;
  8520. int i;
  8521. char *target, *message;
  8522. int namelen, messagelen;
  8523. // validate packet and retrieve name and message
  8524. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8525. return;
  8526. if ( is_atcommand(fd, sd, message, 1) )
  8527. return;
  8528. if (sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8529. return;
  8530. if (battle_config.min_chat_delay) { //[Skotlex]
  8531. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8532. return;
  8533. }
  8534. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8535. }
  8536. // Reset idle time when using whisper/main chat.
  8537. sd->idletime = last_tick;
  8538. // Chat logging type 'W' / Whisper
  8539. 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);
  8540. //-------------------------------------------------------//
  8541. // Lordalfa - Paperboy - To whisper NPC commands //
  8542. //-------------------------------------------------------//
  8543. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8544. {
  8545. char* str = target+4; //Skip the NPC: string part.
  8546. struct npc_data* npc;
  8547. if ((npc = npc_name2id(str))) {
  8548. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8549. char *split;
  8550. char output[256];
  8551. str = message;
  8552. // skip codepage indicator, if detected
  8553. if( str[0] == '|' && strlen(str) >= 4 )
  8554. str += 3;
  8555. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8556. split = strchr(str,'#');
  8557. if( split == NULL ) { // use the remaining string
  8558. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8559. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8560. split_data[i][0] = '\0';
  8561. break;
  8562. }
  8563. *split = '\0';
  8564. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8565. str = split+1;
  8566. }
  8567. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8568. sprintf(output, "@whispervar%d$", i);
  8569. set_var(sd,output,(char *) split_data[i]);
  8570. }
  8571. sprintf(output, "%s::OnWhisperGlobal", npc->exname);
  8572. npc_event(sd,output,0); // Calls the NPC label
  8573. return;
  8574. }
  8575. } else if( target[0] == '#' ) {
  8576. struct Channel *channel = NULL;
  8577. char* chname = target;
  8578. channel = channel_name2channel(chname,sd,3);
  8579. if(channel){
  8580. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  8581. channel_send(channel,sd,message);
  8582. }
  8583. else if( channel->pass[0] == '\0') { //no pass needed
  8584. if (channel_join(channel,sd)==0) channel_send(channel,sd,message); //join success
  8585. }
  8586. else {
  8587. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  8588. }
  8589. return;
  8590. }
  8591. }
  8592. // searching destination character
  8593. dstsd = map_nick2sd(target);
  8594. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8595. // player is not on this map-server
  8596. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8597. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8598. // and if we ask for 'Test', we must not contact 'test' player
  8599. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8600. intif_wis_message(sd, target, message, messagelen);
  8601. return;
  8602. }
  8603. // if player ignores everyone
  8604. if (dstsd->state.ignoreAll) {
  8605. if (dstsd->sc.option & OPTION_INVISIBLE && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8606. clif_wis_end(fd, 1); // 1: target character is not loged in
  8607. else
  8608. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8609. return;
  8610. }
  8611. // if player is autotrading
  8612. if( dstsd->state.autotrade == 1 ) {
  8613. char output[256];
  8614. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8615. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8616. return;
  8617. }
  8618. // if player ignores the source character
  8619. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8620. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8621. clif_wis_end(fd, 2); // 2: ignored by target
  8622. return;
  8623. }
  8624. // notify sender of success
  8625. clif_wis_end(fd, 0); // 0: success to send wisper
  8626. // Normal message
  8627. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8628. }
  8629. /// /b /nb (CZ_BROADCAST).
  8630. /// Request to broadcast a message on whole server.
  8631. /// 0099 <packet len>.W <text>.?B 00
  8632. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  8633. char command[CHAT_SIZE_MAX+11];
  8634. char* msg = (char*)RFIFOP(fd,4);
  8635. unsigned int len = RFIFOW(fd,2)-4;
  8636. // as the length varies depending on the command used, just block unreasonably long strings
  8637. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8638. sprintf(command, "%ckami %s", atcommand_symbol, msg);
  8639. is_atcommand(fd, sd, command, 1);
  8640. }
  8641. /// Request to pick up an item.
  8642. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8643. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8644. /// There are various variants of this packet, some of them have padding between fields.
  8645. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8646. {
  8647. struct flooritem_data *fitem;
  8648. int map_object_id;
  8649. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8650. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8651. do {
  8652. if (pc_isdead(sd)) {
  8653. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8654. break;
  8655. }
  8656. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8657. break;
  8658. if( sd->sc.cant.pickup )
  8659. break;
  8660. if (pc_cant_act(sd))
  8661. break;
  8662. if (!pc_takeitem(sd, fitem))
  8663. break;
  8664. return;
  8665. } while (0);
  8666. // Client REQUIRES a fail packet or you can no longer pick items.
  8667. clif_additem(sd,0,0,6);
  8668. }
  8669. /// Request to drop an item.
  8670. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8671. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8672. /// There are various variants of this packet, some of them have padding between fields.
  8673. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8674. {
  8675. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8676. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8677. for(;;) {
  8678. if (pc_isdead(sd))
  8679. break;
  8680. if (pc_cant_act2(sd))
  8681. break;
  8682. if (sd->sc.count && (
  8683. sd->sc.data[SC_AUTOCOUNTER] ||
  8684. sd->sc.data[SC_BLADESTOP] ||
  8685. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8686. ))
  8687. break;
  8688. if (!pc_dropitem(sd, item_index, item_amount))
  8689. break;
  8690. return;
  8691. }
  8692. //Because the client does not like being ignored.
  8693. clif_dropitem(sd, item_index,0);
  8694. }
  8695. /// Request to use an item.
  8696. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  8697. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  8698. /// There are various variants of this packet, some of them have padding between fields.
  8699. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8700. {
  8701. int n;
  8702. if (pc_isdead(sd)) {
  8703. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8704. return;
  8705. }
  8706. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  8707. return;
  8708. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8709. sd->idletime = last_tick;
  8710. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8711. if(n <0 || n >= MAX_INVENTORY)
  8712. return;
  8713. if (!pc_useitem(sd,n))
  8714. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  8715. }
  8716. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  8717. /// 00a9 <index>.W <position>.W
  8718. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8719. {
  8720. int index;
  8721. if(pc_isdead(sd)) {
  8722. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8723. return;
  8724. }
  8725. index = RFIFOW(fd,2)-2;
  8726. if (index < 0 || index >= MAX_INVENTORY)
  8727. return; //Out of bounds check.
  8728. if(sd->npc_id) {
  8729. if (!sd->npc_item_flag)
  8730. return;
  8731. } else if (sd->state.storage_flag || sd->sc.opt1)
  8732. ; //You can equip/unequip stuff while storage is open/under status changes
  8733. else if (pc_cant_act2(sd))
  8734. return;
  8735. if(!sd->status.inventory[index].identify) {
  8736. clif_equipitemack(sd,index,0,0); // fail
  8737. return;
  8738. }
  8739. if(!sd->inventory_data[index])
  8740. return;
  8741. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8742. pet_equipitem(sd,index);
  8743. return;
  8744. }
  8745. //Client doesn't send the position for ammo.
  8746. if(sd->inventory_data[index]->type == IT_AMMO)
  8747. pc_equipitem(sd,index,EQP_AMMO);
  8748. else
  8749. pc_equipitem(sd,index,RFIFOW(fd,4));
  8750. }
  8751. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  8752. /// 00ab <index>.W
  8753. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8754. {
  8755. int index;
  8756. if(pc_isdead(sd)) {
  8757. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8758. return;
  8759. }
  8760. if (sd->npc_id) {
  8761. if (!sd->npc_item_flag)
  8762. return;
  8763. } else if (sd->state.storage_flag || sd->sc.opt1)
  8764. ; //You can equip/unequip stuff while storage is open/under status changes
  8765. else if (pc_cant_act2(sd))
  8766. return;
  8767. index = RFIFOW(fd,2)-2;
  8768. pc_unequipitem(sd,index,1);
  8769. }
  8770. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  8771. /// 0090 <id>.L <type>.B
  8772. /// type:
  8773. /// 1 = click
  8774. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8775. {
  8776. struct block_list *bl;
  8777. if(pc_isdead(sd)) {
  8778. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8779. return;
  8780. }
  8781. if (pc_cant_act2(sd))
  8782. return;
  8783. bl = map_id2bl(RFIFOL(fd,2));
  8784. if (!bl) return;
  8785. switch (bl->type) {
  8786. case BL_MOB:
  8787. case BL_PC:
  8788. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8789. break;
  8790. case BL_NPC:
  8791. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8792. npc_click(sd,(TBL_NPC*)bl);
  8793. break;
  8794. }
  8795. }
  8796. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  8797. /// 00c5 <id>.L <type>.B
  8798. /// type:
  8799. /// 0 = buy
  8800. /// 1 = sell
  8801. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8802. {
  8803. if (sd->state.trading)
  8804. return;
  8805. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8806. }
  8807. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  8808. /// 00ca <result>.B
  8809. /// result:
  8810. /// 0 = "The deal has successfully completed."
  8811. /// 1 = "You do not have enough zeny."
  8812. /// 2 = "You are over your Weight Limit."
  8813. /// 3 = "Out of the maximum capacity, you have too many items."
  8814. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  8815. {
  8816. int fd = sd->fd;
  8817. WFIFOHEAD(fd,packet_len(0xca));
  8818. WFIFOW(fd,0) = 0xca;
  8819. WFIFOB(fd,2) = result;
  8820. WFIFOSET(fd,packet_len(0xca));
  8821. }
  8822. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  8823. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  8824. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8825. {
  8826. int n = (RFIFOW(fd,2)-4) /4;
  8827. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8828. int result;
  8829. if( sd->state.trading || !sd->npc_shopid )
  8830. result = 1;
  8831. else
  8832. result = npc_buylist(sd,n,item_list);
  8833. sd->npc_shopid = 0; //Clear shop data.
  8834. clif_npc_buy_result(sd, result);
  8835. }
  8836. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  8837. /// 00cb <result>.B
  8838. /// result:
  8839. /// 0 = "The deal has successfully completed."
  8840. /// 1 = "The deal has failed."
  8841. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  8842. {
  8843. int fd = sd->fd;
  8844. WFIFOHEAD(fd,packet_len(0xcb));
  8845. WFIFOW(fd,0) = 0xcb;
  8846. WFIFOB(fd,2) = result;
  8847. WFIFOSET(fd,packet_len(0xcb));
  8848. }
  8849. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  8850. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  8851. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8852. {
  8853. int fail=0,n;
  8854. unsigned short *item_list;
  8855. n = (RFIFOW(fd,2)-4) /4;
  8856. item_list = (unsigned short*)RFIFOP(fd,4);
  8857. if (sd->state.trading || !sd->npc_shopid)
  8858. fail = 1;
  8859. else
  8860. fail = npc_selllist(sd,n,item_list);
  8861. sd->npc_shopid = 0; //Clear shop data.
  8862. clif_npc_sell_result(sd, fail);
  8863. }
  8864. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  8865. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8866. /// type:
  8867. /// 0 = private
  8868. /// 1 = public
  8869. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8870. {
  8871. int len = RFIFOW(fd,2)-15;
  8872. int limit = RFIFOW(fd,4);
  8873. bool pub = (RFIFOB(fd,6) != 0);
  8874. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8875. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8876. char s_password[CHATROOM_PASS_SIZE];
  8877. char s_title[CHATROOM_TITLE_SIZE];
  8878. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8879. return;
  8880. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8881. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  8882. return;
  8883. }
  8884. if( npc_isnear(&sd->bl) ) {
  8885. // uncomment to send msg_txt.
  8886. //char output[150];
  8887. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  8888. //clif_displaymessage(sd->fd, output);
  8889. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  8890. return;
  8891. }
  8892. if( len <= 0 )
  8893. return; // invalid input
  8894. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8895. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8896. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8897. }
  8898. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  8899. /// 00d9 <chat ID>.L <passwd>.8B
  8900. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8901. {
  8902. int chatid = RFIFOL(fd,2);
  8903. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8904. chat_joinchat(sd,chatid,password);
  8905. }
  8906. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  8907. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  8908. /// type:
  8909. /// 0 = private
  8910. /// 1 = public
  8911. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8912. {
  8913. int len = RFIFOW(fd,2)-15;
  8914. int limit = RFIFOW(fd,4);
  8915. bool pub = (RFIFOB(fd,6) != 0);
  8916. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8917. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8918. char s_password[CHATROOM_PASS_SIZE];
  8919. char s_title[CHATROOM_TITLE_SIZE];
  8920. if( len <= 0 )
  8921. return; // invalid input
  8922. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8923. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8924. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8925. }
  8926. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  8927. /// 00e0 <role>.L <nick>.24B
  8928. /// role:
  8929. /// 0 = owner
  8930. /// 1 = normal
  8931. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8932. {
  8933. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8934. }
  8935. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  8936. /// 00e2 <name>.24B
  8937. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8938. {
  8939. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8940. }
  8941. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  8942. /// 00e3
  8943. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8944. {
  8945. chat_leavechat(sd,0);
  8946. }
  8947. //Handles notifying asker and rejecter of what has just ocurred.
  8948. //Type is used to determine the correct msg_txt to use:
  8949. //0:
  8950. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  8951. {
  8952. const char* msg;
  8953. char output[256];
  8954. // Your request has been rejected by autoreject option.
  8955. msg = msg_txt(sd,392);
  8956. clif_disp_onlyself(sd, msg, strlen(msg));
  8957. //Notice that a request was rejected.
  8958. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  8959. clif_disp_onlyself(tsd, output, strlen(output));
  8960. }
  8961. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  8962. /// 00e4 <account id>.L
  8963. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8964. {
  8965. struct map_session_data *t_sd;
  8966. t_sd = map_id2sd(RFIFOL(fd,2));
  8967. if(!sd->chatID && pc_cant_act(sd))
  8968. return; //You can trade while in a chatroom.
  8969. // @noask [LuzZza]
  8970. if(t_sd && t_sd->state.noask) {
  8971. clif_noask_sub(sd, t_sd, 0);
  8972. return;
  8973. }
  8974. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1) {
  8975. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  8976. return;
  8977. }
  8978. trade_traderequest(sd,t_sd);
  8979. }
  8980. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  8981. /// 00e6 <result>.B
  8982. /// result:
  8983. /// 3 = accepted
  8984. /// 4 = rejected
  8985. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8986. {
  8987. trade_tradeack(sd,RFIFOB(fd,2));
  8988. }
  8989. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  8990. /// 00e8 <index>.W <amount>.L
  8991. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8992. {
  8993. short index = RFIFOW(fd,2);
  8994. int amount = RFIFOL(fd,4);
  8995. if( index == 0 )
  8996. trade_tradeaddzeny(sd, amount);
  8997. else
  8998. trade_tradeadditem(sd, index, (short)amount);
  8999. }
  9000. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9001. /// 00eb
  9002. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9003. {
  9004. trade_tradeok(sd);
  9005. }
  9006. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9007. /// 00ed
  9008. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9009. {
  9010. trade_tradecancel(sd);
  9011. }
  9012. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9013. /// 00ef
  9014. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9015. {
  9016. trade_tradecommit(sd);
  9017. }
  9018. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9019. /// 0118
  9020. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9021. {
  9022. pc_stop_attack(sd);
  9023. }
  9024. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9025. /// 0126 <index>.W <amount>.L
  9026. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  9027. {
  9028. if (pc_istrading(sd))
  9029. return;
  9030. if (!pc_iscarton(sd))
  9031. return;
  9032. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9033. }
  9034. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9035. /// 0127 <index>.W <amount>.L
  9036. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9037. {
  9038. if (!pc_iscarton(sd))
  9039. return;
  9040. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9041. }
  9042. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9043. /// 012a
  9044. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9045. {
  9046. /**
  9047. * Attempts to remove these options when this function is called (will remove all available)
  9048. **/
  9049. #ifdef NEW_CARTS
  9050. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9051. if( sd->sc.data[SC_PUSH_CART] )
  9052. pc_setcart(sd,0);
  9053. #else
  9054. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9055. #endif
  9056. }
  9057. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9058. /// 01af <num>.W
  9059. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9060. {// TODO: State tracking?
  9061. int type;
  9062. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  9063. return;
  9064. type = (int)RFIFOW(fd,2);
  9065. #ifdef NEW_CARTS
  9066. if( (type == 9 && sd->status.base_level > 131) ||
  9067. (type == 8 && sd->status.base_level > 121) ||
  9068. (type == 7 && sd->status.base_level > 111) ||
  9069. (type == 6 && sd->status.base_level > 101) ||
  9070. (type == 5 && sd->status.base_level > 90) ||
  9071. (type == 4 && sd->status.base_level > 80) ||
  9072. (type == 3 && sd->status.base_level > 65) ||
  9073. (type == 2 && sd->status.base_level > 40) ||
  9074. (type == 1))
  9075. #else
  9076. if( (type == 5 && sd->status.base_level > 90) ||
  9077. (type == 4 && sd->status.base_level > 80) ||
  9078. (type == 3 && sd->status.base_level > 65) ||
  9079. (type == 2 && sd->status.base_level > 40) ||
  9080. (type == 1))
  9081. #endif
  9082. pc_setcart(sd,type);
  9083. }
  9084. /// Request to increase status (CZ_STATUS_CHANGE).
  9085. /// 00bb <status id>.W <amount>.B
  9086. /// status id:
  9087. /// SP_STR ~ SP_LUK
  9088. /// amount:
  9089. /// client sends always 1 for this, even when using /str+ and
  9090. /// the like
  9091. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  9092. {
  9093. pc_statusup(sd,RFIFOW(fd,2));
  9094. }
  9095. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9096. /// 0112 <skill id>.W
  9097. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9098. {
  9099. pc_skillup(sd,RFIFOW(fd,2));
  9100. }
  9101. 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)
  9102. {
  9103. int lv;
  9104. if( !hd )
  9105. return;
  9106. if( skillnotok_hom(skill_id, hd) )
  9107. return;
  9108. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9109. target_id = hd->bl.id;
  9110. if( hd->ud.skilltimer != INVALID_TIMER )
  9111. {
  9112. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9113. }
  9114. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9115. return;
  9116. lv = merc_hom_checkskill(hd, skill_id);
  9117. if( skill_lv > lv )
  9118. skill_lv = lv;
  9119. if( skill_lv )
  9120. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9121. }
  9122. 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)
  9123. {
  9124. int lv;
  9125. if( !hd )
  9126. return;
  9127. if( skillnotok_hom(skill_id, hd) )
  9128. return;
  9129. if( hd->ud.skilltimer != INVALID_TIMER ) {
  9130. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9131. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  9132. return;
  9133. if( hd->sc.data[SC_BASILICA] )
  9134. return;
  9135. lv = merc_hom_checkskill(hd, skill_id);
  9136. if( skill_lv > lv )
  9137. skill_lv = lv;
  9138. if( skill_lv )
  9139. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9140. }
  9141. 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)
  9142. {
  9143. int lv;
  9144. if( !md )
  9145. return;
  9146. if( skillnotok_mercenary(skill_id, md) )
  9147. return;
  9148. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  9149. target_id = md->bl.id;
  9150. if( md->ud.skilltimer != INVALID_TIMER )
  9151. {
  9152. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9153. }
  9154. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9155. return;
  9156. lv = mercenary_checkskill(md, skill_id);
  9157. if( skill_lv > lv )
  9158. skill_lv = lv;
  9159. if( skill_lv )
  9160. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9161. }
  9162. 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)
  9163. {
  9164. int lv;
  9165. if( !md )
  9166. return;
  9167. if( skillnotok_mercenary(skill_id, md) )
  9168. return;
  9169. if( md->ud.skilltimer != INVALID_TIMER )
  9170. return;
  9171. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9172. {
  9173. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9174. return;
  9175. }
  9176. if( md->sc.data[SC_BASILICA] )
  9177. return;
  9178. lv = mercenary_checkskill(md, skill_id);
  9179. if( skill_lv > lv )
  9180. skill_lv = lv;
  9181. if( skill_lv )
  9182. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9183. }
  9184. /// Request to use a targeted skill.
  9185. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9186. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9187. /// There are various variants of this packet, some of them have padding between fields.
  9188. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9189. {
  9190. uint16 skill_id, skill_lv;
  9191. int tmp, target_id;
  9192. unsigned int tick = gettick();
  9193. skill_lv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9194. skill_id = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9195. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  9196. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9197. tmp = skill_get_inf(skill_id);
  9198. if (tmp&INF_GROUND_SKILL || !tmp)
  9199. return; //Using a ground/passive skill on a target? WRONG.
  9200. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9201. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9202. return;
  9203. }
  9204. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9205. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9206. return;
  9207. }
  9208. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9209. sd->idletime = last_tick;
  9210. if( sd->npc_id ){
  9211. #ifdef RENEWAL
  9212. clif_msg(sd, USAGE_FAIL); // TODO look for the client date that has this message.
  9213. #endif
  9214. return;
  9215. }
  9216. if( pc_cant_act(sd) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) )
  9217. return;
  9218. if( pc_issit(sd) )
  9219. return;
  9220. if( skillnotok(skill_id, sd) )
  9221. return;
  9222. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9223. target_id = sd->bl.id; // never trust the client
  9224. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9225. target_id = sd->bl.id;
  9226. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9227. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9228. return;
  9229. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9230. if( sd->skillitem != skill_id ) {
  9231. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9232. return;
  9233. }
  9234. }
  9235. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9236. return;
  9237. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9238. return; // On basilica only caster can use Basilica again to stop it.
  9239. if( sd->menuskill_id ) {
  9240. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9241. clif_menuskill_clear(sd); //Cancel pet capture.
  9242. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9243. return; //Can't use skills while a menu is open.
  9244. }
  9245. if( sd->skillitem == skill_id ) {
  9246. if( skill_lv != sd->skillitemlv )
  9247. skill_lv = sd->skillitemlv;
  9248. if( !(tmp&INF_SELF_SKILL) )
  9249. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  9250. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9251. return;
  9252. }
  9253. sd->skillitem = sd->skillitemlv = 0;
  9254. if( skill_id >= GD_SKILLBASE ) {
  9255. if( sd->state.gmaster_flag )
  9256. skill_lv = guild_checkskill(sd->state.gmaster_flag, skill_id);
  9257. else
  9258. skill_lv = 0;
  9259. } else {
  9260. tmp = pc_checkskill(sd, skill_id);
  9261. if( skill_lv > tmp )
  9262. skill_lv = tmp;
  9263. }
  9264. pc_delinvincibletimer(sd);
  9265. if( skill_lv )
  9266. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9267. }
  9268. /*==========================================
  9269. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9270. *------------------------------------------*/
  9271. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9272. {
  9273. unsigned int tick = gettick();
  9274. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  9275. return; //Using a target skill on the ground? WRONG.
  9276. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9277. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9278. return;
  9279. }
  9280. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9281. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9282. return;
  9283. }
  9284. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9285. sd->idletime = last_tick;
  9286. if( skillnotok(skill_id, sd) )
  9287. return;
  9288. if( skillmoreinfo != -1 ) {
  9289. if( pc_issit(sd) ) {
  9290. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9291. return;
  9292. }
  9293. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9294. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9295. }
  9296. if( sd->ud.skilltimer != INVALID_TIMER )
  9297. return;
  9298. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9299. if( sd->skillitem != skill_id ) {
  9300. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9301. return;
  9302. }
  9303. }
  9304. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  9305. return;
  9306. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9307. return; // On basilica only caster can use Basilica again to stop it.
  9308. if( sd->menuskill_id ) {
  9309. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9310. clif_menuskill_clear(sd); //Cancel pet capture.
  9311. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9312. return; //Can't use skills while a menu is open.
  9313. }
  9314. pc_delinvincibletimer(sd);
  9315. if( sd->skillitem == skill_id ) {
  9316. if( skill_lv != sd->skillitemlv )
  9317. skill_lv = sd->skillitemlv;
  9318. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9319. } else {
  9320. int lv;
  9321. sd->skillitem = sd->skillitemlv = 0;
  9322. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  9323. if( skill_lv > lv )
  9324. skill_lv = lv;
  9325. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9326. }
  9327. }
  9328. }
  9329. /// Request to use a ground skill.
  9330. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9331. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9332. /// There are various variants of this packet, some of them have padding between fields.
  9333. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9334. {
  9335. if (pc_cant_act(sd))
  9336. return;
  9337. if (pc_issit(sd))
  9338. return;
  9339. clif_parse_UseSkillToPosSub(fd, sd,
  9340. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  9341. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  9342. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9343. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9344. -1 //Skill more info.
  9345. );
  9346. }
  9347. /// Request to use a ground skill with text.
  9348. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9349. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9350. /// There are various variants of this packet, some of them have padding between fields.
  9351. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9352. {
  9353. if (pc_cant_act(sd))
  9354. return;
  9355. if (pc_issit(sd))
  9356. return;
  9357. clif_parse_UseSkillToPosSub(fd, sd,
  9358. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  9359. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  9360. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  9361. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  9362. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  9363. );
  9364. }
  9365. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9366. /// 011b <skill id>.W <map name>.16B
  9367. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9368. {
  9369. uint16 skill_id = RFIFOW(fd,2);
  9370. char map_name[MAP_NAME_LENGTH];
  9371. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  9372. if(skill_id != sd->menuskill_id)
  9373. return;
  9374. if( pc_cant_act(sd) ) {
  9375. clif_menuskill_clear(sd);
  9376. return;
  9377. }
  9378. pc_delinvincibletimer(sd);
  9379. skill_castend_map(sd,skill_id,map_name);
  9380. }
  9381. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9382. /// 011d
  9383. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9384. {
  9385. if (!pc_isdead(sd))
  9386. pc_memo(sd,-1);
  9387. }
  9388. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9389. /// 018e <name id>.W { <material id>.W }*3
  9390. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9391. {
  9392. switch( sd->menuskill_id ) {
  9393. case -1:
  9394. case AM_PHARMACY:
  9395. case RK_RUNEMASTERY:
  9396. case GC_RESEARCHNEWPOISON:
  9397. break;
  9398. default:
  9399. return;
  9400. }
  9401. if (pc_istrading(sd)) {
  9402. //Make it fail to avoid shop exploits where you sell something different than you see.
  9403. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9404. clif_menuskill_clear(sd);
  9405. return;
  9406. }
  9407. if( skill_can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9408. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9409. clif_menuskill_clear(sd);
  9410. }
  9411. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9412. /// 025b <mk type>.W <name id>.W
  9413. /// mk type:
  9414. /// 1 = cooking
  9415. /// 2 = arrow
  9416. /// 3 = elemental
  9417. /// 4 = GN_MIX_COOKING
  9418. /// 5 = GN_MAKEBOMB
  9419. /// 6 = GN_S_PHARMACY
  9420. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9421. int type = RFIFOW(fd,2);
  9422. int nameid = RFIFOW(fd,4);
  9423. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9424. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9425. return;
  9426. if (pc_istrading(sd)) {
  9427. //Make it fail to avoid shop exploits where you sell something different than you see.
  9428. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9429. clif_menuskill_clear(sd);
  9430. return;
  9431. }
  9432. if( skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9433. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9434. clif_menuskill_clear(sd);
  9435. }
  9436. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9437. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9438. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9439. {
  9440. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9441. return;
  9442. if (pc_istrading(sd)) {
  9443. //Make it fail to avoid shop exploits where you sell something different than you see.
  9444. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9445. clif_menuskill_clear(sd);
  9446. return;
  9447. }
  9448. skill_repairweapon(sd,RFIFOW(fd,2));
  9449. clif_menuskill_clear(sd);
  9450. }
  9451. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9452. /// 0222 <index>.L
  9453. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9454. {
  9455. int idx;
  9456. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9457. return;
  9458. if (pc_istrading(sd)) {
  9459. //Make it fail to avoid shop exploits where you sell something different than you see.
  9460. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9461. clif_menuskill_clear(sd);
  9462. return;
  9463. }
  9464. idx = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9465. skill_weaponrefine(sd, idx-2);
  9466. clif_menuskill_clear(sd);
  9467. }
  9468. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9469. /// 00b8 <npc id>.L <choice>.B
  9470. /// choice:
  9471. /// 1~254 = menu item
  9472. /// 255 = cancel
  9473. /// NOTE: If there were more than 254 items in the list, choice
  9474. /// overflows to choice%256.
  9475. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9476. {
  9477. int npc_id = RFIFOL(fd,2);
  9478. uint8 select = RFIFOB(fd,6);
  9479. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9480. #ifdef SECURE_NPCTIMEOUT
  9481. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9482. #endif
  9483. TBL_NPC* nd = map_id2nd(npc_id);
  9484. 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);
  9485. clif_GM_kick(NULL,sd);
  9486. #ifdef SECURE_NPCTIMEOUT
  9487. }
  9488. #endif
  9489. return;
  9490. }
  9491. sd->npc_menu = select;
  9492. npc_scriptcont(sd,npc_id, false);
  9493. }
  9494. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9495. /// 00b9 <npc id>.L
  9496. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9497. {
  9498. npc_scriptcont(sd,RFIFOL(fd,2), false);
  9499. }
  9500. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9501. /// 0143 <npc id>.L <value>.L
  9502. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9503. {
  9504. int npcid = RFIFOL(fd,2);
  9505. int amount = (int)RFIFOL(fd,6);
  9506. sd->npc_amount = amount;
  9507. npc_scriptcont(sd, npcid, false);
  9508. }
  9509. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9510. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9511. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9512. {
  9513. int message_len = RFIFOW(fd,2)-8;
  9514. int npcid = RFIFOL(fd,4);
  9515. const char* message = (char*)RFIFOP(fd,8);
  9516. if( message_len <= 0 )
  9517. return; // invalid input
  9518. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9519. npc_scriptcont(sd, npcid, false);
  9520. }
  9521. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9522. /// 0146 <npc id>.L
  9523. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9524. {
  9525. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9526. return;
  9527. npc_scriptcont(sd, RFIFOL(fd,2), true);
  9528. }
  9529. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9530. /// 0178 <index>.W
  9531. /// index:
  9532. /// -1 = cancel
  9533. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9534. {
  9535. short idx = RFIFOW(fd,2);
  9536. if (sd->menuskill_id != MC_IDENTIFY)
  9537. return;
  9538. if( idx == -1 ) {// cancel pressed
  9539. clif_menuskill_clear(sd);
  9540. return;
  9541. }
  9542. skill_identify(sd,idx-2);
  9543. clif_menuskill_clear(sd);
  9544. }
  9545. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9546. /// 01ae <name id>.W
  9547. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9548. {
  9549. if (pc_istrading(sd)) {
  9550. //Make it fail to avoid shop exploits where you sell something different than you see.
  9551. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9552. clif_menuskill_clear(sd);
  9553. return;
  9554. }
  9555. switch( sd->menuskill_id ) {
  9556. case AC_MAKINGARROW:
  9557. skill_arrow_create(sd,RFIFOW(fd,2));
  9558. break;
  9559. case SA_CREATECON:
  9560. skill_produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9561. break;
  9562. case WL_READING_SB:
  9563. skill_spellbook(sd,RFIFOW(fd,2));
  9564. break;
  9565. case GC_POISONINGWEAPON:
  9566. skill_poisoningweapon(sd,RFIFOW(fd,2));
  9567. break;
  9568. case NC_MAGICDECOY:
  9569. skill_magicdecoy(sd,RFIFOW(fd,2));
  9570. break;
  9571. }
  9572. clif_menuskill_clear(sd);
  9573. }
  9574. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  9575. /// 01ce <skill id>.L
  9576. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9577. {
  9578. if (sd->menuskill_id != SA_AUTOSPELL)
  9579. return;
  9580. skill_autospell(sd,RFIFOL(fd,2));
  9581. clif_menuskill_clear(sd);
  9582. }
  9583. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  9584. /// 017a <card index>.W
  9585. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9586. {
  9587. if (sd->state.trading != 0)
  9588. return;
  9589. clif_use_card(sd,RFIFOW(fd,2)-2);
  9590. }
  9591. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  9592. /// 017c <card index>.W <equip index>.W
  9593. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9594. {
  9595. if (sd->state.trading != 0)
  9596. return;
  9597. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9598. }
  9599. /// Request of character's name by char ID.
  9600. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  9601. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  9602. /// There are various variants of this packet, some of them have padding between fields.
  9603. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9604. {
  9605. int charid;
  9606. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9607. map_reqnickdb(sd, charid);
  9608. }
  9609. /// /resetskill /resetstate (CZ_RESET).
  9610. /// Request to reset stats or skills.
  9611. /// 0197 <type>.W
  9612. /// type:
  9613. /// 0 = state
  9614. /// 1 = skill
  9615. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  9616. char cmd[15];
  9617. if( RFIFOW(fd,2) )
  9618. sprintf(cmd,"%cresetskill",atcommand_symbol);
  9619. else
  9620. sprintf(cmd,"%cresetstat",atcommand_symbol);
  9621. is_atcommand(fd, sd, cmd, 1);
  9622. }
  9623. /// /lb /nlb (CZ_LOCALBROADCAST).
  9624. /// Request to broadcast a message on current map.
  9625. /// 019c <packet len>.W <text>.?B
  9626. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9627. {
  9628. char command[CHAT_SIZE_MAX+16];
  9629. char* msg = (char*)RFIFOP(fd,4);
  9630. unsigned int len = RFIFOW(fd,2)-4;
  9631. // as the length varies depending on the command used, just block unreasonably long strings
  9632. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9633. sprintf(command, "%clkami %s", atcommand_symbol, msg);
  9634. is_atcommand(fd, sd, command, 1);
  9635. }
  9636. /// Request to move an item from inventory to storage.
  9637. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  9638. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  9639. /// There are various variants of this packet, some of them have padding between fields.
  9640. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9641. {
  9642. int item_index, item_amount;
  9643. if (pc_istrading(sd))
  9644. return;
  9645. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9646. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9647. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9648. return;
  9649. if (sd->state.storage_flag == 1)
  9650. storage_storageadd(sd, item_index, item_amount);
  9651. else
  9652. if (sd->state.storage_flag == 2)
  9653. storage_guild_storageadd(sd, item_index, item_amount);
  9654. }
  9655. /// Request to move an item from storage to inventory.
  9656. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  9657. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  9658. /// There are various variants of this packet, some of them have padding between fields.
  9659. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9660. {
  9661. int item_index, item_amount;
  9662. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9663. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9664. if (sd->state.storage_flag == 1)
  9665. storage_storageget(sd, item_index, item_amount);
  9666. else if(sd->state.storage_flag == 2)
  9667. storage_guild_storageget(sd, item_index, item_amount);
  9668. }
  9669. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  9670. /// 0129 <index>.W <amount>.L
  9671. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9672. {
  9673. if( sd->state.vending )
  9674. return;
  9675. if (!pc_iscarton(sd))
  9676. return;
  9677. if (sd->state.storage_flag == 1)
  9678. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9679. else if (sd->state.storage_flag == 2)
  9680. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9681. }
  9682. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  9683. /// 0128 <index>.W <amount>.L
  9684. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9685. {
  9686. if( sd->state.vending )
  9687. return;
  9688. if (!pc_iscarton(sd))
  9689. return;
  9690. if (sd->state.storage_flag == 1)
  9691. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9692. else
  9693. if (sd->state.storage_flag == 2)
  9694. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9695. }
  9696. /// Request to close storage (CZ_CLOSE_STORE).
  9697. /// 00f7
  9698. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9699. {
  9700. if( sd->state.storage_flag == 1 )
  9701. storage_storageclose(sd);
  9702. else
  9703. if( sd->state.storage_flag == 2 )
  9704. storage_guild_storageclose(sd);
  9705. }
  9706. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  9707. /// 023a <info>.W
  9708. /// info:
  9709. /// 0 = password has not been set yet
  9710. /// 1 = storage is password-protected
  9711. /// 8 = too many wrong passwords
  9712. /// ? = ignored
  9713. /// NOTE: This packet is only available on certain non-kRO clients.
  9714. void clif_storagepassword(struct map_session_data* sd, short info)
  9715. {
  9716. int fd = sd->fd;
  9717. WFIFOHEAD(fd,packet_len(0x23a));
  9718. WFIFOW(fd,0) = 0x23a;
  9719. WFIFOW(fd,2) = info;
  9720. WFIFOSET(fd,packet_len(0x23a));
  9721. }
  9722. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  9723. /// 023b <type>.W <password>.16B <new password>.16B
  9724. /// type:
  9725. /// 2 = change password
  9726. /// 3 = check password
  9727. /// NOTE: This packet is only available on certain non-kRO clients.
  9728. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9729. {
  9730. //TODO
  9731. }
  9732. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  9733. /// 023c <result>.W <error count>.W
  9734. /// result:
  9735. /// 4 = password change success
  9736. /// 5 = password change failure
  9737. /// 6 = password check success
  9738. /// 7 = password check failure
  9739. /// 8 = too many wrong passwords
  9740. /// ? = ignored
  9741. /// NOTE: This packet is only available on certain non-kRO clients.
  9742. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  9743. {
  9744. int fd = sd->fd;
  9745. WFIFOHEAD(fd,packet_len(0x23c));
  9746. WFIFOW(fd,0) = 0x23c;
  9747. WFIFOW(fd,2) = result;
  9748. WFIFOW(fd,4) = error_count;
  9749. WFIFOSET(fd,packet_len(0x23c));
  9750. }
  9751. /// Party creation request
  9752. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  9753. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  9754. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9755. {
  9756. char* name = (char*)RFIFOP(fd,2);
  9757. name[NAME_LENGTH-1] = '\0';
  9758. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  9759. clif_displaymessage(fd, msg_txt(sd,227));
  9760. return;
  9761. }
  9762. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  9763. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9764. return;
  9765. }
  9766. party_create(sd,name,0,0);
  9767. }
  9768. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9769. {
  9770. char* name = (char*)RFIFOP(fd,2);
  9771. int item1 = RFIFOB(fd,26);
  9772. int item2 = RFIFOB(fd,27);
  9773. name[NAME_LENGTH-1] = '\0';
  9774. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  9775. clif_displaymessage(fd, msg_txt(sd,227));
  9776. return;
  9777. }
  9778. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 ) {
  9779. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  9780. return;
  9781. }
  9782. party_create(sd,name,item1,item2);
  9783. }
  9784. /// Party invitation request
  9785. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  9786. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  9787. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9788. {
  9789. struct map_session_data *t_sd;
  9790. if(map[sd->bl.m].flag.partylock) {// Party locked.
  9791. clif_displaymessage(fd, msg_txt(sd,227));
  9792. return;
  9793. }
  9794. t_sd = map_id2sd(RFIFOL(fd,2));
  9795. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  9796. clif_noask_sub(sd, t_sd, 1);
  9797. return;
  9798. }
  9799. party_invite(sd, t_sd);
  9800. }
  9801. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9802. {
  9803. struct map_session_data *t_sd;
  9804. char *name = (char*)RFIFOP(fd,2);
  9805. name[NAME_LENGTH-1] = '\0';
  9806. if(map[sd->bl.m].flag.partylock) {// Party locked.
  9807. clif_displaymessage(fd, msg_txt(sd,227));
  9808. return;
  9809. }
  9810. t_sd = map_nick2sd(name);
  9811. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  9812. clif_noask_sub(sd, t_sd, 1);
  9813. return;
  9814. }
  9815. party_invite(sd, t_sd);
  9816. }
  9817. /// Party invitation reply
  9818. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  9819. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  9820. /// flag:
  9821. /// 0 = reject
  9822. /// 1 = accept
  9823. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9824. {
  9825. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9826. }
  9827. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9828. {
  9829. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9830. }
  9831. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  9832. /// 0100
  9833. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9834. {
  9835. if(map[sd->bl.m].flag.partylock) { //Guild locked.
  9836. clif_displaymessage(fd, msg_txt(sd,227));
  9837. return;
  9838. }
  9839. party_leave(sd);
  9840. }
  9841. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  9842. /// 0103 <account id>.L <char name>.24B
  9843. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9844. {
  9845. if(map[sd->bl.m].flag.partylock) { //Guild locked.
  9846. clif_displaymessage(fd, msg_txt(sd,227));
  9847. return;
  9848. }
  9849. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9850. }
  9851. /// Request to change party options.
  9852. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  9853. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  9854. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9855. {
  9856. struct party_data *p;
  9857. int i;
  9858. if( !sd->status.party_id )
  9859. return;
  9860. p = party_search(sd->status.party_id);
  9861. if( p == NULL )
  9862. return;
  9863. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9864. if( i == MAX_PARTY )
  9865. return; //Shouldn't happen
  9866. if( !p->party.member[i].leader )
  9867. return;
  9868. #if PACKETVER < 20090603
  9869. //Client can't change the item-field
  9870. party_changeoption(sd, RFIFOL(fd,2), p->party.item);
  9871. #else
  9872. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  9873. #endif
  9874. }
  9875. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  9876. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  9877. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9878. {
  9879. const char* text = (char*)RFIFOP(fd,4);
  9880. int textlen = RFIFOW(fd,2) - 4;
  9881. char *name, *message;
  9882. int namelen, messagelen;
  9883. // validate packet and retrieve name and message
  9884. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9885. return;
  9886. if( is_atcommand(fd, sd, message, 1) )
  9887. return;
  9888. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9889. return;
  9890. if( battle_config.min_chat_delay )
  9891. { //[Skotlex]
  9892. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9893. return;
  9894. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9895. }
  9896. // Reset idle time when using party chat.
  9897. sd->idletime = last_tick;
  9898. party_send_message(sd, text, textlen);
  9899. }
  9900. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  9901. /// 07da <account id>.L
  9902. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9903. {
  9904. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9905. }
  9906. /// Party Booking in KRO [Spiria]
  9907. ///
  9908. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  9909. /// 0802 <level>.W <map id>.W { <job>.W }*6
  9910. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9911. {
  9912. short level = RFIFOW(fd,2);
  9913. short mapid = RFIFOW(fd,4);
  9914. short job[PARTY_BOOKING_JOBS];
  9915. int i;
  9916. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9917. job[i] = RFIFOB(fd,6+i*2);
  9918. party_booking_register(sd, level, mapid, job);
  9919. }
  9920. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  9921. /// 0803 <result>.W
  9922. /// result:
  9923. /// 0 = success
  9924. /// 1 = failure
  9925. /// 2 = already registered
  9926. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9927. {
  9928. int fd = sd->fd;
  9929. WFIFOHEAD(fd,packet_len(0x803));
  9930. WFIFOW(fd,0) = 0x803;
  9931. WFIFOW(fd,2) = flag;
  9932. WFIFOSET(fd,packet_len(0x803));
  9933. }
  9934. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  9935. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  9936. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9937. {
  9938. short level = RFIFOW(fd,2);
  9939. short mapid = RFIFOW(fd,4);
  9940. short job = RFIFOW(fd,6);
  9941. unsigned long lastindex = RFIFOL(fd,8);
  9942. short resultcount = RFIFOW(fd,12);
  9943. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9944. }
  9945. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  9946. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  9947. /// more results:
  9948. /// 0 = no
  9949. /// 1 = yes
  9950. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9951. {
  9952. int i, j;
  9953. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9954. struct party_booking_ad_info *pb_ad;
  9955. WFIFOHEAD(fd,size*count + 5);
  9956. WFIFOW(fd,0) = 0x805;
  9957. WFIFOW(fd,2) = size*count + 5;
  9958. WFIFOB(fd,4) = more_result;
  9959. for(i=0; i<count; i++)
  9960. {
  9961. pb_ad = results[i];
  9962. WFIFOL(fd,i*size+5) = pb_ad->index;
  9963. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9964. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  9965. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9966. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9967. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9968. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9969. }
  9970. WFIFOSET(fd,WFIFOW(fd,2));
  9971. }
  9972. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  9973. /// 0806
  9974. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9975. {
  9976. if(party_booking_delete(sd))
  9977. clif_PartyBookingDeleteAck(sd, 0);
  9978. }
  9979. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  9980. /// 0807 <result>.W
  9981. /// result:
  9982. /// 0 = success
  9983. /// 1 = success (auto-removed expired ad)
  9984. /// 2 = failure
  9985. /// 3 = nothing registered
  9986. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9987. {
  9988. int fd = sd->fd;
  9989. WFIFOHEAD(fd,packet_len(0x807));
  9990. WFIFOW(fd,0) = 0x807;
  9991. WFIFOW(fd,2) = flag;
  9992. WFIFOSET(fd,packet_len(0x807));
  9993. }
  9994. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  9995. /// 0808 { <job>.W }*6
  9996. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9997. {
  9998. short job[PARTY_BOOKING_JOBS];
  9999. int i;
  10000. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10001. job[i] = RFIFOW(fd,2+i*2);
  10002. party_booking_update(sd, job);
  10003. }
  10004. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10005. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10006. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10007. {
  10008. int i;
  10009. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10010. if(pb_ad == NULL) return;
  10011. WBUFW(buf,0) = 0x809;
  10012. WBUFL(buf,2) = pb_ad->index;
  10013. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10014. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  10015. WBUFW(buf,34) = pb_ad->p_detail.level;
  10016. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10017. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10018. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10019. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10020. }
  10021. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10022. /// 080a <index>.L { <job>.W }*6
  10023. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10024. {
  10025. int i;
  10026. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10027. if(pb_ad == NULL) return;
  10028. WBUFW(buf,0) = 0x80a;
  10029. WBUFL(buf,2) = pb_ad->index;
  10030. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10031. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10032. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10033. }
  10034. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10035. /// 080b <index>.L
  10036. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10037. {
  10038. uint8 buf[6];
  10039. WBUFW(buf,0) = 0x80b;
  10040. WBUFL(buf,2) = index;
  10041. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10042. }
  10043. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10044. /// 012e
  10045. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10046. {
  10047. vending_closevending(sd);
  10048. }
  10049. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10050. /// 0130 <account id>.L
  10051. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10052. {
  10053. if( sd->npc_id ) {// using an NPC
  10054. return;
  10055. }
  10056. vending_vendinglistreq(sd,RFIFOL(fd,2));
  10057. }
  10058. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10059. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10060. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  10061. {
  10062. int len = (int)RFIFOW(fd,2) - 8;
  10063. int id = (int)RFIFOL(fd,4);
  10064. const uint8* data = (uint8*)RFIFOP(fd,8);
  10065. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  10066. // whether it fails or not, the buy window is closed
  10067. sd->vended_id = 0;
  10068. }
  10069. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10070. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10071. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  10072. {
  10073. int len = (int)RFIFOW(fd,2) - 12;
  10074. int aid = (int)RFIFOL(fd,4);
  10075. int uid = (int)RFIFOL(fd,8);
  10076. const uint8* data = (uint8*)RFIFOP(fd,12);
  10077. vending_purchasereq(sd, aid, uid, data, len/4);
  10078. // whether it fails or not, the buy window is closed
  10079. sd->vended_id = 0;
  10080. }
  10081. /// Confirm or cancel the shop preparation window.
  10082. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10083. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10084. /// result:
  10085. /// 0 = canceled
  10086. /// 1 = open
  10087. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  10088. {
  10089. short len = (short)RFIFOW(fd,2) - 85;
  10090. const char* message = (char*)RFIFOP(fd,4);
  10091. bool flag = (bool)RFIFOB(fd,84);
  10092. const uint8* data = (uint8*)RFIFOP(fd,85);
  10093. if( !flag )
  10094. sd->state.prevend = 0;
  10095. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  10096. return;
  10097. if( map[sd->bl.m].flag.novending ) {
  10098. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  10099. return;
  10100. }
  10101. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  10102. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  10103. return;
  10104. }
  10105. if( message[0] == '\0' ) // invalid input
  10106. return;
  10107. vending_openvending(sd, message, data, len/8);
  10108. }
  10109. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10110. /// 0165 <char id>.L <guild name>.24B
  10111. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  10112. {
  10113. char* name = (char*)RFIFOP(fd,6);
  10114. name[NAME_LENGTH-1] = '\0';
  10115. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10116. clif_displaymessage(fd, msg_txt(sd,228));
  10117. return;
  10118. }
  10119. guild_create(sd, name);
  10120. }
  10121. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10122. /// 014d
  10123. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10124. {
  10125. clif_guild_masterormember(sd);
  10126. }
  10127. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10128. /// 014f <type>.L
  10129. /// type:
  10130. /// 0 = basic info
  10131. /// 1 = member manager
  10132. /// 2 = positions
  10133. /// 3 = skills
  10134. /// 4 = expulsion list
  10135. /// 5 = unknown (GM_ALLGUILDLIST)
  10136. /// 6 = notice
  10137. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  10138. {
  10139. if( !sd->status.guild_id && !sd->bg_id )
  10140. return;
  10141. switch( RFIFOL(fd,2) )
  10142. {
  10143. case 0: // Basic Information Guild, hostile alliance information
  10144. clif_guild_basicinfo(sd);
  10145. clif_guild_allianceinfo(sd);
  10146. break;
  10147. case 1: // Members list, list job title
  10148. clif_guild_positionnamelist(sd);
  10149. clif_guild_memberlist(sd);
  10150. break;
  10151. case 2: // List job title, title information list
  10152. clif_guild_positionnamelist(sd);
  10153. clif_guild_positioninfolist(sd);
  10154. break;
  10155. case 3: // Skill list
  10156. clif_guild_skillinfo(sd);
  10157. break;
  10158. case 4: // Expulsion list
  10159. clif_guild_expulsionlist(sd);
  10160. break;
  10161. default:
  10162. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  10163. break;
  10164. }
  10165. }
  10166. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  10167. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  10168. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  10169. {
  10170. int i;
  10171. if(!sd->state.gmaster_flag)
  10172. return;
  10173. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  10174. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  10175. }
  10176. }
  10177. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  10178. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  10179. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  10180. {
  10181. int i;
  10182. if(!sd->state.gmaster_flag)
  10183. return;
  10184. for(i=4;i<RFIFOW(fd,2);i+=12){
  10185. guild_change_memberposition(sd->status.guild_id,
  10186. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  10187. }
  10188. }
  10189. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  10190. /// 0151 <guild id>.L
  10191. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  10192. {
  10193. struct guild* g;
  10194. int guild_id = RFIFOL(fd,2);
  10195. if( (g = guild_search(guild_id)) != NULL )
  10196. clif_guild_emblem(sd,g);
  10197. }
  10198. /// Validates data of a guild emblem (compressed bitmap)
  10199. static bool clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  10200. {
  10201. bool success;
  10202. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  10203. unsigned long buf_len = sizeof(buf);
  10204. success = ( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  10205. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  10206. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  10207. && RBUFL(buf,10) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  10208. ;
  10209. return success;
  10210. }
  10211. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  10212. /// 0153 <packet len>.W <emblem data>.?B
  10213. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  10214. {
  10215. unsigned long emblem_len = RFIFOW(fd,2)-4;
  10216. const uint8* emblem = RFIFOP(fd,4);
  10217. if( !emblem_len || !sd->state.gmaster_flag )
  10218. return;
  10219. if( !clif_validate_emblem(emblem, emblem_len) )
  10220. {
  10221. 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);
  10222. return;
  10223. }
  10224. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  10225. }
  10226. /// Guild notice update request (CZ_GUILD_NOTICE).
  10227. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  10228. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  10229. {
  10230. int guild_id = RFIFOL(fd,2);
  10231. char* msg1 = (char*)RFIFOP(fd,6);
  10232. char* msg2 = (char*)RFIFOP(fd,66);
  10233. if(!sd->state.gmaster_flag)
  10234. return;
  10235. // compensate for some client defects when using multilanguage mode
  10236. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  10237. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  10238. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  10239. guild_change_notice(sd, guild_id, msg1, msg2);
  10240. }
  10241. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  10242. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  10243. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  10244. {
  10245. struct map_session_data *t_sd;
  10246. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10247. clif_displaymessage(fd, msg_txt(sd,228));
  10248. return;
  10249. }
  10250. t_sd = map_id2sd(RFIFOL(fd,2));
  10251. // @noask [LuzZza]
  10252. if(t_sd && t_sd->state.noask) {
  10253. clif_noask_sub(sd, t_sd, 2);
  10254. return;
  10255. }
  10256. guild_invite(sd,t_sd);
  10257. }
  10258. /// Answer to guild invitation (CZ_JOIN_GUILD).
  10259. /// 016b <guild id>.L <answer>.L
  10260. /// answer:
  10261. /// 0 = refuse
  10262. /// 1 = accept
  10263. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  10264. {
  10265. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10266. }
  10267. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  10268. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  10269. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  10270. {
  10271. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10272. clif_displaymessage(fd, msg_txt(sd,228));
  10273. return;
  10274. }
  10275. if( sd->bg_id ) {
  10276. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  10277. return;
  10278. }
  10279. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10280. }
  10281. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  10282. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  10283. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  10284. {
  10285. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  10286. { // Guild locked.
  10287. clif_displaymessage(fd, msg_txt(sd,228));
  10288. return;
  10289. }
  10290. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  10291. }
  10292. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  10293. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  10294. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  10295. {
  10296. const char* text = (char*)RFIFOP(fd,4);
  10297. int textlen = RFIFOW(fd,2) - 4;
  10298. char *name, *message;
  10299. int namelen, messagelen;
  10300. // validate packet and retrieve name and message
  10301. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10302. return;
  10303. if( is_atcommand(fd, sd, message, 1) )
  10304. return;
  10305. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  10306. return;
  10307. if( battle_config.min_chat_delay )
  10308. { //[Skotlex]
  10309. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  10310. return;
  10311. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  10312. }
  10313. // Reset idle time when using guild chat.
  10314. sd->idletime = last_tick;
  10315. if( sd->bg_id )
  10316. bg_send_message(sd, text, textlen);
  10317. else
  10318. guild_send_message(sd, text, textlen);
  10319. }
  10320. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  10321. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  10322. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  10323. {
  10324. struct map_session_data *t_sd;
  10325. if(!sd->state.gmaster_flag)
  10326. return;
  10327. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10328. clif_displaymessage(fd, msg_txt(sd,228));
  10329. return;
  10330. }
  10331. t_sd = map_id2sd(RFIFOL(fd,2));
  10332. // @noask [LuzZza]
  10333. if(t_sd && t_sd->state.noask) {
  10334. clif_noask_sub(sd, t_sd, 3);
  10335. return;
  10336. }
  10337. guild_reqalliance(sd,t_sd);
  10338. }
  10339. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  10340. /// 0172 <inviter account id>.L <answer>.L
  10341. /// answer:
  10342. /// 0 = refuse
  10343. /// 1 = accept
  10344. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  10345. {
  10346. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10347. }
  10348. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  10349. /// 0183 <opponent guild id>.L <relation>.L
  10350. /// relation:
  10351. /// 0 = Ally
  10352. /// 1 = Enemy
  10353. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  10354. {
  10355. if(!sd->state.gmaster_flag)
  10356. return;
  10357. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10358. clif_displaymessage(fd, msg_txt(sd,228));
  10359. return;
  10360. }
  10361. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10362. }
  10363. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  10364. /// 0180 <account id>.L
  10365. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  10366. {
  10367. struct map_session_data *t_sd;
  10368. if(!sd->state.gmaster_flag)
  10369. return;
  10370. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  10371. clif_displaymessage(fd, msg_txt(sd,228));
  10372. return;
  10373. }
  10374. t_sd = map_id2sd(RFIFOL(fd,2));
  10375. // @noask [LuzZza]
  10376. if(t_sd && t_sd->state.noask) {
  10377. clif_noask_sub(sd, t_sd, 4);
  10378. return;
  10379. }
  10380. guild_opposition(sd,t_sd);
  10381. }
  10382. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  10383. /// 015d <key>.40B
  10384. /// key:
  10385. /// now guild name; might have been (intended) email, since the
  10386. /// field name and size is same as the one in CH_DELETE_CHAR.
  10387. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  10388. {
  10389. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  10390. clif_displaymessage(fd, msg_txt(sd,228));
  10391. return;
  10392. }
  10393. guild_break(sd,(char*)RFIFOP(fd,2));
  10394. }
  10395. /// Pet
  10396. ///
  10397. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  10398. /// 01a1 <type>.B
  10399. /// type:
  10400. /// 0 = pet information
  10401. /// 1 = feed
  10402. /// 2 = performance
  10403. /// 3 = return to egg
  10404. /// 4 = unequip accessory
  10405. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  10406. {
  10407. pet_menu(sd,RFIFOB(fd,2));
  10408. }
  10409. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  10410. /// 019f <id>.L
  10411. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  10412. {
  10413. pet_catch_process2(sd,RFIFOL(fd,2));
  10414. }
  10415. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  10416. /// 01a7 <index>.W
  10417. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  10418. {
  10419. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1) {
  10420. //Forged packet, disconnect them [Kevin]
  10421. clif_authfail_fd(fd, 0);
  10422. return;
  10423. }
  10424. pet_select_egg(sd,RFIFOW(fd,2)-2);
  10425. clif_menuskill_clear(sd);
  10426. }
  10427. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  10428. /// 01a9 <data>.L
  10429. /// data:
  10430. /// is either emotion (@see enum emotion_type) or a compound value
  10431. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  10432. /// entry (given in parentheses) in data\pettalktable.xml
  10433. /// act id:
  10434. /// 0 = feeding
  10435. /// 1 = hunting
  10436. /// 2 = danger
  10437. /// 3 = dead
  10438. /// 4 = normal (stand)
  10439. /// 5 = special performance (perfor_s)
  10440. /// 6 = level up (levelup)
  10441. /// 7 = performance 1 (perfor_1)
  10442. /// 8 = performance 2 (perfor_2)
  10443. /// 9 = performance 3 (perfor_3)
  10444. /// 10 = log-in greeting (connect)
  10445. /// hungry value:
  10446. /// 0 = very hungry (hungry)
  10447. /// 1 = hungry (bit_hungry)
  10448. /// 2 = satisfied (noting)
  10449. /// 3 = stuffed (full)
  10450. /// 4 = full (so_full)
  10451. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  10452. {
  10453. if(sd->pd)
  10454. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  10455. }
  10456. /// Request to change pet's name (CZ_RENAME_PET).
  10457. /// 01a5 <name>.24B
  10458. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  10459. {
  10460. pet_change_name(sd,(char*)RFIFOP(fd,2));
  10461. }
  10462. /// /kill (CZ_DISCONNECT_CHARACTER).
  10463. /// Request to disconnect a character.
  10464. /// 00cc <account id>.L
  10465. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  10466. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  10467. {
  10468. struct block_list *target;
  10469. int tid;
  10470. tid = RFIFOL(fd,2);
  10471. target = map_id2bl(tid);
  10472. if (!target) {
  10473. clif_GM_kickack(sd, 0);
  10474. return;
  10475. }
  10476. switch (target->type) {
  10477. case BL_PC:
  10478. {
  10479. char command[NAME_LENGTH+6];
  10480. sprintf(command, "%ckick %s", atcommand_symbol, status_get_name(target));
  10481. is_atcommand(fd, sd, command, 1);
  10482. }
  10483. break;
  10484. /**
  10485. * This one does not invoke any atcommand, so we need to check for permissions.
  10486. */
  10487. case BL_MOB:
  10488. {
  10489. char command[100];
  10490. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  10491. clif_GM_kickack(sd, 0);
  10492. return;
  10493. }
  10494. sprintf(command, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  10495. log_atcommand(sd, command);
  10496. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  10497. }
  10498. break;
  10499. case BL_NPC:
  10500. {
  10501. char command[NAME_LENGTH+11];
  10502. sprintf(command, "%cunloadnpc %s", atcommand_symbol, status_get_name(target));
  10503. is_atcommand(fd, sd, command, 1);
  10504. }
  10505. break;
  10506. default:
  10507. clif_GM_kickack(sd, 0);
  10508. }
  10509. }
  10510. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  10511. /// Request to disconnect all characters.
  10512. /// 00ce
  10513. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  10514. char cmd[15];
  10515. sprintf(cmd,"%ckickall",atcommand_symbol);
  10516. is_atcommand(fd, sd, cmd, 1);
  10517. }
  10518. /// /remove (CZ_REMOVE_AID).
  10519. /// Request to warp to a character with given login ID.
  10520. /// 01ba <account name>.24B
  10521. /// /shift (CZ_SHIFT).
  10522. /// Request to warp to a character with given name.
  10523. /// 01bb <char name>.24B
  10524. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  10525. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  10526. char *player_name;
  10527. char command[NAME_LENGTH+8];
  10528. player_name = (char*)RFIFOP(fd,2);
  10529. player_name[NAME_LENGTH-1] = '\0';
  10530. sprintf(command, "%cjumpto %s", atcommand_symbol, player_name);
  10531. is_atcommand(fd, sd, command, 1);
  10532. }
  10533. /// /remove (CZ_REMOVE_AID_SSO).
  10534. /// Request to warp to a character with given account ID.
  10535. /// 0843 <account id>.L
  10536. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  10537. {
  10538. int account_id;
  10539. struct map_session_data* pl_sd;
  10540. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10541. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  10542. char command[NAME_LENGTH+8];
  10543. sprintf(command, "%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  10544. is_atcommand(fd, sd, command, 1);
  10545. }
  10546. }
  10547. /// /recall (CZ_RECALL).
  10548. /// Request to summon a player with given login ID to own position.
  10549. /// 01bc <account name>.24B
  10550. /// /summon (CZ_RECALL_GID).
  10551. /// Request to summon a player with given name to own position.
  10552. /// 01bd <char name>.24B
  10553. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  10554. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  10555. char *player_name;
  10556. char command [NAME_LENGTH+8];
  10557. player_name = (char*)RFIFOP(fd,2);
  10558. player_name[NAME_LENGTH-1] = '\0';
  10559. sprintf(command, "%crecall %s", atcommand_symbol, player_name);
  10560. is_atcommand(fd, sd, command, 1);
  10561. }
  10562. /// /recall (CZ_RECALL_SSO).
  10563. /// Request to summon a player with given account ID to own position.
  10564. /// 0842 <account id>.L
  10565. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  10566. {
  10567. int account_id;
  10568. struct map_session_data* pl_sd;
  10569. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  10570. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  10571. char command[NAME_LENGTH+8];
  10572. sprintf(command, "%crecall %s", atcommand_symbol, pl_sd->status.name);
  10573. is_atcommand(fd, sd, command, 1);
  10574. }
  10575. }
  10576. /// /item /monster (CZ_ITEM_CREATE).
  10577. /// Request to make items or spawn monsters.
  10578. /// 013f <item/mob name>.24B
  10579. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10580. {
  10581. char *monster_item_name;
  10582. char command[NAME_LENGTH+10];
  10583. monster_item_name = (char*)RFIFOP(fd,2);
  10584. monster_item_name[NAME_LENGTH-1] = '\0';
  10585. // FIXME: Should look for item first, then for monster.
  10586. // FIXME: /monster takes mob_db Sprite_Name as argument
  10587. if( mobdb_searchname(monster_item_name) ) {
  10588. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand_symbol, monster_item_name);
  10589. is_atcommand(fd, sd, command, 1);
  10590. return;
  10591. }
  10592. // FIXME: Stackables have a quantity of 20.
  10593. // FIXME: Equips are supposed to be unidentified.
  10594. if( itemdb_searchname(monster_item_name) ) {
  10595. snprintf(command, sizeof(command)-1, "%citem %s", atcommand_symbol, monster_item_name);
  10596. is_atcommand(fd, sd, command, 1);
  10597. return;
  10598. }
  10599. }
  10600. /// /hide (CZ_CHANGE_EFFECTSTATE).
  10601. /// 019d <effect state>.L
  10602. /// effect state:
  10603. /// TODO: Any OPTION_* ?
  10604. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  10605. char cmd[6];
  10606. sprintf(cmd,"%chide",atcommand_symbol);
  10607. is_atcommand(fd, sd, cmd, 1);
  10608. }
  10609. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  10610. /// 0149 <account id>.L <type>.B <value>.W
  10611. /// type:
  10612. /// 0 = positive points
  10613. /// 1 = negative points
  10614. /// 2 = self mute (+10 minutes)
  10615. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10616. {
  10617. int id, type, value;
  10618. struct map_session_data *dstsd;
  10619. char command[NAME_LENGTH+15];
  10620. id = RFIFOL(fd,2);
  10621. type = RFIFOB(fd,6);
  10622. value = RFIFOW(fd,7);
  10623. if( type == 0 )
  10624. value = -value;
  10625. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10626. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10627. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  10628. return;
  10629. dstsd = map_id2sd(id);
  10630. if( dstsd == NULL )
  10631. return;
  10632. sprintf(command, "%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  10633. is_atcommand(fd, sd, command, 1);
  10634. }
  10635. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  10636. /// GM adjustment of a player's manner value by -60.
  10637. /// 0212 <char name>.24B
  10638. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10639. {
  10640. char command[NAME_LENGTH+15];
  10641. char *name = (char*)RFIFOP(fd,2);
  10642. name[NAME_LENGTH-1] = '\0';
  10643. sprintf(command, "%cmute %d %s", atcommand_symbol, 60, name);
  10644. is_atcommand(fd, sd, command, 1);
  10645. }
  10646. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  10647. /// 01e0 <account id>.L <account name>.24B
  10648. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname)
  10649. {
  10650. int fd = sd->fd;
  10651. WFIFOHEAD(fd,packet_len(0x1e0));
  10652. WFIFOW(fd,0) = 0x1e0;
  10653. WFIFOL(fd,2) = account_id;
  10654. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  10655. WFIFOSET(fd,packet_len(0x1e0));
  10656. }
  10657. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  10658. /// 01df <account id>.L
  10659. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10660. {
  10661. int account_id = RFIFOL(fd,2);
  10662. //TODO: find out if this works for any player or only for authorized GMs
  10663. clif_account_name(sd, account_id, ""); // insert account name here >_<
  10664. }
  10665. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  10666. /// GM single cell type change request.
  10667. /// 0198 <x>.W <y>.W <type>.W
  10668. /// type:
  10669. /// 0 = not walkable
  10670. /// 1 = walkable
  10671. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10672. {
  10673. int x,y,type;
  10674. if( pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  10675. return;
  10676. x = RFIFOW(fd,2);
  10677. y = RFIFOW(fd,4);
  10678. type = RFIFOW(fd,6);
  10679. map_setgatcell(sd->bl.m,x,y,type);
  10680. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10681. //FIXME: once players leave the map, the client 'forgets' this information.
  10682. }
  10683. /// /in /ex (CZ_SETTING_WHISPER_PC).
  10684. /// Request to allow/deny whispers from a nick.
  10685. /// 00cf <nick>.24B <type>.B
  10686. /// type:
  10687. /// 0 = (/ex nick) deny speech from nick
  10688. /// 1 = (/in nick) allow speech from nick
  10689. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10690. {
  10691. char* nick;
  10692. uint8 type;
  10693. int i;
  10694. nick = (char*)RFIFOP(fd,2); // speed up
  10695. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10696. type = RFIFOB(fd,26);
  10697. if( type == 0 ) { // Add name to ignore list (block)
  10698. if (strcmp(wisp_server_name, nick) == 0) {
  10699. clif_wisexin(sd, type, 1); // fail
  10700. return;
  10701. }
  10702. // try to find a free spot, while checking for duplicates at the same time
  10703. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10704. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  10705. clif_wisexin(sd, type, 2); // too many blocks
  10706. return;
  10707. }
  10708. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  10709. clif_wisexin(sd, type, 0); // Aegis reports success.
  10710. return;
  10711. }
  10712. //Insert in position i
  10713. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10714. } else { // Remove name from ignore list (unblock)
  10715. // find entry
  10716. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10717. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  10718. clif_wisexin(sd, type, 1); // fail
  10719. return;
  10720. }
  10721. // move everything one place down to overwrite removed entry
  10722. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10723. // wipe last entry
  10724. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10725. }
  10726. clif_wisexin(sd, type, 0); // success
  10727. }
  10728. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  10729. /// Request to allow/deny all whispers.
  10730. /// 00d0 <type>.B
  10731. /// type:
  10732. /// 0 = (/exall) deny all speech
  10733. /// 1 = (/inall) allow all speech
  10734. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10735. {
  10736. int type = RFIFOB(fd,2), flag;
  10737. if( type == 0 ) {// Deny all
  10738. if( sd->state.ignoreAll ) {
  10739. flag = 1; // fail
  10740. } else {
  10741. sd->state.ignoreAll = 1;
  10742. flag = 0; // success
  10743. }
  10744. } else {//Unblock everyone
  10745. if( sd->state.ignoreAll ) {
  10746. sd->state.ignoreAll = 0;
  10747. flag = 0; // success
  10748. } else {
  10749. if (sd->ignore[0].name[0] != '\0')
  10750. { //Wipe the ignore list.
  10751. memset(sd->ignore, 0, sizeof(sd->ignore));
  10752. flag = 0; // success
  10753. } else {
  10754. flag = 1; // fail
  10755. }
  10756. }
  10757. }
  10758. clif_wisall(sd, type, flag);
  10759. }
  10760. /// Whisper ignore list (ZC_WHISPER_LIST).
  10761. /// 00d4 <packet len>.W { <char name>.24B }*
  10762. void clif_PMIgnoreList(struct map_session_data* sd)
  10763. {
  10764. int i, fd = sd->fd;
  10765. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  10766. WFIFOW(fd,0) = 0xd4;
  10767. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  10768. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  10769. }
  10770. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  10771. WFIFOSET(fd,WFIFOW(fd,2));
  10772. }
  10773. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  10774. /// 00d3
  10775. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10776. {
  10777. clif_PMIgnoreList(sd);
  10778. }
  10779. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  10780. /// 01e7
  10781. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10782. {
  10783. if (sd->state.doridori) return;
  10784. switch (sd->class_&MAPID_UPPERMASK) {
  10785. case MAPID_SOUL_LINKER:
  10786. case MAPID_STAR_GLADIATOR:
  10787. case MAPID_TAEKWON:
  10788. if (!sd->state.rest)
  10789. break;
  10790. case MAPID_SUPER_NOVICE:
  10791. sd->state.doridori=1;
  10792. break;
  10793. }
  10794. }
  10795. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  10796. /// 01ed
  10797. /// Note: This packet is caused by 7 lines of any text, followed by
  10798. /// the prayer and an another line of any text. The prayer is
  10799. /// defined by lines 790~793 in data\msgstringtable.txt
  10800. /// "Dear angel, can you hear my voice?"
  10801. /// "I am" (space separated player name) "Super Novice~"
  10802. /// "Help me out~ Please~ T_T"
  10803. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10804. {
  10805. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  10806. unsigned int next = pc_nextbaseexp(sd);
  10807. if( next == 0 ) next = pc_thisbaseexp(sd);
  10808. if( next ) {
  10809. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  10810. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  10811. 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]
  10812. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  10813. }
  10814. }
  10815. }
  10816. }
  10817. /// Friends List
  10818. ///
  10819. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  10820. /// 0206 <account id>.L <char id>.L <state>.B
  10821. /// state:
  10822. /// 0 = online
  10823. /// 1 = offline
  10824. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10825. {
  10826. int i, fd = sd->fd;
  10827. //Seek friend.
  10828. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10829. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10830. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10831. return; //Not found
  10832. WFIFOHEAD(fd,packet_len(0x206));
  10833. WFIFOW(fd, 0) = 0x206;
  10834. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10835. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10836. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10837. WFIFOSET(fd, packet_len(0x206));
  10838. }
  10839. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10840. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10841. {
  10842. int account_id, char_id, online;
  10843. account_id = va_arg(ap, int);
  10844. char_id = va_arg(ap, int);
  10845. online = va_arg(ap, int);
  10846. clif_friendslist_toggle(sd, account_id, char_id, online);
  10847. return 0;
  10848. }
  10849. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  10850. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  10851. void clif_friendslist_send(struct map_session_data *sd)
  10852. {
  10853. int i = 0, n, fd = sd->fd;
  10854. // Send friends list
  10855. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10856. WFIFOW(fd, 0) = 0x201;
  10857. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  10858. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10859. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10860. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10861. }
  10862. if (i) {
  10863. WFIFOW(fd,2) = 4 + 32 * i;
  10864. WFIFOSET(fd, WFIFOW(fd,2));
  10865. }
  10866. for (n = 0; n < i; n++) { //Sending the online players
  10867. if (map_charid2sd(sd->status.friends[n].char_id))
  10868. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10869. }
  10870. }
  10871. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  10872. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  10873. /// result:
  10874. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  10875. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  10876. /// 2 = MsgStringTable[819]="Your Friend List is full."
  10877. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  10878. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10879. {
  10880. int fd;
  10881. nullpo_retv(sd);
  10882. fd = sd->fd;
  10883. WFIFOHEAD(fd,packet_len(0x209));
  10884. WFIFOW(fd,0) = 0x209;
  10885. WFIFOW(fd,2) = type;
  10886. if (f_sd) {
  10887. WFIFOL(fd,4) = f_sd->status.account_id;
  10888. WFIFOL(fd,8) = f_sd->status.char_id;
  10889. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10890. }
  10891. WFIFOSET(fd, packet_len(0x209));
  10892. }
  10893. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  10894. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  10895. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name)
  10896. {
  10897. int fd = sd->fd;
  10898. WFIFOHEAD(fd,packet_len(0x207));
  10899. WFIFOW(fd,0) = 0x207;
  10900. WFIFOL(fd,2) = account_id;
  10901. WFIFOL(fd,6) = char_id;
  10902. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  10903. WFIFOSET(fd,packet_len(0x207));
  10904. }
  10905. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  10906. /// 0202 <name>.24B
  10907. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10908. {
  10909. struct map_session_data *f_sd;
  10910. int i;
  10911. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10912. // ensure that the request player's friend list is not full
  10913. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  10914. if( i == MAX_FRIENDS ) {
  10915. clif_friendslist_reqack(sd, f_sd, 2);
  10916. return;
  10917. }
  10918. // Friend doesn't exist (no player with this name)
  10919. if (f_sd == NULL) {
  10920. clif_displaymessage(fd, msg_txt(sd,3));
  10921. return;
  10922. }
  10923. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  10924. return;
  10925. }
  10926. // @noask [LuzZza]
  10927. if(f_sd->state.noask) {
  10928. clif_noask_sub(sd, f_sd, 5);
  10929. return;
  10930. }
  10931. // Friend already exists
  10932. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10933. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10934. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  10935. return;
  10936. }
  10937. }
  10938. f_sd->friend_req = sd->status.char_id;
  10939. sd->friend_req = f_sd->status.char_id;
  10940. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  10941. }
  10942. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  10943. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  10944. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  10945. /// result:
  10946. /// 0 = rejected
  10947. /// 1 = accepted
  10948. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10949. {
  10950. struct map_session_data *f_sd;
  10951. int account_id;
  10952. char reply;
  10953. account_id = RFIFOL(fd,2);
  10954. //char_id = RFIFOL(fd,6);
  10955. #if PACKETVER < 6
  10956. reply = RFIFOB(fd,10);
  10957. #else
  10958. reply = RFIFOL(fd,10);
  10959. #endif
  10960. if( sd->bl.id == account_id ) {// adding oneself as friend
  10961. return;
  10962. }
  10963. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10964. if (f_sd == NULL)
  10965. return;
  10966. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  10967. clif_friendslist_reqack(f_sd, sd, 1);
  10968. else {
  10969. int i;
  10970. // Find an empty slot
  10971. for (i = 0; i < MAX_FRIENDS; i++)
  10972. if (f_sd->status.friends[i].char_id == 0)
  10973. break;
  10974. if (i == MAX_FRIENDS) {
  10975. clif_friendslist_reqack(f_sd, sd, 2);
  10976. return;
  10977. }
  10978. f_sd->status.friends[i].account_id = sd->status.account_id;
  10979. f_sd->status.friends[i].char_id = sd->status.char_id;
  10980. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10981. clif_friendslist_reqack(f_sd, sd, 0);
  10982. if (battle_config.friend_auto_add) {
  10983. // Also add f_sd to sd's friendlist.
  10984. for (i = 0; i < MAX_FRIENDS; i++) {
  10985. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10986. return; //No need to add anything.
  10987. if (sd->status.friends[i].char_id == 0)
  10988. break;
  10989. }
  10990. if (i == MAX_FRIENDS) {
  10991. clif_friendslist_reqack(sd, f_sd, 2);
  10992. return;
  10993. }
  10994. sd->status.friends[i].account_id = f_sd->status.account_id;
  10995. sd->status.friends[i].char_id = f_sd->status.char_id;
  10996. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10997. clif_friendslist_reqack(sd, f_sd, 0);
  10998. }
  10999. }
  11000. }
  11001. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  11002. /// 0203 <account id>.L <char id>.L
  11003. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  11004. {
  11005. struct map_session_data *f_sd = NULL;
  11006. int account_id, char_id;
  11007. int i, j;
  11008. account_id = RFIFOL(fd,2);
  11009. char_id = RFIFOL(fd,6);
  11010. // Search friend
  11011. for (i = 0; i < MAX_FRIENDS &&
  11012. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11013. if (i == MAX_FRIENDS) {
  11014. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  11015. return;
  11016. }
  11017. //remove from friend's list first
  11018. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  11019. for (i = 0; i < MAX_FRIENDS &&
  11020. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  11021. if (i != MAX_FRIENDS) {
  11022. // move all chars up
  11023. for(j = i + 1; j < MAX_FRIENDS; j++)
  11024. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  11025. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  11026. //should the guy be notified of some message? we should add it here if so
  11027. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  11028. WFIFOW(f_sd->fd,0) = 0x20a;
  11029. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  11030. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  11031. WFIFOSET(f_sd->fd, packet_len(0x20a));
  11032. }
  11033. } else { //friend not online -- ask char server to delete from his friendlist
  11034. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  11035. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  11036. return;
  11037. }
  11038. }
  11039. // We can now delete from original requester
  11040. for (i = 0; i < MAX_FRIENDS &&
  11041. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11042. // move all chars up
  11043. for(j = i + 1; j < MAX_FRIENDS; j++)
  11044. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  11045. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  11046. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  11047. WFIFOHEAD(fd,packet_len(0x20a));
  11048. WFIFOW(fd,0) = 0x20a;
  11049. WFIFOL(fd,2) = account_id;
  11050. WFIFOL(fd,6) = char_id;
  11051. WFIFOSET(fd, packet_len(0x20a));
  11052. }
  11053. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  11054. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  11055. void clif_PVPInfo(struct map_session_data* sd)
  11056. {
  11057. int fd = sd->fd;
  11058. WFIFOHEAD(fd,packet_len(0x210));
  11059. WFIFOW(fd,0) = 0x210;
  11060. WFIFOL(fd,2) = sd->status.char_id;
  11061. WFIFOL(fd,6) = sd->status.account_id;
  11062. WFIFOL(fd,10) = sd->pvp_won; // times won
  11063. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  11064. WFIFOL(fd,18) = sd->pvp_point;
  11065. WFIFOSET(fd, packet_len(0x210));
  11066. }
  11067. /// /pvpinfo (CZ_REQ_PVPPOINT).
  11068. /// 020f <char id>.L <account id>.L
  11069. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  11070. {
  11071. // TODO: Is there a way to use this on an another player (char/acc id)?
  11072. clif_PVPInfo(sd);
  11073. }
  11074. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  11075. /// 0219 { <name>.24B }*10 { <point>.L }*10
  11076. void clif_blacksmith(struct map_session_data* sd)
  11077. {
  11078. int i, fd = sd->fd;
  11079. const char* name;
  11080. WFIFOHEAD(fd,packet_len(0x219));
  11081. WFIFOW(fd,0) = 0x219;
  11082. //Packet size limits this list to 10 elements. [Skotlex]
  11083. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11084. if (smith_fame_list[i].id > 0) {
  11085. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  11086. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  11087. {
  11088. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  11089. } else
  11090. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  11091. } else
  11092. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  11093. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  11094. }
  11095. for(;i < 10; i++) { //In case the MAX is less than 10.
  11096. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  11097. WFIFOL(fd, 242 + i * 4) = 0;
  11098. }
  11099. WFIFOSET(fd, packet_len(0x219));
  11100. }
  11101. /// /blacksmith (CZ_BLACKSMITH_RANK).
  11102. /// 0217
  11103. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  11104. {
  11105. clif_blacksmith(sd);
  11106. }
  11107. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  11108. /// 021b <points>.L <total points>.L
  11109. void clif_fame_blacksmith(struct map_session_data *sd, int points)
  11110. {
  11111. int fd = sd->fd;
  11112. WFIFOHEAD(fd,packet_len(0x21b));
  11113. WFIFOW(fd,0) = 0x21b;
  11114. WFIFOL(fd,2) = points;
  11115. WFIFOL(fd,6) = sd->status.fame;
  11116. WFIFOSET(fd, packet_len(0x21b));
  11117. }
  11118. /// /alchemist list (ZC_ALCHEMIST_RANK).
  11119. /// 021a { <name>.24B }*10 { <point>.L }*10
  11120. void clif_alchemist(struct map_session_data* sd)
  11121. {
  11122. int i, fd = sd->fd;
  11123. const char* name;
  11124. WFIFOHEAD(fd,packet_len(0x21a));
  11125. WFIFOW(fd,0) = 0x21a;
  11126. //Packet size limits this list to 10 elements. [Skotlex]
  11127. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11128. if (chemist_fame_list[i].id > 0) {
  11129. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  11130. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  11131. {
  11132. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11133. } else
  11134. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  11135. } else
  11136. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11137. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  11138. }
  11139. for(;i < 10; i++) { //In case the MAX is less than 10.
  11140. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11141. WFIFOL(fd, 242 + i * 4) = 0;
  11142. }
  11143. WFIFOSET(fd, packet_len(0x21a));
  11144. }
  11145. /// /alchemist (CZ_ALCHEMIST_RANK).
  11146. /// 0218
  11147. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  11148. {
  11149. clif_alchemist(sd);
  11150. }
  11151. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  11152. /// 021c <points>.L <total points>.L
  11153. void clif_fame_alchemist(struct map_session_data *sd, int points)
  11154. {
  11155. int fd = sd->fd;
  11156. WFIFOHEAD(fd,packet_len(0x21c));
  11157. WFIFOW(fd,0) = 0x21c;
  11158. WFIFOL(fd,2) = points;
  11159. WFIFOL(fd,6) = sd->status.fame;
  11160. WFIFOSET(fd, packet_len(0x21c));
  11161. }
  11162. /// /taekwon list (ZC_TAEKWON_RANK).
  11163. /// 0226 { <name>.24B }*10 { <point>.L }*10
  11164. void clif_taekwon(struct map_session_data* sd)
  11165. {
  11166. int i, fd = sd->fd;
  11167. const char* name;
  11168. WFIFOHEAD(fd,packet_len(0x226));
  11169. WFIFOW(fd,0) = 0x226;
  11170. //Packet size limits this list to 10 elements. [Skotlex]
  11171. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  11172. if (taekwon_fame_list[i].id > 0) {
  11173. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  11174. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  11175. {
  11176. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  11177. } else
  11178. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  11179. } else
  11180. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  11181. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  11182. }
  11183. for(;i < 10; i++) { //In case the MAX is less than 10.
  11184. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  11185. WFIFOL(fd, 242 + i * 4) = 0;
  11186. }
  11187. WFIFOSET(fd, packet_len(0x226));
  11188. }
  11189. /// /taekwon (CZ_TAEKWON_RANK).
  11190. /// 0225
  11191. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  11192. {
  11193. clif_taekwon(sd);
  11194. }
  11195. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  11196. /// 0224 <points>.L <total points>.L
  11197. void clif_fame_taekwon(struct map_session_data *sd, int points)
  11198. {
  11199. int fd = sd->fd;
  11200. WFIFOHEAD(fd,packet_len(0x224));
  11201. WFIFOW(fd,0) = 0x224;
  11202. WFIFOL(fd,2) = points;
  11203. WFIFOL(fd,6) = sd->status.fame;
  11204. WFIFOSET(fd, packet_len(0x224));
  11205. }
  11206. /// /pk list (ZC_KILLER_RANK).
  11207. /// 0238 { <name>.24B }*10 { <point>.L }*10
  11208. void clif_ranking_pk(struct map_session_data* sd)
  11209. {
  11210. int i, fd = sd->fd;
  11211. WFIFOHEAD(fd,packet_len(0x238));
  11212. WFIFOW(fd,0) = 0x238;
  11213. for(i=0;i<10;i++){
  11214. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  11215. WFIFOL(fd,i*4+242) = 0;
  11216. }
  11217. WFIFOSET(fd, packet_len(0x238));
  11218. }
  11219. /// /pk (CZ_KILLER_RANK).
  11220. /// 0237
  11221. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  11222. {
  11223. clif_ranking_pk(sd);
  11224. }
  11225. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  11226. /// 0254 <which>.B
  11227. /// which:
  11228. /// 0 = sun
  11229. /// 1 = moon
  11230. /// 2 = star
  11231. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  11232. {
  11233. int i;
  11234. if (sd->menuskill_id != SG_FEEL)
  11235. return;
  11236. i = sd->menuskill_val-1;
  11237. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  11238. sd->feel_map[i].index = map_id2index(sd->bl.m);
  11239. sd->feel_map[i].m = sd->bl.m;
  11240. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  11241. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  11242. // clif_misceffect2(&sd->bl, 0x1b0);
  11243. // clif_misceffect2(&sd->bl, 0x21f);
  11244. clif_feel_info(sd, i, 0);
  11245. clif_menuskill_clear(sd);
  11246. }
  11247. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  11248. /// 0253 <which>.B
  11249. /// which:
  11250. /// 0 = sun
  11251. /// 1 = moon
  11252. /// 2 = star
  11253. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  11254. {
  11255. WFIFOHEAD(fd,packet_len(0x253));
  11256. WFIFOW(fd,0)=0x253;
  11257. WFIFOB(fd,2)=TOB(skill_lv-1);
  11258. WFIFOSET(fd, packet_len(0x253));
  11259. sd->menuskill_id = SG_FEEL;
  11260. sd->menuskill_val = skill_lv;
  11261. }
  11262. /// Request to change homunculus' name (CZ_RENAME_MER).
  11263. /// 0231 <name>.24B
  11264. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  11265. {
  11266. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  11267. }
  11268. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  11269. /// 0234 <id>.L
  11270. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  11271. {
  11272. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11273. struct block_list *bl = NULL;
  11274. struct unit_data *ud = NULL;
  11275. if( sd->md && sd->md->bl.id == id )
  11276. bl = &sd->md->bl;
  11277. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11278. bl = &sd->hd->bl; // Moving Homunculus
  11279. else
  11280. return;
  11281. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  11282. ud = unit_bl2ud(bl);
  11283. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  11284. }
  11285. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  11286. /// 0232 <id>.L <position data>.3B
  11287. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  11288. {
  11289. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  11290. struct block_list *bl = NULL;
  11291. short x, y;
  11292. RFIFOPOS(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  11293. if( sd->md && sd->md->bl.id == id )
  11294. bl = &sd->md->bl; // Moving Mercenary
  11295. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11296. bl = &sd->hd->bl; // Moving Homunculus
  11297. else
  11298. return;
  11299. unit_walktoxy(bl, x, y, 4);
  11300. }
  11301. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  11302. /// 0233 <id>.L <target id>.L <action>.B
  11303. /// action:
  11304. /// always 0
  11305. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  11306. {
  11307. struct block_list *bl = NULL;
  11308. int id = RFIFOL(fd,2),
  11309. target_id = RFIFOL(fd,6),
  11310. action_type = RFIFOB(fd,10);
  11311. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  11312. bl = &sd->hd->bl;
  11313. else if( sd->md && sd->md->bl.id == id )
  11314. bl = &sd->md->bl;
  11315. else return;
  11316. unit_stop_attack(bl);
  11317. unit_attack(bl, target_id, action_type != 0);
  11318. }
  11319. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  11320. /// 022d <type>.W <command>.B
  11321. /// type:
  11322. /// always 0
  11323. /// command:
  11324. /// 0 = homunculus information
  11325. /// 1 = feed
  11326. /// 2 = delete
  11327. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  11328. { //[orn]
  11329. int cmd;
  11330. cmd = RFIFOW(fd,0);
  11331. if(!merc_is_hom_active(sd->hd))
  11332. return;
  11333. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[1]));
  11334. }
  11335. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  11336. /// 0292
  11337. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  11338. {
  11339. int item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  11340. if (item_position < 0)
  11341. return;
  11342. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  11343. return;
  11344. if (!status_revive(&sd->bl, 100, 100))
  11345. return;
  11346. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  11347. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  11348. }
  11349. /// Information about character's status values (ZC_ACK_STATUS_GM).
  11350. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  11351. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  11352. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  11353. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  11354. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  11355. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  11356. void clif_check(int fd, struct map_session_data* pl_sd)
  11357. {
  11358. WFIFOHEAD(fd,packet_len(0x214));
  11359. WFIFOW(fd, 0) = 0x214;
  11360. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  11361. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  11362. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  11363. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  11364. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  11365. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  11366. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  11367. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  11368. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  11369. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  11370. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  11371. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  11372. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  11373. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  11374. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  11375. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  11376. WFIFOW(fd,22) = pl_sd->battle_status.def;
  11377. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  11378. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  11379. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  11380. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  11381. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  11382. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  11383. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  11384. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  11385. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  11386. WFIFOSET(fd,packet_len(0x214));
  11387. }
  11388. /// /check (CZ_REQ_STATUS_GM).
  11389. /// Request character's status values.
  11390. /// 0213 <char name>.24B
  11391. void clif_parse_Check(int fd, struct map_session_data *sd)
  11392. {
  11393. char charname[NAME_LENGTH];
  11394. struct map_session_data* pl_sd;
  11395. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  11396. return;
  11397. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), sizeof(charname));
  11398. if( ( pl_sd = map_nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  11399. {
  11400. return;
  11401. }
  11402. clif_check(fd, pl_sd);
  11403. }
  11404. /// MAIL SYSTEM
  11405. /// By Zephyrus
  11406. ///
  11407. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  11408. /// 0255 <index>.W <result>.B
  11409. /// result:
  11410. /// 0 = success
  11411. /// 1 = failure
  11412. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  11413. {
  11414. WFIFOHEAD(fd,packet_len(0x255));
  11415. WFIFOW(fd,0) = 0x255;
  11416. WFIFOW(fd,2) = index;
  11417. WFIFOB(fd,4) = flag;
  11418. WFIFOSET(fd,packet_len(0x255));
  11419. }
  11420. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  11421. /// 0245 <result>.B
  11422. /// result:
  11423. /// 0 = success
  11424. /// 1 = failure
  11425. /// 2 = too many items
  11426. void clif_Mail_getattachment(int fd, uint8 flag)
  11427. {
  11428. WFIFOHEAD(fd,packet_len(0x245));
  11429. WFIFOW(fd,0) = 0x245;
  11430. WFIFOB(fd,2) = flag;
  11431. WFIFOSET(fd,packet_len(0x245));
  11432. }
  11433. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  11434. /// 0249 <result>.B
  11435. /// result:
  11436. /// 0 = success
  11437. /// 1 = recipinent does not exist
  11438. void clif_Mail_send(int fd, bool fail)
  11439. {
  11440. WFIFOHEAD(fd,packet_len(0x249));
  11441. WFIFOW(fd,0) = 0x249;
  11442. WFIFOB(fd,2) = fail;
  11443. WFIFOSET(fd,packet_len(0x249));
  11444. }
  11445. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  11446. /// 0257 <mail id>.L <result>.W
  11447. /// result:
  11448. /// 0 = success
  11449. /// 1 = failure
  11450. void clif_Mail_delete(int fd, int mail_id, short fail)
  11451. {
  11452. WFIFOHEAD(fd, packet_len(0x257));
  11453. WFIFOW(fd,0) = 0x257;
  11454. WFIFOL(fd,2) = mail_id;
  11455. WFIFOW(fd,6) = fail;
  11456. WFIFOSET(fd, packet_len(0x257));
  11457. }
  11458. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  11459. /// 0274 <mail id>.L <result>.W
  11460. /// result:
  11461. /// 0 = success
  11462. /// 1 = failure
  11463. void clif_Mail_return(int fd, int mail_id, short fail)
  11464. {
  11465. WFIFOHEAD(fd,packet_len(0x274));
  11466. WFIFOW(fd,0) = 0x274;
  11467. WFIFOL(fd,2) = mail_id;
  11468. WFIFOW(fd,6) = fail;
  11469. WFIFOSET(fd,packet_len(0x274));
  11470. }
  11471. /// Notification about new mail (ZC_MAIL_RECEIVE).
  11472. /// 024a <mail id>.L <title>.40B <sender>.24B
  11473. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  11474. {
  11475. WFIFOHEAD(fd,packet_len(0x24a));
  11476. WFIFOW(fd,0) = 0x24a;
  11477. WFIFOL(fd,2) = mail_id;
  11478. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  11479. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  11480. WFIFOSET(fd,packet_len(0x24a));
  11481. }
  11482. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  11483. /// 0260 <type>.L
  11484. /// type:
  11485. /// 0 = open
  11486. /// 1 = close
  11487. void clif_Mail_window(int fd, int flag)
  11488. {
  11489. WFIFOHEAD(fd,packet_len(0x260));
  11490. WFIFOW(fd,0) = 0x260;
  11491. WFIFOL(fd,2) = flag;
  11492. WFIFOSET(fd,packet_len(0x260));
  11493. }
  11494. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  11495. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  11496. /// read:
  11497. /// 0 = unread
  11498. /// 1 = read
  11499. void clif_Mail_refreshinbox(struct map_session_data *sd)
  11500. {
  11501. int fd = sd->fd;
  11502. struct mail_data *md = &sd->mail.inbox;
  11503. struct mail_message *msg;
  11504. int len, i, j;
  11505. len = 8 + (73 * md->amount);
  11506. WFIFOHEAD(fd,len);
  11507. WFIFOW(fd,0) = 0x240;
  11508. WFIFOW(fd,2) = len;
  11509. WFIFOL(fd,4) = md->amount;
  11510. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  11511. {
  11512. msg = &md->msg[i];
  11513. if (msg->id < 1)
  11514. continue;
  11515. WFIFOL(fd,8+73*j) = msg->id;
  11516. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  11517. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  11518. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  11519. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  11520. j++;
  11521. }
  11522. WFIFOSET(fd,len);
  11523. if( md->full ) {// TODO: is this official?
  11524. char output[100];
  11525. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  11526. clif_disp_onlyself(sd, output, strlen(output));
  11527. }
  11528. }
  11529. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  11530. /// 023f
  11531. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  11532. {
  11533. struct mail_data* md = &sd->mail.inbox;
  11534. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  11535. intif_Mail_requestinbox(sd->status.char_id, 1);
  11536. else
  11537. clif_Mail_refreshinbox(sd);
  11538. mail_removeitem(sd, 0);
  11539. mail_removezeny(sd, 0);
  11540. }
  11541. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  11542. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  11543. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  11544. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  11545. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  11546. {
  11547. int i, fd = sd->fd;
  11548. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11549. if( i == MAIL_MAX_INBOX ) {
  11550. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  11551. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  11552. return;
  11553. } else {
  11554. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11555. struct item *item = &msg->item;
  11556. struct item_data *data;
  11557. int msg_len = strlen(msg->body), len;
  11558. if( msg_len == 0 ) {
  11559. strcpy(msg->body, "(no message)");
  11560. msg_len = strlen(msg->body);
  11561. }
  11562. len = 101 + msg_len;
  11563. WFIFOHEAD(fd,len);
  11564. WFIFOW(fd,0) = 0x242;
  11565. WFIFOW(fd,2) = len;
  11566. WFIFOL(fd,4) = msg->id;
  11567. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  11568. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  11569. WFIFOL(fd,72) = 0;
  11570. WFIFOL(fd,76) = msg->zeny;
  11571. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  11572. WFIFOL(fd,80) = item->amount;
  11573. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  11574. WFIFOW(fd,86) = data->type;
  11575. WFIFOB(fd,88) = item->identify;
  11576. WFIFOB(fd,89) = item->attribute;
  11577. WFIFOB(fd,90) = item->refine;
  11578. WFIFOW(fd,91) = item->card[0];
  11579. WFIFOW(fd,93) = item->card[1];
  11580. WFIFOW(fd,95) = item->card[2];
  11581. WFIFOW(fd,97) = item->card[3];
  11582. } else // no item, set all to zero
  11583. memset(WFIFOP(fd,80), 0x00, 19);
  11584. WFIFOB(fd,99) = (unsigned char)msg_len;
  11585. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  11586. WFIFOSET(fd,len);
  11587. if (msg->status == MAIL_UNREAD) {
  11588. msg->status = MAIL_READ;
  11589. intif_Mail_read(mail_id);
  11590. clif_parse_Mail_refreshinbox(fd, sd);
  11591. }
  11592. }
  11593. }
  11594. /// Request to open a mail (CZ_MAIL_OPEN).
  11595. /// 0241 <mail id>.L
  11596. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  11597. {
  11598. int mail_id = RFIFOL(fd,2);
  11599. if( mail_id <= 0 )
  11600. return;
  11601. if( mail_invalid_operation(sd) )
  11602. return;
  11603. clif_Mail_read(sd, RFIFOL(fd,2));
  11604. }
  11605. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  11606. /// 0244 <mail id>.L
  11607. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  11608. {
  11609. int mail_id = RFIFOL(fd,2);
  11610. int i;
  11611. bool fail = false;
  11612. if( !chrif_isconnected() )
  11613. return;
  11614. if( mail_id <= 0 )
  11615. return;
  11616. if( mail_invalid_operation(sd) )
  11617. return;
  11618. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11619. if( i == MAIL_MAX_INBOX )
  11620. return;
  11621. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  11622. return;
  11623. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  11624. clif_Mail_getattachment(fd, 1);
  11625. return;
  11626. }
  11627. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  11628. struct item_data *data;
  11629. unsigned int weight;
  11630. if ((data = itemdb_exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  11631. return;
  11632. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  11633. case CHKADDITEM_NEW:
  11634. fail = ( pc_inventoryblank(sd) == 0 );
  11635. break;
  11636. case CHKADDITEM_OVERAMOUNT:
  11637. fail = true;
  11638. }
  11639. if( fail ) {
  11640. clif_Mail_getattachment(fd, 1);
  11641. return;
  11642. }
  11643. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11644. if( sd->weight + weight > sd->max_weight ) {
  11645. clif_Mail_getattachment(fd, 2);
  11646. return;
  11647. }
  11648. }
  11649. sd->mail.inbox.msg[i].zeny = 0;
  11650. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11651. clif_Mail_read(sd, mail_id);
  11652. intif_Mail_getattach(sd->status.char_id, mail_id);
  11653. }
  11654. /// Request to delete a mail (CZ_MAIL_DELETE).
  11655. /// 0243 <mail id>.L
  11656. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11657. {
  11658. int mail_id = RFIFOL(fd,2);
  11659. int i;
  11660. if( !chrif_isconnected() )
  11661. return;
  11662. if( mail_id <= 0 )
  11663. return;
  11664. if( mail_invalid_operation(sd) )
  11665. return;
  11666. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11667. if (i < MAIL_MAX_INBOX) {
  11668. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11669. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  11670. clif_Mail_delete(sd->fd, mail_id, 1);
  11671. return;
  11672. }
  11673. intif_Mail_delete(sd->status.char_id, mail_id);
  11674. }
  11675. }
  11676. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  11677. /// 0273 <mail id>.L <receive name>.24B
  11678. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11679. {
  11680. int mail_id = RFIFOL(fd,2);
  11681. int i;
  11682. if( mail_id <= 0 )
  11683. return;
  11684. if( mail_invalid_operation(sd) )
  11685. return;
  11686. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11687. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11688. intif_Mail_return(sd->status.char_id, mail_id);
  11689. else
  11690. clif_Mail_return(sd->fd, mail_id, 1);
  11691. }
  11692. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  11693. /// 0247 <index>.W <amount>.L
  11694. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11695. {
  11696. int idx = RFIFOW(fd,2);
  11697. int amount = RFIFOL(fd,4);
  11698. unsigned char flag;
  11699. if( !chrif_isconnected() )
  11700. return;
  11701. if (idx < 0 || amount < 0)
  11702. return;
  11703. flag = mail_setitem(sd, idx, amount);
  11704. clif_Mail_setattachment(fd,idx,flag);
  11705. }
  11706. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  11707. /// 0246 <type>.W
  11708. /// type:
  11709. /// 0 = reset all
  11710. /// 1 = remove item
  11711. /// 2 = remove zeny
  11712. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11713. {
  11714. int flag = RFIFOW(fd,2);
  11715. if (flag == 0 || flag == 1)
  11716. mail_removeitem(sd, 0);
  11717. if (flag == 0 || flag == 2)
  11718. mail_removezeny(sd, 0);
  11719. }
  11720. /// Request to send mail (CZ_MAIL_SEND).
  11721. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  11722. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11723. {
  11724. struct mail_message msg;
  11725. int body_len;
  11726. if( !chrif_isconnected() )
  11727. return;
  11728. if( sd->state.trading )
  11729. return;
  11730. if( RFIFOW(fd,2) < 69 ) {
  11731. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11732. return;
  11733. }
  11734. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 ) {
  11735. clif_displaymessage(sd->fd,msg_txt(sd,675)); //"Cannot send mails too fast!!."
  11736. clif_Mail_send(fd, true); // fail
  11737. return;
  11738. }
  11739. body_len = RFIFOB(fd,68);
  11740. if (body_len > MAIL_BODY_LENGTH)
  11741. body_len = MAIL_BODY_LENGTH;
  11742. if( !mail_setattachment(sd, &msg) ) { // Invalid Append condition
  11743. clif_Mail_send(sd->fd, true); // fail
  11744. mail_removeitem(sd,0);
  11745. mail_removezeny(sd,0);
  11746. return;
  11747. }
  11748. msg.id = 0; // id will be assigned by charserver
  11749. msg.send_id = sd->status.char_id;
  11750. msg.dest_id = 0; // will attempt to resolve name
  11751. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11752. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11753. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11754. if (msg.title[0] == '\0') {
  11755. return; // Message has no length and somehow client verification was skipped.
  11756. }
  11757. if (body_len)
  11758. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11759. else
  11760. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11761. msg.timestamp = time(NULL);
  11762. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11763. mail_deliveryfail(sd, &msg);
  11764. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11765. }
  11766. /// AUCTION SYSTEM
  11767. /// By Zephyrus
  11768. ///
  11769. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  11770. /// 025f <type>.L
  11771. /// type:
  11772. /// 0 = open
  11773. /// 1 = close
  11774. void clif_Auction_openwindow(struct map_session_data *sd)
  11775. {
  11776. int fd = sd->fd;
  11777. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  11778. return;
  11779. WFIFOHEAD(fd,packet_len(0x25f));
  11780. WFIFOW(fd,0) = 0x25f;
  11781. WFIFOL(fd,2) = 0;
  11782. WFIFOSET(fd,packet_len(0x25f));
  11783. }
  11784. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  11785. /// 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 }*
  11786. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11787. {
  11788. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11789. struct auction_data auction;
  11790. struct item_data *item;
  11791. int k;
  11792. WFIFOHEAD(fd,12 + (count * 83));
  11793. WFIFOW(fd,0) = 0x252;
  11794. WFIFOW(fd,2) = 12 + (count * 83);
  11795. WFIFOL(fd,4) = pages;
  11796. WFIFOL(fd,8) = count;
  11797. for( i = 0; i < count; i++ ) {
  11798. memcpy(&auction, RBUFP(buf,i * len), len);
  11799. k = 12 + (i * 83);
  11800. WFIFOL(fd,k) = auction.auction_id;
  11801. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11802. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  11803. WFIFOW(fd,28+k) = item->view_id;
  11804. else
  11805. WFIFOW(fd,28+k) = auction.item.nameid;
  11806. WFIFOL(fd,30+k) = auction.type;
  11807. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  11808. WFIFOB(fd,36+k) = auction.item.identify;
  11809. WFIFOB(fd,37+k) = auction.item.attribute;
  11810. WFIFOB(fd,38+k) = auction.item.refine;
  11811. WFIFOW(fd,39+k) = auction.item.card[0];
  11812. WFIFOW(fd,41+k) = auction.item.card[1];
  11813. WFIFOW(fd,43+k) = auction.item.card[2];
  11814. WFIFOW(fd,45+k) = auction.item.card[3];
  11815. WFIFOL(fd,47+k) = auction.price;
  11816. WFIFOL(fd,51+k) = auction.buynow;
  11817. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11818. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11819. }
  11820. WFIFOSET(fd,WFIFOW(fd,2));
  11821. }
  11822. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  11823. /// 0256 <index>.W <result>.B
  11824. /// result:
  11825. /// 0 = success
  11826. /// 1 = failure
  11827. static void clif_Auction_setitem(int fd, int index, bool fail)
  11828. {
  11829. WFIFOHEAD(fd,packet_len(0x256));
  11830. WFIFOW(fd,0) = 0x256;
  11831. WFIFOW(fd,2) = index;
  11832. WFIFOB(fd,4) = fail;
  11833. WFIFOSET(fd,packet_len(0x256));
  11834. }
  11835. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  11836. /// 024b <type>.W
  11837. /// type:
  11838. /// 0 = create (any other action in auction window)
  11839. /// 1 = cancel (cancel pressed on register tab)
  11840. /// ? = junk, uninitialized value (ex. when switching between list filters)
  11841. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11842. {
  11843. if( sd->auction.amount > 0 )
  11844. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11845. sd->auction.amount = 0;
  11846. }
  11847. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  11848. /// 024c <index>.W <count>.L
  11849. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11850. {
  11851. int idx = RFIFOW(fd,2) - 2;
  11852. int amount = RFIFOL(fd,4); // Always 1
  11853. struct item_data *item;
  11854. if( sd->auction.amount > 0 )
  11855. sd->auction.amount = 0;
  11856. if( idx < 0 || idx >= MAX_INVENTORY ) {
  11857. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11858. return;
  11859. }
  11860. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  11861. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11862. return;
  11863. }
  11864. 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) )
  11865. { // Consumable or pets are not allowed
  11866. clif_Auction_setitem(sd->fd, idx, true);
  11867. return;
  11868. }
  11869. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  11870. !sd->status.inventory[idx].identify ||
  11871. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  11872. clif_Auction_setitem(sd->fd, idx, true);
  11873. return;
  11874. }
  11875. sd->auction.index = idx;
  11876. sd->auction.amount = amount;
  11877. clif_Auction_setitem(fd, idx + 2, false);
  11878. }
  11879. /// Result from an auction action (ZC_AUCTION_RESULT).
  11880. /// 0250 <result>.B
  11881. /// result:
  11882. /// 0 = You have failed to bid into the auction
  11883. /// 1 = You have successfully bid in the auction
  11884. /// 2 = The auction has been canceled
  11885. /// 3 = An auction with at least one bidder cannot be canceled
  11886. /// 4 = You cannot register more than 5 items in an auction at a time
  11887. /// 5 = You do not have enough Zeny to pay the Auction Fee
  11888. /// 6 = You have won the auction
  11889. /// 7 = You have failed to win the auction
  11890. /// 8 = You do not have enough Zeny
  11891. /// 9 = You cannot place more than 5 bids at a time
  11892. void clif_Auction_message(int fd, unsigned char flag)
  11893. {
  11894. WFIFOHEAD(fd,packet_len(0x250));
  11895. WFIFOW(fd,0) = 0x250;
  11896. WFIFOB(fd,2) = flag;
  11897. WFIFOSET(fd,packet_len(0x250));
  11898. }
  11899. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  11900. /// 025e <result>.W
  11901. /// result:
  11902. /// 0 = You have ended the auction
  11903. /// 1 = You cannot end the auction
  11904. /// 2 = Auction ID is incorrect
  11905. void clif_Auction_close(int fd, unsigned char flag)
  11906. {
  11907. WFIFOHEAD(fd,packet_len(0x25e));
  11908. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  11909. WFIFOW(fd,2) = flag;
  11910. WFIFOSET(fd,packet_len(0x25e));
  11911. }
  11912. /// Request to add an auction (CZ_AUCTION_ADD).
  11913. /// 024d <now money>.L <max money>.L <delete hour>.W
  11914. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11915. {
  11916. struct auction_data auction;
  11917. struct item_data *item;
  11918. auction.price = RFIFOL(fd,2);
  11919. auction.buynow = RFIFOL(fd,6);
  11920. auction.hours = RFIFOW(fd,10);
  11921. // Invalid Situations...
  11922. if( sd->auction.amount < 1 ) {
  11923. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11924. return;
  11925. }
  11926. if( auction.price >= auction.buynow ) {
  11927. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11928. return;
  11929. }
  11930. if( auction.hours < 1 || auction.hours > 48 ) {
  11931. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11932. return;
  11933. }
  11934. // Auction checks...
  11935. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  11936. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11937. return;
  11938. }
  11939. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  11940. auction.buynow = battle_config.auction_maximumprice;
  11941. if( auction.price >= auction.buynow )
  11942. auction.price = auction.buynow - 1;
  11943. }
  11944. auction.auction_id = 0;
  11945. auction.seller_id = sd->status.char_id;
  11946. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  11947. auction.buyer_id = 0;
  11948. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  11949. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11950. {
  11951. clif_Auction_message(fd, 2); // The auction has been canceled
  11952. return;
  11953. }
  11954. if( (item = itemdb_exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11955. { // Just in case
  11956. clif_Auction_message(fd, 2); // The auction has been canceled
  11957. return;
  11958. }
  11959. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  11960. auction.type = item->type;
  11961. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11962. auction.item.amount = 1;
  11963. auction.timestamp = 0;
  11964. if( !intif_Auction_register(&auction) )
  11965. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11966. else
  11967. {
  11968. int zeny = auction.hours*battle_config.auction_feeperhour;
  11969. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  11970. sd->auction.amount = 0;
  11971. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  11972. }
  11973. }
  11974. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  11975. /// 024e <auction id>.L
  11976. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11977. {
  11978. unsigned int auction_id = RFIFOL(fd,2);
  11979. intif_Auction_cancel(sd->status.char_id, auction_id);
  11980. }
  11981. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  11982. /// 025d <auction id>.L
  11983. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11984. {
  11985. unsigned int auction_id = RFIFOL(fd,2);
  11986. intif_Auction_close(sd->status.char_id, auction_id);
  11987. }
  11988. /// Places a bid on an auction (CZ_AUCTION_BUY).
  11989. /// 024f <auction id>.L <money>.L
  11990. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11991. {
  11992. unsigned int auction_id = RFIFOL(fd,2);
  11993. int bid = RFIFOL(fd,6);
  11994. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  11995. clif_displaymessage(sd->fd, msg_txt(sd,246));
  11996. return;
  11997. }
  11998. if( bid <= 0 )
  11999. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12000. else if( bid > sd->status.zeny )
  12001. clif_Auction_message(fd, 8); // You do not have enough zeny
  12002. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  12003. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  12004. else {
  12005. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  12006. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  12007. }
  12008. }
  12009. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  12010. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  12011. /// search type:
  12012. /// 0 = armor
  12013. /// 1 = weapon
  12014. /// 2 = card
  12015. /// 3 = misc
  12016. /// 4 = name search
  12017. /// 5 = auction id search
  12018. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  12019. {
  12020. char search_text[NAME_LENGTH];
  12021. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  12022. int price = RFIFOL(fd,4); // FIXME: bug #5071
  12023. clif_parse_Auction_cancelreg(fd, sd);
  12024. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  12025. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  12026. }
  12027. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  12028. /// 025c <type>.W
  12029. /// type:
  12030. /// 0 = sell (own auctions)
  12031. /// 1 = buy (own bids)
  12032. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  12033. {
  12034. short type = RFIFOW(fd,2) + 6;
  12035. clif_parse_Auction_cancelreg(fd, sd);
  12036. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  12037. }
  12038. /// CASH/POINT SHOP
  12039. ///
  12040. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  12041. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  12042. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  12043. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  12044. {
  12045. int fd,i;
  12046. #if PACKETVER < 20070711
  12047. const int offset = 8;
  12048. #else
  12049. const int offset = 12;
  12050. #endif
  12051. nullpo_retv(sd);
  12052. nullpo_retv(nd);
  12053. fd = sd->fd;
  12054. sd->npc_shopid = nd->bl.id;
  12055. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  12056. WFIFOW(fd,0) = 0x287;
  12057. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  12058. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  12059. #if PACKETVER >= 20070711
  12060. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  12061. #endif
  12062. for( i = 0; i < nd->u.shop.count; i++ ) {
  12063. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  12064. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  12065. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  12066. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  12067. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  12068. }
  12069. WFIFOSET(fd,WFIFOW(fd,2));
  12070. }
  12071. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  12072. /// 0289 <cash point>.L <error>.W
  12073. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  12074. /// error:
  12075. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  12076. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  12077. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  12078. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  12079. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  12080. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  12081. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  12082. /// 7 = You can purchase up to 10 items.
  12083. /// 8 = Some items could not be purchased.
  12084. void clif_cashshop_ack(struct map_session_data* sd, int error)
  12085. {
  12086. int fd = sd->fd;
  12087. WFIFOHEAD(fd, packet_len(0x289));
  12088. WFIFOW(fd,0) = 0x289;
  12089. WFIFOL(fd,2) = sd->cashPoints;
  12090. #if PACKETVER < 20070711
  12091. WFIFOW(fd,6) = TOW(error);
  12092. #else
  12093. WFIFOL(fd,6) = sd->kafraPoints;
  12094. WFIFOW(fd,10) = TOW(error);
  12095. #endif
  12096. WFIFOSET(fd, packet_len(0x289));
  12097. }
  12098. // TODO: find a more accurate date for this
  12099. #if PACKETVER < 20130320
  12100. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  12101. /// 0288 <name id>.W <amount>.W
  12102. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  12103. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  12104. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  12105. int fail = 0;
  12106. nullpo_retv(sd);
  12107. if( sd->state.trading || !sd->npc_shopid )
  12108. fail = 1;
  12109. else {
  12110. #if PACKETVER < 20101116
  12111. short nameid = RFIFOW(fd,2);
  12112. short amount = RFIFOW(fd,4);
  12113. int points = RFIFOL(fd,6);
  12114. fail = npc_cashshop_buy(sd, nameid, amount, points);
  12115. #else
  12116. int len = RFIFOW(fd,2);
  12117. int points = RFIFOL(fd,4);
  12118. int count = RFIFOW(fd,8);
  12119. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  12120. if( len < 10 || len != 10 + count * 4)
  12121. {
  12122. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  12123. return;
  12124. }
  12125. fail = npc_cashshop_buylist(sd,points,count,item_list);
  12126. #endif
  12127. }
  12128. clif_cashshop_ack(sd,fail);
  12129. }
  12130. #endif
  12131. /// Adoption System
  12132. ///
  12133. /// Adoption message (ZC_BABYMSG).
  12134. /// 0216 <msg>.L
  12135. /// msg:
  12136. /// 0 = "You cannot adopt more than 1 child."
  12137. /// 1 = "You must be at least character level 70 in order to adopt someone."
  12138. /// 2 = "You cannot adopt a married person."
  12139. void clif_Adopt_reply(struct map_session_data *sd, int type)
  12140. {
  12141. int fd = sd->fd;
  12142. WFIFOHEAD(fd,6);
  12143. WFIFOW(fd,0) = 0x216;
  12144. WFIFOL(fd,2) = type;
  12145. WFIFOSET(fd,6);
  12146. }
  12147. /// Adoption confirmation (ZC_REQ_BABY).
  12148. /// 01f6 <account id>.L <char id>.L <name>.B
  12149. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  12150. {
  12151. int fd = sd->fd;
  12152. WFIFOHEAD(fd,34);
  12153. WFIFOW(fd,0) = 0x1f6;
  12154. WFIFOL(fd,2) = src->status.account_id;
  12155. WFIFOL(fd,6) = p_id;
  12156. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  12157. WFIFOSET(fd,34);
  12158. }
  12159. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  12160. /// 01f9 <account id>.L
  12161. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  12162. {
  12163. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  12164. if( pc_can_Adopt(sd, p_sd, tsd) )
  12165. {
  12166. tsd->adopt_invite = sd->status.account_id;
  12167. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  12168. }
  12169. }
  12170. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  12171. /// 01f7 <account id>.L <char id>.L <answer>.L
  12172. /// answer:
  12173. /// 0 = rejected
  12174. /// 1 = accepted
  12175. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  12176. {
  12177. int p1_id = RFIFOL(fd,2);
  12178. int p2_id = RFIFOL(fd,6);
  12179. int result = RFIFOL(fd,10);
  12180. struct map_session_data* p1_sd = map_id2sd(p1_id);
  12181. struct map_session_data* p2_sd = map_id2sd(p2_id);
  12182. int pid = sd->adopt_invite;
  12183. sd->adopt_invite = 0;
  12184. if( p1_sd == NULL || p2_sd == NULL )
  12185. return; // Both players need to be online
  12186. if( pid != p1_sd->status.account_id )
  12187. return; // Incorrect values
  12188. if( result == 0 )
  12189. return; // Rejected
  12190. pc_adoption(p1_sd, p2_sd, sd);
  12191. }
  12192. /// Convex Mirror (ZC_BOSS_INFO).
  12193. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  12194. /// infoType:
  12195. /// 0 = No boss on this map (BOSS_INFO_NOT).
  12196. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  12197. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  12198. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  12199. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  12200. {
  12201. WFIFOHEAD(fd,70);
  12202. memset(WFIFOP(fd,0),0,70);
  12203. WFIFOW(fd,0) = 0x293;
  12204. if( md != NULL ) {
  12205. if( md->bl.prev != NULL ) { // Boss on This Map
  12206. if( flag ) {
  12207. WFIFOB(fd,2) = 1;
  12208. WFIFOL(fd,3) = md->bl.x;
  12209. WFIFOL(fd,7) = md->bl.y;
  12210. } else
  12211. WFIFOB(fd,2) = 2; // First Time
  12212. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  12213. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  12214. unsigned int seconds;
  12215. int hours, minutes;
  12216. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  12217. hours = seconds / (60 * 60);
  12218. seconds = seconds - (60 * 60 * hours);
  12219. minutes = seconds / 60;
  12220. WFIFOB(fd,2) = 3;
  12221. WFIFOW(fd,11) = hours; // Hours
  12222. WFIFOW(fd,13) = minutes; // Minutes
  12223. }
  12224. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  12225. }
  12226. WFIFOSET(fd,70);
  12227. }
  12228. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  12229. /// 02d6 <account id>.L
  12230. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  12231. {
  12232. int charid = RFIFOL(fd, 2);
  12233. struct map_session_data* tsd = map_id2sd(charid);
  12234. if (!tsd)
  12235. return;
  12236. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  12237. clif_viewequip_ack(sd, tsd);
  12238. else
  12239. clif_msg(sd, VIEW_EQUIP_FAIL);
  12240. }
  12241. /// Request to change equip window tick (CZ_CONFIG).
  12242. /// 02d8 <type>.L <value>.L
  12243. /// type:
  12244. /// 0 = open equip window
  12245. /// value:
  12246. /// 0 = disabled
  12247. /// 1 = enabled
  12248. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  12249. {
  12250. bool flag = (bool)RFIFOL(fd,6);
  12251. sd->status.show_equip = flag;
  12252. clif_equiptickack(sd, flag);
  12253. }
  12254. /// Questlog System [Kevin] [Inkfish]
  12255. ///
  12256. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  12257. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  12258. void clif_quest_send_list(struct map_session_data * sd)
  12259. {
  12260. int fd = sd->fd;
  12261. int i;
  12262. int len = sd->avail_quests*5+8;
  12263. WFIFOHEAD(fd,len);
  12264. WFIFOW(fd, 0) = 0x2b1;
  12265. WFIFOW(fd, 2) = len;
  12266. WFIFOL(fd, 4) = sd->avail_quests;
  12267. for( i = 0; i < sd->avail_quests; i++ ) {
  12268. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  12269. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  12270. }
  12271. WFIFOSET(fd, len);
  12272. }
  12273. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  12274. /// 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
  12275. void clif_quest_send_mission(struct map_session_data * sd)
  12276. {
  12277. int fd = sd->fd;
  12278. int i, j;
  12279. int len = sd->avail_quests*104+8;
  12280. struct mob_db *mob;
  12281. WFIFOHEAD(fd, len);
  12282. WFIFOW(fd, 0) = 0x2b2;
  12283. WFIFOW(fd, 2) = len;
  12284. WFIFOL(fd, 4) = sd->avail_quests;
  12285. for( i = 0; i < sd->avail_quests; i++ ) {
  12286. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  12287. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  12288. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  12289. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  12290. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ ) {
  12291. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  12292. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  12293. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  12294. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  12295. }
  12296. }
  12297. WFIFOSET(fd, len);
  12298. }
  12299. /// Notification about a new quest (ZC_ADD_QUEST).
  12300. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  12301. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  12302. {
  12303. int fd = sd->fd;
  12304. int i;
  12305. struct mob_db *mob;
  12306. WFIFOHEAD(fd, packet_len(0x2b3));
  12307. WFIFOW(fd, 0) = 0x2b3;
  12308. WFIFOL(fd, 2) = qd->quest_id;
  12309. WFIFOB(fd, 6) = qd->state;
  12310. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  12311. WFIFOL(fd, 11) = qd->time;
  12312. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  12313. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12314. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  12315. WFIFOW(fd, i*30+21) = qd->count[i];
  12316. mob = mob_db(quest_db[index].mob[i]);
  12317. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  12318. }
  12319. WFIFOSET(fd, packet_len(0x2b3));
  12320. }
  12321. /// Notification about a quest being removed (ZC_DEL_QUEST).
  12322. /// 02b4 <quest id>.L
  12323. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  12324. {
  12325. int fd = sd->fd;
  12326. WFIFOHEAD(fd, packet_len(0x2b4));
  12327. WFIFOW(fd, 0) = 0x2b4;
  12328. WFIFOL(fd, 2) = quest_id;
  12329. WFIFOSET(fd, packet_len(0x2b4));
  12330. }
  12331. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  12332. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  12333. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  12334. {
  12335. int fd = sd->fd;
  12336. int i;
  12337. int len = quest_db[index].num_objectives*12+6;
  12338. WFIFOHEAD(fd, len);
  12339. WFIFOW(fd, 0) = 0x2b5;
  12340. WFIFOW(fd, 2) = len;
  12341. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  12342. for( i = 0; i < quest_db[index].num_objectives; i++ ) {
  12343. WFIFOL(fd, i*12+6) = qd->quest_id;
  12344. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  12345. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  12346. WFIFOW(fd, i*12+16) = qd->count[i];
  12347. }
  12348. WFIFOSET(fd, len);
  12349. }
  12350. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  12351. /// 02b6 <quest id>.L <active>.B
  12352. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  12353. {
  12354. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  12355. }
  12356. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  12357. /// 02b7 <quest id>.L <active>.B
  12358. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  12359. {
  12360. int fd = sd->fd;
  12361. WFIFOHEAD(fd, packet_len(0x2b7));
  12362. WFIFOW(fd, 0) = 0x2b7;
  12363. WFIFOL(fd, 2) = quest_id;
  12364. WFIFOB(fd, 6) = active;
  12365. WFIFOSET(fd, packet_len(0x2b7));
  12366. }
  12367. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  12368. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  12369. /// effect:
  12370. /// 0 = none
  12371. /// 1 = exclamation mark icon
  12372. /// 2 = question mark icon
  12373. /// type:
  12374. /// 0 = yellow
  12375. /// 1 = orange
  12376. /// 2 = green
  12377. /// 3 = purple
  12378. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  12379. {
  12380. #if PACKETVER >= 20090218
  12381. int fd = sd->fd;
  12382. WFIFOHEAD(fd, packet_len(0x446));
  12383. WFIFOW(fd, 0) = 0x446;
  12384. WFIFOL(fd, 2) = bl->id;
  12385. WFIFOW(fd, 6) = bl->x;
  12386. WFIFOW(fd, 8) = bl->y;
  12387. WFIFOW(fd, 10) = state;
  12388. WFIFOW(fd, 12) = color;
  12389. WFIFOSET(fd, packet_len(0x446));
  12390. #endif
  12391. }
  12392. /// Mercenary System
  12393. ///
  12394. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  12395. /// 02a2 <var id>.W <value>.L
  12396. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  12397. {
  12398. struct mercenary_data *md;
  12399. struct status_data *status;
  12400. int fd;
  12401. if( sd == NULL || (md = sd->md) == NULL )
  12402. return;
  12403. fd = sd->fd;
  12404. status = &md->battle_status;
  12405. WFIFOHEAD(fd,packet_len(0x2a2));
  12406. WFIFOW(fd,0) = 0x2a2;
  12407. WFIFOW(fd,2) = type;
  12408. switch( type ) {
  12409. case SP_ATK1:
  12410. {
  12411. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12412. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  12413. }
  12414. break;
  12415. case SP_MATK1:
  12416. WFIFOL(fd,4) = cap_value(status->matk_max, 0, INT16_MAX);
  12417. break;
  12418. case SP_HIT:
  12419. WFIFOL(fd,4) = status->hit;
  12420. break;
  12421. case SP_CRITICAL:
  12422. WFIFOL(fd,4) = status->cri/10;
  12423. break;
  12424. case SP_DEF1:
  12425. WFIFOL(fd,4) = status->def;
  12426. break;
  12427. case SP_MDEF1:
  12428. WFIFOL(fd,4) = status->mdef;
  12429. break;
  12430. case SP_MERCFLEE:
  12431. WFIFOL(fd,4) = status->flee;
  12432. break;
  12433. case SP_ASPD:
  12434. WFIFOL(fd,4) = status->amotion;
  12435. break;
  12436. case SP_HP:
  12437. WFIFOL(fd,4) = status->hp;
  12438. break;
  12439. case SP_MAXHP:
  12440. WFIFOL(fd,4) = status->max_hp;
  12441. break;
  12442. case SP_SP:
  12443. WFIFOL(fd,4) = status->sp;
  12444. break;
  12445. case SP_MAXSP:
  12446. WFIFOL(fd,4) = status->max_sp;
  12447. break;
  12448. case SP_MERCKILLS:
  12449. WFIFOL(fd,4) = md->mercenary.kill_count;
  12450. break;
  12451. case SP_MERCFAITH:
  12452. WFIFOL(fd,4) = mercenary_get_faith(md);
  12453. break;
  12454. }
  12455. WFIFOSET(fd,packet_len(0x2a2));
  12456. }
  12457. /// Mercenary base status data (ZC_MER_INIT).
  12458. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  12459. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  12460. /// <calls>.L <kills>.L <atk range>.W
  12461. void clif_mercenary_info(struct map_session_data *sd)
  12462. {
  12463. int fd;
  12464. struct mercenary_data *md;
  12465. struct status_data *status;
  12466. int atk;
  12467. if( sd == NULL || (md = sd->md) == NULL )
  12468. return;
  12469. fd = sd->fd;
  12470. status = &md->battle_status;
  12471. WFIFOHEAD(fd,packet_len(0x29b));
  12472. WFIFOW(fd,0) = 0x29b;
  12473. WFIFOL(fd,2) = md->bl.id;
  12474. // Mercenary shows ATK as a random value between ATK ~ ATK2
  12475. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  12476. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  12477. WFIFOW(fd,8) = cap_value(status->matk_max, 0, INT16_MAX);
  12478. WFIFOW(fd,10) = status->hit;
  12479. WFIFOW(fd,12) = status->cri/10;
  12480. WFIFOW(fd,14) = status->def;
  12481. WFIFOW(fd,16) = status->mdef;
  12482. WFIFOW(fd,18) = status->flee;
  12483. WFIFOW(fd,20) = status->amotion;
  12484. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  12485. WFIFOW(fd,46) = md->db->lv;
  12486. WFIFOL(fd,48) = status->hp;
  12487. WFIFOL(fd,52) = status->max_hp;
  12488. WFIFOL(fd,56) = status->sp;
  12489. WFIFOL(fd,60) = status->max_sp;
  12490. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  12491. WFIFOW(fd,68) = mercenary_get_faith(md);
  12492. WFIFOL(fd,70) = mercenary_get_calls(md);
  12493. WFIFOL(fd,74) = md->mercenary.kill_count;
  12494. WFIFOW(fd,78) = md->battle_status.rhw.range;
  12495. WFIFOSET(fd,packet_len(0x29b));
  12496. }
  12497. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  12498. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  12499. void clif_mercenary_skillblock(struct map_session_data *sd)
  12500. {
  12501. struct mercenary_data *md;
  12502. int fd, i, len = 4, id, j;
  12503. if( sd == NULL || (md = sd->md) == NULL )
  12504. return;
  12505. fd = sd->fd;
  12506. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  12507. WFIFOW(fd,0) = 0x29d;
  12508. for( i = 0; i < MAX_MERCSKILL; i++ )
  12509. {
  12510. if( (id = md->db->skill[i].id) == 0 )
  12511. continue;
  12512. j = id - MC_SKILLBASE;
  12513. WFIFOW(fd,len) = id;
  12514. WFIFOL(fd,len+2) = skill_get_inf(id);
  12515. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  12516. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  12517. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  12518. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  12519. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  12520. len += 37;
  12521. }
  12522. WFIFOW(fd,2) = len;
  12523. WFIFOSET(fd,len);
  12524. }
  12525. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  12526. /// 029f <command>.B
  12527. /// 1 = mercenary information
  12528. /// 2 = delete
  12529. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  12530. {
  12531. int option = RFIFOB(fd,2);
  12532. if( sd->md == NULL )
  12533. return;
  12534. if( option == 2 ) merc_delete(sd->md, 2);
  12535. }
  12536. /// Mercenary Message
  12537. /// message:
  12538. /// 0 = Mercenary soldier's duty hour is over.
  12539. /// 1 = Your mercenary soldier has been killed.
  12540. /// 2 = Your mercenary soldier has been fired.
  12541. /// 3 = Your mercenary soldier has ran away.
  12542. void clif_mercenary_message(struct map_session_data* sd, int message){
  12543. clif_msg(sd, MERC_MSG_BASE + message);
  12544. }
  12545. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  12546. /// 0298 <name id>.W <seconds>.L
  12547. void clif_rental_time(int fd, int nameid, int seconds)
  12548. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  12549. WFIFOHEAD(fd,packet_len(0x298));
  12550. WFIFOW(fd,0) = 0x298;
  12551. WFIFOW(fd,2) = nameid;
  12552. WFIFOL(fd,4) = seconds;
  12553. WFIFOSET(fd,packet_len(0x298));
  12554. }
  12555. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  12556. /// 0299 <index>.W <name id>.W
  12557. void clif_rental_expired(int fd, int index, int nameid)
  12558. { // '<ItemName>' item has been deleted from the Inventory
  12559. WFIFOHEAD(fd,packet_len(0x299));
  12560. WFIFOW(fd,0) = 0x299;
  12561. WFIFOW(fd,2) = index+2;
  12562. WFIFOW(fd,4) = nameid;
  12563. WFIFOSET(fd,packet_len(0x299));
  12564. }
  12565. /// Book Reading (ZC_READ_BOOK).
  12566. /// 0294 <book id>.L <page>.L
  12567. void clif_readbook(int fd, int book_id, int page)
  12568. {
  12569. WFIFOHEAD(fd,packet_len(0x294));
  12570. WFIFOW(fd,0) = 0x294;
  12571. WFIFOL(fd,2) = book_id;
  12572. WFIFOL(fd,6) = page;
  12573. WFIFOSET(fd,packet_len(0x294));
  12574. }
  12575. /// Battlegrounds
  12576. ///
  12577. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  12578. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  12579. void clif_bg_hp(struct map_session_data *sd)
  12580. {
  12581. unsigned char buf[34];
  12582. const int cmd = 0x2e0;
  12583. nullpo_retv(sd);
  12584. WBUFW(buf,0) = cmd;
  12585. WBUFL(buf,2) = sd->status.account_id;
  12586. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12587. if( sd->battle_status.max_hp > INT16_MAX )
  12588. { // To correctly display the %hp bar. [Skotlex]
  12589. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  12590. WBUFW(buf,32) = 100;
  12591. }
  12592. else
  12593. {
  12594. WBUFW(buf,30) = sd->battle_status.hp;
  12595. WBUFW(buf,32) = sd->battle_status.max_hp;
  12596. }
  12597. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  12598. }
  12599. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  12600. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  12601. void clif_bg_xy(struct map_session_data *sd)
  12602. {
  12603. unsigned char buf[36];
  12604. nullpo_retv(sd);
  12605. WBUFW(buf,0)=0x2df;
  12606. WBUFL(buf,2)=sd->status.account_id;
  12607. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  12608. WBUFW(buf,30)=sd->status.class_;
  12609. WBUFW(buf,32)=sd->bl.x;
  12610. WBUFW(buf,34)=sd->bl.y;
  12611. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12612. }
  12613. void clif_bg_xy_remove(struct map_session_data *sd)
  12614. {
  12615. unsigned char buf[36];
  12616. nullpo_retv(sd);
  12617. WBUFW(buf,0)=0x2df;
  12618. WBUFL(buf,2)=sd->status.account_id;
  12619. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  12620. WBUFW(buf,30)=0;
  12621. WBUFW(buf,32)=-1;
  12622. WBUFW(buf,34)=-1;
  12623. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  12624. }
  12625. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  12626. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  12627. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  12628. {
  12629. struct map_session_data *sd;
  12630. unsigned char *buf;
  12631. if( (sd = bg_getavailablesd(bg)) == NULL )
  12632. return;
  12633. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  12634. WBUFW(buf,0) = 0x2dc;
  12635. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  12636. WBUFL(buf,4) = src_id;
  12637. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  12638. memcpy(WBUFP(buf,32), mes, len);
  12639. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  12640. if( buf )
  12641. aFree(buf);
  12642. }
  12643. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  12644. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  12645. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  12646. {
  12647. const char* text = (char*)RFIFOP(fd,4);
  12648. int textlen = RFIFOW(fd,2) - 4;
  12649. char *name, *message;
  12650. int namelen, messagelen;
  12651. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  12652. return;
  12653. if( is_atcommand(fd, sd, message, 1) )
  12654. return;
  12655. if( sd->sc.data[SC_BERSERK] || sd->sc.data[SC__BLOODYLUST] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  12656. return;
  12657. if( battle_config.min_chat_delay ) {
  12658. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  12659. return;
  12660. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  12661. }
  12662. // Reset idle time when using battleground chat.
  12663. sd->idletime = last_tick;
  12664. bg_send_message(sd, text, textlen);
  12665. }
  12666. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  12667. /// 02de <camp A points>.W <camp B points>.W
  12668. void clif_bg_updatescore(int16 m)
  12669. {
  12670. struct block_list bl;
  12671. unsigned char buf[6];
  12672. bl.id = 0;
  12673. bl.type = BL_NUL;
  12674. bl.m = m;
  12675. WBUFW(buf,0) = 0x2de;
  12676. WBUFW(buf,2) = map[m].bgscore_lion;
  12677. WBUFW(buf,4) = map[m].bgscore_eagle;
  12678. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  12679. }
  12680. void clif_bg_updatescore_single(struct map_session_data *sd)
  12681. {
  12682. int fd;
  12683. nullpo_retv(sd);
  12684. fd = sd->fd;
  12685. WFIFOHEAD(fd,packet_len(0x2de));
  12686. WFIFOW(fd,0) = 0x2de;
  12687. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  12688. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  12689. WFIFOSET(fd,packet_len(0x2de));
  12690. }
  12691. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  12692. /// 02dd <account id>.L <name>.24B <camp>.W
  12693. void clif_sendbgemblem_area(struct map_session_data *sd)
  12694. {
  12695. unsigned char buf[33];
  12696. nullpo_retv(sd);
  12697. WBUFW(buf, 0) = 0x2dd;
  12698. WBUFL(buf,2) = sd->bl.id;
  12699. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  12700. WBUFW(buf,30) = sd->bg_id;
  12701. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  12702. }
  12703. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  12704. {
  12705. nullpo_retv(sd);
  12706. WFIFOHEAD(fd,32);
  12707. WFIFOW(fd,0) = 0x2dd;
  12708. WFIFOL(fd,2) = sd->bl.id;
  12709. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  12710. WFIFOW(fd,30) = sd->bg_id;
  12711. WFIFOSET(fd,packet_len(0x2dd));
  12712. }
  12713. /// Custom Fonts (ZC_NOTIFY_FONT).
  12714. /// 02ef <account_id>.L <font id>.W
  12715. void clif_font(struct map_session_data *sd)
  12716. {
  12717. #if PACKETVER >= 20080102
  12718. unsigned char buf[8];
  12719. nullpo_retv(sd);
  12720. WBUFW(buf,0) = 0x2ef;
  12721. WBUFL(buf,2) = sd->bl.id;
  12722. WBUFW(buf,6) = sd->user_font;
  12723. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12724. #endif
  12725. }
  12726. /*==========================================
  12727. * Instancing Window
  12728. *------------------------------------------*/
  12729. int clif_instance(int instance_id, int type, int flag)
  12730. {
  12731. struct map_session_data *sd;
  12732. struct party_data *p;
  12733. unsigned char buf[255];
  12734. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12735. return 0;
  12736. switch( type )
  12737. {
  12738. case 1:
  12739. // S 0x2cb <Instance name>.61B <Standby Position>.W
  12740. // Required to start the instancing information window on Client
  12741. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12742. WBUFW(buf,0) = 0x02CB;
  12743. memcpy(WBUFP(buf,2),instance[instance_id].name,INSTANCE_NAME_LENGTH);
  12744. WBUFW(buf,63) = flag;
  12745. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12746. break;
  12747. case 2:
  12748. // S 0x2cc <Standby Position>.W
  12749. // To announce Instancing queue creation if no maps available
  12750. WBUFW(buf,0) = 0x02CC;
  12751. WBUFW(buf,2) = flag;
  12752. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12753. break;
  12754. case 3:
  12755. case 4:
  12756. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12757. WBUFW(buf,0) = 0x02CD;
  12758. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12759. if( type == 3 )
  12760. {
  12761. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12762. WBUFL(buf,67) = 0;
  12763. }
  12764. else
  12765. {
  12766. WBUFL(buf,63) = 0;
  12767. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12768. }
  12769. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12770. break;
  12771. case 5:
  12772. // S 0x2ce <Message ID>.L
  12773. // 0 = Notification (EnterLimitDate update?)
  12774. // 1 = The Memorial Dungeon expired; it has been destroyed
  12775. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12776. // 3 = The Memorial Dungeon has been removed.
  12777. // 4 = Create failure (removes the instance window)
  12778. WBUFW(buf,0) = 0x02CE;
  12779. WBUFL(buf,2) = flag;
  12780. //WBUFL(buf,6) = EnterLimitDate;
  12781. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12782. break;
  12783. }
  12784. return 0;
  12785. }
  12786. void clif_instance_join(int fd, int instance_id)
  12787. {
  12788. if( instance[instance_id].idle_timer != INVALID_TIMER ) {
  12789. WFIFOHEAD(fd,packet_len(0x02CD));
  12790. WFIFOW(fd,0) = 0x02CD;
  12791. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12792. WFIFOL(fd,63) = 0;
  12793. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12794. WFIFOSET(fd,packet_len(0x02CD));
  12795. } else if( instance[instance_id].progress_timer != INVALID_TIMER ) {
  12796. WFIFOHEAD(fd,packet_len(0x02CD));
  12797. WFIFOW(fd,0) = 0x02CD;
  12798. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12799. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12800. WFIFOL(fd,67) = 0;
  12801. WFIFOSET(fd,packet_len(0x02CD));
  12802. } else {
  12803. WFIFOHEAD(fd,packet_len(0x02CB));
  12804. WFIFOW(fd,0) = 0x02CB;
  12805. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12806. WFIFOW(fd,63) = 0;
  12807. WFIFOSET(fd,packet_len(0x02CB));
  12808. }
  12809. }
  12810. void clif_instance_leave(int fd)
  12811. {
  12812. WFIFOHEAD(fd,packet_len(0x02CE));
  12813. WFIFOW(fd,0) = 0x02ce;
  12814. WFIFOL(fd,2) = 4;
  12815. WFIFOSET(fd,packet_len(0x02CE));
  12816. }
  12817. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  12818. /// 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
  12819. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12820. {
  12821. #if PACKETVER >= 20071002
  12822. unsigned char buf[22];
  12823. struct item_data* id = itemdb_search(item_data->nameid);
  12824. WBUFW(buf,0) = 0x2b8;
  12825. WBUFL(buf,2) = sd->status.account_id;
  12826. WBUFW(buf,6) = item_data->nameid;
  12827. WBUFB(buf,8) = item_data->identify;
  12828. WBUFB(buf,9) = item_data->attribute;
  12829. WBUFB(buf,10) = item_data->refine;
  12830. clif_addcards(WBUFP(buf,11), item_data);
  12831. WBUFW(buf,19) = id->equip; // equip location
  12832. WBUFB(buf,21) = itemtype(id->type); // item type
  12833. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12834. #endif
  12835. }
  12836. /// Display gained exp (ZC_NOTIFY_EXP).
  12837. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  12838. /// var id:
  12839. /// SP_BASEEXP, SP_JOBEXP
  12840. /// exp type:
  12841. /// 0 = normal exp gain/loss
  12842. /// 1 = quest exp gain/loss
  12843. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12844. {
  12845. int fd;
  12846. nullpo_retv(sd);
  12847. fd = sd->fd;
  12848. WFIFOHEAD(fd, packet_len(0x7f6));
  12849. WFIFOW(fd,0) = 0x7f6;
  12850. WFIFOL(fd,2) = sd->bl.id;
  12851. WFIFOL(fd,6) = exp;
  12852. WFIFOW(fd,10) = type;
  12853. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12854. WFIFOSET(fd,packet_len(0x7f6));
  12855. }
  12856. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12857. /// type:
  12858. /// 0 = Displays 'value' for 5 seconds.
  12859. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12860. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12861. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12862. /// value:
  12863. /// 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).
  12864. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12865. {
  12866. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12867. WFIFOW(sd->fd,0) = 0x1b1;
  12868. WFIFOB(sd->fd,2) = type;
  12869. WFIFOL(sd->fd,3) = value;
  12870. WFIFOSET(sd->fd, packet_len(0x1b1));
  12871. }
  12872. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  12873. /// 021d <state>.L
  12874. /// state:
  12875. /// 0 = Full effects
  12876. /// 1 = Reduced effects
  12877. ///
  12878. /// NOTE: The state is used on Aegis for sending skill unit packet
  12879. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  12880. /// whenever possible. Due to the way the decision check is
  12881. /// constructed, this state tracking was rendered useless,
  12882. /// as the only skill unit, that is sent with 0x1c9 is
  12883. /// Graffiti.
  12884. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  12885. {
  12886. int isLess = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  12887. sd->state.lesseffect = ( isLess != 0 );
  12888. }
  12889. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  12890. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  12891. int n = (RFIFOW(fd,2)-12) / 4;
  12892. int type = RFIFOL(fd,4);
  12893. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  12894. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  12895. if( sd->state.trading || sd->npc_shopid )
  12896. return;
  12897. if( flag == 0 || n == 0) {
  12898. clif_menuskill_clear(sd);
  12899. return; // Canceled by player.
  12900. }
  12901. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  12902. clif_menuskill_clear(sd);
  12903. return; // Prevent hacking.
  12904. }
  12905. switch( type ) {
  12906. case 0: // Change Material
  12907. skill_changematerial(sd,n,item_list);
  12908. break;
  12909. case 1: // Level 1: Pure to Rough
  12910. case 2: // Level 2: Rough to Pure
  12911. skill_elementalanalysis(sd,n,type,item_list);
  12912. break;
  12913. }
  12914. clif_menuskill_clear(sd);
  12915. return;
  12916. }
  12917. /*==========================================
  12918. * Elemental System
  12919. *==========================================*/
  12920. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  12921. struct elemental_data *ed;
  12922. struct status_data *status;
  12923. int fd;
  12924. if( sd == NULL || (ed = sd->ed) == NULL )
  12925. return;
  12926. fd = sd->fd;
  12927. status = &ed->battle_status;
  12928. WFIFOHEAD(fd,8);
  12929. WFIFOW(fd,0) = 0x81e;
  12930. WFIFOW(fd,2) = type;
  12931. switch( type ) {
  12932. case SP_HP:
  12933. WFIFOL(fd,4) = status->hp;
  12934. break;
  12935. case SP_MAXHP:
  12936. WFIFOL(fd,4) = status->max_hp;
  12937. break;
  12938. case SP_SP:
  12939. WFIFOL(fd,4) = status->sp;
  12940. break;
  12941. case SP_MAXSP:
  12942. WFIFOL(fd,4) = status->max_sp;
  12943. break;
  12944. }
  12945. WFIFOSET(fd,8);
  12946. }
  12947. void clif_elemental_info(struct map_session_data *sd) {
  12948. int fd;
  12949. struct elemental_data *ed;
  12950. struct status_data *status;
  12951. if( sd == NULL || (ed = sd->ed) == NULL )
  12952. return;
  12953. fd = sd->fd;
  12954. status = &ed->battle_status;
  12955. WFIFOHEAD(fd,22);
  12956. WFIFOW(fd, 0) = 0x81d;
  12957. WFIFOL(fd, 2) = ed->bl.id;
  12958. WFIFOL(fd, 6) = status->hp;
  12959. WFIFOL(fd,10) = status->max_hp;
  12960. WFIFOL(fd,14) = status->sp;
  12961. WFIFOL(fd,18) = status->max_sp;
  12962. WFIFOSET(fd,22);
  12963. }
  12964. /// Buying Store System
  12965. ///
  12966. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  12967. /// 0810 <slots>.B
  12968. void clif_buyingstore_open(struct map_session_data* sd)
  12969. {
  12970. int fd = sd->fd;
  12971. WFIFOHEAD(fd,packet_len(0x810));
  12972. WFIFOW(fd,0) = 0x810;
  12973. WFIFOB(fd,2) = sd->buyingstore.slots;
  12974. WFIFOSET(fd,packet_len(0x810));
  12975. }
  12976. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  12977. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  12978. /// result:
  12979. /// 0 = cancel
  12980. /// 1 = open
  12981. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  12982. {
  12983. const unsigned int blocksize = 8;
  12984. uint8* itemlist;
  12985. char storename[MESSAGE_SIZE];
  12986. unsigned char result;
  12987. int zenylimit;
  12988. unsigned int count, packet_len;
  12989. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  12990. packet_len = RFIFOW(fd,info->pos[0]);
  12991. // TODO: Make this check global for all variable length packets.
  12992. if( packet_len < 89 )
  12993. {// minimum packet length
  12994. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  12995. return;
  12996. }
  12997. zenylimit = RFIFOL(fd,info->pos[1]);
  12998. result = RFIFOL(fd,info->pos[2]);
  12999. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  13000. itemlist = RFIFOP(fd,info->pos[4]);
  13001. // so that buyingstore_create knows, how many elements it has access to
  13002. packet_len-= info->pos[4];
  13003. if( packet_len%blocksize )
  13004. {
  13005. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13006. return;
  13007. }
  13008. count = packet_len/blocksize;
  13009. buyingstore_create(sd, zenylimit, result, storename, itemlist, count);
  13010. }
  13011. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  13012. /// 0812 <result>.W <total weight>.L
  13013. /// result:
  13014. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  13015. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  13016. /// 8 = "No sale (purchase) information available." (0x705)
  13017. /// ? = nothing
  13018. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  13019. {
  13020. int fd = sd->fd;
  13021. WFIFOHEAD(fd,packet_len(0x812));
  13022. WFIFOW(fd,0) = 0x812;
  13023. WFIFOW(fd,2) = result;
  13024. WFIFOL(fd,4) = weight;
  13025. WFIFOSET(fd,packet_len(0x812));
  13026. }
  13027. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  13028. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  13029. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  13030. {
  13031. int fd = sd->fd;
  13032. unsigned int i;
  13033. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  13034. WFIFOW(fd,0) = 0x813;
  13035. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  13036. WFIFOL(fd,4) = sd->bl.id;
  13037. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  13038. for( i = 0; i < sd->buyingstore.slots; i++ )
  13039. {
  13040. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  13041. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  13042. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  13043. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  13044. }
  13045. WFIFOSET(fd,WFIFOW(fd,2));
  13046. }
  13047. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  13048. /// 0814 <account id>.L <store name>.80B
  13049. void clif_buyingstore_entry(struct map_session_data* sd)
  13050. {
  13051. uint8 buf[86];
  13052. WBUFW(buf,0) = 0x814;
  13053. WBUFL(buf,2) = sd->bl.id;
  13054. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  13055. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  13056. }
  13057. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13058. {
  13059. int fd = sd->fd;
  13060. WFIFOHEAD(fd,packet_len(0x814));
  13061. WFIFOW(fd,0) = 0x814;
  13062. WFIFOL(fd,2) = pl_sd->bl.id;
  13063. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  13064. WFIFOSET(fd,packet_len(0x814));
  13065. }
  13066. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  13067. /// 0815
  13068. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  13069. {
  13070. buyingstore_close(sd);
  13071. }
  13072. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  13073. /// 0816 <account id>.L
  13074. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  13075. {
  13076. uint8 buf[6];
  13077. WBUFW(buf,0) = 0x816;
  13078. WBUFL(buf,2) = sd->bl.id;
  13079. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  13080. }
  13081. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  13082. {
  13083. int fd = sd->fd;
  13084. WFIFOHEAD(fd,packet_len(0x816));
  13085. WFIFOW(fd,0) = 0x816;
  13086. WFIFOL(fd,2) = pl_sd->bl.id;
  13087. WFIFOSET(fd,packet_len(0x816));
  13088. }
  13089. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  13090. /// 0817 <account id>.L
  13091. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  13092. {
  13093. int account_id;
  13094. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  13095. buyingstore_open(sd, account_id);
  13096. }
  13097. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  13098. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  13099. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  13100. {
  13101. int fd = sd->fd;
  13102. unsigned int i;
  13103. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  13104. WFIFOW(fd,0) = 0x818;
  13105. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  13106. WFIFOL(fd,4) = pl_sd->bl.id;
  13107. WFIFOL(fd,8) = pl_sd->buyer_id;
  13108. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  13109. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  13110. {
  13111. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  13112. 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.
  13113. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  13114. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  13115. }
  13116. WFIFOSET(fd,WFIFOW(fd,2));
  13117. }
  13118. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  13119. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  13120. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  13121. {
  13122. const unsigned int blocksize = 6;
  13123. uint8* itemlist;
  13124. int account_id;
  13125. unsigned int count, packet_len, buyer_id;
  13126. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13127. packet_len = RFIFOW(fd,info->pos[0]);
  13128. if( packet_len < 12 )
  13129. {// minimum packet length
  13130. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  13131. return;
  13132. }
  13133. account_id = RFIFOL(fd,info->pos[1]);
  13134. buyer_id = RFIFOL(fd,info->pos[2]);
  13135. itemlist = RFIFOP(fd,info->pos[3]);
  13136. // so that buyingstore_trade knows, how many elements it has access to
  13137. packet_len-= info->pos[3];
  13138. if( packet_len%blocksize )
  13139. {
  13140. 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);
  13141. return;
  13142. }
  13143. count = packet_len/blocksize;
  13144. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  13145. }
  13146. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  13147. /// 081a <result>.W
  13148. /// result:
  13149. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  13150. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  13151. /// ? = nothing
  13152. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  13153. {
  13154. int fd = sd->fd;
  13155. WFIFOHEAD(fd,packet_len(0x81a));
  13156. WFIFOW(fd,0) = 0x81a;
  13157. WFIFOW(fd,2) = result;
  13158. WFIFOSET(fd,packet_len(0x81a));
  13159. }
  13160. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  13161. /// 081b <name id>.W <amount>.W <limit zeny>.L
  13162. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  13163. {
  13164. int fd = sd->fd;
  13165. WFIFOHEAD(fd,packet_len(0x81b));
  13166. WFIFOW(fd,0) = 0x81b;
  13167. WFIFOW(fd,2) = nameid;
  13168. WFIFOW(fd,4) = amount; // amount of nameid received
  13169. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  13170. WFIFOSET(fd,packet_len(0x81b));
  13171. }
  13172. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  13173. /// 081c <index>.W <amount>.W <price>.L
  13174. /// message:
  13175. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  13176. ///
  13177. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  13178. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  13179. {
  13180. int fd = sd->fd;
  13181. WFIFOHEAD(fd,packet_len(0x81c));
  13182. WFIFOW(fd,0) = 0x81c;
  13183. WFIFOW(fd,2) = index+2;
  13184. WFIFOW(fd,4) = amount;
  13185. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  13186. WFIFOSET(fd,packet_len(0x81c));
  13187. }
  13188. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  13189. /// 0824 <result>.W <name id>.W
  13190. /// result:
  13191. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  13192. /// 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)
  13193. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  13194. /// ? = nothing
  13195. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  13196. {
  13197. int fd = sd->fd;
  13198. WFIFOHEAD(fd,packet_len(0x824));
  13199. WFIFOW(fd,0) = 0x824;
  13200. WFIFOW(fd,2) = result;
  13201. WFIFOW(fd,4) = nameid;
  13202. WFIFOSET(fd,packet_len(0x824));
  13203. }
  13204. /// Search Store Info System
  13205. ///
  13206. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  13207. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  13208. /// type:
  13209. /// 0 = Vending
  13210. /// 1 = Buying Store
  13211. ///
  13212. /// NOTE: The client determines the item ids by specifying a name and optionally,
  13213. /// amount of card slots. If the client does not know about the item it
  13214. /// cannot be searched.
  13215. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  13216. {
  13217. const unsigned int blocksize = 2;
  13218. const uint8* itemlist;
  13219. const uint8* cardlist;
  13220. unsigned char type;
  13221. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  13222. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13223. packet_len = RFIFOW(fd,info->pos[0]);
  13224. if( packet_len < 15 )
  13225. {// minimum packet length
  13226. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  13227. return;
  13228. }
  13229. type = RFIFOB(fd,info->pos[1]);
  13230. max_price = RFIFOL(fd,info->pos[2]);
  13231. min_price = RFIFOL(fd,info->pos[3]);
  13232. item_count = RFIFOB(fd,info->pos[4]);
  13233. card_count = RFIFOB(fd,info->pos[5]);
  13234. itemlist = RFIFOP(fd,info->pos[6]);
  13235. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  13236. // check, if there is enough data for the claimed count of items
  13237. packet_len-= info->pos[6];
  13238. if( packet_len%blocksize )
  13239. {
  13240. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  13241. return;
  13242. }
  13243. count = packet_len/blocksize;
  13244. if( count < item_count+card_count )
  13245. {
  13246. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  13247. return;
  13248. }
  13249. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  13250. }
  13251. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  13252. /// 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 }*
  13253. /// is first page:
  13254. /// 0 = appends to existing results
  13255. /// 1 = clears previous results before displaying this result set
  13256. /// is next page:
  13257. /// 0 = no "next" label
  13258. /// 1 = "next" label to retrieve more results
  13259. void clif_search_store_info_ack(struct map_session_data* sd)
  13260. {
  13261. const unsigned int blocksize = MESSAGE_SIZE+26;
  13262. int fd = sd->fd;
  13263. unsigned int i, start, end;
  13264. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  13265. end = min(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  13266. WFIFOHEAD(fd,7+(end-start)*blocksize);
  13267. WFIFOW(fd,0) = 0x836;
  13268. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  13269. WFIFOB(fd,4) = !sd->searchstore.pages;
  13270. WFIFOB(fd,5) = searchstore_querynext(sd);
  13271. WFIFOB(fd,6) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13272. for( i = start; i < end; i++ ) {
  13273. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  13274. struct item it;
  13275. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  13276. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  13277. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  13278. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  13279. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(itemdb_type(ssitem->nameid));
  13280. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  13281. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  13282. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  13283. // make-up an item for clif_addcards
  13284. memset(&it, 0, sizeof(it));
  13285. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  13286. it.nameid = ssitem->nameid;
  13287. it.amount = ssitem->amount;
  13288. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  13289. }
  13290. WFIFOSET(fd,WFIFOW(fd,2));
  13291. }
  13292. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  13293. /// 0837 <reason>.B
  13294. /// reason:
  13295. /// 0 = "No matching stores were found." (0x70b)
  13296. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  13297. /// 2 = "You cannot search anymore." (0x706)
  13298. /// 3 = "You cannot search yet." (0x708)
  13299. /// 4 = "No sale (purchase) information available." (0x705)
  13300. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  13301. {
  13302. int fd = sd->fd;
  13303. WFIFOHEAD(fd,packet_len(0x837));
  13304. WFIFOW(fd,0) = 0x837;
  13305. WFIFOB(fd,2) = reason;
  13306. WFIFOSET(fd,packet_len(0x837));
  13307. }
  13308. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  13309. /// 0838
  13310. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  13311. {
  13312. searchstore_next(sd);
  13313. }
  13314. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  13315. /// 083a <type>.W <remaining uses>.B
  13316. /// type:
  13317. /// 0 = Search Stores
  13318. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  13319. void clif_open_search_store_info(struct map_session_data* sd)
  13320. {
  13321. int fd = sd->fd;
  13322. WFIFOHEAD(fd,packet_len(0x83a));
  13323. WFIFOW(fd,0) = 0x83a;
  13324. WFIFOW(fd,2) = sd->searchstore.effect;
  13325. #if PACKETVER > 20100701
  13326. WFIFOB(fd,4) = (unsigned char)min(sd->searchstore.uses, UINT8_MAX);
  13327. #endif
  13328. WFIFOSET(fd,packet_len(0x83a));
  13329. }
  13330. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  13331. /// 083b
  13332. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  13333. {
  13334. searchstore_close(sd);
  13335. }
  13336. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  13337. /// 083c <account id>.L <store id>.L <nameid>.W
  13338. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  13339. {
  13340. unsigned short nameid;
  13341. int account_id, store_id;
  13342. struct s_packet_db* info = &packet_db[sd->packet_ver][RFIFOW(fd,0)];
  13343. account_id = RFIFOL(fd,info->pos[0]);
  13344. store_id = RFIFOL(fd,info->pos[1]);
  13345. nameid = RFIFOW(fd,info->pos[2]);
  13346. searchstore_click(sd, account_id, store_id, nameid);
  13347. }
  13348. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  13349. /// 083d <xPos>.W <yPos>.W
  13350. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  13351. {
  13352. int fd = sd->fd;
  13353. WFIFOHEAD(fd,packet_len(0x83d));
  13354. WFIFOW(fd,0) = 0x83d;
  13355. WFIFOW(fd,2) = x;
  13356. WFIFOW(fd,4) = y;
  13357. WFIFOSET(fd,packet_len(0x83d));
  13358. }
  13359. /// Parse function for packet debugging.
  13360. void clif_parse_debug(int fd,struct map_session_data *sd)
  13361. {
  13362. int cmd, packet_len;
  13363. // clif_parse ensures, that there is at least 2 bytes of data
  13364. cmd = RFIFOW(fd,0);
  13365. if( sd ) {
  13366. packet_len = packet_db[sd->packet_ver][cmd].len;
  13367. if( packet_len == 0 )
  13368. {// unknown
  13369. packet_len = RFIFOREST(fd);
  13370. }
  13371. else if( packet_len == -1 )
  13372. {// variable length
  13373. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  13374. }
  13375. 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);
  13376. }
  13377. else
  13378. {
  13379. packet_len = RFIFOREST(fd);
  13380. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13381. }
  13382. ShowDump(RFIFOP(fd,0), packet_len);
  13383. }
  13384. /*==========================================
  13385. * Server tells client to display a window similar to Magnifier (item) one
  13386. * Server populates the window with avilable elemental converter options according to player's inventory
  13387. *------------------------------------------*/
  13388. int clif_elementalconverter_list(struct map_session_data *sd) {
  13389. int i,c,view,fd;
  13390. nullpo_ret(sd);
  13391. /// Main client packet processing function
  13392. fd=sd->fd;
  13393. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  13394. WFIFOW(fd, 0)=0x1ad;
  13395. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  13396. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  13397. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  13398. WFIFOW(fd,c*2+ 4)= view;
  13399. else
  13400. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  13401. c++;
  13402. }
  13403. }
  13404. WFIFOW(fd,2) = c*2+4;
  13405. WFIFOSET(fd, WFIFOW(fd,2));
  13406. if (c > 0) {
  13407. sd->menuskill_id = SA_CREATECON;
  13408. sd->menuskill_val = c;
  13409. }
  13410. return 0;
  13411. }
  13412. /**
  13413. * Rune Knight
  13414. **/
  13415. void clif_millenniumshield(struct map_session_data *sd, short shields ) {
  13416. #if PACKETVER >= 20081217
  13417. unsigned char buf[10];
  13418. WBUFW(buf,0) = 0x440;
  13419. WBUFL(buf,2) = sd->bl.id;
  13420. WBUFW(buf,6) = shields;
  13421. WBUFW(buf,8) = 0;
  13422. clif_send(buf,packet_len(0x440),&sd->bl,AREA);
  13423. #endif
  13424. }
  13425. /**
  13426. * Warlock
  13427. **/
  13428. /*==========================================
  13429. * Spellbook list [LimitLine/3CeAM]
  13430. *------------------------------------------*/
  13431. int clif_spellbook_list(struct map_session_data *sd)
  13432. {
  13433. int i, c;
  13434. int fd;
  13435. nullpo_ret(sd);
  13436. fd = sd->fd;
  13437. WFIFOHEAD(fd, 8 * 8 + 8);
  13438. WFIFOW(fd,0) = 0x1ad;
  13439. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  13440. {
  13441. if( itemdb_is_spellbook(sd->status.inventory[i].nameid) )
  13442. {
  13443. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13444. c ++;
  13445. }
  13446. }
  13447. if( c > 0 )
  13448. {
  13449. WFIFOW(fd,2) = c * 2 + 4;
  13450. WFIFOSET(fd, WFIFOW(fd, 2));
  13451. sd->menuskill_id = WL_READING_SB;
  13452. sd->menuskill_val = c;
  13453. }
  13454. else{
  13455. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13456. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  13457. }
  13458. return 1;
  13459. }
  13460. /**
  13461. * Mechanic
  13462. **/
  13463. /*==========================================
  13464. * Magic Decoy Material List
  13465. *------------------------------------------*/
  13466. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  13467. int i, c;
  13468. int fd;
  13469. nullpo_ret(sd);
  13470. fd = sd->fd;
  13471. WFIFOHEAD(fd, 8 * 8 + 8);
  13472. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13473. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13474. if( itemdb_is_element(sd->status.inventory[i].nameid) ) {
  13475. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13476. c ++;
  13477. }
  13478. }
  13479. if( c > 0 ) {
  13480. sd->menuskill_id = NC_MAGICDECOY;
  13481. sd->menuskill_val = skill_lv;
  13482. sd->sc.comet_x = x;
  13483. sd->sc.comet_y = y;
  13484. WFIFOW(fd,2) = c * 2 + 4;
  13485. WFIFOSET(fd, WFIFOW(fd, 2));
  13486. } else {
  13487. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  13488. return 0;
  13489. }
  13490. return 1;
  13491. }
  13492. /**
  13493. * Guilotine Cross
  13494. **/
  13495. /*==========================================
  13496. * Guillotine Cross Poisons List
  13497. *------------------------------------------*/
  13498. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  13499. int i, c;
  13500. int fd;
  13501. nullpo_ret(sd);
  13502. fd = sd->fd;
  13503. WFIFOHEAD(fd, 8 * 8 + 8);
  13504. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  13505. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  13506. if( itemdb_is_poison(sd->status.inventory[i].nameid) ) {
  13507. WFIFOW(fd, c * 2 + 4) = sd->status.inventory[i].nameid;
  13508. c ++;
  13509. }
  13510. }
  13511. if( c > 0 ) {
  13512. sd->menuskill_id = GC_POISONINGWEAPON;
  13513. sd->menuskill_val = skill_lv;
  13514. WFIFOW(fd,2) = c * 2 + 4;
  13515. WFIFOSET(fd, WFIFOW(fd, 2));
  13516. } else {
  13517. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  13518. return 0;
  13519. }
  13520. return 1;
  13521. }
  13522. int clif_autoshadowspell_list(struct map_session_data *sd) {
  13523. int fd, i, c;
  13524. nullpo_ret(sd);
  13525. fd = sd->fd;
  13526. if( !fd ) return 0;
  13527. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  13528. return 0;
  13529. WFIFOHEAD(fd, 2 * 6 + 4);
  13530. WFIFOW(fd,0) = 0x442;
  13531. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  13532. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  13533. sd->status.skill[i].id < GS_GLITTERING && skill_get_type(sd->status.skill[i].id) == BF_MAGIC )
  13534. { // Can't auto cast both Extended class and 3rd class skills.
  13535. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  13536. c++;
  13537. }
  13538. if( c > 0 ) {
  13539. WFIFOW(fd,2) = 8 + c * 2;
  13540. WFIFOL(fd,4) = c;
  13541. WFIFOSET(fd,WFIFOW(fd,2));
  13542. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  13543. sd->menuskill_val = c;
  13544. } else {
  13545. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  13546. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  13547. }
  13548. return 1;
  13549. }
  13550. /*===========================================
  13551. * Skill list for Four Elemental Analysis
  13552. * and Change Material skills.
  13553. *------------------------------------------*/
  13554. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv )
  13555. {
  13556. #if PACKETVER >= 20090922
  13557. int fd;
  13558. nullpo_ret(sd);
  13559. sd->menuskill_id = skill_id; // To prevent hacking.
  13560. sd->menuskill_val = skill_lv;
  13561. if( skill_id == GN_CHANGEMATERIAL )
  13562. skill_lv = 0; // Changematerial
  13563. fd = sd->fd;
  13564. WFIFOHEAD(fd,packet_len(0x7e3));
  13565. WFIFOW(fd,0) = 0x7e3;
  13566. WFIFOL(fd,2) = skill_lv;
  13567. WFIFOL(fd,4) = 0;
  13568. WFIFOSET(fd,packet_len(0x7e3));
  13569. #endif
  13570. return 1;
  13571. }
  13572. /**
  13573. * Sends a new status without a tick (currently used by the new mounts)
  13574. **/
  13575. int clif_status_load_notick(struct block_list *bl,int type,int flag,int val1, int val2, int val3) {
  13576. unsigned char buf[32];
  13577. nullpo_ret(bl);
  13578. WBUFW(buf,0)=0x043f;
  13579. WBUFW(buf,2)=type;
  13580. WBUFL(buf,4)=bl->id;
  13581. WBUFB(buf,8)=flag;
  13582. WBUFL(buf,9) = 0;
  13583. WBUFL(buf,13) = val1;
  13584. WBUFL(buf,17) = val2;
  13585. WBUFL(buf,21) = val3;
  13586. clif_send(buf,packet_len(0x043f),bl,AREA);
  13587. return 0;
  13588. }
  13589. //Notifies FD of ID's type
  13590. int clif_status_load_single(int fd, int id,int type,int flag,int val1, int val2, int val3) {
  13591. WFIFOHEAD(fd, packet_len(0x043f));
  13592. WFIFOW(fd,0)=0x043f;
  13593. WFIFOW(fd,2)=type;
  13594. WFIFOL(fd,4)=id;
  13595. WFIFOB(fd,8)=flag;
  13596. WFIFOL(fd,9) = 0;
  13597. WFIFOL(fd,13) = val1;
  13598. WFIFOL(fd,17) = val2;
  13599. WFIFOL(fd,21) = val3;
  13600. WFIFOSET(fd, packet_len(0x043f));
  13601. return 0;
  13602. }
  13603. // msgstringtable.txt
  13604. // 0x291 <line>.W
  13605. void clif_msgtable(int fd, int line) {
  13606. WFIFOHEAD(fd, packet_len(0x291));
  13607. WFIFOW(fd, 0) = 0x291;
  13608. WFIFOW(fd, 2) = line;
  13609. WFIFOSET(fd, packet_len(0x291));
  13610. }
  13611. // msgstringtable.txt
  13612. // 0x7e2 <line>.W <value>.L
  13613. void clif_msgtable_num(int fd, int line, int num) {
  13614. #if PACKETVER >= 20090805
  13615. WFIFOHEAD(fd, packet_len(0x7e2));
  13616. WFIFOW(fd, 0) = 0x7e2;
  13617. WFIFOW(fd, 2) = line;
  13618. WFIFOL(fd, 4) = num;
  13619. WFIFOSET(fd, packet_len(0x7e2));
  13620. #endif
  13621. }
  13622. /*==========================================
  13623. * used by SC_AUTOSHADOWSPELL
  13624. * RFIFOL(fd,2) - flag (currently not used)
  13625. *------------------------------------------*/
  13626. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  13627. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  13628. return;
  13629. if( pc_istrading(sd) ) {
  13630. clif_skill_fail(sd,sd->ud.skill_id,0,0);
  13631. clif_menuskill_clear(sd);
  13632. return;
  13633. }
  13634. skill_select_menu(sd,RFIFOW(fd,6));
  13635. clif_menuskill_clear(sd);
  13636. }
  13637. /*==========================================
  13638. * Kagerou/Oboro amulet spirit
  13639. *------------------------------------------*/
  13640. void clif_talisman(struct map_session_data *sd,short type)
  13641. {
  13642. unsigned char buf[10];
  13643. nullpo_retv(sd);
  13644. WBUFW(buf,0)=0x08cf;
  13645. WBUFL(buf,2)=sd->bl.id;
  13646. WBUFW(buf,6)=type;
  13647. WBUFW(buf,8)=sd->talisman[type];
  13648. clif_send(buf,packet_len(0x08cf),&sd->bl,AREA);
  13649. }
  13650. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  13651. /// 0907 <index>.W
  13652. ///
  13653. /// R 0908 <index>.w <type>.b
  13654. /// type:
  13655. /// 0 = move item to personal tab
  13656. /// 1 = move item to normal tab
  13657. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  13658. #if PACKETVER >= 20111122
  13659. int index;
  13660. /* can't move while dead. */
  13661. if(pc_isdead(sd)) {
  13662. return;
  13663. }
  13664. index = RFIFOW(fd,2)-2;
  13665. if (index < 0 || index >= MAX_INVENTORY)
  13666. return;
  13667. if ( sd->status.inventory[index].favorite && RFIFOB(fd, 4) == 1 )
  13668. sd->status.inventory[index].favorite = 0;
  13669. else if( RFIFOB(fd, 4) == 0 )
  13670. sd->status.inventory[index].favorite = 1;
  13671. else
  13672. return;/* nothing to do. */
  13673. clif_favorite_item(sd, index);
  13674. #endif
  13675. }
  13676. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  13677. /// 0900 <index>.W <favorite>.B
  13678. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  13679. int fd = sd->fd;
  13680. WFIFOHEAD(fd,packet_len(0x908));
  13681. WFIFOW(fd,0) = 0x908;
  13682. WFIFOW(fd,2) = index+2;
  13683. WFIFOL(fd,4) = (sd->status.inventory[index].favorite == 1) ? 0 : 1;
  13684. WFIFOSET(fd,packet_len(0x908));
  13685. }
  13686. void clif_snap( struct block_list *bl, short x, short y ) {
  13687. unsigned char buf[10];
  13688. WBUFW(buf,0) = 0x8d2;
  13689. WBUFL(buf,2) = bl->id;
  13690. WBUFW(buf,6) = x;
  13691. WBUFW(buf,8) = y;
  13692. clif_send(buf,packet_len(0x8d2),bl,AREA);
  13693. }
  13694. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  13695. #if PACKETVER >= 20120404
  13696. WFIFOHEAD(fd,packet_len(0x977));
  13697. WFIFOW(fd,0) = 0x977;
  13698. WFIFOL(fd,2) = md->bl.id;
  13699. WFIFOL(fd,6) = md->status.hp;
  13700. WFIFOL(fd,10) = md->status.max_hp;
  13701. WFIFOSET(fd,packet_len(0x977));
  13702. #endif
  13703. }
  13704. void clif_cashshop_open( struct map_session_data* sd ){
  13705. WFIFOHEAD( sd->fd, 10 );
  13706. WFIFOW( sd->fd, 0 ) = 0x845;
  13707. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13708. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13709. WFIFOSET( sd->fd, 10 );
  13710. }
  13711. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13712. clif_cashshop_open( sd );
  13713. }
  13714. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13715. // No need to do anything here
  13716. }
  13717. void clif_cashshop_list( int fd ){
  13718. int tab;
  13719. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_SEARCH; tab++ ){
  13720. int length = 8 + cash_shop_items->count * 6;
  13721. int i, offset;
  13722. WFIFOHEAD( fd, length );
  13723. WFIFOW( fd, 0 ) = 0x8ca;
  13724. WFIFOW( fd, 2 ) = length;
  13725. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13726. WFIFOW( fd, 6 ) = tab;
  13727. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13728. WFIFOW( fd, offset ) = cash_shop_items[tab].item[i]->nameid;
  13729. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13730. }
  13731. WFIFOSET( fd, length );
  13732. }
  13733. }
  13734. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13735. clif_cashshop_list( fd );
  13736. }
  13737. // TODO: find a more accurate date for this
  13738. #if PACKETVER >= 20130320
  13739. void clif_parse_cashshop_buy( int fd, struct map_session_data *sd ){
  13740. uint16 length = RFIFOW( fd, 2 );
  13741. uint16 count = RFIFOL( fd, 4 );
  13742. if( length < 10 || length < ( 10 + count * 6 ) ){
  13743. return;
  13744. }
  13745. cashshop_buylist( sd, RFIFOL( fd, 6 ), count, (uint16 *)RFIFOP( fd, 10 ) );
  13746. }
  13747. #endif
  13748. void clif_cashshop_result( struct map_session_data *sd, uint16 item_id, uint16 result ){
  13749. WFIFOHEAD( sd->fd, 16 );
  13750. WFIFOW( sd->fd, 0 ) = 0x849;
  13751. WFIFOL( sd->fd, 2 ) = item_id;
  13752. WFIFOW( sd->fd, 6 ) = result;
  13753. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13754. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13755. WFIFOSET( sd->fd, 16 );
  13756. }
  13757. /*==========================================
  13758. * Main client packet processing function
  13759. *------------------------------------------*/
  13760. static int clif_parse(int fd)
  13761. {
  13762. int cmd, packet_ver, packet_len, err;
  13763. TBL_PC* sd;
  13764. int pnum;
  13765. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  13766. // Note: "click masters" can do 80+ clicks in 10 seconds
  13767. 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]
  13768. { // begin main client packet processing loop
  13769. sd = (TBL_PC *)session[fd]->session_data;
  13770. if (session[fd]->flag.eof) {
  13771. if (sd) {
  13772. if (sd->state.autotrade) {
  13773. //Disassociate character from the socket connection.
  13774. session[fd]->session_data = NULL;
  13775. sd->fd = 0;
  13776. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", sd->status.name);
  13777. } else
  13778. if (sd->state.active) {
  13779. // Player logout display [Valaris]
  13780. ShowInfo("Character '"CL_WHITE"%s"CL_RESET"' logged off.\n", sd->status.name);
  13781. clif_quitsave(fd, sd);
  13782. } else {
  13783. //Unusual logout (during log on/off/map-changer procedure)
  13784. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  13785. map_quit(sd);
  13786. }
  13787. } else {
  13788. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  13789. }
  13790. do_close(fd);
  13791. return 0;
  13792. }
  13793. if (RFIFOREST(fd) < 2)
  13794. return 0;
  13795. cmd = RFIFOW(fd,0);
  13796. // identify client's packet version
  13797. if (sd) {
  13798. packet_ver = sd->packet_ver;
  13799. } else {
  13800. // check authentification packet to know packet version
  13801. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  13802. if( err ) {// failed to identify packet version
  13803. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s (p:0x%04x,l:%d).\n", fd, (
  13804. err == 1 ? "" :
  13805. err == 2 ? ", possibly for having an invalid account_id" :
  13806. err == 3 ? ", possibly for having an invalid char_id." :
  13807. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  13808. err == 4 ? ", possibly for having an invalid login_id1." :
  13809. err == 5 ? ", possibly for having an invalid client_tick." :
  13810. */
  13811. err == 6 ? ", possibly for having an invalid sex." :
  13812. ". ERROR invalid error code"), cmd, RFIFOREST(fd));
  13813. WFIFOHEAD(fd,packet_len(0x6a));
  13814. WFIFOW(fd,0) = 0x6a;
  13815. WFIFOB(fd,2) = 3; // Rejected from Server
  13816. WFIFOSET(fd,packet_len(0x6a));
  13817. #ifdef DUMP_INVALID_PACKET
  13818. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13819. #endif
  13820. RFIFOSKIP(fd, RFIFOREST(fd));
  13821. set_eof(fd);
  13822. return 0;
  13823. }
  13824. }
  13825. // filter out invalid / unsupported packets
  13826. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  13827. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  13828. #ifdef DUMP_INVALID_PACKET
  13829. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13830. #endif
  13831. set_eof(fd);
  13832. return 0;
  13833. }
  13834. // determine real packet length
  13835. packet_len = packet_db[packet_ver][cmd].len;
  13836. if (packet_len == -1) { // variable-length packet
  13837. if (RFIFOREST(fd) < 4)
  13838. return 0;
  13839. packet_len = RFIFOW(fd,2);
  13840. if (packet_len < 4 || packet_len > 32768) {
  13841. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  13842. #ifdef DUMP_INVALID_PACKET
  13843. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  13844. #endif
  13845. set_eof(fd);
  13846. return 0;
  13847. }
  13848. }
  13849. if ((int)RFIFOREST(fd) < packet_len)
  13850. return 0; // not enough data received to form the packet
  13851. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  13852. packet_db[packet_ver][cmd].func(fd, sd);
  13853. else if( packet_db[packet_ver][cmd].func != NULL ) {
  13854. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  13855. ; //Only valid packet when there is no session
  13856. else
  13857. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  13858. ; //Only valid packet when player is not on a map
  13859. else
  13860. packet_db[packet_ver][cmd].func(fd, sd);
  13861. }
  13862. #ifdef DUMP_UNKNOWN_PACKET
  13863. else {
  13864. const char* packet_txt = "save/packet.txt";
  13865. FILE* fp;
  13866. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  13867. if( sd ) {
  13868. fprintf(fp, "Unknown packet 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);
  13869. } else {
  13870. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13871. }
  13872. WriteDump(fp, RFIFOP(fd,0), packet_len);
  13873. fprintf(fp, "\n");
  13874. fclose(fp);
  13875. } else {
  13876. ShowError("Failed to write '%s'.\n", packet_txt);
  13877. // Dump on console instead
  13878. if( sd ) {
  13879. ShowDebug("Unknown packet 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);
  13880. } else {
  13881. ShowDebug("Unknown packet 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  13882. }
  13883. ShowDump(RFIFOP(fd,0), packet_len);
  13884. }
  13885. }
  13886. #endif
  13887. RFIFOSKIP(fd, packet_len);
  13888. }; // main loop end
  13889. return 0;
  13890. }
  13891. /*==========================================
  13892. * Reads packet_db.txt and setups its array reference
  13893. *------------------------------------------*/
  13894. static int packetdb_readdb(void)
  13895. {
  13896. FILE *fp;
  13897. char line[1024];
  13898. int ln=0;
  13899. int cmd,i,j,packet_ver;
  13900. int max_cmd=-1;
  13901. int skip_ver = 0;
  13902. int warned = 0;
  13903. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  13904. int packet_len_table[MAX_PACKET_DB] = {
  13905. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13909. //#0x0040
  13910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13912. #if PACKETVER <= 20081217
  13913. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  13914. #else
  13915. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  13916. #endif
  13917. #if PACKETVER < 2
  13918. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  13919. #elif PACKETVER < 20071106 // 78-7b Lv99 effect for later Kameshima
  13920. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  13921. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  13922. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  13923. #else
  13924. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  13925. #endif
  13926. //#0x0080
  13927. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  13928. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  13929. #if PACKETVER <= 20100622
  13930. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  13931. #else
  13932. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  13933. #endif
  13934. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  13935. //#0x00C0
  13936. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  13937. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  13938. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  13939. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  13940. //#0x0100
  13941. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  13942. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  13943. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  13944. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  13945. //#0x0140
  13946. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  13947. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  13948. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  13949. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  13950. //#0x0180
  13951. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  13952. #if PACKETVER < 1
  13953. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13954. #else // 196 comodo icon status display for later
  13955. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  13956. #endif
  13957. #if PACKETVER < 20081126
  13958. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13959. #else // 0x1a2 changed (35->37)
  13960. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  13961. #endif
  13962. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  13963. //#0x01C0, Set 0x1d5=-1
  13964. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  13965. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  13966. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  13967. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  13968. //#0x0200
  13969. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  13970. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  13971. #if PACKETVER < 20071106
  13972. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  13973. #else // 0x22c changed
  13974. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  13975. #endif
  13976. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, 6, -1, 4, 2,
  13977. //#0x0240
  13978. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  13979. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, 6, 4, 6,
  13980. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13981. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13982. //#0x0280
  13983. #if PACKETVER < 20070711
  13984. 0, 0, 0, 6, 14, 0, 0, -1, 6, 8, 18, 0, 0, 0, 0, 0,
  13985. #else
  13986. 0, 0, 0, 6, 14, 0, 0, -1, 10, 12, 18, 0, 0, 0, 0, 0, // 0x288, 0x289 increase by 4 (kafra points)
  13987. #endif
  13988. 0, 4, 0, 70, 10, 0, 0, 0, 8, 6, 27, 80, 0, -1, 0, 0,
  13989. 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13990. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 8, 0, 0, 0, 0,
  13991. //#0x02C0
  13992. 0, -1, 0, 0, 0, 30, 30, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  13993. -1, -1, -1, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 36,
  13994. 34, 33, 0, 0, 0, 0, 0, 0, -1, -1, -1, 13, 67, 59, 60, 8,
  13995. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13996. //#0x0300
  13997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  13999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14001. //#0x0340
  14002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14006. //#0x0380
  14007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14011. //#0x03C0
  14012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14016. //#0x0400
  14017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  14021. //#0x0440
  14022. 10, 4, -1, 0, 0, 0, 14, 0, 0, 0, 6, 0, 0, 0, 0, 0,
  14023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14026. //#0x0480
  14027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14031. //#0x04C0
  14032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14036. //#0x0500
  14037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14041. //#0x0540
  14042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14046. //#0x0580
  14047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14051. //#0x05C0
  14052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14056. //#0x0600
  14057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14061. //#0x0640
  14062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14066. //#0x0680
  14067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14071. //#0x06C0
  14072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14076. //#0x0700
  14077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  14081. //#0x0740
  14082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14086. //#0x0780
  14087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14091. //#0x07C0
  14092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14093. #if PACKETVER < 20090617
  14094. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  14095. #else // 0x7d9 changed
  14096. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  14097. #endif
  14098. 0, 15, 8, 6, -1, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  14099. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 25, 0, 0, 26, 0,
  14100. //#0x0800
  14101. #if PACKETVER < 20091229
  14102. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  14103. #else // for Party booking ( PACKETVER >= 20091229 )
  14104. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  14105. #endif
  14106. 3, -1, 8, -1, 86, 2, 6, 6, -1, -1, 4, 10, 10, 0, 0, 0,
  14107. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14108. 0, 0, 0, 0, 0, -1, -1, 3, 2, 66, 5, 2, 12, 6, 0, 0,
  14109. //#0x0840
  14110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14111. 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
  14112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14114. //#0x0880
  14115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14119. //#0x08C0
  14120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,
  14121. 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14124. //#0x0900
  14125. 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
  14126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14129. //#0x0940
  14130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14133. 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0,
  14134. //#0x0980
  14135. 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  14138. 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0,
  14139. };
  14140. struct {
  14141. void (*func)(int, struct map_session_data *);
  14142. char *name;
  14143. } clif_parse_func[]={
  14144. {clif_parse_WantToConnection,"wanttoconnection"},
  14145. {clif_parse_LoadEndAck,"loadendack"},
  14146. {clif_parse_TickSend,"ticksend"},
  14147. {clif_parse_WalkToXY,"walktoxy"},
  14148. {clif_parse_QuitGame,"quitgame"},
  14149. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  14150. {clif_parse_GlobalMessage,"globalmessage"},
  14151. {clif_parse_MapMove,"mapmove"},
  14152. {clif_parse_ChangeDir,"changedir"},
  14153. {clif_parse_Emotion,"emotion"},
  14154. {clif_parse_HowManyConnections,"howmanyconnections"},
  14155. {clif_parse_ActionRequest,"actionrequest"},
  14156. {clif_parse_Restart,"restart"},
  14157. {clif_parse_WisMessage,"wis"},
  14158. {clif_parse_Broadcast,"broadcast"},
  14159. {clif_parse_TakeItem,"takeitem"},
  14160. {clif_parse_DropItem,"dropitem"},
  14161. {clif_parse_UseItem,"useitem"},
  14162. {clif_parse_EquipItem,"equipitem"},
  14163. {clif_parse_UnequipItem,"unequipitem"},
  14164. {clif_parse_NpcClicked,"npcclicked"},
  14165. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  14166. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  14167. {clif_parse_NpcSellListSend,"npcselllistsend"},
  14168. {clif_parse_CreateChatRoom,"createchatroom"},
  14169. {clif_parse_ChatAddMember,"chataddmember"},
  14170. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  14171. {clif_parse_ChangeChatOwner,"changechatowner"},
  14172. {clif_parse_KickFromChat,"kickfromchat"},
  14173. {clif_parse_ChatLeave,"chatleave"},
  14174. {clif_parse_TradeRequest,"traderequest"},
  14175. {clif_parse_TradeAck,"tradeack"},
  14176. {clif_parse_TradeAddItem,"tradeadditem"},
  14177. {clif_parse_TradeOk,"tradeok"},
  14178. {clif_parse_TradeCancel,"tradecancel"},
  14179. {clif_parse_TradeCommit,"tradecommit"},
  14180. {clif_parse_StopAttack,"stopattack"},
  14181. {clif_parse_PutItemToCart,"putitemtocart"},
  14182. {clif_parse_GetItemFromCart,"getitemfromcart"},
  14183. {clif_parse_RemoveOption,"removeoption"},
  14184. {clif_parse_ChangeCart,"changecart"},
  14185. {clif_parse_StatusUp,"statusup"},
  14186. {clif_parse_SkillUp,"skillup"},
  14187. {clif_parse_UseSkillToId,"useskilltoid"},
  14188. {clif_parse_UseSkillToPos,"useskilltopos"},
  14189. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  14190. {clif_parse_UseSkillMap,"useskillmap"},
  14191. {clif_parse_RequestMemo,"requestmemo"},
  14192. {clif_parse_ProduceMix,"producemix"},
  14193. {clif_parse_Cooking,"cooking"},
  14194. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  14195. {clif_parse_NpcNextClicked,"npcnextclicked"},
  14196. {clif_parse_NpcAmountInput,"npcamountinput"},
  14197. {clif_parse_NpcStringInput,"npcstringinput"},
  14198. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  14199. {clif_parse_ItemIdentify,"itemidentify"},
  14200. {clif_parse_SelectArrow,"selectarrow"},
  14201. {clif_parse_AutoSpell,"autospell"},
  14202. {clif_parse_UseCard,"usecard"},
  14203. {clif_parse_InsertCard,"insertcard"},
  14204. {clif_parse_RepairItem,"repairitem"},
  14205. {clif_parse_WeaponRefine,"weaponrefine"},
  14206. {clif_parse_SolveCharName,"solvecharname"},
  14207. {clif_parse_ResetChar,"resetchar"},
  14208. {clif_parse_LocalBroadcast,"localbroadcast"},
  14209. {clif_parse_MoveToKafra,"movetokafra"},
  14210. {clif_parse_MoveFromKafra,"movefromkafra"},
  14211. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  14212. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  14213. {clif_parse_CloseKafra,"closekafra"},
  14214. {clif_parse_CreateParty,"createparty"},
  14215. {clif_parse_CreateParty2,"createparty2"},
  14216. {clif_parse_PartyInvite,"partyinvite"},
  14217. {clif_parse_PartyInvite2,"partyinvite2"},
  14218. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  14219. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  14220. {clif_parse_LeaveParty,"leaveparty"},
  14221. {clif_parse_RemovePartyMember,"removepartymember"},
  14222. {clif_parse_PartyChangeOption,"partychangeoption"},
  14223. {clif_parse_PartyMessage,"partymessage"},
  14224. {clif_parse_PartyChangeLeader,"partychangeleader"},
  14225. {clif_parse_CloseVending,"closevending"},
  14226. {clif_parse_VendingListReq,"vendinglistreq"},
  14227. {clif_parse_PurchaseReq,"purchasereq"},
  14228. {clif_parse_PurchaseReq2,"purchasereq2"},
  14229. {clif_parse_OpenVending,"openvending"},
  14230. {clif_parse_CreateGuild,"createguild"},
  14231. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  14232. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  14233. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  14234. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  14235. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  14236. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  14237. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  14238. {clif_parse_GuildInvite,"guildinvite"},
  14239. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  14240. {clif_parse_GuildLeave,"guildleave"},
  14241. {clif_parse_GuildExpulsion,"guildexpulsion"},
  14242. {clif_parse_GuildMessage,"guildmessage"},
  14243. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  14244. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  14245. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  14246. {clif_parse_GuildOpposition,"guildopposition"},
  14247. {clif_parse_GuildBreak,"guildbreak"},
  14248. {clif_parse_PetMenu,"petmenu"},
  14249. {clif_parse_CatchPet,"catchpet"},
  14250. {clif_parse_SelectEgg,"selectegg"},
  14251. {clif_parse_SendEmotion,"sendemotion"},
  14252. {clif_parse_ChangePetName,"changepetname"},
  14253. {clif_parse_GMKick,"gmkick"},
  14254. {clif_parse_GMHide,"gmhide"},
  14255. {clif_parse_GMReqNoChat,"gmreqnochat"},
  14256. {clif_parse_GMReqAccountName,"gmreqaccname"},
  14257. {clif_parse_GMKickAll,"killall"},
  14258. {clif_parse_GMRecall,"recall"},
  14259. {clif_parse_GMRecall,"summon"},
  14260. {clif_parse_GM_Monster_Item,"itemmonster"},
  14261. {clif_parse_GMShift,"remove"},
  14262. {clif_parse_GMShift,"shift"},
  14263. {clif_parse_GMChangeMapType,"changemaptype"},
  14264. {clif_parse_GMRc,"rc"},
  14265. {clif_parse_GMRecall2,"recall2"},
  14266. {clif_parse_GMRemove2,"remove2"},
  14267. {clif_parse_NoviceDoriDori,"sndoridori"},
  14268. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  14269. {clif_parse_PMIgnore,"wisexin"},
  14270. {clif_parse_PMIgnoreList,"wisexlist"},
  14271. {clif_parse_PMIgnoreAll,"wisall"},
  14272. {clif_parse_FriendsListAdd,"friendslistadd"},
  14273. {clif_parse_FriendsListRemove,"friendslistremove"},
  14274. {clif_parse_FriendsListReply,"friendslistreply"},
  14275. {clif_parse_Blacksmith,"blacksmith"},
  14276. {clif_parse_Alchemist,"alchemist"},
  14277. {clif_parse_Taekwon,"taekwon"},
  14278. {clif_parse_RankingPk,"rankingpk"},
  14279. {clif_parse_FeelSaveOk,"feelsaveok"},
  14280. {clif_parse_debug,"debug"},
  14281. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  14282. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  14283. {clif_parse_HomMoveTo,"hommoveto"},
  14284. {clif_parse_HomAttack,"homattack"},
  14285. {clif_parse_HomMenu,"hommenu"},
  14286. {clif_parse_StoragePassword,"storagepassword"},
  14287. {clif_parse_Hotkey,"hotkey"},
  14288. {clif_parse_AutoRevive,"autorevive"},
  14289. {clif_parse_Check,"check"},
  14290. {clif_parse_Adopt_request,"adoptrequest"},
  14291. {clif_parse_Adopt_reply,"adoptreply"},
  14292. // MAIL SYSTEM
  14293. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  14294. {clif_parse_Mail_read,"mailread"},
  14295. {clif_parse_Mail_getattach,"mailgetattach"},
  14296. {clif_parse_Mail_delete,"maildelete"},
  14297. {clif_parse_Mail_return,"mailreturn"},
  14298. {clif_parse_Mail_setattach,"mailsetattach"},
  14299. {clif_parse_Mail_winopen,"mailwinopen"},
  14300. {clif_parse_Mail_send,"mailsend"},
  14301. // AUCTION SYSTEM
  14302. {clif_parse_Auction_search,"auctionsearch"},
  14303. {clif_parse_Auction_buysell,"auctionbuysell"},
  14304. {clif_parse_Auction_setitem,"auctionsetitem"},
  14305. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  14306. {clif_parse_Auction_register,"auctionregister"},
  14307. {clif_parse_Auction_cancel,"auctioncancel"},
  14308. {clif_parse_Auction_close,"auctionclose"},
  14309. {clif_parse_Auction_bid,"auctionbid"},
  14310. // Quest Log System
  14311. {clif_parse_questStateAck,"queststate"},
  14312. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  14313. {clif_parse_EquipTick,"equiptickbox"},
  14314. {clif_parse_BattleChat,"battlechat"},
  14315. {clif_parse_mercenary_action,"mermenu"},
  14316. {clif_parse_progressbar,"progressbar"},
  14317. {clif_parse_SkillSelectMenu,"skillselectmenu"},
  14318. {clif_parse_ItemListWindowSelected,"itemlistwindowselected"},
  14319. #if PACKETVER >= 20091229
  14320. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  14321. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  14322. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  14323. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  14324. #endif
  14325. {clif_parse_PVPInfo,"pvpinfo"},
  14326. {clif_parse_LessEffect,"lesseffect"},
  14327. // Buying Store
  14328. {clif_parse_ReqOpenBuyingStore,"reqopenbuyingstore"},
  14329. {clif_parse_ReqCloseBuyingStore,"reqclosebuyingstore"},
  14330. {clif_parse_ReqClickBuyingStore,"reqclickbuyingstore"},
  14331. {clif_parse_ReqTradeBuyingStore,"reqtradebuyingstore"},
  14332. // Store Search
  14333. {clif_parse_SearchStoreInfo,"searchstoreinfo"},
  14334. {clif_parse_SearchStoreInfoNextPage,"searchstoreinfonextpage"},
  14335. {clif_parse_CloseSearchStoreInfo,"closesearchstoreinfo"},
  14336. {clif_parse_SearchStoreInfoListItemClick,"searchstoreinfolistitemclick"},
  14337. // Cashshop
  14338. { clif_parse_cashshop_open_request, "cashshopopen" },
  14339. { clif_parse_cashshop_close, "cashshopclose" },
  14340. { clif_parse_cashshop_list_request, "cashshopitemlist" },
  14341. { clif_parse_cashshop_buy, "cashshopbuy" },
  14342. /* */
  14343. { clif_parse_MoveItem , "moveitem" },
  14344. {NULL,NULL}
  14345. };
  14346. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  14347. memset(packet_db,0,sizeof(packet_db));
  14348. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  14349. packet_len(i) = packet_len_table[i];
  14350. sprintf(line, "%s/packet_db.txt", db_path);
  14351. if( (fp=fopen(line,"r"))==NULL ){
  14352. ShowFatalError("can't read %s\n", line);
  14353. exit(EXIT_FAILURE);
  14354. }
  14355. clif_config.packet_db_ver = MAX_PACKET_VER;
  14356. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  14357. while( fgets(line, sizeof(line), fp) )
  14358. {
  14359. ln++;
  14360. if(line[0]=='/' && line[1]=='/')
  14361. continue;
  14362. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  14363. {
  14364. if(strcmpi(w1,"packet_ver")==0) {
  14365. int prev_ver = packet_ver;
  14366. skip_ver = 0;
  14367. packet_ver = atoi(w2);
  14368. if ( packet_ver > MAX_PACKET_VER )
  14369. { //Check to avoid overflowing. [Skotlex]
  14370. if( (warned&1) == 0 )
  14371. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  14372. warned &= 1;
  14373. skip_ver = 1;
  14374. }
  14375. else if( packet_ver < 0 )
  14376. {
  14377. if( (warned&2) == 0 )
  14378. ShowWarning("Negative packet versions are not supported.\n");
  14379. warned &= 2;
  14380. skip_ver = 1;
  14381. }
  14382. else if( packet_ver == SERVER )
  14383. {
  14384. if( (warned&4) == 0 )
  14385. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  14386. warned &= 4;
  14387. skip_ver = 1;
  14388. }
  14389. if( skip_ver )
  14390. {
  14391. ShowWarning("Skipping packet version %d.\n", packet_ver);
  14392. packet_ver = prev_ver;
  14393. continue;
  14394. }
  14395. // copy from previous version into new version and continue
  14396. // - indicating all following packets should be read into the newer version
  14397. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  14398. continue;
  14399. } else if(strcmpi(w1,"packet_db_ver")==0) {
  14400. if(strcmpi(w2,"default")==0) //This is the preferred version.
  14401. clif_config.packet_db_ver = MAX_PACKET_VER;
  14402. else // to manually set the packet DB version
  14403. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  14404. continue;
  14405. }
  14406. }
  14407. if( skip_ver != 0 )
  14408. continue; // Skipping current packet version
  14409. memset(str,0,sizeof(str));
  14410. for(j=0,p=line;j<4 && p; ++j)
  14411. {
  14412. str[j]=p;
  14413. p=strchr(p,',');
  14414. if(p) *p++=0;
  14415. }
  14416. if(str[0]==NULL)
  14417. continue;
  14418. cmd=strtol(str[0],(char **)NULL,0);
  14419. if(max_cmd < cmd)
  14420. max_cmd = cmd;
  14421. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  14422. continue;
  14423. if(str[1]==NULL){
  14424. ShowError("packet_db: packet len error\n");
  14425. continue;
  14426. }
  14427. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  14428. if(str[2]==NULL){
  14429. packet_db[packet_ver][cmd].func = NULL;
  14430. ln++;
  14431. continue;
  14432. }
  14433. // look up processing function by name
  14434. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  14435. if( j < ARRAYLENGTH(clif_parse_func) )
  14436. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  14437. // set the identifying cmd for the packet_db version
  14438. if (strcmp(str[2],"wanttoconnection")==0)
  14439. clif_config.connect_cmd[packet_ver] = cmd;
  14440. if(str[3]==NULL){
  14441. ShowError("packet_db: packet error\n");
  14442. exit(EXIT_FAILURE);
  14443. }
  14444. for(j=0,p2=str[3];p2;j++){
  14445. short k;
  14446. str2[j]=p2;
  14447. p2=strchr(p2,':');
  14448. if(p2) *p2++=0;
  14449. k = atoi(str2[j]);
  14450. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  14451. if( j >= MAX_PACKET_POS )
  14452. {
  14453. ShowError("Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS);
  14454. break;
  14455. }
  14456. packet_db[packet_ver][cmd].pos[j] = k;
  14457. }
  14458. }
  14459. fclose(fp);
  14460. if(max_cmd > MAX_PACKET_DB)
  14461. {
  14462. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  14463. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  14464. }
  14465. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  14466. { //Locate the nearest version that we still support. [Skotlex]
  14467. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  14468. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  14469. }
  14470. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'.\n","packet_db.txt");
  14471. ShowStatus("Using default packet version: "CL_WHITE"%d"CL_RESET".\n", clif_config.packet_db_ver);
  14472. return 0;
  14473. }
  14474. /*==========================================
  14475. *
  14476. *------------------------------------------*/
  14477. int do_init_clif(void) {
  14478. const char* colors[COLOR_MAX] = { "0xFF0000" };
  14479. int i;
  14480. /**
  14481. * Setup Color Table (saves unnecessary load of strtoul on every call)
  14482. **/
  14483. for(i = 0; i < COLOR_MAX; i++) {
  14484. color_table[i] = strtoul(colors[i],NULL,0);
  14485. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  14486. }
  14487. clif_config.packet_db_ver = -1; // the main packet version of the DB
  14488. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  14489. //Using the packet_db file is the only way to set up packets now [Skotlex]
  14490. packetdb_readdb();
  14491. set_defaultparse(clif_parse);
  14492. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  14493. ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",map_port);
  14494. exit(EXIT_FAILURE);
  14495. }
  14496. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  14497. add_timer_func_list(clif_delayquit, "clif_delayquit");
  14498. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.c::delay_clearunit_ers",ERS_OPT_CLEAR);
  14499. return 0;
  14500. }
  14501. void do_final_clif(void) {
  14502. ers_destroy(delay_clearunit_ers);
  14503. }